OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dialog.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of TDialog class and TDialogAttr struct
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_DIALOG_H)
10#define OWL_DIALOG_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/window.h>
18#include <owl/resource.h>
19
20
21namespace owl {
22
23#include <owl/preclass.h>
24
25/// \addtogroup dlg
26/// @{
27//
28
29/// \struct TDialogAttr
30// ~~~~~~ ~~~~~~~~~~~
31/// Holds a TDialog object's creation attributes, which include the style,
32/// appearance, size, and types of controls associated with the dialog box.
33/// TDialogAttr contains two data members: Name (the resource id) and Param. These
34/// members contain user-defined data used for dialog box creation.
35//
37/// Name holds the identifier, which can be either a string or an integer resource
38/// identifier, of the dialog resource.
40
41/// Param is used to pass initialization data to the dialog box when it is
42/// constructed. You can assign a value to this field in a derived class's
43/// constructor. Although any Param-type information passed to the dialog box can be
44/// saved as a data member, Param is especially useful if you want to create a
45/// dialog box that's implemented by non-ObjectWindows code.
46///
47/// After Param is accepted it is then available in the message response functions
48/// (for example, EvInitDialog()) associated with WM_INITDIALOG.
50};
51/// @}
52//
53/// \addtogroup enabler
54/// @{
55
56/// \class TControlEnabler
57// ~~~~~ ~~~~~~~~~~~~~~~
58/// A TCommandEnabler for child controls in a dialog
59//
61 public:
63
64 // Override virtuals
65 //
66 void Enable(bool enable = true);
67 void SetText(LPCTSTR text);
68
69 using TCommandEnabler::SetText; // string-aware override
70
71 // Use this method with only buttons!
72 //
73 void SetCheck(int check);
74};
75
76/// @}
77
78/// \addtogroup dlg
79/// @{
80
81
82//
83/// \class TDialog
84// ~~~~~ ~~~~~~~
85class _OWLCLASS TDialog : virtual public TWindow {
86 public:
87 // standard constructor
88 TDialog(TWindow* parent, TResId resId, TModule* module = nullptr);
89 // construct from pointer to template
90 explicit TDialog(TWindow* parent, const DLGTEMPLATE& dlgTemplate, TAutoDelete = AutoDelete, TModule* module = nullptr);
91 // Not usual,to avoid ambiquaity, construct from handle to template
92 explicit TDialog(HGLOBAL hTemplate, TWindow* parent, TAutoDelete = AutoDelete, TModule* module=nullptr);
93
94 ~TDialog() override;
95
96 //
97 /// Override this to process messages within the dialog function.
98 /// For most messages, 1 should be returned if the message is handled, and 0 if it is not.
99 /// Some special messages require a message-specific return value other than this:
100 /// WM_CHARTOITEM, WM_COMPAREITEM, WM_CTL*, WM_INITDIALOG, WM_QUERYDRAGICON and WM_VKEYTOITEM.
101 /// See the Windows API documentation for details.
102 //
103 virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2);
104
105 /// Virtual handler for WM_INITDIALOG message, called from DialogFunction()
106 //
107 virtual bool EvInitDialog(HWND hWndFocus);
108
109 // Create a modeless dialog box, and perform actual create call
110 //
111 auto Create() -> bool override;
112
113#if defined(OWL5_COMPAT)
114 // backward compatibility. not use
115 virtual HWND DoCreate();
116#endif
117 // Create a modal dialog box, and perform actual modal execute call
118 //
119 auto Execute() -> int override;
120 auto DoExecute() -> int override;
121
122 // Override virtual functions defined by class TWindow
123 //
124 auto PreProcessMsg(MSG&) -> bool override;
125 void CloseWindow(int retValue = IDCANCEL) override;
126 void Destroy(int retValue = IDCANCEL) override;
127
128 TDialogAttr& GetDialogAttr();
129 void SetDialogAttr(TDialogAttr attr);
130
131 bool GetIsModal() const;
132 void SetIsModal(bool ismodal);
133
134 // enable emulation of Modal Dialog by BeginModal/EndModal
135 void EnableModal(bool enable=true);
136
137 // Handy dialog functions
138 //
139 uint GetDefaultId() const;
140 void SetDefaultId(uint id);
141 bool MapDialogRect(TRect& rect) const;
142 auto MapDialogRectToScreen(const TRect&) const -> TRect;
143 void Reposition();
144
145 /// Enumeration to be used when invoking the 'SetControlFocus' method.
146 /// It specifies whether focus should be set to the next or previous
147 /// sibling of the current control with focus.
148 //
149 enum THow {
150 Next, ///< Set focus to the next sibling
151 Previous ///< Set focus to the previous sibling
152 };
153 void SetControlFocus(HWND hwnd);
154 void SetControlFocus(THow how);
155
156 //
157 /// Sets the dialog procedure message result (DWLP_MSGRESULT) and returns true.
158 //
159 bool SetMsgResult(TResult result);
160
161 // Message response functions
162 //
163 void EvClose();
164 void EvPaint();
165 uint EvGetDefId();
166 bool EvSetDefId(int id);
167 void EvReposition();
168
169 // Child notifications
170 //
171 void CmOk(); // IDOK
172 void CmCancel(); // IDCANCEL
173
174#if defined(OWL5_COMPAT)
175 /// Sends the passed message to the dialog's control which has id DlgItemId
176 /// Obsolete- use TWindow::SendDlgItemMessage()
177 //
179#endif
180
181 /// Callback procs for hooking TDialog to native window
182 //
183 static INT_PTR CALLBACK StdDlgProc(HWND, UINT, WPARAM, LPARAM) noexcept;
184
185 /// Handle enabling and disabling of child controls
186 //
187 auto IdleAction(long idleCount) -> bool override;
188
189 protected:
190 // Override virtual functions defined by class TWindow
191 //
192 auto PerformCreate() -> THandle override;
193 void SetupWindow() override;
194 auto GetWindowClassName() -> TWindowClassName override;
195 void GetWindowClass(WNDCLASS&) override;
196
197 /// Registers WINDOW class(es) of Children
198 //
199 void RegisterChildObjects();
200
201 /// Common initialization in constructor
202 void Init(TWindow* parent, LPCTSTR title, TModule* module);
203
204 /// Initialize dialog controls with contents of DLGINIT resources, if any.
205 //
206 bool PerformDlgInit();
207
209 union {
210 TDialogAttr Attr; ///< Old name
211 TDialogAttr DialogAttr; ///< New name
212 };
213
214#if defined(OWL5_COMPAT)
215/// IsModal is true if the dialog box is modal and false if it is modeless.
216 bool IsModal; ///< Don't use
217#endif
218
220 enum{
221 // using TWindows::Flags
222 //wfInsertAtEdge = 0x008000 // (Decoration) Window to be inserted against frame's edge
223 dfResId = 0x000000L, ///< Dialog created from ResId default
224 dfNoDeleteHandle = 0x010000L, ///< Dialog created from HGLOBAL no delete
225 dfDeleteHandle = 0x020000L, ///< Dialog created from HGLOBAL delete
226 dfNoDeleteTemplate= 0x040000L, ///< Dialog created from LPDIALOGTEMPLATE no delete
227 dfDeleteTemplate = 0x080000L, ///< Dialog created from LPDIALOGTEMPLATE delete
228 dfIsModal = 0x100000L, ///< Dialog Is Modal
229 dfModalWindow = 0x200000L, ///< Use BeginModal() EndModal() functionality
230 };
231
232 private:
233 // Hidden to prevent accidental copying or assignment
234 //
235 TDialog(const TDialog&);
236 TDialog& operator =(const TDialog&);
237
238 DECLARE_RESPONSE_TABLE(TDialog);
239 DECLARE_STREAMABLE_OWL(TDialog, 1);
240};
241/// @}
242
244
245#include <owl/posclass.h>
246
247//----------------------------------------------------------------------------
248// Inline implementations
249//
250
251#if defined(OWL5_COMPAT)
252
253//
254/// Do not use DoCreate. It is included if OWL5_COMPAT is defined for backward
255/// compatibility. It calls PerformCreate() and returns Handle.
256//
257inline TWindow::THandle
258TDialog::DoCreate()
259{
260 return PerformCreate();
261}
262
263//
264/// Sends a window control message, identified by Msg, to the dialog box's control
265/// identified by its supplied ID, ChildID. WParam and LParam become parameters in
266/// the control message. SendDlgItemMsg returns the value returned by the control,
267/// or 0 if the control ID is invalid. This function is obsolete - use
268/// TWindow::SendDlgItemMessage().
269//
270inline TResult
271TDialog::SendDlgItemMsg(int ChildId, TMsgId msg, TParam1 p1, TParam2 p2)
272{
274}
275
276#endif
277
278//
279/// Set the result of the message for the dialog's WndProc.
280//
281inline bool
283{
286 return true;
287}
288
289//
290/// Return the ID of the default pushbutton.
291//
292inline uint
298
299//
300/// Return the attributes data member of TDialog.
301//
302inline TDialogAttr&
304{
305 return DialogAttr;
306}
307
308//
309/// Set the attributes of the dialog.
310//
311inline void
316
317//
318/// Return true if the dialog is modal.
319//
320inline bool
322{
323 return CONST_CAST(TDialog*,this)->IsFlagSet(dfIsModal);//IsModal -> old flag don't use;
324}
325
326//
327/// Set the modal data member of TDialog.
328//
329inline void
331{
332#if defined(OWL5_COMPAT)
333 IsModal = ismodal;// old flag
334#endif
335 ismodal ? SetFlag(dfIsModal) : ClearFlag(dfIsModal);
336}
337
338//
339/// Enables emulation of executing ModalDialog box by calling
340/// BeginModal()/EndModal()
341//
342inline void
344{
345 enable ? SetFlag(dfModalWindow) : ClearFlag(dfModalWindow);
346}
347
348//
349/// Set the id of the default push button.
350//
351inline void
357
358//
359/// Converts the coordinates of the given rect from dialog units into screen units.
360//
361inline bool
363{
365 return ::MapDialogRect(GetHandle(), &rect) != FALSE;
366}
367
368//
369/// Reposition the dialog to ensure it is fully visible.
370//
371inline void
377
378
379} // OWL namespace
380
381#endif // OWL_DIALOG_H
#define PRECONDITION(condition)
Definition checks.h:227
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
A TCommandEnabler for child controls in a dialog.
Definition dialog.h:60
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
void EnableModal(bool enable=true)
Enables emulation of executing ModalDialog box by calling BeginModal()/EndModal()
Definition dialog.h:343
THow
Enumeration to be used when invoking the 'SetControlFocus' method.
Definition dialog.h:149
@ Next
Set focus to the next sibling.
Definition dialog.h:150
bool SetMsgResult(TResult result)
Sets the dialog procedure message result (DWLP_MSGRESULT) and returns true.
Definition dialog.h:282
TDialogAttr & GetDialogAttr()
Return the attributes data member of TDialog.
Definition dialog.h:303
void SetDefaultId(uint id)
Set the id of the default push button.
Definition dialog.h:352
void Reposition()
Reposition the dialog to ensure it is fully visible.
Definition dialog.h:372
uint GetDefaultId() const
Return the ID of the default pushbutton.
Definition dialog.h:293
auto PerformCreate() -> THandle override
Called from Create to perform the final step in creating an Windows interface element to be associate...
Definition dialog.cpp:533
bool MapDialogRect(TRect &rect) const
Converts the coordinates of the given rect from dialog units into screen units.
Definition dialog.h:362
void SetIsModal(bool ismodal)
Set the modal data member of TDialog.
Definition dialog.h:330
TDialogAttr DialogAttr
New name.
Definition dialog.h:211
bool GetIsModal() const
Return true if the dialog is modal.
Definition dialog.h:321
TDialogAttr Attr
Old name.
Definition dialog.h:210
void SetDialogAttr(TDialogAttr attr)
Set the attributes of the dialog.
Definition dialog.h:312
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void SetFlag(uint mask)
Sets the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1783
LONG_PTR SetWindowLongPtr(int index, LONG_PTR newLong)
Changes information about the window. For a list of constants, see GetWindowLongPtr()
Definition window.h:2428
TResult SendDlgItemMessage(int childId, TMsgId, TParam1=0, TParam2=0)
Sends a message (msg) to the control specified in childId.
Definition window.h:2092
void ClearFlag(uint mask)
Clears the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1790
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
@ AutoDelete
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
uint16 LoUint16(LRESULT r)
Definition defs.h:264
LRESULT TResult
Result type.
Definition dispatch.h:52
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define public_data
Definition defs.h:207
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define _OWLCLASS
Definition defs.h:338
Defines classes handling Windows resources.
Holds a TDialog object's creation attributes, which include the style, appearance,...
Definition dialog.h:36
LPARAM Param
Param is used to pass initialization data to the dialog box when it is constructed.
Definition dialog.h:49
TCHAR * Name
Name holds the identifier, which can be either a string or an integer resource identifier,...
Definition dialog.h:39
Base window class TWindow definition, including HWND encapsulation.