OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
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)) {
168 }
169 return retVal;
170}
171
172//
173/// Performs preprocessing of window messages for the MDI child window. If keyboard
174/// handling is enabled the parent client window's TMDIClient_PreProcessMsg member
175/// function is called to preprocess messages. In this case, the return value is
176/// true. Otherwise, TFrameWindow::PreProcessMsg is called and its return value
177/// becomes the return value of this member function.
178///
179/// If the MDI child has requested keyboard navigation then TFrameWindow's
180/// PreProcessMsg() member function will call ::IsDialogMessage() which will
181/// eat the event and the MDI client window won't get a chance to do MDI
182/// accelerator processing
183///
184/// So, we will do it here to make sure it gets done
185//
186bool
188{
189 if (KeyboardHandling && GetParentO()->PreProcessMsg(msg))
190 return true;
191 //????????????????????????????????????????????????????????????????????????????
192 // Parent->Parent-> - this is MDIFrame ???
193 if (HAccel && ::TranslateAccelerator(GetParentO()->GetParentO()->GetHandle(), HAccel, &msg))
194 return true;
195
197}
198
199void
201{
203 // if system message forward it to MainWindows() to display help message
204 if ((flags & MF_SYSMENU)>0){
206 if(frameWnd)
207 frameWnd->ForwardMessage(true);
208 }
209}
210
211//
212// Handle WM_ENTERIDLE in order to display help hints on the messsage bar if
213// there is a hint pending & this frame has a message bar.
214//
215void
217{
218 if (source == MSGF_MENU){
220 if(frameWnd)
221 frameWnd->ForwardMessage(true);
222 }
224}
225
226//
227/// Destroys the interface element associated with the TMDIChild. Calls
228/// EnableAutoCreate for each window in the child list so that the children are also
229/// re-created when the parent window is re-created.
230//
231void
233{
234 if (GetHandle())
235 {
236 for (auto& w : GetChildren())
237 if (w.GetHandle())
238 w.EnableAutoCreate();
239 if (GetParentO()) {
240 // Send destroy message to MDI client window to have it destroy this THandle
241 //
243 SetHandle(0); // Assume success
244 }
245 else {
247 SetHandle(0);
249 WARNX(OwlWin, GetHandle(), 0, "::DestroyWindow(" << static_cast<void*>(GetHandle()) << ") failed");
250 }
251 }
252}
253
254//
255/// Creates the interface element associated with the MDI child window. Otherwise,
256/// it notifies the parent MDI client window to create the child window's interface
257/// element. The supplied menuOrId parameter is ignored because MDI child windows
258/// cannot have menus.
259///
260/// An MDI Child creates its GetHandle() by sending an MDI Create packet to the MDI
261/// client.
262//
265{
266 PRECONDITION(Parent);
267
269 createStruct.szClass = GetWindowClassName().GetPointerRepresentation();
270 createStruct.szTitle = GetCaption();
271 createStruct.hOwner = *GetModule();
272 createStruct.x = Attr.X;
273 createStruct.y = Attr.Y;
274 createStruct.cx = Attr.W;
275 createStruct.cy = Attr.H;
276 createStruct.style = Attr.Style;
277 createStruct.lParam = TParam2(Attr.Param);
278
279 // Work around a Windows MDI bug w/ bad menus if MDI child is created
280 // maximized, by hiding child now & maximizing later
281 //
282 uint32 origStyle = Attr.Style;
283 if (createStruct.style & WS_MAXIMIZE)
284 createStruct.style &= ~(WS_MAXIMIZE | WS_VISIBLE);
285
287 THandle h = reinterpret_cast<THandle>(r);
288
289 // Finish up maximized MDI child workaround
290 //
291 if (h && (origStyle & WS_MAXIMIZE)) {
294 }
295 return h;
296}
297
298//
299/// Instructs a client window to activate or deactivate an MDI child window and then
300/// sends a message to the child window being activated and the child window being
301/// deactivated.
302//
303void
305{
306 if (GetHandle() == hActivated) {
307
308 // A bug in Windows MDI causes the first MDI child to not get a
309 // WM_SETFOCUS. Simulate it now
310 //
313
314 // Merge this windows menubar with the MDI frame's if there is a
315 // MenuDescr assigned
316 //
318 if (GetMenuDescr()){
319 if (frame)
320 frame->MergeMenu(*GetMenuDescr());
321 }
322 if (frame){
323 if(GetBarDescr())
324 frame->MergeBar(*GetBarDescr());
325 else
326 frame->RestoreBar();
327 }
328 }
329 else {
330 // Restore the MDI frame's menubar if there is no other MDI child being
331 // activated
332 //
333 if(!hActivated){
335 if (GetMenuDescr()) {
336 if (frame)
337 frame->RestoreMenu();
338 }
339 if (GetBarDescr()){
340 if (frame)
341 frame->RestoreBar();
342 }
343 }
344 }
345
346 // Forward MDI child activation to our client (if we have one) so that it can
347 // perform any type of activate/deactivate processing that it needs
348 //
350 if (w && w->IsWindow())
352
354}
355
356//
357/// Overrides TWindow::DefWindowProc to provide default processing for any incoming
358/// message the MDI child window does not process. In addition, DefWindowProc
359/// handles the following messages: WM_CHILDACTIVATE, WM_GETMINMAXINFO, WM_MENUCHAR,
360/// WM_MOVE, WM_SETFOCUS, WM_SIZE, and WM_SYSCOMMAND.
361//
364{
365 if (IsFlagSet(wfAlias))
367
368 return ::DefMDIChildProc(GetHandle(), msg, param1, param2);
369}
370
371
372
374
375#if OWL_PERSISTENT_STREAMS
376
377//
378// Reads data of the TMDIChild from the passed opstream
379//
380void*
381TMDIChild::Streamer::Read(ipstream& is, uint32 /*version*/) const
382{
383 ReadVirtualBase((TFrameWindow*)GetObject(), is);
384 return GetObject();
385}
386
387//
388// Writes data of the TMDIChild to the passed opstream
389//
390void
391TMDIChild::Streamer::Write(opstream& os) const
392{
393 WriteVirtualBase((TFrameWindow*)GetObject(), os);
394}
395
396#endif
397
398} // OWL namespace
399/* ========================================================================== */
400
Definition of class TApplication.
#define WARNX(group, condition, level, message)
Definition checks.h:283
#define PRECONDITION(condition)
Definition checks.h:233
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:410
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:363
void Destroy(int retVal=0) override
Destroys the interface element associated with the TMDIChild.
Definition mdichild.cpp:232
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:264
void EvEnterIdle(uint source, HWND hWndDlg)
Definition mdichild.cpp:216
void EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu)
Definition mdichild.cpp:200
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:187
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:304
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:411
void EvEnterIdle(uint source, HWND hWndDlg)
The default message handler for WM_ENTERIDLE.
Definition window.cpp:3927
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1852
virtual bool EnableWindow(bool enable)
Allows the given window to receive input from the keyboard of mouse.
Definition window.h:2169
HWND GetWindow(uint cmd) const
Returns the handle of the window that has the indicated relationship to this window.
Definition window.h:2781
auto GetChildren()
Returns a TWindow::TChildrenRange that can be iterated by standard means.
Definition window.h:547
void SetHandle(THandle)
Sets the window handle in a derived class.
Definition window.h:2031
virtual auto GetWindowClassName() -> TWindowClassName
Definition window.cpp:2274
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Virtual function provides final default processing for an incoming message Calls original window proc...
Definition window.cpp:1238
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
Definition window.cpp:402
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2003
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1838
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
Definition window.cpp:1393
LPCTSTR GetCaption() const
Returns the Title member of TWindow.
Definition window.h:1897
bool EvNCActivate(bool active)
The default message handler for WM_NCACTIVATE.
Definition window.h:3845
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:853
virtual bool ShowWindow(int cmdShow)
Displays this TWindow in a given state.
Definition window.cpp:3714
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
Definition window.h:1794
static HWND GetFocus()
Gets a handle to the window that has the focus.
Definition window.h:2136
void EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu)
The default message handler for WM_MENUSELECT.
Definition window.h:3824
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:415
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2017
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:65
@ wfAlias
TWindow is an alias to a preexisting HWND.
Definition window.h:56
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:50
unsigned long uint32
Definition number.h:30
LPARAM TParam2
Second parameter type.
Definition dispatch.h:52
WPARAM TParam1
First parameter type.
Definition dispatch.h:51
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:49
std::string tstring
Definition defs.h:80
unsigned int uint
Definition number.h:21
EV_WM_ENTERIDLE
Definition decframe.cpp:32
EV_WM_MDIACTIVATE
Definition mdichild.cpp:30
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:221
Holds TWindow attributes set during construction of a window.
Definition window.h:293
#define WS_EX_MDICHILD
Definition wsysinc.h:24