From fed19b9942575e7c0360a0d77a3c544afdbaeb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 15 Feb 2022 02:29:01 +0100 Subject: Update layout on column width change. --- win.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/win.c b/win.c index e675f63..6f82645 100644 --- a/win.c +++ b/win.c @@ -11,12 +11,17 @@ HFONT g_GUIFont; HFONT g_GUIFontBold; +WNDPROC g_PrevLvProc; + int g_SelectedItem = -1; /* Remembered after refresh. */ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); +static LRESULT CALLBACK LvProc(HWND, UINT, WPARAM, LPARAM); + static void CreateListView(HWND); static LRESULT HandleListViewNotify(HWND, LPARAM); +static void UpdateLayout(HWND); static void SetupFonts(); static TCHAR *TSZFromSZ(char *, int); @@ -128,25 +133,7 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) CreateListView(hWnd); break; case WM_SIZE: - { - HWND hListView; - int cxColumn; - RECT rc; - static int cxVScroll = 0; - - if (cxVScroll == 0) - cxVScroll = GetSystemMetrics(SM_CXVSCROLL); - - GetClientRect(hWnd, &rc); - hListView = GetDlgItem(hWnd, IDC_LISTVIEW); - MoveWindow(hListView, 0, 0, - rc.right, rc.bottom, - TRUE); - - cxColumn = ListView_GetColumnWidth(hListView, 0); - ListView_SetColumnWidth(hListView, 1, - rc.right-cxColumn-cxVScroll); - } + UpdateLayout(hWnd); break; case WM_NOTIFY: switch (((NMHDR *)lParam)->idFrom) { @@ -184,6 +171,25 @@ AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } +LRESULT CALLBACK +LvProc(HWND hListView, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_NOTIFY: + switch (((NMHDR *)lParam)->code) { + case HDN_ENDTRACK: + UpdateLayout(GetParent(hListView)); + return TRUE; + } + break; + } + + return CallWindowProc(g_PrevLvProc, + hListView, uMsg, wParam, lParam); +} + +/***/ + void CreateListView(HWND hWnd) { @@ -203,6 +209,9 @@ CreateListView(HWND hWnd) NULL ); + g_PrevLvProc = (WNDPROC)SetWindowLongPtr(hListView, + GWLP_WNDPROC, (LONG_PTR)LvProc); + SendMessage(hListView, WM_SETFONT, (WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0)); @@ -272,6 +281,30 @@ HandleListViewNotify(HWND hWnd, LPARAM lParam) return 0; } +void +UpdateLayout(HWND hWnd) +{ + HWND hListView; + int cxColumn; + RECT rc; + static int cxVScroll = 0; + + if (cxVScroll == 0) + cxVScroll = GetSystemMetrics(SM_CXVSCROLL); + + GetClientRect(hWnd, &rc); + hListView = GetDlgItem(hWnd, IDC_LISTVIEW); + MoveWindow(hListView, 0, 0, + rc.right, rc.bottom, + TRUE); + + cxColumn = ListView_GetColumnWidth(hListView, 0); + ListView_SetColumnWidth(hListView, 1, + rc.right-cxColumn-cxVScroll); + + ListView_EnsureVisible(hListView, g_SelectedItem, TRUE); +} + /***/ void -- cgit v1.2.3