7
#include "Common/IntToString.h"
8
#include "Common/StringConvert.h"
10
#include "Windows/PropVariant.h"
11
#include "Windows/PropVariantConversions.h"
13
#include "../Common/PropIDUtils.h"
14
#include "../../PropID.h"
17
#include "FormatUtils.h"
19
using namespace NWindows;
21
static UString ConvertSizeToStringShort(UInt64 value)
25
if (value < (UInt64)10000)
30
else if (value < ((UInt64)10000 << 10))
35
else if (value < ((UInt64)10000 << 20))
45
ConvertUInt64ToString(value, s);
46
int p = MyStringLen(s);
54
UString ConvertSizeToString(UInt64 value)
57
ConvertUInt64ToString(value, s);
58
int i = MyStringLen(s);
59
int pos = sizeof(s) / sizeof(s[0]);
73
LRESULT CPanel::SetItemText(LVITEMW &item)
78
UINT32 realIndex = GetRealIndex(item);
79
// printf(" CPanel::SetItemText : realIndex=%d\n",realIndex);
82
if ((item.mask & LVIF_IMAGE) != 0)
85
CComPtr<IFolderGetSystemIconIndex> folderGetSystemIconIndex;
86
_folder.QueryInterface(&folderGetSystemIconIndex);
87
if (folderGetSystemIconIndex)
89
folderGetSystemIconIndex->GetSystemIconIndex(index, &item.iImage);
90
defined = (item.iImage > 0);
94
NCOM::CPropVariant prop;
95
_folder->GetProperty(index, kpidAttrib, &prop);
97
if (prop.vt == VT_UI4)
99
else if (IsItemFolder(index))
100
attrib |= FILE_ATTRIBUTE_DIRECTORY;
101
if (_currentFolderPrefix.IsEmpty())
104
item.iImage = _extToIconMap.GetIconIndex(attrib, GetSystemString(GetItemName(index)));
110
if ((item.mask & LVIF_TEXT) == 0)
113
if (realIndex == kParentIndex)
116
UINT32 subItemIndex = item.iSubItem;
117
PROPID propID = _visibleProperties[subItemIndex].ID;
120
NCOM::CPropVariant property;
121
if(propID == kpidType)
122
string = GetFileType(index);
125
HRESULT result = m_ArchiveFolder->GetProperty(index, propID, &property);
128
// PrintMessage("GetPropertyValue error");
131
string = ConvertPropertyToString(property, propID, false);
135
// const NFind::CFileInfo &aFileInfo = m_Files[index];
137
NCOM::CPropVariant prop;
139
bool needRead = true;
140
if (propID == kpidSize)
142
CComPtr<IFolderGetItemFullSize> getItemFullSize;
143
if (_folder.QueryInterface(&getItemFullSize) == S_OK)
145
if (getItemFullSize->GetItemFullSize(index, &prop) == S_OK)
152
if (_folder->GetProperty(realIndex, propID, &prop) != S_OK)
155
if ((propID == kpidSize || propID == kpidPackSize || propID == kpidClusterSize ||
156
propID == kpidNumSubDirs || propID == kpidNumSubFiles) &&
157
(prop.vt == VT_UI8 || prop.vt == VT_UI4))
158
s = ConvertSizeToString(ConvertPropVariantToUInt64(prop));
159
else if ((propID == kpidTotalSize || propID == kpidFreeSpace) &&
160
(prop.vt == VT_UI8 || prop.vt == VT_UI4))
161
s = ConvertSizeToStringShort(ConvertPropVariantToUInt64(prop));
164
s = ConvertPropertyToString(prop, propID, false);
165
s.Replace(wchar_t(0xA), L' ');
166
s.Replace(wchar_t(0xD), L' ');
168
int size = item.cchTextMax;
171
if(s.Length() + 1 > size)
172
s = s.Left(size - 1);
173
MyStringCopy(item.pszText, (const wchar_t *)s);
179
extern DWORD g_ComCtl32Version;
182
void CPanel::OnItemChanged(NMLISTVIEW *item)
184
int index = (int)item->lParam;
185
if (index == kParentIndex)
187
bool oldSelected = (item->uOldState & LVIS_SELECTED) != 0;
188
bool newSelected = (item->uNewState & LVIS_SELECTED) != 0;
189
// Don't change this code. It works only with such check
190
printf("CPanel::OnItemChanged : index=%d oldSel=%d newSel=%d\n",index,(int)oldSelected,(int)newSelected);
191
if(oldSelected != newSelected) {
192
printf("CPanel::OnItemChanged : _selectedStatusVector[%d] = %d\n",index,(int)newSelected);
193
_selectedStatusVector[index] = newSelected;
197
bool CPanel::OnNotifyList(LPNMHDR header, LRESULT &result)
199
printf("CPanel::OnNotifyList : FIXME\n");
200
// bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0;
201
// bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
202
// bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
205
case LVN_ITEMCHANGED:
207
if (_enableItemChangeNotify)
210
OnItemChanged((LPNMLISTVIEW)header);
217
case LVN_ODSTATECHANGED:
224
case LVN_GETDISPINFOW:
226
LV_DISPINFOW *dispInfo = (LV_DISPINFOW *)header;
228
//is the sub-item information being requested?
230
if((dispInfo->item.mask & LVIF_TEXT) != 0 ||
231
(dispInfo->item.mask & LVIF_IMAGE) != 0)
232
SetItemText(dispInfo->item);
237
bool boolResult = OnKeyDown(LPNMLVKEYDOWN(header), result);
243
case LVN_COLUMNCLICK:
244
OnColumnClick(LPNMLISTVIEW(header));
247
case LVN_ITEMACTIVATE:
249
if (!alt && !ctrl && !shift)
250
OpenSelectedItems(true);
256
OpenSelectedItems(true);
261
bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0;
262
bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
263
// bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0;
264
// bool RightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0;
265
bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
266
if (!shift && alt && !ctrl)
271
OpenSelectedItems(true);
279
return OnRightClick((LPNMITEMACTIVATE)header, result);
283
SendRefreshStatusBarMessage();
286
// TODO : Handler default action...
288
case LVN_ITEMCHANGED:
290
NMLISTVIEW *pNMLV = (NMLISTVIEW *) lpnmh;
295
return onSetFocus(NULL);
297
return onKillFocus(NULL);
301
// we need SetFocusToList, if we drag-select items from other panel.
305
if(g_ComCtl32Version >= MAKELONG(71, 4))
306
OnLeftClick((LPNMITEMACTIVATE)header);
309
case LVN_BEGINLABELEDITW:
310
result = OnBeginLabelEdit((LV_DISPINFOW *)header);
312
case LVN_ENDLABELEDITW:
313
result = OnEndLabelEdit((LV_DISPINFOW *)header);
319
return OnCustomDraw((LPNMLVCUSTOMDRAW)header, result);
324
OnDrag((LPNMLISTVIEW)header);
329
// case LVN_BEGINRDRAG:
335
bool CPanel::OnCustomDraw(LPNMLVCUSTOMDRAW lplvcd, LRESULT &result)
337
switch(lplvcd->nmcd.dwDrawStage)
340
result = CDRF_NOTIFYITEMDRAW;
343
case CDDS_ITEMPREPAINT:
345
SelectObject(lplvcd->nmcd.hdc,
346
GetFontForItem(lplvcd->nmcd.dwItemSpec,
347
lplvcd->nmcd.lItemlParam) );
348
lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec,
349
lplvcd->nmcd.lItemlParam);
350
lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec,
351
lplvcd->nmcd.lItemlParam);
353
int realIndex = (int)lplvcd->nmcd.lItemlParam;
354
bool selected = false;
355
if (realIndex != kParentIndex)
356
selected = _selectedStatusVector[realIndex];
358
lplvcd->clrTextBk = RGB(255, 192, 192);
359
// lplvcd->clrText = RGB(255, 0, 128);
361
lplvcd->clrTextBk = _listView.GetBkColor();
362
// lplvcd->clrText = RGB(0, 0, 0);
363
// result = CDRF_NEWFONT;
364
result = CDRF_NOTIFYITEMDRAW;
370
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
371
if (lplvcd->iSubItem == 0)
373
// lplvcd->clrText = RGB(255, 0, 0);
374
lplvcd->clrTextBk = RGB(192, 192, 192);
378
lplvcd->clrText = RGB(0, 0, 0);
379
lplvcd->clrTextBk = RGB(255, 255, 255);
384
/* At this point, you can change the background colors for the item
385
and any subitems and return CDRF_NEWFONT. If the list-view control
386
is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW
387
to customize the item's subitems individually */
391
#endif //#ifdef _WIN32
393
void CPanel::OnRefreshStatusBar()
395
CRecordVector<UINT32> indices;
396
GetOperatedItemIndices(indices);
398
_statusBar.SetText(0, MyFormatNew(IDS_N_SELECTED_ITEMS, 0x02000301, NumberToString(indices.Size())));
400
UString selectSizeString;
402
if (indices.Size() > 0)
404
UInt64 totalSize = 0;
405
for (int i = 0; i < indices.Size(); i++)
406
totalSize += GetItemSize(indices[i]);
407
selectSizeString = ConvertSizeToString(totalSize);
409
_statusBar.SetText(1, selectSizeString);
411
int focusedItem = _listView.GetFocusedItem();
414
if (focusedItem >= 0 && _listView.GetSelectedCount() > 0)
416
int realIndex = GetRealItemIndex(focusedItem);
417
if (realIndex != kParentIndex)
419
sizeString = ConvertSizeToString(GetItemSize(realIndex));
420
NCOM::CPropVariant prop;
421
if (_folder->GetProperty(realIndex, kpidMTime, &prop) == S_OK)
422
dateString = ConvertPropertyToString(prop, kpidMTime, false);
425
_statusBar.SetText(2, sizeString);
426
_statusBar.SetText(3, dateString);
427
// _statusBar.SetText(4, nameString);
428
// _statusBar2.SetText(1, MyFormatNew(L"{0} bytes", NumberToStringW(totalSize)));