diff options
author | John Ankarström <john@ankarstrom.se> | 2022-09-02 20:16:04 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-09-02 20:16:18 +0200 |
commit | bc4cef92d8efbf97a9215122abc2d7247c287f12 (patch) | |
tree | a5ca307281c4f143b5f172428c9fd2b629d6b426 /c/main.cpp | |
parent | 5c1c2ce2bdbf9735ad8a4d162609a8c22a4f0954 (diff) | |
download | EpisodeBrowser-bc4cef92d8efbf97a9215122abc2d7247c287f12.tar.gz |
Improve Window object.
Diffstat (limited to 'c/main.cpp')
-rw-r--r-- | c/main.cpp | 79 |
1 files changed, 49 insertions, 30 deletions
@@ -4,14 +4,14 @@ #include <commctrl.h> #include <libxml/xmlversion.h> -#include "debug.h" -#include "resource.h" #include "datalistview.h" +#include "debug.h" +#include "drag.h" #include "episodelistview.h" -#include "layout.h" -#include "main.h" +#include "resource.h" #include "test.h" #include "util.h" +#include "window.h" #ifdef _DEBUG #define XMAIN 30 @@ -21,10 +21,6 @@ #define YMAIN CW_USEDEFAULT #endif -/* main.cpp defines all global (non-template) variables used in the - * program. `extern' is used to access them from other files, when - * need be. */ - /* Looked-up constants. */ int g_dpi = 96; @@ -36,26 +32,19 @@ HFONT g_hfBold; HCURSOR g_hcArrow = LoadCursorW(nullptr, IDC_ARROW); HCURSOR g_hcSizeNs = LoadCursorW(nullptr, IDC_SIZENS); -/* Menus. */ -HMENU g_hMenuPopup; - -/* Windows. */ -HWND g_hWndFocus; -HWND g_hWndStatus; +/* Main window object. */ +Window* g_window; /* Optional Windows functions. */ BOOL (__stdcall *IsThemeActive)(); HRESULT (__stdcall *SetWindowTheme)(HWND, const wchar_t*, const wchar_t*); -/* Main window object. */ -Window* g_window; - /* Initialize important global state on parent window creation. */ static void InitializeMainWindow(HWND) noexcept; /* Process parent window commands. */ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Handle messages to Help > About dialog. */ -INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); +static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( _In_ const HINSTANCE hInstance, @@ -99,7 +88,7 @@ int WINAPI WinMain( XMAIN, YMAIN, 0, 0, nullptr, nullptr, hInstance, nullptr)); - g_hWndStatus = Require(CreateWindowExW( + g_window->hWndStatus = Require(CreateWindowExW( 0, STATUSCLASSNAME, nullptr, @@ -115,7 +104,7 @@ int WINAPI WinMain( g_window->elv.RestoreFocus(); #ifdef _DEBUG - RunTests(); + RunTests(*g_window); #endif MSG msg; @@ -167,10 +156,6 @@ static void InitializeMainWindow_(const HWND hWnd) SetWindowTheme = (decltype(SetWindowTheme))(void*)GetProcAddress(hModule, "SetWindowTheme"); } - /* Load context menu. */ - g_hMenuPopup = Require(LoadMenuW(nullptr, MAKEINTRESOURCE(IDR_POPUPMENU))); - g_hMenuPopup = Require(GetSubMenu(g_hMenuPopup, 0)); - g_window = new Window(hWnd); } @@ -235,7 +220,7 @@ LRESULT CALLBACK Window::WndProc(const HWND hWnd, const UINT uMsg, const WPARAM return 0; case WM_SIZE: - SendMessage(g_hWndStatus, WM_SIZE, wParam, lParam); + SendMessage(hWndStatus, WM_SIZE, wParam, lParam); UpdateLayout(LOWORD(lParam), HIWORD(lParam)); return 0; @@ -272,9 +257,9 @@ LRESULT CALLBACK Window::WndProc(const HWND hWnd, const UINT uMsg, const WPARAM case WM_ACTIVATE: if (wParam == WA_INACTIVE) - g_hWndFocus = GetFocus(); + hWndFocus = GetFocus(); else { - SetFocus(g_hWndFocus); + SetFocus(hWndFocus); /* TODO: Update tracked episodes. */ elv.Redraw(); } @@ -387,16 +372,16 @@ void Window::HandleMainMenu(const HWND hWnd, const WORD command) case IDM_FILE_FETCH_DATA: { - WaitFor(FetchData); + WaitFor(*this, FetchData); break; } case IDM_FILE_FETCH_SCREENWRITERS: - WaitFor(FetchScreenwriters); + WaitFor(*this, FetchScreenwriters); break; case IDM_FILE_FETCH_CANCEL: - WaitFor(nullptr); + WaitFor(*this, nullptr); break; case IDM_FILE_ABOUT: @@ -441,6 +426,40 @@ void Window::HandleMainMenu(const HWND hWnd, const WORD command) } } +void Window::Status(const wchar_t* msg, unsigned short i) +{ + SendMessage(hWndStatus, SB_SETTEXT, MAKEWPARAM(i, 0), reinterpret_cast<LPARAM>(msg)); +} + +void Window::UpdateLayout(int w, int h) +{ + if (!hWndStatus) return; + + RECT rc, rrStatus; + if (w && h) rc = {0, 0, w, h}; + else Require(GetClientRect(hWnd, &rc)); + Require(GetRelativeRect(hWndStatus, &rrStatus)); + + SendMessageW(hWnd, WM_SETREDRAW, FALSE, 0); + + /* Resize list views. */ + const long pad = EBIsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */ + const long cyDlv = rrStatus.top-dlv.Height()-pad; + Require(SetWindowRect(dlv.hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad)); + Require(SetWindowRect(elv.hWnd, pad, pad, rc.right-pad, cyDlv-pad)); + dlv.ResizeColumns(rc.right-pad-pad); + elv.ResizeColumns(rc.right-pad-pad); + + /* Resize status bar parts. */ + const int aParts[] = {rc.right-Dpi(55), rc.right}; + SendMessageW(hWndStatus, SB_SETPARTS, + sizeof(aParts), reinterpret_cast<LPARAM>(aParts)); + + SendMessageW(hWnd, WM_SETREDRAW, TRUE, 0); + RedrawWindow(hWnd, nullptr, nullptr, + RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN); +} + void Window::UpdateTheme() { if (IsThemeActive) { |