Skip to content

Commit

Permalink
Up to 1.0.4
Browse files Browse the repository at this point in the history
* Column reordering
  • Loading branch information
little-brother committed Mar 22, 2023
1 parent 75b1530 commit 76ec81a
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 ODBC_EXCELX 3

#define APP_NAME TEXT("odbc-wlx")
#define APP_VERSION TEXT("1.0.3")
#define APP_VERSION TEXT("1.0.4")

#define LCS_FINDFIRST 1
#define LCS_MATCHCASE 2
Expand Down Expand Up @@ -332,7 +332,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 @@ -687,8 +687,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[rowNo][colNo]);
_tcsncpy(buf + pos, cache[rowNo][colNo], len);
Expand All @@ -701,6 +706,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 @@ -838,8 +845,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->code == (UINT)NM_SETFOCUS)
SetProp(hWnd, TEXT("LASTFOCUS"), pHdr->hwndFrom);
Expand Down Expand Up @@ -1153,12 +1160,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 76ec81a

Please sign in to comment.