📄 panelitems.cpp
字号:
// PanelItems.cpp
#include "StdAfx.h"
#include "Common/StringConvert.h"
#include "Windows/Menu.h"
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
#include "../../PropID.h"
#include "resource.h"
#include "LangUtils.h"
#include "Panel.h"
#include "PropertyName.h"
#include "RootFolder.h"
extern "C"
{
#include "../../../../C/Sort.h"
}
using namespace NWindows;
static int GetColumnAlign(PROPID propID, VARTYPE varType)
{
switch(propID)
{
case kpidCTime:
case kpidATime:
case kpidMTime:
return LVCFMT_LEFT;
}
switch(varType)
{
case VT_UI1:
case VT_I2:
case VT_UI2:
case VT_I4:
case VT_INT:
case VT_UI4:
case VT_UINT:
case VT_I8:
case VT_UI8:
case VT_BOOL:
return LVCFMT_RIGHT;
case VT_EMPTY:
case VT_I1:
case VT_FILETIME:
case VT_BSTR:
return LVCFMT_LEFT;
default:
return LVCFMT_CENTER;
}
}
void CPanel::InitColumns()
{
if (_needSaveInfo)
SaveListViewInfo();
_listView.DeleteAllItems();
_selectedStatusVector.Clear();
ReadListViewInfo();
PROPID sortID;
/*
if (_listViewInfo.SortIndex >= 0)
sortID = _listViewInfo.Columns[_listViewInfo.SortIndex].PropID;
*/
sortID = _listViewInfo.SortID;
_ascending = _listViewInfo.Ascending;
_properties.Clear();
_needSaveInfo = true;
UInt32 numProperties;
_folder->GetNumberOfProperties(&numProperties);
int i;
for (i = 0; i < (int)numProperties; i++)
{
CMyComBSTR name;
PROPID propID;
VARTYPE varType;
if (_folder->GetPropertyInfo(i, &name, &propID, &varType) != S_OK)
throw 1;
if (propID == kpidIsDir)
continue;
CItemProperty prop;
prop.Type = varType;
prop.ID = propID;
prop.Name = GetNameOfProperty(propID, name);
prop.Order = -1;
prop.IsVisible = true;
prop.Width = 100;
_properties.Add(prop);
}
// InitColumns2(sortID);
for (;;)
if (!_listView.DeleteColumn(0))
break;
int order = 0;
for(i = 0; i < _listViewInfo.Columns.Size(); i++)
{
const CColumnInfo &columnInfo = _listViewInfo.Columns[i];
int index = _properties.FindItemWithID(columnInfo.PropID);
if (index >= 0)
{
CItemProperty &item = _properties[index];
item.IsVisible = columnInfo.IsVisible;
item.Width = columnInfo.Width;
if (columnInfo.IsVisible)
item.Order = order++;
continue;
}
}
for(i = 0; i < _properties.Size(); i++)
{
CItemProperty &item = _properties[i];
if (item.Order < 0)
item.Order = order++;
}
_visibleProperties.Clear();
for (i = 0; i < _properties.Size(); i++)
{
const CItemProperty &property = _properties[i];
if (property.IsVisible)
_visibleProperties.Add(property);
}
// _sortIndex = 0;
_sortID = kpidName;
/*
if (_listViewInfo.SortIndex >= 0)
{
int sortIndex = _properties.FindItemWithID(sortID);
if (sortIndex >= 0)
_sortIndex = sortIndex;
}
*/
_sortID = _listViewInfo.SortID;
for (i = 0; i < _visibleProperties.Size(); i++)
{
InsertColumn(i);
}
}
void CPanel::InsertColumn(int index)
{
const CItemProperty &property = _visibleProperties[index];
LV_COLUMNW column;
column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_ORDER;
column.cx = property.Width;
column.fmt = GetColumnAlign(property.ID, property.Type);
column.iOrder = property.Order;
column.iSubItem = index;
column.pszText = (wchar_t *)(const wchar_t *)property.Name;
_listView.InsertColumn(index, &column);
}
void CPanel::RefreshListCtrl()
{
RefreshListCtrl(UString(), -1, true, UStringVector());
}
int CALLBACK CompareItems(LPARAM lParam1, LPARAM lParam2, LPARAM lpData);
void CPanel::GetSelectedNames(UStringVector &selectedNames)
{
selectedNames.Clear();
CRecordVector<UInt32> indices;
GetSelectedItemsIndices(indices);
selectedNames.Reserve(indices.Size());
for (int i = 0; i < indices.Size(); i++)
selectedNames.Add(GetItemRelPath(indices[i]));
/*
for (int i = 0; i < _listView.GetItemCount(); i++)
{
const int kSize = 1024;
WCHAR name[kSize + 1];
LVITEMW item;
item.iItem = i;
item.pszText = name;
item.cchTextMax = kSize;
item.iSubItem = 0;
item.mask = LVIF_TEXT | LVIF_PARAM;
if (!_listView.GetItem(&item))
continue;
int realIndex = GetRealIndex(item);
if (realIndex == kParentIndex)
continue;
if (_selectedStatusVector[realIndex])
selectedNames.Add(item.pszText);
}
*/
selectedNames.Sort();
}
void CPanel::SaveSelectedState(CSelectedState &s)
{
s.FocusedName.Empty();
s.SelectedNames.Clear();
s.FocusedItem = _listView.GetFocusedItem();
{
if (s.FocusedItem >= 0)
{
int realIndex = GetRealItemIndex(s.FocusedItem);
if (realIndex != kParentIndex)
s.FocusedName = GetItemRelPath(realIndex);
/*
const int kSize = 1024;
WCHAR name[kSize + 1];
LVITEMW item;
item.iItem = focusedItem;
item.pszText = name;
item.cchTextMax = kSize;
item.iSubItem = 0;
item.mask = LVIF_TEXT;
if (_listView.GetItem(&item))
focusedName = item.pszText;
*/
}
}
GetSelectedNames(s.SelectedNames);
}
void CPanel::RefreshListCtrl(const CSelectedState &s)
{
bool selectFocused = s.SelectFocused;
if (_mySelectMode)
selectFocused = true;
RefreshListCtrl(s.FocusedName, s.FocusedItem, selectFocused, s.SelectedNames);
}
void CPanel::RefreshListCtrlSaveFocused()
{
CSelectedState state;
SaveSelectedState(state);
RefreshListCtrl(state);
}
void CPanel::SetFocusedSelectedItem(int index, bool select)
{
UINT state = LVIS_FOCUSED;
if (select)
state |= LVIS_SELECTED;
_listView.SetItemState(index, state, state);
if (!_mySelectMode && select)
{
int realIndex = GetRealItemIndex(index);
if (realIndex != kParentIndex)
_selectedStatusVector[realIndex] = true;
}
}
void CPanel::RefreshListCtrl(const UString &focusedName, int focusedPos, bool selectFocused,
const UStringVector &selectedNames)
{
_dontShowMode = false;
LoadFullPathAndShow();
// OutputDebugStringA("=======\n");
// OutputDebugStringA("s1 \n");
CDisableTimerProcessing timerProcessing(*this);
if (focusedPos < 0)
focusedPos = 0;
_listView.SetRedraw(false);
// m_RedrawEnabled = false;
LVITEMW item;
ZeroMemory(&item, sizeof(item));
_listView.DeleteAllItems();
_selectedStatusVector.Clear();
// _realIndices.Clear();
_startGroupSelect = 0;
_selectionIsDefined = false;
// m_Files.Clear();
// _folder.Release();
if (!_folder)
{
// throw 1;
SetToRootFolder();
}
_headerToolBar.EnableButton(kParentFolderID, !IsRootFolder());
CMyComPtr<IFolderSetFlatMode> folderSetFlatMode;
_folder.QueryInterface(IID_IFolderSetFlatMode, &folderSetFlatMode);
if (folderSetFlatMode)
folderSetFlatMode->SetFlatMode(BoolToInt(_flatMode));
if (_folder->LoadItems() != S_OK)
return;
InitColumns();
// OutputDebugString(TEXT("Start Dir\n"));
UInt32 numItems;
_folder->GetNumberOfItems(&numItems);
bool showDots = _showDots && !IsRootFolder();
_listView.SetItemCount(numItems + (showDots ? 1 : 0));
_selectedStatusVector.Reserve(numItems);
int cursorIndex = -1;
CMyComPtr<IFolderGetSystemIconIndex> folderGetSystemIconIndex;
if (!IsFSFolder() || _showRealFileIcons)
_folder.QueryInterface(IID_IFolderGetSystemIconIndex, &folderGetSystemIconIndex);
if (showDots)
{
UString itemName = L"..";
item.iItem = _listView.GetItemCount();
if (itemName.CompareNoCase(focusedName) == 0)
cursorIndex = item.iItem;
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
int subItem = 0;
item.iSubItem = subItem++;
item.lParam = kParentIndex;
item.pszText = (wchar_t *)(const wchar_t *)itemName;
UInt32 attributes = FILE_ATTRIBUTE_DIRECTORY;
item.iImage = _extToIconMap.GetIconIndex(attributes, itemName);
if (item.iImage < 0)
item.iImage = 0;
if(_listView.InsertItem(&item) == -1)
return;
}
// OutputDebugStringA("S1\n");
for(UInt32 i = 0; i < numItems; i++)
{
UString itemName = GetItemName(i);
const UString relPath = GetItemRelPath(i);
if (relPath.CompareNoCase(focusedName) == 0)
cursorIndex = _listView.GetItemCount();
bool selected = false;
if (selectedNames.FindInSorted(relPath) >= 0)
selected = true;
_selectedStatusVector.Add(selected);
item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
if (!_mySelectMode)
if (selected)
{
item.mask |= LVIF_STATE;
item.state = LVIS_SELECTED;
}
int subItem = 0;
item.iItem = _listView.GetItemCount();
item.iSubItem = subItem++;
item.lParam = i;
UString correctedName;
if (itemName.Find(L" ") >= 0)
{
int pos = 0;
for (;;)
{
int posNew = itemName.Find(L" ", pos);
if (posNew < 0)
{
correctedName += itemName.Mid(pos);
break;
}
correctedName += itemName.Mid(pos, posNew - pos);
correctedName += L" ... ";
pos = posNew;
while (itemName[++pos] == ' ');
}
item.pszText = (wchar_t *)(const wchar_t *)correctedName;
}
else
item.pszText = (wchar_t *)(const wchar_t *)itemName;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -