commit 16001109e6fb971110b8ba004fba9ab34a964e3b
parent 557c2911fccb5433a5e18c73785bddf4473f1033
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 25 Jun 2016 23:28:42 -0400
browser: make the window user-resizable
Diffstat:
6 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/Tupfile b/Tupfile
@@ -1,7 +1,8 @@
WDL := vendor/WDL/WDL
+WDLSOURCE := $(WDL)/wingui/wndsize.cpp
TINYXML := $(WDL)/tinyxml
-WDLSOURCE := $(TINYXML)/tinyxml.cpp $(TINYXML)/tinystr.cpp
+WDLSOURCE += $(TINYXML)/tinyxml.cpp $(TINYXML)/tinystr.cpp
WDLSOURCE += $(TINYXML)/tinyxmlparser.cpp $(TINYXML)/tinyxmlerror.cpp
include @(TUP_PLATFORM).tup
diff --git a/macosx.tup b/macosx.tup
@@ -4,7 +4,7 @@ REAPACK_FILE = reaper_reapack@(SUFFIX).dylib
CXXFLAGS := -Wall -Wextra -Werror
CXXFLAGS += -Wno-unused-parameter -Wno-missing-field-initializers
-CXXFLAGS += -Wno-unused-function -Wno-missing-braces
+CXXFLAGS += -Wno-unused-function -Wno-unused-private-field -Wno-missing-braces
CXXFLAGS += -fdiagnostics-color -fstack-protector-strong -fvisibility=hidden
CXXFLAGS += -pipe -fPIC -O2 -std=c++14
CXXFLAGS += -Ivendor -Ivendor/WDL -Ivendor/WDL/WDL -Ivendor/WDL/WDL/swell
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -115,6 +115,20 @@ void Browser::onInit()
refresh();
m_filterTimer = startTimer(200);
+
+ Dialog::onInit();
+ setAnchor(m_filterHandle, AnchorRight);
+ setAnchor(getControl(IDC_CLEAR), AnchorLeftRight);
+ setAnchor(getControl(IDC_LABEL2), AnchorLeftRight);
+ setAnchor(m_view, AnchorLeftRight);
+ setAnchor(m_displayBtn, AnchorLeftRight);
+ setAnchor(m_list->handle(), AnchorRight | AnchorBottom);
+ setAnchor(getControl(IDC_SELECT), AnchorTop | AnchorBottom);
+ setAnchor(getControl(IDC_UNSELECT), AnchorTop | AnchorBottom);
+ setAnchor(m_actionsBtn, AnchorTop | AnchorBottom);
+ setAnchor(getControl(IDOK), AnchorAll);
+ setAnchor(getControl(IDCANCEL), AnchorAll);
+ setAnchor(m_applyBtn, AnchorAll);
}
void Browser::onCommand(const int id, const int event)
diff --git a/src/dialog.cpp b/src/dialog.cpp
@@ -77,6 +77,16 @@ WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_CONTEXTMENU:
dlg->onContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
break;
+ case WM_GETMINMAXINFO: {
+ MINMAXINFO *mmi = (MINMAXINFO *)lParam;
+ mmi->ptMinTrackSize.x = dlg->m_initialSize.x;
+ mmi->ptMinTrackSize.y = dlg->m_initialSize.y;
+ break;
+ }
+ case WM_SIZE:
+ if(wParam != SIZE_MINIMIZED)
+ dlg->onResize();
+ break;
case WM_DESTROY:
// On Windows, WM_DESTROY is emitted in place of WM_INITDIALOG
// if the dialog resource is invalid (eg. because of an unloaded dll).
@@ -120,7 +130,7 @@ int Dialog::HandleKey(MSG *msg, accelerator_register_t *accel)
}
Dialog::Dialog(const int templateId)
- : m_template(templateId), m_isVisible(false),
+ : m_template(templateId), m_isVisible(false), m_initialSize(),
m_instance(nullptr), m_parent(nullptr), m_handle(nullptr)
{
m_accel.translateAccel = HandleKey;
@@ -307,8 +317,23 @@ string Dialog::getText(HWND handle)
return from_autostring(buffer);
}
+void Dialog::setAnchor(HWND handle, const int flags)
+{
+ const float left = (float)min(1, flags & AnchorLeft);
+ const float top = (float)min(1, flags & AnchorTop);
+ const float right = (float)min(1, flags & AnchorRight);
+ const float bottom = (float)min(1, flags & AnchorBottom);
+
+ m_resizer.init_itemhwnd(handle, left, top, right, bottom);
+}
+
void Dialog::onInit()
{
+ RECT rect;
+ GetWindowRect(m_handle, &rect);
+ m_initialSize = {rect.right - rect.left, rect.bottom - rect.top};
+
+ m_resizer.init(m_handle);
}
void Dialog::onShow()
@@ -373,6 +398,11 @@ bool Dialog::onKeyDown(int, int)
return false;
}
+void Dialog::onResize()
+{
+ m_resizer.onResize();
+}
+
void Dialog::onClose()
{
}
diff --git a/src/dialog.hpp b/src/dialog.hpp
@@ -23,8 +23,9 @@
#include <set>
#include <vector>
-#include <wdltypes.h>
#include <reaper_plugin.h>
+#include <wdltypes.h>
+#include <wingui/wndsize.h>
class Dialog;
typedef std::map<HWND, Dialog *> DialogMap;
@@ -40,6 +41,17 @@ public:
Modal,
};
+ enum AnchorFlags {
+ AnchorLeft = 1<<0,
+ AnchorRight = 1<<1,
+ AnchorTop = 1<<2,
+ AnchorBottom = 1<<3,
+
+ AnchorLeftRight = AnchorLeft | AnchorRight,
+ AnchorTopBottom = AnchorTop | AnchorBottom,
+ AnchorAll = AnchorLeftRight | AnchorTopBottom,
+ };
+
template<class T, class... Args>
static T *Create(REAPER_PLUGIN_HINSTANCE instance, HWND parent, Args&&... args)
{
@@ -93,6 +105,7 @@ public:
void setClipboard(const std::vector<std::string> &);
HWND getControl(int idc);
std::string getText(HWND);
+ void setAnchor(HWND, int flags);
void setCloseHandler(const CloseHandler &cb) { m_closeHandler = cb; }
@@ -129,6 +142,7 @@ protected:
virtual void onNotify(LPNMHDR, LPARAM);
virtual void onContextMenu(HWND, int x, int y);
virtual bool onKeyDown(int key, int mods);
+ virtual void onResize();
private:
static WDL_DLGRET Proc(HWND, UINT, WPARAM, LPARAM);
@@ -137,6 +151,8 @@ private:
const int m_template;
bool m_isVisible;
+ POINT m_initialSize;
+ WDL_WndSizer m_resizer;
Modality m_mode;
REAPER_PLUGIN_HINSTANCE m_instance;
diff --git a/src/resource.rc b/src/resource.rc
@@ -80,7 +80,7 @@ BEGIN
END
IDD_BROWSER_DIALOG DIALOGEX 0, 0, 500, 250
-STYLE DIALOG_STYLE
+STYLE DIALOG_STYLE | WS_THICKFRAME
FONT DIALOG_FONT
CAPTION "ReaPack: Package Browser"
BEGIN