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: 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 #ifndef _UNICODE 35 bool SetItemText(int itemID, LPCWSTR s) 36 { 37 CWindow window(GetItem(itemID)); 38 return window.SetText(s); 39 } 40 #endif 41 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 54 bool SetItemInt(int itemID, UINT value, bool isSigned) 55 { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); } 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 63 HWND GetNextGroupItem(HWND control, bool previous) 64 { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); } 65 HWND GetNextTabItem(HWND control, bool previous) 66 { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); } 67 68 bool MapRect(LPRECT rect) 69 { return BOOLToBool(MapDialogRect(_window, rect)); } 70 71 bool IsMessage(LPMSG message) 72 { return BOOLToBool(IsDialogMessage(_window, message)); } 73 74 LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam) 75 { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); } 76 77 bool CheckButton(int buttonID, UINT checkState) 78 { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); } 79 bool CheckButton(int buttonID, bool checkState) 80 { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); } 81 82 UINT IsButtonChecked(int buttonID) const 83 { return IsDlgButtonChecked(_window, buttonID); } 84 bool IsButtonCheckedBool(int buttonID) const 85 { return (IsButtonChecked(buttonID) == BST_CHECKED); } 86 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); 91 virtual bool OnInit() { return true; } 92 virtual bool OnCommand(WPARAM wParam, LPARAM lParam); 93 virtual bool OnCommand(int code, int itemID, LPARAM lParam); 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 */ 103 virtual void OnHelp() {}; 104 105 virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); 106 virtual void OnOK() {}; 107 virtual void OnCancel() {}; 108 virtual void OnClose() {} 109 virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } 110 virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } 111 112 LONG_PTR SetMsgResult(LONG_PTR newLongPtr ) 113 { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } 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); 131 bool Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); } 132 #ifndef _UNICODE 133 bool Create(LPCWSTR templateName, HWND parentWindow); 134 #endif 135 virtual void OnOK() { Destroy(); } 136 virtual void OnCancel() { Destroy(); } 137 virtual void OnClose() { Destroy(); } 138 }; 139 140 class CModalDialog: public CDialog 141 { 142 public: 143 INT_PTR Create(LPCTSTR templateName, 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 149 bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); } 150 virtual void OnOK() { End(IDOK); } 151 virtual void OnCancel() { End(IDCANCEL); } 152 virtual void OnClose() { End(IDCLOSE); } 153 }; 154 155 class CDialogChildControl: public NWindows::CWindow 156 { 157 int m_ID; 158 public: 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