comparison foosdk/sdk/libPPUI/CDialogResizeHelper.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 #include "CDialogResizeHelperCompat.h"
4 #include <vector>
5
6 // ==========================================================
7 // CDialogResizeHelper
8 // ==========================================================
9 // Usage:
10 // Put CDialogResizeHelper member in your dialog class
11 // Initialize with controls sizing info table, array of CDialogResizeHelper::Param
12 // Put CHAIN_MSG_MAP_MEMBER(m_resizer) before your dialog message handlers
13 // CDialogResizeHelper will do its own message handling without marking messages as handled, that is, your handlers of the same messages will be allowed to run.
14 // CRect minMaxRange specifies allowed size min (left&top) and max (right&bottom) values, in DLU not pixels.
15 // ==========================================================
16
17 class CDialogResizeHelper : public CMessageMap {
18 public:
19
20 typedef CDialogResizeHelperCompat::param ParamOld;
21
22 struct Param {
23 uint32_t id;
24 float snapLeft, snapTop, snapRight, snapBottom;
25 };
26 private:
27 void AddSizeGrip();
28 public:
29 inline void set_min_size(unsigned x, unsigned y) { min_x = x; min_y = y; }
30 inline void set_max_size(unsigned x, unsigned y) { max_x = x; max_y = y; }
31
32 bool m_autoSizeGrip = true;
33
34 BEGIN_MSG_MAP_EX(CDialogResizeHelper)
35 if (uMsg == WM_INITDIALOG) OnInitDialog(hWnd);
36 MSG_WM_SIZE(OnSize)
37 MSG_WM_DESTROY(OnDestroy)
38 MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
39 END_MSG_MAP()
40
41 template<typename TParam, size_t paramCount> CDialogResizeHelper(const TParam(&src)[paramCount], CRect const& minMaxRange = CRect(0, 0, 0, 0)) {
42 InitTable(src, paramCount);
43 InitMinMax(minMaxRange);
44 }
45
46 void InitTable(const Param* table, size_t tableSize);
47 void InitTable(const ParamOld * table, size_t tableSize);
48 void InitMinMax(const CRect & range);
49
50 bool EvalRect(UINT id, CRect & out) const;
51
52 //! initData.id may be null, if so specify a non null window handle.
53 void AddControl( Param const & initData, CWindow wnd = NULL );
54 bool RemoveControl( CWindow wnd );
55 bool HaveControl(CWindow wnd) const;
56 private:
57 struct runtime_t {
58 HWND userHWND = 0;
59 CRect origRect;
60 CSize origWindowSize;
61 Param initData = {};
62 };
63
64 CSize CurrentSize() const;
65 CWindow ResolveWnd( runtime_t const & rt ) const;
66
67 CRect _EvalRect(runtime_t const & rt, CSize wndSize) const;
68 void OnGetMinMaxInfo(LPMINMAXINFO lpMMI) const;
69 void OnSize(UINT nType, CSize size);
70 void OnInitDialog(CWindow thisWnd);
71 void OnDestroy();
72
73
74 std::vector<runtime_t> m_runtime;
75 std::vector<Param> m_initData;
76
77 CWindow m_thisWnd, m_sizeGrip;
78 unsigned min_x, min_y, max_x, max_y;
79 };