diff options
-rw-r--r-- | c/common.h | 30 | ||||
-rw-r--r-- | c/datalistview.cpp | 4 | ||||
-rw-r--r-- | c/datalistview.h | 6 | ||||
-rw-r--r-- | c/episodelistview.cpp | 4 | ||||
-rw-r--r-- | c/episodelistview.h | 8 | ||||
-rw-r--r-- | c/listview.cpp | 2 | ||||
-rw-r--r-- | c/listview.h | 2 | ||||
-rw-r--r-- | c/main.cpp | 40 | ||||
-rw-r--r-- | c/pl.h | 4 |
9 files changed, 51 insertions, 49 deletions
@@ -6,7 +6,14 @@ #include <stdexcept> #include <windows.h> +#ifdef UNICODE +#define WA "W" +#else +#define WA "A" +#endif + std::basic_string<TCHAR> TsmFromSz(const char *, int); + struct Win32Error : public std::exception { Win32Error(DWORD); @@ -16,6 +23,7 @@ private: DWORD m_dwErr; char *m_szMsg = NULL; }; + struct Library { Library(const TCHAR *); @@ -25,32 +33,28 @@ private: HMODULE m_hModule; }; -#ifdef UNICODE -#define WA "W" -#else -#define WA "A" -#endif - inline int Cmp(int a, int b) { - if (a == b) - return 0; - if (a > b) - return 1; + if (a == b) return 0; + if (a > b) return 1; return -1; } +/* Return integer scaled for current DPI. */ inline int Dpi(int i) { extern int g_iDPI; return MulDiv(i, g_iDPI, 96); } -template <class T, typename ...A> -std::optional<T> try_make(A ...args) +/* Create and return an object of type C. If construction fails, + * return nothing. The returned value must be checked before being + * used, as dereferencing is undefined if the value is empty. */ +template <class C, typename ...T> +std::optional<C> try_make(T ...args) { try { - return T(args...); + return C(args...); } catch (...) { return {}; } diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 2f184dc..f75fc99 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -71,7 +71,7 @@ void DataListView::ShowEpisode(int iEpisode) LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; - int iItem = ListView_FindItem(g_lpElv->HWnd(), -1, &lvfi); + int iItem = ListView_FindItem(g_lpElv->Handle(), -1, &lvfi); if (iItem != -1) - ListView_EnsureVisible(g_lpElv->HWnd(), iItem, TRUE); + ListView_EnsureVisible(g_lpElv->Handle(), iItem, TRUE); } diff --git a/c/datalistview.h b/c/datalistview.h index 7dd0447..de1bd81 100644 --- a/c/datalistview.h +++ b/c/datalistview.h @@ -3,13 +3,13 @@ #include "listview.h" +#define DLVSIKEY 0 +#define DLVSIVALUE 1 + struct DataListView : public ListView { DataListView(HWND); void ShowEpisode(int); }; -#define DLVSIKEY 0 -#define DLVSIVALUE 1 - #endif diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index a802f90..5003495 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -407,8 +407,8 @@ int CALLBACK ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lExtra) LVITEM lvi1, lvi2; lvi1.mask = lvi2.mask = LVIF_PARAM; lvi1.iItem = iItem1; lvi2.iItem = iItem2; - if (!ListView_GetItem(lpElv->HWnd(), &lvi1)) return 0; - if (!ListView_GetItem(lpElv->HWnd(), &lvi2)) return 0; + if (!ListView_GetItem(lpElv->Handle(), &lvi1)) return 0; + if (!ListView_GetItem(lpElv->Handle(), &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. */ diff --git a/c/episodelistview.h b/c/episodelistview.h index 141bf84..74fcf3d 100644 --- a/c/episodelistview.h +++ b/c/episodelistview.h @@ -6,6 +6,10 @@ #include "listview.h" +#define ELVSIEPISODE 0 +#define ELVSITITLE 1 +#define ELVSIRATING 2 + struct EpisodeListView : public ListView { EpisodeListView(HWND); @@ -28,8 +32,4 @@ private: friend int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); }; -#define ELVSIEPISODE 0 -#define ELVSITITLE 1 -#define ELVSIRATING 2 - #endif diff --git a/c/listview.cpp b/c/listview.cpp index 0f4cbc1..27529e0 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -40,7 +40,7 @@ int ListView::Height(int bHeader) return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0; } -HWND ListView::HWnd() const +HWND ListView::Handle() const { return m_hWnd; } diff --git a/c/listview.h b/c/listview.h index cf5dc26..e7cd68b 100644 --- a/c/listview.h +++ b/c/listview.h @@ -7,7 +7,7 @@ struct ListView { ListView(HWND, HMENU, DWORD); int Height(int = -1); - HWND HWnd(void) const; + HWND Handle(void) const; virtual void UpdateTheme(BOOL); virtual LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); protected: @@ -185,7 +185,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { UpdateTheme(); SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE); - SetFocus(g_lpElv->HWnd()); + SetFocus(g_lpElv->Handle()); /* Set menu item checkmarks according to saved settings. */ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, @@ -329,13 +329,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) MF_CHECKED); g_szLimitScreenwriter[0] = 0; } else { - iEpFocus = ListView_GetNextItem(g_lpElv->HWnd(), -1, LVNI_FOCUSED); + iEpFocus = ListView_GetNextItem(g_lpElv->Handle(), -1, LVNI_FOCUSED); if (iEpFocus == -1) break; LVITEM lvi; lvi.iItem = iEpFocus; lvi.mask = LVIF_PARAM; - if (!ListView_GetItem(g_lpElv->HWnd(), &lvi)) break; + if (!ListView_GetItem(g_lpElv->Handle(), &lvi)) break; char *sz; if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz)) @@ -377,8 +377,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) lvi.mask = LVIF_PARAM; lvi.iItem = -1; while ((lvi.iItem = ListView_GetNextItem( - g_lpElv->HWnd(), lvi.iItem, LVNI_SELECTED)) != -1) { - if (!ListView_GetItem(g_lpElv->HWnd(), &lvi)) goto b; + g_lpElv->Handle(), lvi.iItem, LVNI_SELECTED)) != -1) { + if (!ListView_GetItem(g_lpElv->Handle(), &lvi)) goto b; switch (LOWORD(wParam)) { case IDM_WATCH_LOCALLY: @@ -517,24 +517,24 @@ void UpdateLayout() yStatus = rcStatus.bottom-rcStatus.top; /* Resize data list view. */ - SendMessage(g_lpDlv->HWnd(), WM_SETREDRAW, FALSE, 0); - SendMessage(g_lpElv->HWnd(), WM_SETREDRAW, FALSE, 0); + SendMessage(g_lpDlv->Handle(), WM_SETREDRAW, FALSE, 0); + SendMessage(g_lpElv->Handle(), WM_SETREDRAW, FALSE, 0); cyDlv = rc.bottom-yStatus-g_lpDlv->Height(); - MoveWindow(g_lpDlv->HWnd(), 0, cyDlv, rc.right, rc.bottom-yStatus-cyDlv, TRUE); - ListView_SetColumnWidth(g_lpDlv->HWnd(), DLVSIKEY, LVSCW_AUTOSIZE); - cxColumn = ListView_GetColumnWidth(g_lpDlv->HWnd(), 0)+4; - ListView_SetColumnWidth(g_lpDlv->HWnd(), DLVSIKEY, cxColumn); - ListView_SetColumnWidth(g_lpDlv->HWnd(), DLVSIVALUE, rc.right-cxColumn-g_cxVScroll-4); + MoveWindow(g_lpDlv->Handle(), 0, cyDlv, rc.right, rc.bottom-yStatus-cyDlv, TRUE); + ListView_SetColumnWidth(g_lpDlv->Handle(), DLVSIKEY, LVSCW_AUTOSIZE); + cxColumn = ListView_GetColumnWidth(g_lpDlv->Handle(), 0)+4; + ListView_SetColumnWidth(g_lpDlv->Handle(), DLVSIKEY, cxColumn); + ListView_SetColumnWidth(g_lpDlv->Handle(), DLVSIVALUE, rc.right-cxColumn-g_cxVScroll-4); /* Resize episode list view. */ - MoveWindow(g_lpElv->HWnd(), 0, 0, rc.right, cyDlv+1, TRUE); - ListView_SetColumnWidth(g_lpElv->HWnd(), ELVSIEPISODE, LVSCW_AUTOSIZE); - cxColumn = ListView_GetColumnWidth(g_lpElv->HWnd(), ELVSIEPISODE)+4; - ListView_SetColumnWidth(g_lpElv->HWnd(), ELVSIEPISODE, cxColumn); - cxColumn += ListView_GetColumnWidth(g_lpElv->HWnd(), ELVSIRATING); - ListView_SetColumnWidth(g_lpElv->HWnd(), ELVSITITLE, rc.right-cxColumn-g_cxVScroll-4); - SendMessage(g_lpElv->HWnd(), WM_SETREDRAW, TRUE, 0); - SendMessage(g_lpDlv->HWnd(), WM_SETREDRAW, TRUE, 0); + MoveWindow(g_lpElv->Handle(), 0, 0, rc.right, cyDlv+1, TRUE); + ListView_SetColumnWidth(g_lpElv->Handle(), ELVSIEPISODE, LVSCW_AUTOSIZE); + cxColumn = ListView_GetColumnWidth(g_lpElv->Handle(), ELVSIEPISODE)+4; + ListView_SetColumnWidth(g_lpElv->Handle(), ELVSIEPISODE, cxColumn); + cxColumn += ListView_GetColumnWidth(g_lpElv->Handle(), ELVSIRATING); + ListView_SetColumnWidth(g_lpElv->Handle(), ELVSITITLE, rc.right-cxColumn-g_cxVScroll-4); + SendMessage(g_lpElv->Handle(), WM_SETREDRAW, TRUE, 0); + SendMessage(g_lpDlv->Handle(), WM_SETREDRAW, TRUE, 0); /* Resize status bar parts. */ int aParts[] = {rc.right-Dpi(55), rc.right}; @@ -6,6 +6,7 @@ int PL_get_tchars(term_t, TCHAR **, int); int Plx(const char *, const char *); + struct Query { Query(module_t ctx, predicate_t p, term_t t0); @@ -17,9 +18,6 @@ private: qid_t m_q; }; -#define DLVSIKEY 0 -#define DLVSIVALUE 1 - /* Polymorphic aliases for PL_put_*, PL_get_*. */ inline int PlPut(term_t t, int x) { return PL_put_integer(t, x); } inline int PlPut(term_t t, long x) { return PL_put_integer(t, x); } |