aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-03 19:22:40 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-03 19:22:40 +0200
commitdee3a413f072e5779fc5ba80692f895ba43815c6 (patch)
treead1a8274626ccfaf15ed064e1e3d2af6ac0ffd4d /c
parent5fb8df682831045c4619b65403c4a24d7583d2e9 (diff)
downloadEpisodeBrowser-dee3a413f072e5779fc5ba80692f895ba43815c6.tar.gz
Clean up Dragger.
Diffstat (limited to 'c')
-rw-r--r--c/layout.cpp16
-rw-r--r--c/layout.h43
-rw-r--r--c/listview.cpp2
-rw-r--r--c/main.cpp2
4 files changed, 47 insertions, 16 deletions
diff --git a/c/layout.cpp b/c/layout.cpp
index 4da7cd8..94978bb 100644
--- a/c/layout.cpp
+++ b/c/layout.cpp
@@ -38,7 +38,7 @@ void UpdateLayout(int w, int h)
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
-bool Dragger::InDragArea(const int x, const int y)
+bool DlvDragger::InDragArea(const int x, const int y)
{
RECT rrDlv;
require(GetRelativeRect(g_dlv->hWnd, &rrDlv));
@@ -50,7 +50,7 @@ bool Dragger::InDragArea(const int x, const int y)
return true;
}
-void Dragger::Drag(const int, const int y)
+void DlvDragger::Drag(const int, const int y)
{
RECT rrDlv;
require(GetRelativeRect(g_dlv->hWnd, &rrDlv));
@@ -64,3 +64,15 @@ void Dragger::Drag(const int, const int y)
RedrawWindow(g_hWnd, NULL, NULL,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW);
}
+
+void DlvDragger::Reset()
+{
+ g_dlv->SetHeight(0);
+ Pl("cfg","set_dlv_height",0);
+ UpdateLayout();
+}
+
+void DlvDragger::Done()
+{
+ Pl("cfg","set_dlv_height",g_dlv->Height());
+}
diff --git a/c/layout.h b/c/layout.h
index 1b78945..47702c4 100644
--- a/c/layout.h
+++ b/c/layout.h
@@ -9,19 +9,39 @@
void UpdateLayout(int w = 0, int h = 0);
+/* Draggable portions of the client area, such as the split between
+ * two list views, are implemented in Dragger singletons.
+ *
+ * HandleDown and HandleMove are called by the relevant window
+ * procedures for WM_(NC)LBUTTONDOWN and WM_SETCURSOR. */
+
struct Dragger
{
bool HandleDown();
bool HandleMove();
-private:
- bool InDragArea(int x, int y);
+protected:
bool IsDown();
bool IsDouble();
- void Drag(int x, int y);
+ virtual bool InDragArea(int x, int y);
+ virtual void Drag(int x, int y);
+ virtual void Reset();
+ virtual void Done();
+private:
bool m_bActive = false;
long m_time = 0;
};
+/* Dragger for data list view (upper border). */
+
+struct DlvDragger : public Dragger
+{
+private:
+ bool InDragArea(int x, int y) override;
+ void Drag(int x, int y) override;
+ void Reset() override;
+ void Done() override;
+};
+
inline bool Dragger::IsDouble()
{
const long time = GetMessageTime();
@@ -43,13 +63,12 @@ inline bool Dragger::HandleDown()
if (!InDragArea(pt.x, pt.y)) return false;
if (IsDouble()) {
- extern DataListView* g_dlv;
- g_dlv->SetHeight(0);
- Pl("cfg","set_dlv_height",0);
- UpdateLayout();
- return false;
+ m_bActive = false;
+ Reset();
} else
- return m_bActive = true;
+ m_bActive = true;
+
+ return m_bActive;
}
inline bool Dragger::HandleMove()
@@ -64,12 +83,12 @@ inline bool Dragger::HandleMove()
SetCursor(g_hcSizeNs);
else
r = false;
- if (!m_bActive) return r;
+ if (!m_bActive)
+ return r;
Drag(pt.x, pt.y);
if (!IsDown()) {
- extern DataListView* g_dlv;
m_bActive = false;
- Pl("cfg","set_dlv_height",g_dlv->Height());
+ Done();
}
return r;
}
diff --git a/c/listview.cpp b/c/listview.cpp
index e5d22b2..531e9dd 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -67,7 +67,7 @@ void ListView::UpdateTheme(const BOOL bThemeActive)
LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
const WPARAM wParam, const LPARAM lParam)
{
- extern Dragger g_dragDlv;
+ extern DlvDragger g_dragDlv;
switch (uMsg) {
case WM_NOTIFY:
switch (((NMHDR*)lParam)->code) {
diff --git a/c/main.cpp b/c/main.cpp
index d73a08a..79fb8eb 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -36,7 +36,7 @@ DataListView* g_dlv;
EpisodeListView* g_elv;
/* Layout handlers. */
-Dragger g_dragDlv;
+DlvDragger g_dragDlv;
/* View settings. */
int g_bViewWatched = 1;