From 1c4748a858749bdaceca42dc8e06d2700c206a70 Mon Sep 17 00:00:00 2001 From: little-brother Date: Wed, 22 Mar 2023 03:08:52 +0300 Subject: [PATCH] Up to 1.0.3 * Column reordering --- main.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 83fa757..eded2ab 100644 --- a/main.c +++ b/main.c @@ -70,7 +70,7 @@ #define MAX_FILTER_LENGTH 2000 #define DELIMITERS TEXT(",;|\t:") #define APP_NAME TEXT("csvtab") -#define APP_VERSION TEXT("1.0.2") +#define APP_VERSION TEXT("1.0.3") #define CP_UTF16LE 1200 #define CP_UTF16BE 1201 @@ -291,7 +291,7 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) { 205, 0, 100, 100, hMainWnd, (HMENU)IDC_GRID, GetModuleHandle(0), NULL); int noLines = getStoredValue(TEXT("disable-grid-lines"), 0); - ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP); + ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP | LVS_EX_HEADERDRAGDROP); SetProp(hGridWnd, TEXT("WNDPROC"), (HANDLE)SetWindowLongPtr(hGridWnd, GWLP_WNDPROC, (LONG_PTR)cbHotKey)); HWND hHeader = ListView_GetHeader(hGridWnd); @@ -542,8 +542,13 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (cmd == IDM_COPY_ROWS) { int pos = 0; int rowNo = ListView_GetNextItem(hGridWnd, -1, LVNI_SELECTED); + + int* colOrder = calloc(colCount, sizeof(int)); + Header_GetOrderArray(hHeader, colCount, colOrder); + while (rowNo != -1) { - for (int colNo = 0; colNo < colCount; colNo++) { + for (int idx = 0; idx < colCount; idx++) { + int colNo = colOrder[idx]; if (ListView_GetColumnWidth(hGridWnd, colNo)) { int len = _tcslen(cache[resultset[rowNo]][colNo]); _tcsncpy(buf + pos, cache[resultset[rowNo]][colNo], len); @@ -556,6 +561,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { rowNo = ListView_GetNextItem(hGridWnd, rowNo, LVNI_SELECTED); } buf[pos - 1] = 0; // remove last \n + + free(colOrder); } if (cmd == IDM_COPY_COLUMN) { @@ -708,8 +715,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { } } - if (pHdr->code == HDN_ITEMCHANGED && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(hWnd, IDC_GRID))) - SendMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0); + if ((pHdr->code == HDN_ITEMCHANGED || pHdr->code == HDN_ENDDRAG) && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(hWnd, IDC_GRID))) + PostMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0); if (pHdr->idFrom == IDC_STATUSBAR && (pHdr->code == NM_CLICK || pHdr->code == NM_RCLICK)) { NMMOUSE* pm = (NMMOUSE*)lParam; @@ -1233,12 +1240,19 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hHeader = ListView_GetHeader(hGridWnd); int colCount = Header_GetItemCount(hHeader); SendMessage(hHeader, WM_SIZE, 0, 0); - for (int colNo = 0; colNo < colCount; colNo++) { + + int* colOrder = calloc(colCount, sizeof(int)); + Header_GetOrderArray(hHeader, colCount, colOrder); + + for (int idx = 0; idx < colCount; idx++) { + int colNo = colOrder[idx]; RECT rc; Header_GetItemRect(hHeader, colNo, &rc); int h2 = round((rc.bottom - rc.top) / 2); SetWindowPos(GetDlgItem(hHeader, IDC_HEADER_EDIT + colNo), 0, rc.left, h2, rc.right - rc.left, h2 + 1, SWP_NOZORDER); } + + free(colOrder); } break;