aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-25 18:51:53 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-25 18:56:03 +0200
commit63a79631a1a070db670b4d0b9d5ccb8e14511acb (patch)
treef00e6422cdf46a5712e7291863f3f7cddb385468
parentaaebc0c072e515701162337d549ac964f63639be (diff)
downloadEpisodeBrowser-63a79631a1a070db670b4d0b9d5ccb8e14511acb.tar.gz
Reorganize resource IDs, message handling.
The resource IDs have been changed such that * the first (least significant) half byte represents the "group", * the second half byte represents the "subgroup", and * the third and fourth half bytes uniquely identify the resource within the group. Combined with the use of a few helper macros, this makes the message handling code a lot simpler.
-rw-r--r--c/main.cpp178
-rw-r--r--c/resource.h86
2 files changed, 120 insertions, 144 deletions
diff --git a/c/main.cpp b/c/main.cpp
index 64e6058..dd18d77 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -133,7 +133,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
(const TCHAR*)NULL,
WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
0, 0, 0, 0,
- hWnd, (HMENU)ID_STATUS, hInstance, (void*)NULL));
+ hWnd, (HMENU)IDR_STATUS, hInstance, (void*)NULL));
ShowWindow(hWnd, nCmdShow);
@@ -272,7 +272,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
break;
case WM_TIMER:
switch (wParam) {
- case IDT_TIMER:
+ case IDR_TIMER:
{
static int i = 0;
@@ -288,7 +288,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
} else {
i = 0;
g_bThread = 0;
- prefer(KillTimer(hWnd, IDT_TIMER));
+ prefer(KillTimer(hWnd, IDR_TIMER));
g_pElv->Update();
}
break;
@@ -296,6 +296,11 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
}
break;
case WM_COMMAND:
+ {
+ if (ID_GROUP((LOWORD(wParam))) == IDG_CTX)
+ goto ctx;
+
+ /* Process main menu commands. */
switch (LOWORD(wParam)) {
case IDM_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
@@ -310,8 +315,8 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
case IDM_FILE_FETCH_SCREENWRITERS:
if (g_bThread) break;
Pl("episode_data","thread_create","update_screenwriters",&g_aThread);
- t: KillTimer(hWnd, IDT_TIMER);
- if (!prefer(SetTimer(hWnd, IDT_TIMER, 500, (TIMERPROC)NULL))) break;
+ t: KillTimer(hWnd, IDR_TIMER);
+ if (!prefer(SetTimer(hWnd, IDR_TIMER, 500, (TIMERPROC)NULL))) break;
SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)TEXT("."));
g_bThread = 1;
break;
@@ -365,120 +370,71 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
g_pElv->Update();
g_pElv->EnsureFocusVisible();
break;
- case IDM_WATCH_LOCALLY:
- case IDM_WATCH_ONLINE:
- case IDM_TOGGLE:
- case IDM_FORGET:
- case IDM_LOOKUP:
- case IDM_WIKI:
- case IDM_RATE10:
- case IDM_RATE9:
- case IDM_RATE8:
- case IDM_RATE7:
- case IDM_RATE6:
- case IDM_RATE5:
- case IDM_RATE4:
- case IDM_RATE3:
- case IDM_RATE2:
- case IDM_RATE1:
- case IDM_RATE0:
- {
- int iRating;
- LVITEM lvi;
+ }
+ break;
+
+ /* Process context menu commands. */
+ ctx:
+ int cNotFound = 0;
+ LVITEM lvi;
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = -1;
+ while ((lvi.iItem = ListView_GetNextItem(
+ g_pElv->hWnd, lvi.iItem, LVNI_SELECTED)) != -1) {
/* Look through selected items, applying the
* selected command to each one. */
- lvi.mask = LVIF_PARAM;
- lvi.iItem = -1;
- while ((lvi.iItem = ListView_GetNextItem(
- g_pElv->hWnd, lvi.iItem, LVNI_SELECTED)) != -1) {
- if (!ListView_GetItem(g_pElv->hWnd, &lvi)) goto b;
-
- switch (LOWORD(wParam)) {
- case IDM_WATCH_LOCALLY:
- if (!Pl("local_episode","open_episode_locally",lvi.lParam))
- EBMessageBox(TEXT("Local episode could not be opened."),
- TEXT("Error"), MB_ICONWARNING);
- break;
- case IDM_WATCH_ONLINE:
- Pl("local_episode","open_episode_online",lvi.lParam);
- break;
- case IDM_TOGGLE:
- Pl("track_episodes","toggle_episode",lvi.lParam);
- g_pElv->Redraw();
- break;
- case IDM_FORGET:
- Pl("track_episodes","forget_episode",lvi.lParam);
- Pl("track_episodes","update_tracked_episodes");
- g_pElv->Redraw();
- break;
- case IDM_LOOKUP:
- Pl("episode_data","retract_episode",lvi.lParam);
- g_pElv->UpdateItem(&lvi);
- g_pElv->Redraw();
- g_pDlv->ShowEpisode(lvi.lParam);
- break;
- case IDM_WIKI:
- Pl("episode_data","open_episode_wiki",lvi.lParam);
- break;
- case IDM_RATE10:
- iRating = 10;
- goto r;
- case IDM_RATE9:
- iRating = 9;
- goto r;
- case IDM_RATE8:
- iRating = 8;
- goto r;
- case IDM_RATE7:
- iRating = 7;
- goto r;
- case IDM_RATE6:
- iRating = 6;
- goto r;
- case IDM_RATE5:
- iRating = 5;
- goto r;
- case IDM_RATE4:
- iRating = 4;
- goto r;
- case IDM_RATE3:
- iRating = 3;
- goto r;
- case IDM_RATE2:
- iRating = 2;
- goto r;
- case IDM_RATE1:
- iRating = 1;
- goto r;
- case IDM_RATE0:
- iRating = 0;
- r: Pl("episode_data","rate_episode",lvi.lParam,iRating);
- g_pElv->UpdateItem(&lvi);
- break;
- }
+ if (!ListView_GetItem(g_pElv->hWnd, &lvi)) goto b;
+
+ /* Process rate command. */
+ if (ID_SUBGROUP(LOWORD(wParam)) == IDG_CTX_RATE) {
+ Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(LOWORD(wParam)));
+ g_pElv->UpdateItem(&lvi);
+ continue;
}
+
+ /* Process other commands. */
switch (LOWORD(wParam)) {
- case IDM_RATE10:
- case IDM_RATE9:
- case IDM_RATE8:
- case IDM_RATE7:
- case IDM_RATE6:
- case IDM_RATE5:
- case IDM_RATE4:
- case IDM_RATE3:
- case IDM_RATE2:
- case IDM_RATE1:
- case IDM_RATE0:
- g_pElv->Redraw();
- g_pElv->Sort();
- g_pElv->ShowFocus();
+ case IDM_WATCH_LOCALLY:
+ if (!Pl("local_episode","open_episode_locally",lvi.lParam))
+ cNotFound++;
+ break;
+ case IDM_WATCH_ONLINE:
+ Pl("local_episode","open_episode_online",lvi.lParam);
+ break;
+ case IDM_TOGGLE:
+ Pl("track_episodes","toggle_episode",lvi.lParam);
+ break;
+ case IDM_FORGET:
+ Pl("track_episodes","forget_episode",lvi.lParam);
+ Pl("track_episodes","update_tracked_episodes");
+ break;
+ case IDM_LOOKUP:
+ Pl("episode_data","retract_episode",lvi.lParam);
+ g_pElv->UpdateItem(&lvi);
+ g_pDlv->ShowEpisode(lvi.lParam);
+ break;
+ case IDM_WIKI:
+ Pl("episode_data","open_episode_wiki",lvi.lParam);
+ break;
}
- b: break;
- }
}
- break;
+
+ g_pElv->Redraw();
+ if (cNotFound == 1) {
+ EBMessageBox(TEXT("Episode could not be opened locally."),
+ TEXT("Error"), MB_ICONWARNING);
+ } else if (cNotFound) {
+ std::basic_ostringstream<TCHAR> tss;
+ tss << cNotFound << TEXT(" episodes could not be opened locally.");
+ EBMessageBox(tss.str().c_str(), TEXT("Error"), MB_ICONWARNING);
+ } else if (ID_SUBGROUP(LOWORD(wParam)) == IDG_CTX_RATE) {
+ g_pElv->Sort();
+ g_pElv->ShowFocus();
+ }
+ b: break;
+ }
case WM_MENUSELECT:
switch (LOWORD(wParam)) {
#define TIP(s) SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)(s));
diff --git a/c/resource.h b/c/resource.h
index 9b2a1ae..b968282 100644
--- a/c/resource.h
+++ b/c/resource.h
@@ -1,38 +1,58 @@
#ifndef RESOURCE_H
#define RESOURCE_H
-#define ID_STATUS 11
-#define IDT_TIMER 21
-#define IDR_MENU 101
-#define IDR_POPUPMENU 102
-#define IDD_ABOUT 201
-#define IDC_ABOUTTEXT 301
-#define IDC_EPISODELISTVIEW 302
-#define IDC_DATALISTVIEW 303
-#define IDM_FILE_EXIT 401
-#define IDM_FILE_REFRESH 402
-#define IDM_FILE_FETCH_DATA 403
-#define IDM_FILE_FETCH_SCREENWRITERS 404
-#define IDM_FILE_ABOUT 411
-#define IDM_VIEW_WATCHED 421
-#define IDM_VIEW_TV_ORIGINAL 422
-#define IDM_VIEW_OTHERS 423
-#define IDM_WATCH_LOCALLY 501
-#define IDM_WATCH_ONLINE 502
-#define IDM_TOGGLE 503
-#define IDM_FORGET 504
-#define IDM_LOOKUP 505
-#define IDM_WIKI 506
-#define IDM_RATE10 525
-#define IDM_RATE9 526
-#define IDM_RATE8 527
-#define IDM_RATE7 528
-#define IDM_RATE6 529
-#define IDM_RATE5 530
-#define IDM_RATE4 531
-#define IDM_RATE3 532
-#define IDM_RATE2 533
-#define IDM_RATE1 534
-#define IDM_RATE0 535
+/* Resource groups. */
+#define ID_GROUP(i) ((i) & 0x000f)
+#define IDG_RES 0x1
+#define IDG_CTL 0x2
+#define IDG_MENU 0x3
+#define IDG_CTX 0x4
+
+/* Subgroups. */
+#define ID_SUBGROUP(i) ((i) & 0x00f0)
+#define IDG_CTX_RATE 0x10
+
+/* Resources, timers, menus. */
+#define IDR_STATUS 0x0001
+#define IDR_TIMER 0x0101
+#define IDR_MENU 0x0201
+#define IDR_POPUPMENU 0x0301
+
+/* Dialogs, controls, child windows. */
+#define IDD_ABOUT 0x0002
+#define IDC_ABOUTTEXT 0x0102
+#define IDC_EPISODELISTVIEW 0x0202
+#define IDC_DATALISTVIEW 0x0302
+
+/* Main menu items. */
+#define IDM_FILE_EXIT 0x0003
+#define IDM_FILE_REFRESH 0x0103
+#define IDM_FILE_FETCH_DATA 0x0203
+#define IDM_FILE_FETCH_SCREENWRITERS 0x0303
+#define IDM_FILE_ABOUT 0x0403
+#define IDM_VIEW_WATCHED 0x0503
+#define IDM_VIEW_TV_ORIGINAL 0x0603
+#define IDM_VIEW_OTHERS 0x0703
+
+/* Context menu items. */
+#define IDM_WATCH_LOCALLY 0x0004
+#define IDM_WATCH_ONLINE 0x0104
+#define IDM_TOGGLE 0x0204
+#define IDM_FORGET 0x0304
+#define IDM_LOOKUP 0x0404
+#define IDM_WIKI 0x0504
+#define IDM_RATE0 0x0614
+#define IDM_RATE1 0x0714
+#define IDM_RATE2 0x0814
+#define IDM_RATE3 0x0914
+#define IDM_RATE4 0x0a14
+#define IDM_RATE5 0x0b14
+#define IDM_RATE6 0x0c14
+#define IDM_RATE7 0x0d14
+#define IDM_RATE8 0x0e14
+#define IDM_RATE9 0x0f14
+#define IDM_RATE10 0x1014
+
+#define ID_RATING(i) (((i) - IDM_RATE0) >> 8)
#endif