From b818c0cdb9be40995c62052e921c828c42c2413f Mon Sep 17 00:00:00 2001 From: mataes2007 Date: Sat, 6 Aug 2011 14:29:02 +0000 Subject: Svc_dbepp: added settings sorting on column click git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@156 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- dbeditorpp/headers.h | 8 ++++++++ dbeditorpp/main_window.cpp | 5 +++++ dbeditorpp/settinglist.cpp | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/dbeditorpp/headers.h b/dbeditorpp/headers.h index 8cd54c9..4cc08e6 100644 --- a/dbeditorpp/headers.h +++ b/dbeditorpp/headers.h @@ -163,6 +163,12 @@ struct WatchListArrayStruct{ int size; }; extern WatchListArrayStruct WatchListArray; + +struct SettingsSortParams{ + HWND hList; + int column; +}; + //======================================================= // Variables //======================================================= @@ -263,4 +269,6 @@ void freeAllWatches(); INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void popupWatchedVar(HANDLE hContact,const char* module,const char* setting); +INT_PTR CALLBACK SettingsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam); + #endif //_COMMONHEADERS_H \ No newline at end of file diff --git a/dbeditorpp/main_window.cpp b/dbeditorpp/main_window.cpp index adb551e..7ff9dc0 100644 --- a/dbeditorpp/main_window.cpp +++ b/dbeditorpp/main_window.cpp @@ -235,6 +235,11 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)GetSubMenu(hMenu,i),0); } + SettingsSortParams params = {0}; + params.hList = GetDlgItem(hwnd, IDC_SETTINGS); + params.column = 0; + ListView_SortItemsEx(params.hList, SettingsCompare, (LPARAM) ¶ms); + // move the dialog to the users position MoveWindow(hwnd,DBGetContactSettingDword(NULL,modname,"x",0),DBGetContactSettingDword(NULL,modname,"y",0),DBGetContactSettingDword(NULL,modname,"width",500),DBGetContactSettingDword(NULL,modname,"height",250),0); diff --git a/dbeditorpp/settinglist.cpp b/dbeditorpp/settinglist.cpp index c3c27cb..e3fbd7e 100644 --- a/dbeditorpp/settinglist.cpp +++ b/dbeditorpp/settinglist.cpp @@ -731,6 +731,23 @@ void EditLabel(HWND hwnd2List, int item, int subitem) static int test; void SettingsListRightClick(HWND hwnd, WPARAM wParam,LPARAM lParam); +static int lastColumn = -1; + +INT_PTR CALLBACK SettingsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam) +{ + SettingsSortParams params = *(SettingsSortParams *) myParam; + const int maxSize = 1024; + TCHAR text1[maxSize]; + TCHAR text2[maxSize]; + long value1, value2; + ListView_GetItemText(params.hList, (int) lParam1, params.column, text1, maxSize); + ListView_GetItemText(params.hList, (int) lParam2, params.column, text2, maxSize); + + int res = _tcsicmp(text1, text2); + res = (params.column == lastColumn) ? -res : res; + return res; +} + void SettingsListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { switch(((NMHDR*)lParam)->code) @@ -773,8 +790,9 @@ void SettingsListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) info->hwnd2Edit = NULL; info->selectedItem = 0; } + break; } - break; + case NM_DBLCLK: { SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(GetDlgItem(hwnd,IDC_SETTINGS),GWLP_USERDATA); @@ -794,12 +812,24 @@ void SettingsListWM_NOTIFY(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) } else EditLabel(GetDlgItem(hwnd,IDC_SETTINGS),hti.iItem,hti.iSubItem); } + break; } - break; case NM_RCLICK: SettingsListRightClick(hwnd,wParam,lParam); - break; + break; + + case LVN_COLUMNCLICK: + { + LPNMLISTVIEW lv = (LPNMLISTVIEW) lParam; + SettingsSortParams params = {0}; + params.hList = GetDlgItem(hwnd, IDC_SETTINGS); + params.column = lv->iSubItem; + ListView_SortItemsEx(params.hList, SettingsCompare, (LPARAM) ¶ms); + lastColumn = (params.column == lastColumn) ? -1 : params.column; + break; + } + } // switch(((NMHDR*)lParam)->code) } -- cgit v1.2.3