~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/UI/FileManager/PanelListNotify.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// PanelListNotify.cpp
 
2
 
 
3
#include "StdAfx.h"
 
4
 
 
5
#include "resource.h"
 
6
 
 
7
#include "Common/IntToString.h"
 
8
#include "Common/StringConvert.h"
 
9
 
 
10
#include "Windows/PropVariant.h"
 
11
#include "Windows/PropVariantConversions.h"
 
12
 
 
13
#include "../Common/PropIDUtils.h"
 
14
#include "../../PropID.h"
 
15
 
 
16
#include "Panel.h"
 
17
#include "FormatUtils.h"
 
18
 
 
19
using namespace NWindows;
 
20
 
 
21
static UString ConvertSizeToStringShort(UInt64 value)
 
22
{
 
23
  wchar_t s[32];
 
24
  wchar_t c, c2 = L'B';
 
25
  if (value < (UInt64)10000)
 
26
  {
 
27
    c = L'B';
 
28
    c2 = L'\0';
 
29
  }
 
30
  else if (value < ((UInt64)10000 << 10))
 
31
  {
 
32
    value >>= 10;
 
33
    c = L'K';
 
34
  }
 
35
  else if (value < ((UInt64)10000 << 20))
 
36
  {
 
37
    value >>= 20;
 
38
    c = L'M';
 
39
  }
 
40
  else
 
41
  {
 
42
    value >>= 30;
 
43
    c = L'G';
 
44
  }
 
45
  ConvertUInt64ToString(value, s);
 
46
  int p = MyStringLen(s);
 
47
  s[p++] = L' ';
 
48
  s[p++] = c;
 
49
  s[p++] = c2;
 
50
  s[p++] = L'\0';
 
51
  return s;
 
52
}
 
53
 
 
54
UString ConvertSizeToString(UInt64 value)
 
55
{
 
56
  wchar_t s[32];
 
57
  ConvertUInt64ToString(value, s);
 
58
  int i = MyStringLen(s);
 
59
  int pos = sizeof(s) / sizeof(s[0]);
 
60
  s[--pos] = L'\0';
 
61
  while (i > 3)
 
62
  {
 
63
    s[--pos] = s[--i];
 
64
    s[--pos] = s[--i];
 
65
    s[--pos] = s[--i];
 
66
    s[--pos] = L' ';
 
67
  }
 
68
  while (i > 0)
 
69
    s[--pos] = s[--i];
 
70
  return s + pos;
 
71
}
 
72
 
 
73
LRESULT CPanel::SetItemText(LVITEMW &item)
 
74
{
 
75
  if (_dontShowMode)
 
76
    return 0;
 
77
 
 
78
  UINT32 realIndex = GetRealIndex(item);
 
79
  // printf(" CPanel::SetItemText : realIndex=%d\n",realIndex);
 
80
 
 
81
  /*
 
82
  if ((item.mask & LVIF_IMAGE) != 0)
 
83
  {
 
84
    bool defined  = false;
 
85
    CComPtr<IFolderGetSystemIconIndex> folderGetSystemIconIndex;
 
86
    _folder.QueryInterface(&folderGetSystemIconIndex);
 
87
    if (folderGetSystemIconIndex)
 
88
    {
 
89
      folderGetSystemIconIndex->GetSystemIconIndex(index, &item.iImage);
 
90
      defined = (item.iImage > 0);
 
91
    }
 
92
    if (!defined)
 
93
    {
 
94
      NCOM::CPropVariant prop;
 
95
      _folder->GetProperty(index, kpidAttrib, &prop);
 
96
      UINT32 attrib = 0;
 
97
      if (prop.vt == VT_UI4)
 
98
        attrib = prop.ulVal;
 
99
      else if (IsItemFolder(index))
 
100
        attrib |= FILE_ATTRIBUTE_DIRECTORY;
 
101
      if (_currentFolderPrefix.IsEmpty())
 
102
        throw 1;
 
103
      else
 
104
        item.iImage = _extToIconMap.GetIconIndex(attrib, GetSystemString(GetItemName(index)));
 
105
    }
 
106
    // item.iImage = 1;
 
107
  }
 
108
  */
 
109
 
 
110
  if ((item.mask & LVIF_TEXT) == 0)
 
111
    return 0;
 
112
 
 
113
  if (realIndex == kParentIndex)
 
114
    return 0;
 
115
  UString s;
 
116
  UINT32 subItemIndex = item.iSubItem;
 
117
  PROPID propID = _visibleProperties[subItemIndex].ID;
 
118
  /*
 
119
  {
 
120
    NCOM::CPropVariant property;
 
121
    if(propID == kpidType)
 
122
      string = GetFileType(index);
 
123
    else
 
124
    {
 
125
      HRESULT result = m_ArchiveFolder->GetProperty(index, propID, &property);
 
126
      if (result != S_OK)
 
127
      {
 
128
        // PrintMessage("GetPropertyValue error");
 
129
        return 0;
 
130
      }
 
131
      string = ConvertPropertyToString(property, propID, false);
 
132
    }
 
133
  }
 
134
  */
 
135
  // const NFind::CFileInfo &aFileInfo = m_Files[index];
 
136
 
 
137
  NCOM::CPropVariant prop;
 
138
  /*
 
139
  bool needRead = true;
 
140
  if (propID == kpidSize)
 
141
  {
 
142
    CComPtr<IFolderGetItemFullSize> getItemFullSize;
 
143
    if (_folder.QueryInterface(&getItemFullSize) == S_OK)
 
144
    {
 
145
      if (getItemFullSize->GetItemFullSize(index, &prop) == S_OK)
 
146
        needRead = false;
 
147
    }
 
148
  }
 
149
  if (needRead)
 
150
  */
 
151
 
 
152
  if (_folder->GetProperty(realIndex, propID, &prop) != S_OK)
 
153
      throw 2723407;
 
154
 
 
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));
 
162
  else
 
163
  {
 
164
    s = ConvertPropertyToString(prop, propID, false);
 
165
    s.Replace(wchar_t(0xA), L' ');
 
166
    s.Replace(wchar_t(0xD), L' ');
 
167
  }
 
168
  int size = item.cchTextMax;
 
169
  if(size > 0)
 
170
  {
 
171
    if(s.Length() + 1 > size)
 
172
      s = s.Left(size - 1);
 
173
    MyStringCopy(item.pszText, (const wchar_t *)s);
 
174
  }
 
175
  return 0;
 
176
}
 
177
 
 
178
#ifdef _WIN32
 
179
extern DWORD g_ComCtl32Version;
 
180
#endif
 
181
 
 
182
void CPanel::OnItemChanged(NMLISTVIEW *item)
 
183
{
 
184
  int index = (int)item->lParam;
 
185
  if (index == kParentIndex)
 
186
    return;
 
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;
 
194
  }
 
195
}
 
196
 
 
197
bool CPanel::OnNotifyList(LPNMHDR header, LRESULT &result)
 
198
{
 
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;
 
203
  switch(header->code)
 
204
  {
 
205
    case LVN_ITEMCHANGED:
 
206
    {
 
207
      if (_enableItemChangeNotify)
 
208
      {
 
209
        if (!_mySelectMode)
 
210
          OnItemChanged((LPNMLISTVIEW)header);
 
211
        RefreshStatusBar();
 
212
      }
 
213
      return false;
 
214
    }
 
215
    /*
 
216
 
 
217
    case LVN_ODSTATECHANGED:
 
218
      {
 
219
      break;
 
220
      }
 
221
    */
 
222
 
 
223
#ifdef _WIN32
 
224
    case LVN_GETDISPINFOW:
 
225
    {
 
226
      LV_DISPINFOW *dispInfo = (LV_DISPINFOW *)header;
 
227
 
 
228
      //is the sub-item information being requested?
 
229
 
 
230
      if((dispInfo->item.mask & LVIF_TEXT) != 0 ||
 
231
        (dispInfo->item.mask & LVIF_IMAGE) != 0)
 
232
        SetItemText(dispInfo->item);
 
233
      return false;
 
234
    }
 
235
    case LVN_KEYDOWN:
 
236
    {
 
237
      bool boolResult = OnKeyDown(LPNMLVKEYDOWN(header), result);
 
238
      RefreshStatusBar();
 
239
      return boolResult;
 
240
    }
 
241
#endif
 
242
 
 
243
    case LVN_COLUMNCLICK:
 
244
      OnColumnClick(LPNMLISTVIEW(header));
 
245
      return false;
 
246
    /*
 
247
    case LVN_ITEMACTIVATE:
 
248
      RefreshStatusBar();
 
249
      if (!alt && !ctrl && !shift)
 
250
        OpenSelectedItems(true);
 
251
      return false;
 
252
    */
 
253
 
 
254
    case NM_DBLCLK:
 
255
      RefreshStatusBar();
 
256
      OpenSelectedItems(true);
 
257
      return false;
 
258
#ifdef _WIN32
 
259
    case NM_RETURN:
 
260
    {
 
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)
 
267
      {
 
268
        Properties();
 
269
        return false;
 
270
      }
 
271
      OpenSelectedItems(true);
 
272
      return false;
 
273
    }
 
274
    case NM_RCLICK:
 
275
      RefreshStatusBar();
 
276
      break;
 
277
 
 
278
    /*
 
279
      return OnRightClick((LPNMITEMACTIVATE)header, result);
 
280
    */
 
281
      /*
 
282
      case NM_CLICK:
 
283
      SendRefreshStatusBarMessage();
 
284
      return 0;
 
285
      
 
286
        // TODO : Handler default action...
 
287
        return 0;
 
288
        case LVN_ITEMCHANGED:
 
289
        {
 
290
        NMLISTVIEW *pNMLV = (NMLISTVIEW *) lpnmh;
 
291
        SelChange(pNMLV);
 
292
        return TRUE;
 
293
        }
 
294
        case NM_SETFOCUS:
 
295
        return onSetFocus(NULL);
 
296
        case NM_KILLFOCUS:
 
297
        return onKillFocus(NULL);
 
298
      */
 
299
    case NM_CLICK:
 
300
    {
 
301
      // we need SetFocusToList, if we drag-select items from other panel.
 
302
      SetFocusToList();
 
303
      RefreshStatusBar();
 
304
      if(_mySelectMode)
 
305
        if(g_ComCtl32Version >= MAKELONG(71, 4))
 
306
          OnLeftClick((LPNMITEMACTIVATE)header);
 
307
      return false;
 
308
    }
 
309
    case LVN_BEGINLABELEDITW:
 
310
      result = OnBeginLabelEdit((LV_DISPINFOW *)header);
 
311
      return true;
 
312
    case LVN_ENDLABELEDITW:
 
313
      result = OnEndLabelEdit((LV_DISPINFOW *)header);
 
314
      return true;
 
315
 
 
316
    case NM_CUSTOMDRAW:
 
317
    {
 
318
      if (_mySelectMode)
 
319
        return OnCustomDraw((LPNMLVCUSTOMDRAW)header, result);
 
320
      break;
 
321
    }
 
322
    case LVN_BEGINDRAG:
 
323
    {
 
324
      OnDrag((LPNMLISTVIEW)header);
 
325
      RefreshStatusBar();
 
326
      break;
 
327
    }
 
328
#endif
 
329
    // case LVN_BEGINRDRAG:
 
330
  }
 
