aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/Control/Dialog.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/Control/Dialog.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/CPP/Windows/Control/Dialog.h b/CPP/Windows/Control/Dialog.h
new file mode 100644
index 0000000..8a39e99
--- /dev/null
+++ b/CPP/Windows/Control/Dialog.h
@@ -0,0 +1,190 @@
1// Windows/Control/Dialog.h
2
3#ifndef __WINDOWS_CONTROL_DIALOG_H
4#define __WINDOWS_CONTROL_DIALOG_H
5
6#include "../Window.h"
7
8namespace NWindows {
9namespace NControl {
10
11class CDialog: public CWindow
12{
13public:
14 CDialog(HWND wnd = NULL): CWindow(wnd){};
15 virtual ~CDialog() {};
16
17 HWND GetItem(int itemID) const
18 { return GetDlgItem(_window, itemID); }
19
20 bool EnableItem(int itemID, bool enable) const
21 { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); }
22
23 bool ShowItem(int itemID, int cmdShow) const
24 { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); }
25
26 bool ShowItem_Bool(int itemID, bool show) const
27 { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); }
28
29 bool HideItem(int itemID) const { return ShowItem(itemID, SW_HIDE); }
30
31 bool SetItemText(int itemID, LPCTSTR s)
32 { return BOOLToBool(SetDlgItemText(_window, itemID, s)); }
33
34 bool SetItemTextA(int itemID, LPCSTR s)
35 { return BOOLToBool(SetDlgItemTextA(_window, itemID, s)); }
36
37 bool SetItemText_Empty(int itemID)
38 { return SetItemText(itemID, TEXT("")); }
39
40 #ifndef _UNICODE
41 bool SetItemText(int itemID, LPCWSTR s)
42 {
43 CWindow window(GetItem(itemID));
44 return window.SetText(s);
45 }
46 #endif
47
48 UINT GetItemText(int itemID, LPTSTR string, int maxCount)
49 { return GetDlgItemText(_window, itemID, string, maxCount); }
50 #ifndef _UNICODE
51 /*
52 bool GetItemText(int itemID, LPWSTR string, int maxCount)
53 {
54 CWindow window(GetItem(itemID));
55 return window.GetText(string, maxCount);
56 }
57 */
58 #endif
59
60 bool GetItemText(int itemID, UString &s)
61 {
62 CWindow window(GetItem(itemID));
63 return window.GetText(s);
64 }
65
66 bool SetItemInt(int itemID, UINT value, bool isSigned)
67 { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); }
68 bool GetItemInt(int itemID, bool isSigned, UINT &value)
69 {
70 BOOL result;
71 value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned));
72 return BOOLToBool(result);
73 }
74
75 HWND GetNextGroupItem(HWND control, bool previous)
76 { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); }
77 HWND GetNextTabItem(HWND control, bool previous)
78 { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
79
80 LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam)
81 { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); }
82 LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); }
83 LRESULT SendMsg_NextDlgCtl_CtlId(int id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); }
84 LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); }
85 LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); }
86
87 bool MapRect(LPRECT rect)
88 { return BOOLToBool(MapDialogRect(_window, rect)); }
89
90 bool IsMessage(LPMSG message)
91 { return BOOLToBool(IsDialogMessage(_window, message)); }
92
93 LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam)
94 { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); }
95
96 bool CheckButton(int buttonID, UINT checkState)
97 { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); }
98 bool CheckButton(int buttonID, bool checkState)
99 { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); }
100
101 UINT IsButtonChecked(int buttonID) const
102 { return IsDlgButtonChecked(_window, buttonID); }
103 bool IsButtonCheckedBool(int buttonID) const
104 { return (IsButtonChecked(buttonID) == BST_CHECKED); }
105
106 bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID)
107 { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); }
108
109 virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
110 virtual bool OnInit() { return true; }
111 virtual bool OnCommand(WPARAM wParam, LPARAM lParam);
112 virtual bool OnCommand(int code, int itemID, LPARAM lParam);
113 virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
114 virtual bool OnDestroy() { return false; }
115
116 /*
117 #ifdef UNDER_CE
118 virtual void OnHelp(void *) { OnHelp(); }
119 #else
120 virtual void OnHelp(LPHELPINFO) { OnHelp(); }
121 #endif
122 */
123 virtual void OnHelp() {};
124
125 virtual bool OnButtonClicked(int buttonID, HWND buttonHWND);
126 virtual void OnOK() {};
127 virtual void OnCancel() {};
128 virtual void OnClose() {}
129 virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; }
130 virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; }
131
132 LONG_PTR SetMsgResult(LONG_PTR newLongPtr )
133 { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); }
134 LONG_PTR GetMsgResult() const
135 { return GetLongPtr(DWLP_MSGRESULT); }
136
137 bool GetMargins(int margin, int &x, int &y);
138 int Units_To_Pixels_X(int units);
139 bool GetItemSizes(int id, int &x, int &y);
140 void GetClientRectOfItem(int id, RECT &rect);
141 bool MoveItem(int id, int x, int y, int width, int height, bool repaint = true);
142
143 void NormalizeSize(bool fullNormalize = false);
144 void NormalizePosition();
145};
146
147class CModelessDialog: public CDialog
148{
149public:
150 bool Create(LPCTSTR templateName, HWND parentWindow);
151 bool Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); }
152 #ifndef _UNICODE
153 bool Create(LPCWSTR templateName, HWND parentWindow);
154 #endif
155 virtual void OnOK() { Destroy(); }
156 virtual void OnCancel() { Destroy(); }
157 virtual void OnClose() { Destroy(); }
158};
159
160class CModalDialog: public CDialog
161{
162public:
163 INT_PTR Create(LPCTSTR templateName, HWND parentWindow);
164 INT_PTR Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); }
165 #ifndef _UNICODE
166 INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
167 #endif
168
169 bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); }
170 virtual void OnOK() { End(IDOK); }
171 virtual void OnCancel() { End(IDCANCEL); }
172 virtual void OnClose() { End(IDCLOSE); }
173};
174
175class CDialogChildControl: public NWindows::CWindow
176{
177 int m_ID;
178public:
179 void Init(const NWindows::NControl::CDialog &parentDialog, int id)
180 {
181 m_ID = id;
182 Attach(parentDialog.GetItem(id));
183 }
184};
185
186bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd = NULL);
187
188}}
189
190#endif