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