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"
43 #include "wx/stockitem.h"
45 #include "wx/msw/private.h"
47 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
48 #include "wx/msw/statbr95.h"
52 #include "wx/toolbar.h"
53 #endif // wxUSE_TOOLBAR
57 // ---------------------------------------------------------------------------
59 // ---------------------------------------------------------------------------
61 extern wxMenu
*wxCurrentPopupMenu
;
63 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
64 extern const wxChar
*wxMDIChildFrameClassName
;
65 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
66 extern void wxRemoveHandleAssociation(wxWindow
*win
);
68 // ---------------------------------------------------------------------------
70 // ---------------------------------------------------------------------------
72 static const int IDM_WINDOWTILEHOR
= 4001;
73 static const int IDM_WINDOWCASCADE
= 4002;
74 static const int IDM_WINDOWICONS
= 4003;
75 static const int IDM_WINDOWNEXT
= 4004;
76 static const int IDM_WINDOWTILEVERT
= 4005;
77 static const int IDM_WINDOWPREV
= 4006;
79 // This range gives a maximum of 500 MDI children. Should be enough :-)
80 static const int wxFIRST_MDI_CHILD
= 4100;
81 static const int wxLAST_MDI_CHILD
= 4600;
83 // ---------------------------------------------------------------------------
85 // ---------------------------------------------------------------------------
87 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
88 // of the parent of win (which is supposed to be the MDI client window)
89 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
91 // insert the window menu (subMenu) into menu just before "Help" submenu or at
92 // the very end if not found
93 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
95 // Remove the window menu
96 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
98 // is this an id of an MDI child?
99 inline bool IsMdiCommandId(int id
)
101 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
104 // unpack the parameters of WM_MDIACTIVATE message
105 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
106 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
108 // return the HMENU of the MDI menu
109 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
111 wxMenu
*menu
= frame
->GetWindowMenu();
112 return menu
? GetHmenuOf(menu
) : 0;
115 // ===========================================================================
117 // ===========================================================================
119 // ---------------------------------------------------------------------------
121 // ---------------------------------------------------------------------------
123 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
124 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
125 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
127 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
128 EVT_SIZE(wxMDIParentFrame::OnSize
)
129 EVT_ICONIZE(wxMDIParentFrame::OnIconized
)
130 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
133 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
134 EVT_IDLE(wxMDIChildFrame::OnIdle
)
137 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
138 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
141 // ===========================================================================
142 // wxMDIParentFrame: the frame which contains the client window which manages
144 // ===========================================================================
146 wxMDIParentFrame::wxMDIParentFrame()
148 m_clientWindow
= NULL
;
149 m_currentChild
= NULL
;
150 m_windowMenu
= (wxMenu
*) NULL
;
151 m_parentFrameActive
= true;
154 bool wxMDIParentFrame::Create(wxWindow
*parent
,
156 const wxString
& title
,
160 const wxString
& name
)
162 m_clientWindow
= NULL
;
163 m_currentChild
= NULL
;
165 // this style can be used to prevent a window from having the standard MDI
167 if ( style
& wxFRAME_NO_WINDOW_MENU
)
169 m_windowMenu
= (wxMenu
*)NULL
;
171 else // normal case: we have the window menu, so construct it
173 m_windowMenu
= new wxMenu
;
175 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
176 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
177 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
178 m_windowMenu
->AppendSeparator();
179 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
180 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
181 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
184 m_parentFrameActive
= true;
187 wxTopLevelWindows
.Append(this);
190 m_windowStyle
= style
;
193 parent
->AddChild(this);
195 if ( id
!= wxID_ANY
)
198 m_windowId
= NewControlId();
201 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
202 msflags
&= ~WS_VSCROLL
;
203 msflags
&= ~WS_HSCROLL
;
205 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
214 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
216 // unlike (almost?) all other windows, frames are created hidden
222 wxMDIParentFrame::~wxMDIParentFrame()
224 // see comment in ~wxMDIChildFrame
226 m_frameToolBar
= NULL
;
229 m_frameStatusBar
= NULL
;
230 #endif // wxUSE_STATUSBAR
237 m_windowMenu
= (wxMenu
*) NULL
;
240 // the MDI frame menubar is not automatically deleted by Windows unlike for
244 ::DestroyMenu((HMENU
)m_hMenu
);
245 m_hMenu
= (WXHMENU
)NULL
;
248 if ( m_clientWindow
)
250 if ( m_clientWindow
->MSWGetOldWndProc() )
251 m_clientWindow
->UnsubclassWin();
253 m_clientWindow
->SetHWND(0);
254 delete m_clientWindow
;
258 #if wxUSE_MENUS_NATIVE
260 void wxMDIParentFrame::InternalSetMenuBar()
262 m_parentFrameActive
= true;
264 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
267 #endif // wxUSE_MENUS_NATIVE
269 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
275 // Remove old window menu
276 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
280 m_windowMenu
= (wxMenu
*) NULL
;
288 InsertWindowMenu(GetClientWindow(), m_hMenu
,
289 GetHmenuOf(m_windowMenu
));
294 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
296 wxMDIChildFrame
*child
= GetActiveChild();
299 wxEvtHandler
* source
= child
->GetEventHandler();
300 wxMenuBar
* bar
= child
->GetMenuBar();
304 menu
->UpdateUI(source
);
310 int nCount
= bar
->GetMenuCount();
311 for (int n
= 0; n
< nCount
; n
++)
312 bar
->GetMenu(n
)->UpdateUI(source
);
318 wxFrameBase::DoMenuUpdates(menu
);
322 void wxMDIParentFrame::UpdateClientSize()
324 if ( GetClientWindow() )
327 GetClientSize(&width
, &height
);
329 GetClientWindow()->SetSize(0, 0, width
, height
);
333 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
337 // do not call event.Skip() here, it somehow messes up MDI client window
340 void wxMDIParentFrame::OnIconized(wxIconizeEvent
& event
)
344 if ( !event
.Iconized() )
350 // Returns the active MDI child window
351 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
353 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
354 WM_MDIGETACTIVE
, 0, 0L);
358 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
361 // Create the client window class (don't Create the window, just return a new
363 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
365 return new wxMDIClientWindow
;
368 // Responds to colour changes, and passes event on to children.
369 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
371 if ( m_clientWindow
)
373 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
374 m_clientWindow
->Refresh();
380 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
382 // we don't have any standard icons (any more)
386 // ---------------------------------------------------------------------------
388 // ---------------------------------------------------------------------------
390 void wxMDIParentFrame::Cascade()
392 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
395 void wxMDIParentFrame::Tile(wxOrientation orient
)
397 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
398 _T("invalid orientation value") );
400 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
401 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
402 : MDITILE_VERTICAL
, 0);
405 void wxMDIParentFrame::ArrangeIcons()
407 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
410 void wxMDIParentFrame::ActivateNext()
412 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
415 void wxMDIParentFrame::ActivatePrevious()
417 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
420 // ---------------------------------------------------------------------------
421 // the MDI parent frame window proc
422 // ---------------------------------------------------------------------------
424 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
429 bool processed
= false;
435 WXWORD state
, minimized
;
437 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
439 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
447 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
449 (void)HandleCommand(id
, cmd
, hwnd
);
451 // even if the frame didn't process it, there is no need to try it
452 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
453 // so pretend we processed the message anyhow
457 // always pass this message DefFrameProc(), otherwise MDI menu
458 // commands (and sys commands - more surprisingly!) won't work
459 MSWDefWindowProc(message
, wParam
, lParam
);
463 m_clientWindow
= OnCreateClient();
464 // Uses own style for client style
465 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
467 wxLogMessage(_("Failed to create MDI parent frame."));
478 // we erase background ourselves
486 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
488 if ( m_parentFrameActive
)
490 processed
= HandleMenuSelect(item
, flags
, hmenu
);
492 else if (m_currentChild
)
494 processed
= m_currentChild
->
495 HandleMenuSelect(item
, flags
, hmenu
);
501 // though we don't (usually) resize the MDI client to exactly fit the
502 // client area we need to pass this one to DefFrameProc to allow the children to show
507 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
512 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
514 bool processed
= false;
516 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
522 // If this window is an MDI parent, we must also send an OnActivate message
523 // to the current child.
524 if ( (m_currentChild
!= NULL
) &&
525 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
527 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
528 event
.SetEventObject( m_currentChild
);
529 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
536 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
538 // In case it's e.g. a toolbar.
541 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
543 return win
->MSWCommand(cmd
, id
);
546 if (wxCurrentPopupMenu
)
548 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
549 wxCurrentPopupMenu
= NULL
;
550 if (popupMenu
->MSWCommand(cmd
, id
))
554 // is it one of standard MDI commands?
560 case IDM_WINDOWCASCADE
:
562 wParam
= MDITILE_SKIPDISABLED
;
565 case IDM_WINDOWTILEHOR
:
566 wParam
|= MDITILE_HORIZONTAL
;
569 case IDM_WINDOWTILEVERT
:
571 wParam
= MDITILE_VERTICAL
;
573 wParam
|= MDITILE_SKIPDISABLED
;
576 case IDM_WINDOWICONS
:
577 msg
= WM_MDIICONARRANGE
;
582 lParam
= 0; // next child
587 lParam
= 1; // previous child
596 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
601 // FIXME VZ: what does this test do??
604 return false; // Get WndProc to call default proc
607 if ( IsMdiCommandId(id
) )
609 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
612 wxWindow
*child
= node
->GetData();
613 if ( child
->GetHWND() )
615 long childId
= wxGetWindowId(child
->GetHWND());
616 if (childId
== (long)id
)
618 ::SendMessage( GetWinHwnd(GetClientWindow()),
620 (WPARAM
)child
->GetHWND(), 0);
624 node
= node
->GetNext();
627 else if ( m_parentFrameActive
)
629 return ProcessCommand(id
);
631 else if ( m_currentChild
)
633 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
637 // this shouldn't happen because it means that our messages are being
638 // lost (they're not sent to the parent frame nor to the children)
639 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
645 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
650 if ( GetClientWindow() )
651 clientWnd
= GetClientWindow()->GetHWND();
655 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
658 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
660 MSG
*pMsg
= (MSG
*)msg
;
662 // first let the current child get it
663 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
664 m_currentChild
->MSWTranslateMessage(msg
) )
669 // then try out accel table (will also check the menu accels)
670 if ( wxFrame::MSWTranslateMessage(msg
) )
675 // finally, check for MDI specific built in accel keys
676 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
678 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
685 // ===========================================================================
687 // ===========================================================================
689 void wxMDIChildFrame::Init()
691 m_needsResize
= true;
692 m_needsInitialShow
= true;
695 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
697 const wxString
& title
,
701 const wxString
& name
)
705 if ( id
!= wxID_ANY
)
708 m_windowId
= (int)NewControlId();
712 parent
->AddChild(this);
722 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
723 ? wxMDIChildFrameClassName
724 : wxMDIChildFrameClassNameNoRedraw
;
726 mcs
.hOwner
= wxGetInstance();
727 if (x
!= wxDefaultCoord
)
730 mcs
.x
= CW_USEDEFAULT
;
732 if (y
!= wxDefaultCoord
)
735 mcs
.y
= CW_USEDEFAULT
;
737 if (width
!= wxDefaultCoord
)
740 mcs
.cx
= CW_USEDEFAULT
;
742 if (height
!= wxDefaultCoord
)
745 mcs
.cy
= CW_USEDEFAULT
;
747 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
748 if (style
& wxMINIMIZE_BOX
)
749 msflags
|= WS_MINIMIZEBOX
;
750 if (style
& wxMAXIMIZE_BOX
)
751 msflags
|= WS_MAXIMIZEBOX
;
752 if (style
& wxRESIZE_BORDER
)
753 msflags
|= WS_THICKFRAME
;
754 if (style
& wxSYSTEM_MENU
)
755 msflags
|= WS_SYSMENU
;
756 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
757 msflags
|= WS_MINIMIZE
;
758 if (style
& wxMAXIMIZE
)
759 msflags
|= WS_MAXIMIZE
;
760 if (style
& wxCAPTION
)
761 msflags
|= WS_CAPTION
;
767 wxWindowCreationHook
hook(this);
769 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
770 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
774 wxLogLastError(_T("WM_MDICREATE"));
783 wxMDIChildFrame::~wxMDIChildFrame()
785 // will be destroyed by DestroyChildren() but reset them before calling it
786 // to avoid using dangling pointers if a callback comes in the meanwhile
788 m_frameToolBar
= NULL
;
791 m_frameStatusBar
= NULL
;
792 #endif // wxUSE_STATUSBAR
796 RemoveWindowMenu(NULL
, m_hMenu
);
801 bool wxMDIChildFrame::Show(bool show
)
803 m_needsInitialShow
= false;
805 if (!wxFrame::Show(show
))
808 // KH: Without this call, new MDI children do not become active.
809 // This was added here after the same BringWindowToTop call was
810 // removed from wxTopLevelWindow::Show (November 2005)
812 ::BringWindowToTop(GetHwnd());
814 // we need to refresh the MDI frame window menu to include (or exclude if
815 // we've been hidden) this frame
816 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
817 MDISetMenu(parent
->GetClientWindow(), NULL
, NULL
);
822 // Set the client size (i.e. leave the calculation of borders etc.
824 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
826 HWND hWnd
= GetHwnd();
829 ::GetClientRect(hWnd
, &rect
);
832 GetWindowRect(hWnd
, &rect2
);
834 // Find the difference between the entire window (title bar and all)
835 // and the client area; add this to the new client size to move the
837 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
838 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
841 if (GetStatusBar() && GetStatusBar()->IsShown())
844 GetStatusBar()->GetSize(&sx
, &sy
);
847 #endif // wxUSE_STATUSBAR
850 point
.x
= rect2
.left
;
853 // If there's an MDI parent, must subtract the parent's top left corner
854 // since MoveWindow moves relative to the parent
855 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
856 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
858 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
860 wxSize
size(width
, height
);
861 wxSizeEvent
event(size
, m_windowId
);
862 event
.SetEventObject( this );
863 GetEventHandler()->ProcessEvent(event
);
866 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
869 GetWindowRect(GetHwnd(), &rect
);
874 // Since we now have the absolute screen coords,
875 // if there's a parent we must subtract its top left corner
876 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
877 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
885 void wxMDIChildFrame::InternalSetMenuBar()
887 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
889 InsertWindowMenu(parent
->GetClientWindow(),
890 m_hMenu
, GetMDIWindowMenu(parent
));
892 parent
->m_parentFrameActive
= false;
895 void wxMDIChildFrame::DetachMenuBar()
897 RemoveWindowMenu(NULL
, m_hMenu
);
898 wxFrame::DetachMenuBar();
901 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
903 // we don't have any standard icons (any more)
907 // ---------------------------------------------------------------------------
909 // ---------------------------------------------------------------------------
911 void wxMDIChildFrame::Maximize(bool maximize
)
913 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
914 if ( parent
&& parent
->GetClientWindow() )
916 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
917 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
918 (WPARAM
)GetHwnd(), 0);
922 void wxMDIChildFrame::Restore()
924 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
925 if ( parent
&& parent
->GetClientWindow() )
927 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
928 (WPARAM
) GetHwnd(), 0);
932 void wxMDIChildFrame::Activate()
934 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
935 if ( parent
&& parent
->GetClientWindow() )
937 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
938 (WPARAM
) GetHwnd(), 0);
942 // ---------------------------------------------------------------------------
943 // MDI window proc and message handlers
944 // ---------------------------------------------------------------------------
946 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
951 bool processed
= false;
959 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
962 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
966 case WM_GETMINMAXINFO
:
967 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
973 WXHWND hwndAct
, hwndDeact
;
974 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
976 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
981 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
982 // scrollbars if necessary
987 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
989 MSWDefWindowProc(message
, wParam
, lParam
);
993 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
994 // the message (the base class version does not)
995 return MSWDefWindowProc(message
, wParam
, lParam
);
997 case WM_WINDOWPOSCHANGING
:
998 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
1003 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
1008 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
1010 // In case it's e.g. a toolbar.
1013 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
1015 return win
->MSWCommand(cmd
, id
);
1018 if (wxCurrentPopupMenu
)
1020 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1021 wxCurrentPopupMenu
= NULL
;
1022 if (popupMenu
->MSWCommand(cmd
, id
))
1027 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
1029 processed
= ProcessCommand(id
);
1039 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
1043 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1045 HMENU menuToSet
= 0;
1049 if ( m_hWnd
== hwndAct
)
1052 parent
->m_currentChild
= this;
1054 HMENU child_menu
= (HMENU
)GetWinMenu();
1057 parent
->m_parentFrameActive
= false;
1059 menuToSet
= child_menu
;
1062 else if ( m_hWnd
== hwndDeact
)
1064 wxASSERT_MSG( parent
->m_currentChild
== this,
1065 wxT("can't deactivate MDI child which wasn't active!") );
1068 parent
->m_currentChild
= NULL
;
1070 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1072 // activate the the parent menu only when there is no other child
1073 // that has been activated
1074 if ( parent_menu
&& !hwndAct
)
1076 parent
->m_parentFrameActive
= true;
1078 menuToSet
= parent_menu
;
1083 // we have nothing to do with it
1089 MDISetMenu(parent
->GetClientWindow(),
1090 menuToSet
, GetMDIWindowMenu(parent
));
1093 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1094 event
.SetEventObject( this );
1096 ResetWindowStyle((void *)NULL
);
1098 return GetEventHandler()->ProcessEvent(event
);
1101 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1103 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1105 if (!(lpPos
->flags
& SWP_NOSIZE
))
1108 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1109 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1110 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1112 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1113 lpPos
->x
= rectClient
.left
;
1114 lpPos
->y
= rectClient
.top
;
1115 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1116 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1123 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1125 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1127 // let the default window proc calculate the size of MDI children
1128 // frames because it is based on the size of the MDI client window,
1129 // not on the values specified in wxWindow m_max variables
1130 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1132 int minWidth
= GetMinWidth(),
1133 minHeight
= GetMinHeight();
1135 // but allow GetSizeHints() to set the min size
1136 if ( minWidth
!= wxDefaultCoord
)
1138 info
->ptMinTrackSize
.x
= minWidth
;
1143 if ( minHeight
!= wxDefaultCoord
)
1145 info
->ptMinTrackSize
.y
= minHeight
;
1153 // ---------------------------------------------------------------------------
1154 // MDI specific message translation/preprocessing
1155 // ---------------------------------------------------------------------------
1157 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1159 return DefMDIChildProc(GetHwnd(),
1160 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1163 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1165 // we must pass the parent frame to ::TranslateAccelerator(), otherwise it
1166 // doesn't do its job correctly for MDI child menus
1167 return MSWDoTranslateMessage((wxMDIChildFrame
*)GetParent(), msg
);
1170 // ---------------------------------------------------------------------------
1172 // ---------------------------------------------------------------------------
1174 void wxMDIChildFrame::MSWDestroyWindow()
1176 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1178 // Must make sure this handle is invalidated (set to NULL) since all sorts
1179 // of things could happen after the child client is destroyed, but before
1180 // the wxFrame is destroyed.
1182 HWND oldHandle
= (HWND
)GetHWND();
1183 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1184 (WPARAM
)oldHandle
, 0);
1186 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1187 ResetWindowStyle((void*) NULL
);
1191 ::DestroyMenu((HMENU
) m_hMenu
);
1194 wxRemoveHandleAssociation(this);
1198 // Change the client window's extended style so we don't get a client edge
1199 // style when a child is maximised (a double border looks silly.)
1200 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1202 RECT
*rect
= (RECT
*)vrect
;
1203 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1204 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1206 if (!pChild
|| (pChild
== this))
1208 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1209 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1211 // we want to test whether there is a maximized child, so just set
1212 // dwThisStyle to 0 if there is no child at all
1213 DWORD dwThisStyle
= pChild
1214 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1215 DWORD dwNewStyle
= dwStyle
;
1216 if ( dwThisStyle
& WS_MAXIMIZE
)
1217 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1219 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1221 if (dwStyle
!= dwNewStyle
)
1223 // force update of everything
1224 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1225 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1226 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1227 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1228 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1229 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1232 ::GetClientRect(hwndClient
, rect
);
1241 // ===========================================================================
1242 // wxMDIClientWindow: the window of predefined (by Windows) class which
1243 // contains the child frames
1244 // ===========================================================================
1246 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1248 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1250 CLIENTCREATESTRUCT ccs
;
1251 m_windowStyle
= style
;
1254 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1255 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1257 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1258 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1260 if ( style
& wxHSCROLL
)
1261 msStyle
|= WS_HSCROLL
;
1262 if ( style
& wxVSCROLL
)
1263 msStyle
|= WS_VSCROLL
;
1265 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1267 wxWindowCreationHook
hook(this);
1268 m_hWnd
= (WXHWND
)::CreateWindowEx
1278 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1281 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1286 SubclassWin(m_hWnd
);
1291 // Explicitly call default scroll behaviour
1292 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1294 // Note: for client windows, the scroll position is not set in
1295 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1296 // scroll position we're at.
1297 // This makes it hard to paint patterns or bitmaps in the background,
1298 // and have the client area scrollable as well.
1300 if ( event
.GetOrientation() == wxHORIZONTAL
)
1301 m_scrollX
= event
.GetPosition(); // Always returns zero!
1303 m_scrollY
= event
.GetPosition(); // Always returns zero!
1308 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1310 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1311 // client area, you can end up with a non-refreshed portion in the client window
1312 // (see OGL studio sample). So check if the position is changed and if so,
1313 // redraw the MDI child frames.
1315 const wxPoint oldPos
= GetPosition();
1317 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
| wxSIZE_FORCE
);
1319 const wxPoint newPos
= GetPosition();
1321 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1325 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1328 wxWindow
*child
= node
->GetData();
1329 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1331 ::RedrawWindow(GetHwndOf(child
),
1338 node
= node
->GetNext();
1344 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1346 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1347 // in flicker e.g. when the frame contained controls with non-trivial
1348 // layout. Since 2.5.3, the frame is created hidden as all other top level
1349 // windows. In order to maintain backward compatibility, the frame is shown
1350 // in OnIdle, unless Show(false) was called by the programmer before.
1351 if ( m_needsInitialShow
)
1356 // MDI child frames get their WM_SIZE when they're constructed but at this
1357 // moment they don't have any children yet so all child windows will be
1358 // positioned incorrectly when they are added later - to fix this, we
1359 // generate an artificial size event here
1360 if ( m_needsResize
)
1362 m_needsResize
= false; // avoid any possibility of recursion
1370 // ---------------------------------------------------------------------------
1371 // non member functions
1372 // ---------------------------------------------------------------------------
1374 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1376 if ( hmenuFrame
|| hmenuWindow
)
1378 if ( !::SendMessage(GetWinHwnd(win
),
1381 (LPARAM
)hmenuWindow
) )
1383 wxLogLastError(_T("SendMessage(WM_MDISETMENU)"));
1387 // update menu bar of the parent window
1388 wxWindow
*parent
= win
->GetParent();
1389 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1391 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1393 ::DrawMenuBar(GetWinHwnd(parent
));
1396 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1398 // Try to insert Window menu in front of Help, otherwise append it.
1399 HMENU hmenu
= (HMENU
)menu
;
1403 int N
= GetMenuItemCount(hmenu
);
1404 bool success
= false;
1405 for ( int i
= 0; i
< N
; i
++ )
1408 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1411 wxLogLastError(wxT("GetMenuString"));
1416 wxString
strBuf(buf
);
1417 if ( wxStripMenuCodes(strBuf
) == wxGetStockLabel(wxID_HELP
,false) )
1420 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1421 (UINT
)subMenu
, _("&Window"));
1428 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1432 MDISetMenu(win
, hmenu
, subMenu
);
1435 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1437 HMENU hMenu
= (HMENU
)menu
;
1443 int N
= ::GetMenuItemCount(hMenu
);
1444 for ( int i
= 0; i
< N
; i
++ )
1446 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1448 // Ignore successful read of menu string with length 0 which
1449 // occurs, for example, for a maximized MDI childs system menu
1450 if ( ::GetLastError() != 0 )
1452 wxLogLastError(wxT("GetMenuString"));
1458 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1460 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1462 wxLogLastError(wxT("RemoveMenu"));
1472 // we don't change the windows menu, but we update the main one
1473 MDISetMenu(win
, hMenu
, NULL
);
1477 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1478 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1481 *hwndAct
= (WXHWND
)lParam
;
1482 *hwndDeact
= (WXHWND
)wParam
;
1485 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)