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