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