From e57d24547c04f1f9ac651676736bcf90670fe6ee Mon Sep 17 00:00:00 2001 From: little-brother Date: Tue, 21 Nov 2023 00:54:27 +0300 Subject: [PATCH] Up to 1.0.6 * Sort columns by Ctrl + 1, Ctrl + 2, ... * Fix issue for non-ANSI fonts --- main.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 31e8dd0..2bd17bf 100644 --- a/main.c +++ b/main.c @@ -31,8 +31,9 @@ #define WMU_SWITCH_TAB WM_USER + 12 #define WMU_HIDE_COLUMN WM_USER + 13 #define WMU_SHOW_COLUMNS WM_USER + 14 -#define WMU_HOT_KEYS WM_USER + 15 -#define WMU_HOT_CHARS WM_USER + 16 +#define WMU_SORT_COLUMN WM_USER + 15 +#define WMU_HOT_KEYS WM_USER + 16 +#define WMU_HOT_CHARS WM_USER + 17 #define IDC_MAIN 100 #define IDC_TREE 101 @@ -67,7 +68,7 @@ #define MAX_LENGTH 4096 #define MAX_COLUMN_LENGTH 2000 #define APP_NAME TEXT("xmltab") -#define APP_VERSION TEXT("1.0.5") +#define APP_VERSION TEXT("1.0.6") #define LOADING TEXT("Loading...") #define WHITESPACE " \t\r\n" @@ -1112,15 +1113,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (pHdr->idFrom == IDC_GRID && pHdr->code == LVN_COLUMNCLICK) { NMLISTVIEW* lv = (NMLISTVIEW*)lParam; - // Hide or sort the column - if (HIWORD(GetKeyState(VK_CONTROL))) - return SendMessage(hWnd, WMU_HIDE_COLUMN, lv->iSubItem, 0); - - int colNo = lv->iSubItem + 1; - int* pOrderBy = (int*)GetProp(hWnd, TEXT("ORDERBY")); - int orderBy = *pOrderBy; - *pOrderBy = colNo == orderBy || colNo == -orderBy ? -orderBy : colNo; - SendMessage(hWnd, WMU_UPDATE_RESULTSET, 0, 0); + return SendMessage(hWnd, HIWORD(GetKeyState(VK_CONTROL)) ? WMU_HIDE_COLUMN : WMU_SORT_COLUMN, lv->iSubItem, 0); } if (pHdr->idFrom == IDC_GRID && (pHdr->code == (DWORD)NM_CLICK || pHdr->code == (DWORD)NM_RCLICK)) { @@ -1181,9 +1174,26 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { } if (kd->wVKey == VK_LEFT || kd->wVKey == VK_RIGHT) { + HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB); + HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID); + HWND hHeader = ListView_GetHeader(hGridWnd); + int colCount = Header_GetItemCount(ListView_GetHeader(pHdr->hwndFrom)); - int colNo = *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO")) + (kd->wVKey == VK_RIGHT ? 1 : -1); - colNo = colNo < 0 ? colCount - 1 : colNo > colCount - 1 ? 0 : colNo; + int colNo = *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO")); + + int* colOrder = calloc(colCount, sizeof(int)); + Header_GetOrderArray(hHeader, colCount, colOrder); + + int dir = kd->wVKey == VK_RIGHT ? 1 : -1; + int idx = 0; + for (idx; colOrder[idx] != colNo; idx++); + do { + idx = (colCount + idx + dir) % colCount; + } while (ListView_GetColumnWidth(hGridWnd, colOrder[idx]) == 0); + + colNo = colOrder[idx]; + free(colOrder); + SendMessage(hWnd, WMU_SET_CURRENT_CELL, *(int*)GetProp(hWnd, TEXT("CURRENTROWNO")), colNo); return TRUE; } @@ -1281,6 +1291,19 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { } break; + // wParam = colNo + case WMU_SORT_COLUMN: { + int colNo = (int)wParam + 1; + if (colNo <= 0) + return FALSE; + + int* pOrderBy = (int*)GetProp(hWnd, TEXT("ORDERBY")); + int orderBy = *pOrderBy; + *pOrderBy = colNo == orderBy || colNo == -orderBy ? -orderBy : colNo; + SendMessage(hWnd, WMU_UPDATE_RESULTSET, 0, 0); + } + break; + case WMU_UPDATE_GRID: { HWND hTreeWnd = GetDlgItem(hWnd, IDC_TREE); HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB); @@ -1892,7 +1915,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { *pFontSize += wParam; DeleteFont(GetProp(hWnd, TEXT("FONT"))); - HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY"))); + HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY"))); HWND hTreeWnd = GetDlgItem(hWnd, IDC_TREE); HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB); HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID); @@ -2008,13 +2031,40 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F3 || wParam == VK_F5 || wParam == VK_F7 || (isCtrl && wParam == 0x46) || // Ctrl + F - ((wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) || // 1 - 8 + ((wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) && !isCtrl || // 1 - 8 (wParam == 0x4E || wParam == 0x50) && !getStoredValue(TEXT("disable-np-keys"), 0) || // N, P wParam == 0x51 && getStoredValue(TEXT("exit-by-q"), 0)) && // Q GetDlgCtrlID(GetFocus()) / 100 * 100 != IDC_HEADER_EDIT) { SetFocus(GetParent(hWnd)); keybd_event(wParam, wParam, KEYEVENTF_EXTENDEDKEY, 0); + return TRUE; + } + + if (isCtrl && wParam >= 0x30 && wParam <= 0x39 && !getStoredValue(TEXT("disable-num-keys"), 0)) {// 0-9 + HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB); + HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID); + HWND hHeader = ListView_GetHeader(hGridWnd); + int colCount = Header_GetItemCount(ListView_GetHeader(hGridWnd)); + + BOOL isCurrent = wParam == 0x30; + int colNo = isCurrent ? *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO")) : wParam - 0x30 - 1; + if (colNo < 0 || colNo > colCount - 1 || isCurrent && ListView_GetColumnWidth(hGridWnd, colNo) == 0) + return FALSE; + + if (!isCurrent) { + int* colOrder = calloc(colCount, sizeof(int)); + Header_GetOrderArray(hHeader, colCount, colOrder); + + int hiddenColCount = 0; + for (int idx = 0; (idx < colCount) && (idx - hiddenColCount <= colNo); idx++) + hiddenColCount += ListView_GetColumnWidth(hGridWnd, colOrder[idx]) == 0; + + colNo = colOrder[colNo + hiddenColCount]; + free(colOrder); + } + + SendMessage(hWnd, WMU_SORT_COLUMN, colNo, 0); return TRUE; } @@ -2026,7 +2076,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { BOOL isCtrl = HIWORD(GetKeyState(VK_CONTROL)); unsigned char scancode = ((unsigned char*)&lParam)[2]; - UINT key = MapVirtualKey(scancode,MAPVK_VSC_TO_VK); + UINT key = MapVirtualKey(scancode, MAPVK_VSC_TO_VK); return !_istprint(wParam) && ( wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F1 ||