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 bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } 109 virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } 110 111 LONG_PTR SetMsgResult(LONG_PTR newLongPtr ) 112 { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } 113 LONG_PTR GetMsgResult() const 114 { return GetLongPtr(DWLP_MSGRESULT); } 115 116 bool GetMargins(int margin, int &x, int &y); 117 int Units_To_Pixels_X(int units); 118 bool GetItemSizes(int id, int &x, int &y); 119 void GetClientRectOfItem(int id, RECT &rect); 120 bool MoveItem(int id, int x, int y, int width, int height, bool repaint = true); 121 122 void NormalizeSize(bool fullNormalize = false); 123 void NormalizePosition(); 124 }; 125 126 class CModelessDialog: public CDialog 127 { 128 public: 129 bool Create(LPCTSTR templateName, HWND parentWindow); 130 bool Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); } 131 #ifndef _UNICODE 132 bool Create(LPCWSTR templateName, HWND parentWindow); 133 #endif 134 virtual void OnOK() { Destroy(); } 135 virtual void OnCancel() { Destroy(); } 136 }; 137 138 class CModalDialog: public CDialog 139 { 140 public: 141 INT_PTR Create(LPCTSTR templateName, HWND parentWindow); 142 INT_PTR Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); } 143 #ifndef _UNICODE 144 INT_PTR Create(LPCWSTR templateName, HWND parentWindow); 145 #endif 146 147 bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); } 148 virtual void OnOK() { End(IDOK); } 149 virtual void OnCancel() { End(IDCANCEL); } 150 }; 151 152 class CDialogChildControl: public NWindows::CWindow 153 { 154 int m_ID; 155 public: 156 void Init(const NWindows::NControl::CDialog &parentDialog, int id) 157 { 158 m_ID = id; 159 Attach(parentDialog.GetItem(id)); 160 } 161 }; 162 163 bool IsDialogSizeOK(int xSize, int ySize); 164 165 }} 166 167 #endif 168