aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/common.c2
-rw-r--r--c/datalistview.c30
-rw-r--r--c/defs.h9
-rw-r--r--c/episodelistview.c93
-rw-r--r--c/listview.c19
-rw-r--r--c/main.c34
-rw-r--r--c/resource.rc9
7 files changed, 96 insertions, 100 deletions
diff --git a/c/common.c b/c/common.c
index af5638d..9a3baa8 100644
--- a/c/common.c
+++ b/c/common.c
@@ -7,7 +7,7 @@
/* Convert zero-terminated non-wide (multi-byte) string to
* zero-terminated wide/non-wide string depending on UNICODE. */
TCHAR *
-TSZFromSZ(const char *sz, int iCp)
+TszFromSz(const char *sz, int iCp)
{
TCHAR *tsz;
diff --git a/c/datalistview.c b/c/datalistview.c
index d859e24..6749af7 100644
--- a/c/datalistview.c
+++ b/c/datalistview.c
@@ -5,29 +5,27 @@
#include "resource.h"
#include "defs.h"
-HWND Dlv_hWnd;
+HWND HDlv;
HWND
-DlvCreate(HWND hWnd)
+DlvCreate()
{
- HWND hDlv;
LVCOLUMN lvc;
- Dlv_hWnd = hWnd;
- hDlv = LvCreate(hWnd, (HMENU)IDC_DATALISTVIEW);
+ HDlv = LvCreate((HMENU)IDC_DATALISTVIEW);
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = TEXT("Key");
lvc.cx = 42;
- ListView_InsertColumn(hDlv, 0, &lvc);
+ ListView_InsertColumn(HDlv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Value");
lvc.cx = 500;
- ListView_InsertColumn(hDlv, 1, &lvc);
+ ListView_InsertColumn(HDlv, 1, &lvc);
- return hDlv;
+ return HDlv;
}
/* Show episode data. */
@@ -35,12 +33,10 @@ void
DlvShowEpisode(int iEpisode)
{
fid_t f;
- HWND hDlv;
LVITEM lviKey, lviValue;
term_t t;
- hDlv = GetDlgItem(Dlv_hWnd, IDC_DATALISTVIEW);
- ListView_DeleteAllItems(hDlv);
+ ListView_DeleteAllItems(HDlv);
lviKey.mask = LVIF_TEXT;
lviValue.mask = LVIF_TEXT;
@@ -75,24 +71,24 @@ DlvShowEpisode(int iEpisode)
if (!PL_get_arg(1, tHead, tValue)) continue;
GAC(tValue,&szValue) continue;
- tszKey = TSZFromSZ(szKey, CP_UTF8);
+ tszKey = TszFromSz(szKey, CP_UTF8);
if (!tszKey) continue;
- tszValue = TSZFromSZ(szValue, CP_UTF8);
- if (!tszValue) goto e1;
+ tszValue = TszFromSz(szValue, CP_UTF8);
+ if (!tszValue) goto n;
lviKey.mask = LVIF_TEXT;
lviKey.iItem = i;
lviKey.iSubItem = 0;
lviKey.pszText = tszKey;
- ListView_InsertItem(hDlv, &lviKey);
+ ListView_InsertItem(HDlv, &lviKey);
lviValue.iItem = i;
lviValue.iSubItem = 1;
lviValue.pszText = tszValue;
- ListView_SetItem(hDlv, &lviValue);
+ ListView_SetItem(HDlv, &lviValue);
free(tszValue);
-e1: free(tszKey);
+n: free(tszKey);
}
}
diff --git a/c/defs.h b/c/defs.h
index db5af3a..041f64a 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -2,26 +2,27 @@
#define DEFS_H
/* common.c */
-TCHAR *TSZFromSZ(const char *, int);
+TCHAR *TszFromSz(const char *, int);
int Watched(int);
/* main.c */
void UpdateLayout(HWND);
/* listview.c */
-HWND LvCreate(HWND, HMENU);
+HWND LvCreate(HMENU);
/* episodelistview.c */
-HWND ElvCreate(HWND);
+HWND ElvCreate();
LRESULT ElvHandleNotify(LPARAM);
int ElvItemEpisode(int);
void ElvRedraw(void);
+void ElvSetTop(int);
void ElvSelectRecent(void);
void ElvUpdate(void);
void ElvUpdateName(int, int);
/* datalistview.c */
-HWND DlvCreate(HWND);
+HWND DlvCreate();
void DlvShowEpisode(int);
#define P(m,p,a,t) if (!PL_call_predicate(NULL, PL_Q_NORMAL, \
diff --git a/c/episodelistview.c b/c/episodelistview.c
index e414c46..df50bad 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -6,34 +6,33 @@
#include "resource.h"
#include "defs.h"
-extern HFONT g_GUIFontBold;
-HWND Elv_hWnd;
-int Elv_iSelectedItem = -1;
-WNDPROC Elv_PrevProc;
+extern HFONT HfBold;
+extern HWND HWnd;
+HWND HElv;
+int IElvSelectedItem = -1;
+WNDPROC ElvPrevProc;
HWND
-ElvCreate(HWND hWnd)
+ElvCreate()
{
- HWND hElv;
LVCOLUMN lvc;
- Elv_hWnd = hWnd;
- hElv = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW);
+ HElv = LvCreate((HMENU)IDC_EPISODELISTVIEW);
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = TEXT("#");
lvc.cx = 42;
- ListView_InsertColumn(hElv, 0, &lvc);
+ ListView_InsertColumn(HElv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Title");
lvc.cx = 500;
- ListView_InsertColumn(hElv, 1, &lvc);
+ ListView_InsertColumn(HElv, 1, &lvc);
ElvUpdate();
ElvSelectRecent();
- return hElv;
+ return HElv;
}
LRESULT
@@ -46,7 +45,7 @@ ElvHandleNotify(LPARAM lParam)
case LVN_ITEMCHANGED:
if ((lpNmLv->uChanged & LVIF_STATE)
&& (lpNmLv->uNewState & LVIS_FOCUSED)) {
- Elv_iSelectedItem = lpNmLv->iItem;
+ IElvSelectedItem = lpNmLv->iItem;
ElvUpdateName(lpNmLv->iItem, lpNmLv->lParam);
DlvShowEpisode(lpNmLv->lParam);
}
@@ -62,7 +61,7 @@ ElvHandleNotify(LPARAM lParam)
case CDDS_ITEMPREPAINT:
if (!Watched(lpLvCd->nmcd.lItemlParam)) {
SelectObject(lpLvCd->nmcd.hdc,
- g_GUIFontBold);
+ HfBold);
return CDRF_NEWFONT;
}
break;
@@ -73,18 +72,18 @@ ElvHandleNotify(LPARAM lParam)
{
term_t t;
t = T(1);
- PI(t+0, ElvItemEpisode(Elv_iSelectedItem)) break;
+ PI(t+0, ElvItemEpisode(IElvSelectedItem)) break;
P("local_episodes","open_episode",1,t);
break;
}
case NM_RCLICK:
{
DWORD dwPos;
- extern HMENU g_hPopupMenu;
+ extern HMENU HPopupMenu;
dwPos = GetMessagePos();
- TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
+ TrackPopupMenu(HPopupMenu, TPM_RIGHTBUTTON,
LOWORD(dwPos), HIWORD(dwPos), 0,
- Elv_hWnd, NULL);
+ HWnd, NULL);
break;
}
}
@@ -94,30 +93,34 @@ ElvHandleNotify(LPARAM lParam)
int
ElvItemEpisode(int iItem) {
- HWND hElv;
LVITEM lvi;
- hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvi.mask = LVIF_PARAM;
lvi.iItem = iItem;
lvi.iSubItem = 0;
- return ListView_GetItem(hElv, &lvi) ? lvi.lParam : -1;
+ return ListView_GetItem(HElv, &lvi) ? lvi.lParam : -1;
}
void
ElvRedraw()
{
- HWND hElv;
- hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
- RedrawWindow(hElv, NULL, NULL,
+ RedrawWindow(HElv, NULL, NULL,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
+void
+ElvSetTop(int iItem)
+{
+ int iLast;
+ iLast = ListView_GetItemCount(HElv)-1;
+ ListView_EnsureVisible(HElv, iLast, TRUE);
+ ListView_EnsureVisible(HElv, iItem, TRUE);
+}
+
/* Select most recent episode. */
void
ElvSelectRecent()
{
fid_t f;
- HWND hElv;
int iEpisode, iItem;
LVFINDINFO lvfi;
term_t t;
@@ -127,16 +130,16 @@ ElvSelectRecent()
P("track_episodes","most_recently_watched",1,t) goto e;
GI(t, &iEpisode) goto e;
- hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
- iItem = ListView_FindItem(hElv, -1, &lvfi);
+ iItem = ListView_FindItem(HElv, -1, &lvfi);
if (iItem == -1) goto e;
- ListView_EnsureVisible(hElv, iItem, TRUE);
- ListView_SetItemState(hElv, iItem, LVIS_SELECTED, LVIS_SELECTED);
- Elv_iSelectedItem = iItem;
+ if (iItem > 5)
+ ElvSetTop(iItem-5);
+ ListView_SetItemState(HElv, iItem, LVIS_SELECTED, LVIS_SELECTED);
+ IElvSelectedItem = iItem;
ElvUpdateName(iItem, iEpisode);
DlvShowEpisode(iEpisode);
@@ -148,16 +151,14 @@ void
ElvUpdate()
{
fid_t f;
- HWND hElv;
- int iLast, iTop;
+ int iTop;
LVITEM lviEpisode, lviName;
qid_t q;
term_t t;
- hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
- SendMessage(hElv, WM_SETREDRAW, FALSE, 0);
- iTop = ListView_GetTopIndex(hElv);
- ListView_DeleteAllItems(hElv);
+ SendMessage(HElv, WM_SETREDRAW, FALSE, 0);
+ iTop = ListView_GetTopIndex(HElv);
+ ListView_DeleteAllItems(HElv);
lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
lviName.mask = LVIF_TEXT;
@@ -183,7 +184,7 @@ ElvUpdate()
tszName = NULL;
P("episode_data","lookup_episode_local",3,t2) goto skipname;
GAC(t2+1,&szName) goto skipname;
- tszName = TSZFromSZ(szName, CP_UTF8);
+ tszName = TszFromSz(szName, CP_UTF8);
if (!tszName) goto e;
/* Format episode string. */
@@ -199,13 +200,13 @@ skipname:
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
lviEpisode.lParam = iEpisode;
- ListView_InsertItem(hElv, &lviEpisode);
+ ListView_InsertItem(HElv, &lviEpisode);
if (tszName) {
lviName.iItem = i;
lviName.iSubItem = 1;
lviName.pszText = tszName;
- ListView_SetItem(hElv, &lviName);
+ ListView_SetItem(HElv, &lviName);
}
free(tszEpisode);
@@ -215,15 +216,13 @@ e: Fd(f2);
/* Reset selection and scrolling position. */
- iLast = ListView_GetItemCount(hElv)-1;
- ListView_EnsureVisible(hElv, iLast, TRUE);
- ListView_EnsureVisible(hElv, iTop, TRUE);
- if (Elv_iSelectedItem != -1) {
- ListView_SetItemState(hElv, Elv_iSelectedItem,
+ ElvSetTop(iTop);
+ if (IElvSelectedItem != -1) {
+ ListView_SetItemState(HElv, IElvSelectedItem,
LVIS_SELECTED, LVIS_SELECTED);
}
- SendMessage(hElv, WM_SETREDRAW, TRUE, 0);
+ SendMessage(HElv, WM_SETREDRAW, TRUE, 0);
ElvRedraw();
Qc(q);
Fd(f);
@@ -235,7 +234,6 @@ ElvUpdateName(int iItem, int iEpisode)
{
char *szName;
fid_t f;
- HWND hElv;
TCHAR *tszName;
term_t t;
@@ -245,11 +243,10 @@ ElvUpdateName(int iItem, int iEpisode)
P("episode_data","lookup_episode",3,t) goto e;
GAC(t+1,&szName) goto e;
- tszName = TSZFromSZ(szName, CP_UTF8);
+ tszName = TszFromSz(szName, CP_UTF8);
if (!tszName) goto e;
- hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
- ListView_SetItemText(hElv, iItem, 1, tszName);
+ ListView_SetItemText(HElv, iItem, 1, tszName);
e: Fd(f);
return;
diff --git a/c/listview.c b/c/listview.c
index d223951..5bc76ce 100644
--- a/c/listview.c
+++ b/c/listview.c
@@ -5,12 +5,13 @@
#include "resource.h"
#include "defs.h"
-extern HFONT g_GUIFont;
-WNDPROC Lv_PrevProc;
+extern HFONT HfNormal;
+extern HWND HWnd;
+WNDPROC LvPrevProc;
static LRESULT CALLBACK LvProc(HWND, UINT, WPARAM, LPARAM);
HWND
-LvCreate(HWND hWnd, HMENU hMenu)
+LvCreate(HMENU hMenu)
{
HMODULE hModule;
HWND hLv;
@@ -21,20 +22,20 @@ LvCreate(HWND hWnd, HMENU hMenu)
TEXT(""),
WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT|LVS_NOSORTHEADER,
0, 0, 0, 0,
- hWnd,
+ HWnd,
hMenu,
GetModuleHandle(NULL),
NULL
);
- Lv_PrevProc = (WNDPROC)SetWindowLongPtr(hLv,
+ LvPrevProc = (WNDPROC)SetWindowLongPtr(hLv,
GWLP_WNDPROC, (LONG_PTR)LvProc);
- ListView_SetExtendedListViewStyle(hLv,
- LVS_EX_DOUBLEBUFFER);
+ ListView_SetExtendedListViewStyleEx(hLv,
+ LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
SendMessage(hLv, WM_SETFONT,
- (WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0));
+ (WPARAM)HfNormal, MAKELPARAM(FALSE, 0));
hModule = LoadLibrary(TEXT("uxtheme.dll"));
if (hModule && GetProcAddress(hModule, "SetWindowTheme")) {
@@ -61,5 +62,5 @@ LvProc(HWND hLv, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
- return CallWindowProc(Lv_PrevProc, hLv, uMsg, wParam, lParam);
+ return CallWindowProc(LvPrevProc, hLv, uMsg, wParam, lParam);
}
diff --git a/c/main.c b/c/main.c
index 330101e..82f30a6 100644
--- a/c/main.c
+++ b/c/main.c
@@ -5,9 +5,10 @@
#include "resource.h"
#include "defs.h"
-HFONT g_GUIFont;
-HFONT g_GUIFontBold;
-HMENU g_hPopupMenu;
+HFONT HfNormal;
+HFONT HfBold;
+HMENU HPopupMenu;
+HWND HWnd;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static int Attach(void);
@@ -37,9 +38,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
- g_hPopupMenu = LoadMenu(NULL,
+ HPopupMenu = LoadMenu(NULL,
MAKEINTRESOURCE(IDR_POPUPMENU));
- g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0);
+ HPopupMenu = GetSubMenu(HPopupMenu, 0);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
@@ -91,8 +92,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0);
break;
case WM_CREATE:
- DlvCreate(hWnd);
- ElvCreate(hWnd);
+ HWnd = hWnd;
+ DlvCreate();
+ ElvCreate();
break;
case WM_SIZE:
UpdateLayout(hWnd);
@@ -128,10 +130,10 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
HWND hElv;
int iEpisode;
term_t t;
- extern int Elv_iSelectedItem;
+ extern int IElvSelectedItem;
hElv = GetDlgItem(hWnd, IDC_EPISODELISTVIEW);
- iEpisode = ElvItemEpisode(Elv_iSelectedItem);
+ iEpisode = ElvItemEpisode(IElvSelectedItem);
F(f);
t = T(1);
@@ -152,7 +154,7 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
case ID_LOOKUP:
P("episode_data","retract_episode",1,t);
- ElvUpdateName(Elv_iSelectedItem, iEpisode);
+ ElvUpdateName(IElvSelectedItem, iEpisode);
ElvRedraw();
DlvShowEpisode(iEpisode);
break;
@@ -226,14 +228,14 @@ SetupFonts()
m.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &m, 0);
- g_GUIFont = CreateFontIndirect(&m.lfMessageFont);
+ HfNormal = CreateFontIndirect(&m.lfMessageFont);
} else {
- g_GUIFont = GetStockObject(DEFAULT_GUI_FONT);
+ HfNormal = GetStockObject(DEFAULT_GUI_FONT);
}
- GetObject(g_GUIFont, sizeof(LOGFONT), &lf);
+ GetObject(HfNormal, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
- g_GUIFontBold = CreateFontIndirect(&lf);
+ HfBold = CreateFontIndirect(&lf);
}
/***/
@@ -244,7 +246,7 @@ UpdateLayout(HWND hWnd)
HWND hElv, hDlv;
int cxColumn, cyDlv;
RECT rc;
- extern int Elv_iSelectedItem;
+ extern int IElvSelectedItem;
static int cxVScroll = 0;
if (cxVScroll == 0)
@@ -270,6 +272,4 @@ UpdateLayout(HWND hWnd)
cxColumn = ListView_GetColumnWidth(hElv, 0);
ListView_SetColumnWidth(hElv, 1,
rc.right-cxColumn-cxVScroll-4);
-
- //ListView_EnsureVisible(hElv, Elv_iSelectedItem, TRUE);
}
diff --git a/c/resource.rc b/c/resource.rc
index 7076016..a5e9362 100644
--- a/c/resource.rc
+++ b/c/resource.rc
@@ -8,7 +8,7 @@ BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Refresh", ID_FILE_REFRESH
- MENUITEM "&Exit", ID_FILE_EXIT
+ MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Help"
BEGIN
@@ -27,7 +27,8 @@ BEGIN
END
END
-#define PAD 7
+#define VPAD 7
+#define HPAD 9
#define ABOUTW 190
#define ABOUTH 40
#define OKW 48
@@ -38,7 +39,7 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "MS Shell Dlg 2"
BEGIN
- DEFPUSHBUTTON "&OK", IDOK, ABOUTW-OKW-PAD, ABOUTH-OKH-PAD, OKW, OKH
+ DEFPUSHBUTTON "&OK", IDOK, ABOUTW-OKW-HPAD, ABOUTH-OKH-VPAD, OKW, OKH
LTEXT TEXT("Episode Browser\r\nCopyright 2021 John Ankarström"),
- IDC_ABOUTTEXT, PAD, PAD, ABOUTW-OKW-PAD*2, ABOUTH-PAD
+ IDC_ABOUTTEXT, HPAD, VPAD, ABOUTW-OKW-HPAD*2, ABOUTH-VPAD
END \ No newline at end of file