blob: 8b43ba5a5273521feb564573517d213e0e4af129 [file] [log] [blame]
Dennis Syrovatskyf3c57662005-11-02 03:53:04 +00001/* Copyright (C) 2005 TightVNC Team. All Rights Reserved.
2*
3* This is free software; you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation; either version 2 of the License, or
6* (at your option) any later version.
7*
8* This software is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this software; if not, write to the Free Software
15* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16* USA.
17*
18* TightVNC distribution homepage on the Web: http://www.tightvnc.com/
19*
20*/
21
22// -=- FTListView.cxx
23
24#include <vncviewer/FTListView.h>
25
26using namespace rfb;
27using namespace rfb::win32;
28
Dennis Syrovatsky8a19ce42005-11-07 08:46:23 +000029FTListView::FTListView(HWND hListView)
Dennis Syrovatskyf3c57662005-11-02 03:53:04 +000030{
Dennis Syrovatsky8a19ce42005-11-07 08:46:23 +000031 m_bInitialized = false;
32 m_hListView = hListView;
Dennis Syrovatskyf3c57662005-11-02 03:53:04 +000033 m_fileInfo.free();
34}
35
36FTListView::~FTListView()
37{
38 m_fileInfo.free();
39}
40
41
42bool
Dennis Syrovatsky8a19ce42005-11-07 08:46:23 +000043FTListView::initialize(HINSTANCE hInst)
Dennis Syrovatskyf3c57662005-11-02 03:53:04 +000044{
Dennis Syrovatsky8a19ce42005-11-07 08:46:23 +000045 if (m_bInitialized) return false;
46
47 initImageList(hInst);
48
49 RECT Rect;
50 GetClientRect(m_hListView, &Rect);
51 Rect.right -= GetSystemMetrics(SM_CXHSCROLL);
52 int xwidth0 = (int) (0.35 * Rect.right);
53 int xwidth1 = (int) (0.22 * Rect.right);
54 int xwidth2 = (int) (0.43 * Rect.right);
55
56 addColumn("Name", 0, xwidth0, LVCFMT_LEFT);
57 addColumn("Size", 1, xwidth1, LVCFMT_RIGHT);
58 addColumn("Data", 2, xwidth2, LVCFMT_LEFT);
59
60 return true;
Dennis Syrovatskyf3c57662005-11-02 03:53:04 +000061}
62
63void
64FTListView::onGetDispInfo(NMLVDISPINFO *pDI)
65{
66 if (m_fileInfo.getFlagsAt(pDI->item.iItem) & FT_ATTR_DIR) {
67 pDI->item.iImage = 0;
68 } else {
69 pDI->item.iImage = 1;
70 }
71
72 switch (pDI->item.iSubItem)
73 {
74 case 0:
75 pDI->item.pszText = m_fileInfo.getNameAt(pDI->item.iItem);
76 break;
77 case 1:
78 {
79 unsigned int flags = m_fileInfo.getFlagsAt(pDI->item.iItem);
80 switch(flags & 0x000000FF)
81 {
82 case FT_ATTR_FILE:
83 {
84 char buf[32];
85 unsigned int size = m_fileInfo.getSizeAt(pDI->item.iItem);
86 sprintf(buf, "%u", size);
87 pDI->item.pszText = buf;
88 }
89 break;
90 case FT_ATTR_DIR:
91 pDI->item.pszText = "";
92 break;
93 default:
94 pDI->item.pszText = "Unspecified";
95 }
96 }
97 break;
98 case 2:
99 {
100 unsigned int data = m_fileInfo.getDataAt(pDI->item.iItem);
101 if (data == 0) {
102 pDI->item.pszText = "Unspecified";
103 } else {
104 FILETIME ft;
105 FolderManager fm;
106 fm.getFiletime(data, &ft);
107
108 SYSTEMTIME st;
109 FileTimeToSystemTime(&ft, &st);
110
111 char pDateTimeStr[1024];
112 char timeFmt[128];
113 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, timeFmt, 128);
114 char dateFmt[128];
115 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, dateFmt, 128);
116
117 char timeStr[128];
118 GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, timeFmt, timeStr, 128);
119 char dateStr[128];
120 GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, dateFmt, dateStr, 128);
121
122 sprintf(pDateTimeStr, "%s %s", dateStr, timeStr);
123 pDI->item.pszText = pDateTimeStr;
124 }
125 }
126 break;
127 default:
128 break;
129 }
130}
131
132void
133FTListView::addItems(FileInfo *pFI)
134{
135 m_fileInfo.add(pFI);
136 LVITEM LVItem;
137 LVItem.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
138 LVItem.state = 0;
139 LVItem.stateMask = 0;
140 for (unsigned int i = 0; i < m_fileInfo.getNumEntries(); i++) {
141 LVItem.iItem = i;
142 LVItem.iSubItem = 0;
143 LVItem.iImage = I_IMAGECALLBACK;
144 LVItem.pszText = LPSTR_TEXTCALLBACK;
145 ListView_InsertItem(m_hListView, &LVItem);
146 }
147}
148
149void
150FTListView::deleteAllItems()
151{
152 ListView_DeleteAllItems(m_hListView);
153 m_fileInfo.free();
154}
155
156char *
157FTListView::getActivateItemName(LPNMITEMACTIVATE lpnmia)
158{
159 return m_fileInfo.getNameAt(lpnmia->iItem);
160}
161
162int
163FTListView::getSelectedItems(FileInfo *pFI)
164{
165 int selCount = ListView_GetSelectedCount(m_hListView);
166 int selItem = ListView_GetSelectionMark(m_hListView);
167 if ((selCount < 1) || (selItem < 0)) return -1;
168
169 selItem = -1;
170 selItem = ListView_GetNextItem(m_hListView, selItem, LVNI_SELECTED);
171 do {
172 pFI->add(m_fileInfo.getFullDataAt(selItem));
173 selItem = ListView_GetNextItem(m_hListView, selItem, LVNI_SELECTED);
174 } while (selItem >= 0);
175
176 return selCount;
177}
178
179void
180FTListView::initImageList(HINSTANCE hInst)
181{
182 m_hImageList = ImageList_Create(16, 16, ILC_MASK, 2, 2);
183
184 HICON hiconItem = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FTDIR));
185 ImageList_AddIcon(m_hImageList, hiconItem);
186 DestroyIcon(hiconItem);
187
188 hiconItem = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FTFILE));
189 ImageList_AddIcon(m_hImageList, hiconItem);
190 DestroyIcon(hiconItem);
191
192 ListView_SetImageList(m_hListView, m_hImageList, LVSIL_SMALL);
193}
Dennis Syrovatsky8a19ce42005-11-07 08:46:23 +0000194
195void
196FTListView::addColumn(char *iText, int iOrder, int xWidth, int alignFmt)
197{
198 LVCOLUMN lvc;
199 lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_ORDER;
200 lvc.fmt = alignFmt;
201 lvc.iSubItem = iOrder;
202 lvc.pszText = iText;
203 lvc.cchTextMax = 32;
204 lvc.cx = xWidth;
205 lvc.iOrder = iOrder;
206 ListView_InsertColumn(m_hListView, iOrder, &lvc);
207}