331
  return false;
 
332
}
 
333
 
 
334
#ifdef _WIN32
 
335
bool CPanel::OnCustomDraw(LPNMLVCUSTOMDRAW lplvcd, LRESULT &result)
 
336
{
 
337
  switch(lplvcd->nmcd.dwDrawStage)
 
338
  {
 
339
  case CDDS_PREPAINT :
 
340
    result = CDRF_NOTIFYITEMDRAW;
 
341
    return true;
 
342
    
 
343
  case CDDS_ITEMPREPAINT:
 
344
    /*
 
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);
 
352
    */
 
353
    int realIndex = (int)lplvcd->nmcd.lItemlParam;
 
354
    bool selected = false;
 
355
    if (realIndex != kParentIndex)
 
356
      selected = _selectedStatusVector[realIndex];
 
357
    if (selected)
 
358
      lplvcd->clrTextBk = RGB(255, 192, 192);
 
359
    // lplvcd->clrText = RGB(255, 0, 128);
 
360
    else
 
361
      lplvcd->clrTextBk = _listView.GetBkColor();
 
362
    // lplvcd->clrText = RGB(0, 0, 0);
 
363
    // result = CDRF_NEWFONT;
 
364
    result = CDRF_NOTIFYITEMDRAW;
 
365
    return true;
 
366
    
 
367
    // return false;
 
368
    // return true;
 
369
    /*
 
370
    case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
 
371
    if (lplvcd->iSubItem == 0)
 
372
    {
 
373
    // lplvcd->clrText = RGB(255, 0, 0);
 
374
    lplvcd->clrTextBk = RGB(192, 192, 192);
 
375
    }
 
376
    else
 
377
    {
 
378
    lplvcd->clrText = RGB(0, 0, 0);
 
379
    lplvcd->clrTextBk = RGB(255, 255, 255);
 
380
    }
 
381
    return true;
 
382
    */
 
383
 
 
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 */
 
388
  }
 
389
  return false;
 
390
}
 
391
#endif //#ifdef _WIN32
 
392
 
 
393
void CPanel::OnRefreshStatusBar()
 
394
{
 
395
  CRecordVector<UINT32> indices;
 
396
  GetOperatedItemIndices(indices);
 
397
 
 
398
  _statusBar.SetText(0, MyFormatNew(IDS_N_SELECTED_ITEMS, 0x02000301, NumberToString(indices.Size())));
 
399
 
 
400
  UString selectSizeString;
 
401
 
 
402
  if (indices.Size() > 0)
 
403
  {
 
404
    UInt64 totalSize = 0;
 
405
    for (int i = 0; i < indices.Size(); i++)
 
406
      totalSize += GetItemSize(indices[i]);
 
407
    selectSizeString = ConvertSizeToString(totalSize);
 
408
  }
 
409
  _statusBar.SetText(1, selectSizeString);
 
410
 
 
411
  int focusedItem = _listView.GetFocusedItem();
 
412
  UString sizeString;
 
413
  UString dateString;
 
414
  if (focusedItem >= 0 && _listView.GetSelectedCount() > 0)
 
415
  {
 
416
    int realIndex = GetRealItemIndex(focusedItem);
 
417
    if (realIndex != kParentIndex)
 
418
    {
 
419
      sizeString = ConvertSizeToString(GetItemSize(realIndex));
 
420
      NCOM::CPropVariant prop;
 
421
      if (_folder->GetProperty(realIndex, kpidMTime, &prop) == S_OK)
 
422
        dateString = ConvertPropertyToString(prop, kpidMTime, false);
 
423
    }
 
424
  }
 
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)));
 
429
}