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
mdichild.cpp
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/// Implementation of TMDIChild. This defines the basic behavior of all MDI
7/// child windows
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/mdichild.h>
11#include <owl/mdi.h>
12#include <owl/applicat.h>
13
14#if defined(__BORLANDC__)
15# pragma option -w-ccc // Disable "Condition is always true/false"
16#endif
17
18namespace owl {
19
21DIAG_DECLARE_GROUP(OwlWin); // diagnostic group for windows
22
23#if !defined(WS_EX_MDICHILD)
24# define WS_EX_MDICHILD 0x00000040L
25#endif
26
27
28DEFINE_RESPONSE_TABLE1(TMDIChild, TFrameWindow)
34
35namespace
36{
37
38 // Initializes attributes (helper used by the constructors).
39 //
41 {
42 a.Y = a.H = CW_USEDEFAULT;
45 a.ExStyle |= WS_EX_MDICHILD;
46 }
47
48} // namespace
49
50//
51/// Constructor for a TMDIChild
52///
53/// Creates an MDI child window of the MDI client window specified by
54/// parent, using the specified title, client window (clientWnd) and instance
55/// (inst). Invokes the TFrameWindow base class constructor, supplying parent,
56/// title, clientWnd, inst, and indicating that the child window is not to be
57/// resized to fit. Invokes the TWindow base class constructor, specifying parent,
58/// title, and inst. The window attributes are then adjusted to include WS_VISIBLE,
59/// WS_CHILD, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, WS_SYSMENU, WS_CAPTION,
60/// WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX. The dimensions of the window
61/// are set to the system default values.
62//
73
74//
75/// String-aware overload
76//
78 TMDIClient& parent,
79 const tstring& title,
81 bool shrinkToClient,
82 TModule* module)
83{
84 TWindow::Init(&parent, title, module);
86 InitAttributes(Attr);
87}
88
89//
90/// Constructor for a TMDIChild which is being used in a DLL as an alias for a non-OWL window
91///
92/// Creates an MDI child window object from a preexisting window, specified
93/// by hWnd. The base class TFrameWindow constructor is invoked, specifying this
94/// hWnd, as well as the specified inst. The base class TWindow constructor is
95/// invoked, supplying the hWnd and inst parameters.
96//
98:
99 TWindow(handle, module),
100 TFrameWindow(handle, module)
101{
102 Attr.Style = WS_CLIPSIBLINGS;
103 Attr.ExStyle |= WS_EX_MDICHILD;
104}
105
106//
107// Destructor for a MDI child
108//
112
113//
114/// Responds to a request to change a title bar or icon.
115///
116/// Don't allow NC Activation if we are only temporarily unhidden for window
117/// menu maintainance
118//
119bool
124
125//
126/// Overrides TWindow's virtual function. Displays a child window according to the
127/// value of cmdShow.
128///
129/// Perform special processing for showing MDI children to make sure that
130/// the MDI client maintains the window list correctly
131//
132bool
134{
135 int retVal = TFrameWindow::ShowWindow(cmdShow); // 0 if had been hidden
136
137 // Process only if visible state has changed
138 //
139 if ((retVal != 0) != (cmdShow != SW_HIDE)) {
141 if (cmdShow == SW_HIDE)
143 else
144 HandleMessage(WM_NCACTIVATE, true); // resend suppressed message
145 }
147 }
148 return retVal;
149}
150
151//
152/// Overrides TWindow's virtual function. Enables a child window.
153///
154/// Perform special processing for enabling MDI children to make sure that
155/// the MDI client maintains the window list correctly
156//
157bool
159{
160 int retVal = TFrameWindow::EnableWindow(enable); // 0 if previously enabled
161
162 // Process only if disabled state has actually changed
163 //
164 if ((retVal != 0) != (enable == 0))
165 {
166 if (!enable && reinterpret_cast<THandle>(GetParent()->HandleMessage(WM_MDIGETACTIVE)) == *this)
169 }
170 return retVal;
171}
172
173//
174/// Performs preprocessing of window messages for the MDI child window. If keyboard
175/// handling is enabled the parent client window's TMDIClient_PreProcessMsg member
176/// function is called to preprocess messages. In this case, the return value is
177/// true. Otherwise, TFrameWindow::PreProcessMsg is called and its return value
178/// becomes the return value of this member function.
179///
180/// If the MDI child has requested keyboard navigation then TFrameWindow's
181/// PreProcessMsg() member function will call ::IsDialogMessage() which will
182/// eat the event and the MDI client window won't get a chance to do MDI
183/// accelerator processing
184///
185/// So, we will do it here to make sure it gets done
186//
187bool
189{
190 if (KeyboardHandling && GetParentO()->PreProcessMsg(msg))
191 return true;
192 //????????????????????????????????????????????????????????????????????????????
193 // Parent->Parent-> - this is MDIFrame ???
194 if (HAccel && ::TranslateAccelerator(GetParentO()->GetParentO()->GetHandle(), HAccel, &msg))
195 return true;
196
198}
199
200void
202{
204 // if system message forward it to MainWindows() to display help message
205 if ((flags & MF_SYSMENU)>0){
207 if(frameWnd)
208 frameWnd->ForwardMessage(true);
209 }
210}
211
212//
213// Handle WM_ENTERIDLE in order to display help hints on the messsage bar if
214// there is a hint pending & this frame has a message bar.
215//
216void
218{
219 if (source == MSGF_MENU){
221 if(frameWnd)
222 frameWnd->ForwardMessage(true);
223 }
225}
226
227//
228/// Destroys the interface element associated with the TMDIChild. Calls
229/// EnableAutoCreate for each window in the child list so that the children are also
230/// re-created when the parent window is re-created.
231//
232void
234{
235 if (GetHandle())
236 {
237 for (auto& w : GetChildren())
238 if (w.GetHandle())
239 w.EnableAutoCreate();
240 if (GetParentO()) {
241 // Send destroy message to MDI client window to have it destroy this THandle
242 //
244 SetHandle(nullptr); // Assume success
245 }
246 else {
248 SetHandle(nullptr);
250 WARNX(OwlWin, GetHandle(), 0, "::DestroyWindow(" << static_cast<void*>(GetHandle()) << ") failed");
251 }
252 }
253}
254
255//
256/// Creates the interface element associated with the MDI child window. Otherwise,
257/// it notifies the parent MDI client window to create the child window's interface
258/// element. The supplied menuOrId parameter is ignored because MDI child windows
259/// cannot have menus.
260///
261/// An MDI Child creates its GetHandle() by sending an MDI Create packet to the MDI
262/// client.
263//
266{
267 PRECONDITION(Parent);
268
270 createStruct.szClass = GetWindowClassName().GetPointerRepresentation();
271 createStruct.szTitle = GetCaption();
272 createStruct.hOwner = *GetModule();
273 createStruct.x = Attr.X;
274 createStruct.y = Attr.Y;
275 createStruct.cx = Attr.W;
276 createStruct.cy = Attr.H;
277 createStruct.style = Attr.Style;
278 createStruct.lParam = TParam2(Attr.Param);
279
280 // Work around a Windows MDI bug w/ bad menus if MDI child is created
281 // maximized, by hiding child now & maximizing later
282 //
283 uint32 origStyle = Attr.Style;
284 if (createStruct.style & WS_MAXIMIZE)
285 createStruct.style &= ~(WS_MAXIMIZE | WS_VISIBLE);
286
288 THandle h = reinterpret_cast<THandle>(r);
289
290 // Finish up maximized MDI child workaround
291 //
292 if (h && (origStyle & WS_MAXIMIZE)) {
295 }
296 return h;
297}
298
299//
300/// Instructs a client window to activate or deactivate an MDI child window and then
301/// sends a message to the child window being activated and the child window being
302/// deactivated.
303//
304void
306{
307 if (GetHandle() == hActivated) {
308
309 // A bug in Windows MDI causes the first MDI child to not get a
310 // WM_SETFOCUS. Simulate it now
311 //
314
315 // Merge this windows menubar with the MDI frame's if there is a
316 // MenuDescr assigned
317 //
319 if (GetMenuDescr()){
320 if (frame)
321 frame->MergeMenu(*GetMenuDescr());
322 }
323 if (frame){
324 if(GetBarDescr())
325 frame->MergeBar(*GetBarDescr());
326 else
327 frame->RestoreBar();
328 }
329 }
330 else {
331 // Restore the MDI frame's menubar if there is no other MDI child being
332 // activated
333 //
334 if(!hActivated){
336 if (GetMenuDescr()) {
337 if (frame)
338 frame->RestoreMenu();
339 }
340 if (GetBarDescr()){
341 if (frame)
342 frame->RestoreBar();
343 }
344 }
345 }
346
347 // Forward MDI child activation to our client (if we have one) so that it can
348 // perform any type of activate/deactivate processing that it needs
349 //
351 if (w && w->IsWindow())
353
355}
356
357//
358/// Overrides TWindow::DefWindowProc to provide default processing for any incoming
359/// message the MDI child window does not process. In addition, DefWindowProc
360/// handles the following messages: WM_CHILDACTIVATE, WM_GETMINMAXINFO, WM_MENUCHAR,
361/// WM_MOVE, WM_SETFOCUS, WM_SIZE, and WM_SYSCOMMAND.
362//
365{
366 if (IsFlagSet(wfAlias))
368
369 return ::DefMDIChildProc(GetHandle(), msg, param1, param2);
370}
371
372
373
375
376#if OWL_PERSISTENT_STREAMS
377
378//
379// Reads data of the TMDIChild from the passed opstream
380//
381void*
382TMDIChild::Streamer::Read(ipstream& is, uint32 /*version*/) const
383{
384 ReadVirtualBase((TFrameWindow*)GetObject(), is);
385 return GetObject();
386}
387
388//
389// Writes data of the TMDIChild to the passed opstream
390//
391void
392TMDIChild::Streamer::Write(opstream& os) const
393{
394 WriteVirtualBase((TFrameWindow*)GetObject(), os);
395}
396
397#endif
398
399} // OWL namespace
400/* ========================================================================== */
401
Definition of class TApplication.
#define WARNX(group, condition, level, message)
Definition checks.h:277
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
void ResumeThrow()
Rethrows the suspended exception stored by a previous call to SuspendThrow.
Derived from TWindow, TFrameWindow controls such window-specific behavior as keyboard navigation and ...
Definition framewin.h:96
void Init(TWindow *clientWnd, bool shrinkToClient)
Normal initialization of a default constructed TFrameWindow.
Definition framewin.cpp:166
virtual bool MergeMenu(const TMenuDescr &childMenuDescr)
Merges the given menu descriptor with this frame's own menu descriptor and displays the resulting men...
virtual TWindow * GetClientWindow()
Returns a pointer to the client window.
Definition framewin.cpp:591
virtual bool MergeBar(const TBarDescr &childBarDescr)
Do nothing. Return false. Overriden in TDecoratedFrame.
Definition framewin.h:333
virtual bool RestoreBar()
Do nothing in TFrameWindow. Overriden in TDecoratedFrame.
Definition framewin.h:341
auto PreProcessMsg(MSG &) -> bool override
Overrides TWindow's virtual function.
Definition framewin.cpp:436
const TMenuDescr * GetMenuDescr() const
Returns a pointer to the menu descriptor for the frame window.
Definition framewin.h:316
const TBarDescr * GetBarDescr() const
Returns a pointer to the control bar descriptor.
Definition framewin.h:324
TMDIChild defines the basic behavior of all MDI child windows.
Definition mdichild.h:42
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Overrides TWindow::DefWindowProc to provide default processing for any incoming message the MDI child...
Definition mdichild.cpp:364
void Destroy(int retVal=0) override
Destroys the interface element associated with the TMDIChild.
Definition mdichild.cpp:233
auto ShowWindow(int cmdShow) -> bool override
Overrides TWindow's virtual function.
Definition mdichild.cpp:133
auto EnableWindow(bool enable) -> bool override
Overrides TWindow's virtual function.
Definition mdichild.cpp:158
TMDIChild(TMDIClient &parent, LPCTSTR title=0, TWindow *clientWnd=0, bool shrinkToClient=false, TModule *module=0)
Constructor for a TMDIChild.
Definition mdichild.cpp:63
auto PerformCreate() -> THandle override
Creates the interface element associated with the MDI child window.
Definition mdichild.cpp:265
void EvEnterIdle(uint source, HWND hWndDlg)
Definition mdichild.cpp:217
void EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu)
Definition mdichild.cpp:201
bool EvNCActivate(bool active)
Responds to a request to change a title bar or icon.
Definition mdichild.cpp:120
auto PreProcessMsg(MSG &) -> bool override
Performs preprocessing of window messages for the MDI child window.
Definition mdichild.cpp:188
void EvMDIActivate(HWND hWndActivated, HWND hWndDeactivated)
Instructs a client window to activate or deactivate an MDI child window and then sends a message to t...
Definition mdichild.cpp:305
Multiple Document Interface (MDI) client windows (represented by a TMDIClient object) manage the MDI ...
Definition mdi.h:37
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void EvEnterIdle(uint source, HWND hWndDlg)
The default message handler for WM_ENTERIDLE.
Definition window.cpp:3926
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1855
virtual bool EnableWindow(bool enable)
Allows the given window to receive input from the keyboard of mouse.
Definition window.h:2172
HWND GetWindow(uint cmd) const
Returns the handle of the window that has the indicated relationship to this window.
Definition window.h:2784
auto GetChildren()
Returns a TWindow::TChildrenRange that can be iterated by standard means.
Definition window.h:550
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
Definition window.h:2013
void SetHandle(THandle)
Sets the window handle in a derived class.
Definition window.h:2034
virtual auto GetWindowClassName() -> TWindowClassName
Definition window.cpp:2273
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Virtual function provides final default processing for an incoming message Calls original window proc...
Definition window.cpp:1237
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
Definition window.cpp:401
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
Definition window.cpp:1392
LPCTSTR GetCaption() const
Returns the Title member of TWindow.
Definition window.h:1900
bool EvNCActivate(bool active)
The default message handler for WM_NCACTIVATE.
Definition window.h:3848
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
virtual bool ShowWindow(int cmdShow)
Displays this TWindow in a given state.
Definition window.cpp:3713
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
Definition window.h:1797
static HWND GetFocus()
Gets a handle to the window that has the focus.
Definition window.h:2139
void EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu)
The default message handler for WM_MENUSELECT.
Definition window.h:3827
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
void ReadVirtualBase(Base *base, ipstream &in)
Definition objstrm.h:1190
void WriteVirtualBase(Base *base, opstream &out)
Definition objstrm.h:1169
#define IMPLEMENT_STREAMABLE2(cls, base1, base2)
Definition objstrm.h:1726
@ wfUnHidden
Used temporarily when destroying MDI child.
Definition window.h:68
@ wfAlias
TWindow is an alias to a preexisting HWND.
Definition window.h:59
Definition of TMDIClient and TMDIFrame classes.
Definition of class TMDIChild.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
EV_WM_NCACTIVATE
Definition floatfra.cpp:31
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
EV_WM_MENUSELECT
Definition decframe.cpp:33
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
EV_WM_ENTERIDLE
Definition decframe.cpp:32
EV_WM_MDIACTIVATE
Definition mdichild.cpp:30
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Holds TWindow attributes set during construction of a window.
Definition window.h:296
#define WS_EX_MDICHILD
Definition wsysinc.h:24