aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-31 19:56:53 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-31 19:58:54 +0200
commitd9e1caa37e53c7dbc42b1fc652efc23a40c47c42 (patch)
treed2a1608a3c88fef98af9a356a116af3551ea5680
parentd9bafcecfd60f38f98bca8a1705f6007b39e18a2 (diff)
downloadEpisodeBrowser-d9e1caa37e53c7dbc42b1fc652efc23a40c47c42.tar.gz
Limit use of Hungarian notation.
I don't hate Hungarian notation. It has some very nice qualities. But it also adds a lot of typing. That said, not using it feels a bit... unsafe. I might go back on this decision. We'll see.
-rw-r--r--README19
-rw-r--r--c/common.cpp40
-rw-r--r--c/common.h36
-rw-r--r--c/datalistview.cpp22
-rw-r--r--c/debug.cpp48
-rw-r--r--c/debug.h4
-rw-r--r--c/episodelistview.cpp146
-rw-r--r--c/episodelistview.h6
-rw-r--r--c/listview.cpp28
-rw-r--r--c/listview.h2
-rw-r--r--c/main.cpp225
-rw-r--r--c/pl.cpp8
-rw-r--r--c/pl.h16
13 files changed, 289 insertions, 311 deletions
diff --git a/README b/README
index b492c53..4fe5ba0 100644
--- a/README
+++ b/README
@@ -58,25 +58,6 @@ Hacking
~~~~~~~
Following is a summary of some coding conventions used in the project.
- ... HUNGARIAN NOTATION ...
-
- - p = pointer
- - b = bool, BOOL, int (boolean value)
- - i = int
- - h = handle
- - l = long, (LPARAM)
- - w = unsigned short, WORD, (WPARAM)
- - dw = DWORD
- - lvi = LVITEM
- - sz = char*
- - wsz = wchar_t*
- - ws = std::wstring
- - wso = wstring_owner
-
-The list above is non-exhaustive. Variables whose type is unknown (in
-templates) do not need prefixes. Some very common self-explanatory
-variables also do not need prefixes, e.g. len (usually size_t).
-
... TYPES ...
Here are some general guidelines for choosing what types to use:
diff --git a/c/common.cpp b/c/common.cpp
index 7ce1372..3ed2b73 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -6,22 +6,22 @@
wstring_owner::wstring_owner() {}
-wstring_owner::wstring_owner(wchar_t* const wsz) : p(wsz) {}
+wstring_owner::wstring_owner(wchar_t* const s) : p(s) {}
-wstring_owner& wstring_owner::operator=(wchar_t* const wsz)
+wstring_owner& wstring_owner::operator=(wchar_t* const s)
{
- if (p != wsz) {
+ if (p != s) {
delete p;
- p = wsz;
+ p = s;
}
return *this;
}
-wstring_owner::wstring_owner(wstring_owner&& wso) noexcept : p(std::exchange(wso.p, nullptr)) {}
+wstring_owner::wstring_owner(wstring_owner&& other) noexcept : p(std::exchange(other.p, nullptr)) {}
-wstring_owner& wstring_owner::operator=(wstring_owner&& wso) noexcept
+wstring_owner& wstring_owner::operator=(wstring_owner&& other) noexcept
{
- std::swap(p, wso.p);
+ std::swap(p, other.p);
return *this;
}
@@ -43,16 +43,16 @@ wstring_owner::~wstring_owner()
delete p;
}
-wstring_owner WsoFromSz(const char* const sz, const int iCp)
+wstring_owner WsoFromSz(const char* const src, const int cp)
{
- int cbMultiByte = strlen(sz)+1;
- int cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0);
- wchar_t* wsz = new wchar_t[cchWideChar];
- if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, wsz, cchWideChar)) {
- delete wsz;
+ int cbMultiByte = strlen(src)+1;
+ int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0);
+ wchar_t* dst = new wchar_t[cchWideChar];
+ if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
+ delete dst;
throw Win32Error();
}
- return wsz;
+ return dst;
}
wstring_owner WsoCopy(const wchar_t* const src)
@@ -65,8 +65,8 @@ wstring_owner WsoCopy(const wchar_t* const src)
/* Win32Error: Exception for Windows API errors. */
-Win32Error::Win32Error() : dwErr(GetLastError()) {}
-Win32Error::Win32Error(const DWORD dwErr) : dwErr(dwErr) {}
+Win32Error::Win32Error() : code(GetLastError()) {}
+Win32Error::Win32Error(const DWORD code) : code(code) {}
Win32Error::~Win32Error()
{
@@ -82,7 +82,7 @@ const char* Win32Error::what() const noexcept
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- dwErr,
+ code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(char*)&m_szMsg,
0, NULL);
@@ -95,7 +95,7 @@ const wchar_t* Win32Error::WhatW() const noexcept
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- dwErr,
+ code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(wchar_t*)&m_wszMsg,
0, NULL);
@@ -104,9 +104,9 @@ const wchar_t* Win32Error::WhatW() const noexcept
/* Library: Wrapper for loading and freeing dynamically linked libraries. */
-Library::Library(const wchar_t* const wszLibrary)
+Library::Library(const wchar_t* const lib)
{
- m_hModule = LoadLibrary(wszLibrary);
+ m_hModule = LoadLibrary(lib);
if (!m_hModule)
throw Win32Error();
}
diff --git a/c/common.h b/c/common.h
index e63095b..39fa9b8 100644
--- a/c/common.h
+++ b/c/common.h
@@ -14,30 +14,30 @@
struct wstring_owner
{
wstring_owner();
- wstring_owner(wchar_t* wsz);
- wstring_owner& operator=(wchar_t* wsz);
- wstring_owner(wstring_owner& wso) = delete;
- wstring_owner& operator=(wstring_owner& wso) = delete;
- wstring_owner(wstring_owner&& wso) noexcept;
- wstring_owner& operator=(wstring_owner&& wso) noexcept;
+ wstring_owner(wchar_t* s);
+ wstring_owner& operator=(wchar_t* s);
+ wstring_owner(wstring_owner& other) = delete;
+ wstring_owner& operator=(wstring_owner& other) = delete;
+ wstring_owner(wstring_owner&& other) noexcept;
+ wstring_owner& operator=(wstring_owner&& other) noexcept;
wchar_t *release();
operator bool() const;
~wstring_owner();
wchar_t* p = nullptr;
};
-wstring_owner WsoFromSz(const char* sz, int iCp = CP_UTF8);
+wstring_owner WsoFromSz(const char* buf, int cp = CP_UTF8);
int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
-wstring_owner WsoCopy(const wchar_t* wsz);
+wstring_owner WsoCopy(const wchar_t* s);
struct Win32Error : public std::exception
{
Win32Error();
- Win32Error(DWORD dwErr);
+ Win32Error(DWORD code);
~Win32Error();
const char* what() const noexcept;
const wchar_t* WhatW() const noexcept;
- DWORD dwErr;
+ DWORD code;
private:
char* m_szMsg = NULL;
wchar_t* m_wszMsg = NULL;
@@ -45,7 +45,7 @@ private:
struct Library
{
- Library(const wchar_t* wszLibrary);
+ Library(const wchar_t* lib);
~Library();
template <class T> T* GetProcAddress(const char* szProc);
private:
@@ -59,9 +59,9 @@ T* Library::GetProcAddress(const char* const szProc)
}
template<size_t N, typename... T>
-inline int wszf(wchar_t (&wsz)[N], const wchar_t* const wszFmt, T... xs)
+inline int wszf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
{
- return _snwprintf_s(wsz, N, _TRUNCATE, wszFmt, xs...);
+ return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...);
}
/* Create and return an object of type C. If construction fails,
@@ -103,8 +103,8 @@ inline T prefer(const T x)
/* Return integer scaled for current DPI. */
inline int Dpi(const int i)
{
- extern int g_iDPI;
- return MulDiv(i, g_iDPI, 96);
+ extern int g_dpi;
+ return MulDiv(i, g_dpi, 96);
}
inline int Cmp(const int a, const int b)
@@ -115,10 +115,10 @@ inline int Cmp(const int a, const int b)
}
/* Get window rectangle relative to parent. */
-inline BOOL GetRelativeRect(const HWND hWnd, RECT* const pRr)
+inline BOOL GetRelativeRect(const HWND hWnd, RECT* const rr)
{
- if (!GetClientRect(hWnd, pRr)) return 0;
- return MapWindowPoints(hWnd, GetParent(hWnd), (POINT*)pRr, 2);
+ if (!GetClientRect(hWnd, rr)) return 0;
+ return MapWindowPoints(hWnd, GetParent(hWnd), (POINT*)rr, 2);
}
inline BOOL SetWindowRect(const HWND hWnd,
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index 02a399f..dd59250 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -40,34 +40,34 @@ void DataListView::ResizeColumns(int w)
void DataListView::ShowEpisode(const int iEpisode)
{
- extern EpisodeListView* const g_pElv;
+ extern EpisodeListView* const g_elv;
ListView_DeleteAllItems(hWnd);
Frame f;
- const int iArity = 3;
- const term_t t = PL_new_term_refs(iArity);
+ const int arity = 3;
+ const term_t t = PL_new_term_refs(arity);
if (!PlPut(t, iEpisode)) return;
- Query q (NULL, PL_predicate("episode_datum", iArity, "episode_data"), t);
+ Query q (NULL, PL_predicate("episode_datum", arity, "episode_data"), t);
LVITEM lviKey = {LVIF_TEXT};
LVITEM lviValue = {LVIF_TEXT};
for (int i = 0; q.NextSolution(std::nothrow); i++) {
- wstring_owner wsoKey;
- wstring_owner wsoValue;
+ wstring_owner key;
+ wstring_owner value;
- if (!(PlGet(t+1, &wsoKey) && PlGet(t+2, &wsoValue)))
+ if (!(PlGet(t+1, &key) && PlGet(t+2, &value)))
continue;
lviKey.iItem = i;
lviKey.iSubItem = 0;
- lviKey.pszText = wsoKey.p;
+ lviKey.pszText = key.p;
ListView_InsertItem(hWnd, &lviKey);
lviValue.iItem = i;
lviValue.iSubItem = 1;
- lviValue.pszText = wsoValue.p;
+ lviValue.pszText = value.p;
ListView_SetItem(hWnd, &lviValue);
}
@@ -76,7 +76,7 @@ void DataListView::ShowEpisode(const int iEpisode)
LVFINDINFO lvfi;
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
- int iItem = ListView_FindItem(g_pElv->hWnd, -1, &lvfi);
+ int iItem = ListView_FindItem(g_elv->hWnd, -1, &lvfi);
if (iItem != -1)
- ListView_EnsureVisible(g_pElv->hWnd, iItem, TRUE);
+ ListView_EnsureVisible(g_elv->hWnd, iItem, TRUE);
}
diff --git a/c/debug.cpp b/c/debug.cpp
index e22234a..07006a9 100644
--- a/c/debug.cpp
+++ b/c/debug.cpp
@@ -10,16 +10,16 @@ struct Avg {
long long sum;
};
-static long long llFrequency;
+static long long freq;
-Benchmark::Benchmark(const char* const szName, const int iId, const int iAvgMax)
- : id(iId), avgmax(iAvgMax), name(szName)
+Benchmark::Benchmark(const char* const name, const int id, const int avgmax)
+ : id(id), avgmax(avgmax), name(name)
{
- if (!llFrequency) {
- static LARGE_INTEGER liFrequency;
- if (!QueryPerformanceFrequency(&liFrequency))
+ if (!freq) {
+ static LARGE_INTEGER liFreq;
+ if (!QueryPerformanceFrequency(&liFreq))
throw Win32Error();
- llFrequency = liFrequency.QuadPart;
+ freq = liFreq.QuadPart;
}
LARGE_INTEGER liTicks;
@@ -42,32 +42,32 @@ Benchmark::~Benchmark()
if (!QueryPerformanceCounter(&liTicks))
return;
- long long ll = liTicks.QuadPart-ticks;
- ll *= 1'000'000;
- ll /= llFrequency;
+ long long dif = liTicks.QuadPart-ticks;
+ dif *= 1'000'000;
+ dif /= freq;
- static Avg aAvg[256] = {0};
- for (size_t i = 0; i < sizeof(aAvg)/sizeof(*aAvg); i++) {
- Avg& avg = aAvg[i];
+ static Avg avgs[256] = {0};
+ for (size_t i = 0; i < sizeof(avgs)/sizeof(*avgs); i++) {
+ Avg& avg = avgs[i];
if (avg.id == id || !avg.id) {
avg.id = id;
if (avg.count < avgmax) {
avg.count++;
- avg.sum += ll;
+ avg.sum += dif;
} else {
avg.count = 1;
- avg.sum = ll;
+ avg.sum = dif;
}
printf("%s: %lld (%lld)\n",
- name, ll, avg.sum/avg.count);
+ name, dif, avg.sum/avg.count);
break;
}
}
}
-const char* SzFromUmsg(const unsigned uMsg)
+const char* MsgName(const unsigned uMsg)
{
- static const unsigned aKeyMsg[] = {
+ static const unsigned vKey[] = {
0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
@@ -94,7 +94,7 @@ const char* SzFromUmsg(const unsigned uMsg)
911, 1024
};
- static const char* const aValueMsg[] = {
+ static const char* const vValue[] = {
"WM_NUL", "WM_CREATE", "WM_DESTROY", "WM_MOVE", "WM_SIZE",
"WM_ACTIVATE", "WM_SETFOCUS", "WM_KILLFOCUS", "WM_ENABLE",
"WM_SETREDRAW", "WM_SETTEXT", "WM_GETTEXT",
@@ -192,11 +192,11 @@ const char* SzFromUmsg(const unsigned uMsg)
"WM_CTLINIT", "WM_PENEVENT", "WM_PENWINLAST", "WM_USER"
};
- static const char* const szUnknown = "unknown message";
+ static const char* const unknown = "unknown message";
- for (size_t i = 0; i < sizeof(aKeyMsg)/sizeof(*aKeyMsg); i++)
- if (aKeyMsg[i] == uMsg) {
- return aValueMsg[i];
+ for (size_t i = 0; i < sizeof(vKey)/sizeof(*vKey); i++)
+ if (vKey[i] == uMsg) {
+ return vValue[i];
}
- return szUnknown;
+ return unknown;
}
diff --git a/c/debug.h b/c/debug.h
index d539573..83ff289 100644
--- a/c/debug.h
+++ b/c/debug.h
@@ -3,7 +3,7 @@
struct Benchmark
{
- Benchmark(const char* szName, int iId, int iAvgMax);
+ Benchmark(const char* name, int id, int avgmax);
~Benchmark();
void Disable();
long long ticks;
@@ -13,6 +13,6 @@ struct Benchmark
const char* name;
};
-const char* SzFromUmsg(unsigned uMsg);
+const char* MsgName(unsigned uMsg);
#endif
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index ffd8879..1c5c9ae 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -31,8 +31,8 @@ EpisodeListView::EpisodeListView(const HWND hWndParent)
lvc.cx = Dpi(30);
ListView_InsertColumn(hWnd, ELVSIRATING, &lvc);
- if (!Pl("cfg","get_sort",&m_iSort))
- m_iSort = 1;
+ if (!Pl("cfg","get_sort",&m_iSortCol))
+ m_iSortCol = 1;
}
void EpisodeListView::EnsureFocusVisible()
@@ -44,30 +44,30 @@ void EpisodeListView::EnsureFocusVisible()
LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
{
- const NMLISTVIEW* const pNmLv = (NMLISTVIEW*)lParam;
+ const NMLISTVIEW* const nm = (NMLISTVIEW*)lParam;
- switch (pNmLv->hdr.code) {
+ switch (nm->hdr.code) {
case LVN_ITEMCHANGED: /* Select/focus episode. */
- if ((pNmLv->uChanged & LVIF_STATE) &&
- (pNmLv->uNewState & LVIS_FOCUSED)) {
- extern DataListView* const g_pDlv;
- UpdateItem(pNmLv->iItem, pNmLv->lParam);
- g_pDlv->ShowEpisode(pNmLv->lParam);
+ if ((nm->uChanged & LVIF_STATE) &&
+ (nm->uNewState & LVIS_FOCUSED)) {
+ extern DataListView* const g_dlv;
+ UpdateItem(nm->iItem, nm->lParam);
+ g_dlv->ShowEpisode(nm->lParam);
}
break;
case LVN_COLUMNCLICK: /* Sort by column. */
{
- const int iColumn = pNmLv->iSubItem+1;
- m_iSort = abs(m_iSort) == iColumn? -m_iSort: iColumn;
- Pl("cfg","set_sort",m_iSort);
+ const int iColumn = nm->iSubItem+1;
+ m_iSortCol = abs(m_iSortCol) == iColumn? -m_iSortCol: iColumn;
+ Pl("cfg","set_sort",m_iSortCol);
Sort();
ShowFocus();
break;
}
case LVN_KEYDOWN: /* Navigate episodes by keyboard. */
{
- const NMLVKEYDOWN *const pNmLvKd = (NMLVKEYDOWN*)lParam;
- switch (pNmLvKd->wVKey) {
+ const NMLVKEYDOWN *const nm = (NMLVKEYDOWN*)lParam;
+ switch (nm->wVKey) {
case VK_LEFT:
SelectUnwatched(-1);
break;
@@ -79,16 +79,16 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
}
case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */
{
- const NMLVCUSTOMDRAW* const pLvCd = (NMLVCUSTOMDRAW*)lParam;
- switch (pLvCd->nmcd.dwDrawStage) {
+ const NMLVCUSTOMDRAW* const nm = (NMLVCUSTOMDRAW*)lParam;
+ switch (nm->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
extern HFONT g_hfBold;
- if (!Pl("track_episodes","watched",pLvCd->nmcd.lItemlParam)) {
- require(SelectObject(pLvCd->nmcd.hdc, g_hfBold));
+ if (!Pl("track_episodes","watched",nm->nmcd.lItemlParam)) {
+ require(SelectObject(nm->nmcd.hdc, g_hfBold));
return CDRF_NEWFONT;
}
break;
@@ -114,10 +114,10 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
}
case NM_RCLICK:
{
- extern HMENU g_hPopupMenu;
- const DWORD dwPos = GetMessagePos();
- require(TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
- LOWORD(dwPos), HIWORD(dwPos), 0,
+ extern HMENU g_hMenuPopup;
+ const DWORD pos = GetMessagePos();
+ require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON,
+ LOWORD(pos), HIWORD(pos), 0,
m_hWndParent, (const RECT*)NULL));
break;
}
@@ -135,10 +135,10 @@ void EpisodeListView::Redraw()
void EpisodeListView::ResizeColumns(int w)
{
ListView_SetColumnWidth(hWnd, ELVSIEPISODE, LVSCW_AUTOSIZE);
- int cxColumn = ListView_GetColumnWidth(hWnd, ELVSIEPISODE)+Dpi(4);
- ListView_SetColumnWidth(hWnd, ELVSIEPISODE, cxColumn);
- cxColumn += ListView_GetColumnWidth(hWnd, ELVSIRATING);
- ListView_SetColumnWidth(hWnd, ELVSITITLE, w-cxColumn-Metric<SM_CXVSCROLL>-Dpi(4));
+ int cx = ListView_GetColumnWidth(hWnd, ELVSIEPISODE)+Dpi(4);
+ ListView_SetColumnWidth(hWnd, ELVSIEPISODE, cx);
+ cx += ListView_GetColumnWidth(hWnd, ELVSIRATING);
+ ListView_SetColumnWidth(hWnd, ELVSITITLE, w-cx-Metric<SM_CXVSCROLL>-Dpi(4));
}
/* Select previously focused episode. */
@@ -146,7 +146,7 @@ void EpisodeListView::RestoreFocus()
{
int i, iEpisode, iItem;
LVFINDINFO lvfi;
- extern DataListView* const g_pDlv;
+ extern DataListView* const g_dlv;
iItem = 0;
if (!Pl("cfg","get_focus",&iEpisode)) return;
@@ -167,7 +167,7 @@ void EpisodeListView::RestoreFocus()
return;
s: UpdateItem(iItem, iEpisode);
- g_pDlv->ShowEpisode(iEpisode);
+ g_dlv->ShowEpisode(iEpisode);
ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED);
SetTop(iItem > 5? iItem-5: 0);
ListView_SetItemState(hWnd, iItem,
@@ -183,13 +183,13 @@ void EpisodeListView::SaveFocus()
void EpisodeListView::SetTop(const int iItem)
{
- const int iLast = ListView_GetItemCount(hWnd)-1;
- ListView_EnsureVisible(hWnd, iLast, TRUE);
+ const int iItemLast = ListView_GetItemCount(hWnd)-1;
+ ListView_EnsureVisible(hWnd, iItemLast, TRUE);
ListView_EnsureVisible(hWnd, iItem, TRUE);
}
/* Select next/previous unwatched episode. */
-void EpisodeListView::SelectUnwatched(int iDir)
+void EpisodeListView::SelectUnwatched(int dir)
{
/* Get focused episode. */
LVITEM lviFocus = {LVIF_PARAM, -1};
@@ -203,7 +203,7 @@ void EpisodeListView::SelectUnwatched(int iDir)
lvfi.lParam = lviFocus.lParam;
do {
- if (!Pl("track_episodes",iDir > 0? "next_unwatched": "previous_unwatched",
+ if (!Pl("track_episodes",dir > 0? "next_unwatched": "previous_unwatched",
lvfi.lParam,&iEpNew))
return;
@@ -233,47 +233,47 @@ void EpisodeListView::Sort()
ListView_SortItemsEx(hWnd, EpisodeListView::SortProc, (LPARAM)this);
}
-int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExtra)
+int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, const LPARAM extra)
{
- EpisodeListView* const pElv = (EpisodeListView*)lExtra;
+ EpisodeListView* const elv = (EpisodeListView*)extra;
LVITEM lvi1 = {LVIF_PARAM, (int)iItem1};
- if (!ListView_GetItem(pElv->hWnd, &lvi1)) return 0;
+ if (!ListView_GetItem(elv->hWnd, &lvi1)) return 0;
LVITEM lvi2 = {LVIF_PARAM, (int)iItem2};
- if (!ListView_GetItem(pElv->hWnd, &lvi2)) return 0;
+ if (!ListView_GetItem(elv->hWnd, &lvi2)) return 0;
- /* abs(m_iSort) is the 1-based index of the column to sort by.
- * If m_iSort is negative, the order is descending. */
- const int iOrder = Cmp(pElv->m_iSort, 0);
+ /* abs(m_iSortCol) is the 1-based index of the column to sort by.
+ * If m_iSortCol is negative, the order is descending. */
+ const int order = Cmp(elv->m_iSortCol, 0);
- switch (abs(pElv->m_iSort)-1) {
+ switch (abs(elv->m_iSortCol)-1) {
case ELVSIEPISODE:
- return iOrder*Cmp(lvi1.lParam, lvi2.lParam);
+ return order*Cmp(lvi1.lParam, lvi2.lParam);
case ELVSIRATING:
{
- int iRating1, iRating2;
- iRating1 = pElv->m_iSort > 0? 99: -1;
- iRating2 = pElv->m_iSort > 0? 99: -1;
- Pl("episode_data","episode_rating",lvi1.lParam,&iRating1);
- Pl("episode_data","episode_rating",lvi2.lParam,&iRating2);
- if (iRating1 == iRating2)
+ int rating1, rating2;
+ rating1 = elv->m_iSortCol > 0? 99: -1;
+ rating2 = elv->m_iSortCol > 0? 99: -1;
+ Pl("episode_data","episode_rating",lvi1.lParam,&rating1);
+ Pl("episode_data","episode_rating",lvi2.lParam,&rating2);
+ if (rating1 == rating2)
return Cmp(lvi1.lParam, lvi2.lParam);
- return iOrder*Cmp(iRating1, iRating2);
+ return order*Cmp(rating1, rating2);
}
case ELVSITITLE:
{
Mark m;
- wstring_owner wso1, wso2;
+ wstring_owner s1, s2;
int cch, cch1, cch2;
- if (!Pl("episode_data","episode_title",lvi1.lParam,&wso1))
+ if (!Pl("episode_data","episode_title",lvi1.lParam,&s1))
return 0;
- if (!Pl("episode_data","episode_title",lvi2.lParam,&wso2))
+ if (!Pl("episode_data","episode_title",lvi2.lParam,&s2))
return 0;
- cch1 = wcslen(wso1.p);
- cch2 = wcslen(wso2.p);
+ cch1 = wcslen(s1.p);
+ cch2 = wcslen(s2.p);
cch = cch1 > cch2? cch2: cch1;
- return iOrder*_wcsnicmp(wso1.p, wso2.p, cch);
+ return order*_wcsnicmp(s1.p, s2.p, cch);
}
default:
return 0;
@@ -320,15 +320,15 @@ void EpisodeListView::Update()
int cItem = 0;
{
- wchar_t wszEpisode[16];
+ wchar_t siEp[16];
LVITEM lviEpisode = {LVIF_TEXT|LVIF_PARAM};
for (int iEp = 1; iEp <= cEp; iEp++) {
- extern char g_szLimitScreenwriter[];
+ extern char g_currentScreenwriter[];
extern int g_bViewTVOriginal, g_bViewWatched;
- if (g_szLimitScreenwriter[0]
+ if (g_currentScreenwriter[0]
&& !Pl("episode_data","episode_datum",
- iEp,"Screenwriter",g_szLimitScreenwriter))
+ iEp,"Screenwriter",g_currentScreenwriter))
continue;
if (!g_bViewWatched)
@@ -337,12 +337,12 @@ void EpisodeListView::Update()
if (!g_bViewTVOriginal)
if (Pl("episode_data","tv_original",iEp)) continue;
- swprintf_s(wszEpisode, sizeof(wszEpisode)/sizeof(*wszEpisode), L"%d", iEp);
+ swprintf_s(siEp, sizeof(siEp)/sizeof(*siEp), L"%d", iEp);
/* Insert item. */
lviEpisode.iItem = cItem++;
lviEpisode.iSubItem = ELVSIEPISODE;
- lviEpisode.pszText = wszEpisode;
+ lviEpisode.pszText = siEp;
lviEpisode.lParam = iEp;
ListView_InsertItem(hWnd, &lviEpisode);
UpdateItem(lviEpisode.iItem, lviEpisode.lParam);
@@ -394,9 +394,9 @@ void EpisodeListView::Update()
/* Show number of displayed items in status bar. */
extern HWND g_hWndStatus;
- wchar_t wszDisp[16];
- swprintf_s(wszDisp, sizeof(wszDisp)/sizeof(*wszDisp), L"%d", cItem);
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)wszDisp);
+ wchar_t disp[16];
+ swprintf_s(disp, sizeof(disp)/sizeof(*disp), L"%d", cItem);
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)disp);
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);
}
@@ -404,22 +404,22 @@ void EpisodeListView::Update()
/* Update episode name and rating. */
void EpisodeListView::UpdateItem(const int iItem, const LPARAM lParam)
{
- wstring_owner wsoName;
- if (!Pl("episode_data","episode_title",lParam,&wsoName)) {
+ wstring_owner name;
+ if (!Pl("episode_data","episode_title",lParam,&name)) {
if (!Pl("episode_data","update_episode_data")) goto r;
- if (!Pl("episode_data","episode_title",lParam,&wsoName)) goto r;
+ if (!Pl("episode_data","episode_title",lParam,&name)) goto r;
}
- ListView_SetItemText(hWnd, iItem, ELVSITITLE, wsoName.p);
+ ListView_SetItemText(hWnd, iItem, ELVSITITLE, name.p);
-r: int iRating;
- if (!Pl("episode_data","episode_rating",lParam,&iRating)) {
+r: int rating;
+ if (!Pl("episode_data","episode_rating",lParam,&rating)) {
ListView_SetItemText(hWnd, iItem, ELVSIRATING, (wchar_t*)L"");
return;
}
- wchar_t wszRating[3];
- swprintf_s(wszRating, sizeof(wszRating)/sizeof(*wszRating), L"%d", iRating);
- ListView_SetItemText(hWnd, iItem, ELVSIRATING, wszRating);
+ wchar_t sRating[3];
+ swprintf_s(sRating, sizeof(sRating)/sizeof(*sRating), L"%d", rating);
+ ListView_SetItemText(hWnd, iItem, ELVSIRATING, sRating);
}
LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg,
@@ -433,7 +433,7 @@ LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg,
* along to the main window procedure, so that it may be
* handled by the NM_RETURN case in HandleNotify. */
- const LRESULT lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
+ const LRESULT lResult = CallWindowProc(m_proc0, hWnd, uMsg, wParam, lParam);
if (lParam && ((MSG*)lParam)->message == WM_KEYDOWN
&& ((MSG*)lParam)->wParam == VK_RETURN)
return DLGC_WANTMESSAGE;
diff --git a/c/episodelistview.h b/c/episodelistview.h
index 8a96096..420d038 100644
--- a/c/episodelistview.h
+++ b/c/episodelistview.h
@@ -20,15 +20,15 @@ struct EpisodeListView : public ListView
void RestoreFocus();
void SaveFocus();
void SetTop(int iItem);
- void SelectUnwatched(int iDir);
+ void SelectUnwatched(int dir);
void ShowFocus();
void Sort();
void Update();
void UpdateItem(int iItem, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
private:
- int m_iSort;
- static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lExtra);
+ int m_iSortCol;
+ static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM extra);
};
#endif
diff --git a/c/listview.cpp b/c/listview.cpp
index b4a61b4..6dfa888 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -22,7 +22,7 @@ ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle
m_hWndParent, hMenu, GetModuleHandle(NULL), this));
if (require(SetProp(hWnd, L"this", (HANDLE)this)))
- m_prevProc = (WNDPROC)SetWindowLongPtr(hWnd,
+ m_proc0 = (WNDPROC)SetWindowLongPtr(hWnd,
GWLP_WNDPROC, (LONG_PTR)::WndProc);
ListView_SetExtendedListViewStyle(hWnd, LVS_EX_FULLROWSELECT);
@@ -42,8 +42,8 @@ int ListView::Height(int bHeader)
{
if (bHeader == -1)
bHeader = m_bHeader;
- const int iCount = ListView_GetItemCount(hWnd);
- return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0;
+ const int cItem = ListView_GetItemCount(hWnd);
+ return cItem? Dpi(bHeader? 27: 4)+cItem*Dpi(19): 0;
}
void ListView::ResizeColumns(int) {}
@@ -51,29 +51,29 @@ void ListView::ResizeColumns(int) {}
void ListView::UpdateTheme(const BOOL bThemeActive)
{
DWORD dwStyle;
- const wchar_t* wszTheme;
- WORD wAction;
+ const wchar_t* theme;
+ WORD action;
extern int g_bThemes;
if (!g_bThemes) return;
if (bThemeActive) {
dwStyle = LVS_EX_DOUBLEBUFFER;
- wszTheme = L"Explorer";
- wAction = UIS_SET;
+ theme = L"Explorer";
+ action = UIS_SET;
} else {
dwStyle = 0;
- wszTheme = NULL;
- wAction = UIS_CLEAR;
+ theme = NULL;
+ action = UIS_CLEAR;
}
/* Use modern "Explorer" theme. */
- SetWindowTheme(hWnd, wszTheme, NULL);
+ SetWindowTheme(hWnd, theme, NULL);
/* The modern theme requires double buffering. */
ListView_SetExtendedListViewStyleEx(hWnd, LVS_EX_DOUBLEBUFFER, dwStyle);
/* Hide focus rectangles. */
- SendMessage(hWnd, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0);
+ SendMessage(hWnd, WM_UPDATEUISTATE, MAKEWPARAM(action, UISF_HIDEFOCUS), 0);
}
LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
@@ -89,16 +89,16 @@ LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
break;
}
- return CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
+ return CallWindowProc(m_proc0, hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
const LPARAM lParam)
{
- ListView* const pLv = (ListView*)GetProp(hWnd, L"this");
+ ListView* const lv = (ListView*)GetProp(hWnd, L"this");
if (uMsg == WM_DESTROY)
RemoveProp(hWnd, L"this");
- return pLv? pLv->WndProc(hWnd, uMsg, wParam, lParam): FALSE;
+ return lv? lv->WndProc(hWnd, uMsg, wParam, lParam): FALSE;
}
diff --git a/c/listview.h b/c/listview.h
index 858b156..84ad9d5 100644
--- a/c/listview.h
+++ b/c/listview.h
@@ -16,7 +16,7 @@ struct ListView
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
protected:
int m_bHeader = 1;
- WNDPROC m_prevProc;
+ WNDPROC m_proc0;
HWND m_hWndParent;
};
diff --git a/c/main.cpp b/c/main.cpp
index 7af5a0b..f896ef3 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -13,14 +13,14 @@
/* Looked-up constants. */
int g_bThemes;
-int g_iDPI = 96;
+int g_dpi = 96;
/* Fonts. */
HFONT g_hfNormal;
HFONT g_hfBold;
/* Menus. */
-HMENU g_hPopupMenu;
+HMENU g_hMenuPopup;
/* Windows. */
HWND g_hWndFocus;
@@ -28,13 +28,13 @@ HWND g_hWnd;
HWND g_hWndStatus;
/* Child window objects. */
-DataListView* g_pDlv;
-EpisodeListView* g_pElv;
+DataListView* g_dlv;
+EpisodeListView* g_elv;
/* View settings. */
int g_bViewWatched = 1;
int g_bViewTVOriginal = 1;
-char g_szLimitScreenwriter[64];
+char g_currentScreenwriter[64];
static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM);
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
@@ -46,28 +46,28 @@ static void UpdateTheme();
void OnTerminate() noexcept
{
- const wchar_t* wszWhat = L"an exception";
- wstring_owner wsoWhy;
+ const wchar_t* what = L"an exception";
+ wstring_owner why;
try {
std::rethrow_exception(std::current_exception());
} catch (const term_t& t) {
- wszWhat = L"a Prolog exception";
- try { wsoWhy = PlString(t); } catch (...) {}
+ what = L"a Prolog exception";
+ try { why = PlString(t); } catch (...) {}
} catch (const Win32Error& e) {
- wszWhat = L"a Windows error";
- try { wsoWhy = WsoCopy(e.WhatW()); } catch (...) {}
+ what = L"a Windows error";
+ try { why = WsoCopy(e.WhatW()); } catch (...) {}
} catch (const std::exception& e) {
- try { wsoWhy = WsoFromSz(e.what()); } catch (...) {}
+ try { why = WsoFromSz(e.what()); } catch (...) {}
} catch (...) {}
- wchar_t wsz[256] = {0};
- if (wsoWhy)
- wszf(wsz, L"Episode Browser was terminated due to %s: %s", wszWhat, wsoWhy.p);
+ wchar_t msg[256] = {0};
+ if (why)
+ wszf(msg, L"Episode Browser was terminated due to %s: %s", what, why.p);
else
- wszf(wsz, L"Episode Browser was terminated due to %s.", wszWhat);
+ wszf(msg, L"Episode Browser was terminated due to %s.", what);
- MessageBox(g_hWnd, wsz, L"Fatal Error", MB_ICONERROR);
+ MessageBox(g_hWnd, msg, L"Fatal Error", MB_ICONERROR);
_Exit(1);
}
@@ -89,8 +89,8 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
icc.dwICC = ICC_WIN95_CLASSES;
require(InitCommonControlsEx(&icc));
- g_hPopupMenu = require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU)));
- g_hPopupMenu = require(GetSubMenu(g_hPopupMenu, 0));
+ g_hMenuPopup = require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU)));
+ g_hMenuPopup = require(GetSubMenu(g_hMenuPopup, 0));
WNDCLASSEX wc;
memset(&wc, 0, sizeof(WNDCLASSEX));
@@ -131,8 +131,8 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
/* Populate episode list view. */
Pl("track_episodes","update_tracked_episodes");
- g_pElv->Update();
- g_pElv->RestoreFocus();
+ g_elv->Update();
+ g_elv->RestoreFocus();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
@@ -157,16 +157,16 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
g_hWnd = (HWND)wParam;
/* Look up constants. */
- if (auto opLib = maybe_make<Library>(L"User32.dll");
- auto GetDpiForWindow = opLib->GetProcAddress<UINT(HWND)>("GetDpiForWindow"))
- g_iDPI = GetDpiForWindow(g_hWnd);
+ if (auto lib = maybe_make<Library>(L"User32.dll");
+ auto GetDpiForWindow = lib->GetProcAddress<UINT(HWND)>("GetDpiForWindow"))
+ g_dpi = GetDpiForWindow(g_hWnd);
- if (auto opLib = maybe_make<Library>(L"uxtheme.dll");
- opLib->GetProcAddress<void>("SetWindowTheme"))
+ if (auto lib = maybe_make<Library>(L"uxtheme.dll");
+ lib->GetProcAddress<void>("SetWindowTheme"))
g_bThemes = 1;
- if (auto opLib = maybe_make<Library>(L"User32.dll");
- opLib->GetProcAddress<void>("SystemParametersInfo" WA)) {
+ if (auto lib = maybe_make<Library>(L"User32.dll");
+ lib->GetProcAddress<void>("SystemParametersInfo" WA)) {
NONCLIENTMETRICS m;
m.cbSize = sizeof(NONCLIENTMETRICS);
require(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
@@ -181,15 +181,15 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
g_hfBold = require(CreateFontIndirect(&lf));
/* Create child windows. */
- g_pDlv = new DataListView(g_hWnd);
- g_pElv = new EpisodeListView(g_hWnd);
+ g_dlv = new DataListView(g_hWnd);
+ g_elv = new EpisodeListView(g_hWnd);
/* Get saved view settings. */
- char* sz;
+ char* s;
Pl("cfg","get_view_watched",&g_bViewWatched);
Pl("cfg","get_view_tv_original",&g_bViewTVOriginal);
- if (Pl("cfg","get_limit_screenwriter",&sz))
- strcpy_s(g_szLimitScreenwriter, sizeof(g_szLimitScreenwriter), sz);
+ if (Pl("cfg","get_limit_screenwriter",&s))
+ strcpy_s(g_currentScreenwriter, sizeof(g_currentScreenwriter), s);
return 0;
}
@@ -199,7 +199,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
case WM_CREATE:
UpdateTheme();
SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(412), SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
- SetFocus(g_pElv->hWnd);
+ SetFocus(g_elv->hWnd);
/* Set menu item checkmarks according to saved settings. */
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
@@ -207,13 +207,13 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
g_bViewTVOriginal? MF_CHECKED: MF_UNCHECKED);
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
- g_szLimitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
+ g_currentScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
- g_pElv->SaveFocus();
+ g_elv->SaveFocus();
PostQuitMessage(0);
break;
case WM_SIZE:
@@ -221,30 +221,27 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
UpdateLayout(LOWORD(lParam), HIWORD(lParam));
break;
case WM_GETMINMAXINFO:
- {
- MINMAXINFO* const pMMI = (MINMAXINFO*)lParam;
- pMMI->ptMinTrackSize.x = Dpi(220);
- pMMI->ptMinTrackSize.y = Dpi(220);
+ ((MINMAXINFO*)lParam)->ptMinTrackSize.x = Dpi(220);
+ ((MINMAXINFO*)lParam)->ptMinTrackSize.y = Dpi(220);
break;
- }
case WM_THEMECHANGED:
UpdateTheme();
UpdateLayout();
break;
case 0x02E0: /* WM_DPICHANGED */
{
- const RECT* const lpr = (RECT*)lParam;
+ const RECT* const r = (RECT*)lParam;
/* Update DPI and cached metrics. */
- g_iDPI = HIWORD(wParam);
+ g_dpi = HIWORD(wParam);
Metric<SM_CXVSCROLL> = GetSystemMetrics(SM_CXVSCROLL);
prefer(SetWindowPos(hWnd, (HWND)NULL,
- lpr->left, lpr->top,
- lpr->right-lpr->left,
- lpr->bottom-lpr->top,
+ r->left, r->top,
+ r->right-r->left,
+ r->bottom-r->top,
SWP_NOZORDER|SWP_NOACTIVATE));
- UpdateLayout(lpr->right-lpr->left, lpr->bottom-lpr->top);
+ UpdateLayout(r->right-r->left, r->bottom-r->top);
break;
}
case WM_ACTIVATE:
@@ -256,35 +253,35 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
case WA_CLICKACTIVE:
SetFocus(g_hWndFocus);
Pl("track_episodes","update_tracked_episodes");
- g_pElv->Redraw();
+ g_elv->Redraw();
}
break;
case WM_NOTIFY:
switch (((NMHDR*)lParam)->idFrom) {
case IDC_EPISODELISTVIEW:
- return g_pElv->HandleNotify(lParam);
+ return g_elv->HandleNotify(lParam);
}
break;
case WM_COMMAND:
{
- const unsigned short wCommand = LOWORD(wParam);
- switch (ID_GROUP(wCommand)) {
+ const unsigned short command = LOWORD(wParam);
+ switch (ID_GROUP(command)) {
case IDG_MENU:
- WndProcMainMenu(hWnd, wCommand);
+ WndProcMainMenu(hWnd, command);
break;
case IDG_CTX:
- WndProcContextMenu(hWnd, wCommand);
+ WndProcContextMenu(hWnd, command);
break;
}
break;
}
case WM_MENUSELECT:
{
- /* Look up status bar help for menu command. The help
+ /* Look up status bar tip for menu command. The tip
* strings are stored in arrays, whose indices
* correspond to the IDM_ values (see resource.h). */
- const wchar_t* aWszMenu[] = {
+ const wchar_t* vTipMenu[] = {
/*IDM_FILE_EXIT*/L"Close Episode Browser.",
/*IDM_FILE_REFRESH*/L"Quickly refresh episode list.",
/*IDM_FILE_FETCH_DATA*/L"Fetch episode data from the web (may take a few seconds).",
@@ -296,11 +293,11 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
/*IDM_VIEW_TV_ORIGINAL*/(g_bViewTVOriginal?
L"Click to hide TV original episodes.":
L"Click to show TV original episodes."),
- /*IDM_VIEW_OTHERS*/(g_szLimitScreenwriter?
+ /*IDM_VIEW_OTHERS*/(g_currentScreenwriter?
L"Click to hide episodes by other screenwriters.":
L"Click to show episodes by other screenwriters.")
};
- const wchar_t* aWszCtx[] = {
+ const wchar_t* vTipCtx[] = {
/*IDM_WATCH_LOCALLY*/L"Open local copy of episode, if available.",
/*IDM_WATCH_ONLINE*/L"Open episode in the web browser.",
/*IDM_TOGGLE*/L"Toggle watched/unwatched status.",
@@ -320,14 +317,14 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
/*IDM_RATE10*/L"Rate episode 10/10."
};
- const unsigned short wCommand = LOWORD(wParam);
- const unsigned short wGroup = ID_GROUP(wCommand);
- const wchar_t* wsz = {0};
- if (wGroup) {
- const wchar_t** aWsz = wGroup==IDG_MENU? aWszMenu: aWszCtx;
- wsz = aWsz[ID_INDEX(wCommand)];
+ const unsigned short command = LOWORD(wParam);
+ const unsigned short group = ID_GROUP(command);
+ const wchar_t* tip = {0};
+ if (group) {
+ const wchar_t** const vTip = group==IDG_MENU? vTipMenu: vTipCtx;
+ tip = vTip[ID_INDEX(command)];
}
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)wsz);
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)tip);
break;
}
default:
@@ -338,14 +335,14 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
}
/* Process main menu commands. */
-void WndProcMainMenu(const HWND hWnd, unsigned short wCommand)
+void WndProcMainMenu(const HWND hWnd, unsigned short command)
{
- switch (wCommand) {
+ switch (command) {
case IDM_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
case IDM_FILE_REFRESH:
- g_pElv->Update();
+ g_elv->Update();
break;
case IDM_FILE_FETCH_DATA:
WaitFor("episode_data","update_episode_data");
@@ -366,46 +363,46 @@ void WndProcMainMenu(const HWND hWnd, unsigned short wCommand)
g_bViewWatched? MF_UNCHECKED: MF_CHECKED);
g_bViewWatched = !g_bViewWatched;
Pl("cfg","set_view_watched",g_bViewWatched);
- g_pElv->Update();
- g_pElv->EnsureFocusVisible();
+ g_elv->Update();
+ g_elv->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();
+ g_elv->Update();
+ g_elv->EnsureFocusVisible();
break;
case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */
- if (g_szLimitScreenwriter[0]) {
+ if (g_currentScreenwriter[0]) {
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
MF_CHECKED);
- g_szLimitScreenwriter[0] = 0;
+ g_currentScreenwriter[0] = 0;
} else {
- const int iEpFocus = ListView_GetNextItem(g_pElv->hWnd, -1, LVNI_FOCUSED);
+ const int iEpFocus = ListView_GetNextItem(g_elv->hWnd, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
LVITEM lvi = {LVIF_PARAM, iEpFocus};
- if (!ListView_GetItem(g_pElv->hWnd, &lvi)) break;
+ if (!ListView_GetItem(g_elv->hWnd, &lvi)) break;
- char* sz;
- if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz))
+ char* s;
+ if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&s))
break;
- strcpy_s(g_szLimitScreenwriter,
- sizeof(g_szLimitScreenwriter), sz);
+ strcpy_s(g_currentScreenwriter,
+ sizeof(g_currentScreenwriter), s);
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
MF_UNCHECKED);
}
- Pl("cfg","set_limit_screenwriter",g_szLimitScreenwriter);
- g_pElv->Update();
- g_pElv->EnsureFocusVisible();
+ Pl("cfg","set_limit_screenwriter",g_currentScreenwriter);
+ g_elv->Update();
+ g_elv->EnsureFocusVisible();
break;
}
}
/* Process context menu commands. */
-void WndProcContextMenu(const HWND, unsigned short wCommand)
+void WndProcContextMenu(const HWND, unsigned short command)
{
int cNotFound = 0;
@@ -413,17 +410,17 @@ void WndProcContextMenu(const HWND, unsigned short wCommand)
* selected command to each one. */
LVITEM lvi = {LVIF_PARAM, -1};
- while (g_pElv->FindNextItem(&lvi, LVNI_SELECTED)) {
+ while (g_elv->FindNextItem(&lvi, LVNI_SELECTED)) {
/* Process rate commands. */
- if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) {
- Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(wCommand));
- g_pElv->UpdateItem(lvi.iItem, lvi.lParam);
+ if (ID_SUBGROUP(command) == IDG_CTX_RATE) {
+ Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(command));
+ g_elv->UpdateItem(lvi.iItem, lvi.lParam);
continue;
}
/* Process other commands. */
- switch (wCommand) {
+ switch (command) {
case IDM_WATCH_LOCALLY:
if (!Pl("local_episode","open_episode_locally",lvi.lParam))
cNotFound++;
@@ -440,8 +437,8 @@ void WndProcContextMenu(const HWND, unsigned short wCommand)
break;
case IDM_LOOKUP:
Pl("episode_data","retract_episode",lvi.lParam);
- g_pElv->UpdateItem(lvi.iItem, lvi.lParam);
- g_pDlv->ShowEpisode(lvi.lParam);
+ g_elv->UpdateItem(lvi.iItem, lvi.lParam);
+ g_dlv->ShowEpisode(lvi.lParam);
break;
case IDM_WIKI:
Pl("episode_data","open_episode_wiki",lvi.lParam);
@@ -449,38 +446,38 @@ void WndProcContextMenu(const HWND, unsigned short wCommand)
}
}
- g_pElv->Redraw();
+ g_elv->Redraw();
if (cNotFound == 1) {
EBMessageBox(L"Episode could not be opened locally.",
L"Error", MB_ICONWARNING);
} else if (cNotFound) {
- wchar_t wsz[64] = {0};
- wszf(wsz, L"%d episodes could not be opened locally.", cNotFound);
- EBMessageBox(wsz, L"Error", MB_ICONWARNING);
- } else if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) {
- g_pElv->Sort();
- g_pElv->ShowFocus();
+ wchar_t msg[64] = {0};
+ wszf(msg, L"%d episodes could not be opened locally.", cNotFound);
+ EBMessageBox(msg, L"Error", MB_ICONWARNING);
+ } else if (ID_SUBGROUP(command) == IDG_CTX_RATE) {
+ g_elv->Sort();
+ g_elv->ShowFocus();
}
}
/* Call Prolog predicate in other thread, if available. */
-void WaitFor(const char* szMod, const char* szPred)
+void WaitFor(const char* mod, const char* pred)
{
static atom_t aThread;
static int bActive;
static int iTimer;
- static wstring_owner wsoPred;
+ static wstring_owner activePred;
if (bActive) {
- wchar_t wsz[256] = {0};
- wszf(wsz, L"Another task (%s) is active. "
+ wchar_t msg[256] = {0};
+ wszf(msg, L"Another task (%s) is active. "
L"Do you want to cancel the existing task and start a new one?",
- wsoPred.p);
- if (EBMessageBox(wsz, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES)
+ activePred.p);
+ if (EBMessageBox(msg, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES)
return;
KillTimer(NULL, iTimer);
bActive = 0;
- g_pElv->Update();
+ g_elv->Update();
}
/* The timer procedure animates an ellipsis in the status bar
@@ -498,14 +495,14 @@ void WaitFor(const char* szMod, const char* szPred)
KillTimer(NULL, iTimer);
i = 0;
bActive = 0;
- g_pElv->Update();
+ g_elv->Update();
}
};
- Plx(szMod,"thread_create",szPred,&aThread);
+ Plx(mod,"thread_create",pred,&aThread);
SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L".");
if (prefer(iTimer = SetTimer(NULL, -1, 500, proc))) {
- wsoPred = WsoFromSz(szPred);
+ activePred = WsoFromSz(pred);
bActive = 1;
}
}
@@ -544,11 +541,11 @@ void UpdateLayout(int w, int h)
/* Resize list views. */
const long pad = IsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */
- const long cyDlv = rrStatus.top-g_pDlv->Height()-pad;
- require(SetWindowRect(g_pDlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad));
- require(SetWindowRect(g_pElv->hWnd, pad, pad, rc.right-pad, cyDlv-pad));
- g_pDlv->ResizeColumns(rc.right-pad-pad);
- g_pElv->ResizeColumns(rc.right-pad-pad);
+ const long cyDlv = rrStatus.top-g_dlv->Height()-pad;
+ require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad));
+ require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad));
+ g_dlv->ResizeColumns(rc.right-pad-pad);
+ g_elv->ResizeColumns(rc.right-pad-pad);
/* Resize status bar parts. */
const int aParts[] = {rc.right-Dpi(55), rc.right};
@@ -564,6 +561,6 @@ void UpdateTheme()
{
if (!g_bThemes) return;
const BOOL bThemeActive = IsThemeActive();
- g_pDlv->UpdateTheme(bThemeActive);
- g_pElv->UpdateTheme(bThemeActive);
+ g_dlv->UpdateTheme(bThemeActive);
+ g_elv->UpdateTheme(bThemeActive);
}
diff --git a/c/pl.cpp b/c/pl.cpp
index 1255609..e0c7971 100644
--- a/c/pl.cpp
+++ b/c/pl.cpp
@@ -90,11 +90,11 @@ int Query::NextSolution()
}
/* Convert Prolog term to wide characters. */
-wstring_owner PlString(const term_t t, const int iFlags)
+wstring_owner PlString(const term_t t, const int flags)
{
- char* sz;
- if (PL_get_chars(t, &sz, iFlags))
- return {WsoFromSz(sz)};
+ char* s;
+ if (PL_get_chars(t, &s, flags))
+ return {WsoFromSz(s)};
else
return {};
}
diff --git a/c/pl.h b/c/pl.h
index c7fcfc8..0a65c96 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -7,7 +7,7 @@
#include "common.h"
-wstring_owner PlString(const term_t t, const int iFlags = CVT_WRITE);
+wstring_owner PlString(const term_t t, const int flags = CVT_WRITE);
struct Frame
{
@@ -69,9 +69,9 @@ inline int PlGet(term_t t, atom_t* x) { return PL_get_atom(t, x); }
inline int PlGet(term_t t, char** x) { return PL_get_atom_chars(t, x); }
inline int PlGet(term_t t, wstring_owner* x) {
Mark m;
- char* sz;
- if (!PlGet(t, &sz)) return 0;
- *x = WsoFromSz(sz);
+ char* s;
+ if (!PlGet(t, &s)) return 0;
+ *x = WsoFromSz(s);
return 1; /* or catch potential exception from BstrFromSz? */
}
@@ -89,13 +89,13 @@ inline bool PlGetN(term_t t, T x, U... xs) { return PlGet(t, x) && PlGetN(t+1, x
/* Call Prolog predicate. */
template <bool Except = false, typename... T>
-int Pl(const char* const szMod, const char* const szPred, T... xs)
+int Pl(const char* const mod, const char* const pred, T... xs)
{
Frame f;
const term_t t = PL_new_term_refs(sizeof...(T));
if (!PlPutN(t, xs...)) return 0;
- Query q(NULL, PL_predicate(szPred, sizeof...(T), szMod), t);
+ Query q(NULL, PL_predicate(pred, sizeof...(T), mod), t);
if constexpr (Except) {
if (!q.NextSolution()) return 0;
@@ -109,9 +109,9 @@ int Pl(const char* const szMod, const char* const szPred, T... xs)
/* Call Prolog predicate, propagating Prolog exceptions. */
template <typename... T>
-int Plx(const char* const szMod, const char* const szPred, T... xs)
+int Plx(const char* const mod, const char* const pred, T... xs)
{
- return Pl<true>(szMod, szPred, xs...);
+ return Pl<true>(mod, pred, xs...);
}
#endif