aboutsummaryrefslogtreecommitdiff
path: root/c/listview.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-10 23:23:09 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-10 23:25:09 +0200
commit295d423cc47f9ee8a72134dc544892a03b279311 (patch)
tree3e89b0bbcf42b3053225eb0dff88b887dd16df48 /c/listview.cpp
parent85a4ad2c184ed915915a2fb630415a80ed9a286f (diff)
downloadEpisodeBrowser-295d423cc47f9ee8a72134dc544892a03b279311.tar.gz
Convert to C++.
I already hit upon some object-oriented programming patterns in *listview.c, so I felt that it would be natural to use this as an opportunity to learn C++.
Diffstat (limited to 'c/listview.cpp')
-rw-r--r--c/listview.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/c/listview.cpp b/c/listview.cpp
new file mode 100644
index 0000000..9f24dc3
--- /dev/null
+++ b/c/listview.cpp
@@ -0,0 +1,76 @@
+#include <windows.h>
+#include <commctrl.h>
+#include <uxtheme.h>
+
+#include "resource.h"
+#include "defs.h"
+
+extern HFONT g_hfNormal;
+extern HWND g_hWnd;
+static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+
+void
+ListView::Create(HMENU hMenu, DWORD dwStyle)
+{
+ m_hWnd = CreateWindowEx(
+ WS_EX_CLIENTEDGE,
+ WC_LISTVIEW,
+ TEXT(""),
+ dwStyle
+ |WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS,
+ 0, 0, 0, 0,
+ g_hWnd, hMenu, GetModuleHandle(NULL), this
+ );
+
+ if (SetProp(m_hWnd, TEXT("this"), (HANDLE)this))
+ m_prevProc = (WNDPROC)SetWindowLongPtr(m_hWnd,
+ GWLP_WNDPROC, (LONG_PTR)::WndProc);
+
+ ListView_SetExtendedListViewStyle(m_hWnd, LVS_EX_FULLROWSELECT);
+
+ SendMessage(m_hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0));
+}
+
+/* Naively calculate height of list view. */
+int
+ListView::Height(int bHeader)
+{
+ int iCount;
+ iCount = ListView_GetItemCount(m_hWnd);
+ return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0;
+}
+
+HWND
+ListView::HWnd()
+{
+ return m_hWnd;
+}
+
+LRESULT CALLBACK
+ListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->code) {
+ case HDN_ENDTRACK:
+ UpdateLayout();
+ return TRUE;
+ }
+ break;
+ }
+
+ return CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
+}
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_DESTROY:
+ RemoveProp(hWnd, TEXT("this"));
+ break;
+ }
+
+ ListView *lpThis = (ListView *)GetProp(hWnd, TEXT("this"));
+ return lpThis? lpThis->WndProc(hWnd, uMsg, wParam, lParam): FALSE;
+}