Skip to content

Commit

Permalink
Up to 1.0.5
Browse files Browse the repository at this point in the history
* Column reordering
  • Loading branch information
little-brother committed Mar 22, 2023
1 parent 66e4e46 commit a6b1774
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 @@ -67,7 +67,7 @@
#define MAX_LENGTH 4096
#define MAX_COLUMN_LENGTH 2000
#define APP_NAME TEXT("xmltab")
#define APP_VERSION TEXT("1.0.4")
#define APP_VERSION TEXT("1.0.5")
#define LOADING TEXT("Loading...")
#define WHITESPACE " \t\r\n"

Expand Down Expand Up @@ -461,7 +461,7 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) {
205, 0, 100, 100, hTabWnd, (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 @@ -855,8 +855,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 @@ -869,6 +874,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 @@ -1209,8 +1216,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
TreeView_SelectItem(hTreeWnd, hItem);
}

if (pHdr->code == HDN_ITEMCHANGED && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(GetDlgItem(hWnd, IDC_TAB), IDC_GRID)))
SendMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0);
if ((pHdr->code == HDN_ITEMCHANGED || pHdr->code == HDN_ENDDRAG) && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(GetDlgItem(hWnd, IDC_TAB), IDC_GRID)))
PostMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0);

if (pHdr->code == (UINT)NM_SETFOCUS)
SetProp(hWnd, TEXT("LASTFOCUS"), pHdr->hwndFrom);
Expand Down Expand Up @@ -1706,12 +1713,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 a6b1774

Please sign in to comment.