]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
a967ef9d VZ |
2 | // Name: src/msw/mdi.cpp |
3 | // Purpose: MDI classes for wxMSW | |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
c2dcfdef | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a23fd0e1 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
a23fd0e1 | 21 | #pragma implementation "mdi.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
a23fd0e1 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
a23fd0e1 VZ |
32 | #include "wx/setup.h" |
33 | #include "wx/frame.h" | |
34 | #include "wx/menu.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/utils.h" | |
37 | #include "wx/dialog.h" | |
7c0ea335 VZ |
38 | #if wxUSE_STATUSBAR |
39 | #include "wx/statusbr.h" | |
40 | #endif | |
a23fd0e1 | 41 | #include "wx/settings.h" |
0c589ad0 BM |
42 | #include "wx/intl.h" |
43 | #include "wx/log.h" | |
2bda0e17 KB |
44 | #endif |
45 | ||
b9f933ab JS |
46 | #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__) |
47 | ||
2bda0e17 KB |
48 | #include "wx/mdi.h" |
49 | #include "wx/msw/private.h" | |
50 | ||
7c0ea335 | 51 | #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |
3096bd2f | 52 | #include "wx/msw/statbr95.h" |
2bda0e17 KB |
53 | #endif |
54 | ||
7c0ea335 VZ |
55 | #if wxUSE_TOOLBAR |
56 | #include "wx/toolbar.h" | |
57 | #endif // wxUSE_TOOLBAR | |
58 | ||
2bda0e17 KB |
59 | #include <string.h> |
60 | ||
a23fd0e1 VZ |
61 | // --------------------------------------------------------------------------- |
62 | // global variables | |
63 | // --------------------------------------------------------------------------- | |
64 | ||
65 | extern wxWindowList wxModelessWindows; // from dialog.cpp | |
e1a6fc11 | 66 | extern wxMenu *wxCurrentPopupMenu; |
2bda0e17 | 67 | |
3ca6a5f0 | 68 | extern const wxChar *wxMDIFrameClassName; // from app.cpp |
2ffa221c | 69 | extern const wxChar *wxMDIChildFrameClassName; |
3ca6a5f0 BP |
70 | extern const wxChar *wxMDIChildFrameClassNameNoRedraw; |
71 | ||
c7527e3f | 72 | extern void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win); |
ac6482e0 | 73 | extern void wxRemoveHandleAssociation(wxWindow *win); |
a23fd0e1 | 74 | |
42e69d6b VZ |
75 | static HWND invalidHandle = 0; |
76 | ||
a23fd0e1 VZ |
77 | // --------------------------------------------------------------------------- |
78 | // constants | |
79 | // --------------------------------------------------------------------------- | |
80 | ||
81 | static const int IDM_WINDOWTILE = 4001; | |
42e69d6b | 82 | static const int IDM_WINDOWTILEHOR = 4001; |
a23fd0e1 VZ |
83 | static const int IDM_WINDOWCASCADE = 4002; |
84 | static const int IDM_WINDOWICONS = 4003; | |
85 | static const int IDM_WINDOWNEXT = 4004; | |
42e69d6b | 86 | static const int IDM_WINDOWTILEVERT = 4005; |
4f3b37fd | 87 | static const int IDM_WINDOWPREV = 4006; |
a23fd0e1 VZ |
88 | |
89 | // This range gives a maximum of 500 MDI children. Should be enough :-) | |
90 | static const int wxFIRST_MDI_CHILD = 4100; | |
91 | static const int wxLAST_MDI_CHILD = 4600; | |
2bda0e17 KB |
92 | |
93 | // Status border dimensions | |
a23fd0e1 VZ |
94 | static const int wxTHICK_LINE_BORDER = 3; |
95 | static const int wxTHICK_LINE_WIDTH = 1; | |
2bda0e17 | 96 | |
42e69d6b VZ |
97 | // --------------------------------------------------------------------------- |
98 | // private functions | |
99 | // --------------------------------------------------------------------------- | |
100 | ||
101 | // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu | |
102 | // of the parent of win (which is supposed to be the MDI client window) | |
103 | static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow); | |
104 | ||
105 | // insert the window menu (subMenu) into menu just before "Help" submenu or at | |
106 | // the very end if not found | |
107 | static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu); | |
108 | ||
df61c009 JS |
109 | // Remove the window menu |
110 | static void RemoveWindowMenu(wxWindow *win, WXHMENU menu); | |
111 | ||
42e69d6b VZ |
112 | // is this an id of an MDI child? |
113 | inline bool IsMdiCommandId(int id) | |
114 | { | |
115 | return (id >= wxFIRST_MDI_CHILD) && (id <= wxLAST_MDI_CHILD); | |
116 | } | |
117 | ||
4e152a23 | 118 | // unpack the parameters of WM_MDIACTIVATE message |
2917e920 BM |
119 | static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
120 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact); | |
42e69d6b | 121 | |
4e152a23 VZ |
122 | // return the HMENU of the MDI menu |
123 | static inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame) | |
124 | { | |
125 | wxMenu *menu = frame->GetWindowMenu(); | |
126 | return menu ? GetHmenuOf(menu) : 0; | |
127 | } | |
128 | ||
a23fd0e1 VZ |
129 | // =========================================================================== |
130 | // implementation | |
131 | // =========================================================================== | |
132 | ||
133 | // --------------------------------------------------------------------------- | |
134 | // wxWin macros | |
135 | // --------------------------------------------------------------------------- | |
2bda0e17 | 136 | |
225fe9d6 VZ |
137 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) |
138 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
139 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
2bda0e17 KB |
140 | |
141 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
a23fd0e1 | 142 | EVT_SIZE(wxMDIParentFrame::OnSize) |
a23fd0e1 | 143 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) |
2bda0e17 KB |
144 | END_EVENT_TABLE() |
145 | ||
f6bcfd97 BP |
146 | BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) |
147 | EVT_IDLE(wxMDIChildFrame::OnIdle) | |
148 | END_EVENT_TABLE() | |
149 | ||
2bda0e17 | 150 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) |
a23fd0e1 | 151 | EVT_SCROLL(wxMDIClientWindow::OnScroll) |
2bda0e17 KB |
152 | END_EVENT_TABLE() |
153 | ||
42e69d6b VZ |
154 | // =========================================================================== |
155 | // wxMDIParentFrame: the frame which contains the client window which manages | |
156 | // the children | |
157 | // =========================================================================== | |
2bda0e17 | 158 | |
c2dcfdef | 159 | wxMDIParentFrame::wxMDIParentFrame() |
2bda0e17 KB |
160 | { |
161 | m_clientWindow = NULL; | |
162 | m_currentChild = NULL; | |
df61c009 | 163 | m_windowMenu = (wxMenu*) NULL; |
4f8090e0 | 164 | m_parentFrameActive = true; |
2bda0e17 KB |
165 | } |
166 | ||
167 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
a23fd0e1 VZ |
168 | wxWindowID id, |
169 | const wxString& title, | |
170 | const wxPoint& pos, | |
171 | const wxSize& size, | |
172 | long style, | |
173 | const wxString& name) | |
2bda0e17 | 174 | { |
2bda0e17 KB |
175 | m_clientWindow = NULL; |
176 | m_currentChild = NULL; | |
df61c009 | 177 | |
3d8dea7e VZ |
178 | // this style can be used to prevent a window from having the standard MDI |
179 | // "Window" menu | |
180 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
181 | { | |
182 | m_windowMenu = (wxMenu *)NULL; | |
183 | } | |
184 | else // normal case: we have the window menu, so construct it | |
df61c009 | 185 | { |
df61c009 JS |
186 | m_windowMenu = new wxMenu; |
187 | ||
b0a2157c VZ |
188 | m_windowMenu->Append(IDM_WINDOWCASCADE, _("&Cascade")); |
189 | m_windowMenu->Append(IDM_WINDOWTILEHOR, _("Tile &Horizontally")); | |
190 | m_windowMenu->Append(IDM_WINDOWTILEVERT, _("Tile &Vertically")); | |
df61c009 | 191 | m_windowMenu->AppendSeparator(); |
b0a2157c VZ |
192 | m_windowMenu->Append(IDM_WINDOWICONS, _("&Arrange Icons")); |
193 | m_windowMenu->Append(IDM_WINDOWNEXT, _("&Next")); | |
4f3b37fd | 194 | m_windowMenu->Append(IDM_WINDOWPREV, _("&Previous")); |
df61c009 JS |
195 | } |
196 | ||
4f8090e0 | 197 | m_parentFrameActive = true; |
2bda0e17 KB |
198 | |
199 | if (!parent) | |
200 | wxTopLevelWindows.Append(this); | |
201 | ||
202 | SetName(name); | |
203 | m_windowStyle = style; | |
204 | ||
b225f659 VZ |
205 | if ( parent ) |
206 | parent->AddChild(this); | |
2bda0e17 KB |
207 | |
208 | if ( id > -1 ) | |
209 | m_windowId = id; | |
210 | else | |
b225f659 | 211 | m_windowId = NewControlId(); |
2bda0e17 | 212 | |
912c192f VZ |
213 | WXDWORD exflags; |
214 | WXDWORD msflags = MSWGetCreateWindowFlags(&exflags); | |
2bda0e17 | 215 | |
b225f659 | 216 | if ( !wxWindow::MSWCreate(wxMDIFrameClassName, |
3ca6a5f0 | 217 | title, |
b225f659 VZ |
218 | pos, size, |
219 | msflags, | |
220 | exflags) ) | |
3ca6a5f0 | 221 | { |
4f8090e0 | 222 | return false; |
3ca6a5f0 | 223 | } |
2bda0e17 KB |
224 | |
225 | wxModelessWindows.Append(this); | |
226 | ||
f6bcfd97 | 227 | // unlike (almost?) all other windows, frames are created hidden |
4f8090e0 | 228 | m_isShown = false; |
f6bcfd97 | 229 | |
4f8090e0 | 230 | return true; |
2bda0e17 KB |
231 | } |
232 | ||
c2dcfdef | 233 | wxMDIParentFrame::~wxMDIParentFrame() |
2bda0e17 | 234 | { |
42e69d6b | 235 | DestroyChildren(); |
4e152a23 | 236 | |
f048e32f VZ |
237 | // already delete by DestroyChildren() |
238 | m_frameToolBar = NULL; | |
c0bcc480 | 239 | m_frameStatusBar = NULL; |
f048e32f | 240 | |
df61c009 JS |
241 | if (m_windowMenu) |
242 | { | |
243 | delete m_windowMenu; | |
244 | m_windowMenu = (wxMenu*) NULL; | |
245 | } | |
2bda0e17 | 246 | |
4e152a23 VZ |
247 | // the MDI frame menubar is not automatically deleted by Windows unlike for |
248 | // the normal frames | |
249 | if ( m_hMenu ) | |
250 | { | |
251 | ::DestroyMenu((HMENU)m_hMenu); | |
7c46a16b | 252 | m_hMenu = (WXHMENU)NULL; |
4e152a23 VZ |
253 | } |
254 | ||
42e69d6b VZ |
255 | if ( m_clientWindow ) |
256 | { | |
257 | if ( m_clientWindow->MSWGetOldWndProc() ) | |
258 | m_clientWindow->UnsubclassWin(); | |
2bda0e17 | 259 | |
42e69d6b VZ |
260 | m_clientWindow->SetHWND(0); |
261 | delete m_clientWindow; | |
262 | } | |
2bda0e17 KB |
263 | } |
264 | ||
1e6feb95 VZ |
265 | #if wxUSE_MENUS_NATIVE |
266 | ||
42e69d6b | 267 | void wxMDIParentFrame::InternalSetMenuBar() |
2bda0e17 | 268 | { |
4f8090e0 | 269 | m_parentFrameActive = true; |
2bda0e17 | 270 | |
4e152a23 | 271 | InsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this)); |
2bda0e17 KB |
272 | } |
273 | ||
1e6feb95 VZ |
274 | #endif // wxUSE_MENUS_NATIVE |
275 | ||
df61c009 JS |
276 | void wxMDIParentFrame::SetWindowMenu(wxMenu* menu) |
277 | { | |
278 | if (m_windowMenu) | |
279 | { | |
280 | if (GetMenuBar()) | |
281 | { | |
282 | // Remove old window menu | |
283 | RemoveWindowMenu(GetClientWindow(), m_hMenu); | |
284 | } | |
285 | ||
286 | delete m_windowMenu; | |
287 | m_windowMenu = (wxMenu*) NULL; | |
288 | } | |
4e152a23 | 289 | |
df61c009 JS |
290 | if (menu) |
291 | { | |
292 | m_windowMenu = menu; | |
293 | if (GetMenuBar()) | |
b0a2157c VZ |
294 | { |
295 | InsertWindowMenu(GetClientWindow(), m_hMenu, | |
88c49a0f | 296 | GetHmenuOf(m_windowMenu)); |
b0a2157c | 297 | } |
df61c009 JS |
298 | } |
299 | } | |
300 | ||
a967ef9d | 301 | void wxMDIParentFrame::OnSize(wxSizeEvent&) |
2bda0e17 | 302 | { |
2bda0e17 | 303 | if ( GetClientWindow() ) |
42e69d6b VZ |
304 | { |
305 | int width, height; | |
306 | GetClientSize(&width, &height); | |
2bda0e17 | 307 | |
42e69d6b VZ |
308 | GetClientWindow()->SetSize(0, 0, width, height); |
309 | } | |
2bda0e17 KB |
310 | } |
311 | ||
2bda0e17 | 312 | // Returns the active MDI child window |
c2dcfdef | 313 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const |
2bda0e17 | 314 | { |
a23fd0e1 VZ |
315 | HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), |
316 | WM_MDIGETACTIVE, 0, 0L); | |
317 | if ( hWnd == 0 ) | |
318 | return NULL; | |
319 | else | |
320 | return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd); | |
2bda0e17 KB |
321 | } |
322 | ||
a23fd0e1 VZ |
323 | // Create the client window class (don't Create the window, just return a new |
324 | // class) | |
c2dcfdef | 325 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() |
2bda0e17 | 326 | { |
a23fd0e1 | 327 | return new wxMDIClientWindow; |
2bda0e17 KB |
328 | } |
329 | ||
330 | // Responds to colour changes, and passes event on to children. | |
331 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
332 | { | |
333 | if ( m_clientWindow ) | |
334 | { | |
a756f210 | 335 | m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
336 | m_clientWindow->Refresh(); |
337 | } | |
2bda0e17 | 338 | |
42e69d6b | 339 | event.Skip(); |
2bda0e17 KB |
340 | } |
341 | ||
82c9f85c VZ |
342 | WXHICON wxMDIParentFrame::GetDefaultIcon() const |
343 | { | |
344 | return (WXHICON)(wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON | |
345 | : wxDEFAULT_MDIPARENTFRAME_ICON); | |
346 | } | |
347 | ||
42e69d6b | 348 | // --------------------------------------------------------------------------- |
2bda0e17 | 349 | // MDI operations |
42e69d6b VZ |
350 | // --------------------------------------------------------------------------- |
351 | ||
c2dcfdef | 352 | void wxMDIParentFrame::Cascade() |
2bda0e17 | 353 | { |
a23fd0e1 | 354 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0); |
2bda0e17 KB |
355 | } |
356 | ||
42e69d6b | 357 | // TODO: add a direction argument (hor/vert) |
c2dcfdef | 358 | void wxMDIParentFrame::Tile() |
2bda0e17 | 359 | { |
a23fd0e1 | 360 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0); |
2bda0e17 KB |
361 | } |
362 | ||
c2dcfdef | 363 | void wxMDIParentFrame::ArrangeIcons() |
2bda0e17 | 364 | { |
a23fd0e1 | 365 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0); |
2bda0e17 KB |
366 | } |
367 | ||
c2dcfdef | 368 | void wxMDIParentFrame::ActivateNext() |
2bda0e17 | 369 | { |
a23fd0e1 | 370 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0); |
2bda0e17 KB |
371 | } |
372 | ||
c2dcfdef | 373 | void wxMDIParentFrame::ActivatePrevious() |
2bda0e17 | 374 | { |
a23fd0e1 | 375 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1); |
2bda0e17 KB |
376 | } |
377 | ||
42e69d6b | 378 | // --------------------------------------------------------------------------- |
a23fd0e1 | 379 | // the MDI parent frame window proc |
42e69d6b VZ |
380 | // --------------------------------------------------------------------------- |
381 | ||
a23fd0e1 VZ |
382 | long wxMDIParentFrame::MSWWindowProc(WXUINT message, |
383 | WXWPARAM wParam, | |
384 | WXLPARAM lParam) | |
2bda0e17 | 385 | { |
a23fd0e1 | 386 | long rc = 0; |
4f8090e0 | 387 | bool processed = false; |
2bda0e17 | 388 | |
a23fd0e1 VZ |
389 | switch ( message ) |
390 | { | |
42e69d6b VZ |
391 | case WM_ACTIVATE: |
392 | { | |
393 | WXWORD state, minimized; | |
394 | WXHWND hwnd; | |
395 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
396 | ||
397 | processed = HandleActivate(state, minimized != 0, hwnd); | |
398 | } | |
399 | break; | |
400 | ||
401 | case WM_COMMAND: | |
402 | { | |
403 | WXWORD id, cmd; | |
404 | WXHWND hwnd; | |
405 | UnpackCommand(wParam, lParam, &id, &hwnd, &cmd); | |
406 | ||
407 | (void)HandleCommand(id, cmd, hwnd); | |
408 | ||
409 | // even if the frame didn't process it, there is no need to try it | |
410 | // once again (i.e. call wxFrame::HandleCommand()) - we just dud it, | |
411 | // so pretend we processed the message anyhow | |
4f8090e0 | 412 | processed = true; |
42e69d6b | 413 | } |
b3818fbe VZ |
414 | |
415 | // always pass this message DefFrameProc(), otherwise MDI menu | |
416 | // commands (and sys commands - more surprizingly!) won't work | |
417 | MSWDefWindowProc(message, wParam, lParam); | |
42e69d6b VZ |
418 | break; |
419 | ||
a23fd0e1 VZ |
420 | case WM_CREATE: |
421 | m_clientWindow = OnCreateClient(); | |
422 | // Uses own style for client style | |
423 | if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) ) | |
424 | { | |
425 | wxLogMessage(_("Failed to create MDI parent frame.")); | |
2bda0e17 | 426 | |
a23fd0e1 VZ |
427 | rc = -1; |
428 | } | |
2bda0e17 | 429 | |
4f8090e0 | 430 | processed = true; |
a23fd0e1 | 431 | break; |
2bda0e17 | 432 | |
a23fd0e1 | 433 | case WM_ERASEBKGND: |
4f8090e0 | 434 | processed = true; |
2bda0e17 | 435 | |
a23fd0e1 | 436 | // we erase background ourselves |
4f8090e0 | 437 | rc = true; |
a23fd0e1 VZ |
438 | break; |
439 | ||
440 | case WM_MENUSELECT: | |
441 | { | |
42e69d6b VZ |
442 | WXWORD item, flags; |
443 | WXHMENU hmenu; | |
444 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
445 | ||
a23fd0e1 VZ |
446 | if ( m_parentFrameActive ) |
447 | { | |
42e69d6b | 448 | processed = HandleMenuSelect(item, flags, hmenu); |
a23fd0e1 VZ |
449 | } |
450 | else if (m_currentChild) | |
451 | { | |
452 | processed = m_currentChild-> | |
42e69d6b | 453 | HandleMenuSelect(item, flags, hmenu); |
a23fd0e1 VZ |
454 | } |
455 | } | |
456 | break; | |
b3818fbe VZ |
457 | |
458 | case WM_SIZE: | |
0655ad29 VZ |
459 | // as we don't (usually) resize the MDI client to exactly fit the |
460 | // client area (we put it below the toolbar, above statusbar &c), | |
461 | // we should not pass this one to DefFrameProc | |
b3818fbe | 462 | break; |
a23fd0e1 | 463 | } |
2bda0e17 | 464 | |
a23fd0e1 VZ |
465 | if ( !processed ) |
466 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
2bda0e17 | 467 | |
a23fd0e1 | 468 | return rc; |
2bda0e17 KB |
469 | } |
470 | ||
42e69d6b | 471 | bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate) |
2bda0e17 | 472 | { |
4f8090e0 | 473 | bool processed = false; |
a23fd0e1 | 474 | |
42e69d6b | 475 | if ( wxWindow::HandleActivate(state, minimized, activate) ) |
a23fd0e1 VZ |
476 | { |
477 | // already processed | |
4f8090e0 | 478 | processed = true; |
a23fd0e1 | 479 | } |
2bda0e17 KB |
480 | |
481 | // If this window is an MDI parent, we must also send an OnActivate message | |
482 | // to the current child. | |
42e69d6b | 483 | if ( (m_currentChild != NULL) && |
a23fd0e1 | 484 | ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) ) |
c2dcfdef | 485 | { |
4f8090e0 | 486 | wxActivateEvent event(wxEVT_ACTIVATE, true, m_currentChild->GetId()); |
debe6624 | 487 | event.SetEventObject( m_currentChild ); |
a23fd0e1 | 488 | if ( m_currentChild->GetEventHandler()->ProcessEvent(event) ) |
4f8090e0 | 489 | processed = true; |
2bda0e17 | 490 | } |
a23fd0e1 VZ |
491 | |
492 | return processed; | |
2bda0e17 KB |
493 | } |
494 | ||
42e69d6b | 495 | bool wxMDIParentFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd) |
2bda0e17 | 496 | { |
2bda0e17 | 497 | // In case it's e.g. a toolbar. |
42e69d6b | 498 | if ( hwnd ) |
e1a6fc11 | 499 | { |
42e69d6b VZ |
500 | wxWindow *win = wxFindWinFromHandle(hwnd); |
501 | if ( win ) | |
502 | return win->MSWCommand(cmd, id); | |
e1a6fc11 JS |
503 | } |
504 | ||
42e69d6b VZ |
505 | // is it one of standard MDI commands? |
506 | WXWPARAM wParam = 0; | |
4f3b37fd | 507 | WXLPARAM lParam = 0; |
42e69d6b VZ |
508 | int msg; |
509 | switch ( id ) | |
2bda0e17 | 510 | { |
42e69d6b VZ |
511 | case IDM_WINDOWCASCADE: |
512 | msg = WM_MDICASCADE; | |
513 | wParam = MDITILE_SKIPDISABLED; | |
514 | break; | |
515 | ||
516 | case IDM_WINDOWTILEHOR: | |
517 | wParam |= MDITILE_HORIZONTAL; | |
518 | // fall through | |
519 | ||
520 | case IDM_WINDOWTILEVERT: | |
521 | if ( !wParam ) | |
522 | wParam = MDITILE_VERTICAL; | |
523 | msg = WM_MDITILE; | |
524 | wParam |= MDITILE_SKIPDISABLED; | |
525 | break; | |
526 | ||
527 | case IDM_WINDOWICONS: | |
528 | msg = WM_MDIICONARRANGE; | |
529 | break; | |
530 | ||
531 | case IDM_WINDOWNEXT: | |
532 | msg = WM_MDINEXT; | |
4f3b37fd JS |
533 | lParam = 0; // next child |
534 | break; | |
535 | ||
536 | case IDM_WINDOWPREV: | |
537 | msg = WM_MDINEXT; | |
538 | lParam = 1; // previous child | |
42e69d6b VZ |
539 | break; |
540 | ||
541 | default: | |
542 | msg = 0; | |
2bda0e17 | 543 | } |
c2dcfdef | 544 | |
42e69d6b | 545 | if ( msg ) |
2bda0e17 | 546 | { |
4f3b37fd | 547 | ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, lParam); |
42e69d6b | 548 | |
4f8090e0 | 549 | return true; |
2bda0e17 | 550 | } |
42e69d6b VZ |
551 | |
552 | // FIXME VZ: what does this test do?? | |
553 | if (id >= 0xF000) | |
2bda0e17 | 554 | { |
4f8090e0 | 555 | return false; // Get WndProc to call default proc |
2bda0e17 | 556 | } |
42e69d6b VZ |
557 | |
558 | if ( IsMdiCommandId(id) ) | |
2bda0e17 | 559 | { |
d162a7ee | 560 | wxWindowList::Node *node = GetChildren().GetFirst(); |
42e69d6b | 561 | while ( node ) |
2bda0e17 | 562 | { |
d162a7ee | 563 | wxWindow *child = node->GetData(); |
42e69d6b | 564 | if ( child->GetHWND() ) |
2bda0e17 | 565 | { |
42e69d6b | 566 | long childId = wxGetWindowId(child->GetHWND()); |
48c12cb1 | 567 | if (childId == (long)id) |
42e69d6b VZ |
568 | { |
569 | ::SendMessage( GetWinHwnd(GetClientWindow()), | |
570 | WM_MDIACTIVATE, | |
571 | (WPARAM)child->GetHWND(), 0); | |
4f8090e0 | 572 | return true; |
42e69d6b | 573 | } |
2bda0e17 | 574 | } |
42e69d6b | 575 | node = node->GetNext(); |
2bda0e17 | 576 | } |
2bda0e17 | 577 | } |
42e69d6b | 578 | else if ( m_parentFrameActive ) |
2bda0e17 | 579 | { |
42e69d6b VZ |
580 | return ProcessCommand(id); |
581 | } | |
582 | else if ( m_currentChild ) | |
583 | { | |
584 | return m_currentChild->HandleCommand(id, cmd, hwnd); | |
585 | } | |
586 | else | |
587 | { | |
588 | // this shouldn't happen because it means that our messages are being | |
589 | // lost (they're not sent to the parent frame nor to the children) | |
f6bcfd97 | 590 | wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?")); |
2bda0e17 | 591 | } |
2bda0e17 | 592 | |
4f8090e0 | 593 | return false; |
2bda0e17 KB |
594 | } |
595 | ||
42e69d6b VZ |
596 | long wxMDIParentFrame::MSWDefWindowProc(WXUINT message, |
597 | WXWPARAM wParam, | |
598 | WXLPARAM lParam) | |
2bda0e17 | 599 | { |
c2dcfdef VZ |
600 | WXHWND clientWnd; |
601 | if ( GetClientWindow() ) | |
602 | clientWnd = GetClientWindow()->GetHWND(); | |
603 | else | |
604 | clientWnd = 0; | |
2bda0e17 | 605 | |
a23fd0e1 | 606 | return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam); |
2bda0e17 KB |
607 | } |
608 | ||
57a7b7c1 JS |
609 | bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) |
610 | { | |
a23fd0e1 | 611 | MSG *pMsg = (MSG *)msg; |
2bda0e17 | 612 | |
f6bcfd97 | 613 | // first let the current child get it |
a23fd0e1 VZ |
614 | if ( m_currentChild && m_currentChild->GetHWND() && |
615 | m_currentChild->MSWTranslateMessage(msg) ) | |
616 | { | |
4f8090e0 | 617 | return true; |
a23fd0e1 | 618 | } |
2bda0e17 | 619 | |
f6bcfd97 BP |
620 | // then try out accel table (will also check the menu accels) |
621 | if ( wxFrame::MSWTranslateMessage(msg) ) | |
a23fd0e1 | 622 | { |
4f8090e0 | 623 | return true; |
a23fd0e1 | 624 | } |
2bda0e17 | 625 | |
f6bcfd97 | 626 | // finally, check for MDI specific built in accel keys |
a23fd0e1 VZ |
627 | if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN ) |
628 | { | |
629 | if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg)) | |
4f8090e0 | 630 | return true; |
a23fd0e1 | 631 | } |
57a7b7c1 | 632 | |
4f8090e0 | 633 | return false; |
2bda0e17 KB |
634 | } |
635 | ||
42e69d6b | 636 | // =========================================================================== |
a23fd0e1 | 637 | // wxMDIChildFrame |
42e69d6b | 638 | // =========================================================================== |
2bda0e17 | 639 | |
f6bcfd97 | 640 | void wxMDIChildFrame::Init() |
2bda0e17 | 641 | { |
4f8090e0 | 642 | m_needsResize = true; |
2bda0e17 KB |
643 | } |
644 | ||
645 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
a23fd0e1 VZ |
646 | wxWindowID id, |
647 | const wxString& title, | |
648 | const wxPoint& pos, | |
649 | const wxSize& size, | |
650 | long style, | |
651 | const wxString& name) | |
2bda0e17 | 652 | { |
2bda0e17 | 653 | SetName(name); |
4f8090e0 | 654 | wxWindowBase::Show(true); // MDI child frame starts off shown |
2bda0e17 KB |
655 | |
656 | if ( id > -1 ) | |
657 | m_windowId = id; | |
658 | else | |
659 | m_windowId = (int)NewControlId(); | |
660 | ||
42e69d6b VZ |
661 | if ( parent ) |
662 | { | |
663 | parent->AddChild(this); | |
664 | } | |
2bda0e17 | 665 | |
2bda0e17 KB |
666 | int x = pos.x; |
667 | int y = pos.y; | |
668 | int width = size.x; | |
669 | int height = size.y; | |
670 | ||
671 | MDICREATESTRUCT mcs; | |
c2dcfdef | 672 | |
3ca6a5f0 BP |
673 | mcs.szClass = style & wxNO_FULL_REPAINT_ON_RESIZE |
674 | ? wxMDIChildFrameClassNameNoRedraw | |
675 | : wxMDIChildFrameClassName; | |
2bda0e17 KB |
676 | mcs.szTitle = title; |
677 | mcs.hOwner = wxGetInstance(); | |
42e69d6b VZ |
678 | if (x > -1) |
679 | mcs.x = x; | |
680 | else | |
681 | mcs.x = CW_USEDEFAULT; | |
2bda0e17 | 682 | |
42e69d6b VZ |
683 | if (y > -1) |
684 | mcs.y = y; | |
685 | else | |
686 | mcs.y = CW_USEDEFAULT; | |
2bda0e17 | 687 | |
42e69d6b VZ |
688 | if (width > -1) |
689 | mcs.cx = width; | |
690 | else | |
691 | mcs.cx = CW_USEDEFAULT; | |
2bda0e17 | 692 | |
42e69d6b VZ |
693 | if (height > -1) |
694 | mcs.cy = height; | |
695 | else | |
696 | mcs.cy = CW_USEDEFAULT; | |
2bda0e17 | 697 | |
5c44cd05 | 698 | DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_THICKFRAME | WS_VISIBLE ; |
2bda0e17 KB |
699 | if (style & wxMINIMIZE_BOX) |
700 | msflags |= WS_MINIMIZEBOX; | |
701 | if (style & wxMAXIMIZE_BOX) | |
702 | msflags |= WS_MAXIMIZEBOX; | |
703 | if (style & wxTHICK_FRAME) | |
704 | msflags |= WS_THICKFRAME; | |
705 | if (style & wxSYSTEM_MENU) | |
706 | msflags |= WS_SYSMENU; | |
707 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
708 | msflags |= WS_MINIMIZE; | |
709 | if (style & wxMAXIMIZE) | |
710 | msflags |= WS_MAXIMIZE; | |
711 | if (style & wxCAPTION) | |
712 | msflags |= WS_CAPTION; | |
713 | ||
714 | mcs.style = msflags; | |
715 | ||
716 | mcs.lParam = 0; | |
717 | ||
b225f659 VZ |
718 | wxWindowCreationHook hook(this); |
719 | ||
3ca6a5f0 BP |
720 | m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()), |
721 | WM_MDICREATE, 0, (LONG)(LPSTR)&mcs); | |
2bda0e17 | 722 | |
c7527e3f | 723 | wxAssociateWinWithHandle((HWND) GetHWND(), this); |
2bda0e17 | 724 | |
2bda0e17 | 725 | wxModelessWindows.Append(this); |
921a43c1 | 726 | |
4f8090e0 | 727 | return true; |
2bda0e17 KB |
728 | } |
729 | ||
c2dcfdef | 730 | wxMDIChildFrame::~wxMDIChildFrame() |
2bda0e17 | 731 | { |
627a3091 JS |
732 | DestroyChildren(); |
733 | ||
4e152a23 | 734 | // already deleted by DestroyChildren() |
627a3091 JS |
735 | m_frameToolBar = NULL; |
736 | m_frameStatusBar = NULL; | |
737 | ||
4e152a23 VZ |
738 | RemoveWindowMenu(NULL, m_hMenu); |
739 | ||
c2dcfdef | 740 | MSWDestroyWindow(); |
2bda0e17 KB |
741 | } |
742 | ||
743 | // Set the client size (i.e. leave the calculation of borders etc. | |
744 | // to wxWindows) | |
cc2b7472 | 745 | void wxMDIChildFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 746 | { |
b3818fbe | 747 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
748 | |
749 | RECT rect; | |
2de8030d | 750 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
751 | |
752 | RECT rect2; | |
753 | GetWindowRect(hWnd, &rect2); | |
754 | ||
755 | // Find the difference between the entire window (title bar and all) | |
756 | // and the client area; add this to the new client size to move the | |
757 | // window | |
758 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
759 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
760 | ||
a2327a9f | 761 | if (GetStatusBar() && GetStatusBar()->IsShown()) |
2bda0e17 | 762 | { |
c2dcfdef VZ |
763 | int sx, sy; |
764 | GetStatusBar()->GetSize(&sx, &sy); | |
2bda0e17 KB |
765 | actual_height += sy; |
766 | } | |
767 | ||
768 | POINT point; | |
769 | point.x = rect2.left; | |
770 | point.y = rect2.top; | |
771 | ||
772 | // If there's an MDI parent, must subtract the parent's top left corner | |
773 | // since MoveWindow moves relative to the parent | |
774 | wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent(); | |
775 | ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point); | |
776 | ||
4f8090e0 | 777 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)true); |
debe6624 | 778 | |
2bda0e17 | 779 | wxSizeEvent event(wxSize(width, height), m_windowId); |
debe6624 | 780 | event.SetEventObject( this ); |
2bda0e17 | 781 | GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
782 | } |
783 | ||
cc2b7472 | 784 | void wxMDIChildFrame::DoGetPosition(int *x, int *y) const |
2bda0e17 KB |
785 | { |
786 | RECT rect; | |
b3818fbe | 787 | GetWindowRect(GetHwnd(), &rect); |
2bda0e17 KB |
788 | POINT point; |
789 | point.x = rect.left; | |
790 | point.y = rect.top; | |
791 | ||
792 | // Since we now have the absolute screen coords, | |
793 | // if there's a parent we must subtract its top left corner | |
794 | wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent(); | |
795 | ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point); | |
796 | ||
797 | *x = point.x; | |
798 | *y = point.y; | |
799 | } | |
800 | ||
42e69d6b | 801 | void wxMDIChildFrame::InternalSetMenuBar() |
2bda0e17 | 802 | { |
42e69d6b | 803 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 804 | |
4e152a23 VZ |
805 | InsertWindowMenu(parent->GetClientWindow(), |
806 | m_hMenu, GetMDIWindowMenu(parent)); | |
2bda0e17 | 807 | |
4f8090e0 | 808 | parent->m_parentFrameActive = false; |
2bda0e17 KB |
809 | } |
810 | ||
82c9f85c VZ |
811 | WXHICON wxMDIChildFrame::GetDefaultIcon() const |
812 | { | |
813 | return (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON | |
814 | : wxDEFAULT_MDICHILDFRAME_ICON); | |
815 | } | |
816 | ||
42e69d6b | 817 | // --------------------------------------------------------------------------- |
2bda0e17 | 818 | // MDI operations |
42e69d6b VZ |
819 | // --------------------------------------------------------------------------- |
820 | ||
9b73db3c | 821 | void wxMDIChildFrame::Maximize(bool maximize) |
2bda0e17 KB |
822 | { |
823 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
824 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
825 | { |
826 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), | |
827 | maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE, | |
828 | (WPARAM)GetHwnd(), 0); | |
829 | } | |
2bda0e17 KB |
830 | } |
831 | ||
c2dcfdef | 832 | void wxMDIChildFrame::Restore() |
2bda0e17 KB |
833 | { |
834 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
835 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
836 | { |
837 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE, | |
838 | (WPARAM) GetHwnd(), 0); | |
839 | } | |
2bda0e17 KB |
840 | } |
841 | ||
c2dcfdef | 842 | void wxMDIChildFrame::Activate() |
2bda0e17 KB |
843 | { |
844 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
845 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
846 | { |
847 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE, | |
848 | (WPARAM) GetHwnd(), 0); | |
849 | } | |
2bda0e17 KB |
850 | } |
851 | ||
42e69d6b VZ |
852 | // --------------------------------------------------------------------------- |
853 | // MDI window proc and message handlers | |
854 | // --------------------------------------------------------------------------- | |
855 | ||
856 | long wxMDIChildFrame::MSWWindowProc(WXUINT message, | |
857 | WXWPARAM wParam, | |
858 | WXLPARAM lParam) | |
859 | { | |
860 | long rc = 0; | |
4f8090e0 | 861 | bool processed = false; |
42e69d6b VZ |
862 | |
863 | switch ( message ) | |
864 | { | |
865 | case WM_COMMAND: | |
866 | { | |
867 | WORD id, cmd; | |
868 | WXHWND hwnd; | |
869 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
870 | &id, &hwnd, &cmd); | |
871 | ||
872 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
873 | } | |
874 | break; | |
875 | ||
42e69d6b | 876 | case WM_GETMINMAXINFO: |
3ebcfb76 VZ |
877 | processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam); |
878 | break; | |
42e69d6b VZ |
879 | |
880 | case WM_MDIACTIVATE: | |
881 | { | |
882 | WXWORD act; | |
883 | WXHWND hwndAct, hwndDeact; | |
884 | UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact); | |
885 | ||
886 | processed = HandleMDIActivate(act, hwndAct, hwndDeact); | |
887 | } | |
b3818fbe VZ |
888 | // fall through |
889 | ||
890 | case WM_MOVE: | |
891 | // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client | |
892 | // scrollbars if necessary | |
893 | ||
894 | // fall through | |
895 | ||
896 | case WM_SIZE: | |
897 | // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird | |
898 | // things happen | |
899 | MSWDefWindowProc(message, wParam, lParam); | |
42e69d6b VZ |
900 | break; |
901 | ||
b3818fbe VZ |
902 | case WM_SYSCOMMAND: |
903 | // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it | |
904 | // the message (the base class version does not) | |
905 | return MSWDefWindowProc(message, wParam, lParam); | |
906 | ||
42e69d6b VZ |
907 | case WM_WINDOWPOSCHANGING: |
908 | processed = HandleWindowPosChanging((LPWINDOWPOS)lParam); | |
909 | break; | |
910 | } | |
911 | ||
912 | if ( !processed ) | |
913 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
914 | ||
915 | return rc; | |
916 | } | |
917 | ||
42e69d6b | 918 | bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd) |
2bda0e17 | 919 | { |
2bda0e17 | 920 | // In case it's e.g. a toolbar. |
42e69d6b VZ |
921 | if ( hwnd ) |
922 | { | |
923 | wxWindow *win = wxFindWinFromHandle(hwnd); | |
924 | if (win) | |
925 | return win->MSWCommand(cmd, id); | |
926 | } | |
2bda0e17 | 927 | |
e1a6fc11 JS |
928 | if (wxCurrentPopupMenu) |
929 | { | |
930 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
931 | wxCurrentPopupMenu = NULL; | |
932 | if (popupMenu->MSWCommand(cmd, id)) | |
4f8090e0 | 933 | return true; |
e1a6fc11 JS |
934 | } |
935 | ||
3ca6a5f0 | 936 | bool processed; |
dd60b9ec | 937 | if (GetMenuBar() && GetMenuBar()->FindItem(id)) |
2bda0e17 | 938 | { |
3ca6a5f0 | 939 | processed = ProcessCommand(id); |
2bda0e17 KB |
940 | } |
941 | else | |
3ca6a5f0 | 942 | { |
4f8090e0 | 943 | processed = false; |
3ca6a5f0 | 944 | } |
42e69d6b | 945 | |
3ca6a5f0 | 946 | return processed; |
2bda0e17 KB |
947 | } |
948 | ||
42e69d6b VZ |
949 | bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), |
950 | WXHWND hwndAct, | |
951 | WXHWND hwndDeact) | |
2bda0e17 | 952 | { |
42e69d6b | 953 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 954 | |
42e69d6b | 955 | HMENU menuToSet = 0; |
57a7b7c1 | 956 | |
42e69d6b | 957 | bool activated; |
57a7b7c1 | 958 | |
42e69d6b VZ |
959 | if ( m_hWnd == hwndAct ) |
960 | { | |
4f8090e0 | 961 | activated = true; |
42e69d6b | 962 | parent->m_currentChild = this; |
2bda0e17 | 963 | |
42e69d6b VZ |
964 | HMENU child_menu = (HMENU)GetWinMenu(); |
965 | if ( child_menu ) | |
966 | { | |
4f8090e0 | 967 | parent->m_parentFrameActive = false; |
2bda0e17 | 968 | |
42e69d6b VZ |
969 | menuToSet = child_menu; |
970 | } | |
971 | } | |
972 | else if ( m_hWnd == hwndDeact ) | |
2bda0e17 | 973 | { |
42e69d6b | 974 | wxASSERT_MSG( parent->m_currentChild == this, |
223d09f6 | 975 | wxT("can't deactivate MDI child which wasn't active!") ); |
42e69d6b | 976 | |
4f8090e0 | 977 | activated = false; |
42e69d6b | 978 | parent->m_currentChild = NULL; |
2bda0e17 | 979 | |
42e69d6b | 980 | HMENU parent_menu = (HMENU)parent->GetWinMenu(); |
f4075804 VZ |
981 | |
982 | // activate the the parent menu only when there is no other child | |
983 | // that has been activated | |
984 | if ( parent_menu && !hwndAct ) | |
42e69d6b | 985 | { |
4f8090e0 | 986 | parent->m_parentFrameActive = true; |
42e69d6b VZ |
987 | |
988 | menuToSet = parent_menu; | |
989 | } | |
990 | } | |
991 | else | |
992 | { | |
18d2e170 | 993 | // we have nothing to do with it |
4f8090e0 | 994 | return false; |
2bda0e17 | 995 | } |
debe6624 | 996 | |
42e69d6b VZ |
997 | if ( menuToSet ) |
998 | { | |
4e152a23 VZ |
999 | MDISetMenu(parent->GetClientWindow(), |
1000 | menuToSet, GetMDIWindowMenu(parent)); | |
42e69d6b VZ |
1001 | } |
1002 | ||
1003 | wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId); | |
debe6624 | 1004 | event.SetEventObject( this ); |
2bda0e17 | 1005 | |
c03b48d7 GT |
1006 | ResetWindowStyle((void *)NULL); |
1007 | ||
42e69d6b VZ |
1008 | return GetEventHandler()->ProcessEvent(event); |
1009 | } | |
1010 | ||
1011 | bool wxMDIChildFrame::HandleWindowPosChanging(void *pos) | |
1012 | { | |
1013 | WINDOWPOS *lpPos = (WINDOWPOS *)pos; | |
1014 | #if defined(__WIN95__) | |
1015 | if (!(lpPos->flags & SWP_NOSIZE)) | |
2bda0e17 | 1016 | { |
42e69d6b | 1017 | RECT rectClient; |
b3818fbe VZ |
1018 | DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); |
1019 | DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
42e69d6b VZ |
1020 | if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE)) |
1021 | { | |
4f8090e0 | 1022 | ::AdjustWindowRectEx(&rectClient, dwStyle, false, dwExStyle); |
42e69d6b VZ |
1023 | lpPos->x = rectClient.left; |
1024 | lpPos->y = rectClient.top; | |
1025 | lpPos->cx = rectClient.right - rectClient.left; | |
1026 | lpPos->cy = rectClient.bottom - rectClient.top; | |
1027 | } | |
1028 | wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent(); | |
a2327a9f | 1029 | if (pFrameWnd && pFrameWnd->GetToolBar() && pFrameWnd->GetToolBar()->IsShown()) |
42e69d6b VZ |
1030 | { |
1031 | pFrameWnd->GetToolBar()->Refresh(); | |
1032 | } | |
1033 | } | |
1034 | #endif // Win95 | |
1035 | ||
4f8090e0 | 1036 | return false; |
42e69d6b VZ |
1037 | } |
1038 | ||
3ebcfb76 VZ |
1039 | bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo) |
1040 | { | |
1041 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; | |
1042 | ||
1043 | // let the default window proc calculate the size of MDI children | |
1044 | // frames because it is based on the size of the MDI client window, | |
1045 | // not on the values specified in wxWindow m_max variables | |
d9f9aa2d | 1046 | bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0; |
3ebcfb76 | 1047 | |
e7dda1ff VS |
1048 | int minWidth = GetMinWidth(), |
1049 | minHeight = GetMinHeight(); | |
1050 | ||
3ebcfb76 | 1051 | // but allow GetSizeHints() to set the min size |
e7dda1ff | 1052 | if ( minWidth != -1 ) |
3ebcfb76 | 1053 | { |
e7dda1ff | 1054 | info->ptMinTrackSize.x = minWidth; |
3ebcfb76 | 1055 | |
4f8090e0 | 1056 | processed = true; |
3ebcfb76 VZ |
1057 | } |
1058 | ||
e7dda1ff | 1059 | if ( minHeight != -1 ) |
3ebcfb76 | 1060 | { |
e7dda1ff | 1061 | info->ptMinTrackSize.y = minHeight; |
3ebcfb76 | 1062 | |
4f8090e0 | 1063 | processed = true; |
3ebcfb76 VZ |
1064 | } |
1065 | ||
4f8090e0 | 1066 | return true; |
3ebcfb76 VZ |
1067 | } |
1068 | ||
42e69d6b VZ |
1069 | // --------------------------------------------------------------------------- |
1070 | // MDI specific message translation/preprocessing | |
1071 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1072 | |
42e69d6b VZ |
1073 | long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam) |
1074 | { | |
1075 | return DefMDIChildProc(GetHwnd(), | |
1076 | (UINT)message, (WPARAM)wParam, (LPARAM)lParam); | |
1077 | } | |
1078 | ||
1079 | bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) | |
1080 | { | |
5a2762f0 | 1081 | return wxFrame::MSWTranslateMessage(msg); |
2bda0e17 KB |
1082 | } |
1083 | ||
42e69d6b VZ |
1084 | // --------------------------------------------------------------------------- |
1085 | // misc | |
1086 | // --------------------------------------------------------------------------- | |
1087 | ||
c2dcfdef | 1088 | void wxMDIChildFrame::MSWDestroyWindow() |
2bda0e17 | 1089 | { |
b3818fbe | 1090 | invalidHandle = GetHwnd(); |
2bda0e17 | 1091 | |
42e69d6b | 1092 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 1093 | |
42e69d6b VZ |
1094 | // Must make sure this handle is invalidated (set to NULL) since all sorts |
1095 | // of things could happen after the child client is destroyed, but before | |
1096 | // the wxFrame is destroyed. | |
2bda0e17 | 1097 | |
42e69d6b | 1098 | HWND oldHandle = (HWND)GetHWND(); |
b3818fbe VZ |
1099 | SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY, |
1100 | (WPARAM)oldHandle, 0); | |
18d2e170 JS |
1101 | |
1102 | if (parent->GetActiveChild() == (wxMDIChildFrame*) NULL) | |
1103 | ResetWindowStyle((void*) NULL); | |
1104 | ||
42e69d6b | 1105 | invalidHandle = 0; |
2bda0e17 | 1106 | |
42e69d6b VZ |
1107 | if (m_hMenu) |
1108 | { | |
1109 | ::DestroyMenu((HMENU) m_hMenu); | |
1110 | m_hMenu = 0; | |
1111 | } | |
ac6482e0 | 1112 | wxRemoveHandleAssociation(this); |
42e69d6b | 1113 | m_hWnd = 0; |
2bda0e17 KB |
1114 | } |
1115 | ||
42e69d6b VZ |
1116 | // Change the client window's extended style so we don't get a client edge |
1117 | // style when a child is maximised (a double border looks silly.) | |
2bda0e17 KB |
1118 | bool wxMDIChildFrame::ResetWindowStyle(void *vrect) |
1119 | { | |
1120 | #if defined(__WIN95__) | |
1121 | RECT *rect = (RECT *)vrect; | |
c2dcfdef VZ |
1122 | wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent(); |
1123 | wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild(); | |
1124 | if (!pChild || (pChild == this)) | |
1125 | { | |
47ca6bfb | 1126 | HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow()); |
8082a771 VZ |
1127 | DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE); |
1128 | ||
1129 | // we want to test whether there is a maximized child, so just set | |
1130 | // dwThisStyle to 0 if there is no child at all | |
1131 | DWORD dwThisStyle = pChild | |
1f3943e0 | 1132 | ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0; |
c2dcfdef | 1133 | DWORD dwNewStyle = dwStyle; |
8082a771 | 1134 | if ( dwThisStyle & WS_MAXIMIZE ) |
c2dcfdef VZ |
1135 | dwNewStyle &= ~(WS_EX_CLIENTEDGE); |
1136 | else | |
1137 | dwNewStyle |= WS_EX_CLIENTEDGE; | |
1138 | ||
1139 | if (dwStyle != dwNewStyle) | |
1140 | { | |
47ca6bfb VZ |
1141 | // force update of everything |
1142 | ::RedrawWindow(hwndClient, NULL, NULL, | |
1143 | RDW_INVALIDATE | RDW_ALLCHILDREN); | |
1144 | ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle); | |
1145 | ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0, | |
42e69d6b VZ |
1146 | SWP_FRAMECHANGED | SWP_NOACTIVATE | |
1147 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | | |
1148 | SWP_NOCOPYBITS); | |
c2dcfdef | 1149 | if (rect) |
47ca6bfb | 1150 | ::GetClientRect(hwndClient, rect); |
2bda0e17 | 1151 | |
4f8090e0 | 1152 | return true; |
2bda0e17 | 1153 | } |
c2dcfdef | 1154 | } |
42e69d6b | 1155 | #endif // Win95 |
a23fd0e1 | 1156 | |
4f8090e0 | 1157 | return false; |
2bda0e17 KB |
1158 | } |
1159 | ||
42e69d6b VZ |
1160 | // =========================================================================== |
1161 | // wxMDIClientWindow: the window of predefined (by Windows) class which | |
1162 | // contains the child frames | |
1163 | // =========================================================================== | |
2bda0e17 | 1164 | |
debe6624 | 1165 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) |
2bda0e17 | 1166 | { |
a756f210 | 1167 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); |
2bda0e17 | 1168 | |
42e69d6b VZ |
1169 | CLIENTCREATESTRUCT ccs; |
1170 | m_windowStyle = style; | |
1171 | m_parent = parent; | |
c2dcfdef | 1172 | |
4e152a23 | 1173 | ccs.hWindowMenu = GetMDIWindowMenu(parent); |
42e69d6b | 1174 | ccs.idFirstChild = wxFIRST_MDI_CHILD; |
2bda0e17 | 1175 | |
5c44cd05 | 1176 | DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD | |
b0766406 JS |
1177 | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
1178 | ||
42e69d6b VZ |
1179 | if ( style & wxHSCROLL ) |
1180 | msStyle |= WS_HSCROLL; | |
1181 | if ( style & wxVSCROLL ) | |
1182 | msStyle |= WS_VSCROLL; | |
2bda0e17 KB |
1183 | |
1184 | #if defined(__WIN95__) | |
42e69d6b | 1185 | DWORD exStyle = WS_EX_CLIENTEDGE; |
2bda0e17 | 1186 | #else |
42e69d6b | 1187 | DWORD exStyle = 0; |
2bda0e17 KB |
1188 | #endif |
1189 | ||
b225f659 | 1190 | wxWindowCreationHook hook(this); |
42e69d6b VZ |
1191 | m_hWnd = (WXHWND)::CreateWindowEx |
1192 | ( | |
1193 | exStyle, | |
223d09f6 | 1194 | wxT("MDICLIENT"), |
42e69d6b VZ |
1195 | NULL, |
1196 | msStyle, | |
1197 | 0, 0, 0, 0, | |
1198 | GetWinHwnd(parent), | |
1199 | NULL, | |
1200 | wxGetInstance(), | |
1201 | (LPSTR)(LPCLIENTCREATESTRUCT)&ccs); | |
1202 | if ( !m_hWnd ) | |
1203 | { | |
f6bcfd97 | 1204 | wxLogLastError(wxT("CreateWindowEx(MDI client)")); |
2bda0e17 | 1205 | |
4f8090e0 | 1206 | return false; |
42e69d6b | 1207 | } |
2bda0e17 | 1208 | |
42e69d6b | 1209 | SubclassWin(m_hWnd); |
2bda0e17 | 1210 | |
4f8090e0 | 1211 | return true; |
2bda0e17 KB |
1212 | } |
1213 | ||
1214 | // Explicitly call default scroll behaviour | |
1215 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
1216 | { | |
1217 | // Note: for client windows, the scroll position is not set in | |
1218 | // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what | |
1219 | // scroll position we're at. | |
1220 | // This makes it hard to paint patterns or bitmaps in the background, | |
1221 | // and have the client area scrollable as well. | |
1222 | ||
1223 | if ( event.GetOrientation() == wxHORIZONTAL ) | |
1224 | m_scrollX = event.GetPosition(); // Always returns zero! | |
1225 | else | |
1226 | m_scrollY = event.GetPosition(); // Always returns zero! | |
1227 | ||
42e69d6b VZ |
1228 | event.Skip(); |
1229 | } | |
1230 | ||
ec06b234 JS |
1231 | void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
1232 | { | |
1233 | // Try to fix a problem whereby if you show an MDI child frame, then reposition the | |
1234 | // client area, you can end up with a non-refreshed portion in the client window | |
1235 | // (see OGL studio sample). So check if the position is changed and if so, | |
1236 | // redraw the MDI child frames. | |
1237 | ||
1238 | wxPoint oldPos = GetPosition(); | |
1239 | ||
1240 | wxWindow::DoSetSize(x, y, width, height, sizeFlags); | |
1241 | ||
1242 | wxPoint newPos = GetPosition(); | |
1243 | ||
1244 | if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y)) | |
1245 | { | |
1246 | if (GetParent()) | |
1247 | { | |
d162a7ee | 1248 | wxWindowList::Node *node = GetParent()->GetChildren().GetFirst(); |
ec06b234 JS |
1249 | while (node) |
1250 | { | |
d162a7ee | 1251 | wxWindow *child = node->GetData(); |
ec06b234 JS |
1252 | if (child->IsKindOf(CLASSINFO(wxMDIChildFrame))) |
1253 | { | |
d162a7ee VZ |
1254 | ::RedrawWindow(GetHwndOf(child), |
1255 | NULL, | |
1256 | NULL, | |
1257 | RDW_FRAME | | |
1258 | RDW_ALLCHILDREN | | |
1259 | RDW_INVALIDATE); | |
ec06b234 | 1260 | } |
4f8090e0 | 1261 | node = node->GetNext(); |
ec06b234 JS |
1262 | } |
1263 | } | |
1264 | } | |
1265 | } | |
1266 | ||
f6bcfd97 BP |
1267 | void wxMDIChildFrame::OnIdle(wxIdleEvent& event) |
1268 | { | |
1269 | // MDI child frames get their WM_SIZE when they're constructed but at this | |
1270 | // moment they don't have any children yet so all child windows will be | |
1271 | // positioned incorrectly when they are added later - to fix this, we | |
1272 | // generate an artificial size event here | |
1273 | if ( m_needsResize ) | |
1274 | { | |
4f8090e0 | 1275 | m_needsResize = false; // avoid any possibility of recursion |
f6bcfd97 BP |
1276 | |
1277 | SendSizeEvent(); | |
1278 | } | |
1279 | ||
1280 | event.Skip(); | |
1281 | } | |
1282 | ||
42e69d6b VZ |
1283 | // --------------------------------------------------------------------------- |
1284 | // non member functions | |
1285 | // --------------------------------------------------------------------------- | |
1286 | ||
1287 | static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow) | |
1288 | { | |
1289 | ::SendMessage(GetWinHwnd(win), WM_MDISETMENU, | |
1290 | #ifdef __WIN32__ | |
f6bcfd97 | 1291 | (WPARAM)hmenuFrame, (LPARAM)hmenuWindow |
42e69d6b | 1292 | #else |
f6bcfd97 | 1293 | 0, MAKELPARAM(hmenuFrame, hmenuWindow) |
42e69d6b | 1294 | #endif |
f6bcfd97 | 1295 | ); |
42e69d6b VZ |
1296 | |
1297 | // update menu bar of the parent window | |
1298 | wxWindow *parent = win->GetParent(); | |
223d09f6 | 1299 | wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") ); |
42e69d6b | 1300 | |
788722ac | 1301 | #ifndef __WIN16__ |
a967ef9d | 1302 | ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L); |
788722ac JS |
1303 | #endif |
1304 | ||
42e69d6b VZ |
1305 | ::DrawMenuBar(GetWinHwnd(parent)); |
1306 | } | |
1307 | ||
1308 | static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu) | |
1309 | { | |
1310 | // Try to insert Window menu in front of Help, otherwise append it. | |
1311 | HMENU hmenu = (HMENU)menu; | |
df61c009 JS |
1312 | |
1313 | if (subMenu) | |
1314 | { | |
4e152a23 | 1315 | int N = GetMenuItemCount(hmenu); |
4f8090e0 | 1316 | bool success = false; |
4e152a23 | 1317 | for ( int i = 0; i < N; i++ ) |
42e69d6b | 1318 | { |
4e152a23 VZ |
1319 | wxChar buf[256]; |
1320 | int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION); | |
1321 | if ( chars == 0 ) | |
1322 | { | |
1323 | wxLogLastError(wxT("GetMenuString")); | |
42e69d6b | 1324 | |
4e152a23 VZ |
1325 | continue; |
1326 | } | |
1327 | ||
1328 | if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) ) | |
1329 | { | |
4f8090e0 | 1330 | success = true; |
4e152a23 VZ |
1331 | ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING, |
1332 | (UINT)subMenu, _("&Window")); | |
1333 | break; | |
1334 | } | |
42e69d6b VZ |
1335 | } |
1336 | ||
4e152a23 | 1337 | if ( !success ) |
42e69d6b | 1338 | { |
4e152a23 | 1339 | ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window")); |
42e69d6b VZ |
1340 | } |
1341 | } | |
1342 | ||
42e69d6b VZ |
1343 | MDISetMenu(win, hmenu, subMenu); |
1344 | } | |
1345 | ||
df61c009 JS |
1346 | static void RemoveWindowMenu(wxWindow *win, WXHMENU menu) |
1347 | { | |
4e152a23 VZ |
1348 | HMENU hMenu = (HMENU)menu; |
1349 | ||
1350 | if ( hMenu ) | |
df61c009 | 1351 | { |
4e152a23 VZ |
1352 | wxChar buf[1024]; |
1353 | ||
1354 | int N = ::GetMenuItemCount(hMenu); | |
1355 | for ( int i = 0; i < N; i++ ) | |
df61c009 | 1356 | { |
4e152a23 VZ |
1357 | if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) ) |
1358 | { | |
2c62b3c3 VZ |
1359 | // Ignore successful read of menu string with length 0 which |
1360 | // occurs, for example, for a maximized MDI childs system menu | |
1361 | if ( ::GetLastError() != 0 ) | |
1362 | { | |
1363 | wxLogLastError(wxT("GetMenuString")); | |
1364 | } | |
df61c009 | 1365 | |
4e152a23 VZ |
1366 | continue; |
1367 | } | |
df61c009 | 1368 | |
4e152a23 VZ |
1369 | if ( wxStrcmp(buf, _("&Window")) == 0 ) |
1370 | { | |
1371 | if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) ) | |
1372 | { | |
1373 | wxLogLastError(wxT("RemoveMenu")); | |
1374 | } | |
1375 | ||
1376 | break; | |
1377 | } | |
df61c009 JS |
1378 | } |
1379 | } | |
1380 | ||
4e152a23 VZ |
1381 | if ( win ) |
1382 | { | |
1383 | // we don't change the windows menu, but we update the main one | |
1384 | MDISetMenu(win, hMenu, NULL); | |
1385 | } | |
df61c009 JS |
1386 | } |
1387 | ||
2917e920 BM |
1388 | static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
1389 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact) | |
42e69d6b VZ |
1390 | { |
1391 | #ifdef __WIN32__ | |
4f8090e0 | 1392 | *activate = true; |
42e69d6b VZ |
1393 | *hwndAct = (WXHWND)lParam; |
1394 | *hwndDeact = (WXHWND)wParam; | |
1395 | #else // Win16 | |
1396 | *activate = (WXWORD)wParam; | |
1397 | *hwndAct = (WXHWND)LOWORD(lParam); | |
1398 | *hwndDeact = (WXHWND)HIWORD(lParam); | |
1399 | #endif // Win32/Win16 | |
2bda0e17 | 1400 | } |
b9f933ab JS |
1401 | |
1402 | #endif | |
1403 | // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__) | |
1404 |