aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/defs.h4
-rw-r--r--c/episodelistview.cpp60
-rw-r--r--c/listview.cpp29
-rw-r--r--c/main.cpp159
4 files changed, 127 insertions, 125 deletions
diff --git a/c/defs.h b/c/defs.h
index 9f53c92..f36b8ea 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -20,6 +20,7 @@ public:
void Create(HMENU, DWORD);
int Height(int);
HWND HWnd(void);
+ virtual void UpdateTheme(BOOL);
virtual LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
};
@@ -30,8 +31,9 @@ public:
void DoSort(void);
LRESULT HandleNotify(LPARAM);
void Redraw(void);
+ void SaveFocus(void);
void SetTop(int);
- void SelectFocus(void);
+ void RestoreFocus(void);
void SelectUnwatched(int);
void ShowFocus(void);
void Update(void);
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 8fb3ec7..7c79043 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -155,6 +155,16 @@ EpisodeListView::Redraw()
}
void
+EpisodeListView::SaveFocus()
+{
+ LVITEM lvi;
+ lvi.mask = LVIF_PARAM;
+ if ((lvi.iItem = ListView_GetNextItem(m_hWnd, -1, LVNI_FOCUSED)) != -1
+ && ListView_GetItem(m_hWnd, &lvi))
+ Pl("cfg","set_focus","I",lvi.lParam);
+}
+
+void
EpisodeListView::SetTop(int iItem)
{
int iLast;
@@ -165,7 +175,7 @@ EpisodeListView::SetTop(int iItem)
/* Select previously focused episode. */
void
-EpisodeListView::SelectFocus()
+EpisodeListView::RestoreFocus()
{
int i, iEpisode, iItem;
LVFINDINFO lvfi;
@@ -388,6 +398,30 @@ r: if (!Pl("episode_data","episode_rating","Ii",lpLvi->lParam,&iRating)) {
f: if (tszName) free(tszName);
}
+LRESULT CALLBACK
+EpisodeListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_GETDLGCODE:
+ {
+ LRESULT lResult;
+
+ /* For the episode list view, the Enter key should not
+ * be handled by the dialog manager, but instead be sent
+ * along to the main window procedure, so that it may be
+ * handled by the NM_RETURN case in ElvHandleNotify. */
+
+ lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
+ if (lParam && ((MSG *)lParam)->message == WM_KEYDOWN
+ && ((MSG *)lParam)->wParam == VK_RETURN)
+ return DLGC_WANTMESSAGE;
+ return lResult;
+ }
+ }
+
+ return ListView::WndProc(hWnd, uMsg, wParam, lParam);
+}
+
/* Sort list view items, iSort being the 1-based index of the column
* to sort by. If iSort is negative, the order is descending. */
int CALLBACK
@@ -434,27 +468,3 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
return 0;
}
}
-
-LRESULT CALLBACK
-EpisodeListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- switch (uMsg) {
- case WM_GETDLGCODE:
- {
- LRESULT lResult;
-
- /* For the episode list view, the Enter key should not
- * be handled by the dialog manager, but instead be sent
- * along to the main window procedure, so that it may be
- * handled by the NM_RETURN case in ElvHandleNotify. */
-
- lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
- if (lParam && ((MSG *)lParam)->message == WM_KEYDOWN
- && ((MSG *)lParam)->wParam == VK_RETURN)
- return DLGC_WANTMESSAGE;
- return lResult;
- }
- }
-
- return ListView::WndProc(hWnd, uMsg, wParam, lParam);
-}
diff --git a/c/listview.cpp b/c/listview.cpp
index 9f24dc3..87b7dbc 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -46,6 +46,35 @@ ListView::HWnd()
return m_hWnd;
}
+void
+ListView::UpdateTheme(BOOL bThemeActive)
+{
+ DWORD dwStyle;
+ LPTSTR tszTheme;
+ WORD wAction;
+ extern int g_bThemes;
+
+ if (!g_bThemes) return;
+ if (bThemeActive) {
+ dwStyle = LVS_EX_DOUBLEBUFFER;
+ tszTheme = TEXT("Explorer");
+ wAction = UIS_SET;
+ } else {
+ dwStyle = 0;
+ tszTheme = NULL;
+ wAction = UIS_CLEAR;
+ }
+
+ /* Use modern "Explorer" theme. */
+ SetWindowTheme(m_hWnd, tszTheme, NULL);
+
+ /* The modern theme requires double buffering. */
+ ListView_SetExtendedListViewStyleEx(m_hWnd, LVS_EX_DOUBLEBUFFER, dwStyle);
+
+ /* Hide focus rectangles. */
+ SendMessage(m_hWnd, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0);
+}
+
LRESULT CALLBACK
ListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
diff --git a/c/main.cpp b/c/main.cpp
index 6799280..840450e 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -6,8 +6,8 @@
#include "resource.h"
#include "defs.h"
-EpisodeListView g_elv;
DataListView g_dlv;
+EpisodeListView g_elv;
atom_t g_aThread;
char g_szLimitScreenwriter[64] = {0};
@@ -17,11 +17,11 @@ HMENU g_hPopupMenu;
HWND g_hFocus;
HWND g_hWnd;
HWND g_hWndStatus;
+int g_bThemes;
int g_bViewTVOriginal = 1;
int g_bViewWatched = 1;
int g_bThread = 0;
int g_iDPI = -1;
-static int g_bThemes;
static int g_cxVScroll;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
@@ -34,21 +34,17 @@ int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, INT nCmdShow)
{
- char *argv[2];
- HMODULE hModule;
HWND hWnd;
LPTSTR tszErr;
- MSG msg;
- INITCOMMONCONTROLSEX icc;
- WNDCLASSEX wc;
/* Set constant values. */
- hModule = LoadLibrary(TEXT("uxtheme.dll"));
- g_bThemes = hModule && GetProcAddress(hModule,"SetWindowTheme");
+ HMODULE hModule = LoadLibrary(TEXT("uxtheme.dll"));
+ g_bThemes = hModule && GetProcAddress(hModule, "SetWindowTheme");
if (hModule) FreeLibrary(hModule);
g_cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
/* Initialize Prolog. */
+ char *argv[2];
argv[0] = (char *)"EpisodeBrowser";
argv[1] = NULL;
tszErr = TEXT("Could not initialize Prolog.");
@@ -57,6 +53,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (!Attach()) goto f;
/* Initialize common controls, load menu and register window class. */
+ INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
tszErr = TEXT("Could not initialize common controls.");
@@ -65,6 +62,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
g_hPopupMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_POPUPMENU));
g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0);
+ WNDCLASSEX wc;
memset(&wc, 0, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
@@ -95,8 +93,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
/* Populate episode list view. */
Pl("track_episodes", "update_tracked_episodes", "");
g_elv.Update();
- g_elv.SelectFocus();
+ g_elv.RestoreFocus();
+ MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
if (IsDialogMessage(hWnd, &msg)) continue;
TranslateMessage(&msg);
@@ -116,31 +115,37 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (uMsg) {
case WM_CREATE:
{
- HMODULE hModule;
- UINT (*GetDpiForWindow)(HWND);
g_hWnd = hWnd;
- g_iDPI = 96;
- hModule = LoadLibrary(TEXT("User32.dll"));
+
+ /* Get DPI. */
+ UINT (*GetDpiForWindow)(HWND);
+ HMODULE hModule = LoadLibrary(TEXT("User32.dll"));
if (hModule && (GetDpiForWindow = (UINT (*)(HWND))GetProcAddress(hModule, "GetDpiForWindow"))) {
g_iDPI = GetDpiForWindow(g_hWnd);
FreeLibrary(hModule);
- }
+ } else
+ g_iDPI = 96;
+
+ /* Set window size. */
SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE);
+
+ /* Get and apply saved view settings. */
if (Pl("cfg","get_view_watched","i",&g_bViewWatched))
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
g_bViewWatched? MF_CHECKED: MF_UNCHECKED);
+
if (Pl("cfg","get_view_tv_original","i",&g_bViewTVOriginal))
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
g_bViewTVOriginal? MF_CHECKED: MF_UNCHECKED);
- {
- char *sz;
- if (!Pl("cfg","get_limit_screenwriter","s",&sz))
- goto s;
- strcpy_s(g_szLimitScreenwriter,
- sizeof(g_szLimitScreenwriter), sz);
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
- g_szLimitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
- }
+
+ char *sz;
+ if (!Pl("cfg","get_limit_screenwriter","s",&sz))
+ goto s;
+ strcpy_s(g_szLimitScreenwriter,
+ sizeof(g_szLimitScreenwriter), sz);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
+ g_szLimitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
+
s: SetupFonts();
g_dlv.Create();
g_elv.Create();
@@ -153,13 +158,7 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
case WM_DESTROY:
{
- LVITEM lvi;
- HWND hElv;
- hElv = g_elv.HWnd();
- lvi.mask = LVIF_PARAM;
- if ((lvi.iItem=ListView_GetNextItem(hElv,-1,LVNI_FOCUSED)) != -1
- && ListView_GetItem(hElv, &lvi))
- Pl("cfg","set_focus","I",lvi.lParam);
+ g_elv.SaveFocus();
PostQuitMessage(0);
break;
}
@@ -170,7 +169,8 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_GETMINMAXINFO:
{
LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
- lpMMI->ptMinTrackSize.y = g_dlv.Height(0)+80;
+ lpMMI->ptMinTrackSize.x = Dpi(220);
+ lpMMI->ptMinTrackSize.y = g_dlv.Height(0)+Dpi(180);
break;
}
case WM_THEMECHANGED:
@@ -259,38 +259,32 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_WATCHED:
{
int iEpFocus;
- HWND hElv;
- hElv = g_elv.HWnd();
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
g_bViewWatched? MF_UNCHECKED: MF_CHECKED);
g_bViewWatched = !g_bViewWatched;
g_elv.Update();
Pl("cfg","set_view_watched","I",g_bViewWatched);
- iEpFocus = ListView_GetNextItem(hElv, -1, LVNI_FOCUSED);
+ iEpFocus = ListView_GetNextItem(g_elv.HWnd(), -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
- ListView_EnsureVisible(hElv, iEpFocus, TRUE);
+ ListView_EnsureVisible(g_elv.HWnd(), iEpFocus, TRUE);
break;
}
case IDM_VIEW_TV_ORIGINAL:
{
int iEpFocus;
- HWND hElv;
- hElv = g_elv.HWnd();
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED);
g_bViewTVOriginal = !g_bViewTVOriginal;
g_elv.Update();
Pl("cfg","set_view_tv_original","I",g_bViewTVOriginal);
- iEpFocus = ListView_GetNextItem(hElv, -1, LVNI_FOCUSED);
+ iEpFocus = ListView_GetNextItem(g_elv.HWnd(), -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
- ListView_EnsureVisible(hElv, iEpFocus, TRUE);
+ ListView_EnsureVisible(g_elv.HWnd(), iEpFocus, TRUE);
break;
}
case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */
{
int iEpFocus;
- HWND hElv;
- hElv = g_elv.HWnd();
if (g_szLimitScreenwriter[0]) {
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
MF_CHECKED);
@@ -298,11 +292,11 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
} else {
char *sz;
LVITEM lvi;
- iEpFocus = ListView_GetNextItem(hElv, -1, LVNI_FOCUSED);
+ iEpFocus = ListView_GetNextItem(g_elv.HWnd(), -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
lvi.iItem = iEpFocus;
lvi.mask = LVIF_PARAM;
- if (!ListView_GetItem(hElv, &lvi)) break;
+ if (!ListView_GetItem(g_elv.HWnd(), &lvi)) break;
if (!Pl("episode_data","episode_datum","ISs",
lvi.lParam,"Screenwriter",&sz))
break;
@@ -314,9 +308,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
g_elv.Update();
Pl("cfg","set_limit_screenwriter","S",
g_szLimitScreenwriter);
- iEpFocus = ListView_GetNextItem(hElv, -1, LVNI_FOCUSED);
+ iEpFocus = ListView_GetNextItem(g_elv.HWnd(), -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
- ListView_EnsureVisible(hElv, iEpFocus, TRUE);
+ ListView_EnsureVisible(g_elv.HWnd(), iEpFocus, TRUE);
break;
}
case IDM_WATCH_LOCALLY:
@@ -339,8 +333,6 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int iRating;
LVITEM lvi;
- HWND hElv;
- hElv = g_elv.HWnd();
/* Look through selected items, applying the
* selected command to each one. */
@@ -348,8 +340,8 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
lvi.mask = LVIF_PARAM;
lvi.iItem = -1;
while ((lvi.iItem = ListView_GetNextItem(
- hElv, lvi.iItem, LVNI_SELECTED)) != -1) {
- if (!ListView_GetItem(hElv, &lvi)) goto b;
+ g_elv.HWnd(), lvi.iItem, LVNI_SELECTED)) != -1) {
+ if (!ListView_GetItem(g_elv.HWnd(), &lvi)) goto b;
switch (LOWORD(wParam)) {
case IDM_WATCH_LOCALLY:
@@ -519,34 +511,30 @@ UpdateLayout()
{
int cxColumn, cyDlv, yStatus;
RECT rc, rcStatus;
- HWND hDlv, hElv;
-
- hDlv = g_dlv.HWnd();
- hElv = g_elv.HWnd();
GetClientRect(g_hWnd, &rc);
GetClientRect(g_hWndStatus, &rcStatus);
yStatus = rcStatus.bottom-rcStatus.top;
/* Resize data list view. */
- SendMessage(hDlv, WM_SETREDRAW, FALSE, 0);
- SendMessage(hElv, WM_SETREDRAW, FALSE, 0);
+ SendMessage(g_dlv.HWnd(), WM_SETREDRAW, FALSE, 0);
+ SendMessage(g_elv.HWnd(), WM_SETREDRAW, FALSE, 0);
cyDlv = rc.bottom-yStatus-g_dlv.Height(DLVSIKEY);
- MoveWindow(hDlv, 0, cyDlv, rc.right, rc.bottom-yStatus-cyDlv, TRUE);
- ListView_SetColumnWidth(hDlv, DLVSIKEY, LVSCW_AUTOSIZE);
- cxColumn = ListView_GetColumnWidth(hDlv, 0)+4;
- ListView_SetColumnWidth(hDlv, DLVSIKEY, cxColumn);
- ListView_SetColumnWidth(hDlv, DLVSIVALUE, rc.right-cxColumn-g_cxVScroll-4);
+ MoveWindow(g_dlv.HWnd(), 0, cyDlv, rc.right, rc.bottom-yStatus-cyDlv, TRUE);
+ ListView_SetColumnWidth(g_dlv.HWnd(), DLVSIKEY, LVSCW_AUTOSIZE);
+ cxColumn = ListView_GetColumnWidth(g_dlv.HWnd(), 0)+4;
+ ListView_SetColumnWidth(g_dlv.HWnd(), DLVSIKEY, cxColumn);
+ ListView_SetColumnWidth(g_dlv.HWnd(), DLVSIVALUE, rc.right-cxColumn-g_cxVScroll-4);
/* Resize episode list view. */
- MoveWindow(hElv, 0, 0, rc.right, cyDlv+1, TRUE);
- ListView_SetColumnWidth(hElv, ELVSIEPISODE, LVSCW_AUTOSIZE);
- cxColumn = ListView_GetColumnWidth(hElv, ELVSIEPISODE)+4;
- ListView_SetColumnWidth(hElv, ELVSIEPISODE, cxColumn);
- cxColumn += ListView_GetColumnWidth(hElv, ELVSIRATING);
- ListView_SetColumnWidth(hElv, ELVSITITLE, rc.right-cxColumn-g_cxVScroll-4);
- SendMessage(hElv, WM_SETREDRAW, TRUE, 0);
- SendMessage(hDlv, WM_SETREDRAW, TRUE, 0);
+ MoveWindow(g_elv.HWnd(), 0, 0, rc.right, cyDlv+1, TRUE);
+ ListView_SetColumnWidth(g_elv.HWnd(), ELVSIEPISODE, LVSCW_AUTOSIZE);
+ cxColumn = ListView_GetColumnWidth(g_elv.HWnd(), ELVSIEPISODE)+4;
+ ListView_SetColumnWidth(g_elv.HWnd(), ELVSIEPISODE, cxColumn);
+ cxColumn += ListView_GetColumnWidth(g_elv.HWnd(), ELVSIRATING);
+ ListView_SetColumnWidth(g_elv.HWnd(), ELVSITITLE, rc.right-cxColumn-g_cxVScroll-4);
+ SendMessage(g_elv.HWnd(), WM_SETREDRAW, TRUE, 0);
+ SendMessage(g_dlv.HWnd(), WM_SETREDRAW, TRUE, 0);
/* Resize status bar parts. */
{
@@ -560,34 +548,7 @@ UpdateLayout()
void
UpdateTheme()
{
- DWORD dwStyle;
- LPTSTR tszTheme;
- WORD wAction;
- HWND hDlv, hElv;
-
- hDlv = g_dlv.HWnd();
- hElv = g_elv.HWnd();
-
- if (!g_bThemes) return;
- if (IsThemeActive()) {
- dwStyle = LVS_EX_DOUBLEBUFFER;
- tszTheme = TEXT("Explorer");
- wAction = UIS_SET;
- } else {
- dwStyle = 0;
- tszTheme = NULL;
- wAction = UIS_CLEAR;
- }
-
- /* Use modern "Explorer" theme. */
- SetWindowTheme(hElv, tszTheme, NULL);
- SetWindowTheme(hDlv, tszTheme, NULL);
-
- /* The modern theme requires double buffering. */
- ListView_SetExtendedListViewStyleEx(hElv, LVS_EX_DOUBLEBUFFER, dwStyle);
- ListView_SetExtendedListViewStyleEx(hDlv, LVS_EX_DOUBLEBUFFER, dwStyle);
-
- /* Hide focus rectangles. */
- SendMessage(hElv, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0);
- SendMessage(hDlv, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0);
+ BOOL bThemeActive = IsThemeActive();
+ g_dlv.UpdateTheme(bThemeActive);
+ g_elv.UpdateTheme(bThemeActive);
}