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