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