1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
39 #include "wx/dialog.h"
41 #include "wx/statusbr.h"
43 #include "wx/settings.h"
49 #include "wx/msw/private.h"
51 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
52 #include "wx/msw/statbr95.h"
56 #include "wx/toolbar.h"
57 #endif // wxUSE_TOOLBAR
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 extern wxWindowList wxModelessWindows
; // from dialog.cpp
66 extern wxMenu
*wxCurrentPopupMenu
;
68 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
69 extern const wxChar
*wxMDIChildFrameClassName
;
70 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
71 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
72 extern void wxRemoveHandleAssociation(wxWindow
*win
);
74 static HWND invalidHandle
= 0;
76 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
80 static const int IDM_WINDOWTILE
= 4001;
81 static const int IDM_WINDOWTILEHOR
= 4001;
82 static const int IDM_WINDOWCASCADE
= 4002;
83 static const int IDM_WINDOWICONS
= 4003;
84 static const int IDM_WINDOWNEXT
= 4004;
85 static const int IDM_WINDOWTILEVERT
= 4005;
86 static const int IDM_WINDOWPREV
= 4006;
88 // This range gives a maximum of 500 MDI children. Should be enough :-)
89 static const int wxFIRST_MDI_CHILD
= 4100;
90 static const int wxLAST_MDI_CHILD
= 4600;
92 // Status border dimensions
93 static const int wxTHICK_LINE_BORDER
= 3;
94 static const int wxTHICK_LINE_WIDTH
= 1;
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
101 // of the parent of win (which is supposed to be the MDI client window)
102 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
104 // insert the window menu (subMenu) into menu just before "Help" submenu or at
105 // the very end if not found
106 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
108 // Remove the window menu
109 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
111 // is this an id of an MDI child?
112 inline bool IsMdiCommandId(int id
)
114 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
117 // unpack the parameters of WM_MDIACTIVATE message
118 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
119 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
121 // return the HMENU of the MDI menu
122 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
124 wxMenu
*menu
= frame
->GetWindowMenu();
125 return menu
? GetHmenuOf(menu
) : 0;
128 // ===========================================================================
130 // ===========================================================================
132 // ---------------------------------------------------------------------------
134 // ---------------------------------------------------------------------------
136 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
137 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
138 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
140 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
141 EVT_SIZE(wxMDIParentFrame::OnSize
)
142 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
145 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
146 EVT_IDLE(wxMDIChildFrame::OnIdle
)
149 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
150 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
153 // ===========================================================================
154 // wxMDIParentFrame: the frame which contains the client window which manages
156 // ===========================================================================
158 wxMDIParentFrame::wxMDIParentFrame()
160 m_clientWindow
= NULL
;
161 m_currentChild
= NULL
;
162 m_windowMenu
= (wxMenu
*) NULL
;
163 m_parentFrameActive
= true;
166 bool wxMDIParentFrame::Create(wxWindow
*parent
,
168 const wxString
& title
,
172 const wxString
& name
)
174 m_clientWindow
= NULL
;
175 m_currentChild
= NULL
;
177 // this style can be used to prevent a window from having the standard MDI
179 if ( style
& wxFRAME_NO_WINDOW_MENU
)
181 m_windowMenu
= (wxMenu
*)NULL
;
183 else // normal case: we have the window menu, so construct it
185 m_windowMenu
= new wxMenu
;
187 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
188 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
189 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
190 m_windowMenu
->AppendSeparator();
191 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
192 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
193 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
196 m_parentFrameActive
= true;
199 wxTopLevelWindows
.Append(this);
202 m_windowStyle
= style
;
205 parent
->AddChild(this);
210 m_windowId
= NewControlId();
213 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
214 msflags
&= ~WS_VSCROLL
;
215 msflags
&= ~WS_HSCROLL
;
217 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
226 wxModelessWindows
.Append(this);
228 // unlike (almost?) all other windows, frames are created hidden
234 wxMDIParentFrame::~wxMDIParentFrame()
238 // already delete by DestroyChildren()
239 m_frameToolBar
= NULL
;
240 m_frameStatusBar
= NULL
;
245 m_windowMenu
= (wxMenu
*) NULL
;
248 // the MDI frame menubar is not automatically deleted by Windows unlike for
252 ::DestroyMenu((HMENU
)m_hMenu
);
253 m_hMenu
= (WXHMENU
)NULL
;
256 if ( m_clientWindow
)
258 if ( m_clientWindow
->MSWGetOldWndProc() )
259 m_clientWindow
->UnsubclassWin();
261 m_clientWindow
->SetHWND(0);
262 delete m_clientWindow
;
266 #if wxUSE_MENUS_NATIVE
268 void wxMDIParentFrame::InternalSetMenuBar()
270 m_parentFrameActive
= true;
272 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
275 #endif // wxUSE_MENUS_NATIVE
277 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
283 // Remove old window menu
284 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
288 m_windowMenu
= (wxMenu
*) NULL
;
296 InsertWindowMenu(GetClientWindow(), m_hMenu
,
297 GetHmenuOf(m_windowMenu
));
302 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
304 if ( GetClientWindow() )
307 GetClientSize(&width
, &height
);
309 GetClientWindow()->SetSize(0, 0, width
, height
);
313 // Returns the active MDI child window
314 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
316 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
317 WM_MDIGETACTIVE
, 0, 0L);
321 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
324 // Create the client window class (don't Create the window, just return a new
326 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
328 return new wxMDIClientWindow
;
331 // Responds to colour changes, and passes event on to children.
332 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
334 if ( m_clientWindow
)
336 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
337 m_clientWindow
->Refresh();
343 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
345 // we don't have any standard icons (any more)
349 // ---------------------------------------------------------------------------
351 // ---------------------------------------------------------------------------
353 void wxMDIParentFrame::Cascade()
355 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
358 // TODO: add a direction argument (hor/vert)
359 void wxMDIParentFrame::Tile()
361 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
364 void wxMDIParentFrame::ArrangeIcons()
366 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
369 void wxMDIParentFrame::ActivateNext()
371 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
374 void wxMDIParentFrame::ActivatePrevious()
376 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
379 // ---------------------------------------------------------------------------
380 // the MDI parent frame window proc
381 // ---------------------------------------------------------------------------
383 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
388 bool processed
= false;
394 WXWORD state
, minimized
;
396 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
398 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
406 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
408 (void)HandleCommand(id
, cmd
, hwnd
);
410 // even if the frame didn't process it, there is no need to try it
411 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
412 // so pretend we processed the message anyhow
416 // always pass this message DefFrameProc(), otherwise MDI menu
417 // commands (and sys commands - more surprisingly!) won't work
418 MSWDefWindowProc(message
, wParam
, lParam
);
422 m_clientWindow
= OnCreateClient();
423 // Uses own style for client style
424 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
426 wxLogMessage(_("Failed to create MDI parent frame."));
437 // we erase background ourselves
445 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
447 if ( m_parentFrameActive
)
449 processed
= HandleMenuSelect(item
, flags
, hmenu
);
451 else if (m_currentChild
)
453 processed
= m_currentChild
->
454 HandleMenuSelect(item
, flags
, hmenu
);
460 // as we don't (usually) resize the MDI client to exactly fit the
461 // client area (we put it below the toolbar, above statusbar &c),
462 // we should not pass this one to DefFrameProc
467 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
472 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
474 bool processed
= false;
476 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
482 // If this window is an MDI parent, we must also send an OnActivate message
483 // to the current child.
484 if ( (m_currentChild
!= NULL
) &&
485 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
487 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
488 event
.SetEventObject( m_currentChild
);
489 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
496 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
498 // In case it's e.g. a toolbar.
501 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
503 return win
->MSWCommand(cmd
, id
);
506 // is it one of standard MDI commands?
512 case IDM_WINDOWCASCADE
:
514 wParam
= MDITILE_SKIPDISABLED
;
517 case IDM_WINDOWTILEHOR
:
518 wParam
|= MDITILE_HORIZONTAL
;
521 case IDM_WINDOWTILEVERT
:
523 wParam
= MDITILE_VERTICAL
;
525 wParam
|= MDITILE_SKIPDISABLED
;
528 case IDM_WINDOWICONS
:
529 msg
= WM_MDIICONARRANGE
;
534 lParam
= 0; // next child
539 lParam
= 1; // previous child
548 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
553 // FIXME VZ: what does this test do??
556 return false; // Get WndProc to call default proc
559 if ( IsMdiCommandId(id
) )
561 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
564 wxWindow
*child
= node
->GetData();
565 if ( child
->GetHWND() )
567 long childId
= wxGetWindowId(child
->GetHWND());
568 if (childId
== (long)id
)
570 ::SendMessage( GetWinHwnd(GetClientWindow()),
572 (WPARAM
)child
->GetHWND(), 0);
576 node
= node
->GetNext();
579 else if ( m_parentFrameActive
)
581 return ProcessCommand(id
);
583 else if ( m_currentChild
)
585 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
589 // this shouldn't happen because it means that our messages are being
590 // lost (they're not sent to the parent frame nor to the children)
591 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
597 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
602 if ( GetClientWindow() )
603 clientWnd
= GetClientWindow()->GetHWND();
607 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
610 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
612 MSG
*pMsg
= (MSG
*)msg
;
614 // first let the current child get it
615 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
616 m_currentChild
->MSWTranslateMessage(msg
) )
621 // then try out accel table (will also check the menu accels)
622 if ( wxFrame::MSWTranslateMessage(msg
) )
627 // finally, check for MDI specific built in accel keys
628 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
630 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
637 // ===========================================================================
639 // ===========================================================================
641 void wxMDIChildFrame::Init()
643 m_needsResize
= true;
646 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
648 const wxString
& title
,
652 const wxString
& name
)
655 wxWindowBase::Show(true); // MDI child frame starts off shown
660 m_windowId
= (int)NewControlId();
664 parent
->AddChild(this);
674 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
675 ? wxMDIChildFrameClassName
676 : wxMDIChildFrameClassNameNoRedraw
;
678 mcs
.hOwner
= wxGetInstance();
682 mcs
.x
= CW_USEDEFAULT
;
687 mcs
.y
= CW_USEDEFAULT
;
692 mcs
.cx
= CW_USEDEFAULT
;
697 mcs
.cy
= CW_USEDEFAULT
;
699 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_THICKFRAME
| WS_VISIBLE
;
700 if (style
& wxMINIMIZE_BOX
)
701 msflags
|= WS_MINIMIZEBOX
;
702 if (style
& wxMAXIMIZE_BOX
)
703 msflags
|= WS_MAXIMIZEBOX
;
704 if (style
& wxTHICK_FRAME
)
705 msflags
|= WS_THICKFRAME
;
706 if (style
& wxSYSTEM_MENU
)
707 msflags
|= WS_SYSMENU
;
708 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
709 msflags
|= WS_MINIMIZE
;
710 if (style
& wxMAXIMIZE
)
711 msflags
|= WS_MAXIMIZE
;
712 if (style
& wxCAPTION
)
713 msflags
|= WS_CAPTION
;
719 wxWindowCreationHook
hook(this);
721 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
722 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
724 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
726 wxModelessWindows
.Append(this);
731 wxMDIChildFrame::~wxMDIChildFrame()
735 // already deleted by DestroyChildren()
736 m_frameToolBar
= NULL
;
737 m_frameStatusBar
= NULL
;
739 RemoveWindowMenu(NULL
, m_hMenu
);
744 // Set the client size (i.e. leave the calculation of borders etc.
746 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
748 HWND hWnd
= GetHwnd();
751 ::GetClientRect(hWnd
, &rect
);
754 GetWindowRect(hWnd
, &rect2
);
756 // Find the difference between the entire window (title bar and all)
757 // and the client area; add this to the new client size to move the
759 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
760 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
762 if (GetStatusBar() && GetStatusBar()->IsShown())
765 GetStatusBar()->GetSize(&sx
, &sy
);
770 point
.x
= rect2
.left
;
773 // If there's an MDI parent, must subtract the parent's top left corner
774 // since MoveWindow moves relative to the parent
775 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
776 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
778 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
780 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
781 event
.SetEventObject( this );
782 GetEventHandler()->ProcessEvent(event
);
785 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
788 GetWindowRect(GetHwnd(), &rect
);
793 // Since we now have the absolute screen coords,
794 // if there's a parent we must subtract its top left corner
795 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
796 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
802 void wxMDIChildFrame::InternalSetMenuBar()
804 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
806 InsertWindowMenu(parent
->GetClientWindow(),
807 m_hMenu
, GetMDIWindowMenu(parent
));
809 parent
->m_parentFrameActive
= false;
812 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
814 // we don't have any standard icons (any more)
818 // ---------------------------------------------------------------------------
820 // ---------------------------------------------------------------------------
822 void wxMDIChildFrame::Maximize(bool maximize
)
824 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
825 if ( parent
&& parent
->GetClientWindow() )
827 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
828 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
829 (WPARAM
)GetHwnd(), 0);
833 void wxMDIChildFrame::Restore()
835 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
836 if ( parent
&& parent
->GetClientWindow() )
838 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
839 (WPARAM
) GetHwnd(), 0);
843 void wxMDIChildFrame::Activate()
845 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
846 if ( parent
&& parent
->GetClientWindow() )
848 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
849 (WPARAM
) GetHwnd(), 0);
853 // ---------------------------------------------------------------------------
854 // MDI window proc and message handlers
855 // ---------------------------------------------------------------------------
857 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
862 bool processed
= false;
870 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
873 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
877 case WM_GETMINMAXINFO
:
878 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
884 WXHWND hwndAct
, hwndDeact
;
885 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
887 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
892 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
893 // scrollbars if necessary
898 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
900 MSWDefWindowProc(message
, wParam
, lParam
);
904 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
905 // the message (the base class version does not)
906 return MSWDefWindowProc(message
, wParam
, lParam
);
908 case WM_WINDOWPOSCHANGING
:
909 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
914 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
919 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
921 // In case it's e.g. a toolbar.
924 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
926 return win
->MSWCommand(cmd
, id
);
929 if (wxCurrentPopupMenu
)
931 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
932 wxCurrentPopupMenu
= NULL
;
933 if (popupMenu
->MSWCommand(cmd
, id
))
938 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
940 processed
= ProcessCommand(id
);
950 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
954 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
960 if ( m_hWnd
== hwndAct
)
963 parent
->m_currentChild
= this;
965 HMENU child_menu
= (HMENU
)GetWinMenu();
968 parent
->m_parentFrameActive
= false;
970 menuToSet
= child_menu
;
973 else if ( m_hWnd
== hwndDeact
)
975 wxASSERT_MSG( parent
->m_currentChild
== this,
976 wxT("can't deactivate MDI child which wasn't active!") );
979 parent
->m_currentChild
= NULL
;
981 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
983 // activate the the parent menu only when there is no other child
984 // that has been activated
985 if ( parent_menu
&& !hwndAct
)
987 parent
->m_parentFrameActive
= true;
989 menuToSet
= parent_menu
;
994 // we have nothing to do with it
1000 MDISetMenu(parent
->GetClientWindow(),
1001 menuToSet
, GetMDIWindowMenu(parent
));
1004 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1005 event
.SetEventObject( this );
1007 ResetWindowStyle((void *)NULL
);
1009 return GetEventHandler()->ProcessEvent(event
);
1012 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1014 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1015 #if defined(__WIN95__)
1016 if (!(lpPos
->flags
& SWP_NOSIZE
))
1019 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1020 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1021 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1023 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1024 lpPos
->x
= rectClient
.left
;
1025 lpPos
->y
= rectClient
.top
;
1026 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1027 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1029 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1030 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1032 pFrameWnd
->GetToolBar()->Refresh();
1040 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1042 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1044 // let the default window proc calculate the size of MDI children
1045 // frames because it is based on the size of the MDI client window,
1046 // not on the values specified in wxWindow m_max variables
1047 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1049 int minWidth
= GetMinWidth(),
1050 minHeight
= GetMinHeight();
1052 // but allow GetSizeHints() to set the min size
1053 if ( minWidth
!= -1 )
1055 info
->ptMinTrackSize
.x
= minWidth
;
1060 if ( minHeight
!= -1 )
1062 info
->ptMinTrackSize
.y
= minHeight
;
1070 // ---------------------------------------------------------------------------
1071 // MDI specific message translation/preprocessing
1072 // ---------------------------------------------------------------------------
1074 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1076 return DefMDIChildProc(GetHwnd(),
1077 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1080 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1082 return wxFrame::MSWTranslateMessage(msg
);
1085 // ---------------------------------------------------------------------------
1087 // ---------------------------------------------------------------------------
1089 void wxMDIChildFrame::MSWDestroyWindow()
1091 invalidHandle
= GetHwnd();
1093 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1095 // Must make sure this handle is invalidated (set to NULL) since all sorts
1096 // of things could happen after the child client is destroyed, but before
1097 // the wxFrame is destroyed.
1099 HWND oldHandle
= (HWND
)GetHWND();
1100 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1101 (WPARAM
)oldHandle
, 0);
1103 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1104 ResetWindowStyle((void*) NULL
);
1110 ::DestroyMenu((HMENU
) m_hMenu
);
1113 wxRemoveHandleAssociation(this);
1117 // Change the client window's extended style so we don't get a client edge
1118 // style when a child is maximised (a double border looks silly.)
1119 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1121 #if defined(__WIN95__)
1122 RECT
*rect
= (RECT
*)vrect
;
1123 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1124 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1125 if (!pChild
|| (pChild
== this))
1127 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1128 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1130 // we want to test whether there is a maximized child, so just set
1131 // dwThisStyle to 0 if there is no child at all
1132 DWORD dwThisStyle
= pChild
1133 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1134 DWORD dwNewStyle
= dwStyle
;
1135 if ( dwThisStyle
& WS_MAXIMIZE
)
1136 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1138 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1140 if (dwStyle
!= dwNewStyle
)
1142 // force update of everything
1143 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1144 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1145 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1146 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1147 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1148 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1151 ::GetClientRect(hwndClient
, rect
);
1161 // ===========================================================================
1162 // wxMDIClientWindow: the window of predefined (by Windows) class which
1163 // contains the child frames
1164 // ===========================================================================
1166 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1168 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1170 CLIENTCREATESTRUCT ccs
;
1171 m_windowStyle
= style
;
1174 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1175 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1177 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1178 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1180 if ( style
& wxHSCROLL
)
1181 msStyle
|= WS_HSCROLL
;
1182 if ( style
& wxVSCROLL
)
1183 msStyle
|= WS_VSCROLL
;
1185 #if defined(__WIN95__)
1186 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1191 wxWindowCreationHook
hook(this);
1192 m_hWnd
= (WXHWND
)::CreateWindowEx
1202 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1205 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1210 SubclassWin(m_hWnd
);
1215 // Explicitly call default scroll behaviour
1216 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1218 // Note: for client windows, the scroll position is not set in
1219 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1220 // scroll position we're at.
1221 // This makes it hard to paint patterns or bitmaps in the background,
1222 // and have the client area scrollable as well.
1224 if ( event
.GetOrientation() == wxHORIZONTAL
)
1225 m_scrollX
= event
.GetPosition(); // Always returns zero!
1227 m_scrollY
= event
.GetPosition(); // Always returns zero!
1232 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1234 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1235 // client area, you can end up with a non-refreshed portion in the client window
1236 // (see OGL studio sample). So check if the position is changed and if so,
1237 // redraw the MDI child frames.
1239 wxPoint oldPos
= GetPosition();
1241 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1243 wxPoint newPos
= GetPosition();
1245 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1249 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1252 wxWindow
*child
= node
->GetData();
1253 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1255 ::RedrawWindow(GetHwndOf(child
),
1262 node
= node
->GetNext();
1268 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1270 // MDI child frames get their WM_SIZE when they're constructed but at this
1271 // moment they don't have any children yet so all child windows will be
1272 // positioned incorrectly when they are added later - to fix this, we
1273 // generate an artificial size event here
1274 if ( m_needsResize
)
1276 m_needsResize
= false; // avoid any possibility of recursion
1284 // ---------------------------------------------------------------------------
1285 // non member functions
1286 // ---------------------------------------------------------------------------
1288 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1290 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1292 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1294 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1298 // update menu bar of the parent window
1299 wxWindow
*parent
= win
->GetParent();
1300 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1303 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1306 ::DrawMenuBar(GetWinHwnd(parent
));
1309 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1311 // Try to insert Window menu in front of Help, otherwise append it.
1312 HMENU hmenu
= (HMENU
)menu
;
1316 int N
= GetMenuItemCount(hmenu
);
1317 bool success
= false;
1318 for ( int i
= 0; i
< N
; i
++ )
1321 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1324 wxLogLastError(wxT("GetMenuString"));
1329 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1332 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1333 (UINT
)subMenu
, _("&Window"));
1340 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1344 MDISetMenu(win
, hmenu
, subMenu
);
1347 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1349 HMENU hMenu
= (HMENU
)menu
;
1355 int N
= ::GetMenuItemCount(hMenu
);
1356 for ( int i
= 0; i
< N
; i
++ )
1358 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1360 // Ignore successful read of menu string with length 0 which
1361 // occurs, for example, for a maximized MDI childs system menu
1362 if ( ::GetLastError() != 0 )
1364 wxLogLastError(wxT("GetMenuString"));
1370 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1372 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1374 wxLogLastError(wxT("RemoveMenu"));
1384 // we don't change the windows menu, but we update the main one
1385 MDISetMenu(win
, hMenu
, NULL
);
1389 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1390 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1394 *hwndAct
= (WXHWND
)lParam
;
1395 *hwndDeact
= (WXHWND
)wParam
;
1397 *activate
= (WXWORD
)wParam
;
1398 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1399 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1400 #endif // Win32/Win16
1404 // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)