]>
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | ||
b442f107 VZ |
31 | #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__) |
32 | ||
2bda0e17 | 33 | #ifndef WX_PRECOMP |
a23fd0e1 VZ |
34 | #include "wx/setup.h" |
35 | #include "wx/frame.h" | |
36 | #include "wx/menu.h" | |
37 | #include "wx/app.h" | |
38 | #include "wx/utils.h" | |
39 | #include "wx/dialog.h" | |
7c0ea335 VZ |
40 | #if wxUSE_STATUSBAR |
41 | #include "wx/statusbr.h" | |
42 | #endif | |
a23fd0e1 | 43 | #include "wx/settings.h" |
0c589ad0 BM |
44 | #include "wx/intl.h" |
45 | #include "wx/log.h" | |
2bda0e17 KB |
46 | #endif |
47 | ||
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; |
c7527e3f | 71 | extern void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win); |
ac6482e0 | 72 | extern void wxRemoveHandleAssociation(wxWindow *win); |
a23fd0e1 | 73 | |
42e69d6b VZ |
74 | static HWND invalidHandle = 0; |
75 | ||
a23fd0e1 VZ |
76 | // --------------------------------------------------------------------------- |
77 | // constants | |
78 | // --------------------------------------------------------------------------- | |
79 | ||
80 | static const int IDM_WINDOWTILE = 4001; | |
42e69d6b | 81 | static const int IDM_WINDOWTILEHOR = 4001; |
a23fd0e1 VZ |
82 | static const int IDM_WINDOWCASCADE = 4002; |
83 | static const int IDM_WINDOWICONS = 4003; | |
84 | static const int IDM_WINDOWNEXT = 4004; | |
42e69d6b | 85 | static const int IDM_WINDOWTILEVERT = 4005; |
4f3b37fd | 86 | static const int IDM_WINDOWPREV = 4006; |
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 | ||
4e152a23 | 117 | // unpack the parameters of WM_MDIACTIVATE message |
2917e920 BM |
118 | static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
119 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact); | |
42e69d6b | 120 | |
4e152a23 VZ |
121 | // return the HMENU of the MDI menu |
122 | static inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame) | |
123 | { | |
124 | wxMenu *menu = frame->GetWindowMenu(); | |
125 | return menu ? GetHmenuOf(menu) : 0; | |
126 | } | |
127 | ||
a23fd0e1 VZ |
128 | // =========================================================================== |
129 | // implementation | |
130 | // =========================================================================== | |
131 | ||
132 | // --------------------------------------------------------------------------- | |
133 | // wxWin macros | |
134 | // --------------------------------------------------------------------------- | |
2bda0e17 | 135 | |
225fe9d6 VZ |
136 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) |
137 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
138 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
2bda0e17 KB |
139 | |
140 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
a23fd0e1 | 141 | EVT_SIZE(wxMDIParentFrame::OnSize) |
a23fd0e1 | 142 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) |
2bda0e17 KB |
143 | END_EVENT_TABLE() |
144 | ||
f6bcfd97 BP |
145 | BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) |
146 | EVT_IDLE(wxMDIChildFrame::OnIdle) | |
147 | END_EVENT_TABLE() | |
148 | ||
2bda0e17 | 149 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) |
a23fd0e1 | 150 | EVT_SCROLL(wxMDIClientWindow::OnScroll) |
2bda0e17 KB |
151 | END_EVENT_TABLE() |
152 | ||
42e69d6b VZ |
153 | // =========================================================================== |
154 | // wxMDIParentFrame: the frame which contains the client window which manages | |
155 | // the children | |
156 | // =========================================================================== | |
2bda0e17 | 157 | |
c2dcfdef | 158 | wxMDIParentFrame::wxMDIParentFrame() |
2bda0e17 KB |
159 | { |
160 | m_clientWindow = NULL; | |
161 | m_currentChild = NULL; | |
df61c009 | 162 | m_windowMenu = (wxMenu*) NULL; |
4f8090e0 | 163 | m_parentFrameActive = true; |
2bda0e17 KB |
164 | } |
165 | ||
166 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
a23fd0e1 VZ |
167 | wxWindowID id, |
168 | const wxString& title, | |
169 | const wxPoint& pos, | |
170 | const wxSize& size, | |
171 | long style, | |
172 | const wxString& name) | |
2bda0e17 | 173 | { |
2bda0e17 KB |
174 | m_clientWindow = NULL; |
175 | m_currentChild = NULL; | |
df61c009 | 176 | |
3d8dea7e VZ |
177 | // this style can be used to prevent a window from having the standard MDI |
178 | // "Window" menu | |
179 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
180 | { | |
181 | m_windowMenu = (wxMenu *)NULL; | |
182 | } | |
183 | else // normal case: we have the window menu, so construct it | |
df61c009 | 184 | { |
df61c009 JS |
185 | m_windowMenu = new wxMenu; |
186 | ||
b0a2157c VZ |
187 | m_windowMenu->Append(IDM_WINDOWCASCADE, _("&Cascade")); |
188 | m_windowMenu->Append(IDM_WINDOWTILEHOR, _("Tile &Horizontally")); | |
189 | m_windowMenu->Append(IDM_WINDOWTILEVERT, _("Tile &Vertically")); | |
df61c009 | 190 | m_windowMenu->AppendSeparator(); |
b0a2157c VZ |
191 | m_windowMenu->Append(IDM_WINDOWICONS, _("&Arrange Icons")); |
192 | m_windowMenu->Append(IDM_WINDOWNEXT, _("&Next")); | |
4f3b37fd | 193 | m_windowMenu->Append(IDM_WINDOWPREV, _("&Previous")); |
df61c009 JS |
194 | } |
195 | ||
4f8090e0 | 196 | m_parentFrameActive = true; |
2bda0e17 KB |
197 | |
198 | if (!parent) | |
199 | wxTopLevelWindows.Append(this); | |
200 | ||
201 | SetName(name); | |
202 | m_windowStyle = style; | |
203 | ||
b225f659 VZ |
204 | if ( parent ) |
205 | parent->AddChild(this); | |
2bda0e17 KB |
206 | |
207 | if ( id > -1 ) | |
208 | m_windowId = id; | |
209 | else | |
b225f659 | 210 | m_windowId = NewControlId(); |
2bda0e17 | 211 | |
912c192f VZ |
212 | WXDWORD exflags; |
213 | WXDWORD msflags = MSWGetCreateWindowFlags(&exflags); | |
ea723360 JS |
214 | msflags &= ~WS_VSCROLL; |
215 | msflags &= ~WS_HSCROLL; | |
2bda0e17 | 216 | |
b225f659 | 217 | if ( !wxWindow::MSWCreate(wxMDIFrameClassName, |
3ca6a5f0 | 218 | title, |
b225f659 VZ |
219 | pos, size, |
220 | msflags, | |
221 | exflags) ) | |
3ca6a5f0 | 222 | { |
4f8090e0 | 223 | return false; |
3ca6a5f0 | 224 | } |
2bda0e17 KB |
225 | |
226 | wxModelessWindows.Append(this); | |
227 | ||
f6bcfd97 | 228 | // unlike (almost?) all other windows, frames are created hidden |
4f8090e0 | 229 | m_isShown = false; |
f6bcfd97 | 230 | |
4f8090e0 | 231 | return true; |
2bda0e17 KB |
232 | } |
233 | ||
c2dcfdef | 234 | wxMDIParentFrame::~wxMDIParentFrame() |
2bda0e17 | 235 | { |
d1e44484 | 236 | // see comment in ~wxMDIChildFrame |
1904aa72 | 237 | #if wxUSE_TOOLBAR |
f048e32f | 238 | m_frameToolBar = NULL; |
1904aa72 | 239 | #endif |
c0bcc480 | 240 | m_frameStatusBar = NULL; |
f048e32f | 241 | |
d1e44484 VZ |
242 | DestroyChildren(); |
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 | { | |
94826170 VZ |
347 | // we don't have any standard icons (any more) |
348 | return (WXHICON)0; | |
82c9f85c VZ |
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 | |
01ebf752 | 413 | // once again (i.e. call wxFrame::HandleCommand()) - we just did it, |
42e69d6b | 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 | |
01ebf752 | 419 | // commands (and sys commands - more surprisingly!) won't work |
b3818fbe | 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 | { |
222ed1d6 | 563 | wxWindowList::compatibility_iterator 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 | |
e441e1f4 VZ |
676 | mcs.szClass = style & wxFULL_REPAINT_ON_RESIZE |
677 | ? wxMDIChildFrameClassName | |
678 | : wxMDIChildFrameClassNameNoRedraw; | |
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 | |
3b60c67b | 701 | DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN | 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 | { |
d1e44484 VZ |
735 | // will be destroyed by DestroyChildren() but reset them before calling it |
736 | // to avoid using dangling pointers if a callback comes in the meanwhile | |
1904aa72 | 737 | #if wxUSE_TOOLBAR |
627a3091 | 738 | m_frameToolBar = NULL; |
1904aa72 | 739 | #endif |
627a3091 JS |
740 | m_frameStatusBar = NULL; |
741 | ||
d1e44484 VZ |
742 | DestroyChildren(); |
743 | ||
4e152a23 VZ |
744 | RemoveWindowMenu(NULL, m_hMenu); |
745 | ||
c2dcfdef | 746 | MSWDestroyWindow(); |
2bda0e17 KB |
747 | } |
748 | ||
749 | // Set the client size (i.e. leave the calculation of borders etc. | |
750 | // to wxWindows) | |
cc2b7472 | 751 | void wxMDIChildFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 752 | { |
b3818fbe | 753 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
754 | |
755 | RECT rect; | |
2de8030d | 756 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
757 | |
758 | RECT rect2; | |
759 | GetWindowRect(hWnd, &rect2); | |
760 | ||
761 | // Find the difference between the entire window (title bar and all) | |
762 | // and the client area; add this to the new client size to move the | |
763 | // window | |
764 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
765 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
766 | ||
a2327a9f | 767 | if (GetStatusBar() && GetStatusBar()->IsShown()) |
2bda0e17 | 768 | { |
c2dcfdef VZ |
769 | int sx, sy; |
770 | GetStatusBar()->GetSize(&sx, &sy); | |
2bda0e17 KB |
771 | actual_height += sy; |
772 | } | |
773 | ||
774 | POINT point; | |
775 | point.x = rect2.left; | |
776 | point.y = rect2.top; | |
777 | ||
778 | // If there's an MDI parent, must subtract the parent's top left corner | |
779 | // since MoveWindow moves relative to the parent | |
780 | wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent(); | |
781 | ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point); | |
782 | ||
4f8090e0 | 783 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)true); |
debe6624 | 784 | |
2bda0e17 | 785 | wxSizeEvent event(wxSize(width, height), m_windowId); |
debe6624 | 786 | event.SetEventObject( this ); |
2bda0e17 | 787 | GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
788 | } |
789 | ||
cc2b7472 | 790 | void wxMDIChildFrame::DoGetPosition(int *x, int *y) const |
2bda0e17 KB |
791 | { |
792 | RECT rect; | |
b3818fbe | 793 | GetWindowRect(GetHwnd(), &rect); |
2bda0e17 KB |
794 | POINT point; |
795 | point.x = rect.left; | |
796 | point.y = rect.top; | |
797 | ||
798 | // Since we now have the absolute screen coords, | |
799 | // if there's a parent we must subtract its top left corner | |
800 | wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent(); | |
801 | ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point); | |
802 | ||
803 | *x = point.x; | |
804 | *y = point.y; | |
805 | } | |
806 | ||
42e69d6b | 807 | void wxMDIChildFrame::InternalSetMenuBar() |
2bda0e17 | 808 | { |
42e69d6b | 809 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 810 | |
4e152a23 VZ |
811 | InsertWindowMenu(parent->GetClientWindow(), |
812 | m_hMenu, GetMDIWindowMenu(parent)); | |
2bda0e17 | 813 | |
4f8090e0 | 814 | parent->m_parentFrameActive = false; |
2bda0e17 KB |
815 | } |
816 | ||
82c9f85c VZ |
817 | WXHICON wxMDIChildFrame::GetDefaultIcon() const |
818 | { | |
94826170 VZ |
819 | // we don't have any standard icons (any more) |
820 | return (WXHICON)0; | |
82c9f85c VZ |
821 | } |
822 | ||
42e69d6b | 823 | // --------------------------------------------------------------------------- |
2bda0e17 | 824 | // MDI operations |
42e69d6b VZ |
825 | // --------------------------------------------------------------------------- |
826 | ||
9b73db3c | 827 | void wxMDIChildFrame::Maximize(bool maximize) |
2bda0e17 KB |
828 | { |
829 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
830 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
831 | { |
832 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), | |
833 | maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE, | |
834 | (WPARAM)GetHwnd(), 0); | |
835 | } | |
2bda0e17 KB |
836 | } |
837 | ||
c2dcfdef | 838 | void wxMDIChildFrame::Restore() |
2bda0e17 KB |
839 | { |
840 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
841 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
842 | { |
843 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE, | |
844 | (WPARAM) GetHwnd(), 0); | |
845 | } | |
2bda0e17 KB |
846 | } |
847 | ||
c2dcfdef | 848 | void wxMDIChildFrame::Activate() |
2bda0e17 KB |
849 | { |
850 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); | |
851 | if ( parent && parent->GetClientWindow() ) | |
9b73db3c VZ |
852 | { |
853 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE, | |
854 | (WPARAM) GetHwnd(), 0); | |
855 | } | |
2bda0e17 KB |
856 | } |
857 | ||
42e69d6b VZ |
858 | // --------------------------------------------------------------------------- |
859 | // MDI window proc and message handlers | |
860 | // --------------------------------------------------------------------------- | |
861 | ||
862 | long wxMDIChildFrame::MSWWindowProc(WXUINT message, | |
863 | WXWPARAM wParam, | |
864 | WXLPARAM lParam) | |
865 | { | |
866 | long rc = 0; | |
4f8090e0 | 867 | bool processed = false; |
42e69d6b VZ |
868 | |
869 | switch ( message ) | |
870 | { | |
871 | case WM_COMMAND: | |
872 | { | |
873 | WORD id, cmd; | |
874 | WXHWND hwnd; | |
875 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
876 | &id, &hwnd, &cmd); | |
877 | ||
878 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
879 | } | |
880 | break; | |
881 | ||
42e69d6b | 882 | case WM_GETMINMAXINFO: |
3ebcfb76 VZ |
883 | processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam); |
884 | break; | |
42e69d6b VZ |
885 | |
886 | case WM_MDIACTIVATE: | |
887 | { | |
888 | WXWORD act; | |
889 | WXHWND hwndAct, hwndDeact; | |
890 | UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact); | |
891 | ||
892 | processed = HandleMDIActivate(act, hwndAct, hwndDeact); | |
893 | } | |
b3818fbe VZ |
894 | // fall through |
895 | ||
896 | case WM_MOVE: | |
897 | // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client | |
898 | // scrollbars if necessary | |
899 | ||
900 | // fall through | |
901 | ||
902 | case WM_SIZE: | |
903 | // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird | |
904 | // things happen | |
905 | MSWDefWindowProc(message, wParam, lParam); | |
42e69d6b VZ |
906 | break; |
907 | ||
b3818fbe VZ |
908 | case WM_SYSCOMMAND: |
909 | // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it | |
910 | // the message (the base class version does not) | |
911 | return MSWDefWindowProc(message, wParam, lParam); | |
912 | ||
42e69d6b VZ |
913 | case WM_WINDOWPOSCHANGING: |
914 | processed = HandleWindowPosChanging((LPWINDOWPOS)lParam); | |
915 | break; | |
916 | } | |
917 | ||
918 | if ( !processed ) | |
919 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
920 | ||
921 | return rc; | |
922 | } | |
923 | ||
42e69d6b | 924 | bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd) |
2bda0e17 | 925 | { |
2bda0e17 | 926 | // In case it's e.g. a toolbar. |
42e69d6b VZ |
927 | if ( hwnd ) |
928 | { | |
929 | wxWindow *win = wxFindWinFromHandle(hwnd); | |
930 | if (win) | |
931 | return win->MSWCommand(cmd, id); | |
932 | } | |
2bda0e17 | 933 | |
e1a6fc11 JS |
934 | if (wxCurrentPopupMenu) |
935 | { | |
936 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
937 | wxCurrentPopupMenu = NULL; | |
938 | if (popupMenu->MSWCommand(cmd, id)) | |
4f8090e0 | 939 | return true; |
e1a6fc11 JS |
940 | } |
941 | ||
3ca6a5f0 | 942 | bool processed; |
dd60b9ec | 943 | if (GetMenuBar() && GetMenuBar()->FindItem(id)) |
2bda0e17 | 944 | { |
3ca6a5f0 | 945 | processed = ProcessCommand(id); |
2bda0e17 KB |
946 | } |
947 | else | |
3ca6a5f0 | 948 | { |
4f8090e0 | 949 | processed = false; |
3ca6a5f0 | 950 | } |
42e69d6b | 951 | |
3ca6a5f0 | 952 | return processed; |
2bda0e17 KB |
953 | } |
954 | ||
42e69d6b VZ |
955 | bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), |
956 | WXHWND hwndAct, | |
957 | WXHWND hwndDeact) | |
2bda0e17 | 958 | { |
42e69d6b | 959 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 960 | |
42e69d6b | 961 | HMENU menuToSet = 0; |
57a7b7c1 | 962 | |
42e69d6b | 963 | bool activated; |
57a7b7c1 | 964 | |
42e69d6b VZ |
965 | if ( m_hWnd == hwndAct ) |
966 | { | |
4f8090e0 | 967 | activated = true; |
42e69d6b | 968 | parent->m_currentChild = this; |
2bda0e17 | 969 | |
42e69d6b VZ |
970 | HMENU child_menu = (HMENU)GetWinMenu(); |
971 | if ( child_menu ) | |
972 | { | |
4f8090e0 | 973 | parent->m_parentFrameActive = false; |
2bda0e17 | 974 | |
42e69d6b VZ |
975 | menuToSet = child_menu; |
976 | } | |
977 | } | |
978 | else if ( m_hWnd == hwndDeact ) | |
2bda0e17 | 979 | { |
42e69d6b | 980 | wxASSERT_MSG( parent->m_currentChild == this, |
223d09f6 | 981 | wxT("can't deactivate MDI child which wasn't active!") ); |
42e69d6b | 982 | |
4f8090e0 | 983 | activated = false; |
42e69d6b | 984 | parent->m_currentChild = NULL; |
2bda0e17 | 985 | |
42e69d6b | 986 | HMENU parent_menu = (HMENU)parent->GetWinMenu(); |
f4075804 VZ |
987 | |
988 | // activate the the parent menu only when there is no other child | |
989 | // that has been activated | |
990 | if ( parent_menu && !hwndAct ) | |
42e69d6b | 991 | { |
4f8090e0 | 992 | parent->m_parentFrameActive = true; |
42e69d6b VZ |
993 | |
994 | menuToSet = parent_menu; | |
995 | } | |
996 | } | |
997 | else | |
998 | { | |
18d2e170 | 999 | // we have nothing to do with it |
4f8090e0 | 1000 | return false; |
2bda0e17 | 1001 | } |
debe6624 | 1002 | |
42e69d6b VZ |
1003 | if ( menuToSet ) |
1004 | { | |
4e152a23 VZ |
1005 | MDISetMenu(parent->GetClientWindow(), |
1006 | menuToSet, GetMDIWindowMenu(parent)); | |
42e69d6b VZ |
1007 | } |
1008 | ||
1009 | wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId); | |
debe6624 | 1010 | event.SetEventObject( this ); |
2bda0e17 | 1011 | |
c03b48d7 GT |
1012 | ResetWindowStyle((void *)NULL); |
1013 | ||
42e69d6b VZ |
1014 | return GetEventHandler()->ProcessEvent(event); |
1015 | } | |
1016 | ||
1017 | bool wxMDIChildFrame::HandleWindowPosChanging(void *pos) | |
1018 | { | |
1019 | WINDOWPOS *lpPos = (WINDOWPOS *)pos; | |
1020 | #if defined(__WIN95__) | |
1021 | if (!(lpPos->flags & SWP_NOSIZE)) | |
2bda0e17 | 1022 | { |
42e69d6b | 1023 | RECT rectClient; |
b3818fbe VZ |
1024 | DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); |
1025 | DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
42e69d6b VZ |
1026 | if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE)) |
1027 | { | |
4f8090e0 | 1028 | ::AdjustWindowRectEx(&rectClient, dwStyle, false, dwExStyle); |
42e69d6b VZ |
1029 | lpPos->x = rectClient.left; |
1030 | lpPos->y = rectClient.top; | |
1031 | lpPos->cx = rectClient.right - rectClient.left; | |
1032 | lpPos->cy = rectClient.bottom - rectClient.top; | |
1033 | } | |
1904aa72 | 1034 | #if wxUSE_TOOLBAR |
42e69d6b | 1035 | wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent(); |
a2327a9f | 1036 | if (pFrameWnd && pFrameWnd->GetToolBar() && pFrameWnd->GetToolBar()->IsShown()) |
42e69d6b VZ |
1037 | { |
1038 | pFrameWnd->GetToolBar()->Refresh(); | |
1039 | } | |
1904aa72 | 1040 | #endif |
42e69d6b VZ |
1041 | } |
1042 | #endif // Win95 | |
1043 | ||
4f8090e0 | 1044 | return false; |
42e69d6b VZ |
1045 | } |
1046 | ||
3ebcfb76 VZ |
1047 | bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo) |
1048 | { | |
1049 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; | |
1050 | ||
1051 | // let the default window proc calculate the size of MDI children | |
1052 | // frames because it is based on the size of the MDI client window, | |
1053 | // not on the values specified in wxWindow m_max variables | |
d9f9aa2d | 1054 | bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0; |
3ebcfb76 | 1055 | |
e7dda1ff VS |
1056 | int minWidth = GetMinWidth(), |
1057 | minHeight = GetMinHeight(); | |
1058 | ||
3ebcfb76 | 1059 | // but allow GetSizeHints() to set the min size |
e7dda1ff | 1060 | if ( minWidth != -1 ) |
3ebcfb76 | 1061 | { |
e7dda1ff | 1062 | info->ptMinTrackSize.x = minWidth; |
3ebcfb76 | 1063 | |
4f8090e0 | 1064 | processed = true; |
3ebcfb76 VZ |
1065 | } |
1066 | ||
e7dda1ff | 1067 | if ( minHeight != -1 ) |
3ebcfb76 | 1068 | { |
e7dda1ff | 1069 | info->ptMinTrackSize.y = minHeight; |
3ebcfb76 | 1070 | |
4f8090e0 | 1071 | processed = true; |
3ebcfb76 VZ |
1072 | } |
1073 | ||
4c9d78a4 | 1074 | return processed; |
3ebcfb76 VZ |
1075 | } |
1076 | ||
42e69d6b VZ |
1077 | // --------------------------------------------------------------------------- |
1078 | // MDI specific message translation/preprocessing | |
1079 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1080 | |
42e69d6b VZ |
1081 | long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam) |
1082 | { | |
1083 | return DefMDIChildProc(GetHwnd(), | |
1084 | (UINT)message, (WPARAM)wParam, (LPARAM)lParam); | |
1085 | } | |
1086 | ||
1087 | bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) | |
1088 | { | |
5a2762f0 | 1089 | return wxFrame::MSWTranslateMessage(msg); |
2bda0e17 KB |
1090 | } |
1091 | ||
42e69d6b VZ |
1092 | // --------------------------------------------------------------------------- |
1093 | // misc | |
1094 | // --------------------------------------------------------------------------- | |
1095 | ||
c2dcfdef | 1096 | void wxMDIChildFrame::MSWDestroyWindow() |
2bda0e17 | 1097 | { |
b3818fbe | 1098 | invalidHandle = GetHwnd(); |
2bda0e17 | 1099 | |
42e69d6b | 1100 | wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); |
2bda0e17 | 1101 | |
42e69d6b VZ |
1102 | // Must make sure this handle is invalidated (set to NULL) since all sorts |
1103 | // of things could happen after the child client is destroyed, but before | |
1104 | // the wxFrame is destroyed. | |
2bda0e17 | 1105 | |
42e69d6b | 1106 | HWND oldHandle = (HWND)GetHWND(); |
b3818fbe VZ |
1107 | SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY, |
1108 | (WPARAM)oldHandle, 0); | |
18d2e170 JS |
1109 | |
1110 | if (parent->GetActiveChild() == (wxMDIChildFrame*) NULL) | |
1111 | ResetWindowStyle((void*) NULL); | |
1112 | ||
42e69d6b | 1113 | invalidHandle = 0; |
2bda0e17 | 1114 | |
42e69d6b VZ |
1115 | if (m_hMenu) |
1116 | { | |
1117 | ::DestroyMenu((HMENU) m_hMenu); | |
1118 | m_hMenu = 0; | |
1119 | } | |
ac6482e0 | 1120 | wxRemoveHandleAssociation(this); |
42e69d6b | 1121 | m_hWnd = 0; |
2bda0e17 KB |
1122 | } |
1123 | ||
42e69d6b VZ |
1124 | // Change the client window's extended style so we don't get a client edge |
1125 | // style when a child is maximised (a double border looks silly.) | |
2bda0e17 KB |
1126 | bool wxMDIChildFrame::ResetWindowStyle(void *vrect) |
1127 | { | |
1128 | #if defined(__WIN95__) | |
1129 | RECT *rect = (RECT *)vrect; | |
c2dcfdef VZ |
1130 | wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent(); |
1131 | wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild(); | |
1132 | if (!pChild || (pChild == this)) | |
1133 | { | |
47ca6bfb | 1134 | HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow()); |
8082a771 VZ |
1135 | DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE); |
1136 | ||
1137 | // we want to test whether there is a maximized child, so just set | |
1138 | // dwThisStyle to 0 if there is no child at all | |
1139 | DWORD dwThisStyle = pChild | |
1f3943e0 | 1140 | ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0; |
c2dcfdef | 1141 | DWORD dwNewStyle = dwStyle; |
8082a771 | 1142 | if ( dwThisStyle & WS_MAXIMIZE ) |
c2dcfdef VZ |
1143 | dwNewStyle &= ~(WS_EX_CLIENTEDGE); |
1144 | else | |
1145 | dwNewStyle |= WS_EX_CLIENTEDGE; | |
1146 | ||
1147 | if (dwStyle != dwNewStyle) | |
1148 | { | |
47ca6bfb VZ |
1149 | // force update of everything |
1150 | ::RedrawWindow(hwndClient, NULL, NULL, | |
1151 | RDW_INVALIDATE | RDW_ALLCHILDREN); | |
1152 | ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle); | |
1153 | ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0, | |
42e69d6b VZ |
1154 | SWP_FRAMECHANGED | SWP_NOACTIVATE | |
1155 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | | |
1156 | SWP_NOCOPYBITS); | |
c2dcfdef | 1157 | if (rect) |
47ca6bfb | 1158 | ::GetClientRect(hwndClient, rect); |
2bda0e17 | 1159 | |
4f8090e0 | 1160 | return true; |
2bda0e17 | 1161 | } |
c2dcfdef | 1162 | } |
42e69d6b | 1163 | #endif // Win95 |
a23fd0e1 | 1164 | |
4f8090e0 | 1165 | return false; |
2bda0e17 KB |
1166 | } |
1167 | ||
42e69d6b VZ |
1168 | // =========================================================================== |
1169 | // wxMDIClientWindow: the window of predefined (by Windows) class which | |
1170 | // contains the child frames | |
1171 | // =========================================================================== | |
2bda0e17 | 1172 | |
debe6624 | 1173 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) |
2bda0e17 | 1174 | { |
a756f210 | 1175 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); |
2bda0e17 | 1176 | |
42e69d6b VZ |
1177 | CLIENTCREATESTRUCT ccs; |
1178 | m_windowStyle = style; | |
1179 | m_parent = parent; | |
c2dcfdef | 1180 | |
4e152a23 | 1181 | ccs.hWindowMenu = GetMDIWindowMenu(parent); |
42e69d6b | 1182 | ccs.idFirstChild = wxFIRST_MDI_CHILD; |
2bda0e17 | 1183 | |
5c44cd05 | 1184 | DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD | |
b0766406 JS |
1185 | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
1186 | ||
42e69d6b VZ |
1187 | if ( style & wxHSCROLL ) |
1188 | msStyle |= WS_HSCROLL; | |
1189 | if ( style & wxVSCROLL ) | |
1190 | msStyle |= WS_VSCROLL; | |
2bda0e17 KB |
1191 | |
1192 | #if defined(__WIN95__) | |
42e69d6b | 1193 | DWORD exStyle = WS_EX_CLIENTEDGE; |
2bda0e17 | 1194 | #else |
42e69d6b | 1195 | DWORD exStyle = 0; |
2bda0e17 KB |
1196 | #endif |
1197 | ||
b225f659 | 1198 | wxWindowCreationHook hook(this); |
42e69d6b VZ |
1199 | m_hWnd = (WXHWND)::CreateWindowEx |
1200 | ( | |
1201 | exStyle, | |
223d09f6 | 1202 | wxT("MDICLIENT"), |
42e69d6b VZ |
1203 | NULL, |
1204 | msStyle, | |
1205 | 0, 0, 0, 0, | |
1206 | GetWinHwnd(parent), | |
1207 | NULL, | |
1208 | wxGetInstance(), | |
1209 | (LPSTR)(LPCLIENTCREATESTRUCT)&ccs); | |
1210 | if ( !m_hWnd ) | |
1211 | { | |
f6bcfd97 | 1212 | wxLogLastError(wxT("CreateWindowEx(MDI client)")); |
2bda0e17 | 1213 | |
4f8090e0 | 1214 | return false; |
42e69d6b | 1215 | } |
2bda0e17 | 1216 | |
42e69d6b | 1217 | SubclassWin(m_hWnd); |
2bda0e17 | 1218 | |
4f8090e0 | 1219 | return true; |
2bda0e17 KB |
1220 | } |
1221 | ||
1222 | // Explicitly call default scroll behaviour | |
1223 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
1224 | { | |
1225 | // Note: for client windows, the scroll position is not set in | |
1226 | // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what | |
1227 | // scroll position we're at. | |
1228 | // This makes it hard to paint patterns or bitmaps in the background, | |
1229 | // and have the client area scrollable as well. | |
1230 | ||
1231 | if ( event.GetOrientation() == wxHORIZONTAL ) | |
1232 | m_scrollX = event.GetPosition(); // Always returns zero! | |
1233 | else | |
1234 | m_scrollY = event.GetPosition(); // Always returns zero! | |
1235 | ||
42e69d6b VZ |
1236 | event.Skip(); |
1237 | } | |
1238 | ||
ec06b234 JS |
1239 | void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
1240 | { | |
1241 | // Try to fix a problem whereby if you show an MDI child frame, then reposition the | |
1242 | // client area, you can end up with a non-refreshed portion in the client window | |
1243 | // (see OGL studio sample). So check if the position is changed and if so, | |
1244 | // redraw the MDI child frames. | |
1245 | ||
1246 | wxPoint oldPos = GetPosition(); | |
1247 | ||
1248 | wxWindow::DoSetSize(x, y, width, height, sizeFlags); | |
1249 | ||
1250 | wxPoint newPos = GetPosition(); | |
1251 | ||
1252 | if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y)) | |
1253 | { | |
1254 | if (GetParent()) | |
1255 | { | |
222ed1d6 | 1256 | wxWindowList::compatibility_iterator node = GetParent()->GetChildren().GetFirst(); |
ec06b234 JS |
1257 | while (node) |
1258 | { | |
d162a7ee | 1259 | wxWindow *child = node->GetData(); |
ec06b234 JS |
1260 | if (child->IsKindOf(CLASSINFO(wxMDIChildFrame))) |
1261 | { | |
d162a7ee VZ |
1262 | ::RedrawWindow(GetHwndOf(child), |
1263 | NULL, | |
1264 | NULL, | |
1265 | RDW_FRAME | | |
1266 | RDW_ALLCHILDREN | | |
1267 | RDW_INVALIDATE); | |
ec06b234 | 1268 | } |
4f8090e0 | 1269 | node = node->GetNext(); |
ec06b234 JS |
1270 | } |
1271 | } | |
1272 | } | |
1273 | } | |
1274 | ||
f6bcfd97 BP |
1275 | void wxMDIChildFrame::OnIdle(wxIdleEvent& event) |
1276 | { | |
1277 | // MDI child frames get their WM_SIZE when they're constructed but at this | |
1278 | // moment they don't have any children yet so all child windows will be | |
1279 | // positioned incorrectly when they are added later - to fix this, we | |
1280 | // generate an artificial size event here | |
1281 | if ( m_needsResize ) | |
1282 | { | |
4f8090e0 | 1283 | m_needsResize = false; // avoid any possibility of recursion |
f6bcfd97 BP |
1284 | |
1285 | SendSizeEvent(); | |
1286 | } | |
1287 | ||
1288 | event.Skip(); | |
1289 | } | |
1290 | ||
42e69d6b VZ |
1291 | // --------------------------------------------------------------------------- |
1292 | // non member functions | |
1293 | // --------------------------------------------------------------------------- | |
1294 | ||
1295 | static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow) | |
1296 | { | |
1297 | ::SendMessage(GetWinHwnd(win), WM_MDISETMENU, | |
1298 | #ifdef __WIN32__ | |
f6bcfd97 | 1299 | (WPARAM)hmenuFrame, (LPARAM)hmenuWindow |
42e69d6b | 1300 | #else |
f6bcfd97 | 1301 | 0, MAKELPARAM(hmenuFrame, hmenuWindow) |
42e69d6b | 1302 | #endif |
f6bcfd97 | 1303 | ); |
42e69d6b VZ |
1304 | |
1305 | // update menu bar of the parent window | |
1306 | wxWindow *parent = win->GetParent(); | |
223d09f6 | 1307 | wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") ); |
42e69d6b | 1308 | |
788722ac | 1309 | #ifndef __WIN16__ |
a967ef9d | 1310 | ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L); |
788722ac JS |
1311 | #endif |
1312 | ||
42e69d6b VZ |
1313 | ::DrawMenuBar(GetWinHwnd(parent)); |
1314 | } | |
1315 | ||
1316 | static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu) | |
1317 | { | |
1318 | // Try to insert Window menu in front of Help, otherwise append it. | |
1319 | HMENU hmenu = (HMENU)menu; | |
df61c009 JS |
1320 | |
1321 | if (subMenu) | |
1322 | { | |
4e152a23 | 1323 | int N = GetMenuItemCount(hmenu); |
4f8090e0 | 1324 | bool success = false; |
4e152a23 | 1325 | for ( int i = 0; i < N; i++ ) |
42e69d6b | 1326 | { |
4e152a23 VZ |
1327 | wxChar buf[256]; |
1328 | int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION); | |
1329 | if ( chars == 0 ) | |
1330 | { | |
1331 | wxLogLastError(wxT("GetMenuString")); | |
42e69d6b | 1332 | |
4e152a23 VZ |
1333 | continue; |
1334 | } | |
1335 | ||
1336 | if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) ) | |
1337 | { | |
4f8090e0 | 1338 | success = true; |
4e152a23 VZ |
1339 | ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING, |
1340 | (UINT)subMenu, _("&Window")); | |
1341 | break; | |
1342 | } | |
42e69d6b VZ |
1343 | } |
1344 | ||
4e152a23 | 1345 | if ( !success ) |
42e69d6b | 1346 | { |
4e152a23 | 1347 | ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window")); |
42e69d6b VZ |
1348 | } |
1349 | } | |
1350 | ||
42e69d6b VZ |
1351 | MDISetMenu(win, hmenu, subMenu); |
1352 | } | |
1353 | ||
df61c009 JS |
1354 | static void RemoveWindowMenu(wxWindow *win, WXHMENU menu) |
1355 | { | |
4e152a23 VZ |
1356 | HMENU hMenu = (HMENU)menu; |
1357 | ||
1358 | if ( hMenu ) | |
df61c009 | 1359 | { |
4e152a23 VZ |
1360 | wxChar buf[1024]; |
1361 | ||
1362 | int N = ::GetMenuItemCount(hMenu); | |
1363 | for ( int i = 0; i < N; i++ ) | |
df61c009 | 1364 | { |
4e152a23 VZ |
1365 | if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) ) |
1366 | { | |
2c62b3c3 VZ |
1367 | // Ignore successful read of menu string with length 0 which |
1368 | // occurs, for example, for a maximized MDI childs system menu | |
1369 | if ( ::GetLastError() != 0 ) | |
1370 | { | |
1371 | wxLogLastError(wxT("GetMenuString")); | |
1372 | } | |
df61c009 | 1373 | |
4e152a23 VZ |
1374 | continue; |
1375 | } | |
df61c009 | 1376 | |
4e152a23 VZ |
1377 | if ( wxStrcmp(buf, _("&Window")) == 0 ) |
1378 | { | |
1379 | if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) ) | |
1380 | { | |
1381 | wxLogLastError(wxT("RemoveMenu")); | |
1382 | } | |
1383 | ||
1384 | break; | |
1385 | } | |
df61c009 JS |
1386 | } |
1387 | } | |
1388 | ||
4e152a23 VZ |
1389 | if ( win ) |
1390 | { | |
1391 | // we don't change the windows menu, but we update the main one | |
1392 | MDISetMenu(win, hMenu, NULL); | |
1393 | } | |
df61c009 JS |
1394 | } |
1395 | ||
2917e920 BM |
1396 | static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
1397 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact) | |
42e69d6b VZ |
1398 | { |
1399 | #ifdef __WIN32__ | |
4f8090e0 | 1400 | *activate = true; |
42e69d6b VZ |
1401 | *hwndAct = (WXHWND)lParam; |
1402 | *hwndDeact = (WXHWND)wParam; | |
1403 | #else // Win16 | |
1404 | *activate = (WXWORD)wParam; | |
1405 | *hwndAct = (WXHWND)LOWORD(lParam); | |
1406 | *hwndDeact = (WXHWND)HIWORD(lParam); | |
1407 | #endif // Win32/Win16 | |
2bda0e17 | 1408 | } |
b9f933ab JS |
1409 | |
1410 | #endif | |
1411 | // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__) | |
1412 |