diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-14 04:05:34 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-14 04:05:34 +0200 |
commit | 96f0accc818ad98abcb0d37e53d0a31e08ce4987 (patch) | |
tree | 0ff850793420b66cf78ac539d4dbe9f7c393ac11 | |
parent | 26f70ab37bee8ffd70b662ff999613c643215605 (diff) | |
download | EpisodeBrowser-96f0accc818ad98abcb0d37e53d0a31e08ce4987.tar.gz |
Minor formal changes.
Height(DLVSIKEY) was incorrect. The argument to Height is supposed to
be a boolean value, in this case false. It happened to work because
DLVSIKEY is 0 (because Key is the 0th column in the data list view).
-rw-r--r-- | c/defs.h | 6 | ||||
-rw-r--r-- | c/episodelistview.cpp | 31 | ||||
-rw-r--r-- | c/listview.cpp | 14 | ||||
-rw-r--r-- | c/main.cpp | 2 |
4 files changed, 25 insertions, 28 deletions
@@ -14,11 +14,12 @@ void UpdateLayout(); /* listview.cpp */ class ListView { protected: + int m_bHeader = 1; WNDPROC m_prevProc; HWND m_hWnd; public: ListView(HMENU, DWORD); - int Height(int); + int Height(int = -1); HWND HWnd(void) const; virtual void UpdateTheme(BOOL); virtual LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); @@ -29,6 +30,7 @@ class EpisodeListView : public ListView { private: int m_iSort; LVITEM m_lviFocus; + friend int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); public: EpisodeListView(void); void DoSort(void); @@ -43,7 +45,7 @@ public: void ShowFocus(void); void Update(void); void UpdateItem(LPLVITEM); - LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) override; }; /* datalistview.cpp */ diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index e34fb34..15d7ba4 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -7,7 +7,7 @@ #include "defs.h" extern DataListView *g_lpDlv; -static int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); +int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); EpisodeListView::EpisodeListView() : ListView((HMENU)IDC_EPISODELISTVIEW, 0) { @@ -141,12 +141,6 @@ EpisodeListView::HandleNotify(LPARAM lParam) return 0; } -int -EpisodeListView::ISort() const -{ - return m_iSort; -} - void EpisodeListView::Redraw() { @@ -419,36 +413,34 @@ EpisodeListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 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 -ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lpLv) +ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lExtra) { - EpisodeListView *lpThis = (EpisodeListView *)lpLv; + EpisodeListView *lpElv = (EpisodeListView *)lExtra; LVITEM lvi1, lvi2; lvi1.mask = lvi2.mask = LVIF_PARAM; lvi1.iItem = iItem1; lvi2.iItem = iItem2; - if (!ListView_GetItem(lpThis->HWnd(), &lvi1)) return 0; - if (!ListView_GetItem(lpThis->HWnd(), &lvi2)) return 0; + if (!ListView_GetItem(lpElv->HWnd(), &lvi1)) return 0; + if (!ListView_GetItem(lpElv->HWnd(), &lvi2)) return 0; - int iOrder = Cmp(lpThis->ISort(), 0); + /* abs(m_iSort) is the 1-based index of the column to sort by. + * If m_iSort is negative, the order is descending. */ + int iOrder = Cmp(lpElv->m_iSort, 0); - switch (abs(lpThis->ISort())-1) { + switch (abs(lpElv->m_iSort)-1) { case ELVSIEPISODE: return iOrder*Cmp(lvi1.lParam, lvi2.lParam); - break; case ELVSIRATING: { int iRating1, iRating2; - iRating1 = lpThis->ISort() > 0? 99: -1; - iRating2 = lpThis->ISort() > 0? 99: -1; + iRating1 = lpElv->m_iSort > 0? 99: -1; + iRating2 = lpElv->m_iSort > 0? 99: -1; Pl("episode_data","episode_rating","Ii",lvi1.lParam,&iRating1); Pl("episode_data","episode_rating","Ii",lvi2.lParam,&iRating2); if (iRating1 == iRating2) return Cmp(lvi1.lParam, lvi2.lParam); return iOrder*Cmp(iRating1, iRating2); - break; } case ELVSITITLE: { @@ -462,7 +454,6 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lpLv) cch2 = strlen(sz2); cch = cch1 > cch2? cch2: cch1; return iOrder*_strnicmp(sz1, sz2, cch); - break; } default: return 0; diff --git a/c/listview.cpp b/c/listview.cpp index 8e92ea1..b375454 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -11,12 +11,14 @@ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); ListView::ListView(HMENU hMenu, DWORD dwStyle) { + if (dwStyle & LVS_NOCOLUMNHEADER) + m_bHeader = 0; + m_hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, TEXT(""), - dwStyle - |WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS, + dwStyle|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS, 0, 0, 0, 0, g_hWnd, hMenu, GetModuleHandle(NULL), this ); @@ -34,6 +36,8 @@ ListView::ListView(HMENU hMenu, DWORD dwStyle) int ListView::Height(int bHeader) { + if (bHeader == -1) + bHeader = m_bHeader; int iCount = ListView_GetItemCount(m_hWnd); return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0; } @@ -89,7 +93,7 @@ ListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam); } -static LRESULT CALLBACK +LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -98,6 +102,6 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - ListView *lpThis = (ListView *)GetProp(hWnd, TEXT("this")); - return lpThis? lpThis->WndProc(hWnd, uMsg, wParam, lParam): FALSE; + ListView *lpLv = (ListView *)GetProp(hWnd, TEXT("this")); + return lpLv? lpLv->WndProc(hWnd, uMsg, wParam, lParam): FALSE; } @@ -522,7 +522,7 @@ UpdateLayout() /* Resize data list view. */ SendMessage(g_lpDlv->HWnd(), WM_SETREDRAW, FALSE, 0); SendMessage(g_lpElv->HWnd(), WM_SETREDRAW, FALSE, 0); - cyDlv = rc.bottom-yStatus-g_lpDlv->Height(DLVSIKEY); + 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; |