aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-02 20:10:35 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-02 20:10:35 +0200
commitae3225a4e7ef86d159fdf27834c453ffcd4da76c (patch)
treef52129b946fdebfee8ffd88bc2b90347786e6e0e /c/main.cpp
parent288f4c294ac1be89b151a3f96eb9d5cb9d91055f (diff)
downloadEpisodeBrowser-ae3225a4e7ef86d159fdf27834c453ffcd4da76c.tar.gz
Implement draggable split.
Next step is to allow a double click to reset the split to be automatically resized.
Diffstat (limited to 'c/main.cpp')
-rw-r--r--c/main.cpp64
1 files changed, 28 insertions, 36 deletions
diff --git a/c/main.cpp b/c/main.cpp
index ebce3a6..477e750 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -4,17 +4,22 @@
#include <uxtheme.h>
#include <SWI-Prolog.h>
+#include "debug.h"
#include "resource.h"
#include "common.h"
#include "datalistview.h"
#include "episodelistview.h"
-#include "main.h"
+#include "layout.h"
#include "pl.h"
/* Looked-up constants. */
int g_bThemes;
int g_dpi = 96;
+/* Cursors. */
+HCURSOR g_hcArrow = LoadCursor(NULL, IDC_ARROW);
+HCURSOR g_hcSizeNs = LoadCursor(NULL, IDC_SIZENS);
+
/* Fonts. */
HFONT g_hfNormal;
HFONT g_hfBold;
@@ -31,6 +36,9 @@ HWND g_hWndStatus;
DataListView* g_dlv;
EpisodeListView* g_elv;
+/* Layout handlers. */
+Dragger g_dragDlv;
+
/* View settings. */
int g_bViewWatched = 1;
int g_bViewTVOriginal = 1;
@@ -38,8 +46,8 @@ char g_currentScreenwriter[64];
static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM);
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
-void WndProcMainMenu(const HWND, unsigned short);
-void WndProcContextMenu(const HWND, unsigned short);
+static void HandleMainMenu(HWND, unsigned short);
+static void HandleContextMenu(HWND, unsigned short);
static void WaitFor(const char*, const char*);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static void UpdateTheme();
@@ -98,7 +106,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hCursor = g_hcArrow;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = L"Episode Browser";
@@ -267,10 +275,10 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
const unsigned short command = LOWORD(wParam);
switch (ID_GROUP(command)) {
case IDG_MENU:
- WndProcMainMenu(hWnd, command);
+ HandleMainMenu(hWnd, command);
break;
case IDG_CTX:
- WndProcContextMenu(hWnd, command);
+ HandleContextMenu(hWnd, command);
break;
}
break;
@@ -327,6 +335,18 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)tip);
break;
}
+ case WM_LBUTTONDOWN:
+ g_dragDlv.HandleDown();
+ break;
+ case WM_SETCURSOR:
+ if (!g_dragDlv.HandleMove()) {
+ /* Use default cursor. */
+ if ((HWND)wParam == hWnd)
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ else
+ return 0;
+ }
+ return 1;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
@@ -335,7 +355,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
}
/* Process main menu commands. */
-void WndProcMainMenu(const HWND hWnd, unsigned short command)
+void HandleMainMenu(const HWND hWnd, unsigned short command)
{
switch (command) {
case IDM_FILE_EXIT:
@@ -402,7 +422,7 @@ void WndProcMainMenu(const HWND hWnd, unsigned short command)
}
/* Process context menu commands. */
-void WndProcContextMenu(const HWND, unsigned short command)
+void HandleContextMenu(const HWND, unsigned short command)
{
int cNotFound = 0;
@@ -528,34 +548,6 @@ INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wPa
return TRUE;
}
-void UpdateLayout(int w, int h)
-{
- if (!g_hWndStatus) return;
-
- RECT rc, rrStatus;
- if (w && h) rc = {0, 0, w, h};
- else require(GetClientRect(g_hWnd, &rc));
- require(GetRelativeRect(g_hWndStatus, &rrStatus));
-
- SendMessage(g_hWnd, WM_SETREDRAW, FALSE, 0);
-
- /* Resize list views. */
- const long pad = IsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */
- const long cyDlv = rrStatus.top-g_dlv->Height()-pad;
- require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad));
- require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad));
- g_dlv->ResizeColumns(rc.right-pad-pad);
- g_elv->ResizeColumns(rc.right-pad-pad);
-
- /* Resize status bar parts. */
- const int aParts[] = {rc.right-Dpi(55), rc.right};
- SendMessage(g_hWndStatus, SB_SETPARTS, (WPARAM)sizeof(aParts), (LPARAM)aParts);
-
- SendMessage(g_hWnd, WM_SETREDRAW, TRUE, 0);
- RedrawWindow(g_hWnd, NULL, NULL,
- RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
-}
-
/* Try to style application according to current Windows theme. */
void UpdateTheme()
{