1370b324cSopenharmony_ci// Windows/Control/Dialog.h
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#ifndef ZIP7_INC_WINDOWS_CONTROL_DIALOG_H
4370b324cSopenharmony_ci#define ZIP7_INC_WINDOWS_CONTROL_DIALOG_H
5370b324cSopenharmony_ci
6370b324cSopenharmony_ci#include "../Window.h"
7370b324cSopenharmony_ci
8370b324cSopenharmony_cinamespace NWindows {
9370b324cSopenharmony_cinamespace NControl {
10370b324cSopenharmony_ci
11370b324cSopenharmony_ciclass CDialog: public CWindow
12370b324cSopenharmony_ci{
13370b324cSopenharmony_ci  // Z7_CLASS_NO_COPY(CDialog)
14370b324cSopenharmony_cipublic:
15370b324cSopenharmony_ci  CDialog(HWND wnd = NULL): CWindow(wnd) {}
16370b324cSopenharmony_ci  virtual ~CDialog() {}
17370b324cSopenharmony_ci
18370b324cSopenharmony_ci  HWND GetItem(unsigned itemID) const
19370b324cSopenharmony_ci    { return GetDlgItem(_window, (int)itemID); }
20370b324cSopenharmony_ci
21370b324cSopenharmony_ci  bool EnableItem(unsigned itemID, bool enable) const
22370b324cSopenharmony_ci    { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); }
23370b324cSopenharmony_ci
24370b324cSopenharmony_ci  bool ShowItem(unsigned itemID, int cmdShow) const
25370b324cSopenharmony_ci    { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); }
26370b324cSopenharmony_ci
27370b324cSopenharmony_ci  bool ShowItem_Bool(unsigned itemID, bool show) const
28370b324cSopenharmony_ci    { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); }
29370b324cSopenharmony_ci
30370b324cSopenharmony_ci  bool HideItem(unsigned itemID) const { return ShowItem(itemID, SW_HIDE); }
31370b324cSopenharmony_ci
32370b324cSopenharmony_ci  bool SetItemText(unsigned itemID, LPCTSTR s)
33370b324cSopenharmony_ci    { return BOOLToBool(SetDlgItemText(_window, (int)itemID, s)); }
34370b324cSopenharmony_ci
35370b324cSopenharmony_ci  bool SetItemTextA(unsigned itemID, LPCSTR s)
36370b324cSopenharmony_ci    { return BOOLToBool(SetDlgItemTextA(_window, (int)itemID, s)); }
37370b324cSopenharmony_ci
38370b324cSopenharmony_ci  bool SetItemText_Empty(unsigned itemID)
39370b324cSopenharmony_ci    { return SetItemText(itemID, TEXT("")); }
40370b324cSopenharmony_ci
41370b324cSopenharmony_ci  #ifndef _UNICODE
42370b324cSopenharmony_ci  bool SetItemText(unsigned itemID, LPCWSTR s)
43370b324cSopenharmony_ci  {
44370b324cSopenharmony_ci    CWindow window(GetItem(itemID));
45370b324cSopenharmony_ci    return window.SetText(s);
46370b324cSopenharmony_ci  }
47370b324cSopenharmony_ci  #endif
48370b324cSopenharmony_ci
49370b324cSopenharmony_ci  UINT GetItemText(unsigned itemID, LPTSTR string, unsigned maxCount)
50370b324cSopenharmony_ci    { return GetDlgItemText(_window, (int)itemID, string, (int)maxCount); }
51370b324cSopenharmony_ci  #ifndef _UNICODE
52370b324cSopenharmony_ci  /*
53370b324cSopenharmony_ci  bool GetItemText(unsigned itemID, LPWSTR string, int maxCount)
54370b324cSopenharmony_ci  {
55370b324cSopenharmony_ci    CWindow window(GetItem(unsigned));
56370b324cSopenharmony_ci    return window.GetText(string, maxCount);
57370b324cSopenharmony_ci  }
58370b324cSopenharmony_ci  */
59370b324cSopenharmony_ci  #endif
60370b324cSopenharmony_ci
61370b324cSopenharmony_ci  bool GetItemText(unsigned itemID, UString &s)
62370b324cSopenharmony_ci  {
63370b324cSopenharmony_ci    CWindow window(GetItem(itemID));
64370b324cSopenharmony_ci    return window.GetText(s);
65370b324cSopenharmony_ci  }
66370b324cSopenharmony_ci
67370b324cSopenharmony_ci  bool SetItemInt(unsigned itemID, UINT value, bool isSigned)
68370b324cSopenharmony_ci    { return BOOLToBool(SetDlgItemInt(_window, (int)itemID, value, BoolToBOOL(isSigned))); }
69370b324cSopenharmony_ci  bool GetItemInt(unsigned itemID, bool isSigned, UINT &value)
70370b324cSopenharmony_ci  {
71370b324cSopenharmony_ci    BOOL result;
72370b324cSopenharmony_ci    value = GetDlgItemInt(_window, (int)itemID, &result, BoolToBOOL(isSigned));
73370b324cSopenharmony_ci    return BOOLToBool(result);
74370b324cSopenharmony_ci  }
75370b324cSopenharmony_ci
76370b324cSopenharmony_ci  HWND GetNextGroupItem(HWND control, bool previous)
77370b324cSopenharmony_ci    { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); }
78370b324cSopenharmony_ci  HWND GetNextTabItem(HWND control, bool previous)
79370b324cSopenharmony_ci    { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
80370b324cSopenharmony_ci
81370b324cSopenharmony_ci  LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam)
82370b324cSopenharmony_ci    { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); }
83370b324cSopenharmony_ci  LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); }
84370b324cSopenharmony_ci  LRESULT SendMsg_NextDlgCtl_CtlId(unsigned id)   { return SendMsg_NextDlgCtl_HWND(GetItem(id)); }
85370b324cSopenharmony_ci  LRESULT SendMsg_NextDlgCtl_Next()          { return SendMsg_NextDlgCtl(0, FALSE); }
86370b324cSopenharmony_ci  LRESULT SendMsg_NextDlgCtl_Prev()          { return SendMsg_NextDlgCtl(1, FALSE); }
87370b324cSopenharmony_ci
88370b324cSopenharmony_ci  bool MapRect(LPRECT rect)
89370b324cSopenharmony_ci    { return BOOLToBool(MapDialogRect(_window, rect)); }
90370b324cSopenharmony_ci
91370b324cSopenharmony_ci  bool IsMessage(LPMSG message)
92370b324cSopenharmony_ci    { return BOOLToBool(IsDialogMessage(_window, message)); }
93370b324cSopenharmony_ci
94370b324cSopenharmony_ci  LRESULT SendItemMessage(unsigned itemID, UINT message, WPARAM wParam, LPARAM lParam)
95370b324cSopenharmony_ci    { return SendDlgItemMessage(_window, (int)itemID, message, wParam, lParam); }
96370b324cSopenharmony_ci
97370b324cSopenharmony_ci  bool CheckButton(unsigned buttonID, UINT checkState)
98370b324cSopenharmony_ci    { return BOOLToBool(CheckDlgButton(_window, (int)buttonID, checkState)); }
99370b324cSopenharmony_ci  bool CheckButton(unsigned buttonID, bool checkState)
100370b324cSopenharmony_ci    { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); }
101370b324cSopenharmony_ci
102370b324cSopenharmony_ci  UINT IsButtonChecked_BST(unsigned buttonID) const
103370b324cSopenharmony_ci    { return IsDlgButtonChecked(_window, (int)buttonID); }
104370b324cSopenharmony_ci  bool IsButtonCheckedBool(unsigned buttonID) const
105370b324cSopenharmony_ci    { return (IsButtonChecked_BST(buttonID) == BST_CHECKED); }
106370b324cSopenharmony_ci
107370b324cSopenharmony_ci  bool CheckRadioButton(unsigned firstButtonID, unsigned lastButtonID, unsigned checkButtonID)
108370b324cSopenharmony_ci    { return BOOLToBool(::CheckRadioButton(_window,
109370b324cSopenharmony_ci        (int)firstButtonID, (int)lastButtonID, (int)checkButtonID)); }
110370b324cSopenharmony_ci
111370b324cSopenharmony_ci  virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
112370b324cSopenharmony_ci  virtual bool OnInit() { return true; }
113370b324cSopenharmony_ci  // virtual bool OnCommand2(WPARAM wParam, LPARAM lParam);
114370b324cSopenharmony_ci  virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam);
115370b324cSopenharmony_ci  virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
116370b324cSopenharmony_ci  virtual bool OnDestroy() { return false; }
117370b324cSopenharmony_ci
118370b324cSopenharmony_ci  /*
119370b324cSopenharmony_ci  #ifdef UNDER_CE
120370b324cSopenharmony_ci  virtual void OnHelp(void *) { OnHelp(); }
121370b324cSopenharmony_ci  #else
122370b324cSopenharmony_ci  virtual void OnHelp(LPHELPINFO) { OnHelp(); }
123370b324cSopenharmony_ci  #endif
124370b324cSopenharmony_ci  */
125370b324cSopenharmony_ci  virtual void OnHelp() {}
126370b324cSopenharmony_ci
127370b324cSopenharmony_ci  virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND);
128370b324cSopenharmony_ci  virtual void OnOK() {}
129370b324cSopenharmony_ci  virtual void OnCancel() {}
130370b324cSopenharmony_ci  virtual void OnClose() {}
131370b324cSopenharmony_ci  virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; }
132370b324cSopenharmony_ci  virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; }
133370b324cSopenharmony_ci
134370b324cSopenharmony_ci  LONG_PTR SetMsgResult(LONG_PTR newLongPtr )
135370b324cSopenharmony_ci    { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); }
136370b324cSopenharmony_ci  LONG_PTR GetMsgResult() const
137370b324cSopenharmony_ci    { return GetLongPtr(DWLP_MSGRESULT); }
138370b324cSopenharmony_ci
139370b324cSopenharmony_ci  bool GetMargins(int margin, int &x, int &y);
140370b324cSopenharmony_ci  int Units_To_Pixels_X(int units);
141370b324cSopenharmony_ci  bool GetItemSizes(unsigned id, int &x, int &y);
142370b324cSopenharmony_ci  void GetClientRectOfItem(unsigned id, RECT &rect);
143370b324cSopenharmony_ci  bool MoveItem(unsigned id, int x, int y, int width, int height, bool repaint = true);
144370b324cSopenharmony_ci  bool MoveItem_RECT(unsigned id, const RECT &r, bool repaint = true)
145370b324cSopenharmony_ci    { return MoveItem(id, r.left, r.top, RECT_SIZE_X(r), RECT_SIZE_Y(r), repaint); }
146370b324cSopenharmony_ci
147370b324cSopenharmony_ci  void NormalizeSize(bool fullNormalize = false);
148370b324cSopenharmony_ci  void NormalizePosition();
149370b324cSopenharmony_ci};
150370b324cSopenharmony_ci
151370b324cSopenharmony_ciclass CModelessDialog: public CDialog
152370b324cSopenharmony_ci{
153370b324cSopenharmony_cipublic:
154370b324cSopenharmony_ci  bool Create(LPCTSTR templateName, HWND parentWindow);
155370b324cSopenharmony_ci  bool Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); }
156370b324cSopenharmony_ci  #ifndef _UNICODE
157370b324cSopenharmony_ci  bool Create(LPCWSTR templateName, HWND parentWindow);
158370b324cSopenharmony_ci  #endif
159370b324cSopenharmony_ci  virtual void OnOK() Z7_override { Destroy(); }
160370b324cSopenharmony_ci  virtual void OnCancel() Z7_override { Destroy(); }
161370b324cSopenharmony_ci  virtual void OnClose() Z7_override { Destroy(); }
162370b324cSopenharmony_ci};
163370b324cSopenharmony_ci
164370b324cSopenharmony_ciclass CModalDialog: public CDialog
165370b324cSopenharmony_ci{
166370b324cSopenharmony_cipublic:
167370b324cSopenharmony_ci  INT_PTR Create(LPCTSTR templateName, HWND parentWindow);
168370b324cSopenharmony_ci  INT_PTR Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); }
169370b324cSopenharmony_ci  #ifndef _UNICODE
170370b324cSopenharmony_ci  INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
171370b324cSopenharmony_ci  #endif
172370b324cSopenharmony_ci
173370b324cSopenharmony_ci  bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); }
174370b324cSopenharmony_ci  virtual void OnOK() Z7_override { End(IDOK); }
175370b324cSopenharmony_ci  virtual void OnCancel() Z7_override { End(IDCANCEL); }
176370b324cSopenharmony_ci  virtual void OnClose() Z7_override { End(IDCLOSE); }
177370b324cSopenharmony_ci};
178370b324cSopenharmony_ci
179370b324cSopenharmony_ciclass CDialogChildControl: public NWindows::CWindow
180370b324cSopenharmony_ci{
181370b324cSopenharmony_ci  // unsigned m_ID;
182370b324cSopenharmony_cipublic:
183370b324cSopenharmony_ci  void Init(const NWindows::NControl::CDialog &parentDialog, unsigned id)
184370b324cSopenharmony_ci  {
185370b324cSopenharmony_ci    // m_ID = id;
186370b324cSopenharmony_ci    Attach(parentDialog.GetItem(id));
187370b324cSopenharmony_ci  }
188370b324cSopenharmony_ci};
189370b324cSopenharmony_ci
190370b324cSopenharmony_cibool IsDialogSizeOK(int xSize, int ySize, HWND hwnd = NULL);
191370b324cSopenharmony_ci
192370b324cSopenharmony_ci}}
193370b324cSopenharmony_ci
194370b324cSopenharmony_ci#endif
195