1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_MDI && !defined(__WXUNIVERSAL__)
39 #include "wx/dialog.h"
41 #include "wx/statusbr.h"
43 #include "wx/settings.h"
49 #include "wx/msw/private.h"
51 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
52 #include "wx/msw/statbr95.h"
56 #include "wx/toolbar.h"
57 #endif // wxUSE_TOOLBAR
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 extern wxMenu
*wxCurrentPopupMenu
;
67 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
68 extern const wxChar
*wxMDIChildFrameClassName
;
69 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
70 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
71 extern void wxRemoveHandleAssociation(wxWindow
*win
);
73 static HWND invalidHandle
= 0;
75 // ---------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------
79 static const int IDM_WINDOWTILEHOR
= 4001;
80 static const int IDM_WINDOWCASCADE
= 4002;
81 static const int IDM_WINDOWICONS
= 4003;
82 static const int IDM_WINDOWNEXT
= 4004;
83 static const int IDM_WINDOWTILEVERT
= 4005;
84 static const int IDM_WINDOWPREV
= 4006;
86 // This range gives a maximum of 500 MDI children. Should be enough :-)
87 static const int wxFIRST_MDI_CHILD
= 4100;
88 static const int wxLAST_MDI_CHILD
= 4600;
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
95 // of the parent of win (which is supposed to be the MDI client window)
96 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
98 // insert the window menu (subMenu) into menu just before "Help" submenu or at
99 // the very end if not found
100 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
102 // Remove the window menu
103 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
105 // is this an id of an MDI child?
106 inline bool IsMdiCommandId(int id
)
108 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
111 // unpack the parameters of WM_MDIACTIVATE message
112 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
113 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
115 // return the HMENU of the MDI menu
116 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
118 wxMenu
*menu
= frame
->GetWindowMenu();
119 return menu
? GetHmenuOf(menu
) : 0;
122 // ===========================================================================
124 // ===========================================================================
126 // ---------------------------------------------------------------------------
128 // ---------------------------------------------------------------------------
130 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
131 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
132 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
134 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
135 EVT_SIZE(wxMDIParentFrame::OnSize
)
136 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
139 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
140 EVT_IDLE(wxMDIChildFrame::OnIdle
)
143 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
144 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
147 // ===========================================================================
148 // wxMDIParentFrame: the frame which contains the client window which manages
150 // ===========================================================================
152 wxMDIParentFrame::wxMDIParentFrame()
154 m_clientWindow
= NULL
;
155 m_currentChild
= NULL
;
156 m_windowMenu
= (wxMenu
*) NULL
;
157 m_parentFrameActive
= true;
160 bool wxMDIParentFrame::Create(wxWindow
*parent
,
162 const wxString
& title
,
166 const wxString
& name
)
168 m_clientWindow
= NULL
;
169 m_currentChild
= NULL
;
171 // this style can be used to prevent a window from having the standard MDI
173 if ( style
& wxFRAME_NO_WINDOW_MENU
)
175 m_windowMenu
= (wxMenu
*)NULL
;
177 else // normal case: we have the window menu, so construct it
179 m_windowMenu
= new wxMenu
;
181 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
182 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
183 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
184 m_windowMenu
->AppendSeparator();
185 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
186 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
187 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
190 m_parentFrameActive
= true;
193 wxTopLevelWindows
.Append(this);
196 m_windowStyle
= style
;
199 parent
->AddChild(this);
201 if ( id
!= wxID_ANY
)
204 m_windowId
= NewControlId();
207 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
208 msflags
&= ~WS_VSCROLL
;
209 msflags
&= ~WS_HSCROLL
;
211 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
220 // unlike (almost?) all other windows, frames are created hidden
226 wxMDIParentFrame::~wxMDIParentFrame()
228 // see comment in ~wxMDIChildFrame
230 m_frameToolBar
= NULL
;
233 m_frameStatusBar
= NULL
;
234 #endif // wxUSE_STATUSBAR
241 m_windowMenu
= (wxMenu
*) NULL
;
244 // the MDI frame menubar is not automatically deleted by Windows unlike for
248 ::DestroyMenu((HMENU
)m_hMenu
);
249 m_hMenu
= (WXHMENU
)NULL
;
252 if ( m_clientWindow
)
254 if ( m_clientWindow
->MSWGetOldWndProc() )
255 m_clientWindow
->UnsubclassWin();
257 m_clientWindow
->SetHWND(0);
258 delete m_clientWindow
;
262 #if wxUSE_MENUS_NATIVE
264 void wxMDIParentFrame::InternalSetMenuBar()
266 m_parentFrameActive
= true;
268 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
271 #endif // wxUSE_MENUS_NATIVE
273 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
279 // Remove old window menu
280 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
284 m_windowMenu
= (wxMenu
*) NULL
;
292 InsertWindowMenu(GetClientWindow(), m_hMenu
,
293 GetHmenuOf(m_windowMenu
));
298 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
300 wxMDIChildFrame
*child
= GetActiveChild();
303 wxEvtHandler
* source
= child
->GetEventHandler();
304 wxMenuBar
* bar
= child
->GetMenuBar();
308 menu
->UpdateUI(source
);
314 int nCount
= bar
->GetMenuCount();
315 for (int n
= 0; n
< nCount
; n
++)
316 bar
->GetMenu(n
)->UpdateUI(source
);
322 wxFrameBase::DoMenuUpdates(menu
);
326 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
328 if ( GetClientWindow() )
331 GetClientSize(&width
, &height
);
333 GetClientWindow()->SetSize(0, 0, width
, height
);
337 // Returns the active MDI child window
338 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
340 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
341 WM_MDIGETACTIVE
, 0, 0L);
345 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
348 // Create the client window class (don't Create the window, just return a new
350 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
352 return new wxMDIClientWindow
;
355 // Responds to colour changes, and passes event on to children.
356 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
358 if ( m_clientWindow
)
360 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
361 m_clientWindow
->Refresh();
367 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
369 // we don't have any standard icons (any more)
373 // ---------------------------------------------------------------------------
375 // ---------------------------------------------------------------------------
377 void wxMDIParentFrame::Cascade()
379 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
382 void wxMDIParentFrame::Tile(wxOrientation orient
)
384 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
385 _T("invalid orientation value") );
387 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
388 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
389 : MDITILE_VERTICAL
, 0);
392 void wxMDIParentFrame::ArrangeIcons()
394 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
397 void wxMDIParentFrame::ActivateNext()
399 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
402 void wxMDIParentFrame::ActivatePrevious()
404 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
407 // ---------------------------------------------------------------------------
408 // the MDI parent frame window proc
409 // ---------------------------------------------------------------------------
411 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
416 bool processed
= false;
422 WXWORD state
, minimized
;
424 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
426 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
434 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
436 (void)HandleCommand(id
, cmd
, hwnd
);
438 // even if the frame didn't process it, there is no need to try it
439 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
440 // so pretend we processed the message anyhow
444 // always pass this message DefFrameProc(), otherwise MDI menu
445 // commands (and sys commands - more surprisingly!) won't work
446 MSWDefWindowProc(message
, wParam
, lParam
);
450 m_clientWindow
= OnCreateClient();
451 // Uses own style for client style
452 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
454 wxLogMessage(_("Failed to create MDI parent frame."));
465 // we erase background ourselves
473 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
475 if ( m_parentFrameActive
)
477 processed
= HandleMenuSelect(item
, flags
, hmenu
);
479 else if (m_currentChild
)
481 processed
= m_currentChild
->
482 HandleMenuSelect(item
, flags
, hmenu
);
488 // though we don't (usually) resize the MDI client to exactly fit the
489 // client area we need to pass this one to DefFrameProc to allow the children to show
494 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
499 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
501 bool processed
= false;
503 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
509 // If this window is an MDI parent, we must also send an OnActivate message
510 // to the current child.
511 if ( (m_currentChild
!= NULL
) &&
512 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
514 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
515 event
.SetEventObject( m_currentChild
);
516 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
523 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
525 // In case it's e.g. a toolbar.
528 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
530 return win
->MSWCommand(cmd
, id
);
533 // is it one of standard MDI commands?
539 case IDM_WINDOWCASCADE
:
541 wParam
= MDITILE_SKIPDISABLED
;
544 case IDM_WINDOWTILEHOR
:
545 wParam
|= MDITILE_HORIZONTAL
;
548 case IDM_WINDOWTILEVERT
:
550 wParam
= MDITILE_VERTICAL
;
552 wParam
|= MDITILE_SKIPDISABLED
;
555 case IDM_WINDOWICONS
:
556 msg
= WM_MDIICONARRANGE
;
561 lParam
= 0; // next child
566 lParam
= 1; // previous child
575 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
580 // FIXME VZ: what does this test do??
583 return false; // Get WndProc to call default proc
586 if ( IsMdiCommandId(id
) )
588 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
591 wxWindow
*child
= node
->GetData();
592 if ( child
->GetHWND() )
594 long childId
= wxGetWindowId(child
->GetHWND());
595 if (childId
== (long)id
)
597 ::SendMessage( GetWinHwnd(GetClientWindow()),
599 (WPARAM
)child
->GetHWND(), 0);
603 node
= node
->GetNext();
606 else if ( m_parentFrameActive
)
608 return ProcessCommand(id
);
610 else if ( m_currentChild
)
612 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
616 // this shouldn't happen because it means that our messages are being
617 // lost (they're not sent to the parent frame nor to the children)
618 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
624 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
629 if ( GetClientWindow() )
630 clientWnd
= GetClientWindow()->GetHWND();
634 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
637 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
639 MSG
*pMsg
= (MSG
*)msg
;
641 // first let the current child get it
642 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
643 m_currentChild
->MSWTranslateMessage(msg
) )
648 // then try out accel table (will also check the menu accels)
649 if ( wxFrame::MSWTranslateMessage(msg
) )
654 // finally, check for MDI specific built in accel keys
655 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
657 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
664 // ===========================================================================
666 // ===========================================================================
668 void wxMDIChildFrame::Init()
670 m_needsResize
= true;
671 m_needsInitialShow
= true;
674 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
676 const wxString
& title
,
680 const wxString
& name
)
684 if ( id
!= wxID_ANY
)
687 m_windowId
= (int)NewControlId();
691 parent
->AddChild(this);
701 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
702 ? wxMDIChildFrameClassName
703 : wxMDIChildFrameClassNameNoRedraw
;
705 mcs
.hOwner
= wxGetInstance();
706 if (x
!= wxDefaultCoord
)
709 mcs
.x
= CW_USEDEFAULT
;
711 if (y
!= wxDefaultCoord
)
714 mcs
.y
= CW_USEDEFAULT
;
716 if (width
!= wxDefaultCoord
)
719 mcs
.cx
= CW_USEDEFAULT
;
721 if (height
!= wxDefaultCoord
)
724 mcs
.cy
= CW_USEDEFAULT
;
726 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
727 if (style
& wxMINIMIZE_BOX
)
728 msflags
|= WS_MINIMIZEBOX
;
729 if (style
& wxMAXIMIZE_BOX
)
730 msflags
|= WS_MAXIMIZEBOX
;
731 if (style
& wxTHICK_FRAME
)
732 msflags
|= WS_THICKFRAME
;
733 if (style
& wxSYSTEM_MENU
)
734 msflags
|= WS_SYSMENU
;
735 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
736 msflags
|= WS_MINIMIZE
;
737 if (style
& wxMAXIMIZE
)
738 msflags
|= WS_MAXIMIZE
;
739 if (style
& wxCAPTION
)
740 msflags
|= WS_CAPTION
;
746 wxWindowCreationHook
hook(this);
748 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
749 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
751 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
756 wxMDIChildFrame::~wxMDIChildFrame()
758 // will be destroyed by DestroyChildren() but reset them before calling it
759 // to avoid using dangling pointers if a callback comes in the meanwhile
761 m_frameToolBar
= NULL
;
764 m_frameStatusBar
= NULL
;
765 #endif // wxUSE_STATUSBAR
769 RemoveWindowMenu(NULL
, m_hMenu
);
774 bool wxMDIChildFrame::Show(bool show
)
776 m_needsInitialShow
= false;
777 return wxFrame::Show(show
);
780 // Set the client size (i.e. leave the calculation of borders etc.
782 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
784 HWND hWnd
= GetHwnd();
787 ::GetClientRect(hWnd
, &rect
);
790 GetWindowRect(hWnd
, &rect2
);
792 // Find the difference between the entire window (title bar and all)
793 // and the client area; add this to the new client size to move the
795 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
796 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
799 if (GetStatusBar() && GetStatusBar()->IsShown())
802 GetStatusBar()->GetSize(&sx
, &sy
);
805 #endif // wxUSE_STATUSBAR
808 point
.x
= rect2
.left
;
811 // If there's an MDI parent, must subtract the parent's top left corner
812 // since MoveWindow moves relative to the parent
813 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
814 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
816 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
818 wxSize
size(width
, height
);
819 wxSizeEvent
event(size
, m_windowId
);
820 event
.SetEventObject( this );
821 GetEventHandler()->ProcessEvent(event
);
824 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
827 GetWindowRect(GetHwnd(), &rect
);
832 // Since we now have the absolute screen coords,
833 // if there's a parent we must subtract its top left corner
834 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
835 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
843 void wxMDIChildFrame::InternalSetMenuBar()
845 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
847 InsertWindowMenu(parent
->GetClientWindow(),
848 m_hMenu
, GetMDIWindowMenu(parent
));
850 parent
->m_parentFrameActive
= false;
853 void wxMDIChildFrame::DetachMenuBar()
855 RemoveWindowMenu(NULL
, m_hMenu
);
856 wxFrame::DetachMenuBar();
859 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
861 // we don't have any standard icons (any more)
865 // ---------------------------------------------------------------------------
867 // ---------------------------------------------------------------------------
869 void wxMDIChildFrame::Maximize(bool maximize
)
871 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
872 if ( parent
&& parent
->GetClientWindow() )
874 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
875 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
876 (WPARAM
)GetHwnd(), 0);
880 void wxMDIChildFrame::Restore()
882 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
883 if ( parent
&& parent
->GetClientWindow() )
885 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
886 (WPARAM
) GetHwnd(), 0);
890 void wxMDIChildFrame::Activate()
892 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
893 if ( parent
&& parent
->GetClientWindow() )
895 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
896 (WPARAM
) GetHwnd(), 0);
900 // ---------------------------------------------------------------------------
901 // MDI window proc and message handlers
902 // ---------------------------------------------------------------------------
904 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
909 bool processed
= false;
917 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
920 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
924 case WM_GETMINMAXINFO
:
925 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
931 WXHWND hwndAct
, hwndDeact
;
932 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
934 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
939 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
940 // scrollbars if necessary
945 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
947 MSWDefWindowProc(message
, wParam
, lParam
);
951 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
952 // the message (the base class version does not)
953 return MSWDefWindowProc(message
, wParam
, lParam
);
955 case WM_WINDOWPOSCHANGING
:
956 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
961 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
966 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
968 // In case it's e.g. a toolbar.
971 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
973 return win
->MSWCommand(cmd
, id
);
976 if (wxCurrentPopupMenu
)
978 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
979 wxCurrentPopupMenu
= NULL
;
980 if (popupMenu
->MSWCommand(cmd
, id
))
985 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
987 processed
= ProcessCommand(id
);
997 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
1001 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1003 HMENU menuToSet
= 0;
1007 if ( m_hWnd
== hwndAct
)
1010 parent
->m_currentChild
= this;
1012 HMENU child_menu
= (HMENU
)GetWinMenu();
1015 parent
->m_parentFrameActive
= false;
1017 menuToSet
= child_menu
;
1020 else if ( m_hWnd
== hwndDeact
)
1022 wxASSERT_MSG( parent
->m_currentChild
== this,
1023 wxT("can't deactivate MDI child which wasn't active!") );
1026 parent
->m_currentChild
= NULL
;
1028 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1030 // activate the the parent menu only when there is no other child
1031 // that has been activated
1032 if ( parent_menu
&& !hwndAct
)
1034 parent
->m_parentFrameActive
= true;
1036 menuToSet
= parent_menu
;
1041 // we have nothing to do with it
1047 MDISetMenu(parent
->GetClientWindow(),
1048 menuToSet
, GetMDIWindowMenu(parent
));
1051 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1052 event
.SetEventObject( this );
1054 ResetWindowStyle((void *)NULL
);
1056 return GetEventHandler()->ProcessEvent(event
);
1059 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1061 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1062 #if defined(__WIN95__)
1063 if (!(lpPos
->flags
& SWP_NOSIZE
))
1066 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1067 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1068 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1070 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1071 lpPos
->x
= rectClient
.left
;
1072 lpPos
->y
= rectClient
.top
;
1073 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1074 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1077 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1078 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1080 pFrameWnd
->GetToolBar()->Refresh();
1089 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1091 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1093 // let the default window proc calculate the size of MDI children
1094 // frames because it is based on the size of the MDI client window,
1095 // not on the values specified in wxWindow m_max variables
1096 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1098 int minWidth
= GetMinWidth(),
1099 minHeight
= GetMinHeight();
1101 // but allow GetSizeHints() to set the min size
1102 if ( minWidth
!= -1 )
1104 info
->ptMinTrackSize
.x
= minWidth
;
1109 if ( minHeight
!= -1 )
1111 info
->ptMinTrackSize
.y
= minHeight
;
1119 // ---------------------------------------------------------------------------
1120 // MDI specific message translation/preprocessing
1121 // ---------------------------------------------------------------------------
1123 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1125 return DefMDIChildProc(GetHwnd(),
1126 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1129 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1131 return wxFrame::MSWTranslateMessage(msg
);
1134 // ---------------------------------------------------------------------------
1136 // ---------------------------------------------------------------------------
1138 void wxMDIChildFrame::MSWDestroyWindow()
1140 invalidHandle
= GetHwnd();
1142 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1144 // Must make sure this handle is invalidated (set to NULL) since all sorts
1145 // of things could happen after the child client is destroyed, but before
1146 // the wxFrame is destroyed.
1148 HWND oldHandle
= (HWND
)GetHWND();
1149 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1150 (WPARAM
)oldHandle
, 0);
1152 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1153 ResetWindowStyle((void*) NULL
);
1159 ::DestroyMenu((HMENU
) m_hMenu
);
1162 wxRemoveHandleAssociation(this);
1166 // Change the client window's extended style so we don't get a client edge
1167 // style when a child is maximised (a double border looks silly.)
1168 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1170 #if defined(__WIN95__)
1171 RECT
*rect
= (RECT
*)vrect
;
1172 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1173 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1174 if (!pChild
|| (pChild
== this))
1176 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1177 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1179 // we want to test whether there is a maximized child, so just set
1180 // dwThisStyle to 0 if there is no child at all
1181 DWORD dwThisStyle
= pChild
1182 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1183 DWORD dwNewStyle
= dwStyle
;
1184 if ( dwThisStyle
& WS_MAXIMIZE
)
1185 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1187 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1189 if (dwStyle
!= dwNewStyle
)
1191 // force update of everything
1192 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1193 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1194 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1195 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1196 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1197 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1200 ::GetClientRect(hwndClient
, rect
);
1210 // ===========================================================================
1211 // wxMDIClientWindow: the window of predefined (by Windows) class which
1212 // contains the child frames
1213 // ===========================================================================
1215 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1217 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1219 CLIENTCREATESTRUCT ccs
;
1220 m_windowStyle
= style
;
1223 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1224 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1226 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1227 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1229 if ( style
& wxHSCROLL
)
1230 msStyle
|= WS_HSCROLL
;
1231 if ( style
& wxVSCROLL
)
1232 msStyle
|= WS_VSCROLL
;
1234 #if defined(__WIN95__)
1235 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1240 wxWindowCreationHook
hook(this);
1241 m_hWnd
= (WXHWND
)::CreateWindowEx
1251 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1254 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1259 SubclassWin(m_hWnd
);
1264 // Explicitly call default scroll behaviour
1265 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1267 // Note: for client windows, the scroll position is not set in
1268 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1269 // scroll position we're at.
1270 // This makes it hard to paint patterns or bitmaps in the background,
1271 // and have the client area scrollable as well.
1273 if ( event
.GetOrientation() == wxHORIZONTAL
)
1274 m_scrollX
= event
.GetPosition(); // Always returns zero!
1276 m_scrollY
= event
.GetPosition(); // Always returns zero!
1281 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1283 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1284 // client area, you can end up with a non-refreshed portion in the client window
1285 // (see OGL studio sample). So check if the position is changed and if so,
1286 // redraw the MDI child frames.
1288 wxPoint oldPos
= GetPosition();
1290 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1292 wxPoint newPos
= GetPosition();
1294 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1298 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1301 wxWindow
*child
= node
->GetData();
1302 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1304 ::RedrawWindow(GetHwndOf(child
),
1311 node
= node
->GetNext();
1317 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1319 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1320 // in flicker e.g. when the frame contained controls with non-trivial
1321 // layout. Since 2.5.3, the frame is created hidden as all other top level
1322 // windows. In order to maintain backward compatibility, the frame is shown
1323 // in OnIdle, unless Show(false) was called by the programmer before.
1324 if ( m_needsInitialShow
)
1329 // MDI child frames get their WM_SIZE when they're constructed but at this
1330 // moment they don't have any children yet so all child windows will be
1331 // positioned incorrectly when they are added later - to fix this, we
1332 // generate an artificial size event here
1333 if ( m_needsResize
)
1335 m_needsResize
= false; // avoid any possibility of recursion
1343 // ---------------------------------------------------------------------------
1344 // non member functions
1345 // ---------------------------------------------------------------------------
1347 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1349 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1351 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1353 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1357 // update menu bar of the parent window
1358 wxWindow
*parent
= win
->GetParent();
1359 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1361 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1363 ::DrawMenuBar(GetWinHwnd(parent
));
1366 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1368 // Try to insert Window menu in front of Help, otherwise append it.
1369 HMENU hmenu
= (HMENU
)menu
;
1373 int N
= GetMenuItemCount(hmenu
);
1374 bool success
= false;
1375 for ( int i
= 0; i
< N
; i
++ )
1378 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1381 wxLogLastError(wxT("GetMenuString"));
1387 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1390 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1391 (UINT
)subMenu
, _("&Window"));
1398 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1402 MDISetMenu(win
, hmenu
, subMenu
);
1405 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1407 HMENU hMenu
= (HMENU
)menu
;
1413 int N
= ::GetMenuItemCount(hMenu
);
1414 for ( int i
= 0; i
< N
; i
++ )
1416 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1418 // Ignore successful read of menu string with length 0 which
1419 // occurs, for example, for a maximized MDI childs system menu
1420 if ( ::GetLastError() != 0 )
1422 wxLogLastError(wxT("GetMenuString"));
1428 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1430 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1432 wxLogLastError(wxT("RemoveMenu"));
1442 // we don't change the windows menu, but we update the main one
1443 MDISetMenu(win
, hMenu
, NULL
);
1447 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1448 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1451 *hwndAct
= (WXHWND
)lParam
;
1452 *hwndDeact
= (WXHWND
)wParam
;
1455 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)