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
;
67 extern const wxChar
*wxMDIChildFrameClassName
;
68 extern wxWindow
*wxWndHook
; // from window.cpp
70 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
71 extern void wxRemoveHandleAssociation(wxWindow
*win
);
73 static HWND invalidHandle
= 0;
75 // ---------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------
79 static const int IDM_WINDOWTILE
= 4001;
80 static const int IDM_WINDOWTILEHOR
= 4001;
81 static const int IDM_WINDOWCASCADE
= 4002;
82 static const int IDM_WINDOWICONS
= 4003;
83 static const int IDM_WINDOWNEXT
= 4004;
84 static const int IDM_WINDOWTILEVERT
= 4005;
86 // This range gives a maximum of 500 MDI children. Should be enough :-)
87 static const int wxFIRST_MDI_CHILD
= 4100;
88 static const int wxLAST_MDI_CHILD
= 4600;
90 // Status border dimensions
91 static const int wxTHICK_LINE_BORDER
= 3;
92 static const int wxTHICK_LINE_WIDTH
= 1;
94 // ---------------------------------------------------------------------------
96 // ---------------------------------------------------------------------------
98 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
99 // of the parent of win (which is supposed to be the MDI client window)
100 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
102 // insert the window menu (subMenu) into menu just before "Help" submenu or at
103 // the very end if not found
104 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
106 // Remove the window menu
107 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
109 // is this an id of an MDI child?
110 inline bool IsMdiCommandId(int id
)
112 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
115 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
116 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
118 // ===========================================================================
120 // ===========================================================================
122 // ---------------------------------------------------------------------------
124 // ---------------------------------------------------------------------------
126 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
127 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
128 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
130 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
131 EVT_SIZE(wxMDIParentFrame::OnSize
)
132 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
135 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
136 EVT_IDLE(wxMDIChildFrame::OnIdle
)
139 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
140 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
143 // ===========================================================================
144 // wxMDIParentFrame: the frame which contains the client window which manages
146 // ===========================================================================
148 wxMDIParentFrame::wxMDIParentFrame()
150 m_clientWindow
= NULL
;
151 m_currentChild
= NULL
;
152 m_windowMenu
= (wxMenu
*) NULL
;
153 m_parentFrameActive
= TRUE
;
156 bool wxMDIParentFrame::Create(wxWindow
*parent
,
158 const wxString
& title
,
162 const wxString
& name
)
164 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
166 m_clientWindow
= NULL
;
167 m_currentChild
= NULL
;
169 if (style
& wxFRAME_NO_WINDOW_MENU
)
170 m_windowMenu
= (wxMenu
*) NULL
;
173 // m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
174 m_windowMenu
= new wxMenu
;
177 m_windowMenu
->Append(4002, wxT("&Cascade"));
178 m_windowMenu
->Append(4001, wxT("Tile &Horizontally"));
179 m_windowMenu
->Append(4005, wxT("Tile &Vertically"));
180 m_windowMenu
->AppendSeparator();
181 m_windowMenu
->Append(4003, wxT("&Arrange Icons"));
182 m_windowMenu
->Append(4004, wxT("&Next"));
185 m_parentFrameActive
= TRUE
;
188 wxTopLevelWindows
.Append(this);
191 m_windowStyle
= style
;
193 if (parent
) parent
->AddChild(this);
198 m_windowId
= (int)NewControlId();
205 DWORD msflags
= WS_OVERLAPPED
;
206 if (style
& wxMINIMIZE_BOX
)
207 msflags
|= WS_MINIMIZEBOX
;
208 if (style
& wxMAXIMIZE_BOX
)
209 msflags
|= WS_MAXIMIZEBOX
;
210 if (style
& wxTHICK_FRAME
)
211 msflags
|= WS_THICKFRAME
;
212 if (style
& wxSYSTEM_MENU
)
213 msflags
|= WS_SYSMENU
;
214 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
215 msflags
|= WS_MINIMIZE
;
216 if (style
& wxMAXIMIZE
)
217 msflags
|= WS_MAXIMIZE
;
218 if (style
& wxCAPTION
)
219 msflags
|= WS_CAPTION
;
221 if (style
& wxCLIP_CHILDREN
)
222 msflags
|= WS_CLIPCHILDREN
;
224 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
227 wxModelessWindows
.Append(this);
229 // unlike (almost?) all other windows, frames are created hidden
235 wxMDIParentFrame::~wxMDIParentFrame()
238 // already delete by DestroyChildren()
239 m_frameToolBar
= NULL
;
240 m_frameStatusBar
= NULL
;
242 // ::DestroyMenu((HMENU)m_windowMenu);
246 m_windowMenu
= (wxMenu
*) NULL
;
249 if ( m_clientWindow
)
251 if ( m_clientWindow
->MSWGetOldWndProc() )
252 m_clientWindow
->UnsubclassWin();
254 m_clientWindow
->SetHWND(0);
255 delete m_clientWindow
;
259 void wxMDIParentFrame::InternalSetMenuBar()
261 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
263 m_parentFrameActive
= TRUE
;
265 HMENU subMenu
= (HMENU
) 0;
267 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
269 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
272 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
278 // Remove old window menu
279 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
283 m_windowMenu
= (wxMenu
*) NULL
;
289 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
293 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
295 if ( GetClientWindow() )
298 GetClientSize(&width
, &height
);
300 GetClientWindow()->SetSize(0, 0, width
, height
);
304 // Returns the active MDI child window
305 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
307 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
308 WM_MDIGETACTIVE
, 0, 0L);
312 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
315 // Create the client window class (don't Create the window, just return a new
317 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
319 return new wxMDIClientWindow
;
322 // Responds to colour changes, and passes event on to children.
323 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
325 if ( m_clientWindow
)
327 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
328 m_clientWindow
->Refresh();
334 // ---------------------------------------------------------------------------
336 // ---------------------------------------------------------------------------
338 void wxMDIParentFrame::Cascade()
340 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
343 // TODO: add a direction argument (hor/vert)
344 void wxMDIParentFrame::Tile()
346 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
349 void wxMDIParentFrame::ArrangeIcons()
351 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
354 void wxMDIParentFrame::ActivateNext()
356 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
359 void wxMDIParentFrame::ActivatePrevious()
361 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
364 // ---------------------------------------------------------------------------
365 // the MDI parent frame window proc
366 // ---------------------------------------------------------------------------
368 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
373 bool processed
= FALSE
;
379 WXWORD state
, minimized
;
381 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
383 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
391 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
393 (void)HandleCommand(id
, cmd
, hwnd
);
395 // even if the frame didn't process it, there is no need to try it
396 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
397 // so pretend we processed the message anyhow
401 // always pass this message DefFrameProc(), otherwise MDI menu
402 // commands (and sys commands - more surprizingly!) won't work
403 MSWDefWindowProc(message
, wParam
, lParam
);
407 m_clientWindow
= OnCreateClient();
408 // Uses own style for client style
409 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
411 wxLogMessage(_("Failed to create MDI parent frame."));
422 // we erase background ourselves
430 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
432 if ( m_parentFrameActive
)
434 processed
= HandleMenuSelect(item
, flags
, hmenu
);
436 else if (m_currentChild
)
438 processed
= m_currentChild
->
439 HandleMenuSelect(item
, flags
, hmenu
);
445 // as we don't (usually) resize the MDI client to exactly fit the
446 // client area (we put it below the toolbar, above statusbar &c),
447 // we should not pass this one to DefFrameProc
452 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
457 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
459 bool processed
= FALSE
;
461 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
467 // If this window is an MDI parent, we must also send an OnActivate message
468 // to the current child.
469 if ( (m_currentChild
!= NULL
) &&
470 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
472 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
473 event
.SetEventObject( m_currentChild
);
474 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
481 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
483 // In case it's e.g. a toolbar.
486 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
488 return win
->MSWCommand(cmd
, id
);
491 // is it one of standard MDI commands?
496 case IDM_WINDOWCASCADE
:
498 wParam
= MDITILE_SKIPDISABLED
;
501 case IDM_WINDOWTILEHOR
:
502 wParam
|= MDITILE_HORIZONTAL
;
505 case IDM_WINDOWTILEVERT
:
507 wParam
= MDITILE_VERTICAL
;
509 wParam
|= MDITILE_SKIPDISABLED
;
512 case IDM_WINDOWICONS
:
513 msg
= WM_MDIICONARRANGE
;
526 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
531 // FIXME VZ: what does this test do??
534 return FALSE
; // Get WndProc to call default proc
537 if ( IsMdiCommandId(id
) )
539 wxWindowList::Node
* node
= GetChildren().GetFirst();
542 wxWindow
* child
= node
->GetData();
543 if ( child
->GetHWND() )
545 long childId
= wxGetWindowId(child
->GetHWND());
546 if (childId
== (long)id
)
548 ::SendMessage( GetWinHwnd(GetClientWindow()),
550 (WPARAM
)child
->GetHWND(), 0);
554 node
= node
->GetNext();
557 else if ( m_parentFrameActive
)
559 return ProcessCommand(id
);
561 else if ( m_currentChild
)
563 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
567 // this shouldn't happen because it means that our messages are being
568 // lost (they're not sent to the parent frame nor to the children)
569 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
575 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
580 if ( GetClientWindow() )
581 clientWnd
= GetClientWindow()->GetHWND();
585 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
588 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
590 MSG
*pMsg
= (MSG
*)msg
;
592 // first let the current child get it
593 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
594 m_currentChild
->MSWTranslateMessage(msg
) )
599 // then try out accel table (will also check the menu accels)
600 if ( wxFrame::MSWTranslateMessage(msg
) )
605 // finally, check for MDI specific built in accel keys
606 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
608 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
615 // ===========================================================================
617 // ===========================================================================
619 void wxMDIChildFrame::Init()
621 m_needsResize
= TRUE
;
624 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
626 const wxString
& title
,
630 const wxString
& name
)
632 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
633 : wxDEFAULT_MDICHILDFRAME_ICON
);
640 m_windowId
= (int)NewControlId();
644 parent
->AddChild(this);
656 mcs
.szClass
= wxMDIChildFrameClassName
;
658 mcs
.hOwner
= wxGetInstance();
662 mcs
.x
= CW_USEDEFAULT
;
667 mcs
.y
= CW_USEDEFAULT
;
672 mcs
.cx
= CW_USEDEFAULT
;
677 mcs
.cy
= CW_USEDEFAULT
;
679 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
680 if (style
& wxMINIMIZE_BOX
)
681 msflags
|= WS_MINIMIZEBOX
;
682 if (style
& wxMAXIMIZE_BOX
)
683 msflags
|= WS_MAXIMIZEBOX
;
684 if (style
& wxTHICK_FRAME
)
685 msflags
|= WS_THICKFRAME
;
686 if (style
& wxSYSTEM_MENU
)
687 msflags
|= WS_SYSMENU
;
688 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
689 msflags
|= WS_MINIMIZE
;
690 if (style
& wxMAXIMIZE
)
691 msflags
|= WS_MAXIMIZE
;
692 if (style
& wxCAPTION
)
693 msflags
|= WS_CAPTION
;
699 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
700 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
702 //handle = (HWND)LOWORD(Return);
703 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
704 m_hWnd
= (WXHWND
)Return
;
707 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
709 // VZ: what's this? an act of piracy?
710 //SetWindowLong(GetHwnd(), 0, (long)this);
712 wxModelessWindows
.Append(this);
716 wxMDIChildFrame::~wxMDIChildFrame()
720 // already delete by DestroyChildren()
721 m_frameToolBar
= NULL
;
722 m_frameStatusBar
= NULL
;
727 // Set the client size (i.e. leave the calculation of borders etc.
729 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
731 HWND hWnd
= GetHwnd();
734 ::GetClientRect(hWnd
, &rect
);
737 GetWindowRect(hWnd
, &rect2
);
739 // Find the difference between the entire window (title bar and all)
740 // and the client area; add this to the new client size to move the
742 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
743 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
745 if (GetStatusBar() && GetStatusBar()->IsShown())
748 GetStatusBar()->GetSize(&sx
, &sy
);
753 point
.x
= rect2
.left
;
756 // If there's an MDI parent, must subtract the parent's top left corner
757 // since MoveWindow moves relative to the parent
758 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
759 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
761 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
763 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
764 event
.SetEventObject( this );
765 GetEventHandler()->ProcessEvent(event
);
768 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
771 GetWindowRect(GetHwnd(), &rect
);
776 // Since we now have the absolute screen coords,
777 // if there's a parent we must subtract its top left corner
778 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
779 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
785 void wxMDIChildFrame::InternalSetMenuBar()
787 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
789 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
790 HMENU subMenu
= (HMENU
) 0;
791 if (parent
->GetWindowMenu())
792 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
794 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
796 parent
->m_parentFrameActive
= FALSE
;
799 // ---------------------------------------------------------------------------
801 // ---------------------------------------------------------------------------
803 void wxMDIChildFrame::Maximize(bool maximize
)
805 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
806 if ( parent
&& parent
->GetClientWindow() )
808 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
809 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
810 (WPARAM
)GetHwnd(), 0);
814 void wxMDIChildFrame::Restore()
816 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
817 if ( parent
&& parent
->GetClientWindow() )
819 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
820 (WPARAM
) GetHwnd(), 0);
824 void wxMDIChildFrame::Activate()
826 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
827 if ( parent
&& parent
->GetClientWindow() )
829 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
830 (WPARAM
) GetHwnd(), 0);
834 // ---------------------------------------------------------------------------
835 // MDI window proc and message handlers
836 // ---------------------------------------------------------------------------
838 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
843 bool processed
= FALSE
;
851 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
854 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
858 case WM_GETMINMAXINFO
:
859 // let the default window proc calculate the size of MDI children
860 // frames because it is based on the size of the MDI client window,
861 // not on the values specified in wxWindow m_min/max variables
862 return MSWDefWindowProc(message
, wParam
, lParam
);
867 WXHWND hwndAct
, hwndDeact
;
868 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
870 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
875 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
876 // scrollbars if necessary
881 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
883 MSWDefWindowProc(message
, wParam
, lParam
);
887 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
888 // the message (the base class version does not)
889 return MSWDefWindowProc(message
, wParam
, lParam
);
891 case WM_WINDOWPOSCHANGING
:
892 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
897 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
902 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
904 // In case it's e.g. a toolbar.
907 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
909 return win
->MSWCommand(cmd
, id
);
912 if (wxCurrentPopupMenu
)
914 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
915 wxCurrentPopupMenu
= NULL
;
916 if (popupMenu
->MSWCommand(cmd
, id
))
920 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
931 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
935 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
941 if ( m_hWnd
== hwndAct
)
944 parent
->m_currentChild
= this;
946 HMENU child_menu
= (HMENU
)GetWinMenu();
949 parent
->m_parentFrameActive
= FALSE
;
951 menuToSet
= child_menu
;
954 else if ( m_hWnd
== hwndDeact
)
956 wxASSERT_MSG( parent
->m_currentChild
== this,
957 wxT("can't deactivate MDI child which wasn't active!") );
960 parent
->m_currentChild
= NULL
;
962 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
965 parent
->m_parentFrameActive
= TRUE
;
967 menuToSet
= parent_menu
;
972 // we have nothing to do with it
978 HMENU subMenu
= (HMENU
) 0;
979 if (parent
->GetWindowMenu())
980 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
982 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
985 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
986 event
.SetEventObject( this );
988 return GetEventHandler()->ProcessEvent(event
);
991 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
993 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
994 #if defined(__WIN95__)
995 if (!(lpPos
->flags
& SWP_NOSIZE
))
998 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
999 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1000 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1002 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1003 lpPos
->x
= rectClient
.left
;
1004 lpPos
->y
= rectClient
.top
;
1005 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1006 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1008 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1009 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1011 pFrameWnd
->GetToolBar()->Refresh();
1019 // ---------------------------------------------------------------------------
1020 // MDI specific message translation/preprocessing
1021 // ---------------------------------------------------------------------------
1023 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1025 return DefMDIChildProc(GetHwnd(),
1026 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1029 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1031 return m_acceleratorTable
.Translate(GetParent(), msg
);
1034 // ---------------------------------------------------------------------------
1036 // ---------------------------------------------------------------------------
1038 void wxMDIChildFrame::MSWDestroyWindow()
1040 MSWDetachWindowMenu();
1041 invalidHandle
= GetHwnd();
1043 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1045 // Must make sure this handle is invalidated (set to NULL) since all sorts
1046 // of things could happen after the child client is destroyed, but before
1047 // the wxFrame is destroyed.
1049 HWND oldHandle
= (HWND
)GetHWND();
1050 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1051 (WPARAM
)oldHandle
, 0);
1053 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1054 ResetWindowStyle((void*) NULL
);
1060 ::DestroyMenu((HMENU
) m_hMenu
);
1063 wxRemoveHandleAssociation(this);
1067 // Change the client window's extended style so we don't get a client edge
1068 // style when a child is maximised (a double border looks silly.)
1069 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1071 #if defined(__WIN95__)
1072 RECT
*rect
= (RECT
*)vrect
;
1073 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1074 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1075 if (!pChild
|| (pChild
== this))
1077 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1078 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1079 DWORD dwNewStyle
= dwStyle
;
1080 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1081 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1083 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1085 if (dwStyle
!= dwNewStyle
)
1087 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1088 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1089 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1090 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1091 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1092 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1095 ::GetClientRect(hwnd
, rect
);
1105 // ===========================================================================
1106 // wxMDIClientWindow: the window of predefined (by Windows) class which
1107 // contains the child frames
1108 // ===========================================================================
1110 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1112 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1114 CLIENTCREATESTRUCT ccs
;
1115 m_windowStyle
= style
;
1118 ccs
.hWindowMenu
= (HMENU
) 0;
1119 if (parent
->GetWindowMenu())
1120 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1121 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1123 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1124 if ( style
& wxHSCROLL
)
1125 msStyle
|= WS_HSCROLL
;
1126 if ( style
& wxVSCROLL
)
1127 msStyle
|= WS_VSCROLL
;
1129 #if defined(__WIN95__)
1130 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1136 m_hWnd
= (WXHWND
)::CreateWindowEx
1146 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1149 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1154 SubclassWin(m_hWnd
);
1160 // Explicitly call default scroll behaviour
1161 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1163 // Note: for client windows, the scroll position is not set in
1164 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1165 // scroll position we're at.
1166 // This makes it hard to paint patterns or bitmaps in the background,
1167 // and have the client area scrollable as well.
1169 if ( event
.GetOrientation() == wxHORIZONTAL
)
1170 m_scrollX
= event
.GetPosition(); // Always returns zero!
1172 m_scrollY
= event
.GetPosition(); // Always returns zero!
1177 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1179 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1180 // client area, you can end up with a non-refreshed portion in the client window
1181 // (see OGL studio sample). So check if the position is changed and if so,
1182 // redraw the MDI child frames.
1184 wxPoint oldPos
= GetPosition();
1186 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1188 wxPoint newPos
= GetPosition();
1190 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1194 wxNode
* node
= GetParent()->GetChildren().First();
1197 wxWindow
* child
= (wxWindow
*) node
->Data();
1198 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1200 HWND hWnd
= (HWND
) child
->GetHWND();
1201 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1203 node
= node
->Next();
1209 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1211 // MDI child frames get their WM_SIZE when they're constructed but at this
1212 // moment they don't have any children yet so all child windows will be
1213 // positioned incorrectly when they are added later - to fix this, we
1214 // generate an artificial size event here
1215 if ( m_needsResize
)
1217 m_needsResize
= FALSE
; // avoid any possibility of recursion
1225 // ---------------------------------------------------------------------------
1226 // non member functions
1227 // ---------------------------------------------------------------------------
1229 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1231 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1233 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1235 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1239 // update menu bar of the parent window
1240 wxWindow
*parent
= win
->GetParent();
1241 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1243 ::DrawMenuBar(GetWinHwnd(parent
));
1246 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1248 // Try to insert Window menu in front of Help, otherwise append it.
1249 HMENU hmenu
= (HMENU
)menu
;
1253 int N
= GetMenuItemCount(hmenu
);
1254 bool success
= FALSE
;
1255 for ( int i
= 0; i
< N
; i
++ )
1258 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1261 wxLogLastError(wxT("GetMenuString"));
1266 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1269 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1270 (UINT
)subMenu
, _("&Window"));
1277 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1281 MDISetMenu(win
, hmenu
, subMenu
);
1284 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1286 // Try to insert Window menu in front of Help, otherwise append it.
1287 HMENU hmenu
= (HMENU
)menu
;
1288 int N
= GetMenuItemCount(hmenu
);
1289 bool success
= FALSE
;
1290 for ( int i
= 0; i
< N
; i
++ )
1293 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1296 wxLogLastError(wxT("GetMenuString"));
1301 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Window")) )
1304 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1309 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1310 MDISetMenu(win
, hmenu
, 0);
1313 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1314 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1318 *hwndAct
= (WXHWND
)lParam
;
1319 *hwndDeact
= (WXHWND
)wParam
;
1321 *activate
= (WXWORD
)wParam
;
1322 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1323 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1324 #endif // Win32/Win16