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