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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_MDI && !defined(__WXUNIVERSAL__)
34 #include "wx/dialog.h"
36 #include "wx/statusbr.h"
38 #include "wx/settings.h"
41 #include "wx/toolbar.h"
44 #include "wx/stockitem.h"
46 #include "wx/msw/private.h"
48 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
49 #include "wx/msw/statbr95.h"
54 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
58 extern wxMenu
*wxCurrentPopupMenu
;
60 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
61 extern const wxChar
*wxMDIChildFrameClassName
;
62 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
63 extern void wxRemoveHandleAssociation(wxWindow
*win
);
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
69 static const int IDM_WINDOWTILEHOR
= 4001;
70 static const int IDM_WINDOWCASCADE
= 4002;
71 static const int IDM_WINDOWICONS
= 4003;
72 static const int IDM_WINDOWNEXT
= 4004;
73 static const int IDM_WINDOWTILEVERT
= 4005;
74 static const int IDM_WINDOWPREV
= 4006;
76 // This range gives a maximum of 500 MDI children. Should be enough :-)
77 static const int wxFIRST_MDI_CHILD
= 4100;
78 static const int wxLAST_MDI_CHILD
= 4600;
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
85 // of the parent of win (which is supposed to be the MDI client window)
86 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
88 // insert the window menu (subMenu) into menu just before "Help" submenu or at
89 // the very end if not found
90 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
92 // Remove the window menu
93 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
95 // is this an id of an MDI child?
96 inline bool IsMdiCommandId(int id
)
98 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
101 // unpack the parameters of WM_MDIACTIVATE message
102 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
103 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
105 // return the HMENU of the MDI menu
106 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
108 wxMenu
*menu
= frame
->GetWindowMenu();
109 return menu
? GetHmenuOf(menu
) : 0;
112 // ===========================================================================
114 // ===========================================================================
116 // ---------------------------------------------------------------------------
118 // ---------------------------------------------------------------------------
120 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
121 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
122 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
124 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
125 EVT_SIZE(wxMDIParentFrame::OnSize
)
126 EVT_ICONIZE(wxMDIParentFrame::OnIconized
)
127 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
130 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
131 EVT_IDLE(wxMDIChildFrame::OnIdle
)
134 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
135 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
138 // ===========================================================================
139 // wxMDIParentFrame: the frame which contains the client window which manages
141 // ===========================================================================
143 wxMDIParentFrame::wxMDIParentFrame()
145 m_clientWindow
= NULL
;
146 m_currentChild
= NULL
;
147 m_windowMenu
= (wxMenu
*) NULL
;
148 m_parentFrameActive
= true;
151 bool wxMDIParentFrame::Create(wxWindow
*parent
,
153 const wxString
& title
,
157 const wxString
& name
)
159 m_clientWindow
= NULL
;
160 m_currentChild
= NULL
;
162 // this style can be used to prevent a window from having the standard MDI
164 if ( style
& wxFRAME_NO_WINDOW_MENU
)
166 m_windowMenu
= (wxMenu
*)NULL
;
168 else // normal case: we have the window menu, so construct it
170 m_windowMenu
= new wxMenu
;
172 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
173 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
174 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
175 m_windowMenu
->AppendSeparator();
176 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
177 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
178 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
181 m_parentFrameActive
= true;
184 wxTopLevelWindows
.Append(this);
187 m_windowStyle
= style
;
190 parent
->AddChild(this);
192 if ( id
!= wxID_ANY
)
195 m_windowId
= NewControlId();
198 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
199 msflags
&= ~WS_VSCROLL
;
200 msflags
&= ~WS_HSCROLL
;
202 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
211 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
213 // unlike (almost?) all other windows, frames are created hidden
219 wxMDIParentFrame::~wxMDIParentFrame()
221 // see comment in ~wxMDIChildFrame
223 m_frameToolBar
= NULL
;
226 m_frameStatusBar
= NULL
;
227 #endif // wxUSE_STATUSBAR
234 m_windowMenu
= (wxMenu
*) NULL
;
237 // the MDI frame menubar is not automatically deleted by Windows unlike for
241 ::DestroyMenu((HMENU
)m_hMenu
);
242 m_hMenu
= (WXHMENU
)NULL
;
245 if ( m_clientWindow
)
247 if ( m_clientWindow
->MSWGetOldWndProc() )
248 m_clientWindow
->UnsubclassWin();
250 m_clientWindow
->SetHWND(0);
251 delete m_clientWindow
;
255 #if wxUSE_MENUS_NATIVE
257 void wxMDIParentFrame::InternalSetMenuBar()
259 m_parentFrameActive
= true;
261 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
264 #endif // wxUSE_MENUS_NATIVE
266 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
272 // Remove old window menu
273 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
277 m_windowMenu
= (wxMenu
*) NULL
;
285 InsertWindowMenu(GetClientWindow(), m_hMenu
,
286 GetHmenuOf(m_windowMenu
));
291 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
293 wxMDIChildFrame
*child
= GetActiveChild();
296 wxEvtHandler
* source
= child
->GetEventHandler();
297 wxMenuBar
* bar
= child
->GetMenuBar();
301 menu
->UpdateUI(source
);
307 int nCount
= bar
->GetMenuCount();
308 for (int n
= 0; n
< nCount
; n
++)
309 bar
->GetMenu(n
)->UpdateUI(source
);
315 wxFrameBase::DoMenuUpdates(menu
);
319 void wxMDIParentFrame::UpdateClientSize()
321 if ( GetClientWindow() )
324 GetClientSize(&width
, &height
);
326 GetClientWindow()->SetSize(0, 0, width
, height
);
330 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
334 // do not call event.Skip() here, it somehow messes up MDI client window
337 void wxMDIParentFrame::OnIconized(wxIconizeEvent
& event
)
341 if ( !event
.Iconized() )
347 // Returns the active MDI child window
348 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
350 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
351 WM_MDIGETACTIVE
, 0, 0L);
355 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
358 // Create the client window class (don't Create the window, just return a new
360 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
362 return new wxMDIClientWindow
;
365 // Responds to colour changes, and passes event on to children.
366 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
368 if ( m_clientWindow
)
370 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
371 m_clientWindow
->Refresh();
377 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
379 // we don't have any standard icons (any more)
383 // ---------------------------------------------------------------------------
385 // ---------------------------------------------------------------------------
387 void wxMDIParentFrame::Cascade()
389 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
392 void wxMDIParentFrame::Tile(wxOrientation orient
)
394 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
395 _T("invalid orientation value") );
397 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
398 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
399 : MDITILE_VERTICAL
, 0);
402 void wxMDIParentFrame::ArrangeIcons()
404 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
407 void wxMDIParentFrame::ActivateNext()
409 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
412 void wxMDIParentFrame::ActivatePrevious()
414 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
417 // ---------------------------------------------------------------------------
418 // the MDI parent frame window proc
419 // ---------------------------------------------------------------------------
421 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
426 bool processed
= false;
432 WXWORD state
, minimized
;
434 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
436 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
444 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
446 (void)HandleCommand(id
, cmd
, hwnd
);
448 // even if the frame didn't process it, there is no need to try it
449 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
450 // so pretend we processed the message anyhow
454 // always pass this message DefFrameProc(), otherwise MDI menu
455 // commands (and sys commands - more surprisingly!) won't work
456 MSWDefWindowProc(message
, wParam
, lParam
);
460 m_clientWindow
= OnCreateClient();
461 // Uses own style for client style
462 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
464 wxLogMessage(_("Failed to create MDI parent frame."));
475 // we erase background ourselves
483 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
485 if ( m_parentFrameActive
)
487 processed
= HandleMenuSelect(item
, flags
, hmenu
);
489 else if (m_currentChild
)
491 processed
= m_currentChild
->
492 HandleMenuSelect(item
, flags
, hmenu
);
498 // though we don't (usually) resize the MDI client to exactly fit the
499 // client area we need to pass this one to DefFrameProc to allow the children to show
504 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
509 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
511 bool processed
= false;
513 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
519 // If this window is an MDI parent, we must also send an OnActivate message
520 // to the current child.
521 if ( (m_currentChild
!= NULL
) &&
522 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
524 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
525 event
.SetEventObject( m_currentChild
);
526 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
533 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
535 // In case it's e.g. a toolbar.
538 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
540 return win
->MSWCommand(cmd
, id
);
543 if (wxCurrentPopupMenu
)
545 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
546 wxCurrentPopupMenu
= NULL
;
547 if (popupMenu
->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
& wxRESIZE_BORDER
)
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
);
771 wxLogLastError(_T("WM_MDICREATE"));
780 wxMDIChildFrame::~wxMDIChildFrame()
782 // will be destroyed by DestroyChildren() but reset them before calling it
783 // to avoid using dangling pointers if a callback comes in the meanwhile
785 m_frameToolBar
= NULL
;
788 m_frameStatusBar
= NULL
;
789 #endif // wxUSE_STATUSBAR
793 RemoveWindowMenu(NULL
, m_hMenu
);
798 bool wxMDIChildFrame::Show(bool show
)
800 m_needsInitialShow
= false;
802 if (!wxFrame::Show(show
))
805 // KH: Without this call, new MDI children do not become active.
806 // This was added here after the same BringWindowToTop call was
807 // removed from wxTopLevelWindow::Show (November 2005)
809 ::BringWindowToTop(GetHwnd());
811 // we need to refresh the MDI frame window menu to include (or exclude if
812 // we've been hidden) this frame
813 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
814 MDISetMenu(parent
->GetClientWindow(), NULL
, NULL
);
819 // Set the client size (i.e. leave the calculation of borders etc.
821 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
823 HWND hWnd
= GetHwnd();
826 ::GetClientRect(hWnd
, &rect
);
829 GetWindowRect(hWnd
, &rect2
);
831 // Find the difference between the entire window (title bar and all)
832 // and the client area; add this to the new client size to move the
834 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
835 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
838 if (GetStatusBar() && GetStatusBar()->IsShown())
841 GetStatusBar()->GetSize(&sx
, &sy
);
844 #endif // wxUSE_STATUSBAR
847 point
.x
= rect2
.left
;
850 // If there's an MDI parent, must subtract the parent's top left corner
851 // since MoveWindow moves relative to the parent
852 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
853 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
855 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
857 wxSize
size(width
, height
);
858 wxSizeEvent
event(size
, m_windowId
);
859 event
.SetEventObject( this );
860 GetEventHandler()->ProcessEvent(event
);
863 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
866 GetWindowRect(GetHwnd(), &rect
);
871 // Since we now have the absolute screen coords,
872 // if there's a parent we must subtract its top left corner
873 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
874 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
882 void wxMDIChildFrame::InternalSetMenuBar()
884 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
886 InsertWindowMenu(parent
->GetClientWindow(),
887 m_hMenu
, GetMDIWindowMenu(parent
));
889 parent
->m_parentFrameActive
= false;
892 void wxMDIChildFrame::DetachMenuBar()
894 RemoveWindowMenu(NULL
, m_hMenu
);
895 wxFrame::DetachMenuBar();
898 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
900 // we don't have any standard icons (any more)
904 // ---------------------------------------------------------------------------
906 // ---------------------------------------------------------------------------
908 void wxMDIChildFrame::Maximize(bool maximize
)
910 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
911 if ( parent
&& parent
->GetClientWindow() )
913 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
914 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
915 (WPARAM
)GetHwnd(), 0);
919 void wxMDIChildFrame::Restore()
921 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
922 if ( parent
&& parent
->GetClientWindow() )
924 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
925 (WPARAM
) GetHwnd(), 0);
929 void wxMDIChildFrame::Activate()
931 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
932 if ( parent
&& parent
->GetClientWindow() )
934 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
935 (WPARAM
) GetHwnd(), 0);
939 // ---------------------------------------------------------------------------
940 // MDI window proc and message handlers
941 // ---------------------------------------------------------------------------
943 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
948 bool processed
= false;
956 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
959 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
963 case WM_GETMINMAXINFO
:
964 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
970 WXHWND hwndAct
, hwndDeact
;
971 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
973 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
978 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
979 // scrollbars if necessary
984 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
986 MSWDefWindowProc(message
, wParam
, lParam
);
990 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
991 // the message (the base class version does not)
992 return MSWDefWindowProc(message
, wParam
, lParam
);
994 case WM_WINDOWPOSCHANGING
:
995 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
1000 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
1005 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
1007 // In case it's e.g. a toolbar.
1010 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
1012 return win
->MSWCommand(cmd
, id
);
1015 if (wxCurrentPopupMenu
)
1017 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1018 wxCurrentPopupMenu
= NULL
;
1019 if (popupMenu
->MSWCommand(cmd
, id
))
1024 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
1026 processed
= ProcessCommand(id
);
1036 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
1040 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1042 HMENU menuToSet
= 0;
1046 if ( m_hWnd
== hwndAct
)
1049 parent
->m_currentChild
= this;
1051 HMENU child_menu
= (HMENU
)GetWinMenu();
1054 parent
->m_parentFrameActive
= false;
1056 menuToSet
= child_menu
;
1059 else if ( m_hWnd
== hwndDeact
)
1061 wxASSERT_MSG( parent
->m_currentChild
== this,
1062 wxT("can't deactivate MDI child which wasn't active!") );
1065 parent
->m_currentChild
= NULL
;
1067 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1069 // activate the the parent menu only when there is no other child
1070 // that has been activated
1071 if ( parent_menu
&& !hwndAct
)
1073 parent
->m_parentFrameActive
= true;
1075 menuToSet
= parent_menu
;
1080 // we have nothing to do with it
1086 MDISetMenu(parent
->GetClientWindow(),
1087 menuToSet
, GetMDIWindowMenu(parent
));
1090 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1091 event
.SetEventObject( this );
1093 ResetWindowStyle((void *)NULL
);
1095 return GetEventHandler()->ProcessEvent(event
);
1098 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1100 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1102 if (!(lpPos
->flags
& SWP_NOSIZE
))
1105 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1106 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1107 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1109 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1110 lpPos
->x
= rectClient
.left
;
1111 lpPos
->y
= rectClient
.top
;
1112 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1113 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1120 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1122 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1124 // let the default window proc calculate the size of MDI children
1125 // frames because it is based on the size of the MDI client window,
1126 // not on the values specified in wxWindow m_max variables
1127 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1129 int minWidth
= GetMinWidth(),
1130 minHeight
= GetMinHeight();
1132 // but allow GetSizeHints() to set the min size
1133 if ( minWidth
!= wxDefaultCoord
)
1135 info
->ptMinTrackSize
.x
= minWidth
;
1140 if ( minHeight
!= wxDefaultCoord
)
1142 info
->ptMinTrackSize
.y
= minHeight
;
1150 // ---------------------------------------------------------------------------
1151 // MDI specific message translation/preprocessing
1152 // ---------------------------------------------------------------------------
1154 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1156 return DefMDIChildProc(GetHwnd(),
1157 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1160 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1162 // we must pass the parent frame to ::TranslateAccelerator(), otherwise it
1163 // doesn't do its job correctly for MDI child menus
1164 return MSWDoTranslateMessage((wxMDIChildFrame
*)GetParent(), msg
);
1167 // ---------------------------------------------------------------------------
1169 // ---------------------------------------------------------------------------
1171 void wxMDIChildFrame::MSWDestroyWindow()
1173 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1175 // Must make sure this handle is invalidated (set to NULL) since all sorts
1176 // of things could happen after the child client is destroyed, but before
1177 // the wxFrame is destroyed.
1179 HWND oldHandle
= (HWND
)GetHWND();
1180 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1181 (WPARAM
)oldHandle
, 0);
1183 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1184 ResetWindowStyle((void*) NULL
);
1188 ::DestroyMenu((HMENU
) m_hMenu
);
1191 wxRemoveHandleAssociation(this);
1195 // Change the client window's extended style so we don't get a client edge
1196 // style when a child is maximised (a double border looks silly.)
1197 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1199 RECT
*rect
= (RECT
*)vrect
;
1200 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1201 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1203 if (!pChild
|| (pChild
== this))
1205 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1206 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1208 // we want to test whether there is a maximized child, so just set
1209 // dwThisStyle to 0 if there is no child at all
1210 DWORD dwThisStyle
= pChild
1211 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1212 DWORD dwNewStyle
= dwStyle
;
1213 if ( dwThisStyle
& WS_MAXIMIZE
)
1214 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1216 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1218 if (dwStyle
!= dwNewStyle
)
1220 // force update of everything
1221 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1222 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1223 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1224 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1225 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1226 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1229 ::GetClientRect(hwndClient
, rect
);
1238 // ===========================================================================
1239 // wxMDIClientWindow: the window of predefined (by Windows) class which
1240 // contains the child frames
1241 // ===========================================================================
1243 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1245 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1247 CLIENTCREATESTRUCT ccs
;
1248 m_windowStyle
= style
;
1251 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1252 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1254 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1255 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1257 if ( style
& wxHSCROLL
)
1258 msStyle
|= WS_HSCROLL
;
1259 if ( style
& wxVSCROLL
)
1260 msStyle
|= WS_VSCROLL
;
1262 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1264 wxWindowCreationHook
hook(this);
1265 m_hWnd
= (WXHWND
)::CreateWindowEx
1275 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1278 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1283 SubclassWin(m_hWnd
);
1288 // Explicitly call default scroll behaviour
1289 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1291 // Note: for client windows, the scroll position is not set in
1292 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1293 // scroll position we're at.
1294 // This makes it hard to paint patterns or bitmaps in the background,
1295 // and have the client area scrollable as well.
1297 if ( event
.GetOrientation() == wxHORIZONTAL
)
1298 m_scrollX
= event
.GetPosition(); // Always returns zero!
1300 m_scrollY
= event
.GetPosition(); // Always returns zero!
1305 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1307 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1308 // client area, you can end up with a non-refreshed portion in the client window
1309 // (see OGL studio sample). So check if the position is changed and if so,
1310 // redraw the MDI child frames.
1312 const wxPoint oldPos
= GetPosition();
1314 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
| wxSIZE_FORCE
);
1316 const wxPoint newPos
= GetPosition();
1318 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1322 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1325 wxWindow
*child
= node
->GetData();
1326 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1328 ::RedrawWindow(GetHwndOf(child
),
1335 node
= node
->GetNext();
1341 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1343 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1344 // in flicker e.g. when the frame contained controls with non-trivial
1345 // layout. Since 2.5.3, the frame is created hidden as all other top level
1346 // windows. In order to maintain backward compatibility, the frame is shown
1347 // in OnIdle, unless Show(false) was called by the programmer before.
1348 if ( m_needsInitialShow
)
1353 // MDI child frames get their WM_SIZE when they're constructed but at this
1354 // moment they don't have any children yet so all child windows will be
1355 // positioned incorrectly when they are added later - to fix this, we
1356 // generate an artificial size event here
1357 if ( m_needsResize
)
1359 m_needsResize
= false; // avoid any possibility of recursion
1367 // ---------------------------------------------------------------------------
1368 // non member functions
1369 // ---------------------------------------------------------------------------
1371 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1373 if ( hmenuFrame
|| hmenuWindow
)
1375 if ( !::SendMessage(GetWinHwnd(win
),
1378 (LPARAM
)hmenuWindow
) )
1380 wxLogLastError(_T("SendMessage(WM_MDISETMENU)"));
1384 // update menu bar of the parent window
1385 wxWindow
*parent
= win
->GetParent();
1386 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1388 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1390 ::DrawMenuBar(GetWinHwnd(parent
));
1393 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1395 // Try to insert Window menu in front of Help, otherwise append it.
1396 HMENU hmenu
= (HMENU
)menu
;
1400 int N
= GetMenuItemCount(hmenu
);
1401 bool success
= false;
1402 for ( int i
= 0; i
< N
; i
++ )
1405 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1408 wxLogLastError(wxT("GetMenuString"));
1413 wxString
strBuf(buf
);
1414 if ( wxStripMenuCodes(strBuf
) == wxGetStockLabel(wxID_HELP
,false) )
1417 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1418 (UINT
)subMenu
, _("&Window"));
1425 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1429 MDISetMenu(win
, hmenu
, subMenu
);
1432 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1434 HMENU hMenu
= (HMENU
)menu
;
1440 int N
= ::GetMenuItemCount(hMenu
);
1441 for ( int i
= 0; i
< N
; i
++ )
1443 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1445 // Ignore successful read of menu string with length 0 which
1446 // occurs, for example, for a maximized MDI childs system menu
1447 if ( ::GetLastError() != 0 )
1449 wxLogLastError(wxT("GetMenuString"));
1455 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1457 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1459 wxLogLastError(wxT("RemoveMenu"));
1469 // we don't change the windows menu, but we update the main one
1470 MDISetMenu(win
, hMenu
, NULL
);
1474 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1475 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1478 *hwndAct
= (WXHWND
)lParam
;
1479 *hwndDeact
= (WXHWND
)wParam
;
1482 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)