Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 // Windows/Control/Dialog.h
3 #ifndef __WINDOWS_CONTROL_DIALOG_H
4 #define __WINDOWS_CONTROL_DIALOG_H
6 #include "Windows/Window.h"
7 #include "Windows/Defs.h"
9 namespace NWindows {
10 namespace NControl {
12 class CDialog: public CWindow
13 {
14 public:
15 CDialog(HWND wndow = NULL): CWindow(wndow){};
16 virtual ~CDialog() {};
18 HWND GetItem(int itemID) const
19 { return GetDlgItem(_window, itemID); }
21 bool EnableItem(int itemID, bool enable) const
22 { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); }
24 bool SetItemText(int itemID, LPCTSTR s)
25 { return BOOLToBool(SetDlgItemText(_window, itemID, s)); }
27 #ifndef _UNICODE
28 bool SetItemText(int itemID, LPCWSTR s)
29 {
30 CWindow window(GetItem(itemID));
31 return window.SetText(s);
32 }
33 #endif
35 UINT GetItemText(int itemID, LPTSTR string, int maxCount)
36 { return GetDlgItemText(_window, itemID, string, maxCount); }
37 #ifndef _UNICODE
38 /*
39 bool GetItemText(int itemID, LPWSTR string, int maxCount)
40 {
41 CWindow window(GetItem(itemID));
42 return window.GetText(string, maxCount);
43 }
44 */
45 #endif
47 bool SetItemInt(int itemID, UINT value, bool isSigned)
48 { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); }
49 bool GetItemInt(int itemID, bool isSigned, UINT &value)
50 {
51 BOOL result;
52 value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned));
53 return BOOLToBool(result);
54 }
56 HWND GetNextGroupItem(HWND control, bool previous)
57 { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); }
58 HWND GetNextTabItem(HWND control, bool previous)
59 { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
61 bool MapRect(LPRECT rect)
62 { return BOOLToBool(MapDialogRect(_window, rect)); }
64 bool IsMessage(LPMSG message)
65 { return BOOLToBool(IsDialogMessage(_window, message)); }
67 LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam)
68 { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); }
70 bool CheckButton(int buttonID, UINT checkState)
71 { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); }
72 bool CheckButton(int buttonID, bool checkState)
73 { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); }
75 UINT IsButtonChecked(int buttonID) const
76 { return IsDlgButtonChecked(_window, buttonID); }
77 bool IsButtonCheckedBool(int buttonID) const
78 { return (IsButtonChecked(buttonID) == BST_CHECKED); }
80 bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID)
81 { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); }
83 virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
84 virtual bool OnInit() { return true; }
85 virtual bool OnCommand(WPARAM wParam, LPARAM lParam);
86 virtual bool OnCommand(int code, int itemID, LPARAM lParam);
87 virtual void OnHelp(LPHELPINFO helpInfo) { OnHelp(); };
88 virtual void OnHelp() {};
89 virtual bool OnButtonClicked(int buttonID, HWND buttonHWND);
90 virtual void OnOK() {};
91 virtual void OnCancel() {};
92 virtual bool OnNotify(UINT controlID, LPNMHDR lParam) { return false; }
93 virtual bool OnTimer(WPARAM timerID, LPARAM callback) { return false; }
95 LONG_PTR SetMsgResult(LONG_PTR newLongPtr )
96 { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); }
97 LONG_PTR GetMsgResult() const
98 { return GetLongPtr(DWLP_MSGRESULT); }
99 };
101 class CModelessDialog: public CDialog
102 {
103 public:
104 bool Create(LPCTSTR templateName, HWND parentWindow);
105 #ifndef _UNICODE
106 bool Create(LPCWSTR templateName, HWND parentWindow);
107 #endif
108 virtual void OnOK() { Destroy(); }
109 virtual void OnCancel() { Destroy(); }
110 };
112 class CModalDialog: public CDialog
113 {
114 public:
115 INT_PTR Create(LPCTSTR templateName, HWND parentWindow);
116 INT_PTR Create(UINT resID, HWND parentWindow)
117 { return Create(MAKEINTRESOURCEW(resID), parentWindow); }
118 #ifndef _UNICODE
119 INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
120 #endif
122 bool End(INT_PTR result)
123 { return BOOLToBool(::EndDialog(_window, result)); }
124 virtual void OnOK() { End(IDOK); }
125 virtual void OnCancel() { End(IDCANCEL); }
126 };
128 class CDialogChildControl: public NWindows::CWindow
129 {
130 public:
131 int m_ID;
132 void Init(const NWindows::NControl::CDialog &parentDialog, int id)
133 {
134 m_ID = id;
135 Attach(parentDialog.GetItem(id));
136 }
137 };
139 }}
141 #endif