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 // ---------------------------------------------------------------------------
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/dialog.h"
39 #include "wx/statusbr.h"
41 #include "wx/settings.h"
46 #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
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 #ifdef __DIGITALMARS__
72 extern "C" void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
74 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
76 extern void wxRemoveHandleAssociation(wxWindow
*win
);
78 static HWND invalidHandle
= 0;
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 static const int IDM_WINDOWTILE
= 4001;
85 static const int IDM_WINDOWTILEHOR
= 4001;
86 static const int IDM_WINDOWCASCADE
= 4002;
87 static const int IDM_WINDOWICONS
= 4003;
88 static const int IDM_WINDOWNEXT
= 4004;
89 static const int IDM_WINDOWTILEVERT
= 4005;
90 static const int IDM_WINDOWPREV
= 4006;
92 // This range gives a maximum of 500 MDI children. Should be enough :-)
93 static const int wxFIRST_MDI_CHILD
= 4100;
94 static const int wxLAST_MDI_CHILD
= 4600;
96 // Status border dimensions
97 static const int wxTHICK_LINE_BORDER
= 3;
98 static const int wxTHICK_LINE_WIDTH
= 1;
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
105 // of the parent of win (which is supposed to be the MDI client window)
106 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
108 // insert the window menu (subMenu) into menu just before "Help" submenu or at
109 // the very end if not found
110 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
112 // Remove the window menu
113 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
115 // is this an id of an MDI child?
116 inline bool IsMdiCommandId(int id
)
118 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
121 // unpack the parameters of WM_MDIACTIVATE message
122 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
123 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
125 // return the HMENU of the MDI menu
126 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
128 wxMenu
*menu
= frame
->GetWindowMenu();
129 return menu
? GetHmenuOf(menu
) : 0;
132 // ===========================================================================
134 // ===========================================================================
136 // ---------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
141 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
142 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
144 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
145 EVT_SIZE(wxMDIParentFrame::OnSize
)
146 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
149 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
150 EVT_IDLE(wxMDIChildFrame::OnIdle
)
153 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
154 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
157 // ===========================================================================
158 // wxMDIParentFrame: the frame which contains the client window which manages
160 // ===========================================================================
162 wxMDIParentFrame::wxMDIParentFrame()
164 m_clientWindow
= NULL
;
165 m_currentChild
= NULL
;
166 m_windowMenu
= (wxMenu
*) NULL
;
167 m_parentFrameActive
= true;
170 bool wxMDIParentFrame::Create(wxWindow
*parent
,
172 const wxString
& title
,
176 const wxString
& name
)
178 m_clientWindow
= NULL
;
179 m_currentChild
= NULL
;
181 // this style can be used to prevent a window from having the standard MDI
183 if ( style
& wxFRAME_NO_WINDOW_MENU
)
185 m_windowMenu
= (wxMenu
*)NULL
;
187 else // normal case: we have the window menu, so construct it
189 m_windowMenu
= new wxMenu
;
191 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
192 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
193 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
194 m_windowMenu
->AppendSeparator();
195 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
196 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
197 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
200 m_parentFrameActive
= true;
203 wxTopLevelWindows
.Append(this);
206 m_windowStyle
= style
;
209 parent
->AddChild(this);
214 m_windowId
= NewControlId();
217 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
218 msflags
&= ~WS_VSCROLL
;
219 msflags
&= ~WS_HSCROLL
;
221 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
230 wxModelessWindows
.Append(this);
232 // unlike (almost?) all other windows, frames are created hidden
238 wxMDIParentFrame::~wxMDIParentFrame()
242 // already delete by DestroyChildren()
243 m_frameToolBar
= NULL
;
244 m_frameStatusBar
= NULL
;
249 m_windowMenu
= (wxMenu
*) NULL
;
252 // the MDI frame menubar is not automatically deleted by Windows unlike for
256 ::DestroyMenu((HMENU
)m_hMenu
);
257 m_hMenu
= (WXHMENU
)NULL
;
260 if ( m_clientWindow
)
262 if ( m_clientWindow
->MSWGetOldWndProc() )
263 m_clientWindow
->UnsubclassWin();
265 m_clientWindow
->SetHWND(0);
266 delete m_clientWindow
;
270 #if wxUSE_MENUS_NATIVE
272 void wxMDIParentFrame::InternalSetMenuBar()
274 m_parentFrameActive
= true;
276 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
279 #endif // wxUSE_MENUS_NATIVE
281 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
287 // Remove old window menu
288 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
292 m_windowMenu
= (wxMenu
*) NULL
;
300 InsertWindowMenu(GetClientWindow(), m_hMenu
,
301 GetHmenuOf(m_windowMenu
));
306 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
308 if ( GetClientWindow() )
311 GetClientSize(&width
, &height
);
313 GetClientWindow()->SetSize(0, 0, width
, height
);
317 // Returns the active MDI child window
318 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
320 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
321 WM_MDIGETACTIVE
, 0, 0L);
325 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
328 // Create the client window class (don't Create the window, just return a new
330 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
332 return new wxMDIClientWindow
;
335 // Responds to colour changes, and passes event on to children.
336 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
338 if ( m_clientWindow
)
340 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
341 m_clientWindow
->Refresh();
347 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
349 return (WXHICON
)(wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
350 : wxDEFAULT_MDIPARENTFRAME_ICON
);
353 // ---------------------------------------------------------------------------
355 // ---------------------------------------------------------------------------
357 void wxMDIParentFrame::Cascade()
359 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
362 // TODO: add a direction argument (hor/vert)
363 void wxMDIParentFrame::Tile()
365 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
368 void wxMDIParentFrame::ArrangeIcons()
370 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
373 void wxMDIParentFrame::ActivateNext()
375 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
378 void wxMDIParentFrame::ActivatePrevious()
380 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
383 // ---------------------------------------------------------------------------
384 // the MDI parent frame window proc
385 // ---------------------------------------------------------------------------
387 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
392 bool processed
= false;
398 WXWORD state
, minimized
;
400 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
402 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
410 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
412 (void)HandleCommand(id
, cmd
, hwnd
);
414 // even if the frame didn't process it, there is no need to try it
415 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
416 // so pretend we processed the message anyhow
420 // always pass this message DefFrameProc(), otherwise MDI menu
421 // commands (and sys commands - more surprizingly!) won't work
422 MSWDefWindowProc(message
, wParam
, lParam
);
426 m_clientWindow
= OnCreateClient();
427 // Uses own style for client style
428 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
430 wxLogMessage(_("Failed to create MDI parent frame."));
441 // we erase background ourselves
449 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
451 if ( m_parentFrameActive
)
453 processed
= HandleMenuSelect(item
, flags
, hmenu
);
455 else if (m_currentChild
)
457 processed
= m_currentChild
->
458 HandleMenuSelect(item
, flags
, hmenu
);
464 // as we don't (usually) resize the MDI client to exactly fit the
465 // client area (we put it below the toolbar, above statusbar &c),
466 // we should not pass this one to DefFrameProc
471 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
476 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
478 bool processed
= false;
480 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
486 // If this window is an MDI parent, we must also send an OnActivate message
487 // to the current child.
488 if ( (m_currentChild
!= NULL
) &&
489 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
491 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
492 event
.SetEventObject( m_currentChild
);
493 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
500 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
502 // In case it's e.g. a toolbar.
505 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
507 return win
->MSWCommand(cmd
, id
);
510 // is it one of standard MDI commands?
516 case IDM_WINDOWCASCADE
:
518 wParam
= MDITILE_SKIPDISABLED
;
521 case IDM_WINDOWTILEHOR
:
522 wParam
|= MDITILE_HORIZONTAL
;
525 case IDM_WINDOWTILEVERT
:
527 wParam
= MDITILE_VERTICAL
;
529 wParam
|= MDITILE_SKIPDISABLED
;
532 case IDM_WINDOWICONS
:
533 msg
= WM_MDIICONARRANGE
;
538 lParam
= 0; // next child
543 lParam
= 1; // previous child
552 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
557 // FIXME VZ: what does this test do??
560 return false; // Get WndProc to call default proc
563 if ( IsMdiCommandId(id
) )
565 wxWindowList::Node
*node
= GetChildren().GetFirst();
568 wxWindow
*child
= node
->GetData();
569 if ( child
->GetHWND() )
571 long childId
= wxGetWindowId(child
->GetHWND());
572 if (childId
== (long)id
)
574 ::SendMessage( GetWinHwnd(GetClientWindow()),
576 (WPARAM
)child
->GetHWND(), 0);
580 node
= node
->GetNext();
583 else if ( m_parentFrameActive
)
585 return ProcessCommand(id
);
587 else if ( m_currentChild
)
589 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
593 // this shouldn't happen because it means that our messages are being
594 // lost (they're not sent to the parent frame nor to the children)
595 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
601 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
606 if ( GetClientWindow() )
607 clientWnd
= GetClientWindow()->GetHWND();
611 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
614 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
616 MSG
*pMsg
= (MSG
*)msg
;
618 // first let the current child get it
619 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
620 m_currentChild
->MSWTranslateMessage(msg
) )
625 // then try out accel table (will also check the menu accels)
626 if ( wxFrame::MSWTranslateMessage(msg
) )
631 // finally, check for MDI specific built in accel keys
632 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
634 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
641 // ===========================================================================
643 // ===========================================================================
645 void wxMDIChildFrame::Init()
647 m_needsResize
= true;
650 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
652 const wxString
& title
,
656 const wxString
& name
)
659 wxWindowBase::Show(true); // MDI child frame starts off shown
664 m_windowId
= (int)NewControlId();
668 parent
->AddChild(this);
678 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
679 ? wxMDIChildFrameClassNameNoRedraw
680 : wxMDIChildFrameClassName
;
682 mcs
.hOwner
= wxGetInstance();
686 mcs
.x
= CW_USEDEFAULT
;
691 mcs
.y
= CW_USEDEFAULT
;
696 mcs
.cx
= CW_USEDEFAULT
;
701 mcs
.cy
= CW_USEDEFAULT
;
703 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_THICKFRAME
| WS_VISIBLE
;
704 if (style
& wxMINIMIZE_BOX
)
705 msflags
|= WS_MINIMIZEBOX
;
706 if (style
& wxMAXIMIZE_BOX
)
707 msflags
|= WS_MAXIMIZEBOX
;
708 if (style
& wxTHICK_FRAME
)
709 msflags
|= WS_THICKFRAME
;
710 if (style
& wxSYSTEM_MENU
)
711 msflags
|= WS_SYSMENU
;
712 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
713 msflags
|= WS_MINIMIZE
;
714 if (style
& wxMAXIMIZE
)
715 msflags
|= WS_MAXIMIZE
;
716 if (style
& wxCAPTION
)
717 msflags
|= WS_CAPTION
;
723 wxWindowCreationHook
hook(this);
725 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
726 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
728 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
730 wxModelessWindows
.Append(this);
735 wxMDIChildFrame::~wxMDIChildFrame()
739 // already deleted by DestroyChildren()
740 m_frameToolBar
= NULL
;
741 m_frameStatusBar
= NULL
;
743 RemoveWindowMenu(NULL
, m_hMenu
);
748 // Set the client size (i.e. leave the calculation of borders etc.
750 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
752 HWND hWnd
= GetHwnd();
755 ::GetClientRect(hWnd
, &rect
);
758 GetWindowRect(hWnd
, &rect2
);
760 // Find the difference between the entire window (title bar and all)
761 // and the client area; add this to the new client size to move the
763 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
764 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
766 if (GetStatusBar() && GetStatusBar()->IsShown())
769 GetStatusBar()->GetSize(&sx
, &sy
);
774 point
.x
= rect2
.left
;
777 // If there's an MDI parent, must subtract the parent's top left corner
778 // since MoveWindow moves relative to the parent
779 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
780 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
782 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
784 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
785 event
.SetEventObject( this );
786 GetEventHandler()->ProcessEvent(event
);
789 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
792 GetWindowRect(GetHwnd(), &rect
);
797 // Since we now have the absolute screen coords,
798 // if there's a parent we must subtract its top left corner
799 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
800 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
806 void wxMDIChildFrame::InternalSetMenuBar()
808 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
810 InsertWindowMenu(parent
->GetClientWindow(),
811 m_hMenu
, GetMDIWindowMenu(parent
));
813 parent
->m_parentFrameActive
= false;
816 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
818 return (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
819 : wxDEFAULT_MDICHILDFRAME_ICON
);
822 // ---------------------------------------------------------------------------
824 // ---------------------------------------------------------------------------
826 void wxMDIChildFrame::Maximize(bool maximize
)
828 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
829 if ( parent
&& parent
->GetClientWindow() )
831 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
832 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
833 (WPARAM
)GetHwnd(), 0);
837 void wxMDIChildFrame::Restore()
839 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
840 if ( parent
&& parent
->GetClientWindow() )
842 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
843 (WPARAM
) GetHwnd(), 0);
847 void wxMDIChildFrame::Activate()
849 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
850 if ( parent
&& parent
->GetClientWindow() )
852 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
853 (WPARAM
) GetHwnd(), 0);
857 // ---------------------------------------------------------------------------
858 // MDI window proc and message handlers
859 // ---------------------------------------------------------------------------
861 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
866 bool processed
= false;
874 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
877 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
881 case WM_GETMINMAXINFO
:
882 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
888 WXHWND hwndAct
, hwndDeact
;
889 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
891 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
896 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
897 // scrollbars if necessary
902 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
904 MSWDefWindowProc(message
, wParam
, lParam
);
908 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
909 // the message (the base class version does not)
910 return MSWDefWindowProc(message
, wParam
, lParam
);
912 case WM_WINDOWPOSCHANGING
:
913 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
918 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
923 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
925 // In case it's e.g. a toolbar.
928 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
930 return win
->MSWCommand(cmd
, id
);
933 if (wxCurrentPopupMenu
)
935 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
936 wxCurrentPopupMenu
= NULL
;
937 if (popupMenu
->MSWCommand(cmd
, id
))
942 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
944 processed
= ProcessCommand(id
);
954 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
958 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
964 if ( m_hWnd
== hwndAct
)
967 parent
->m_currentChild
= this;
969 HMENU child_menu
= (HMENU
)GetWinMenu();
972 parent
->m_parentFrameActive
= false;
974 menuToSet
= child_menu
;
977 else if ( m_hWnd
== hwndDeact
)
979 wxASSERT_MSG( parent
->m_currentChild
== this,
980 wxT("can't deactivate MDI child which wasn't active!") );
983 parent
->m_currentChild
= NULL
;
985 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
987 // activate the the parent menu only when there is no other child
988 // that has been activated
989 if ( parent_menu
&& !hwndAct
)
991 parent
->m_parentFrameActive
= true;
993 menuToSet
= parent_menu
;
998 // we have nothing to do with it
1004 MDISetMenu(parent
->GetClientWindow(),
1005 menuToSet
, GetMDIWindowMenu(parent
));
1008 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1009 event
.SetEventObject( this );
1011 ResetWindowStyle((void *)NULL
);
1013 return GetEventHandler()->ProcessEvent(event
);
1016 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1018 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1019 #if defined(__WIN95__)
1020 if (!(lpPos
->flags
& SWP_NOSIZE
))
1023 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1024 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1025 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1027 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1028 lpPos
->x
= rectClient
.left
;
1029 lpPos
->y
= rectClient
.top
;
1030 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1031 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1033 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1034 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1036 pFrameWnd
->GetToolBar()->Refresh();
1044 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1046 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1048 // let the default window proc calculate the size of MDI children
1049 // frames because it is based on the size of the MDI client window,
1050 // not on the values specified in wxWindow m_max variables
1051 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1053 int minWidth
= GetMinWidth(),
1054 minHeight
= GetMinHeight();
1056 // but allow GetSizeHints() to set the min size
1057 if ( minWidth
!= -1 )
1059 info
->ptMinTrackSize
.x
= minWidth
;
1064 if ( minHeight
!= -1 )
1066 info
->ptMinTrackSize
.y
= minHeight
;
1074 // ---------------------------------------------------------------------------
1075 // MDI specific message translation/preprocessing
1076 // ---------------------------------------------------------------------------
1078 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1080 return DefMDIChildProc(GetHwnd(),
1081 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1084 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1086 return wxFrame::MSWTranslateMessage(msg
);
1089 // ---------------------------------------------------------------------------
1091 // ---------------------------------------------------------------------------
1093 void wxMDIChildFrame::MSWDestroyWindow()
1095 invalidHandle
= GetHwnd();
1097 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1099 // Must make sure this handle is invalidated (set to NULL) since all sorts
1100 // of things could happen after the child client is destroyed, but before
1101 // the wxFrame is destroyed.
1103 HWND oldHandle
= (HWND
)GetHWND();
1104 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1105 (WPARAM
)oldHandle
, 0);
1107 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1108 ResetWindowStyle((void*) NULL
);
1114 ::DestroyMenu((HMENU
) m_hMenu
);
1117 wxRemoveHandleAssociation(this);
1121 // Change the client window's extended style so we don't get a client edge
1122 // style when a child is maximised (a double border looks silly.)
1123 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1125 #if defined(__WIN95__)
1126 RECT
*rect
= (RECT
*)vrect
;
1127 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1128 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1129 if (!pChild
|| (pChild
== this))
1131 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1132 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1134 // we want to test whether there is a maximized child, so just set
1135 // dwThisStyle to 0 if there is no child at all
1136 DWORD dwThisStyle
= pChild
1137 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1138 DWORD dwNewStyle
= dwStyle
;
1139 if ( dwThisStyle
& WS_MAXIMIZE
)
1140 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1142 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1144 if (dwStyle
!= dwNewStyle
)
1146 // force update of everything
1147 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1148 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1149 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1150 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1151 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1152 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1155 ::GetClientRect(hwndClient
, rect
);
1165 // ===========================================================================
1166 // wxMDIClientWindow: the window of predefined (by Windows) class which
1167 // contains the child frames
1168 // ===========================================================================
1170 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1172 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1174 CLIENTCREATESTRUCT ccs
;
1175 m_windowStyle
= style
;
1178 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1179 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1181 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1182 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1184 if ( style
& wxHSCROLL
)
1185 msStyle
|= WS_HSCROLL
;
1186 if ( style
& wxVSCROLL
)
1187 msStyle
|= WS_VSCROLL
;
1189 #if defined(__WIN95__)
1190 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1195 wxWindowCreationHook
hook(this);
1196 m_hWnd
= (WXHWND
)::CreateWindowEx
1206 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1209 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1214 SubclassWin(m_hWnd
);
1219 // Explicitly call default scroll behaviour
1220 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1222 // Note: for client windows, the scroll position is not set in
1223 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1224 // scroll position we're at.
1225 // This makes it hard to paint patterns or bitmaps in the background,
1226 // and have the client area scrollable as well.
1228 if ( event
.GetOrientation() == wxHORIZONTAL
)
1229 m_scrollX
= event
.GetPosition(); // Always returns zero!
1231 m_scrollY
= event
.GetPosition(); // Always returns zero!
1236 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1238 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1239 // client area, you can end up with a non-refreshed portion in the client window
1240 // (see OGL studio sample). So check if the position is changed and if so,
1241 // redraw the MDI child frames.
1243 wxPoint oldPos
= GetPosition();
1245 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1247 wxPoint newPos
= GetPosition();
1249 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1253 wxWindowList::Node
*node
= GetParent()->GetChildren().GetFirst();
1256 wxWindow
*child
= node
->GetData();
1257 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1259 ::RedrawWindow(GetHwndOf(child
),
1266 node
= node
->GetNext();
1272 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1274 // MDI child frames get their WM_SIZE when they're constructed but at this
1275 // moment they don't have any children yet so all child windows will be
1276 // positioned incorrectly when they are added later - to fix this, we
1277 // generate an artificial size event here
1278 if ( m_needsResize
)
1280 m_needsResize
= false; // avoid any possibility of recursion
1288 // ---------------------------------------------------------------------------
1289 // non member functions
1290 // ---------------------------------------------------------------------------
1292 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1294 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1296 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1298 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1302 // update menu bar of the parent window
1303 wxWindow
*parent
= win
->GetParent();
1304 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1307 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1310 ::DrawMenuBar(GetWinHwnd(parent
));
1313 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1315 // Try to insert Window menu in front of Help, otherwise append it.
1316 HMENU hmenu
= (HMENU
)menu
;
1320 int N
= GetMenuItemCount(hmenu
);
1321 bool success
= false;
1322 for ( int i
= 0; i
< N
; i
++ )
1325 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1328 wxLogLastError(wxT("GetMenuString"));
1333 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1336 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1337 (UINT
)subMenu
, _("&Window"));
1344 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1348 MDISetMenu(win
, hmenu
, subMenu
);
1351 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1353 HMENU hMenu
= (HMENU
)menu
;
1359 int N
= ::GetMenuItemCount(hMenu
);
1360 for ( int i
= 0; i
< N
; i
++ )
1362 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1364 // Ignore successful read of menu string with length 0 which
1365 // occurs, for example, for a maximized MDI childs system menu
1366 if ( ::GetLastError() != 0 )
1368 wxLogLastError(wxT("GetMenuString"));
1374 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1376 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1378 wxLogLastError(wxT("RemoveMenu"));
1388 // we don't change the windows menu, but we update the main one
1389 MDISetMenu(win
, hMenu
, NULL
);
1393 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1394 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1398 *hwndAct
= (WXHWND
)lParam
;
1399 *hwndDeact
= (WXHWND
)wParam
;
1401 *activate
= (WXWORD
)wParam
;
1402 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1403 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1404 #endif // Win32/Win16
1408 // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)