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