aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--win.c71
1 files 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