diff options
-rw-r--r-- | c/episodelistview.c | 25 | ||||
-rw-r--r-- | c/main.c | 105 | ||||
-rw-r--r-- | c/resource.h | 33 | ||||
-rw-r--r-- | c/resource.rc | 32 |
4 files changed, 112 insertions, 83 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index f533d4f..14fc6b9 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -170,7 +170,9 @@ ElvUpdate() LVITEM lvi, lviEpisode, lviTop; LVFINDINFO lvfi; term_t t; - static int rgEpSel[2048]; + extern HWND HWndStatus; + static TCHAR tszDisp[16], tszEpisode[16], tszTotal[16]; + static int aEpSel[2048]; lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; @@ -187,9 +189,9 @@ ElvUpdate() HElv, lvi.iItem, LVNI_SELECTED)) != -1 && i < 2048) { if (!ListView_GetItem(HElv, &lvi)) continue; - rgEpSel[i++] = lvi.lParam; + aEpSel[i++] = lvi.lParam; } - rgEpSel[i] = 0; + aEpSel[i] = 0; /* Save focus. */ iEpFocus = 0; @@ -208,8 +210,6 @@ ElvUpdate() GI(t,&cEp) return; for (iEp = 1, iItem = 0; iEp <= cEp; iEp++) { - int cb; - TCHAR *tszEpisode; extern int BViewTVOriginal, BViewWatched; if (!BViewWatched) { @@ -229,10 +229,7 @@ ElvUpdate() } /* Format episode number string. */ - ep: cb = 100; - tszEpisode = malloc(cb*sizeof(TCHAR)); - if (!tszEpisode) continue; - _stprintf_s(tszEpisode, cb, TEXT("%d"), iEp); + ep: _stprintf_s(tszEpisode, sizeof(tszEpisode), TEXT("%d"), iEp); /* Insert item. */ lviEpisode.iItem = iItem++; @@ -241,8 +238,6 @@ ElvUpdate() lviEpisode.lParam = iEp; ListView_InsertItem(HElv, &lviEpisode); ElvUpdateItem(&lviEpisode); - - free(tszEpisode); } lvfi.flags = LVFI_PARAM; @@ -257,9 +252,9 @@ ElvUpdate() ElvSetTop(iItemTopNew); /* Reset selection. */ - for (i = 0; rgEpSel[i]; i++) { + for (i = 0; aEpSel[i]; i++) { int iSel; - lvfi.lParam = rgEpSel[i]; + lvfi.lParam = aEpSel[i]; if ((iSel = ListView_FindItem(HElv, -1, &lvfi)) != -1) ListView_SetItemState(HElv, iSel, LVIS_SELECTED, LVIS_SELECTED); @@ -278,6 +273,10 @@ ElvUpdate() LVIS_FOCUSED, LVIS_FOCUSED); } + _stprintf_s(tszDisp, sizeof(tszDisp), TEXT("%d"), iItem); + SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)tszDisp); + _stprintf_s(tszTotal, sizeof(tszTotal), TEXT("%d"), cEp); + SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(2,0), (LPARAM)tszTotal); SendMessage(HElv, WM_SETREDRAW, TRUE, 0); ElvRedraw(); } @@ -11,6 +11,7 @@ HFONT HfBold; HMENU HPopupMenu; HWND HFocus; HWND HWnd; +HWND HWndStatus; int BViewTVOriginal = 1; int BViewWatched = 1; int IDPI = -1; @@ -18,6 +19,7 @@ static int BThemes; static int CxVScroll; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); +static HWND CreateStatusBar(HWND, HINSTANCE); static int Attach(void); static void SetupFonts(void); static void UpdateTheme(void); @@ -82,6 +84,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, ); tszErr = TEXT("Could not create main window."); if (!hWnd) goto f; + HWndStatus = CreateStatusBar(hWnd, hInstance); ShowWindow(hWnd, nCmdShow); /* Populate episode list view. */ @@ -125,18 +128,18 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) t = T(1); P("cfg","get_view_watched",1,t) goto s; GI(t,&BViewWatched); - CheckMenuItem(GetMenu(hWnd), ID_VIEW_WATCHED, + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, BViewWatched? MF_CHECKED: MF_UNCHECKED); } - { + s: { term_t t; t = T(1); - P("cfg","get_view_tv_original",1,t) goto s; + P("cfg","get_view_tv_original",1,t) goto t; GI(t,&BViewTVOriginal); - CheckMenuItem(GetMenu(hWnd), ID_VIEW_TV_ORIGINAL, + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, BViewTVOriginal? MF_CHECKED: MF_UNCHECKED); } - s: SetupFonts(); + t: SetupFonts(); DlvCreate(); ElvCreate(); UpdateTheme(); @@ -150,6 +153,7 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) PostQuitMessage(0); break; case WM_SIZE: + SendMessage(HWndStatus, WM_SIZE, wParam, lParam); UpdateLayout(); break; case WM_GETMINMAXINFO: @@ -199,16 +203,16 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_COMMAND: switch (LOWORD(wParam)) { - case ID_FILE_EXIT: + case IDM_FILE_EXIT: PostMessage(hWnd, WM_CLOSE, 0, 0); break; - case ID_FILE_REFRESH: + case IDM_FILE_REFRESH: ElvUpdate(); break; - case ID_FILE_RESET: + case IDM_FILE_RESET: ElvSelectRecent(); break; - case ID_FILE_ABOUT: + case IDM_FILE_ABOUT: DialogBox( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), @@ -216,10 +220,10 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) AboutDlgProc ); break; - case ID_VIEW_WATCHED: + case IDM_VIEW_WATCHED: { term_t t; - CheckMenuItem(GetMenu(hWnd), ID_VIEW_WATCHED, + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, BViewWatched? MF_UNCHECKED: MF_CHECKED); BViewWatched = !BViewWatched; ElvUpdate(); @@ -228,10 +232,10 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) P("cfg","set_view_watched",1,t); break; } - case ID_VIEW_TV_ORIGINAL: + case IDM_VIEW_TV_ORIGINAL: { term_t t; - CheckMenuItem(GetMenu(hWnd), ID_VIEW_TV_ORIGINAL, + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, BViewTVOriginal? MF_UNCHECKED: MF_CHECKED); BViewTVOriginal = !BViewTVOriginal; ElvUpdate(); @@ -240,16 +244,16 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) P("cfg","set_view_tv_original",1,t); break; } - case ID_WATCH: - case ID_TOGGLE: - case ID_FORGET: - case ID_LOOKUP: - case ID_RATE5: - case ID_RATE4: - case ID_RATE3: - case ID_RATE2: - case ID_RATE1: - case ID_RATE0: + case IDM_WATCH: + case IDM_TOGGLE: + case IDM_FORGET: + case IDM_LOOKUP: + case IDM_RATE5: + case IDM_RATE4: + case IDM_RATE3: + case IDM_RATE2: + case IDM_RATE1: + case IDM_RATE0: { LVITEM lvi; term_t t; @@ -267,40 +271,40 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) PI(t,lvi.lParam) goto b; switch (LOWORD(wParam)) { - case ID_WATCH: + case IDM_WATCH: P("local_episode","open_episode",1,t); break; - case ID_TOGGLE: + case IDM_TOGGLE: P("track_episodes","toggle_episode",1,t); ElvRedraw(); break; - case ID_FORGET: + case IDM_FORGET: P("track_episodes","forget_episode",1,t); P("track_episodes","update_tracked_episodes",0,t); ElvRedraw(); break; - case ID_LOOKUP: + case IDM_LOOKUP: P("episode_data","retract_episode",1,t); ElvUpdateItem(&lvi); ElvRedraw(); DlvShowEpisode(lvi.lParam); break; - case ID_RATE5: + case IDM_RATE5: PI(t+1,5) break; goto r; - case ID_RATE4: + case IDM_RATE4: PI(t+1,4) break; goto r; - case ID_RATE3: + case IDM_RATE3: PI(t+1,3) break; goto r; - case ID_RATE2: + case IDM_RATE2: PI(t+1,2) break; goto r; - case ID_RATE1: + case IDM_RATE1: PI(t+1,1) break; goto r; - case ID_RATE0: + case IDM_RATE0: PI(t+1,0) break; r: P("episode_data","rate_episode",2,t); ElvUpdateItem(&lvi); @@ -340,6 +344,24 @@ AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } +HWND +CreateStatusBar(HWND hWndParent, HINSTANCE hInstance) +{ + HWND hWnd; + hWnd = CreateWindowEx( + 0, + STATUSCLASSNAME, + (LPCTSTR) NULL, + WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, + 0, 0, 0, 0, + hWndParent, + (HMENU)ID_STATUS, + hInstance, + NULL + ); + return hWnd; +} + /***/ /* Attach persistent databases. */ @@ -380,16 +402,18 @@ SetupFonts() void UpdateLayout() { - int cxColumn, cyDlv; - RECT rc; + int cxColumn, cyDlv, yStatus; + RECT rc, rcStatus; extern HWND HDlv, HElv; GetClientRect(HWnd, &rc); + GetClientRect(HWndStatus, &rcStatus); + yStatus = rcStatus.bottom-rcStatus.top; /* Resize data list view. */ SendMessage(HDlv, WM_SETREDRAW, FALSE, 0); - cyDlv = rc.bottom - LvHeight(HDlv, 0); - MoveWindow(HDlv, 0, cyDlv, rc.right, rc.bottom, TRUE); + cyDlv = rc.bottom-yStatus-LvHeight(HDlv, 0); + MoveWindow(HDlv, 0, cyDlv, rc.right, rc.bottom-yStatus-cyDlv, TRUE); ListView_SetColumnWidth(HDlv, 0, LVSCW_AUTOSIZE); cxColumn = ListView_GetColumnWidth(HDlv, 0)+4; ListView_SetColumnWidth(HDlv, 0, cxColumn); @@ -406,7 +430,12 @@ UpdateLayout() ListView_SetColumnWidth(HElv, 2, rc.right-cxColumn-CxVScroll-4); SendMessage(HElv, WM_SETREDRAW, TRUE, 0); -#undef SETCOLW + /* Resize status bar parts. */ + { + int aParts[] = {rc.right-Dpi(100), rc.right-Dpi(50), rc.right}; + SendMessage(HWndStatus, SB_SETPARTS, + (WPARAM)sizeof(aParts), (LPARAM)aParts); + } } /* Try to style application according to current Windows theme. */ diff --git a/c/resource.h b/c/resource.h index b60432a..c251144 100644 --- a/c/resource.h +++ b/c/resource.h @@ -1,27 +1,28 @@ #ifndef RESOURCE_H #define RESOURCE_H +#define ID_STATUS 11 #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 ID_FILE_EXIT 401 -#define ID_FILE_REFRESH 402 -#define ID_FILE_RESET 403 -#define ID_FILE_ABOUT 411 -#define ID_VIEW_WATCHED 421 -#define ID_VIEW_TV_ORIGINAL 422 -#define ID_WATCH 501 -#define ID_TOGGLE 502 -#define ID_FORGET 503 -#define ID_LOOKUP 504 -#define ID_RATE5 525 -#define ID_RATE4 526 -#define ID_RATE3 527 -#define ID_RATE2 528 -#define ID_RATE1 529 -#define ID_RATE0 530 +#define IDM_FILE_EXIT 401 +#define IDM_FILE_REFRESH 402 +#define IDM_FILE_RESET 403 +#define IDM_FILE_ABOUT 411 +#define IDM_VIEW_WATCHED 421 +#define IDM_VIEW_TV_ORIGINAL 422 +#define IDM_WATCH 501 +#define IDM_TOGGLE 502 +#define IDM_FORGET 503 +#define IDM_LOOKUP 504 +#define IDM_RATE5 525 +#define IDM_RATE4 526 +#define IDM_RATE3 527 +#define IDM_RATE2 528 +#define IDM_RATE1 529 +#define IDM_RATE0 530 #endif diff --git a/c/resource.rc b/c/resource.rc index 68fdc5f..6a73e01 100644 --- a/c/resource.rc +++ b/c/resource.rc @@ -7,18 +7,18 @@ IDR_MENU MENU BEGIN POPUP "&File" BEGIN - MENUITEM "&Refresh", ID_FILE_REFRESH - MENUITEM "Re&set", ID_FILE_RESET - MENUITEM "E&xit", ID_FILE_EXIT + MENUITEM "&Refresh", IDM_FILE_REFRESH + MENUITEM "Re&set", IDM_FILE_RESET + MENUITEM "E&xit", IDM_FILE_EXIT END POPUP "&View" BEGIN - MENUITEM "&Watched", ID_VIEW_WATCHED, CHECKED - MENUITEM "&TV Originals", ID_VIEW_TV_ORIGINAL, CHECKED + MENUITEM "&Watched", IDM_VIEW_WATCHED, CHECKED + MENUITEM "&TV Originals", IDM_VIEW_TV_ORIGINAL, CHECKED END POPUP "&Help" BEGIN - MENUITEM "&About", ID_FILE_ABOUT + MENUITEM "&About", IDM_FILE_ABOUT END END @@ -26,18 +26,18 @@ IDR_POPUPMENU MENU DISCARDABLE BEGIN POPUP "Episode Menu" BEGIN - MENUITEM "&Watch", ID_WATCH - MENUITEM "&Toggle", ID_TOGGLE - MENUITEM "&Forget", ID_FORGET - MENUITEM "&Lookup", ID_LOOKUP + MENUITEM "&Watch", IDM_WATCH + MENUITEM "&Toggle", IDM_TOGGLE + MENUITEM "&Forget", IDM_FORGET + MENUITEM "&Lookup", IDM_LOOKUP POPUP "&Rate" BEGIN - MENUITEM "&5", ID_RATE5 - MENUITEM "&4", ID_RATE4 - MENUITEM "&3", ID_RATE3 - MENUITEM "&2", ID_RATE2 - MENUITEM "&1", ID_RATE1 - MENUITEM "&-", ID_RATE0 + 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 |