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