xref: /third_party/lzma/CPP/Windows/Control/Dialog.h (revision 370b324c)
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
8namespace NWindows {
9namespace NControl {
10
11class CDialog: public CWindow
12{
13  // Z7_CLASS_NO_COPY(CDialog)
14public:
15  CDialog(HWND wnd = NULL): CWindow(wnd) {}
16  virtual ~CDialog() {}
17
18  HWND GetItem(unsigned itemID) const
19    { return GetDlgItem(_window, (int)itemID); }
20
21  bool EnableItem(unsigned itemID, bool enable) const
22    { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); }
23
24  bool ShowItem(unsigned itemID, int cmdShow) const
25    { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); }
26
27  bool ShowItem_Bool(unsigned itemID, bool show) const
28    { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); }
29
30  bool HideItem(unsigned itemID) const { return ShowItem(itemID, SW_HIDE); }
31
32  bool SetItemText(unsigned itemID, LPCTSTR s)
33    { return BOOLToBool(SetDlgItemText(_window, (int)itemID, s)); }
34
35  bool SetItemTextA(unsigned itemID, LPCSTR s)
36    { return BOOLToBool(SetDlgItemTextA(_window, (int)itemID, s)); }
37
38  bool SetItemText_Empty(unsigned itemID)
39    { return SetItemText(itemID, TEXT("")); }
40
41  #ifndef _UNICODE
42  bool SetItemText(unsigned itemID, LPCWSTR s)
43  {
44    CWindow window(GetItem(itemID));
45    return window.SetText(s);
46  }
47  #endif
48
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
61  bool GetItemText(unsigned itemID, UString &s)
62  {
63    CWindow window(GetItem(itemID));
64    return window.GetText(s);
65  }
66
67  bool SetItemInt(unsigned itemID, UINT value, bool isSigned)
68    { return BOOLToBool(SetDlgItemInt(_window, (int)itemID, value, BoolToBOOL(isSigned))); }
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
76  HWND GetNextGroupItem(HWND control, bool previous)
77    { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); }
78  HWND GetNextTabItem(HWND control, bool previous)
79    { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
80
81  LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam)
82    { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); }
83  LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); }
84  LRESULT SendMsg_NextDlgCtl_CtlId(unsigned id)   { return SendMsg_NextDlgCtl_HWND(GetItem(id)); }
85  LRESULT SendMsg_NextDlgCtl_Next()          { return SendMsg_NextDlgCtl(0, FALSE); }
86  LRESULT SendMsg_NextDlgCtl_Prev()          { return SendMsg_NextDlgCtl(1, FALSE); }
87
88  bool MapRect(LPRECT rect)
89    { return BOOLToBool(MapDialogRect(_window, rect)); }
90
91  bool IsMessage(LPMSG message)
92    { return BOOLToBool(IsDialogMessage(_window, message)); }
93
94  LRESULT SendItemMessage(unsigned itemID, UINT message, WPARAM wParam, LPARAM lParam)
95    { return SendDlgItemMessage(_window, (int)itemID, message, wParam, lParam); }
96
97  bool CheckButton(unsigned buttonID, UINT checkState)
98    { return BOOLToBool(CheckDlgButton(_window, (int)buttonID, checkState)); }
99  bool CheckButton(unsigned buttonID, bool checkState)
100    { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); }
101
102  UINT IsButtonChecked_BST(unsigned buttonID) const
103    { return IsDlgButtonChecked(_window, (int)buttonID); }
104  bool IsButtonCheckedBool(unsigned buttonID) const
105    { return (IsButtonChecked_BST(buttonID) == BST_CHECKED); }
106
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);
112  virtual bool OnInit() { return true; }
113  // virtual bool OnCommand2(WPARAM wParam, LPARAM lParam);
114  virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam);
115  virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
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  */
125  virtual void OnHelp() {}
126
127  virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND);
128  virtual void OnOK() {}
129  virtual void OnCancel() {}
130  virtual void OnClose() {}
131  virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; }
132  virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; }
133
134  LONG_PTR SetMsgResult(LONG_PTR newLongPtr )
135    { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); }
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
151class CModelessDialog: public CDialog
152{
153public:
154  bool Create(LPCTSTR templateName, 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
159  virtual void OnOK() Z7_override { Destroy(); }
160  virtual void OnCancel() Z7_override { Destroy(); }
161  virtual void OnClose() Z7_override { Destroy(); }
162};
163
164class CModalDialog: public CDialog
165{
166public:
167  INT_PTR Create(LPCTSTR templateName, 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
173  bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); }
174  virtual void OnOK() Z7_override { End(IDOK); }
175  virtual void OnCancel() Z7_override { End(IDCANCEL); }
176  virtual void OnClose() Z7_override { End(IDCLOSE); }
177};
178
179class CDialogChildControl: public NWindows::CWindow
180{
181  // unsigned m_ID;
182public:
183  void Init(const NWindows::NControl::CDialog &parentDialog, unsigned id)
184  {
185    // m_ID = id;
186    Attach(parentDialog.GetItem(id));
187  }
188};
189
190bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd = NULL);
191
192}}
193
194#endif
195