diff options
author | Dennis Syrovatsky <dennis@tightvnc.com> | 2005-11-02 03:53:04 +0000 |
---|---|---|
committer | Dennis Syrovatsky <dennis@tightvnc.com> | 2005-11-02 03:53:04 +0000 |
commit | f3c5766d6015b16ff0083a6515901abe447ab301 (patch) | |
tree | 20544f5d26d46e3d0e637a825d8c726e0122565b /vncviewer/FTListView.cxx | |
parent | af20f423b30143022b4f794e4bd15bf37f1c0048 (diff) | |
download | tigervnc-f3c5766d6015b16ff0083a6515901abe447ab301.tar.gz tigervnc-f3c5766d6015b16ff0083a6515901abe447ab301.zip |
Added FTListView class.
Code improvements.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@365 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'vncviewer/FTListView.cxx')
-rw-r--r-- | vncviewer/FTListView.cxx | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/vncviewer/FTListView.cxx b/vncviewer/FTListView.cxx new file mode 100644 index 00000000..162d7c1c --- /dev/null +++ b/vncviewer/FTListView.cxx @@ -0,0 +1,177 @@ +/* Copyright (C) 2005 TightVNC Team. All Rights Reserved. +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this software; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +* USA. +* +* TightVNC distribution homepage on the Web: http://www.tightvnc.com/ +* +*/ + +// -=- FTListView.cxx + +#include <vncviewer/FTListView.h> + +using namespace rfb; +using namespace rfb::win32; + +FTListView::FTListView(HWND hLV) +{ + m_hListView = hLV; + m_fileInfo.free(); +} + +FTListView::~FTListView() +{ + m_fileInfo.free(); +} + + +bool +FTListView::initialize() +{ + return false; +} + +void +FTListView::onGetDispInfo(NMLVDISPINFO *pDI) +{ + if (m_fileInfo.getFlagsAt(pDI->item.iItem) & FT_ATTR_DIR) { + pDI->item.iImage = 0; + } else { + pDI->item.iImage = 1; + } + + switch (pDI->item.iSubItem) + { + case 0: + pDI->item.pszText = m_fileInfo.getNameAt(pDI->item.iItem); + break; + case 1: + { + unsigned int flags = m_fileInfo.getFlagsAt(pDI->item.iItem); + switch(flags & 0x000000FF) + { + case FT_ATTR_FILE: + { + char buf[32]; + unsigned int size = m_fileInfo.getSizeAt(pDI->item.iItem); + sprintf(buf, "%u", size); + pDI->item.pszText = buf; + } + break; + case FT_ATTR_DIR: + pDI->item.pszText = ""; + break; + default: + pDI->item.pszText = "Unspecified"; + } + } + break; + case 2: + { + unsigned int data = m_fileInfo.getDataAt(pDI->item.iItem); + if (data == 0) { + pDI->item.pszText = "Unspecified"; + } else { + FILETIME ft; + FolderManager fm; + fm.getFiletime(data, &ft); + + SYSTEMTIME st; + FileTimeToSystemTime(&ft, &st); + + char pDateTimeStr[1024]; + char timeFmt[128]; + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, timeFmt, 128); + char dateFmt[128]; + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, dateFmt, 128); + + char timeStr[128]; + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, timeFmt, timeStr, 128); + char dateStr[128]; + GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, dateFmt, dateStr, 128); + + sprintf(pDateTimeStr, "%s %s", dateStr, timeStr); + pDI->item.pszText = pDateTimeStr; + } + } + break; + default: + break; + } +} + +void +FTListView::addItems(FileInfo *pFI) +{ + m_fileInfo.add(pFI); + LVITEM LVItem; + LVItem.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE; + LVItem.state = 0; + LVItem.stateMask = 0; + for (unsigned int i = 0; i < m_fileInfo.getNumEntries(); i++) { + LVItem.iItem = i; + LVItem.iSubItem = 0; + LVItem.iImage = I_IMAGECALLBACK; + LVItem.pszText = LPSTR_TEXTCALLBACK; + ListView_InsertItem(m_hListView, &LVItem); + } +} + +void +FTListView::deleteAllItems() +{ + ListView_DeleteAllItems(m_hListView); + m_fileInfo.free(); +} + +char * +FTListView::getActivateItemName(LPNMITEMACTIVATE lpnmia) +{ + return m_fileInfo.getNameAt(lpnmia->iItem); +} + +int +FTListView::getSelectedItems(FileInfo *pFI) +{ + int selCount = ListView_GetSelectedCount(m_hListView); + int selItem = ListView_GetSelectionMark(m_hListView); + if ((selCount < 1) || (selItem < 0)) return -1; + + selItem = -1; + selItem = ListView_GetNextItem(m_hListView, selItem, LVNI_SELECTED); + do { + pFI->add(m_fileInfo.getFullDataAt(selItem)); + selItem = ListView_GetNextItem(m_hListView, selItem, LVNI_SELECTED); + } while (selItem >= 0); + + return selCount; +} + +void +FTListView::initImageList(HINSTANCE hInst) +{ + m_hImageList = ImageList_Create(16, 16, ILC_MASK, 2, 2); + + HICON hiconItem = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FTDIR)); + ImageList_AddIcon(m_hImageList, hiconItem); + DestroyIcon(hiconItem); + + hiconItem = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FTFILE)); + ImageList_AddIcon(m_hImageList, hiconItem); + DestroyIcon(hiconItem); + + ListView_SetImageList(m_hListView, m_hImageList, LVSIL_SMALL); +} |