Skip to content

Commit

Permalink
Up to 1.0.3
Browse files Browse the repository at this point in the history
* Column reordering
  • Loading branch information
little-brother committed Mar 22, 2023
1 parent 2c9deb7 commit 1c4748a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 1c4748a

Please sign in to comment.