diff options
-rw-r--r-- | c/main.cpp | 279 |
1 files changed, 144 insertions, 135 deletions
@@ -43,6 +43,8 @@ char g_szLimitScreenwriter[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 INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static void UpdateTheme(); @@ -296,145 +298,15 @@ 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); - break; - case IDM_FILE_REFRESH: - g_pElv->Update(); + switch (ID_GROUP((LOWORD(wParam)))) { + case IDG_MENU: + WndProcMainMenu(hWnd, LOWORD(wParam)); break; - case IDM_FILE_FETCH_DATA: - if (g_bThread) break; - Pl("episode_data","thread_create","update_episode_data",&g_aThread); - goto t; - case IDM_FILE_FETCH_SCREENWRITERS: - if (g_bThread) break; - Pl("episode_data","thread_create","update_screenwriters",&g_aThread); - 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; - case IDM_FILE_ABOUT: - DialogBox( - GetModuleHandle(NULL), - MAKEINTRESOURCE(IDD_ABOUT), - hWnd, - AboutDlgProc - ); - break; - case IDM_VIEW_WATCHED: - CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, - g_bViewWatched? MF_UNCHECKED: MF_CHECKED); - g_bViewWatched = !g_bViewWatched; - Pl("cfg","set_view_watched",g_bViewWatched); - g_pElv->Update(); - g_pElv->EnsureFocusVisible(); - break; - case IDM_VIEW_TV_ORIGINAL: - CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, - g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED); - g_bViewTVOriginal = !g_bViewTVOriginal; - Pl("cfg","set_view_tv_original",g_bViewTVOriginal); - g_pElv->Update(); - g_pElv->EnsureFocusVisible(); - break; - case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */ - if (g_szLimitScreenwriter[0]) { - CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, - MF_CHECKED); - g_szLimitScreenwriter[0] = 0; - } else { - const int iEpFocus = ListView_GetNextItem(g_pElv->hWnd, -1, LVNI_FOCUSED); - if (iEpFocus == -1) break; - - LVITEM lvi; - lvi.iItem = iEpFocus; - lvi.mask = LVIF_PARAM; - if (!ListView_GetItem(g_pElv->hWnd, &lvi)) break; - - char* sz; - if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz)) - break; - strcpy_s(g_szLimitScreenwriter, - sizeof(g_szLimitScreenwriter), sz); - CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, - MF_UNCHECKED); - } - Pl("cfg","set_limit_screenwriter",g_szLimitScreenwriter); - g_pElv->Update(); - g_pElv->EnsureFocusVisible(); + case IDG_CTX: + WndProcContextMenu(hWnd, LOWORD(wParam)); break; } 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. */ - - 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_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; - } - } - - 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)); @@ -490,6 +362,143 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, return 0; } +/* Process main menu commands. */ +void WndProcMainMenu(const HWND hWnd, unsigned short wCommand) +{ + switch (wCommand) { + case IDM_FILE_EXIT: + PostMessage(hWnd, WM_CLOSE, 0, 0); + break; + case IDM_FILE_REFRESH: + g_pElv->Update(); + break; + case IDM_FILE_FETCH_DATA: + if (g_bThread) break; + Pl("episode_data","thread_create","update_episode_data",&g_aThread); + goto t; + case IDM_FILE_FETCH_SCREENWRITERS: + if (g_bThread) break; + Pl("episode_data","thread_create","update_screenwriters",&g_aThread); + 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; + case IDM_FILE_ABOUT: + DialogBox( + GetModuleHandle(NULL), + MAKEINTRESOURCE(IDD_ABOUT), + hWnd, + AboutDlgProc + ); + break; + case IDM_VIEW_WATCHED: + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, + g_bViewWatched? MF_UNCHECKED: MF_CHECKED); + g_bViewWatched = !g_bViewWatched; + Pl("cfg","set_view_watched",g_bViewWatched); + g_pElv->Update(); + g_pElv->EnsureFocusVisible(); + break; + case IDM_VIEW_TV_ORIGINAL: + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, + g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED); + g_bViewTVOriginal = !g_bViewTVOriginal; + Pl("cfg","set_view_tv_original",g_bViewTVOriginal); + g_pElv->Update(); + g_pElv->EnsureFocusVisible(); + break; + case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */ + if (g_szLimitScreenwriter[0]) { + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, + MF_CHECKED); + g_szLimitScreenwriter[0] = 0; + } else { + const int iEpFocus = ListView_GetNextItem(g_pElv->hWnd, -1, LVNI_FOCUSED); + if (iEpFocus == -1) break; + + LVITEM lvi; + lvi.iItem = iEpFocus; + lvi.mask = LVIF_PARAM; + if (!ListView_GetItem(g_pElv->hWnd, &lvi)) break; + + char* sz; + if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz)) + break; + strcpy_s(g_szLimitScreenwriter, + sizeof(g_szLimitScreenwriter), sz); + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, + MF_UNCHECKED); + } + Pl("cfg","set_limit_screenwriter",g_szLimitScreenwriter); + g_pElv->Update(); + g_pElv->EnsureFocusVisible(); + break; + } +} + +/* Process context menu commands. */ +void WndProcContextMenu(const HWND, unsigned short wCommand) +{ + LVITEM lvi; + int cNotFound = 0; + + /* 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 + && ListView_GetItem(g_pElv->hWnd, &lvi)) { + + /* Process rate commands. */ + if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) { + Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(wCommand)); + g_pElv->UpdateItem(&lvi); + continue; + } + + /* Process other commands. */ + switch (wCommand) { + 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; + } + } + + 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(wCommand) == IDG_CTX_RATE) { + g_pElv->Sort(); + g_pElv->ShowFocus(); + } +} + /* Handle messages to Help > About dialog. */ INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM) { |