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_ICONIZE(wxMDIParentFrame::OnIconized
)
137 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
140 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
141 EVT_IDLE(wxMDIChildFrame::OnIdle
)
144 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
145 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
148 // ===========================================================================
149 // wxMDIParentFrame: the frame which contains the client window which manages
151 // ===========================================================================
153 wxMDIParentFrame::wxMDIParentFrame()
155 m_clientWindow
= NULL
;
156 m_currentChild
= NULL
;
157 m_windowMenu
= (wxMenu
*) NULL
;
158 m_parentFrameActive
= true;
161 bool wxMDIParentFrame::Create(wxWindow
*parent
,
163 const wxString
& title
,
167 const wxString
& name
)
169 m_clientWindow
= NULL
;
170 m_currentChild
= NULL
;
172 // this style can be used to prevent a window from having the standard MDI
174 if ( style
& wxFRAME_NO_WINDOW_MENU
)
176 m_windowMenu
= (wxMenu
*)NULL
;
178 else // normal case: we have the window menu, so construct it
180 m_windowMenu
= new wxMenu
;
182 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
183 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
184 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
185 m_windowMenu
->AppendSeparator();
186 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
187 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
188 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
191 m_parentFrameActive
= true;
194 wxTopLevelWindows
.Append(this);
197 m_windowStyle
= style
;
200 parent
->AddChild(this);
202 if ( id
!= wxID_ANY
)
205 m_windowId
= NewControlId();
208 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
209 msflags
&= ~WS_VSCROLL
;
210 msflags
&= ~WS_HSCROLL
;
212 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
221 // unlike (almost?) all other windows, frames are created hidden
227 wxMDIParentFrame::~wxMDIParentFrame()
229 // see comment in ~wxMDIChildFrame
231 m_frameToolBar
= NULL
;
234 m_frameStatusBar
= NULL
;
235 #endif // wxUSE_STATUSBAR
242 m_windowMenu
= (wxMenu
*) NULL
;
245 // the MDI frame menubar is not automatically deleted by Windows unlike for
249 ::DestroyMenu((HMENU
)m_hMenu
);
250 m_hMenu
= (WXHMENU
)NULL
;
253 if ( m_clientWindow
)
255 if ( m_clientWindow
->MSWGetOldWndProc() )
256 m_clientWindow
->UnsubclassWin();
258 m_clientWindow
->SetHWND(0);
259 delete m_clientWindow
;
263 #if wxUSE_MENUS_NATIVE
265 void wxMDIParentFrame::InternalSetMenuBar()
267 m_parentFrameActive
= true;
269 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
272 #endif // wxUSE_MENUS_NATIVE
274 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
280 // Remove old window menu
281 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
285 m_windowMenu
= (wxMenu
*) NULL
;
293 InsertWindowMenu(GetClientWindow(), m_hMenu
,
294 GetHmenuOf(m_windowMenu
));
299 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
301 wxMDIChildFrame
*child
= GetActiveChild();
304 wxEvtHandler
* source
= child
->GetEventHandler();
305 wxMenuBar
* bar
= child
->GetMenuBar();
309 menu
->UpdateUI(source
);
315 int nCount
= bar
->GetMenuCount();
316 for (int n
= 0; n
< nCount
; n
++)
317 bar
->GetMenu(n
)->UpdateUI(source
);
323 wxFrameBase::DoMenuUpdates(menu
);
327 void wxMDIParentFrame::UpdateClientSize()
329 if ( GetClientWindow() )
332 GetClientSize(&width
, &height
);
334 GetClientWindow()->SetSize(0, 0, width
, height
);
338 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
342 // do not call event.Skip() here, it somehow messes up MDI client window
345 void wxMDIParentFrame::OnIconized(wxIconizeEvent
& event
)
349 if ( !event
.Iconized() )
355 // Returns the active MDI child window
356 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
358 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
359 WM_MDIGETACTIVE
, 0, 0L);
363 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
366 // Create the client window class (don't Create the window, just return a new
368 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
370 return new wxMDIClientWindow
;
373 // Responds to colour changes, and passes event on to children.
374 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
376 if ( m_clientWindow
)
378 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
379 m_clientWindow
->Refresh();
385 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
387 // we don't have any standard icons (any more)
391 // ---------------------------------------------------------------------------
393 // ---------------------------------------------------------------------------
395 void wxMDIParentFrame::Cascade()
397 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
400 void wxMDIParentFrame::Tile(wxOrientation orient
)
402 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
403 _T("invalid orientation value") );
405 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
406 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
407 : MDITILE_VERTICAL
, 0);
410 void wxMDIParentFrame::ArrangeIcons()
412 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
415 void wxMDIParentFrame::ActivateNext()
417 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
420 void wxMDIParentFrame::ActivatePrevious()
422 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
425 // ---------------------------------------------------------------------------
426 // the MDI parent frame window proc
427 // ---------------------------------------------------------------------------
429 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
434 bool processed
= false;
440 WXWORD state
, minimized
;
442 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
444 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
452 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
454 (void)HandleCommand(id
, cmd
, hwnd
);
456 // even if the frame didn't process it, there is no need to try it
457 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
458 // so pretend we processed the message anyhow
462 // always pass this message DefFrameProc(), otherwise MDI menu
463 // commands (and sys commands - more surprisingly!) won't work
464 MSWDefWindowProc(message
, wParam
, lParam
);
468 m_clientWindow
= OnCreateClient();
469 // Uses own style for client style
470 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
472 wxLogMessage(_("Failed to create MDI parent frame."));
483 // we erase background ourselves
491 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
493 if ( m_parentFrameActive
)
495 processed
= HandleMenuSelect(item
, flags
, hmenu
);
497 else if (m_currentChild
)
499 processed
= m_currentChild
->
500 HandleMenuSelect(item
, flags
, hmenu
);
506 // though we don't (usually) resize the MDI client to exactly fit the
507 // client area we need to pass this one to DefFrameProc to allow the children to show
512 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
517 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
519 bool processed
= false;
521 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
527 // If this window is an MDI parent, we must also send an OnActivate message
528 // to the current child.
529 if ( (m_currentChild
!= NULL
) &&
530 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
532 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
533 event
.SetEventObject( m_currentChild
);
534 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
541 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
543 // In case it's e.g. a toolbar.
546 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
548 return win
->MSWCommand(cmd
, id
);
551 // is it one of standard MDI commands?
557 case IDM_WINDOWCASCADE
:
559 wParam
= MDITILE_SKIPDISABLED
;
562 case IDM_WINDOWTILEHOR
:
563 wParam
|= MDITILE_HORIZONTAL
;
566 case IDM_WINDOWTILEVERT
:
568 wParam
= MDITILE_VERTICAL
;
570 wParam
|= MDITILE_SKIPDISABLED
;
573 case IDM_WINDOWICONS
:
574 msg
= WM_MDIICONARRANGE
;
579 lParam
= 0; // next child
584 lParam
= 1; // previous child
593 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
598 // FIXME VZ: what does this test do??
601 return false; // Get WndProc to call default proc
604 if ( IsMdiCommandId(id
) )
606 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
609 wxWindow
*child
= node
->GetData();
610 if ( child
->GetHWND() )
612 long childId
= wxGetWindowId(child
->GetHWND());
613 if (childId
== (long)id
)
615 ::SendMessage( GetWinHwnd(GetClientWindow()),
617 (WPARAM
)child
->GetHWND(), 0);
621 node
= node
->GetNext();
624 else if ( m_parentFrameActive
)
626 return ProcessCommand(id
);
628 else if ( m_currentChild
)
630 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
634 // this shouldn't happen because it means that our messages are being
635 // lost (they're not sent to the parent frame nor to the children)
636 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
642 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
647 if ( GetClientWindow() )
648 clientWnd
= GetClientWindow()->GetHWND();
652 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
655 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
657 MSG
*pMsg
= (MSG
*)msg
;
659 // first let the current child get it
660 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
661 m_currentChild
->MSWTranslateMessage(msg
) )
666 // then try out accel table (will also check the menu accels)
667 if ( wxFrame::MSWTranslateMessage(msg
) )
672 // finally, check for MDI specific built in accel keys
673 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
675 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
682 // ===========================================================================
684 // ===========================================================================
686 void wxMDIChildFrame::Init()
688 m_needsResize
= true;
689 m_needsInitialShow
= true;
692 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
694 const wxString
& title
,
698 const wxString
& name
)
702 if ( id
!= wxID_ANY
)
705 m_windowId
= (int)NewControlId();
709 parent
->AddChild(this);
719 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
720 ? wxMDIChildFrameClassName
721 : wxMDIChildFrameClassNameNoRedraw
;
723 mcs
.hOwner
= wxGetInstance();
724 if (x
!= wxDefaultCoord
)
727 mcs
.x
= CW_USEDEFAULT
;
729 if (y
!= wxDefaultCoord
)
732 mcs
.y
= CW_USEDEFAULT
;
734 if (width
!= wxDefaultCoord
)
737 mcs
.cx
= CW_USEDEFAULT
;
739 if (height
!= wxDefaultCoord
)
742 mcs
.cy
= CW_USEDEFAULT
;
744 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
745 if (style
& wxMINIMIZE_BOX
)
746 msflags
|= WS_MINIMIZEBOX
;
747 if (style
& wxMAXIMIZE_BOX
)
748 msflags
|= WS_MAXIMIZEBOX
;
749 if (style
& wxTHICK_FRAME
)
750 msflags
|= WS_THICKFRAME
;
751 if (style
& wxSYSTEM_MENU
)
752 msflags
|= WS_SYSMENU
;
753 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
754 msflags
|= WS_MINIMIZE
;
755 if (style
& wxMAXIMIZE
)
756 msflags
|= WS_MAXIMIZE
;
757 if (style
& wxCAPTION
)
758 msflags
|= WS_CAPTION
;
764 wxWindowCreationHook
hook(this);
766 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
767 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
769 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
774 wxMDIChildFrame::~wxMDIChildFrame()
776 // will be destroyed by DestroyChildren() but reset them before calling it
777 // to avoid using dangling pointers if a callback comes in the meanwhile
779 m_frameToolBar
= NULL
;
782 m_frameStatusBar
= NULL
;
783 #endif // wxUSE_STATUSBAR
787 RemoveWindowMenu(NULL
, m_hMenu
);
792 bool wxMDIChildFrame::Show(bool show
)
794 m_needsInitialShow
= false;
795 return wxFrame::Show(show
);
798 // Set the client size (i.e. leave the calculation of borders etc.
800 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
802 HWND hWnd
= GetHwnd();
805 ::GetClientRect(hWnd
, &rect
);
808 GetWindowRect(hWnd
, &rect2
);
810 // Find the difference between the entire window (title bar and all)
811 // and the client area; add this to the new client size to move the
813 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
814 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
817 if (GetStatusBar() && GetStatusBar()->IsShown())
820 GetStatusBar()->GetSize(&sx
, &sy
);
823 #endif // wxUSE_STATUSBAR
826 point
.x
= rect2
.left
;
829 // If there's an MDI parent, must subtract the parent's top left corner
830 // since MoveWindow moves relative to the parent
831 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
832 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
834 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
836 wxSize
size(width
, height
);
837 wxSizeEvent
event(size
, m_windowId
);
838 event
.SetEventObject( this );
839 GetEventHandler()->ProcessEvent(event
);
842 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
845 GetWindowRect(GetHwnd(), &rect
);
850 // Since we now have the absolute screen coords,
851 // if there's a parent we must subtract its top left corner
852 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
853 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
861 void wxMDIChildFrame::InternalSetMenuBar()
863 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
865 InsertWindowMenu(parent
->GetClientWindow(),
866 m_hMenu
, GetMDIWindowMenu(parent
));
868 parent
->m_parentFrameActive
= false;
871 void wxMDIChildFrame::DetachMenuBar()
873 RemoveWindowMenu(NULL
, m_hMenu
);
874 wxFrame::DetachMenuBar();
877 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
879 // we don't have any standard icons (any more)
883 // ---------------------------------------------------------------------------
885 // ---------------------------------------------------------------------------
887 void wxMDIChildFrame::Maximize(bool maximize
)
889 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
890 if ( parent
&& parent
->GetClientWindow() )
892 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
893 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
894 (WPARAM
)GetHwnd(), 0);
898 void wxMDIChildFrame::Restore()
900 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
901 if ( parent
&& parent
->GetClientWindow() )
903 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
904 (WPARAM
) GetHwnd(), 0);
908 void wxMDIChildFrame::Activate()
910 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
911 if ( parent
&& parent
->GetClientWindow() )
913 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
914 (WPARAM
) GetHwnd(), 0);
918 // ---------------------------------------------------------------------------
919 // MDI window proc and message handlers
920 // ---------------------------------------------------------------------------
922 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
927 bool processed
= false;
935 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
938 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
942 case WM_GETMINMAXINFO
:
943 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
949 WXHWND hwndAct
, hwndDeact
;
950 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
952 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
957 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
958 // scrollbars if necessary
963 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
965 MSWDefWindowProc(message
, wParam
, lParam
);
969 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
970 // the message (the base class version does not)
971 return MSWDefWindowProc(message
, wParam
, lParam
);
973 case WM_WINDOWPOSCHANGING
:
974 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
979 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
984 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
986 // In case it's e.g. a toolbar.
989 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
991 return win
->MSWCommand(cmd
, id
);
994 if (wxCurrentPopupMenu
)
996 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
997 wxCurrentPopupMenu
= NULL
;
998 if (popupMenu
->MSWCommand(cmd
, id
))
1003 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
1005 processed
= ProcessCommand(id
);
1015 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
1019 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1021 HMENU menuToSet
= 0;
1025 if ( m_hWnd
== hwndAct
)
1028 parent
->m_currentChild
= this;
1030 HMENU child_menu
= (HMENU
)GetWinMenu();
1033 parent
->m_parentFrameActive
= false;
1035 menuToSet
= child_menu
;
1038 else if ( m_hWnd
== hwndDeact
)
1040 wxASSERT_MSG( parent
->m_currentChild
== this,
1041 wxT("can't deactivate MDI child which wasn't active!") );
1044 parent
->m_currentChild
= NULL
;
1046 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1048 // activate the the parent menu only when there is no other child
1049 // that has been activated
1050 if ( parent_menu
&& !hwndAct
)
1052 parent
->m_parentFrameActive
= true;
1054 menuToSet
= parent_menu
;
1059 // we have nothing to do with it
1065 MDISetMenu(parent
->GetClientWindow(),
1066 menuToSet
, GetMDIWindowMenu(parent
));
1069 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1070 event
.SetEventObject( this );
1072 ResetWindowStyle((void *)NULL
);
1074 return GetEventHandler()->ProcessEvent(event
);
1077 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1079 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1080 #if defined(__WIN95__)
1081 if (!(lpPos
->flags
& SWP_NOSIZE
))
1084 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1085 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1086 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1088 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1089 lpPos
->x
= rectClient
.left
;
1090 lpPos
->y
= rectClient
.top
;
1091 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1092 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1095 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1096 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1098 pFrameWnd
->GetToolBar()->Refresh();
1107 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1109 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1111 // let the default window proc calculate the size of MDI children
1112 // frames because it is based on the size of the MDI client window,
1113 // not on the values specified in wxWindow m_max variables
1114 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1116 int minWidth
= GetMinWidth(),
1117 minHeight
= GetMinHeight();
1119 // but allow GetSizeHints() to set the min size
1120 if ( minWidth
!= -1 )
1122 info
->ptMinTrackSize
.x
= minWidth
;
1127 if ( minHeight
!= -1 )
1129 info
->ptMinTrackSize
.y
= minHeight
;
1137 // ---------------------------------------------------------------------------
1138 // MDI specific message translation/preprocessing
1139 // ---------------------------------------------------------------------------
1141 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1143 return DefMDIChildProc(GetHwnd(),
1144 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1147 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1149 return wxFrame::MSWTranslateMessage(msg
);
1152 // ---------------------------------------------------------------------------
1154 // ---------------------------------------------------------------------------
1156 void wxMDIChildFrame::MSWDestroyWindow()
1158 invalidHandle
= GetHwnd();
1160 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1162 // Must make sure this handle is invalidated (set to NULL) since all sorts
1163 // of things could happen after the child client is destroyed, but before
1164 // the wxFrame is destroyed.
1166 HWND oldHandle
= (HWND
)GetHWND();
1167 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1168 (WPARAM
)oldHandle
, 0);
1170 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1171 ResetWindowStyle((void*) NULL
);
1177 ::DestroyMenu((HMENU
) m_hMenu
);
1180 wxRemoveHandleAssociation(this);
1184 // Change the client window's extended style so we don't get a client edge
1185 // style when a child is maximised (a double border looks silly.)
1186 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1188 #if defined(__WIN95__)
1189 RECT
*rect
= (RECT
*)vrect
;
1190 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1191 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1192 if (!pChild
|| (pChild
== this))
1194 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1195 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1197 // we want to test whether there is a maximized child, so just set
1198 // dwThisStyle to 0 if there is no child at all
1199 DWORD dwThisStyle
= pChild
1200 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1201 DWORD dwNewStyle
= dwStyle
;
1202 if ( dwThisStyle
& WS_MAXIMIZE
)
1203 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1205 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1207 if (dwStyle
!= dwNewStyle
)
1209 // force update of everything
1210 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1211 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1212 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1213 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1214 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1215 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1218 ::GetClientRect(hwndClient
, rect
);
1228 // ===========================================================================
1229 // wxMDIClientWindow: the window of predefined (by Windows) class which
1230 // contains the child frames
1231 // ===========================================================================
1233 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1235 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1237 CLIENTCREATESTRUCT ccs
;
1238 m_windowStyle
= style
;
1241 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1242 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1244 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1245 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1247 if ( style
& wxHSCROLL
)
1248 msStyle
|= WS_HSCROLL
;
1249 if ( style
& wxVSCROLL
)
1250 msStyle
|= WS_VSCROLL
;
1252 #if defined(__WIN95__)
1253 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1258 wxWindowCreationHook
hook(this);
1259 m_hWnd
= (WXHWND
)::CreateWindowEx
1269 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1272 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1277 SubclassWin(m_hWnd
);
1282 // Explicitly call default scroll behaviour
1283 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1285 // Note: for client windows, the scroll position is not set in
1286 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1287 // scroll position we're at.
1288 // This makes it hard to paint patterns or bitmaps in the background,
1289 // and have the client area scrollable as well.
1291 if ( event
.GetOrientation() == wxHORIZONTAL
)
1292 m_scrollX
= event
.GetPosition(); // Always returns zero!
1294 m_scrollY
= event
.GetPosition(); // Always returns zero!
1299 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1301 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1302 // client area, you can end up with a non-refreshed portion in the client window
1303 // (see OGL studio sample). So check if the position is changed and if so,
1304 // redraw the MDI child frames.
1306 const wxPoint oldPos
= GetPosition();
1308 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
| wxSIZE_FORCE
);
1310 const wxPoint newPos
= GetPosition();
1312 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1316 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1319 wxWindow
*child
= node
->GetData();
1320 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1322 ::RedrawWindow(GetHwndOf(child
),
1329 node
= node
->GetNext();
1335 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1337 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1338 // in flicker e.g. when the frame contained controls with non-trivial
1339 // layout. Since 2.5.3, the frame is created hidden as all other top level
1340 // windows. In order to maintain backward compatibility, the frame is shown
1341 // in OnIdle, unless Show(false) was called by the programmer before.
1342 if ( m_needsInitialShow
)
1347 // MDI child frames get their WM_SIZE when they're constructed but at this
1348 // moment they don't have any children yet so all child windows will be
1349 // positioned incorrectly when they are added later - to fix this, we
1350 // generate an artificial size event here
1351 if ( m_needsResize
)
1353 m_needsResize
= false; // avoid any possibility of recursion
1361 // ---------------------------------------------------------------------------
1362 // non member functions
1363 // ---------------------------------------------------------------------------
1365 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1367 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1369 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1371 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1375 // update menu bar of the parent window
1376 wxWindow
*parent
= win
->GetParent();
1377 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1379 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1381 ::DrawMenuBar(GetWinHwnd(parent
));
1384 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1386 // Try to insert Window menu in front of Help, otherwise append it.
1387 HMENU hmenu
= (HMENU
)menu
;
1391 int N
= GetMenuItemCount(hmenu
);
1392 bool success
= false;
1393 for ( int i
= 0; i
< N
; i
++ )
1396 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1399 wxLogLastError(wxT("GetMenuString"));
1404 wxString
strHelp(_("&Help"));
1405 wxString
strBuf(buf
);
1406 if ( wxStripMenuCodes(strBuf
) == wxStripMenuCodes(strHelp
) )
1409 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1410 (UINT
)subMenu
, _("&Window"));
1417 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1421 MDISetMenu(win
, hmenu
, subMenu
);
1424 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1426 HMENU hMenu
= (HMENU
)menu
;
1432 int N
= ::GetMenuItemCount(hMenu
);
1433 for ( int i
= 0; i
< N
; i
++ )
1435 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1437 // Ignore successful read of menu string with length 0 which
1438 // occurs, for example, for a maximized MDI childs system menu
1439 if ( ::GetLastError() != 0 )
1441 wxLogLastError(wxT("GetMenuString"));
1447 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1449 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1451 wxLogLastError(wxT("RemoveMenu"));
1461 // we don't change the windows menu, but we update the main one
1462 MDISetMenu(win
, hMenu
, NULL
);
1466 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1467 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1470 *hwndAct
= (WXHWND
)lParam
;
1471 *hwndDeact
= (WXHWND
)wParam
;
1474 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)