1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/dialog.h"
39 #include "wx/statusbr.h"
41 #include "wx/settings.h"
47 #include "wx/msw/private.h"
49 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
50 #include "wx/msw/statbr95.h"
54 #include "wx/toolbar.h"
55 #endif // wxUSE_TOOLBAR
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 extern wxWindowList wxModelessWindows
; // from dialog.cpp
64 extern wxMenu
*wxCurrentPopupMenu
;
66 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
67 extern const wxChar
*wxMDIChildFrameClassName
;
68 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
70 extern wxWindow
*wxWndHook
; // from window.cpp
72 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
73 extern void wxRemoveHandleAssociation(wxWindow
*win
);
75 static HWND invalidHandle
= 0;
77 // ---------------------------------------------------------------------------
79 // ---------------------------------------------------------------------------
81 static const int IDM_WINDOWTILE
= 4001;
82 static const int IDM_WINDOWTILEHOR
= 4001;
83 static const int IDM_WINDOWCASCADE
= 4002;
84 static const int IDM_WINDOWICONS
= 4003;
85 static const int IDM_WINDOWNEXT
= 4004;
86 static const int IDM_WINDOWTILEVERT
= 4005;
88 // This range gives a maximum of 500 MDI children. Should be enough :-)
89 static const int wxFIRST_MDI_CHILD
= 4100;
90 static const int wxLAST_MDI_CHILD
= 4600;
92 // Status border dimensions
93 static const int wxTHICK_LINE_BORDER
= 3;
94 static const int wxTHICK_LINE_WIDTH
= 1;
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
101 // of the parent of win (which is supposed to be the MDI client window)
102 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
104 // insert the window menu (subMenu) into menu just before "Help" submenu or at
105 // the very end if not found
106 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
108 // Remove the window menu
109 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
111 // is this an id of an MDI child?
112 inline bool IsMdiCommandId(int id
)
114 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
117 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
118 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
120 // ===========================================================================
122 // ===========================================================================
124 // ---------------------------------------------------------------------------
126 // ---------------------------------------------------------------------------
128 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
129 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
130 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
132 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
133 EVT_SIZE(wxMDIParentFrame::OnSize
)
134 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
137 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
138 EVT_IDLE(wxMDIChildFrame::OnIdle
)
141 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
142 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
145 // ===========================================================================
146 // wxMDIParentFrame: the frame which contains the client window which manages
148 // ===========================================================================
150 wxMDIParentFrame::wxMDIParentFrame()
152 m_clientWindow
= NULL
;
153 m_currentChild
= NULL
;
154 m_windowMenu
= (wxMenu
*) NULL
;
155 m_parentFrameActive
= TRUE
;
158 bool wxMDIParentFrame::Create(wxWindow
*parent
,
160 const wxString
& title
,
164 const wxString
& name
)
166 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
167 ? wxSTD_MDIPARENTFRAME_ICON
168 : wxDEFAULT_MDIPARENTFRAME_ICON
);
170 m_clientWindow
= NULL
;
171 m_currentChild
= NULL
;
173 // this style can be used to prevent a window from having the standard MDI
175 if ( style
& wxFRAME_NO_WINDOW_MENU
)
177 m_windowMenu
= (wxMenu
*)NULL
;
179 else // normal case: we have the window menu, so construct it
181 m_windowMenu
= new wxMenu
;
183 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
184 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
185 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
186 m_windowMenu
->AppendSeparator();
187 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
188 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
191 m_parentFrameActive
= TRUE
;
194 wxTopLevelWindows
.Append(this);
197 m_windowStyle
= style
;
199 if (parent
) parent
->AddChild(this);
204 m_windowId
= (int)NewControlId();
211 DWORD msflags
= WS_OVERLAPPED
;
212 if (style
& wxMINIMIZE_BOX
)
213 msflags
|= WS_MINIMIZEBOX
;
214 if (style
& wxMAXIMIZE_BOX
)
215 msflags
|= WS_MAXIMIZEBOX
;
216 if (style
& wxTHICK_FRAME
)
217 msflags
|= WS_THICKFRAME
;
218 if (style
& wxSYSTEM_MENU
)
219 msflags
|= WS_SYSMENU
;
220 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
221 msflags
|= WS_MINIMIZE
;
222 if (style
& wxMAXIMIZE
)
223 msflags
|= WS_MAXIMIZE
;
224 if (style
& wxCAPTION
)
225 msflags
|= WS_CAPTION
;
227 if (style
& wxCLIP_CHILDREN
)
228 msflags
|= WS_CLIPCHILDREN
;
230 if ( !wxWindow::MSWCreate(m_windowId
,
241 wxModelessWindows
.Append(this);
243 // unlike (almost?) all other windows, frames are created hidden
249 wxMDIParentFrame::~wxMDIParentFrame()
252 // already delete by DestroyChildren()
253 m_frameToolBar
= NULL
;
254 m_frameStatusBar
= NULL
;
256 // ::DestroyMenu((HMENU)m_windowMenu);
260 m_windowMenu
= (wxMenu
*) NULL
;
263 if ( m_clientWindow
)
265 if ( m_clientWindow
->MSWGetOldWndProc() )
266 m_clientWindow
->UnsubclassWin();
268 m_clientWindow
->SetHWND(0);
269 delete m_clientWindow
;
273 void wxMDIParentFrame::InternalSetMenuBar()
275 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
277 m_parentFrameActive
= TRUE
;
279 HMENU subMenu
= (HMENU
) 0;
281 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
283 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
286 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
292 // Remove old window menu
293 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
297 m_windowMenu
= (wxMenu
*) NULL
;
304 InsertWindowMenu(GetClientWindow(), m_hMenu
,
305 GetHmenuOf(m_windowMenu
));
310 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
312 if ( GetClientWindow() )
315 GetClientSize(&width
, &height
);
317 GetClientWindow()->SetSize(0, 0, width
, height
);
321 // Returns the active MDI child window
322 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
324 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
325 WM_MDIGETACTIVE
, 0, 0L);
329 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
332 // Create the client window class (don't Create the window, just return a new
334 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
336 return new wxMDIClientWindow
;
339 // Responds to colour changes, and passes event on to children.
340 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
342 if ( m_clientWindow
)
344 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
345 m_clientWindow
->Refresh();
351 // ---------------------------------------------------------------------------
353 // ---------------------------------------------------------------------------
355 void wxMDIParentFrame::Cascade()
357 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
360 // TODO: add a direction argument (hor/vert)
361 void wxMDIParentFrame::Tile()
363 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
366 void wxMDIParentFrame::ArrangeIcons()
368 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
371 void wxMDIParentFrame::ActivateNext()
373 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
376 void wxMDIParentFrame::ActivatePrevious()
378 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
381 // ---------------------------------------------------------------------------
382 // the MDI parent frame window proc
383 // ---------------------------------------------------------------------------
385 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
390 bool processed
= FALSE
;
396 WXWORD state
, minimized
;
398 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
400 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
408 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
410 (void)HandleCommand(id
, cmd
, hwnd
);
412 // even if the frame didn't process it, there is no need to try it
413 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
414 // so pretend we processed the message anyhow
418 // always pass this message DefFrameProc(), otherwise MDI menu
419 // commands (and sys commands - more surprizingly!) won't work
420 MSWDefWindowProc(message
, wParam
, lParam
);
424 m_clientWindow
= OnCreateClient();
425 // Uses own style for client style
426 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
428 wxLogMessage(_("Failed to create MDI parent frame."));
439 // we erase background ourselves
447 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
449 if ( m_parentFrameActive
)
451 processed
= HandleMenuSelect(item
, flags
, hmenu
);
453 else if (m_currentChild
)
455 processed
= m_currentChild
->
456 HandleMenuSelect(item
, flags
, hmenu
);
462 // as we don't (usually) resize the MDI client to exactly fit the
463 // client area (we put it below the toolbar, above statusbar &c),
464 // we should not pass this one to DefFrameProc
469 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
474 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
476 bool processed
= FALSE
;
478 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
484 // If this window is an MDI parent, we must also send an OnActivate message
485 // to the current child.
486 if ( (m_currentChild
!= NULL
) &&
487 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
489 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
490 event
.SetEventObject( m_currentChild
);
491 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
498 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
500 // In case it's e.g. a toolbar.
503 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
505 return win
->MSWCommand(cmd
, id
);
508 // is it one of standard MDI commands?
513 case IDM_WINDOWCASCADE
:
515 wParam
= MDITILE_SKIPDISABLED
;
518 case IDM_WINDOWTILEHOR
:
519 wParam
|= MDITILE_HORIZONTAL
;
522 case IDM_WINDOWTILEVERT
:
524 wParam
= MDITILE_VERTICAL
;
526 wParam
|= MDITILE_SKIPDISABLED
;
529 case IDM_WINDOWICONS
:
530 msg
= WM_MDIICONARRANGE
;
543 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
548 // FIXME VZ: what does this test do??
551 return FALSE
; // Get WndProc to call default proc
554 if ( IsMdiCommandId(id
) )
556 wxWindowList::Node
* node
= GetChildren().GetFirst();
559 wxWindow
* child
= node
->GetData();
560 if ( child
->GetHWND() )
562 long childId
= wxGetWindowId(child
->GetHWND());
563 if (childId
== (long)id
)
565 ::SendMessage( GetWinHwnd(GetClientWindow()),
567 (WPARAM
)child
->GetHWND(), 0);
571 node
= node
->GetNext();
574 else if ( m_parentFrameActive
)
576 return ProcessCommand(id
);
578 else if ( m_currentChild
)
580 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
584 // this shouldn't happen because it means that our messages are being
585 // lost (they're not sent to the parent frame nor to the children)
586 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
592 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
597 if ( GetClientWindow() )
598 clientWnd
= GetClientWindow()->GetHWND();
602 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
605 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
607 MSG
*pMsg
= (MSG
*)msg
;
609 // first let the current child get it
610 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
611 m_currentChild
->MSWTranslateMessage(msg
) )
616 // then try out accel table (will also check the menu accels)
617 if ( wxFrame::MSWTranslateMessage(msg
) )
622 // finally, check for MDI specific built in accel keys
623 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
625 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
632 // ===========================================================================
634 // ===========================================================================
636 void wxMDIChildFrame::Init()
638 m_needsResize
= TRUE
;
641 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
643 const wxString
& title
,
647 const wxString
& name
)
649 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
650 : wxDEFAULT_MDICHILDFRAME_ICON
);
653 wxWindowBase::Show(TRUE
); // MDI child frame starts off shown
658 m_windowId
= (int)NewControlId();
662 parent
->AddChild(this);
674 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
675 ? wxMDIChildFrameClassNameNoRedraw
676 : wxMDIChildFrameClassName
;
678 mcs
.hOwner
= wxGetInstance();
682 mcs
.x
= CW_USEDEFAULT
;
687 mcs
.y
= CW_USEDEFAULT
;
692 mcs
.cx
= CW_USEDEFAULT
;
697 mcs
.cy
= CW_USEDEFAULT
;
699 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_THICKFRAME
| WS_VISIBLE
;
700 if (style
& wxMINIMIZE_BOX
)
701 msflags
|= WS_MINIMIZEBOX
;
702 if (style
& wxMAXIMIZE_BOX
)
703 msflags
|= WS_MAXIMIZEBOX
;
704 if (style
& wxTHICK_FRAME
)
705 msflags
|= WS_THICKFRAME
;
706 if (style
& wxSYSTEM_MENU
)
707 msflags
|= WS_SYSMENU
;
708 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
709 msflags
|= WS_MINIMIZE
;
710 if (style
& wxMAXIMIZE
)
711 msflags
|= WS_MAXIMIZE
;
712 if (style
& wxCAPTION
)
713 msflags
|= WS_CAPTION
;
719 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
720 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
723 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
725 // VZ: what's this? an act of piracy?
726 //SetWindowLong(GetHwnd(), 0, (long)this);
728 wxModelessWindows
.Append(this);
733 wxMDIChildFrame::~wxMDIChildFrame()
737 // already delete by DestroyChildren()
738 m_frameToolBar
= NULL
;
739 m_frameStatusBar
= NULL
;
744 // Set the client size (i.e. leave the calculation of borders etc.
746 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
748 HWND hWnd
= GetHwnd();
751 ::GetClientRect(hWnd
, &rect
);
754 GetWindowRect(hWnd
, &rect2
);
756 // Find the difference between the entire window (title bar and all)
757 // and the client area; add this to the new client size to move the
759 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
760 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
762 if (GetStatusBar() && GetStatusBar()->IsShown())
765 GetStatusBar()->GetSize(&sx
, &sy
);
770 point
.x
= rect2
.left
;
773 // If there's an MDI parent, must subtract the parent's top left corner
774 // since MoveWindow moves relative to the parent
775 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
776 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
778 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
780 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
781 event
.SetEventObject( this );
782 GetEventHandler()->ProcessEvent(event
);
785 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
788 GetWindowRect(GetHwnd(), &rect
);
793 // Since we now have the absolute screen coords,
794 // if there's a parent we must subtract its top left corner
795 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
796 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
802 void wxMDIChildFrame::InternalSetMenuBar()
804 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
806 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
807 HMENU subMenu
= (HMENU
) 0;
808 if (parent
->GetWindowMenu())
809 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
811 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
813 parent
->m_parentFrameActive
= FALSE
;
816 // ---------------------------------------------------------------------------
818 // ---------------------------------------------------------------------------
820 void wxMDIChildFrame::Maximize(bool maximize
)
822 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
823 if ( parent
&& parent
->GetClientWindow() )
825 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
826 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
827 (WPARAM
)GetHwnd(), 0);
831 void wxMDIChildFrame::Restore()
833 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
834 if ( parent
&& parent
->GetClientWindow() )
836 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
837 (WPARAM
) GetHwnd(), 0);
841 void wxMDIChildFrame::Activate()
843 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
844 if ( parent
&& parent
->GetClientWindow() )
846 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
847 (WPARAM
) GetHwnd(), 0);
851 // ---------------------------------------------------------------------------
852 // MDI window proc and message handlers
853 // ---------------------------------------------------------------------------
855 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
860 bool processed
= FALSE
;
868 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
871 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
875 case WM_GETMINMAXINFO
:
876 // let the default window proc calculate the size of MDI children
877 // frames because it is based on the size of the MDI client window,
878 // not on the values specified in wxWindow m_min/max variables
879 return MSWDefWindowProc(message
, wParam
, lParam
);
884 WXHWND hwndAct
, hwndDeact
;
885 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
887 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
892 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
893 // scrollbars if necessary
898 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
900 MSWDefWindowProc(message
, wParam
, lParam
);
904 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
905 // the message (the base class version does not)
906 return MSWDefWindowProc(message
, wParam
, lParam
);
908 case WM_WINDOWPOSCHANGING
:
909 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
914 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
919 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
921 // In case it's e.g. a toolbar.
924 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
926 return win
->MSWCommand(cmd
, id
);
929 if (wxCurrentPopupMenu
)
931 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
932 wxCurrentPopupMenu
= NULL
;
933 if (popupMenu
->MSWCommand(cmd
, id
))
938 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
940 processed
= ProcessCommand(id
);
950 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
954 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
960 if ( m_hWnd
== hwndAct
)
963 parent
->m_currentChild
= this;
965 HMENU child_menu
= (HMENU
)GetWinMenu();
968 parent
->m_parentFrameActive
= FALSE
;
970 menuToSet
= child_menu
;
973 else if ( m_hWnd
== hwndDeact
)
975 wxASSERT_MSG( parent
->m_currentChild
== this,
976 wxT("can't deactivate MDI child which wasn't active!") );
979 parent
->m_currentChild
= NULL
;
981 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
984 parent
->m_parentFrameActive
= TRUE
;
986 menuToSet
= parent_menu
;
991 // we have nothing to do with it
997 HMENU subMenu
= (HMENU
) 0;
998 if (parent
->GetWindowMenu())
999 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1001 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
1004 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1005 event
.SetEventObject( this );
1007 ResetWindowStyle((void *)NULL
);
1009 return GetEventHandler()->ProcessEvent(event
);
1012 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1014 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1015 #if defined(__WIN95__)
1016 if (!(lpPos
->flags
& SWP_NOSIZE
))
1019 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1020 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1021 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1023 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1024 lpPos
->x
= rectClient
.left
;
1025 lpPos
->y
= rectClient
.top
;
1026 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1027 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1029 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1030 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1032 pFrameWnd
->GetToolBar()->Refresh();
1040 // ---------------------------------------------------------------------------
1041 // MDI specific message translation/preprocessing
1042 // ---------------------------------------------------------------------------
1044 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1046 return DefMDIChildProc(GetHwnd(),
1047 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1050 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1052 return wxFrame::MSWTranslateMessage(msg
);
1055 // ---------------------------------------------------------------------------
1057 // ---------------------------------------------------------------------------
1059 void wxMDIChildFrame::MSWDestroyWindow()
1061 MSWDetachWindowMenu();
1062 invalidHandle
= GetHwnd();
1064 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1066 // Must make sure this handle is invalidated (set to NULL) since all sorts
1067 // of things could happen after the child client is destroyed, but before
1068 // the wxFrame is destroyed.
1070 HWND oldHandle
= (HWND
)GetHWND();
1071 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1072 (WPARAM
)oldHandle
, 0);
1074 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1075 ResetWindowStyle((void*) NULL
);
1081 ::DestroyMenu((HMENU
) m_hMenu
);
1084 wxRemoveHandleAssociation(this);
1088 // Change the client window's extended style so we don't get a client edge
1089 // style when a child is maximised (a double border looks silly.)
1090 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1092 #if defined(__WIN95__)
1093 RECT
*rect
= (RECT
*)vrect
;
1094 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1095 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1096 if (!pChild
|| (pChild
== this))
1098 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1099 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1101 // we want to test whether there is a maximized child, so just set
1102 // dwThisStyle to 0 if there is no child at all
1103 DWORD dwThisStyle
= pChild
1104 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1105 DWORD dwNewStyle
= dwStyle
;
1106 if ( dwThisStyle
& WS_MAXIMIZE
)
1107 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1109 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1111 if (dwStyle
!= dwNewStyle
)
1113 // force update of everything
1114 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1115 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1116 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1117 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1118 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1119 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1122 ::GetClientRect(hwndClient
, rect
);
1132 // ===========================================================================
1133 // wxMDIClientWindow: the window of predefined (by Windows) class which
1134 // contains the child frames
1135 // ===========================================================================
1137 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1139 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1141 CLIENTCREATESTRUCT ccs
;
1142 m_windowStyle
= style
;
1145 ccs
.hWindowMenu
= (HMENU
) 0;
1146 if (parent
->GetWindowMenu())
1147 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1148 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1150 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1151 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1153 if ( style
& wxHSCROLL
)
1154 msStyle
|= WS_HSCROLL
;
1155 if ( style
& wxVSCROLL
)
1156 msStyle
|= WS_VSCROLL
;
1158 #if defined(__WIN95__)
1159 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1165 m_hWnd
= (WXHWND
)::CreateWindowEx
1175 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1178 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1183 SubclassWin(m_hWnd
);
1189 // Explicitly call default scroll behaviour
1190 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1192 // Note: for client windows, the scroll position is not set in
1193 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1194 // scroll position we're at.
1195 // This makes it hard to paint patterns or bitmaps in the background,
1196 // and have the client area scrollable as well.
1198 if ( event
.GetOrientation() == wxHORIZONTAL
)
1199 m_scrollX
= event
.GetPosition(); // Always returns zero!
1201 m_scrollY
= event
.GetPosition(); // Always returns zero!
1206 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1208 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1209 // client area, you can end up with a non-refreshed portion in the client window
1210 // (see OGL studio sample). So check if the position is changed and if so,
1211 // redraw the MDI child frames.
1213 wxPoint oldPos
= GetPosition();
1215 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1217 wxPoint newPos
= GetPosition();
1219 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1223 wxNode
* node
= GetParent()->GetChildren().First();
1226 wxWindow
* child
= (wxWindow
*) node
->Data();
1227 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1229 HWND hWnd
= (HWND
) child
->GetHWND();
1230 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1232 node
= node
->Next();
1238 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1240 // MDI child frames get their WM_SIZE when they're constructed but at this
1241 // moment they don't have any children yet so all child windows will be
1242 // positioned incorrectly when they are added later - to fix this, we
1243 // generate an artificial size event here
1244 if ( m_needsResize
)
1246 m_needsResize
= FALSE
; // avoid any possibility of recursion
1254 // ---------------------------------------------------------------------------
1255 // non member functions
1256 // ---------------------------------------------------------------------------
1258 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1260 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1262 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1264 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1268 // update menu bar of the parent window
1269 wxWindow
*parent
= win
->GetParent();
1270 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1273 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1276 ::DrawMenuBar(GetWinHwnd(parent
));
1279 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1281 // Try to insert Window menu in front of Help, otherwise append it.
1282 HMENU hmenu
= (HMENU
)menu
;
1286 int N
= GetMenuItemCount(hmenu
);
1287 bool success
= FALSE
;
1288 for ( int i
= 0; i
< N
; i
++ )
1291 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1294 wxLogLastError(wxT("GetMenuString"));
1299 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1302 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1303 (UINT
)subMenu
, _("&Window"));
1310 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1314 MDISetMenu(win
, hmenu
, subMenu
);
1317 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1319 // Try to insert Window menu in front of Help, otherwise append it.
1320 HMENU hmenu
= (HMENU
)menu
;
1321 int N
= GetMenuItemCount(hmenu
);
1322 for ( int i
= 0; i
< N
; i
++ )
1325 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1328 wxLogLastError(wxT("GetMenuString"));
1333 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Window")) )
1335 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1340 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1341 MDISetMenu(win
, hmenu
, 0);
1344 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1345 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1349 *hwndAct
= (WXHWND
)lParam
;
1350 *hwndDeact
= (WXHWND
)wParam
;
1352 *activate
= (WXWORD
)wParam
;
1353 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1354 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1355 #endif // Win32/Win16