1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
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"
47 #include "wx/msw/private.h"
49 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
50 #include "wx/msw/statbr95.h"
54 #include "wx/toolbar.h"
55 #endif // wxUSE_TOOLBAR
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 extern wxWindowList wxModelessWindows
; // from dialog.cpp
64 extern wxMenu
*wxCurrentPopupMenu
;
66 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
67 extern const wxChar
*wxMDIChildFrameClassName
;
68 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
70 extern wxWindow
*wxWndHook
; // from window.cpp
72 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
73 extern void wxRemoveHandleAssociation(wxWindow
*win
);
75 static HWND invalidHandle
= 0;
77 // ---------------------------------------------------------------------------
79 // ---------------------------------------------------------------------------
81 static const int IDM_WINDOWTILE
= 4001;
82 static const int IDM_WINDOWTILEHOR
= 4001;
83 static const int IDM_WINDOWCASCADE
= 4002;
84 static const int IDM_WINDOWICONS
= 4003;
85 static const int IDM_WINDOWNEXT
= 4004;
86 static const int IDM_WINDOWTILEVERT
= 4005;
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 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
118 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
120 // ===========================================================================
122 // ===========================================================================
124 // ---------------------------------------------------------------------------
126 // ---------------------------------------------------------------------------
128 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
129 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
130 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
132 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
133 EVT_SIZE(wxMDIParentFrame::OnSize
)
134 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
137 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
138 EVT_IDLE(wxMDIChildFrame::OnIdle
)
141 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
142 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
145 // ===========================================================================
146 // wxMDIParentFrame: the frame which contains the client window which manages
148 // ===========================================================================
150 wxMDIParentFrame::wxMDIParentFrame()
152 m_clientWindow
= NULL
;
153 m_currentChild
= NULL
;
154 m_windowMenu
= (wxMenu
*) NULL
;
155 m_parentFrameActive
= TRUE
;
158 bool wxMDIParentFrame::Create(wxWindow
*parent
,
160 const wxString
& title
,
164 const wxString
& name
)
166 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
167 ? wxSTD_MDIPARENTFRAME_ICON
168 : wxDEFAULT_MDIPARENTFRAME_ICON
);
170 m_clientWindow
= NULL
;
171 m_currentChild
= NULL
;
173 // this style can be used to prevent a window from having the standard MDI
175 if ( style
& wxFRAME_NO_WINDOW_MENU
)
177 m_windowMenu
= (wxMenu
*)NULL
;
179 else // normal case: we have the window menu, so construct it
181 m_windowMenu
= new wxMenu
;
183 m_windowMenu
->Append(IDM_WINDOWCASCADE
, wxT("&Cascade"));
184 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, wxT("Tile &Horizontally"));
185 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, wxT("Tile &Vertically"));
186 m_windowMenu
->AppendSeparator();
187 m_windowMenu
->Append(IDM_WINDOWICONS
, wxT("&Arrange Icons"));
188 m_windowMenu
->Append(IDM_WINDOWNEXT
, wxT("&Next"));
191 m_parentFrameActive
= TRUE
;
194 wxTopLevelWindows
.Append(this);
197 m_windowStyle
= style
;
199 if (parent
) parent
->AddChild(this);
204 m_windowId
= (int)NewControlId();
211 DWORD msflags
= WS_OVERLAPPED
;
212 if (style
& wxMINIMIZE_BOX
)
213 msflags
|= WS_MINIMIZEBOX
;
214 if (style
& wxMAXIMIZE_BOX
)
215 msflags
|= WS_MAXIMIZEBOX
;
216 if (style
& wxTHICK_FRAME
)
217 msflags
|= WS_THICKFRAME
;
218 if (style
& wxSYSTEM_MENU
)
219 msflags
|= WS_SYSMENU
;
220 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
221 msflags
|= WS_MINIMIZE
;
222 if (style
& wxMAXIMIZE
)
223 msflags
|= WS_MAXIMIZE
;
224 if (style
& wxCAPTION
)
225 msflags
|= WS_CAPTION
;
227 if (style
& wxCLIP_CHILDREN
)
228 msflags
|= WS_CLIPCHILDREN
;
230 if ( !wxWindow::MSWCreate(m_windowId
,
241 wxModelessWindows
.Append(this);
243 // unlike (almost?) all other windows, frames are created hidden
249 wxMDIParentFrame::~wxMDIParentFrame()
252 // already delete by DestroyChildren()
253 m_frameToolBar
= NULL
;
254 m_frameStatusBar
= NULL
;
256 // ::DestroyMenu((HMENU)m_windowMenu);
260 m_windowMenu
= (wxMenu
*) NULL
;
263 if ( m_clientWindow
)
265 if ( m_clientWindow
->MSWGetOldWndProc() )
266 m_clientWindow
->UnsubclassWin();
268 m_clientWindow
->SetHWND(0);
269 delete m_clientWindow
;
273 void wxMDIParentFrame::InternalSetMenuBar()
275 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
277 m_parentFrameActive
= TRUE
;
279 HMENU subMenu
= (HMENU
) 0;
281 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
283 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
286 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
292 // Remove old window menu
293 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
297 m_windowMenu
= (wxMenu
*) NULL
;
303 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
307 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
309 if ( GetClientWindow() )
312 GetClientSize(&width
, &height
);
314 GetClientWindow()->SetSize(0, 0, width
, height
);
318 // Returns the active MDI child window
319 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
321 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
322 WM_MDIGETACTIVE
, 0, 0L);
326 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
329 // Create the client window class (don't Create the window, just return a new
331 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
333 return new wxMDIClientWindow
;
336 // Responds to colour changes, and passes event on to children.
337 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
339 if ( m_clientWindow
)
341 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
342 m_clientWindow
->Refresh();
348 // ---------------------------------------------------------------------------
350 // ---------------------------------------------------------------------------
352 void wxMDIParentFrame::Cascade()
354 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
357 // TODO: add a direction argument (hor/vert)
358 void wxMDIParentFrame::Tile()
360 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
363 void wxMDIParentFrame::ArrangeIcons()
365 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
368 void wxMDIParentFrame::ActivateNext()
370 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
373 void wxMDIParentFrame::ActivatePrevious()
375 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
378 // ---------------------------------------------------------------------------
379 // the MDI parent frame window proc
380 // ---------------------------------------------------------------------------
382 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
387 bool processed
= FALSE
;
393 WXWORD state
, minimized
;
395 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
397 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
405 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
407 (void)HandleCommand(id
, cmd
, hwnd
);
409 // even if the frame didn't process it, there is no need to try it
410 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
411 // so pretend we processed the message anyhow
415 // always pass this message DefFrameProc(), otherwise MDI menu
416 // commands (and sys commands - more surprizingly!) won't work
417 MSWDefWindowProc(message
, wParam
, lParam
);
421 m_clientWindow
= OnCreateClient();
422 // Uses own style for client style
423 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
425 wxLogMessage(_("Failed to create MDI parent frame."));
436 // we erase background ourselves
444 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
446 if ( m_parentFrameActive
)
448 processed
= HandleMenuSelect(item
, flags
, hmenu
);
450 else if (m_currentChild
)
452 processed
= m_currentChild
->
453 HandleMenuSelect(item
, flags
, hmenu
);
459 // as we don't (usually) resize the MDI client to exactly fit the
460 // client area (we put it below the toolbar, above statusbar &c),
461 // we should not pass this one to DefFrameProc
466 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
471 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
473 bool processed
= FALSE
;
475 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
481 // If this window is an MDI parent, we must also send an OnActivate message
482 // to the current child.
483 if ( (m_currentChild
!= NULL
) &&
484 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
486 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
487 event
.SetEventObject( m_currentChild
);
488 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
495 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
497 // In case it's e.g. a toolbar.
500 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
502 return win
->MSWCommand(cmd
, id
);
505 // is it one of standard MDI commands?
510 case IDM_WINDOWCASCADE
:
512 wParam
= MDITILE_SKIPDISABLED
;
515 case IDM_WINDOWTILEHOR
:
516 wParam
|= MDITILE_HORIZONTAL
;
519 case IDM_WINDOWTILEVERT
:
521 wParam
= MDITILE_VERTICAL
;
523 wParam
|= MDITILE_SKIPDISABLED
;
526 case IDM_WINDOWICONS
:
527 msg
= WM_MDIICONARRANGE
;
540 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
545 // FIXME VZ: what does this test do??
548 return FALSE
; // Get WndProc to call default proc
551 if ( IsMdiCommandId(id
) )
553 wxWindowList::Node
* node
= GetChildren().GetFirst();
556 wxWindow
* child
= node
->GetData();
557 if ( child
->GetHWND() )
559 long childId
= wxGetWindowId(child
->GetHWND());
560 if (childId
== (long)id
)
562 ::SendMessage( GetWinHwnd(GetClientWindow()),
564 (WPARAM
)child
->GetHWND(), 0);
568 node
= node
->GetNext();
571 else if ( m_parentFrameActive
)
573 return ProcessCommand(id
);
575 else if ( m_currentChild
)
577 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
581 // this shouldn't happen because it means that our messages are being
582 // lost (they're not sent to the parent frame nor to the children)
583 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
589 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
594 if ( GetClientWindow() )
595 clientWnd
= GetClientWindow()->GetHWND();
599 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
602 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
604 MSG
*pMsg
= (MSG
*)msg
;
606 // first let the current child get it
607 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
608 m_currentChild
->MSWTranslateMessage(msg
) )
613 // then try out accel table (will also check the menu accels)
614 if ( wxFrame::MSWTranslateMessage(msg
) )
619 // finally, check for MDI specific built in accel keys
620 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
622 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
629 // ===========================================================================
631 // ===========================================================================
633 void wxMDIChildFrame::Init()
635 m_needsResize
= TRUE
;
638 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
640 const wxString
& title
,
644 const wxString
& name
)
646 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
647 : wxDEFAULT_MDICHILDFRAME_ICON
);
654 m_windowId
= (int)NewControlId();
658 parent
->AddChild(this);
670 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
671 ? wxMDIChildFrameClassNameNoRedraw
672 : wxMDIChildFrameClassName
;
674 mcs
.hOwner
= wxGetInstance();
678 mcs
.x
= CW_USEDEFAULT
;
683 mcs
.y
= CW_USEDEFAULT
;
688 mcs
.cx
= CW_USEDEFAULT
;
693 mcs
.cy
= CW_USEDEFAULT
;
695 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
696 if (style
& wxMINIMIZE_BOX
)
697 msflags
|= WS_MINIMIZEBOX
;
698 if (style
& wxMAXIMIZE_BOX
)
699 msflags
|= WS_MAXIMIZEBOX
;
700 if (style
& wxTHICK_FRAME
)
701 msflags
|= WS_THICKFRAME
;
702 if (style
& wxSYSTEM_MENU
)
703 msflags
|= WS_SYSMENU
;
704 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
705 msflags
|= WS_MINIMIZE
;
706 if (style
& wxMAXIMIZE
)
707 msflags
|= WS_MAXIMIZE
;
708 if (style
& wxCAPTION
)
709 msflags
|= WS_CAPTION
;
715 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
716 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
719 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
721 // VZ: what's this? an act of piracy?
722 //SetWindowLong(GetHwnd(), 0, (long)this);
724 wxModelessWindows
.Append(this);
728 wxMDIChildFrame::~wxMDIChildFrame()
732 // already delete by DestroyChildren()
733 m_frameToolBar
= NULL
;
734 m_frameStatusBar
= NULL
;
739 // Set the client size (i.e. leave the calculation of borders etc.
741 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
743 HWND hWnd
= GetHwnd();
746 ::GetClientRect(hWnd
, &rect
);
749 GetWindowRect(hWnd
, &rect2
);
751 // Find the difference between the entire window (title bar and all)
752 // and the client area; add this to the new client size to move the
754 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
755 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
757 if (GetStatusBar() && GetStatusBar()->IsShown())
760 GetStatusBar()->GetSize(&sx
, &sy
);
765 point
.x
= rect2
.left
;
768 // If there's an MDI parent, must subtract the parent's top left corner
769 // since MoveWindow moves relative to the parent
770 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
771 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
773 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
775 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
776 event
.SetEventObject( this );
777 GetEventHandler()->ProcessEvent(event
);
780 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
783 GetWindowRect(GetHwnd(), &rect
);
788 // Since we now have the absolute screen coords,
789 // if there's a parent we must subtract its top left corner
790 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
791 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
797 void wxMDIChildFrame::InternalSetMenuBar()
799 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
801 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
802 HMENU subMenu
= (HMENU
) 0;
803 if (parent
->GetWindowMenu())
804 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
806 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
808 parent
->m_parentFrameActive
= FALSE
;
811 // ---------------------------------------------------------------------------
813 // ---------------------------------------------------------------------------
815 void wxMDIChildFrame::Maximize(bool maximize
)
817 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
818 if ( parent
&& parent
->GetClientWindow() )
820 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
821 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
822 (WPARAM
)GetHwnd(), 0);
826 void wxMDIChildFrame::Restore()
828 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
829 if ( parent
&& parent
->GetClientWindow() )
831 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
832 (WPARAM
) GetHwnd(), 0);
836 void wxMDIChildFrame::Activate()
838 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
839 if ( parent
&& parent
->GetClientWindow() )
841 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
842 (WPARAM
) GetHwnd(), 0);
846 // ---------------------------------------------------------------------------
847 // MDI window proc and message handlers
848 // ---------------------------------------------------------------------------
850 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
855 bool processed
= FALSE
;
863 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
866 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
870 case WM_GETMINMAXINFO
:
871 // let the default window proc calculate the size of MDI children
872 // frames because it is based on the size of the MDI client window,
873 // not on the values specified in wxWindow m_min/max variables
874 return MSWDefWindowProc(message
, wParam
, lParam
);
879 WXHWND hwndAct
, hwndDeact
;
880 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
882 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
887 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
888 // scrollbars if necessary
893 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
895 MSWDefWindowProc(message
, wParam
, lParam
);
899 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
900 // the message (the base class version does not)
901 return MSWDefWindowProc(message
, wParam
, lParam
);
903 case WM_WINDOWPOSCHANGING
:
904 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
909 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
914 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
916 // In case it's e.g. a toolbar.
919 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
921 return win
->MSWCommand(cmd
, id
);
924 if (wxCurrentPopupMenu
)
926 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
927 wxCurrentPopupMenu
= NULL
;
928 if (popupMenu
->MSWCommand(cmd
, id
))
933 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
935 processed
= ProcessCommand(id
);
945 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
949 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
955 if ( m_hWnd
== hwndAct
)
958 parent
->m_currentChild
= this;
960 HMENU child_menu
= (HMENU
)GetWinMenu();
963 parent
->m_parentFrameActive
= FALSE
;
965 menuToSet
= child_menu
;
968 else if ( m_hWnd
== hwndDeact
)
970 wxASSERT_MSG( parent
->m_currentChild
== this,
971 wxT("can't deactivate MDI child which wasn't active!") );
974 parent
->m_currentChild
= NULL
;
976 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
979 parent
->m_parentFrameActive
= TRUE
;
981 menuToSet
= parent_menu
;
986 // we have nothing to do with it
992 HMENU subMenu
= (HMENU
) 0;
993 if (parent
->GetWindowMenu())
994 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
996 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
999 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1000 event
.SetEventObject( this );
1002 return GetEventHandler()->ProcessEvent(event
);
1005 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1007 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1008 #if defined(__WIN95__)
1009 if (!(lpPos
->flags
& SWP_NOSIZE
))
1012 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1013 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1014 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1016 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1017 lpPos
->x
= rectClient
.left
;
1018 lpPos
->y
= rectClient
.top
;
1019 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1020 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1022 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1023 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1025 pFrameWnd
->GetToolBar()->Refresh();
1033 // ---------------------------------------------------------------------------
1034 // MDI specific message translation/preprocessing
1035 // ---------------------------------------------------------------------------
1037 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1039 return DefMDIChildProc(GetHwnd(),
1040 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1043 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1045 return wxFrame::MSWTranslateMessage(msg
);
1048 // ---------------------------------------------------------------------------
1050 // ---------------------------------------------------------------------------
1052 void wxMDIChildFrame::MSWDestroyWindow()
1054 MSWDetachWindowMenu();
1055 invalidHandle
= GetHwnd();
1057 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1059 // Must make sure this handle is invalidated (set to NULL) since all sorts
1060 // of things could happen after the child client is destroyed, but before
1061 // the wxFrame is destroyed.
1063 HWND oldHandle
= (HWND
)GetHWND();
1064 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1065 (WPARAM
)oldHandle
, 0);
1067 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1068 ResetWindowStyle((void*) NULL
);
1074 ::DestroyMenu((HMENU
) m_hMenu
);
1077 wxRemoveHandleAssociation(this);
1081 // Change the client window's extended style so we don't get a client edge
1082 // style when a child is maximised (a double border looks silly.)
1083 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1085 #if defined(__WIN95__)
1086 RECT
*rect
= (RECT
*)vrect
;
1087 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1088 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1089 if (!pChild
|| (pChild
== this))
1091 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1092 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1093 DWORD dwNewStyle
= dwStyle
;
1094 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1095 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1097 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1099 if (dwStyle
!= dwNewStyle
)
1101 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1102 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1103 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1104 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1105 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1106 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1109 ::GetClientRect(hwnd
, rect
);
1119 // ===========================================================================
1120 // wxMDIClientWindow: the window of predefined (by Windows) class which
1121 // contains the child frames
1122 // ===========================================================================
1124 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1126 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1128 CLIENTCREATESTRUCT ccs
;
1129 m_windowStyle
= style
;
1132 ccs
.hWindowMenu
= (HMENU
) 0;
1133 if (parent
->GetWindowMenu())
1134 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1135 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1137 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1138 if ( style
& wxHSCROLL
)
1139 msStyle
|= WS_HSCROLL
;
1140 if ( style
& wxVSCROLL
)
1141 msStyle
|= WS_VSCROLL
;
1143 #if defined(__WIN95__)
1144 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1150 m_hWnd
= (WXHWND
)::CreateWindowEx
1160 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1163 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1168 SubclassWin(m_hWnd
);
1174 // Explicitly call default scroll behaviour
1175 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1177 // Note: for client windows, the scroll position is not set in
1178 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1179 // scroll position we're at.
1180 // This makes it hard to paint patterns or bitmaps in the background,
1181 // and have the client area scrollable as well.
1183 if ( event
.GetOrientation() == wxHORIZONTAL
)
1184 m_scrollX
= event
.GetPosition(); // Always returns zero!
1186 m_scrollY
= event
.GetPosition(); // Always returns zero!
1191 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1193 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1194 // client area, you can end up with a non-refreshed portion in the client window
1195 // (see OGL studio sample). So check if the position is changed and if so,
1196 // redraw the MDI child frames.
1198 wxPoint oldPos
= GetPosition();
1200 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1202 wxPoint newPos
= GetPosition();
1204 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1208 wxNode
* node
= GetParent()->GetChildren().First();
1211 wxWindow
* child
= (wxWindow
*) node
->Data();
1212 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1214 HWND hWnd
= (HWND
) child
->GetHWND();
1215 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1217 node
= node
->Next();
1223 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1225 // MDI child frames get their WM_SIZE when they're constructed but at this
1226 // moment they don't have any children yet so all child windows will be
1227 // positioned incorrectly when they are added later - to fix this, we
1228 // generate an artificial size event here
1229 if ( m_needsResize
)
1231 m_needsResize
= FALSE
; // avoid any possibility of recursion
1239 // ---------------------------------------------------------------------------
1240 // non member functions
1241 // ---------------------------------------------------------------------------
1243 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1245 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1247 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1249 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1253 // update menu bar of the parent window
1254 wxWindow
*parent
= win
->GetParent();
1255 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1257 ::DrawMenuBar(GetWinHwnd(parent
));
1260 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1262 // Try to insert Window menu in front of Help, otherwise append it.
1263 HMENU hmenu
= (HMENU
)menu
;
1267 int N
= GetMenuItemCount(hmenu
);
1268 bool success
= FALSE
;
1269 for ( int i
= 0; i
< N
; i
++ )
1272 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1275 wxLogLastError(wxT("GetMenuString"));
1280 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1283 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1284 (UINT
)subMenu
, _("&Window"));
1291 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1295 MDISetMenu(win
, hmenu
, subMenu
);
1298 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1300 // Try to insert Window menu in front of Help, otherwise append it.
1301 HMENU hmenu
= (HMENU
)menu
;
1302 int N
= GetMenuItemCount(hmenu
);
1303 bool success
= FALSE
;
1304 for ( int i
= 0; i
< N
; i
++ )
1307 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1310 wxLogLastError(wxT("GetMenuString"));
1315 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Window")) )
1318 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1323 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1324 MDISetMenu(win
, hmenu
, 0);
1327 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1328 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1332 *hwndAct
= (WXHWND
)lParam
;
1333 *hwndDeact
= (WXHWND
)wParam
;
1335 *activate
= (WXWORD
)wParam
;
1336 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1337 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1338 #endif // Win32/Win16