OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
mdiframe.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 class TMDIFrame. This defines the basic behavior of
7/// all MDI frame windows.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/mdi.h>
11#include <owl/applicat.h>
12#include <type_traits>
13
14namespace owl {
15
19
20
21DEFINE_RESPONSE_TABLE1(TMDIFrame, TFrameWindow)
23
24//
25/// Constructs an MDI frame window object using the caption (title) and resource ID
26/// (menuResId). If no client window is specified (clientWnd), then an instance of
27/// TMDIClient is created automatically and used as the client window of the frame.
28/// The supplied library ID (module) is passed to the TFrameWindow constructor along
29/// with a null parent window pointer, caption, client window, and a flag indicating
30/// that the client window is not to be resized to fit. The TWindow constructor is
31/// also invoked; it passes the supplied caption and library ID, as well as a null
32/// parent window pointer. Then the child menu position is initialized to be the
33/// leftmost menu item, and the supplied menu resource ID is used in a call to
34/// TFrameWindow::AssignMenu.
35//
36TMDIFrame::TMDIFrame(LPCTSTR title, TResId menuResId, std::unique_ptr<TMDIClient> clientWnd, TModule* module)
37{
38 auto c = clientWnd ? move(clientWnd) : std::make_unique<TMDIClient>();
39
40 // Initialize virtual bases.
41 //
42 TWindow::Init(nullptr, title, module);
43 TFrameWindow::Init(c.get(), false);
44 c.release(); // Base took ownership.
45
46 if (menuResId)
48}
49
50//
51/// String-aware overload.
52//
53TMDIFrame::TMDIFrame(const tstring& title, TResId menuResId, std::unique_ptr<TMDIClient> clientWnd, TModule* module)
55{}
56
57#if defined(OWL5_COMPAT)
58
59//
60/// Old OWL 5 constructor.
61/// Use the new safe constructor instead.
62//
66 TModule* module)
67{
68 // Initialize virtual bases, in case the derived-most used default ctor
69 //
70 TWindow::Init(0, title, module);
72
73 if (menuResId)
75}
76
77//
78/// String-aware overload of the old OWL 5 constructor.
79/// Use the new safe constructor instead.
80//
82 const tstring& title,
83 TResId menuResId,
84 TMDIClient& clientWnd,
85 TModule* module)
86{
87 // Initialize virtual bases, in case the derived-most used default ctor
88 //
89 TWindow::Init(0, title, module);
91 if (menuResId)
93}
94
95#endif
96
97//
98/// Constructs an MDI frame window using an already created non-ObjectWindows
99/// window. Invokes the TFrameWindow and TWindow constructors, passing in the
100/// window handle (hWindow) and library ID (module). Initializes the child menu
101/// position to the leftmost menu item and constructs a TMDIClient object that
102/// corresponds to the supplied clientHWnd.
103//
105:
106 TWindow(handle, module),
107 TFrameWindow(handle, module)
108{
110
111 // NOTE: Attr.Menu set in TWindow's constructor
112 //
113 ClientWnd = new TMDIClient(clientHandle);
114 ClientWnd->SetParent(this);
115}
116
117//
118/// Overrides TWindow's virtual PerformCreate function. Creates the interface
119/// element associated with the MDI frame window.
120///
121//
123{
124 PRECONDITION(GetModule());
125 //
126 // An MDI frame must have a menu. Give it an empty one if none is supplied.
127 // Use RAII to ensure the menu is released in case of failure.
128 //
129 struct TMenuGuard
130 {
131 HMENU m;
132 TMenuGuard(HMENU m_) : m(m_) {}
133 ~TMenuGuard() { if (m) DestroyMenu(m); }
134 operator HMENU() { return m; }
135 HMENU RelinquishOwnership() { HMENU tmp = m; m = nullptr; return tmp; }
136 }
137 menu(Attr.Menu ? LoadMenu(Attr.Menu) : CreateMenu());
138 WARNX(OwlWin, !menu, 0, _T("Unable to load menu: ") << Attr.Menu << _T(" from ") << *GetModule());
140 Attr.ExStyle,
141 GetWindowClassName().GetPointerRepresentation(),
142 Title,
143 Attr.Style,
144 Attr.X, Attr.Y, Attr.W, Attr.H,
145 Parent ? Parent->GetHandle() : nullptr,
146 menu,
147 *GetModule(),
148 Attr.Param
149 );
150 if (h) menu.RelinquishOwnership(); // The menu belongs to the window now.
151 return h;
152}
153
154//
155/// FindChildMenu searches, from right to left, the pop-up child menus contained in
156/// the newMenu menu resource for a child menu containing command items with one of
157/// the following identifiers: CM_CASCADECHILDREN, CM_TITLECHILDREN, or
158/// CM_ARRANGEICONS. The return value of FindChildMenu is the HMENU of the first
159/// child menu containing one of these identifiers. If one of these identifiers is
160/// not found, FindChildMenu returns 0.
161/// FindChildMenu is used to locate the menu to which the MDI child window list
162/// will be appended. This call to FindChildMenu is made from within the TMDIClient
163/// class.
164//
165HMENU
167{
168 if (menu) {
169 int numItems = ::GetMenuItemCount(menu);
170 for (int i = numItems-1; i >= 0; i--) {
171 HMENU childMenu = ::GetSubMenu(menu, i);
172 if (childMenu &&
176 {
177 return childMenu;
178 }
179 }
180 }
181 return nullptr;
182}
183
184//
185/// Searches for the MDI child menu in the new menu bar and updates the child menu
186/// position with the specified menu index. Then sends the client window an
187/// WM_MDISETMENU message to set the new menu and invokes TWindow::DrawMenuBar to
188/// redraw the menu. Returns false if the MDI client indicates that there was no
189/// previous menu; otherwise returns true.
190//
191bool
193{
195
198
199 if (GetHandle()) {
201 HMENU oldMenu = (HMENU)ClientWnd->HandleMessage(WM_MDISETMENU,
204 DrawMenuBar();
205 if (!oldMenu)
206 return false;
207 }
208 return true;
209}
210
211//
212/// Returns a pointer to the MDI client window.
213//
216{
217 return TYPESAFE_DOWNCAST(ClientWnd,TMDIClient);
218}
219
220//
221/// Locates and returns the child window that is the target of the command and the
222/// command enabling messages. If the current application does not have focus or if
223/// the focus is within a toolbar in the application, GetCommandTarget returns the
224/// most recently active child window. If an alternative form of command processing
225/// is desired, a user's main window class can override this function.
226//
228{
229 TFrameWindow* mdiChild = GetClientWindow()->GetActiveMDIChild();
230
231 TRACEX(OwlCmd, 1, "TMDIFrame::GetCommandTarget - returns " << \
232 (mdiChild ? "ActiveMDIChild->GetCommandTarget()" \
233 : "TFrameWindow::GetCommandTarget()"));
234
235 return mdiChild ? mdiChild->GetCommandTarget() : TFrameWindow::GetCommandTarget();
236}
237
238//
239/// Overrides TWindow::DefWindowProc and provides default processing for any
240/// incoming message the MDI frame window does not process.
241//
244{
245 return ::DefFrameProc(GetHandle(), ClientWnd ? ClientWnd->GetHandle() : nullptr, message, param1, param2);
246}
247
248
250
251#if OWL_PERSISTENT_STREAMS
252
253//
254// Reads an instance of TMDIFrame from the passed ipstream
255//
256void*
257TMDIFrame::Streamer::Read(ipstream& is, uint32 /*version*/) const
258{
260 GetObject()->AssignMenu(GetObject()->Attr.Menu);
261 return GetObject();
262}
263
264//
265// Writes the TMDIFrame to the passed opstream
266//
267void
268TMDIFrame::Streamer::Write(opstream& os) const
269{
270 WriteVirtualBase<TFrameWindow>((TFrameWindow*)GetObject(), os);
271}
272
273#endif
274
275} // OWL namespace
276/* ========================================================================== */
277
Definition of class TApplication.
#define CHECK(condition)
Definition checks.h:239
#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
#define TRACEX(group, level, message)
Definition checks.h:263
virtual void PreProcessMenu(HMENU hMenubar)
Called by the main window to provide an oportunity to preprocess the main window's menubar before it ...
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 HWND GetCommandTarget()
Locates and returns the child window that is the target of the command and command enable messages.
Definition framewin.cpp:328
virtual bool AssignMenu(TResId menuResId)
Perform a high-level menu assignment either before or after the HWND for the window has been created.
Definition framewin.cpp:491
Multiple Document Interface (MDI) client windows (represented by a TMDIClient object) manage the MDI ...
Definition mdi.h:37
Multiple Document Interface (MDI) frame windows, represented by TMDIFrame, are overlapped windows tha...
Definition mdi.h:122
auto SetMenu(HMENU) -> bool override
Searches for the MDI child menu in the new menu bar and updates the child menu position with the spec...
Definition mdiframe.cpp:192
auto GetClientWindow() -> TMDIClient *override
Returns a pointer to the MDI client window.
Definition mdiframe.cpp:215
auto PerformCreate() -> THandle override
Overrides TWindow's virtual PerformCreate function.
Definition mdiframe.cpp:122
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Overrides TWindow::DefWindowProc and provides default processing for any incoming message the MDI fra...
Definition mdiframe.cpp:243
static HMENU FindChildMenu(HMENU)
Find & return the child menu of an MDI frame's (or anyone's) menu bar.
Definition mdiframe.cpp:166
auto GetCommandTarget() -> HWND override
Locates and returns the child window that is the target of the command and the command enabling messa...
Definition mdiframe.cpp:227
TMDIFrame(LPCTSTR title, TResId menuResId, std::unique_ptr< TMDIClient > clientWnd=nullptr, TModule *=nullptr)
Constructs an MDI frame window object using the caption (title) and resource ID (menuResId).
Definition mdiframe.cpp:36
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
static UINT GetMenuState(HMENU, UINT, UINT)
Definition module.cpp:1110
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1855
void DrawMenuBar()
DrawMenuBar redraws the menu bar.
Definition window.h:3313
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
Definition window.h:2013
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
Definition window.cpp:401
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
Definition window.h:1797
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 _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define IMPLEMENT_STREAMABLE2(cls, base1, base2)
Definition objstrm.h:1726
@ wfMainWindow
This frame window is the main window.
Definition window.h:63
Definition of TMDIClient and TMDIFrame classes.
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
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269