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