michael@0: // Windows/Control/Dialog.h michael@0: michael@0: #ifndef __WINDOWS_CONTROL_DIALOG_H michael@0: #define __WINDOWS_CONTROL_DIALOG_H michael@0: michael@0: #include "Windows/Window.h" michael@0: #include "Windows/Defs.h" michael@0: michael@0: namespace NWindows { michael@0: namespace NControl { michael@0: michael@0: class CDialog: public CWindow michael@0: { michael@0: public: michael@0: CDialog(HWND wndow = NULL): CWindow(wndow){}; michael@0: virtual ~CDialog() {}; michael@0: michael@0: HWND GetItem(int itemID) const michael@0: { return GetDlgItem(_window, itemID); } michael@0: michael@0: bool EnableItem(int itemID, bool enable) const michael@0: { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); } michael@0: michael@0: bool SetItemText(int itemID, LPCTSTR s) michael@0: { return BOOLToBool(SetDlgItemText(_window, itemID, s)); } michael@0: michael@0: #ifndef _UNICODE michael@0: bool SetItemText(int itemID, LPCWSTR s) michael@0: { michael@0: CWindow window(GetItem(itemID)); michael@0: return window.SetText(s); michael@0: } michael@0: #endif michael@0: michael@0: UINT GetItemText(int itemID, LPTSTR string, int maxCount) michael@0: { return GetDlgItemText(_window, itemID, string, maxCount); } michael@0: #ifndef _UNICODE michael@0: /* michael@0: bool GetItemText(int itemID, LPWSTR string, int maxCount) michael@0: { michael@0: CWindow window(GetItem(itemID)); michael@0: return window.GetText(string, maxCount); michael@0: } michael@0: */ michael@0: #endif michael@0: michael@0: bool SetItemInt(int itemID, UINT value, bool isSigned) michael@0: { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); } michael@0: bool GetItemInt(int itemID, bool isSigned, UINT &value) michael@0: { michael@0: BOOL result; michael@0: value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned)); michael@0: return BOOLToBool(result); michael@0: } michael@0: michael@0: HWND GetNextGroupItem(HWND control, bool previous) michael@0: { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); } michael@0: HWND GetNextTabItem(HWND control, bool previous) michael@0: { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); } michael@0: michael@0: bool MapRect(LPRECT rect) michael@0: { return BOOLToBool(MapDialogRect(_window, rect)); } michael@0: michael@0: bool IsMessage(LPMSG message) michael@0: { return BOOLToBool(IsDialogMessage(_window, message)); } michael@0: michael@0: LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam) michael@0: { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); } michael@0: michael@0: bool CheckButton(int buttonID, UINT checkState) michael@0: { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); } michael@0: bool CheckButton(int buttonID, bool checkState) michael@0: { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); } michael@0: michael@0: UINT IsButtonChecked(int buttonID) const michael@0: { return IsDlgButtonChecked(_window, buttonID); } michael@0: bool IsButtonCheckedBool(int buttonID) const michael@0: { return (IsButtonChecked(buttonID) == BST_CHECKED); } michael@0: michael@0: bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID) michael@0: { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); } michael@0: michael@0: virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam); michael@0: virtual bool OnInit() { return true; } michael@0: virtual bool OnCommand(WPARAM wParam, LPARAM lParam); michael@0: virtual bool OnCommand(int code, int itemID, LPARAM lParam); michael@0: virtual void OnHelp(LPHELPINFO helpInfo) { OnHelp(); }; michael@0: virtual void OnHelp() {}; michael@0: virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); michael@0: virtual void OnOK() {}; michael@0: virtual void OnCancel() {}; michael@0: virtual bool OnNotify(UINT controlID, LPNMHDR lParam) { return false; } michael@0: virtual bool OnTimer(WPARAM timerID, LPARAM callback) { return false; } michael@0: michael@0: LONG_PTR SetMsgResult(LONG_PTR newLongPtr ) michael@0: { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } michael@0: LONG_PTR GetMsgResult() const michael@0: { return GetLongPtr(DWLP_MSGRESULT); } michael@0: }; michael@0: michael@0: class CModelessDialog: public CDialog michael@0: { michael@0: public: michael@0: bool Create(LPCTSTR templateName, HWND parentWindow); michael@0: #ifndef _UNICODE michael@0: bool Create(LPCWSTR templateName, HWND parentWindow); michael@0: #endif michael@0: virtual void OnOK() { Destroy(); } michael@0: virtual void OnCancel() { Destroy(); } michael@0: }; michael@0: michael@0: class CModalDialog: public CDialog michael@0: { michael@0: public: michael@0: INT_PTR Create(LPCTSTR templateName, HWND parentWindow); michael@0: INT_PTR Create(UINT resID, HWND parentWindow) michael@0: { return Create(MAKEINTRESOURCEW(resID), parentWindow); } michael@0: #ifndef _UNICODE michael@0: INT_PTR Create(LPCWSTR templateName, HWND parentWindow); michael@0: #endif michael@0: michael@0: bool End(INT_PTR result) michael@0: { return BOOLToBool(::EndDialog(_window, result)); } michael@0: virtual void OnOK() { End(IDOK); } michael@0: virtual void OnCancel() { End(IDCANCEL); } michael@0: }; michael@0: michael@0: class CDialogChildControl: public NWindows::CWindow michael@0: { michael@0: public: michael@0: int m_ID; michael@0: void Init(const NWindows::NControl::CDialog &parentDialog, int id) michael@0: { michael@0: m_ID = id; michael@0: Attach(parentDialog.GetItem(id)); michael@0: } michael@0: }; michael@0: michael@0: }} michael@0: michael@0: #endif