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