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