]>
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 | { |
3d8dea7e VZ |
166 | m_defaultIcon = (WXHICON) (wxSTD_MDIPARENTFRAME_ICON |
167 | ? wxSTD_MDIPARENTFRAME_ICON | |
168 | : wxDEFAULT_MDIPARENTFRAME_ICON); | |
2bda0e17 | 169 | |
2bda0e17 KB |
170 | m_clientWindow = NULL; |
171 | m_currentChild = NULL; | |
df61c009 | 172 | |
3d8dea7e VZ |
173 | // this style can be used to prevent a window from having the standard MDI |
174 | // "Window" menu | |
175 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
176 | { | |
177 | m_windowMenu = (wxMenu *)NULL; | |
178 | } | |
179 | else // normal case: we have the window menu, so construct it | |
df61c009 | 180 | { |
df61c009 JS |
181 | m_windowMenu = new wxMenu; |
182 | ||
b0a2157c VZ |
183 | m_windowMenu->Append(IDM_WINDOWCASCADE, _("&Cascade")); |
184 | m_windowMenu->Append(IDM_WINDOWTILEHOR, _("Tile &Horizontally")); | |
185 | m_windowMenu->Append(IDM_WINDOWTILEVERT, _("Tile &Vertically")); | |
df61c009 | 186 | m_windowMenu->AppendSeparator(); |
b0a2157c VZ |
187 | m_windowMenu->Append(IDM_WINDOWICONS, _("&Arrange Icons")); |
188 | m_windowMenu->Append(IDM_WINDOWNEXT, _("&Next")); | |
df61c009 JS |
189 | } |
190 | ||
2bda0e17 KB |
191 | m_parentFrameActive = TRUE; |
192 | ||
193 | if (!parent) | |
194 | wxTopLevelWindows.Append(this); | |
195 | ||
196 | SetName(name); | |
197 | m_windowStyle = style; | |
198 | ||
199 | if (parent) parent->AddChild(this); | |
200 | ||
201 | if ( id > -1 ) | |
202 | m_windowId = id; | |
203 | else | |
204 | m_windowId = (int)NewControlId(); | |
205 | ||
206 | int x = pos.x; | |
207 | int y = pos.y; | |
208 | int width = size.x; | |
209 | int height = size.y; | |
210 | ||
42e69d6b | 211 | DWORD msflags = WS_OVERLAPPED; |
2bda0e17 KB |
212 | if (style & wxMINIMIZE_BOX) |
213 | msflags |= WS_MINIMIZEBOX; | |
214 | if (style & wxMAXIMIZE_BOX) | |
215 | msflags |= WS_MAXIMIZEBOX; | |
216 | if (style & wxTHICK_FRAME) | |
217 | msflags |= WS_THICKFRAME; | |
218 | if (style & wxSYSTEM_MENU) | |
219 | msflags |= WS_SYSMENU; | |
220 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
221 | msflags |= WS_MINIMIZE; | |
222 | if (style & wxMAXIMIZE) | |
223 | msflags |= WS_MAXIMIZE; | |
224 | if (style & wxCAPTION) | |
225 | msflags |= WS_CAPTION; | |
46851318 | 226 | |
0655ad29 VZ |
227 | if (style & wxCLIP_CHILDREN) |
228 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 | 229 | |
3ca6a5f0 BP |
230 | if ( !wxWindow::MSWCreate(m_windowId, |
231 | parent, | |
232 | wxMDIFrameClassName, | |
233 | this, | |
234 | title, | |
235 | x, y, width, height, | |
236 | msflags) ) | |
237 | { | |
238 | return FALSE; | |
239 | } | |
2bda0e17 KB |
240 | |
241 | wxModelessWindows.Append(this); | |
242 | ||
f6bcfd97 BP |
243 | // unlike (almost?) all other windows, frames are created hidden |
244 | m_isShown = FALSE; | |
245 | ||
2bda0e17 KB |
246 | return TRUE; |
247 | } | |
248 | ||
c2dcfdef | 249 | wxMDIParentFrame::~wxMDIParentFrame() |
2bda0e17 | 250 | { |
42e69d6b | 251 | DestroyChildren(); |
f048e32f VZ |
252 | // already delete by DestroyChildren() |
253 | m_frameToolBar = NULL; | |
c0bcc480 | 254 | m_frameStatusBar = NULL; |
f048e32f | 255 | |
df61c009 JS |
256 | // ::DestroyMenu((HMENU)m_windowMenu); |
257 | if (m_windowMenu) | |
258 | { | |
259 | delete m_windowMenu; | |
260 | m_windowMenu = (wxMenu*) NULL; | |
261 | } | |
2bda0e17 | 262 | |
42e69d6b VZ |
263 | if ( m_clientWindow ) |
264 | { | |
265 | if ( m_clientWindow->MSWGetOldWndProc() ) | |
266 | m_clientWindow->UnsubclassWin(); | |
2bda0e17 | 267 | |
42e69d6b VZ |
268 | m_clientWindow->SetHWND(0); |
269 | delete m_clientWindow; | |
270 | } | |
2bda0e17 KB |
271 | } |
272 | ||
42e69d6b | 273 | void wxMDIParentFrame::InternalSetMenuBar() |
2bda0e17 | 274 | { |
df61c009 | 275 | // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0); |
2bda0e17 | 276 | |
42e69d6b | 277 | m_parentFrameActive = TRUE; |
2bda0e17 | 278 | |
df61c009 JS |
279 | HMENU subMenu = (HMENU) 0; |
280 | if (GetWindowMenu()) | |
281 | subMenu = (HMENU) GetWindowMenu()->GetHMenu(); | |
282 | ||
42e69d6b | 283 | InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu); |
2bda0e17 KB |
284 | } |
285 | ||
df61c009 JS |
286 | void wxMDIParentFrame::SetWindowMenu(wxMenu* menu) |
287 | { | |
288 | if (m_windowMenu) | |
289 | { | |
290 | if (GetMenuBar()) | |
291 | { | |
292 | // Remove old window menu | |
293 | RemoveWindowMenu(GetClientWindow(), m_hMenu); | |
294 | } | |
295 | ||
296 | delete m_windowMenu; | |
297 | m_windowMenu = (wxMenu*) NULL; | |
298 | } | |
299 | if (menu) | |
300 | { | |
301 | m_windowMenu = menu; | |
302 | if (GetMenuBar()) | |
b0a2157c VZ |
303 | { |
304 | InsertWindowMenu(GetClientWindow(), m_hMenu, | |
88c49a0f | 305 | GetHmenuOf(m_windowMenu)); |
b0a2157c | 306 | } |
df61c009 JS |
307 | } |
308 | } | |
309 | ||
a967ef9d | 310 | void wxMDIParentFrame::OnSize(wxSizeEvent&) |
2bda0e17 | 311 | { |
2bda0e17 | 312 | if ( GetClientWindow() ) |
42e69d6b VZ |
313 | { |
314 | int width, height; | |
315 | GetClientSize(&width, &height); | |
2bda0e17 | 316 | |
42e69d6b VZ |
317 | GetClientWindow()->SetSize(0, 0, width, height); |
318 | } | |
2bda0e17 KB |
319 | } |
320 | ||
2bda0e17 | 321 | // Returns the active MDI child window |
c2dcfdef | 322 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const |
2bda0e17 | 323 | { |
a23fd0e1 VZ |
324 | HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), |
325 | WM_MDIGETACTIVE, 0, 0L); | |
326 | if ( hWnd == 0 ) | |
327 | return NULL; | |
328 | else | |
329 | return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd); | |
2bda0e17 KB |
330 | } |
331 | ||
a23fd0e1 VZ |
332 | // Create the client window class (don't Create the window, just return a new |
333 | // class) | |
c2dcfdef | 334 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() |
2bda0e17 | 335 | { |
a23fd0e1 | 336 | return new wxMDIClientWindow; |
2bda0e17 KB |
337 | } |
338 | ||
339 | // Responds to colour changes, and passes event on to children. | |
340 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
341 | { | |
342 | if ( m_clientWindow ) | |
343 | { | |
344 | m_clientWindow->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
345 | m_clientWindow->Refresh(); | |
346 | } | |
2bda0e17 | 347 | |
42e69d6b | 348 | event.Skip(); |
2bda0e17 KB |
349 | } |
350 | ||
42e69d6b | 351 | // --------------------------------------------------------------------------- |
2bda0e17 | 352 | // MDI operations |
42e69d6b VZ |
353 | // --------------------------------------------------------------------------- |
354 | ||
c2dcfdef | 355 | void wxMDIParentFrame::Cascade() |
2bda0e17 | 356 | { |
a23fd0e1 | 357 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0); |
2bda0e17 KB |
358 | } |
359 | ||
42e69d6b | 360 | // TODO: add a direction argument (hor/vert) |
c2dcfdef | 361 | void wxMDIParentFrame::Tile() |
2bda0e17 | 362 | { |
a23fd0e1 | 363 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0); |
2bda0e17 KB |
364 | } |
365 | ||
c2dcfdef | 366 | void wxMDIParentFrame::ArrangeIcons() |
2bda0e17 | 367 | { |
a23fd0e1 | 368 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0); |
2bda0e17 KB |
369 | } |
370 | ||
c2dcfdef | 371 | void wxMDIParentFrame::ActivateNext() |
2bda0e17 | 372 | { |
a23fd0e1 | 373 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0); |
2bda0e17 KB |
374 | } |
375 | ||
c2dcfdef | 376 | void wxMDIParentFrame::ActivatePrevious() |
2bda0e17 | 377 | { |
a23fd0e1 | 378 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1); |
2bda0e17 KB |
379 | } |
380 | ||
42e69d6b | 381 | // --------------------------------------------------------------------------- |
a23fd0e1 | 382 | // the MDI parent frame window proc |
42e69d6b VZ |
383 | // --------------------------------------------------------------------------- |
384 | ||
a23fd0e1 VZ |
385 | long wxMDIParentFrame::MSWWindowProc(WXUINT message, |
386 | WXWPARAM wParam, | |
387 | WXLPARAM lParam) | |
2bda0e17 | 388 | { |
a23fd0e1 VZ |
389 | long rc = 0; |
390 | bool processed = FALSE; | |
2bda0e17 | 391 | |
a23fd0e1 VZ |
392 | switch ( message ) |
393 | { | |
42e69d6b VZ |
394 | case WM_ACTIVATE: |
395 | { | |
396 | WXWORD state, minimized; | |
397 | WXHWND hwnd; | |
398 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
399 | ||
400 | processed = HandleActivate(state, minimized != 0, hwnd); | |
401 | } | |
402 | break; | |
403 | ||
404 | case WM_COMMAND: | |
405 | { | |
406 | WXWORD id, cmd; | |
407 | WXHWND hwnd; | |
408 | UnpackCommand(wParam, lParam, &id, &hwnd, &cmd); | |
409 | ||
410 | (void)HandleCommand(id, cmd, hwnd); | |
411 | ||
412 | // even if the frame didn't process it, there is no need to try it | |
413 | // once again (i.e. call wxFrame::HandleCommand()) - we just dud it, | |
414 | // so pretend we processed the message anyhow | |
415 | processed = TRUE; | |
416 | } | |
b3818fbe VZ |
417 | |
418 | // always pass this message DefFrameProc(), otherwise MDI menu | |
419 | // commands (and sys commands - more surprizingly!) won't work | |
420 | MSWDefWindowProc(message, wParam, lParam); | |
42e69d6b VZ |
421 | break; |
422 | ||
a23fd0e1 VZ |
423 | case WM_CREATE: |
424 | m_clientWindow = OnCreateClient(); | |
425 | // Uses own style for client style | |
426 | if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) ) | |
427 | { | |
428 | wxLogMessage(_("Failed to create MDI parent frame.")); | |
2bda0e17 | 429 | |
a23fd0e1 VZ |
430 | rc = -1; |
431 | } | |
2bda0e17 | 432 | |
a23fd0e1 VZ |
433 | processed = TRUE; |
434 | break; | |
2bda0e17 | 435 | |
a23fd0e1 VZ |
436 | case WM_ERASEBKGND: |
437 | processed = TRUE; | |
2bda0e17 | 438 | |
a23fd0e1 VZ |
439 | // we erase background ourselves |
440 | rc = TRUE; | |
441 | break; | |
442 | ||
443 | case WM_MENUSELECT: | |
444 | { | |
42e69d6b VZ |
445 | WXWORD item, flags; |
446 | WXHMENU hmenu; | |
447 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
448 | ||
a23fd0e1 VZ |
449 | if ( m_parentFrameActive ) |
450 | { | |
42e69d6b | 451 | processed = HandleMenuSelect(item, flags, hmenu); |
a23fd0e1 VZ |
452 | } |
453 | else if (m_currentChild) | |
454 | { | |
455 | processed = m_currentChild-> | |
42e69d6b | 456 | HandleMenuSelect(item, flags, hmenu); |
a23fd0e1 VZ |
457 | } |
458 | } | |
459 | break; | |
b3818fbe VZ |
460 | |
461 | case WM_SIZE: | |
0655ad29 VZ |
462 | // as we don't (usually) resize the MDI client to exactly fit the |
463 | // client area (we put it below the toolbar, above statusbar &c), | |
464 | // we should not pass this one to DefFrameProc | |
b3818fbe | 465 | break; |
a23fd0e1 | 466 | } |
2bda0e17 | 467 | |
a23fd0e1 VZ |
468 | if ( !processed ) |
469 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
2bda0e17 | 470 | |
a23fd0e1 | 471 | return rc; |
2bda0e17 KB |
472 | } |
473 | ||
42e69d6b | 474 | bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate) |
2bda0e17 | 475 | { |
a23fd0e1 VZ |
476 | bool processed = FALSE; |
477 | ||
42e69d6b | 478 | if ( wxWindow::HandleActivate(state, minimized, activate) ) |
a23fd0e1 VZ |
479 | { |
480 | // already processed | |
481 | processed = TRUE; | |
482 | } | |
2bda0e17 KB |
483 | |
484 | // If this window is an MDI parent, we must also send an OnActivate message | |
485 | // to the current child. | |
42e69d6b | 486 | if ( (m_currentChild != NULL) && |
a23fd0e1 | 487 | ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) ) |
c2dcfdef | 488 | { |
debe6624 JS |
489 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId()); |
490 | event.SetEventObject( m_currentChild ); | |
a23fd0e1 VZ |
491 | if ( m_currentChild->GetEventHandler()->ProcessEvent(event) ) |
492 | processed = TRUE; | |
2bda0e17 | 493 | } |
a23fd0e1 VZ |
494 | |
495 | return processed; | |
2bda0e17 KB |
496 | } |
497 | ||
42e69d6b | 498 | bool wxMDIParentFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd) |
2bda0e17 | 499 | { |
2bda0e17 | 500 | // In case it's e.g. a toolbar. |
42e69d6b | 501 | if ( hwnd ) |
e1a6fc11 | 502 | { |
42e69d6b VZ |
503 | wxWindow *win = wxFindWinFromHandle(hwnd); |
504 | if ( win ) | |
505 | return win->MSWCommand(cmd, id); | |
e1a6fc11 JS |
506 | } |
507 | ||
42e69d6b VZ |
508 | // is it one of standard MDI commands? |
509 | WXWPARAM wParam = 0; | |
510 | int msg; | |
511 | switch ( id ) | |
2bda0e17 | 512 | { |
42e69d6b VZ |
513 | case IDM_WINDOWCASCADE: |
514 | msg = WM_MDICASCADE; | |
515 | wParam = MDITILE_SKIPDISABLED; | |
516 | break; | |
517 | ||
518 | case IDM_WINDOWTILEHOR: | |
519 | wParam |= MDITILE_HORIZONTAL; | |
520 | // fall through | |
521 | ||
522 | case IDM_WINDOWTILEVERT: | |
523 | if ( !wParam ) | |
524 | wParam = MDITILE_VERTICAL; | |
525 | msg = WM_MDITILE; | |
526 | wParam |= MDITILE_SKIPDISABLED; | |
527 | break; | |
528 | ||
529 | case IDM_WINDOWICONS: | |
530 | msg = WM_MDIICONARRANGE; | |
531 | break; | |
532 | ||
533 | case IDM_WINDOWNEXT: | |
534 | msg = WM_MDINEXT; | |
535 | break; | |
536 | ||
537 | default: | |
538 | msg = 0; | |
2bda0e17 | 539 | } |
c2dcfdef | 540 | |
42e69d6b | 541 | if ( msg ) |
2bda0e17 | 542 | { |
42e69d6b VZ |
543 | ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0); |
544 | ||
545 | return TRUE; | |
2bda0e17 | 546 | } |
42e69d6b VZ |
547 | |
548 | // FIXME VZ: what does this test do?? | |
549 | if (id >= 0xF000) | |
2bda0e17 | 550 | { |
42e69d6b | 551 | return FALSE; // Get WndProc to call default proc |
2bda0e17 | 552 | } |
42e69d6b VZ |
553 | |
554 | if ( IsMdiCommandId(id) ) | |
2bda0e17 | 555 | { |
42e69d6b VZ |
556 | wxWindowList::Node* node = GetChildren().GetFirst(); |
557 | while ( node ) | |
2bda0e17 | 558 | { |
42e69d6b VZ |
559 | wxWindow* child = node->GetData(); |
560 | if ( child->GetHWND() ) | |
2bda0e17 | 561 | { |
42e69d6b | 562 | long childId = wxGetWindowId(child->GetHWND()); |
48c12cb1 | 563 | if (childId == (long)id) |
42e69d6b VZ |
564 | { |
565 | ::SendMessage( GetWinHwnd(GetClientWindow()), | |
566 | WM_MDIACTIVATE, | |
567 | (WPARAM)child->GetHWND(), 0); | |
568 | return TRUE; | |
569 | } | |
2bda0e17 | 570 | } |
42e69d6b | 571 | node = node->GetNext(); |
2bda0e17 | 572 | } |
2bda0e17 | 573 | } |
42e69d6b | 574 | else if ( m_parentFrameActive ) |
2bda0e17 | 575 | { |
42e69d6b VZ |
576 | return ProcessCommand(id); |
577 | } | |
578 | else if ( m_currentChild ) | |
579 | { | |
580 | return m_currentChild->HandleCommand(id, cmd, hwnd); | |
581 | } | |
582 | else | |
583 | { | |
584 | // this shouldn't happen because it means that our messages are being | |
585 | // lost (they're not sent to the parent frame nor to the children) | |
f6bcfd97 | 586 | wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?")); |
2bda0e17 | 587 | } |
2bda0e17 | 588 | |
42e69d6b | 589 | return FALSE; |
2bda0e17 KB |
590 | } |
591 | ||
42e69d6b VZ |
592 | long wxMDIParentFrame::MSWDefWindowProc(WXUINT message, |
593 | WXWPARAM wParam, | |
594 | WXLPARAM lParam) | |
2bda0e17 | 595 | { |
c2dcfdef VZ |
596 | WXHWND clientWnd; |
597 | if ( GetClientWindow() ) | |
598 | clientWnd = GetClientWindow()->GetHWND(); | |
599 | else | |
600 | clientWnd = 0; | |
2bda0e17 | 601 | |
a23fd0e1 | 602 | return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam); |
2bda0e17 KB |
603 | } |
604 | ||
57a7b7c1 JS |
605 | bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) |
606 | { | |
a23fd0e1 | 607 | MSG *pMsg = (MSG *)msg; |
2bda0e17 | 608 | |
f6bcfd97 | 609 | // first let the current child get it |
a23fd0e1 VZ |
610 | if ( m_currentChild && m_currentChild->GetHWND() && |
611 | m_currentChild->MSWTranslateMessage(msg) ) | |
612 | { | |
613 | return TRUE; | |
614 | } | |
2bda0e17 | 615 | |
f6bcfd97 BP |
616 | // then try out accel table (will also check the menu accels) |
617 | if ( wxFrame::MSWTranslateMessage(msg) ) | |
a23fd0e1 VZ |
618 | { |
619 | return TRUE; | |
620 | } | |
2bda0e17 | 621 | |
f6bcfd97 | 622 | // finally, check for MDI specific built in accel keys |
a23fd0e1 VZ |
623 | if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN ) |
624 | { | |
625 | if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg)) | |
626 | return TRUE; | |
627 | } | |
57a7b7c1 | 628 | |
a23fd0e1 | 629 | return FALSE; |
2bda0e17 KB |
630 | } |
631 | ||
42e69d6b | 632 | // =========================================================================== |
a23fd0e1 | 633 | // wxMDIChildFrame |
42e69d6b | 634 | // =========================================================================== |
2bda0e17 | 635 | |
f6bcfd97 | 636 | void wxMDIChildFrame::Init() |
2bda0e17 | 637 | { |
f6bcfd97 | 638 | m_needsResize = TRUE; |
2bda0e17 KB |
639 | } |
640 | ||
641 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
a23fd0e1 VZ |
642 | wxWindowID id, |
643 | const wxString& title, | |
644 | const wxPoint& pos, | |
645 | const wxSize& size, | |
646 | long style, | |
647 | const wxString& name) | |
2bda0e17 | 648 | { |
42e69d6b VZ |
649 | m_defaultIcon = (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON |
650 | : wxDEFAULT_MDICHILDFRAME_ICON); | |
2bda0e17 KB |
651 | |
652 | SetName(name); | |
653 | ||
654 | if ( id > -1 ) | |
655 | m_windowId = id; | |
656 | else | |
657 | m_windowId = (int)NewControlId(); | |
658 | ||
42e69d6b VZ |
659 | if ( parent ) |
660 | { | |
661 | parent->AddChild(this); | |
662 | } | |
2bda0e17 KB |
663 | |
664 | wxWndHook = this; | |
665 | ||
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 | |
42e69d6b | 698 | DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN; |
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 | ||
3ca6a5f0 BP |
718 | m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()), |
719 | WM_MDICREATE, 0, (LONG)(LPSTR)&mcs); | |
2bda0e17 | 720 | |
2bda0e17 | 721 | wxWndHook = NULL; |
c7527e3f | 722 | wxAssociateWinWithHandle((HWND) GetHWND(), this); |
2bda0e17 | 723 | |
b3818fbe VZ |
724 | // VZ: what's this? an act of piracy? |
725 | //SetWindowLong(GetHwnd(), 0, (long)this); | |
2bda0e17 KB |
726 | |
727 | wxModelessWindows.Append(this); | |
921a43c1 | 728 | |
2bda0e17 KB |
729 | return TRUE; |
730 | } | |
731 | ||
c2dcfdef | 732 | wxMDIChildFrame::~wxMDIChildFrame() |
2bda0e17 | 733 | { |
627a3091 JS |
734 | DestroyChildren(); |
735 | ||
736 | // already delete by DestroyChildren() | |
737 | m_frameToolBar = NULL; | |
738 | m_frameStatusBar = NULL; | |
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 | ||
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 | |
df61c009 JS |
805 | // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0); |
806 | HMENU subMenu = (HMENU) 0; | |
807 | if (parent->GetWindowMenu()) | |
808 | subMenu = (HMENU) parent->GetWindowMenu()->GetHMenu(); | |
2bda0e17 | 809 | |
42e69d6b | 810 | InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu); |
2bda0e17 | 811 | |
42e69d6b | 812 | parent->m_parentFrameActive = FALSE; |
2bda0e17 KB |
813 | } |
814 | ||
42e69d6b | 815 | // --------------------------------------------------------------------------- |
2bda0e17 | 816 | // MDI operations |
42e69d6b VZ |
817 | // --------------------------------------------------------------------------- |
818 | ||
9b73db3c | 819 | void wxMDIChildFrame::Maximize(bool maximize) |
2bda0e17 KB |
820 | { |
821 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
822 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
823 | { |
824 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), | |
825 | maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE, | |
826 | (WPARAM)GetHwnd(), 0); | |
827 | } | |
2bda0e17 KB |
828 | } |
829 | ||
c2dcfdef | 830 | void wxMDIChildFrame::Restore() |
2bda0e17 KB |
831 | { |
832 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
833 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
834 | { |
835 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE, | |
836 | (WPARAM) GetHwnd(), 0); | |
837 | } | |
2bda0e17 KB |
838 | } |
839 | ||
c2dcfdef | 840 | void wxMDIChildFrame::Activate() |
2bda0e17 KB |
841 | { |
842 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
843 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
844 | { |
845 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE, | |
846 | (WPARAM) GetHwnd(), 0); | |
847 | } | |
2bda0e17 KB |
848 | } |
849 | ||
42e69d6b VZ |
850 | // --------------------------------------------------------------------------- |
851 | // MDI window proc and message handlers | |
852 | // --------------------------------------------------------------------------- | |
853 | ||
854 | long wxMDIChildFrame::MSWWindowProc(WXUINT message, | |
855 | WXWPARAM wParam, | |
856 | WXLPARAM lParam) | |
857 | { | |
858 | long rc = 0; | |
859 | bool processed = FALSE; | |
860 | ||
861 | switch ( message ) | |
862 | { | |
863 | case WM_COMMAND: | |
864 | { | |
865 | WORD id, cmd; | |
866 | WXHWND hwnd; | |
867 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
868 | &id, &hwnd, &cmd); | |
869 | ||
870 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
871 | } | |
872 | break; | |
873 | ||
42e69d6b VZ |
874 | case WM_GETMINMAXINFO: |
875 | // let the default window proc calculate the size of MDI children | |
876 | // frames because it is based on the size of the MDI client window, | |
877 | // not on the values specified in wxWindow m_min/max variables | |
878 | return MSWDefWindowProc(message, wParam, lParam); | |
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)) | |
933 | return TRUE; | |
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 BP |
942 | { |
943 | processed = FALSE; | |
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 | { | |
961 | activated = TRUE; | |
962 | parent->m_currentChild = this; | |
2bda0e17 | 963 | |
42e69d6b VZ |
964 | HMENU child_menu = (HMENU)GetWinMenu(); |
965 | if ( child_menu ) | |
966 | { | |
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 VZ |
976 | |
977 | activated = FALSE; | |
978 | parent->m_currentChild = NULL; | |
2bda0e17 | 979 | |
42e69d6b VZ |
980 | HMENU parent_menu = (HMENU)parent->GetWinMenu(); |
981 | if ( parent_menu ) | |
982 | { | |
983 | parent->m_parentFrameActive = TRUE; | |
984 | ||
985 | menuToSet = parent_menu; | |
986 | } | |
987 | } | |
988 | else | |
989 | { | |
18d2e170 | 990 | // we have nothing to do with it |
42e69d6b | 991 | return FALSE; |
2bda0e17 | 992 | } |
debe6624 | 993 | |
42e69d6b VZ |
994 | if ( menuToSet ) |
995 | { | |
df61c009 JS |
996 | HMENU subMenu = (HMENU) 0; |
997 | if (parent->GetWindowMenu()) | |
998 | subMenu = (HMENU) parent->GetWindowMenu()->GetHMenu(); | |
42e69d6b VZ |
999 | |
1000 | MDISetMenu(parent->GetClientWindow(), menuToSet, subMenu); | |
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 | { | |
1022 | ::AdjustWindowRectEx(&rectClient, dwStyle, FALSE, dwExStyle); | |
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 | ||
1036 | return FALSE; | |
1037 | } | |
1038 | ||
1039 | // --------------------------------------------------------------------------- | |
1040 | // MDI specific message translation/preprocessing | |
1041 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1042 | |
42e69d6b VZ |
1043 | long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam) |
1044 | { | |
1045 | return DefMDIChildProc(GetHwnd(), | |
1046 | (UINT)message, (WPARAM)wParam, (LPARAM)lParam); | |
1047 | } | |
1048 | ||
1049 | bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) | |
1050 | { | |
5a2762f0 | 1051 | return wxFrame::MSWTranslateMessage(msg); |
2bda0e17 KB |
1052 | } |
1053 | ||
42e69d6b VZ |
1054 | // --------------------------------------------------------------------------- |
1055 | // misc | |
1056 | // --------------------------------------------------------------------------- | |
1057 | ||
c2dcfdef | 1058 | void wxMDIChildFrame::MSWDestroyWindow() |
2bda0e17 | 1059 | { |
42e69d6b | 1060 | MSWDetachWindowMenu(); |
b3818fbe | 1061 | invalidHandle = GetHwnd(); |
2bda0e17 | 1062 | |
42e69d6b | 1063 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 1064 | |
42e69d6b VZ |
1065 | // Must make sure this handle is invalidated (set to NULL) since all sorts |
1066 | // of things could happen after the child client is destroyed, but before | |
1067 | // the wxFrame is destroyed. | |
2bda0e17 | 1068 | |
42e69d6b | 1069 | HWND oldHandle = (HWND)GetHWND(); |
b3818fbe VZ |
1070 | SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY, |
1071 | (WPARAM)oldHandle, 0); | |
18d2e170 JS |
1072 | |
1073 | if (parent->GetActiveChild() == (wxMDIChildFrame*) NULL) | |
1074 | ResetWindowStyle((void*) NULL); | |
1075 | ||
42e69d6b | 1076 | invalidHandle = 0; |
2bda0e17 | 1077 | |
42e69d6b VZ |
1078 | if (m_hMenu) |
1079 | { | |
1080 | ::DestroyMenu((HMENU) m_hMenu); | |
1081 | m_hMenu = 0; | |
1082 | } | |
ac6482e0 | 1083 | wxRemoveHandleAssociation(this); |
42e69d6b | 1084 | m_hWnd = 0; |
2bda0e17 KB |
1085 | } |
1086 | ||
42e69d6b VZ |
1087 | // Change the client window's extended style so we don't get a client edge |
1088 | // style when a child is maximised (a double border looks silly.) | |
2bda0e17 KB |
1089 | bool wxMDIChildFrame::ResetWindowStyle(void *vrect) |
1090 | { | |
1091 | #if defined(__WIN95__) | |
1092 | RECT *rect = (RECT *)vrect; | |
c2dcfdef VZ |
1093 | wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent(); |
1094 | wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild(); | |
1095 | if (!pChild || (pChild == this)) | |
1096 | { | |
47ca6bfb | 1097 | HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow()); |
8082a771 VZ |
1098 | DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE); |
1099 | ||
1100 | // we want to test whether there is a maximized child, so just set | |
1101 | // dwThisStyle to 0 if there is no child at all | |
1102 | DWORD dwThisStyle = pChild | |
1f3943e0 | 1103 | ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0; |
c2dcfdef | 1104 | DWORD dwNewStyle = dwStyle; |
8082a771 | 1105 | if ( dwThisStyle & WS_MAXIMIZE ) |
c2dcfdef VZ |
1106 | dwNewStyle &= ~(WS_EX_CLIENTEDGE); |
1107 | else | |
1108 | dwNewStyle |= WS_EX_CLIENTEDGE; | |
1109 | ||
1110 | if (dwStyle != dwNewStyle) | |
1111 | { | |
47ca6bfb VZ |
1112 | // force update of everything |
1113 | ::RedrawWindow(hwndClient, NULL, NULL, | |
1114 | RDW_INVALIDATE | RDW_ALLCHILDREN); | |
1115 | ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle); | |
1116 | ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0, | |
42e69d6b VZ |
1117 | SWP_FRAMECHANGED | SWP_NOACTIVATE | |
1118 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | | |
1119 | SWP_NOCOPYBITS); | |
c2dcfdef | 1120 | if (rect) |
47ca6bfb | 1121 | ::GetClientRect(hwndClient, rect); |
2bda0e17 | 1122 | |
42e69d6b | 1123 | return TRUE; |
2bda0e17 | 1124 | } |
c2dcfdef | 1125 | } |
42e69d6b | 1126 | #endif // Win95 |
a23fd0e1 VZ |
1127 | |
1128 | return FALSE; | |
2bda0e17 KB |
1129 | } |
1130 | ||
42e69d6b VZ |
1131 | // =========================================================================== |
1132 | // wxMDIClientWindow: the window of predefined (by Windows) class which | |
1133 | // contains the child frames | |
1134 | // =========================================================================== | |
2bda0e17 | 1135 | |
debe6624 | 1136 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) |
2bda0e17 | 1137 | { |
42e69d6b | 1138 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE); |
2bda0e17 | 1139 | |
42e69d6b VZ |
1140 | CLIENTCREATESTRUCT ccs; |
1141 | m_windowStyle = style; | |
1142 | m_parent = parent; | |
c2dcfdef | 1143 | |
df61c009 JS |
1144 | ccs.hWindowMenu = (HMENU) 0; |
1145 | if (parent->GetWindowMenu()) | |
1146 | ccs.hWindowMenu = (HMENU) parent->GetWindowMenu()->GetHMenu(); | |
42e69d6b | 1147 | ccs.idFirstChild = wxFIRST_MDI_CHILD; |
2bda0e17 | 1148 | |
e1437298 | 1149 | DWORD msStyle = /* MDIS_ALLCHILDSTYLES | */ WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN; |
42e69d6b VZ |
1150 | if ( style & wxHSCROLL ) |
1151 | msStyle |= WS_HSCROLL; | |
1152 | if ( style & wxVSCROLL ) | |
1153 | msStyle |= WS_VSCROLL; | |
2bda0e17 KB |
1154 | |
1155 | #if defined(__WIN95__) | |
42e69d6b | 1156 | DWORD exStyle = WS_EX_CLIENTEDGE; |
2bda0e17 | 1157 | #else |
42e69d6b | 1158 | DWORD exStyle = 0; |
2bda0e17 KB |
1159 | #endif |
1160 | ||
42e69d6b VZ |
1161 | wxWndHook = this; |
1162 | m_hWnd = (WXHWND)::CreateWindowEx | |
1163 | ( | |
1164 | exStyle, | |
223d09f6 | 1165 | wxT("MDICLIENT"), |
42e69d6b VZ |
1166 | NULL, |
1167 | msStyle, | |
1168 | 0, 0, 0, 0, | |
1169 | GetWinHwnd(parent), | |
1170 | NULL, | |
1171 | wxGetInstance(), | |
1172 | (LPSTR)(LPCLIENTCREATESTRUCT)&ccs); | |
1173 | if ( !m_hWnd ) | |
1174 | { | |
f6bcfd97 | 1175 | wxLogLastError(wxT("CreateWindowEx(MDI client)")); |
2bda0e17 | 1176 | |
42e69d6b VZ |
1177 | return FALSE; |
1178 | } | |
2bda0e17 | 1179 | |
42e69d6b VZ |
1180 | SubclassWin(m_hWnd); |
1181 | wxWndHook = NULL; | |
2bda0e17 | 1182 | |
42e69d6b | 1183 | return TRUE; |
2bda0e17 KB |
1184 | } |
1185 | ||
1186 | // Explicitly call default scroll behaviour | |
1187 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
1188 | { | |
1189 | // Note: for client windows, the scroll position is not set in | |
1190 | // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what | |
1191 | // scroll position we're at. | |
1192 | // This makes it hard to paint patterns or bitmaps in the background, | |
1193 | // and have the client area scrollable as well. | |
1194 | ||
1195 | if ( event.GetOrientation() == wxHORIZONTAL ) | |
1196 | m_scrollX = event.GetPosition(); // Always returns zero! | |
1197 | else | |
1198 | m_scrollY = event.GetPosition(); // Always returns zero! | |
1199 | ||
42e69d6b VZ |
1200 | event.Skip(); |
1201 | } | |
1202 | ||
ec06b234 JS |
1203 | void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
1204 | { | |
1205 | // Try to fix a problem whereby if you show an MDI child frame, then reposition the | |
1206 | // client area, you can end up with a non-refreshed portion in the client window | |
1207 | // (see OGL studio sample). So check if the position is changed and if so, | |
1208 | // redraw the MDI child frames. | |
1209 | ||
1210 | wxPoint oldPos = GetPosition(); | |
1211 | ||
1212 | wxWindow::DoSetSize(x, y, width, height, sizeFlags); | |
1213 | ||
1214 | wxPoint newPos = GetPosition(); | |
1215 | ||
1216 | if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y)) | |
1217 | { | |
1218 | if (GetParent()) | |
1219 | { | |
1220 | wxNode* node = GetParent()->GetChildren().First(); | |
1221 | while (node) | |
1222 | { | |
1223 | wxWindow* child = (wxWindow*) node->Data(); | |
1224 | if (child->IsKindOf(CLASSINFO(wxMDIChildFrame))) | |
1225 | { | |
1226 | HWND hWnd = (HWND) child->GetHWND(); | |
1227 | ::RedrawWindow(hWnd, NULL, NULL, RDW_FRAME|RDW_ALLCHILDREN|RDW_INVALIDATE ); | |
1228 | } | |
1229 | node = node->Next(); | |
1230 | } | |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | ||
f6bcfd97 BP |
1235 | void wxMDIChildFrame::OnIdle(wxIdleEvent& event) |
1236 | { | |
1237 | // MDI child frames get their WM_SIZE when they're constructed but at this | |
1238 | // moment they don't have any children yet so all child windows will be | |
1239 | // positioned incorrectly when they are added later - to fix this, we | |
1240 | // generate an artificial size event here | |
1241 | if ( m_needsResize ) | |
1242 | { | |
1243 | m_needsResize = FALSE; // avoid any possibility of recursion | |
1244 | ||
1245 | SendSizeEvent(); | |
1246 | } | |
1247 | ||
1248 | event.Skip(); | |
1249 | } | |
1250 | ||
42e69d6b VZ |
1251 | // --------------------------------------------------------------------------- |
1252 | // non member functions | |
1253 | // --------------------------------------------------------------------------- | |
1254 | ||
1255 | static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow) | |
1256 | { | |
1257 | ::SendMessage(GetWinHwnd(win), WM_MDISETMENU, | |
1258 | #ifdef __WIN32__ | |
f6bcfd97 | 1259 | (WPARAM)hmenuFrame, (LPARAM)hmenuWindow |
42e69d6b | 1260 | #else |
f6bcfd97 | 1261 | 0, MAKELPARAM(hmenuFrame, hmenuWindow) |
42e69d6b | 1262 | #endif |
f6bcfd97 | 1263 | ); |
42e69d6b VZ |
1264 | |
1265 | // update menu bar of the parent window | |
1266 | wxWindow *parent = win->GetParent(); | |
223d09f6 | 1267 | wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") ); |
42e69d6b | 1268 | |
a967ef9d | 1269 | ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L); |
42e69d6b VZ |
1270 | ::DrawMenuBar(GetWinHwnd(parent)); |
1271 | } | |
1272 | ||
1273 | static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu) | |
1274 | { | |
1275 | // Try to insert Window menu in front of Help, otherwise append it. | |
1276 | HMENU hmenu = (HMENU)menu; | |
df61c009 JS |
1277 | |
1278 | if (subMenu) | |
1279 | { | |
42e69d6b VZ |
1280 | int N = GetMenuItemCount(hmenu); |
1281 | bool success = FALSE; | |
1282 | for ( int i = 0; i < N; i++ ) | |
1283 | { | |
837e5743 | 1284 | wxChar buf[256]; |
42e69d6b VZ |
1285 | int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION); |
1286 | if ( chars == 0 ) | |
1287 | { | |
223d09f6 | 1288 | wxLogLastError(wxT("GetMenuString")); |
42e69d6b VZ |
1289 | |
1290 | continue; | |
1291 | } | |
1292 | ||
f6bcfd97 | 1293 | if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) ) |
42e69d6b VZ |
1294 | { |
1295 | success = TRUE; | |
1296 | ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING, | |
f6bcfd97 | 1297 | (UINT)subMenu, _("&Window")); |
42e69d6b VZ |
1298 | break; |
1299 | } | |
1300 | } | |
1301 | ||
1302 | if ( !success ) | |
1303 | { | |
f6bcfd97 | 1304 | ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window")); |
42e69d6b | 1305 | } |
df61c009 | 1306 | } |
42e69d6b VZ |
1307 | |
1308 | MDISetMenu(win, hmenu, subMenu); | |
1309 | } | |
1310 | ||
df61c009 JS |
1311 | static void RemoveWindowMenu(wxWindow *win, WXHMENU menu) |
1312 | { | |
1313 | // Try to insert Window menu in front of Help, otherwise append it. | |
1314 | HMENU hmenu = (HMENU)menu; | |
1315 | int N = GetMenuItemCount(hmenu); | |
df61c009 JS |
1316 | for ( int i = 0; i < N; i++ ) |
1317 | { | |
1318 | wxChar buf[256]; | |
1319 | int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION); | |
1320 | if ( chars == 0 ) | |
1321 | { | |
1322 | wxLogLastError(wxT("GetMenuString")); | |
1323 | ||
1324 | continue; | |
1325 | } | |
1326 | ||
f6bcfd97 | 1327 | if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Window")) ) |
df61c009 | 1328 | { |
df61c009 JS |
1329 | ::RemoveMenu(hmenu, i, MF_BYPOSITION); |
1330 | break; | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | // Does passing 0 for the window menu really work with WM_MDISETMENU? | |
1335 | MDISetMenu(win, hmenu, 0); | |
1336 | } | |
1337 | ||
2917e920 BM |
1338 | static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
1339 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact) | |
42e69d6b VZ |
1340 | { |
1341 | #ifdef __WIN32__ | |
1342 | *activate = TRUE; | |
1343 | *hwndAct = (WXHWND)lParam; | |
1344 | *hwndDeact = (WXHWND)wParam; | |
1345 | #else // Win16 | |
1346 | *activate = (WXWORD)wParam; | |
1347 | *hwndAct = (WXHWND)LOWORD(lParam); | |
1348 | *hwndDeact = (WXHWND)HIWORD(lParam); | |
1349 | #endif // Win32/Win16 | |
2bda0e17 | 1350 | } |