aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-23 00:16:42 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-23 00:16:42 +0200
commit97f0a27ab0cbf605ba789be553c0df3bb44a6787 (patch)
tree78d2c78343b43a8dcaab8df627af578ba9574b37
parent21e96c692595f204b91431a90123419e4a1780c4 (diff)
downloadEpisodeBrowser-97f0a27ab0cbf605ba789be553c0df3bb44a6787.tar.gz
Improve UpdateLayout and ResizeColumns.
This incidentally removes the need for the variable template introduced by 21e96c6. I'm sure it will be needed at some point, though.
-rw-r--r--c/common.h4
-rw-r--r--c/datalistview.cpp8
-rw-r--r--c/datalistview.h2
-rw-r--r--c/episodelistview.cpp9
-rw-r--r--c/episodelistview.h2
-rw-r--r--c/listview.cpp2
-rw-r--r--c/listview.h2
-rw-r--r--c/main.cpp13
8 files changed, 23 insertions, 19 deletions
diff --git a/c/common.h b/c/common.h
index c6c7dbd..5fe6d62 100644
--- a/c/common.h
+++ b/c/common.h
@@ -54,10 +54,6 @@ std::optional<T> maybe_make(U... xs)
}
}
-/* Variable template for caching values from GetSystemMetrics. */
-template <int I>
-const auto Metric = GetSystemMetrics(I);
-
/* Check result of Windows API call, throwing error on NULL. */
template <typename T>
inline T require(const T x)
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index 9ff4659..b728fa8 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -29,13 +29,15 @@ DataListView::DataListView(const HWND hWndParent)
ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc);
}
-void DataListView::ResizeColumns(RECT& rcParent)
+void DataListView::ResizeColumns()
{
- ListView_SetColumnWidth(hWnd, DLVSIKEY, LVSCW_AUTOSIZE);
+ RECT rc;
+ require(GetClientRect(hWnd, &rc));
+ ListView_SetColumnWidth(hWnd, DLVSIKEY, LVSCW_AUTOSIZE);
const int cxColumn = ListView_GetColumnWidth(hWnd, 0)+4;
ListView_SetColumnWidth(hWnd, DLVSIKEY, cxColumn);
- ListView_SetColumnWidth(hWnd, DLVSIVALUE, rcParent.right-cxColumn-Metric<SM_CXVSCROLL>-4);
+ ListView_SetColumnWidth(hWnd, DLVSIVALUE, rc.right-cxColumn);
}
void DataListView::ShowEpisode(const int iEpisode)
diff --git a/c/datalistview.h b/c/datalistview.h
index ad35f25..0bea546 100644
--- a/c/datalistview.h
+++ b/c/datalistview.h
@@ -9,7 +9,7 @@
struct DataListView : public ListView
{
DataListView(HWND hWndParent);
- void ResizeColumns(RECT& rcParent) override;
+ void ResizeColumns() override;
void ShowEpisode(int iEpisode);
};
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 17ae373..cdb3dc7 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -141,15 +141,16 @@ void EpisodeListView::Redraw()
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
-void EpisodeListView::ResizeColumns(RECT& rcParent)
+void EpisodeListView::ResizeColumns()
{
- ListView_SetColumnWidth(hWnd, ELVSIEPISODE, LVSCW_AUTOSIZE);
+ RECT rc;
+ require(GetClientRect(hWnd, &rc));
+ ListView_SetColumnWidth(hWnd, ELVSIEPISODE, LVSCW_AUTOSIZE);
int cxColumn = ListView_GetColumnWidth(hWnd, ELVSIEPISODE)+4;
ListView_SetColumnWidth(hWnd, ELVSIEPISODE, cxColumn);
-
cxColumn += ListView_GetColumnWidth(hWnd, ELVSIRATING);
- ListView_SetColumnWidth(hWnd, ELVSITITLE, rcParent.right-cxColumn-Metric<SM_CXVSCROLL>-4);
+ ListView_SetColumnWidth(hWnd, ELVSITITLE, rc.right-cxColumn);
}
/* Select previously focused episode. */
diff --git a/c/episodelistview.h b/c/episodelistview.h
index 3b32b6f..36ac04b 100644
--- a/c/episodelistview.h
+++ b/c/episodelistview.h
@@ -16,7 +16,7 @@ struct EpisodeListView : public ListView
void EnsureFocusVisible();
LRESULT HandleNotify(LPARAM lParam);
void Redraw();
- void ResizeColumns(RECT& rcParent) override;
+ void ResizeColumns() override;
void RestoreFocus();
void SaveFocus();
void SetTop(int iItem);
diff --git a/c/listview.cpp b/c/listview.cpp
index 72c2c60..5418e33 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -38,7 +38,7 @@ int ListView::Height(int bHeader)
return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0;
}
-void ListView::ResizeColumns(RECT&) {}
+void ListView::ResizeColumns() {}
void ListView::UpdateTheme(const BOOL bThemeActive)
{
diff --git a/c/listview.h b/c/listview.h
index 6254c2d..528ddc3 100644
--- a/c/listview.h
+++ b/c/listview.h
@@ -9,7 +9,7 @@ struct ListView
ListView(HWND hWndParent, HMENU hMenu, DWORD dwStyle);
int Height(int bHeader = -1);
- virtual void ResizeColumns(RECT& rcParent);
+ virtual void ResizeColumns();
virtual void UpdateTheme(BOOL bThemeActive);
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
protected:
diff --git a/c/main.cpp b/c/main.cpp
index c04890d..421e0ca 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -518,11 +518,16 @@ void UpdateLayout()
SendMessage(g_pDlv->hWnd, WM_SETREDRAW, FALSE, 0);
SendMessage(g_pElv->hWnd, WM_SETREDRAW, FALSE, 0);
+ /* If a modern theme is used, list view borders should be
+ * hidden. This variable governs that. (See how it is used in
+ * the arguments to SetWindowRect below.) */
+ const long x = IsThemeActive();
+
const long cyDlv = rrStatus.top-g_pDlv->Height();
- require(SetWindowRect(g_pDlv->hWnd, 0, cyDlv, rc.right, rrStatus.top));
- require(SetWindowRect(g_pElv->hWnd, 0, 0, rc.right, cyDlv+IsThemeActive()));
- g_pDlv->ResizeColumns(rc);
- g_pElv->ResizeColumns(rc);
+ require(SetWindowRect(g_pDlv->hWnd, -x, cyDlv, rc.right+x*2, rrStatus.top+x));
+ require(SetWindowRect(g_pElv->hWnd, -x, -x*2, rc.right+x*2, cyDlv+x));
+ g_pDlv->ResizeColumns();
+ g_pElv->ResizeColumns();
SendMessage(g_pElv->hWnd, WM_SETREDRAW, TRUE, 0);
SendMessage(g_pDlv->hWnd, WM_SETREDRAW, TRUE, 0);