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__)
36 #include "wx/dialog.h"
37 #include "wx/statusbr.h"
38 #include "wx/settings.h"
41 #include "wx/toolbar.h"
44 #include "wx/stockitem.h"
45 #include "wx/msw/private.h"
49 // ---------------------------------------------------------------------------
51 // ---------------------------------------------------------------------------
53 extern wxMenu
*wxCurrentPopupMenu
;
55 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
56 extern const wxChar
*wxMDIChildFrameClassName
;
57 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
58 extern void wxRemoveHandleAssociation(wxWindow
*win
);
60 // ---------------------------------------------------------------------------
62 // ---------------------------------------------------------------------------
64 static const int IDM_WINDOWTILEHOR
= 4001;
65 static const int IDM_WINDOWCASCADE
= 4002;
66 static const int IDM_WINDOWICONS
= 4003;
67 static const int IDM_WINDOWNEXT
= 4004;
68 static const int IDM_WINDOWTILEVERT
= 4005;
69 static const int IDM_WINDOWPREV
= 4006;
71 // This range gives a maximum of 500 MDI children. Should be enough :-)
72 static const int wxFIRST_MDI_CHILD
= 4100;
73 static const int wxLAST_MDI_CHILD
= 4600;
75 // ---------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------
79 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
80 // of the parent of win (which is supposed to be the MDI client window)
81 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
83 // insert the window menu (subMenu) into menu just before "Help" submenu or at
84 // the very end if not found
85 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
87 // Remove the window menu
88 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
90 // is this an id of an MDI child?
91 inline bool IsMdiCommandId(int id
)
93 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
96 // unpack the parameters of WM_MDIACTIVATE message
97 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
98 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
100 // return the HMENU of the MDI menu
101 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
103 wxMenu
*menu
= frame
->GetWindowMenu();
104 return menu
? GetHmenuOf(menu
) : 0;
107 // ===========================================================================
109 // ===========================================================================
111 // ---------------------------------------------------------------------------
113 // ---------------------------------------------------------------------------
115 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
116 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
117 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
119 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
120 EVT_SIZE(wxMDIParentFrame::OnSize
)
121 EVT_ICONIZE(wxMDIParentFrame::OnIconized
)
122 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
125 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
126 EVT_IDLE(wxMDIChildFrame::OnIdle
)
129 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
130 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
133 // ===========================================================================
134 // wxMDIParentFrame: the frame which contains the client window which manages
136 // ===========================================================================
138 wxMDIParentFrame::wxMDIParentFrame()
140 m_clientWindow
= NULL
;
141 m_currentChild
= NULL
;
142 m_windowMenu
= (wxMenu
*) NULL
;
143 m_parentFrameActive
= true;
146 bool wxMDIParentFrame::Create(wxWindow
*parent
,
148 const wxString
& title
,
152 const wxString
& name
)
154 m_clientWindow
= NULL
;
155 m_currentChild
= NULL
;
157 // this style can be used to prevent a window from having the standard MDI
159 if ( style
& wxFRAME_NO_WINDOW_MENU
)
161 m_windowMenu
= (wxMenu
*)NULL
;
163 else // normal case: we have the window menu, so construct it
165 m_windowMenu
= new wxMenu
;
167 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
168 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
169 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
170 m_windowMenu
->AppendSeparator();
171 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
172 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
173 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
176 m_parentFrameActive
= true;
179 wxTopLevelWindows
.Append(this);
182 m_windowStyle
= style
;
185 parent
->AddChild(this);
187 if ( id
!= wxID_ANY
)
190 m_windowId
= NewControlId();
193 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
194 msflags
&= ~WS_VSCROLL
;
195 msflags
&= ~WS_HSCROLL
;
197 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
206 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
208 // unlike (almost?) all other windows, frames are created hidden
214 wxMDIParentFrame::~wxMDIParentFrame()
216 // see comment in ~wxMDIChildFrame
218 m_frameToolBar
= NULL
;
221 m_frameStatusBar
= NULL
;
222 #endif // wxUSE_STATUSBAR
229 m_windowMenu
= (wxMenu
*) NULL
;
232 // the MDI frame menubar is not automatically deleted by Windows unlike for
236 ::DestroyMenu((HMENU
)m_hMenu
);
237 m_hMenu
= (WXHMENU
)NULL
;
240 if ( m_clientWindow
)
242 if ( m_clientWindow
->MSWGetOldWndProc() )
243 m_clientWindow
->UnsubclassWin();
245 m_clientWindow
->SetHWND(0);
246 delete m_clientWindow
;
250 #if wxUSE_MENUS_NATIVE
252 void wxMDIParentFrame::InternalSetMenuBar()
254 m_parentFrameActive
= true;
256 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
259 #endif // wxUSE_MENUS_NATIVE
261 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
267 // Remove old window menu
268 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
272 m_windowMenu
= (wxMenu
*) NULL
;
280 InsertWindowMenu(GetClientWindow(), m_hMenu
,
281 GetHmenuOf(m_windowMenu
));
286 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
288 wxMDIChildFrame
*child
= GetActiveChild();
291 wxEvtHandler
* source
= child
->GetEventHandler();
292 wxMenuBar
* bar
= child
->GetMenuBar();
296 menu
->UpdateUI(source
);
302 int nCount
= bar
->GetMenuCount();
303 for (int n
= 0; n
< nCount
; n
++)
304 bar
->GetMenu(n
)->UpdateUI(source
);
310 wxFrameBase::DoMenuUpdates(menu
);
314 const wxMenuItem
*wxMDIParentFrame::FindItemInMenuBar(int menuId
) const
316 const wxMenuItem
*item
= wxFrame::FindItemInMenuBar(menuId
);
317 if ( !item
&& m_currentChild
)
319 item
= m_currentChild
->FindItemInMenuBar(menuId
);
325 void wxMDIParentFrame::UpdateClientSize()
327 if ( GetClientWindow() )
330 GetClientSize(&width
, &height
);
332 GetClientWindow()->SetSize(0, 0, width
, height
);
336 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
340 // do not call event.Skip() here, it somehow messes up MDI client window
343 void wxMDIParentFrame::OnIconized(wxIconizeEvent
& event
)
347 if ( !event
.Iconized() )
353 // Returns the active MDI child window
354 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
356 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
357 WM_MDIGETACTIVE
, 0, 0L);
361 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
364 // Create the client window class (don't Create the window, just return a new
366 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
368 return new wxMDIClientWindow
;
371 // Responds to colour changes, and passes event on to children.
372 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
374 if ( m_clientWindow
)
376 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
377 m_clientWindow
->Refresh();
383 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
385 // we don't have any standard icons (any more)
389 // ---------------------------------------------------------------------------
391 // ---------------------------------------------------------------------------
393 void wxMDIParentFrame::Cascade()
395 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
398 void wxMDIParentFrame::Tile(wxOrientation orient
)
400 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
401 _T("invalid orientation value") );
403 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
404 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
405 : MDITILE_VERTICAL
, 0);
408 void wxMDIParentFrame::ArrangeIcons()
410 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
413 void wxMDIParentFrame::ActivateNext()
415 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
418 void wxMDIParentFrame::ActivatePrevious()
420 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
423 // ---------------------------------------------------------------------------
424 // the MDI parent frame window proc
425 // ---------------------------------------------------------------------------
427 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
432 bool processed
= false;
438 WXWORD state
, minimized
;
440 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
442 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
450 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
452 (void)HandleCommand(id
, cmd
, hwnd
);
454 // even if the frame didn't process it, there is no need to try it
455 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
456 // so pretend we processed the message anyhow
460 // always pass this message DefFrameProc(), otherwise MDI menu
461 // commands (and sys commands - more surprisingly!) won't work
462 MSWDefWindowProc(message
, wParam
, lParam
);
466 m_clientWindow
= OnCreateClient();
467 // Uses own style for client style
468 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
470 wxLogMessage(_("Failed to create MDI parent frame."));
481 // we erase background ourselves
486 // though we don't (usually) resize the MDI client to exactly fit the
487 // client area we need to pass this one to DefFrameProc to allow the children to show
492 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
497 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
499 bool processed
= false;
501 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
507 // If this window is an MDI parent, we must also send an OnActivate message
508 // to the current child.
509 if ( (m_currentChild
!= NULL
) &&
510 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
512 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
513 event
.SetEventObject( m_currentChild
);
514 if ( m_currentChild
->HandleWindowEvent(event
) )
521 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
523 // In case it's e.g. a toolbar.
526 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
528 return win
->MSWCommand(cmd
, id
);
531 if (wxCurrentPopupMenu
)
533 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
534 wxCurrentPopupMenu
= NULL
;
535 if (popupMenu
->MSWCommand(cmd
, id
))
539 // is it one of standard MDI commands?
545 case IDM_WINDOWCASCADE
:
547 wParam
= MDITILE_SKIPDISABLED
;
550 case IDM_WINDOWTILEHOR
:
551 wParam
|= MDITILE_HORIZONTAL
;
554 case IDM_WINDOWTILEVERT
:
556 wParam
= MDITILE_VERTICAL
;
558 wParam
|= MDITILE_SKIPDISABLED
;
561 case IDM_WINDOWICONS
:
562 msg
= WM_MDIICONARRANGE
;
567 lParam
= 0; // next child
572 lParam
= 1; // previous child
581 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
586 // FIXME VZ: what does this test do??
589 return false; // Get WndProc to call default proc
592 if ( IsMdiCommandId(id
) )
594 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
597 wxWindow
*child
= node
->GetData();
598 if ( child
->GetHWND() )
600 int childId
= wxGetWindowId(child
->GetHWND());
601 if ( childId
== (signed short)id
)
603 ::SendMessage( GetWinHwnd(GetClientWindow()),
605 (WPARAM
)child
->GetHWND(), 0);
609 node
= node
->GetNext();
612 else if ( m_parentFrameActive
)
614 return ProcessCommand(id
);
616 else if ( m_currentChild
)
618 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
622 // this shouldn't happen because it means that our messages are being
623 // lost (they're not sent to the parent frame nor to the children)
624 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
630 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
635 if ( GetClientWindow() )
636 clientWnd
= GetClientWindow()->GetHWND();
640 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
643 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
645 MSG
*pMsg
= (MSG
*)msg
;
647 // first let the current child get it
648 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
649 m_currentChild
->MSWTranslateMessage(msg
) )
654 // then try out accel table (will also check the menu accels)
655 if ( wxFrame::MSWTranslateMessage(msg
) )
660 // finally, check for MDI specific built in accel keys
661 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
663 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
670 // ===========================================================================
672 // ===========================================================================
674 void wxMDIChildFrame::Init()
676 m_needsResize
= true;
677 m_needsInitialShow
= true;
680 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
682 const wxString
& title
,
686 const wxString
& name
)
690 if ( id
!= wxID_ANY
)
693 m_windowId
= NewControlId();
697 parent
->AddChild(this);
707 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
708 ? wxMDIChildFrameClassName
709 : wxMDIChildFrameClassNameNoRedraw
;
710 mcs
.szTitle
= title
.wx_str();
711 mcs
.hOwner
= wxGetInstance();
712 if (x
!= wxDefaultCoord
)
715 mcs
.x
= CW_USEDEFAULT
;
717 if (y
!= wxDefaultCoord
)
720 mcs
.y
= CW_USEDEFAULT
;
722 if (width
!= wxDefaultCoord
)
725 mcs
.cx
= CW_USEDEFAULT
;
727 if (height
!= wxDefaultCoord
)
730 mcs
.cy
= CW_USEDEFAULT
;
732 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
733 if (style
& wxMINIMIZE_BOX
)
734 msflags
|= WS_MINIMIZEBOX
;
735 if (style
& wxMAXIMIZE_BOX
)
736 msflags
|= WS_MAXIMIZEBOX
;
737 if (style
& wxRESIZE_BORDER
)
738 msflags
|= WS_THICKFRAME
;
739 if (style
& wxSYSTEM_MENU
)
740 msflags
|= WS_SYSMENU
;
741 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
742 msflags
|= WS_MINIMIZE
;
743 if (style
& wxMAXIMIZE
)
744 msflags
|= WS_MAXIMIZE
;
745 if (style
& wxCAPTION
)
746 msflags
|= WS_CAPTION
;
752 wxWindowCreationHook
hook(this);
754 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
755 WM_MDICREATE
, 0, (LPARAM
)&mcs
);
759 wxLogLastError(_T("WM_MDICREATE"));
768 wxMDIChildFrame::~wxMDIChildFrame()
770 // if we hadn't been created, there is nothing to destroy
774 // will be destroyed by DestroyChildren() but reset them before calling it
775 // to avoid using dangling pointers if a callback comes in the meanwhile
777 m_frameToolBar
= NULL
;
780 m_frameStatusBar
= NULL
;
781 #endif // wxUSE_STATUSBAR
785 RemoveWindowMenu(NULL
, m_hMenu
);
790 bool wxMDIChildFrame::Show(bool show
)
792 m_needsInitialShow
= false;
794 if (!wxFrame::Show(show
))
797 // KH: Without this call, new MDI children do not become active.
798 // This was added here after the same BringWindowToTop call was
799 // removed from wxTopLevelWindow::Show (November 2005)
801 ::BringWindowToTop(GetHwnd());
803 // we need to refresh the MDI frame window menu to include (or exclude if
804 // we've been hidden) this frame
805 wxMDIParentFrame
*parent
= GetMDIParent();
806 MDISetMenu(parent
->GetClientWindow(), NULL
, NULL
);
811 // Set the client size (i.e. leave the calculation of borders etc.
813 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
815 HWND hWnd
= GetHwnd();
818 ::GetClientRect(hWnd
, &rect
);
821 GetWindowRect(hWnd
, &rect2
);
823 // Find the difference between the entire window (title bar and all)
824 // and the client area; add this to the new client size to move the
826 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
827 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
830 if (GetStatusBar() && GetStatusBar()->IsShown())
833 GetStatusBar()->GetSize(&sx
, &sy
);
836 #endif // wxUSE_STATUSBAR
839 point
.x
= rect2
.left
;
842 // If there's an MDI parent, must subtract the parent's top left corner
843 // since MoveWindow moves relative to the parent
844 wxMDIParentFrame
*mdiParent
= GetMDIParent();
845 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
847 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
849 wxSize
size(width
, height
);
850 wxSizeEvent
event(size
, m_windowId
);
851 event
.SetEventObject( this );
852 HandleWindowEvent(event
);
855 // Unlike other wxTopLevelWindowBase, the mdi child's "GetPosition" is not the
856 // same as its GetScreenPosition
857 void wxMDIChildFrame::DoGetScreenPosition(int *x
, int *y
) const
859 HWND hWnd
= GetHwnd();
862 ::GetWindowRect(hWnd
, &rect
);
870 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
873 GetWindowRect(GetHwnd(), &rect
);
878 // Since we now have the absolute screen coords,
879 // if there's a parent we must subtract its top left corner
880 wxMDIParentFrame
*mdiParent
= GetMDIParent();
881 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
889 void wxMDIChildFrame::InternalSetMenuBar()
891 wxMDIParentFrame
*parent
= GetMDIParent();
893 InsertWindowMenu(parent
->GetClientWindow(),
894 m_hMenu
, GetMDIWindowMenu(parent
));
896 parent
->m_parentFrameActive
= false;
899 void wxMDIChildFrame::DetachMenuBar()
901 RemoveWindowMenu(NULL
, m_hMenu
);
902 wxFrame::DetachMenuBar();
905 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
907 // we don't have any standard icons (any more)
911 // ---------------------------------------------------------------------------
913 // ---------------------------------------------------------------------------
915 void wxMDIChildFrame::Maximize(bool maximize
)
917 wxMDIParentFrame
*parent
= GetMDIParent();
918 if ( parent
&& parent
->GetClientWindow() )
920 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
921 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
922 (WPARAM
)GetHwnd(), 0);
926 void wxMDIChildFrame::Restore()
928 wxMDIParentFrame
*parent
= GetMDIParent();
929 if ( parent
&& parent
->GetClientWindow() )
931 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
932 (WPARAM
) GetHwnd(), 0);
936 void wxMDIChildFrame::Activate()
938 wxMDIParentFrame
*parent
= GetMDIParent();
939 if ( parent
&& parent
->GetClientWindow() )
941 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
942 (WPARAM
) GetHwnd(), 0);
946 // ---------------------------------------------------------------------------
947 // MDI window proc and message handlers
948 // ---------------------------------------------------------------------------
950 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
955 bool processed
= false;
963 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
966 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
970 case WM_GETMINMAXINFO
:
971 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
977 WXHWND hwndAct
, hwndDeact
;
978 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
980 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
985 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
986 // scrollbars if necessary
991 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
993 MSWDefWindowProc(message
, wParam
, lParam
);
997 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
998 // the message (the base class version does not)
999 return MSWDefWindowProc(message
, wParam
, lParam
);
1001 case WM_WINDOWPOSCHANGING
:
1002 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
1007 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
1012 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
1014 // In case it's e.g. a toolbar.
1017 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
1019 return win
->MSWCommand(cmd
, id
);
1022 if (wxCurrentPopupMenu
)
1024 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1025 wxCurrentPopupMenu
= NULL
;
1026 if (popupMenu
->MSWCommand(cmd
, id
))
1031 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
1033 processed
= ProcessCommand(id
);
1043 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
1047 wxMDIParentFrame
*parent
= GetMDIParent();
1049 HMENU menuToSet
= 0;
1053 if ( m_hWnd
== hwndAct
)
1056 parent
->m_currentChild
= this;
1058 HMENU child_menu
= (HMENU
)GetWinMenu();
1061 parent
->m_parentFrameActive
= false;
1063 menuToSet
= child_menu
;
1066 else if ( m_hWnd
== hwndDeact
)
1068 wxASSERT_MSG( parent
->m_currentChild
== this,
1069 wxT("can't deactivate MDI child which wasn't active!") );
1072 parent
->m_currentChild
= NULL
;
1074 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1076 // activate the the parent menu only when there is no other child
1077 // that has been activated
1078 if ( parent_menu
&& !hwndAct
)
1080 parent
->m_parentFrameActive
= true;
1082 menuToSet
= parent_menu
;
1087 // we have nothing to do with it
1093 MDISetMenu(parent
->GetClientWindow(),
1094 menuToSet
, GetMDIWindowMenu(parent
));
1097 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1098 event
.SetEventObject( this );
1100 ResetWindowStyle((void *)NULL
);
1102 return HandleWindowEvent(event
);
1105 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1107 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1109 if (!(lpPos
->flags
& SWP_NOSIZE
))
1112 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1113 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1114 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1116 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1117 lpPos
->x
= rectClient
.left
;
1118 lpPos
->y
= rectClient
.top
;
1119 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1120 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1127 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1129 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1131 // let the default window proc calculate the size of MDI children
1132 // frames because it is based on the size of the MDI client window,
1133 // not on the values specified in wxWindow m_max variables
1134 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1136 int minWidth
= GetMinWidth(),
1137 minHeight
= GetMinHeight();
1139 // but allow GetSizeHints() to set the min size
1140 if ( minWidth
!= wxDefaultCoord
)
1142 info
->ptMinTrackSize
.x
= minWidth
;
1147 if ( minHeight
!= wxDefaultCoord
)
1149 info
->ptMinTrackSize
.y
= minHeight
;
1157 // ---------------------------------------------------------------------------
1158 // MDI specific message translation/preprocessing
1159 // ---------------------------------------------------------------------------
1161 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1163 return DefMDIChildProc(GetHwnd(),
1164 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1167 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1169 // we must pass the parent frame to ::TranslateAccelerator(), otherwise it
1170 // doesn't do its job correctly for MDI child menus
1171 return MSWDoTranslateMessage(GetMDIParent(), msg
);
1174 // ---------------------------------------------------------------------------
1176 // ---------------------------------------------------------------------------
1178 void wxMDIChildFrame::MSWDestroyWindow()
1180 wxMDIParentFrame
*parent
= GetMDIParent();
1182 // Must make sure this handle is invalidated (set to NULL) since all sorts
1183 // of things could happen after the child client is destroyed, but before
1184 // the wxFrame is destroyed.
1186 HWND oldHandle
= (HWND
)GetHWND();
1187 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1188 (WPARAM
)oldHandle
, 0);
1190 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1191 ResetWindowStyle((void*) NULL
);
1195 ::DestroyMenu((HMENU
) m_hMenu
);
1198 wxRemoveHandleAssociation(this);
1202 // Change the client window's extended style so we don't get a client edge
1203 // style when a child is maximised (a double border looks silly.)
1204 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1206 RECT
*rect
= (RECT
*)vrect
;
1207 wxMDIParentFrame
* pFrameWnd
= GetMDIParent();
1208 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1210 if (!pChild
|| (pChild
== this))
1212 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1213 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1215 // we want to test whether there is a maximized child, so just set
1216 // dwThisStyle to 0 if there is no child at all
1217 DWORD dwThisStyle
= pChild
1218 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1219 DWORD dwNewStyle
= dwStyle
;
1220 if ( dwThisStyle
& WS_MAXIMIZE
)
1221 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1223 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1225 if (dwStyle
!= dwNewStyle
)
1227 // force update of everything
1228 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1229 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1230 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1231 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1232 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1233 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1236 ::GetClientRect(hwndClient
, rect
);
1245 // ===========================================================================
1246 // wxMDIClientWindow: the window of predefined (by Windows) class which
1247 // contains the child frames
1248 // ===========================================================================
1250 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1252 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1254 CLIENTCREATESTRUCT ccs
;
1255 m_windowStyle
= style
;
1258 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1259 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1261 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1262 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1264 if ( style
& wxHSCROLL
)
1265 msStyle
|= WS_HSCROLL
;
1266 if ( style
& wxVSCROLL
)
1267 msStyle
|= WS_VSCROLL
;
1269 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1271 wxWindowCreationHook
hook(this);
1272 m_hWnd
= (WXHWND
)::CreateWindowEx
1282 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1285 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1290 SubclassWin(m_hWnd
);
1295 // Explicitly call default scroll behaviour
1296 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1298 // Note: for client windows, the scroll position is not set in
1299 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1300 // scroll position we're at.
1301 // This makes it hard to paint patterns or bitmaps in the background,
1302 // and have the client area scrollable as well.
1304 if ( event
.GetOrientation() == wxHORIZONTAL
)
1305 m_scrollX
= event
.GetPosition(); // Always returns zero!
1307 m_scrollY
= event
.GetPosition(); // Always returns zero!
1312 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1314 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1315 // client area, you can end up with a non-refreshed portion in the client window
1316 // (see OGL studio sample). So check if the position is changed and if so,
1317 // redraw the MDI child frames.
1319 const wxPoint oldPos
= GetPosition();
1321 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
| wxSIZE_FORCE
);
1323 const wxPoint newPos
= GetPosition();
1325 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1329 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1332 wxWindow
*child
= node
->GetData();
1333 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1335 ::RedrawWindow(GetHwndOf(child
),
1342 node
= node
->GetNext();
1348 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1350 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1351 // in flicker e.g. when the frame contained controls with non-trivial
1352 // layout. Since 2.5.3, the frame is created hidden as all other top level
1353 // windows. In order to maintain backward compatibility, the frame is shown
1354 // in OnIdle, unless Show(false) was called by the programmer before.
1355 if ( m_needsInitialShow
)
1360 // MDI child frames get their WM_SIZE when they're constructed but at this
1361 // moment they don't have any children yet so all child windows will be
1362 // positioned incorrectly when they are added later - to fix this, we
1363 // generate an artificial size event here
1364 if ( m_needsResize
)
1366 m_needsResize
= false; // avoid any possibility of recursion
1374 // ---------------------------------------------------------------------------
1375 // non member functions
1376 // ---------------------------------------------------------------------------
1378 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1380 if ( hmenuFrame
|| hmenuWindow
)
1382 if ( !::SendMessage(GetWinHwnd(win
),
1385 (LPARAM
)hmenuWindow
) )
1388 DWORD err
= ::GetLastError();
1390 wxLogApiError(_T("SendMessage(WM_MDISETMENU)"), err
);
1391 #endif // __WXDEBUG__
1395 // update menu bar of the parent window
1396 wxWindow
*parent
= win
->GetParent();
1397 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1399 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1401 ::DrawMenuBar(GetWinHwnd(parent
));
1404 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1406 // Try to insert Window menu in front of Help, otherwise append it.
1407 HMENU hmenu
= (HMENU
)menu
;
1411 int N
= GetMenuItemCount(hmenu
);
1412 bool success
= false;
1413 for ( int i
= 0; i
< N
; i
++ )
1416 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1419 wxLogLastError(wxT("GetMenuString"));
1424 wxString
strBuf(buf
);
1425 if ( wxStripMenuCodes(strBuf
) == wxGetStockLabel(wxID_HELP
,false) )
1428 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1429 (UINT_PTR
)subMenu
, _("&Window").wx_str());
1436 ::AppendMenu(hmenu
, MF_POPUP
,
1437 (UINT_PTR
)subMenu
, _("&Window").wx_str());
1441 MDISetMenu(win
, hmenu
, subMenu
);
1444 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1446 HMENU hMenu
= (HMENU
)menu
;
1452 int N
= ::GetMenuItemCount(hMenu
);
1453 for ( int i
= 0; i
< N
; i
++ )
1455 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1457 // Ignore successful read of menu string with length 0 which
1458 // occurs, for example, for a maximized MDI childs system menu
1459 if ( ::GetLastError() != 0 )
1461 wxLogLastError(wxT("GetMenuString"));
1467 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1469 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1471 wxLogLastError(wxT("RemoveMenu"));
1481 // we don't change the windows menu, but we update the main one
1482 MDISetMenu(win
, hMenu
, NULL
);
1486 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1487 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1490 *hwndAct
= (WXHWND
)lParam
;
1491 *hwndDeact
= (WXHWND
)wParam
;
1494 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)