From 2cd22c671c67deaf2c1fcb659e3262bf57552557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 3 Sep 2022 01:15:01 +0200 Subject: Add Preferences dialog (WIP). --- c/CMakeLists.txt | 4 +-- c/data.cpp | 2 +- c/datalistview.cpp | 2 +- c/episodelistview.cpp | 2 +- c/main.cpp | 32 ++++++++++++++++-- c/res.h | 66 ++++++++++++++++++++++++++++++++++++++ c/res.rc | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ c/resource.h | 59 ---------------------------------- c/resource.rc | 71 ---------------------------------------- c/window.h | 2 +- 10 files changed, 191 insertions(+), 138 deletions(-) create mode 100644 c/res.h create mode 100644 c/res.rc delete mode 100644 c/resource.h delete mode 100644 c/resource.rc (limited to 'c') diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index cd86f08..0c8bb83 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -29,8 +29,8 @@ target_sources(EpisodeBrowser PRIVATE listview.cpp listview.h main.cpp - resource.h - resource.rc + res.h + res.rc test.cpp test.h util.h diff --git a/c/data.cpp b/c/data.cpp index 62d544a..f862a5e 100644 --- a/c/data.cpp +++ b/c/data.cpp @@ -7,7 +7,7 @@ #include "data.h" #include "episodelistview.h" -#include "resource.h" +#include "res.h" #include "util.h" #include "win32.h" #include "window.h" diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 4ed3d41..2e31d25 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -7,7 +7,7 @@ #include "datalistview.h" #include "episodelistview.h" #include "listview.h" -#include "resource.h" +#include "res.h" #include "window.h" DataListView::DataListView(Window& parent) diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 29c015b..b683114 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -8,7 +8,7 @@ #include "episodelistview.h" #include "ext.h" #include "listview.h" -#include "resource.h" +#include "res.h" #include "util.h" #include "win32.h" #include "window.h" diff --git a/c/main.cpp b/c/main.cpp index 82cda68..9e8cee3 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -8,7 +8,7 @@ #include "debug.h" #include "drag.h" #include "episodelistview.h" -#include "resource.h" +#include "res.h" #include "test.h" #include "util.h" #include "window.h" @@ -45,6 +45,8 @@ static void InitializeMainWindow(HWND) noexcept; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Handle messages to Help > About dialog. */ static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); +/* Handle messages to File > Preferences... dialog. */ +static INT_PTR CALLBACK PreferencesDlgProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( _In_ const HINSTANCE hInstance, @@ -200,6 +202,23 @@ INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wPa } } +INT_PTR CALLBACK PreferencesDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM) +{ + switch (uMsg) { + case WM_CLOSE: + EndDialog(hWnd, IDOK); + return TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK) + EndDialog(hWnd, IDOK); + return TRUE; + + default: + return FALSE; + } +} + LRESULT CALLBACK Window::WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { @@ -296,11 +315,12 @@ LRESULT CALLBACK Window::WndProc(const HWND hWnd, const UINT uMsg, const WPARAM { /* Look up status bar tip for menu command. The tip * strings are stored in arrays, whose indices - * correspond to the IDM_ values (see resource.h). */ + * correspond to the IDM_ values (see res.h). */ const wchar_t* vTipMenu[] = { /*IDM_FILE_EXIT*/L"Close Episode Browser.", /*IDM_FILE_REFRESH*/L"Quickly refresh episode list.", + /*IDM_FILE_PREFERENCES*/L"Configure Episode Browser.", /*IDM_FILE_FETCH_DATA*/L"Fetch episode data from the web (may take a few seconds).", /*IDM_FILE_FETCH_SCREENWRITERS*/L"Fetch screenwriters from the web (may take a minute).", /*IDM_FILE_FETCH_CANCEL*/L"Stop fetching data from the web.", @@ -375,6 +395,14 @@ void Window::HandleMainMenu(const HWND hWnd, const WORD command) elv.Update(); break; + case IDM_FILE_PREFERENCES: + DialogBox( + GetModuleHandle(nullptr), + MAKEINTRESOURCE(IDD_PREFERENCES), + hWnd, + PreferencesDlgProc); + break; + case IDM_FILE_FETCH_DATA: { WaitFor(*this, FetchData); diff --git a/c/res.h b/c/res.h new file mode 100644 index 0000000..a0b7f8a --- /dev/null +++ b/c/res.h @@ -0,0 +1,66 @@ +#ifndef RES_H +#define RES_H + +/* Resource groups. */ +#define ID_GROUP(i) ((i) & 0x0f00) +#define IDG_RES 0x0100 +#define IDG_CTL 0x0200 +#define IDG_MENU 0x0300 +#define IDG_CTX 0x0400 + +/* Subgroups. */ +#define ID_SUBGROUP(i) ((i) & 0xf000) +#define IDG_CTX_RATE 0x1000 + +/* Index within resource group. */ +#define ID_INDEX(i) ((i) & 0x00ff) + +/* Resources, timers, menus. */ +#define IDR_STATUS 0x0100 +#define IDR_MENU 0x0101 +#define IDR_POPUPMENU 0x0102 + +/* Dialogs, controls, child windows. */ +#define IDD_ABOUT 0x0200 +#define IDC_ABOUTTEXT 0x0201 +#define IDC_EPISODELISTVIEW 0x0202 +#define IDC_DATALISTVIEW 0x0203 +#define IDD_PREFERENCES 0x0204 +#define IDC_STATIC 0x0205 +#define IDC_BROWSE 0x0206 +#define IDC_EDIT_ROOT 0x0207 +#define IDC_EDIT_URL 0x0208 +#define IDC_EDIT_PREFIX 0x0209 + +/* Main menu items. */ +#define IDM_FILE_EXIT 0x0300 +#define IDM_FILE_REFRESH 0x0301 +#define IDM_FILE_PREFERENCES 0x0302 +#define IDM_FILE_FETCH_DATA 0x0303 +#define IDM_FILE_FETCH_SCREENWRITERS 0x0304 +#define IDM_FILE_FETCH_CANCEL 0x0305 +#define IDM_FILE_ABOUT 0x0306 +#define IDM_VIEW_WATCHED 0x0307 +#define IDM_VIEW_TV_ORIGINAL 0x0308 +#define IDM_VIEW_OTHERS 0x0309 + +/* Context menu items. */ +#define IDM_WATCH_LOCALLY 0x0400 +#define IDM_WATCH_ONLINE 0x0401 +#define IDM_TOGGLE 0x0402 +#define IDM_WIKI 0x0403 +#define IDM_RATE0 0x1404 +#define IDM_RATE1 0x1405 +#define IDM_RATE2 0x1406 +#define IDM_RATE3 0x1407 +#define IDM_RATE4 0x1408 +#define IDM_RATE5 0x1409 +#define IDM_RATE6 0x140a +#define IDM_RATE7 0x140b +#define IDM_RATE8 0x140c +#define IDM_RATE9 0x140d +#define IDM_RATE10 0x140e + +#define ID_RATING(i) ((i) - IDM_RATE0) + +#endif diff --git a/c/res.rc b/c/res.rc new file mode 100644 index 0000000..e5117a1 --- /dev/null +++ b/c/res.rc @@ -0,0 +1,89 @@ +#include +#include "res.h" + +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "application.manifest" + +IDR_MENU MENU +BEGIN + POPUP "&File" + BEGIN + POPUP "&Fetch" + BEGIN + MENUITEM "&General Data", IDM_FILE_FETCH_DATA + MENUITEM "&Screenwriters", IDM_FILE_FETCH_SCREENWRITERS + MENUITEM "&Cancel", IDM_FILE_FETCH_CANCEL, GRAYED + END + MENUITEM "&Refresh", IDM_FILE_REFRESH + MENUITEM "&Preferences...", IDM_FILE_PREFERENCES + MENUITEM "E&xit", IDM_FILE_EXIT + END + POPUP "&View" + BEGIN + MENUITEM "&Watched", IDM_VIEW_WATCHED, CHECKED + MENUITEM "&TV Originals", IDM_VIEW_TV_ORIGINAL, CHECKED + MENUITEM "Other &Screenwriters", IDM_VIEW_OTHERS, CHECKED + END + POPUP "&Help" + BEGIN + MENUITEM "&About", IDM_FILE_ABOUT + END +END + +IDR_POPUPMENU MENU DISCARDABLE +BEGIN + POPUP "Episode Menu" + BEGIN + MENUITEM "&Watch Locally", IDM_WATCH_LOCALLY + MENUITEM "Watch &Online", IDM_WATCH_ONLINE + MENUITEM "&Toggle", IDM_TOGGLE + MENUITEM "Wi&ki", IDM_WIKI + POPUP "&Rate" + BEGIN + MENUITEM "&10", IDM_RATE10 + MENUITEM "&9", IDM_RATE9 + MENUITEM "&8", IDM_RATE8 + MENUITEM "&7", IDM_RATE7 + MENUITEM "&6", IDM_RATE6 + MENUITEM "&5", IDM_RATE5 + MENUITEM "&4", IDM_RATE4 + MENUITEM "&3", IDM_RATE3 + MENUITEM "&2", IDM_RATE2 + MENUITEM "&1", IDM_RATE1 + MENUITEM "&-", IDM_RATE0 + END + END +END + +#define VPAD 7 +#define HPAD 9 +#define ABOUTW 190 +#define ABOUTH 40 +#define OKW 48 +#define OKH 16 + +IDD_ABOUT DIALOGEX DISCARDABLE 20, 20, ABOUTW, ABOUTH +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "About" +FONT 8, "MS Shell Dlg 2" +BEGIN +DEFPUSHBUTTON "&OK", IDOK, ABOUTW-OKW-HPAD, ABOUTH-OKH-VPAD, OKW, OKH +LTEXT "Episode Browser\r\nCopyright 2021 John Ankarström", +IDC_ABOUTTEXT, HPAD, VPAD, ABOUTW-OKW-HPAD-HPAD, ABOUTH-VPAD +END + +IDD_PREFERENCES DIALOGEX 20, 20, 256, 137 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTEXTHELP +CAPTION "Preferences" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,145,116,50,14 + PUSHBUTTON "Cancel",IDCANCEL,199,116,50,14 + EDITTEXT IDC_EDIT_ROOT,14,18,172,14,ES_AUTOHSCROLL,WS_EX_ACCEPTFILES + PUSHBUTTON "Browse...",IDC_BROWSE,191,18,50,14 + GROUPBOX "Root directory for local episode lookup",IDC_STATIC,7,7,242,32 + EDITTEXT IDC_EDIT_URL,14,54,227,14,ES_AUTOHSCROLL + GROUPBOX "URL for online episode lookup",IDC_STATIC,7,42,242,32 + EDITTEXT IDC_EDIT_PREFIX,14,90,227,14,ES_AUTOHSCROLL + GROUPBOX "Prefix for internal internet requests (for Windows XP compatibility)",IDC_STATIC,7,79,242,32 +END diff --git a/c/resource.h b/c/resource.h deleted file mode 100644 index db88852..0000000 --- a/c/resource.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RESOURCE_H -#define RESOURCE_H - -/* Resource groups. */ -#define ID_GROUP(i) ((i) & 0x0f00) -#define IDG_RES 0x0100 -#define IDG_CTL 0x0200 -#define IDG_MENU 0x0300 -#define IDG_CTX 0x0400 - -/* Subgroups. */ -#define ID_SUBGROUP(i) ((i) & 0xf000) -#define IDG_CTX_RATE 0x1000 - -/* Index within resource group. */ -#define ID_INDEX(i) ((i) & 0x00ff) - -/* Resources, timers, menus. */ -#define IDR_STATUS 0x0100 -#define IDR_MENU 0x0101 -#define IDR_POPUPMENU 0x0102 - -/* Dialogs, controls, child windows. */ -#define IDD_ABOUT 0x0200 -#define IDC_ABOUTTEXT 0x0201 -#define IDC_EPISODELISTVIEW 0x0202 -#define IDC_DATALISTVIEW 0x0203 - -/* Main menu items. */ -#define IDM_FILE_EXIT 0x0300 -#define IDM_FILE_REFRESH 0x0301 -#define IDM_FILE_FETCH_DATA 0x0302 -#define IDM_FILE_FETCH_SCREENWRITERS 0x0303 -#define IDM_FILE_FETCH_CANCEL 0x0304 -#define IDM_FILE_ABOUT 0x0305 -#define IDM_VIEW_WATCHED 0x0306 -#define IDM_VIEW_TV_ORIGINAL 0x0307 -#define IDM_VIEW_OTHERS 0x0308 - -/* Context menu items. */ -#define IDM_WATCH_LOCALLY 0x0400 -#define IDM_WATCH_ONLINE 0x0401 -#define IDM_TOGGLE 0x0402 -#define IDM_WIKI 0x0403 -#define IDM_RATE0 0x1404 -#define IDM_RATE1 0x1405 -#define IDM_RATE2 0x1406 -#define IDM_RATE3 0x1407 -#define IDM_RATE4 0x1408 -#define IDM_RATE5 0x1409 -#define IDM_RATE6 0x140a -#define IDM_RATE7 0x140b -#define IDM_RATE8 0x140c -#define IDM_RATE9 0x140d -#define IDM_RATE10 0x140e - -#define ID_RATING(i) ((i) - IDM_RATE0) - -#endif diff --git a/c/resource.rc b/c/resource.rc deleted file mode 100644 index f25bb63..0000000 --- a/c/resource.rc +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include "resource.h" - -CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "application.manifest" - -IDR_MENU MENU -BEGIN - POPUP "&File" - BEGIN - POPUP "&Fetch" - BEGIN - MENUITEM "&General Data", IDM_FILE_FETCH_DATA - MENUITEM "&Screenwriters", IDM_FILE_FETCH_SCREENWRITERS - MENUITEM "&Cancel", IDM_FILE_FETCH_CANCEL, GRAYED - END - MENUITEM "&Refresh", IDM_FILE_REFRESH - MENUITEM "E&xit", IDM_FILE_EXIT - END - POPUP "&View" - BEGIN - MENUITEM "&Watched", IDM_VIEW_WATCHED, CHECKED - MENUITEM "&TV Originals", IDM_VIEW_TV_ORIGINAL, CHECKED - MENUITEM "Other &Screenwriters", IDM_VIEW_OTHERS, CHECKED - END - POPUP "&Help" - BEGIN - MENUITEM "&About", IDM_FILE_ABOUT - END -END - -IDR_POPUPMENU MENU DISCARDABLE -BEGIN - POPUP "Episode Menu" - BEGIN - MENUITEM "&Watch Locally", IDM_WATCH_LOCALLY - MENUITEM "Watch &Online", IDM_WATCH_ONLINE - MENUITEM "&Toggle", IDM_TOGGLE - MENUITEM "Wi&ki", IDM_WIKI - POPUP "&Rate" - BEGIN - MENUITEM "&10", IDM_RATE10 - MENUITEM "&9", IDM_RATE9 - MENUITEM "&8", IDM_RATE8 - MENUITEM "&7", IDM_RATE7 - MENUITEM "&6", IDM_RATE6 - MENUITEM "&5", IDM_RATE5 - MENUITEM "&4", IDM_RATE4 - MENUITEM "&3", IDM_RATE3 - MENUITEM "&2", IDM_RATE2 - MENUITEM "&1", IDM_RATE1 - MENUITEM "&-", IDM_RATE0 - END - END -END - -#define VPAD 7 -#define HPAD 9 -#define ABOUTW 190 -#define ABOUTH 40 -#define OKW 48 -#define OKH 16 - -IDD_ABOUT DIALOGEX DISCARDABLE 20, 20, ABOUTW, ABOUTH -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "About" -FONT 8, "MS Shell Dlg 2" -BEGIN -DEFPUSHBUTTON "&OK", IDOK, ABOUTW-OKW-HPAD, ABOUTH-OKH-VPAD, OKW, OKH -LTEXT "Episode Browser\r\nCopyright 2021 John Ankarström", -IDC_ABOUTTEXT, HPAD, VPAD, ABOUTW-OKW-HPAD-HPAD, ABOUTH-VPAD -END \ No newline at end of file diff --git a/c/window.h b/c/window.h index 2c81194..daf7202 100644 --- a/c/window.h +++ b/c/window.h @@ -7,7 +7,7 @@ #include "datalistview.h" #include "drag.h" #include "episodelistview.h" -#include "resource.h" +#include "res.h" #include "win32.h" struct Window -- cgit v1.2.3