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
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
168 m_clientWindow
= NULL
;
169 m_currentChild
= NULL
;
171 if (style
& wxFRAME_NO_WINDOW_MENU
)
172 m_windowMenu
= (wxMenu
*) NULL
;
175 // m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
176 m_windowMenu
= new wxMenu
;
179 m_windowMenu
->Append(4002, wxT("&Cascade"));
180 m_windowMenu
->Append(4001, wxT("Tile &Horizontally"));
181 m_windowMenu
->Append(4005, wxT("Tile &Vertically"));
182 m_windowMenu
->AppendSeparator();
183 m_windowMenu
->Append(4003, wxT("&Arrange Icons"));
184 m_windowMenu
->Append(4004, wxT("&Next"));
187 m_parentFrameActive
= TRUE
;
190 wxTopLevelWindows
.Append(this);
193 m_windowStyle
= style
;
195 if (parent
) parent
->AddChild(this);
200 m_windowId
= (int)NewControlId();
207 DWORD msflags
= WS_OVERLAPPED
;
208 if (style
& wxMINIMIZE_BOX
)
209 msflags
|= WS_MINIMIZEBOX
;
210 if (style
& wxMAXIMIZE_BOX
)
211 msflags
|= WS_MAXIMIZEBOX
;
212 if (style
& wxTHICK_FRAME
)
213 msflags
|= WS_THICKFRAME
;
214 if (style
& wxSYSTEM_MENU
)
215 msflags
|= WS_SYSMENU
;
216 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
217 msflags
|= WS_MINIMIZE
;
218 if (style
& wxMAXIMIZE
)
219 msflags
|= WS_MAXIMIZE
;
220 if (style
& wxCAPTION
)
221 msflags
|= WS_CAPTION
;
223 if (style
& wxCLIP_CHILDREN
)
224 msflags
|= WS_CLIPCHILDREN
;
226 if ( !wxWindow::MSWCreate(m_windowId
,
237 wxModelessWindows
.Append(this);
239 // unlike (almost?) all other windows, frames are created hidden
245 wxMDIParentFrame::~wxMDIParentFrame()
248 // already delete by DestroyChildren()
249 m_frameToolBar
= NULL
;
250 m_frameStatusBar
= NULL
;
252 // ::DestroyMenu((HMENU)m_windowMenu);
256 m_windowMenu
= (wxMenu
*) NULL
;
259 if ( m_clientWindow
)
261 if ( m_clientWindow
->MSWGetOldWndProc() )
262 m_clientWindow
->UnsubclassWin();
264 m_clientWindow
->SetHWND(0);
265 delete m_clientWindow
;
269 void wxMDIParentFrame::InternalSetMenuBar()
271 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
273 m_parentFrameActive
= TRUE
;
275 HMENU subMenu
= (HMENU
) 0;
277 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
279 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
282 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
288 // Remove old window menu
289 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
293 m_windowMenu
= (wxMenu
*) NULL
;
299 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
303 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
305 if ( GetClientWindow() )
308 GetClientSize(&width
, &height
);
310 GetClientWindow()->SetSize(0, 0, width
, height
);
314 // Returns the active MDI child window
315 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
317 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
318 WM_MDIGETACTIVE
, 0, 0L);
322 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
325 // Create the client window class (don't Create the window, just return a new
327 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
329 return new wxMDIClientWindow
;
332 // Responds to colour changes, and passes event on to children.
333 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
335 if ( m_clientWindow
)
337 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
338 m_clientWindow
->Refresh();
344 // ---------------------------------------------------------------------------
346 // ---------------------------------------------------------------------------
348 void wxMDIParentFrame::Cascade()
350 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
353 // TODO: add a direction argument (hor/vert)
354 void wxMDIParentFrame::Tile()
356 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
359 void wxMDIParentFrame::ArrangeIcons()
361 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
364 void wxMDIParentFrame::ActivateNext()
366 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
369 void wxMDIParentFrame::ActivatePrevious()
371 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
374 // ---------------------------------------------------------------------------
375 // the MDI parent frame window proc
376 // ---------------------------------------------------------------------------
378 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
383 bool processed
= FALSE
;
389 WXWORD state
, minimized
;
391 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
393 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
401 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
403 (void)HandleCommand(id
, cmd
, hwnd
);
405 // even if the frame didn't process it, there is no need to try it
406 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
407 // so pretend we processed the message anyhow
411 // always pass this message DefFrameProc(), otherwise MDI menu
412 // commands (and sys commands - more surprizingly!) won't work
413 MSWDefWindowProc(message
, wParam
, lParam
);
417 m_clientWindow
= OnCreateClient();
418 // Uses own style for client style
419 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
421 wxLogMessage(_("Failed to create MDI parent frame."));
432 // we erase background ourselves
440 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
442 if ( m_parentFrameActive
)
444 processed
= HandleMenuSelect(item
, flags
, hmenu
);
446 else if (m_currentChild
)
448 processed
= m_currentChild
->
449 HandleMenuSelect(item
, flags
, hmenu
);
455 // as we don't (usually) resize the MDI client to exactly fit the
456 // client area (we put it below the toolbar, above statusbar &c),
457 // we should not pass this one to DefFrameProc
462 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
467 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
469 bool processed
= FALSE
;
471 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
477 // If this window is an MDI parent, we must also send an OnActivate message
478 // to the current child.
479 if ( (m_currentChild
!= NULL
) &&
480 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
482 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
483 event
.SetEventObject( m_currentChild
);
484 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
491 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
493 // In case it's e.g. a toolbar.
496 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
498 return win
->MSWCommand(cmd
, id
);
501 // is it one of standard MDI commands?
506 case IDM_WINDOWCASCADE
:
508 wParam
= MDITILE_SKIPDISABLED
;
511 case IDM_WINDOWTILEHOR
:
512 wParam
|= MDITILE_HORIZONTAL
;
515 case IDM_WINDOWTILEVERT
:
517 wParam
= MDITILE_VERTICAL
;
519 wParam
|= MDITILE_SKIPDISABLED
;
522 case IDM_WINDOWICONS
:
523 msg
= WM_MDIICONARRANGE
;
536 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
541 // FIXME VZ: what does this test do??
544 return FALSE
; // Get WndProc to call default proc
547 if ( IsMdiCommandId(id
) )
549 wxWindowList::Node
* node
= GetChildren().GetFirst();
552 wxWindow
* child
= node
->GetData();
553 if ( child
->GetHWND() )
555 long childId
= wxGetWindowId(child
->GetHWND());
556 if (childId
== (long)id
)
558 ::SendMessage( GetWinHwnd(GetClientWindow()),
560 (WPARAM
)child
->GetHWND(), 0);
564 node
= node
->GetNext();
567 else if ( m_parentFrameActive
)
569 return ProcessCommand(id
);
571 else if ( m_currentChild
)
573 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
577 // this shouldn't happen because it means that our messages are being
578 // lost (they're not sent to the parent frame nor to the children)
579 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
585 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
590 if ( GetClientWindow() )
591 clientWnd
= GetClientWindow()->GetHWND();
595 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
598 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
600 MSG
*pMsg
= (MSG
*)msg
;
602 // first let the current child get it
603 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
604 m_currentChild
->MSWTranslateMessage(msg
) )
609 // then try out accel table (will also check the menu accels)
610 if ( wxFrame::MSWTranslateMessage(msg
) )
615 // finally, check for MDI specific built in accel keys
616 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
618 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
625 // ===========================================================================
627 // ===========================================================================
629 void wxMDIChildFrame::Init()
631 m_needsResize
= TRUE
;
634 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
636 const wxString
& title
,
640 const wxString
& name
)
642 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
643 : wxDEFAULT_MDICHILDFRAME_ICON
);
650 m_windowId
= (int)NewControlId();
654 parent
->AddChild(this);
666 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
667 ? wxMDIChildFrameClassNameNoRedraw
668 : wxMDIChildFrameClassName
;
670 mcs
.hOwner
= wxGetInstance();
674 mcs
.x
= CW_USEDEFAULT
;
679 mcs
.y
= CW_USEDEFAULT
;
684 mcs
.cx
= CW_USEDEFAULT
;
689 mcs
.cy
= CW_USEDEFAULT
;
691 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
692 if (style
& wxMINIMIZE_BOX
)
693 msflags
|= WS_MINIMIZEBOX
;
694 if (style
& wxMAXIMIZE_BOX
)
695 msflags
|= WS_MAXIMIZEBOX
;
696 if (style
& wxTHICK_FRAME
)
697 msflags
|= WS_THICKFRAME
;
698 if (style
& wxSYSTEM_MENU
)
699 msflags
|= WS_SYSMENU
;
700 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
701 msflags
|= WS_MINIMIZE
;
702 if (style
& wxMAXIMIZE
)
703 msflags
|= WS_MAXIMIZE
;
704 if (style
& wxCAPTION
)
705 msflags
|= WS_CAPTION
;
711 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
712 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
715 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
717 // VZ: what's this? an act of piracy?
718 //SetWindowLong(GetHwnd(), 0, (long)this);
720 wxModelessWindows
.Append(this);
724 wxMDIChildFrame::~wxMDIChildFrame()
728 // already delete by DestroyChildren()
729 m_frameToolBar
= NULL
;
730 m_frameStatusBar
= NULL
;
735 // Set the client size (i.e. leave the calculation of borders etc.
737 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
739 HWND hWnd
= GetHwnd();
742 ::GetClientRect(hWnd
, &rect
);
745 GetWindowRect(hWnd
, &rect2
);
747 // Find the difference between the entire window (title bar and all)
748 // and the client area; add this to the new client size to move the
750 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
751 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
753 if (GetStatusBar() && GetStatusBar()->IsShown())
756 GetStatusBar()->GetSize(&sx
, &sy
);
761 point
.x
= rect2
.left
;
764 // If there's an MDI parent, must subtract the parent's top left corner
765 // since MoveWindow moves relative to the parent
766 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
767 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
769 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
771 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
772 event
.SetEventObject( this );
773 GetEventHandler()->ProcessEvent(event
);
776 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
779 GetWindowRect(GetHwnd(), &rect
);
784 // Since we now have the absolute screen coords,
785 // if there's a parent we must subtract its top left corner
786 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
787 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
793 void wxMDIChildFrame::InternalSetMenuBar()
795 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
797 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
798 HMENU subMenu
= (HMENU
) 0;
799 if (parent
->GetWindowMenu())
800 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
802 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
804 parent
->m_parentFrameActive
= FALSE
;
807 // ---------------------------------------------------------------------------
809 // ---------------------------------------------------------------------------
811 void wxMDIChildFrame::Maximize(bool maximize
)
813 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
814 if ( parent
&& parent
->GetClientWindow() )
816 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
817 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
818 (WPARAM
)GetHwnd(), 0);
822 void wxMDIChildFrame::Restore()
824 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
825 if ( parent
&& parent
->GetClientWindow() )
827 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
828 (WPARAM
) GetHwnd(), 0);
832 void wxMDIChildFrame::Activate()
834 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
835 if ( parent
&& parent
->GetClientWindow() )
837 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
838 (WPARAM
) GetHwnd(), 0);
842 // ---------------------------------------------------------------------------
843 // MDI window proc and message handlers
844 // ---------------------------------------------------------------------------
846 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
851 bool processed
= FALSE
;
859 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
862 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
866 case WM_GETMINMAXINFO
:
867 // let the default window proc calculate the size of MDI children
868 // frames because it is based on the size of the MDI client window,
869 // not on the values specified in wxWindow m_min/max variables
870 return MSWDefWindowProc(message
, wParam
, lParam
);
875 WXHWND hwndAct
, hwndDeact
;
876 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
878 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
883 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
884 // scrollbars if necessary
889 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
891 MSWDefWindowProc(message
, wParam
, lParam
);
895 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
896 // the message (the base class version does not)
897 return MSWDefWindowProc(message
, wParam
, lParam
);
899 case WM_WINDOWPOSCHANGING
:
900 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
905 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
910 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
912 // In case it's e.g. a toolbar.
915 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
917 return win
->MSWCommand(cmd
, id
);
920 if (wxCurrentPopupMenu
)
922 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
923 wxCurrentPopupMenu
= NULL
;
924 if (popupMenu
->MSWCommand(cmd
, id
))
929 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
931 processed
= ProcessCommand(id
);
941 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
945 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
951 if ( m_hWnd
== hwndAct
)
954 parent
->m_currentChild
= this;
956 HMENU child_menu
= (HMENU
)GetWinMenu();
959 parent
->m_parentFrameActive
= FALSE
;
961 menuToSet
= child_menu
;
964 else if ( m_hWnd
== hwndDeact
)
966 wxASSERT_MSG( parent
->m_currentChild
== this,
967 wxT("can't deactivate MDI child which wasn't active!") );
970 parent
->m_currentChild
= NULL
;
972 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
975 parent
->m_parentFrameActive
= TRUE
;
977 menuToSet
= parent_menu
;
982 // we have nothing to do with it
988 HMENU subMenu
= (HMENU
) 0;
989 if (parent
->GetWindowMenu())
990 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
992 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
995 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
996 event
.SetEventObject( this );
998 return GetEventHandler()->ProcessEvent(event
);
1001 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1003 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1004 #if defined(__WIN95__)
1005 if (!(lpPos
->flags
& SWP_NOSIZE
))
1008 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1009 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1010 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1012 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1013 lpPos
->x
= rectClient
.left
;
1014 lpPos
->y
= rectClient
.top
;
1015 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1016 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1018 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1019 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1021 pFrameWnd
->GetToolBar()->Refresh();
1029 // ---------------------------------------------------------------------------
1030 // MDI specific message translation/preprocessing
1031 // ---------------------------------------------------------------------------
1033 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1035 return DefMDIChildProc(GetHwnd(),
1036 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1039 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1041 return wxFrame::MSWTranslateMessage(msg
);
1044 // ---------------------------------------------------------------------------
1046 // ---------------------------------------------------------------------------
1048 void wxMDIChildFrame::MSWDestroyWindow()
1050 MSWDetachWindowMenu();
1051 invalidHandle
= GetHwnd();
1053 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1055 // Must make sure this handle is invalidated (set to NULL) since all sorts
1056 // of things could happen after the child client is destroyed, but before
1057 // the wxFrame is destroyed.
1059 HWND oldHandle
= (HWND
)GetHWND();
1060 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1061 (WPARAM
)oldHandle
, 0);
1063 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1064 ResetWindowStyle((void*) NULL
);
1070 ::DestroyMenu((HMENU
) m_hMenu
);
1073 wxRemoveHandleAssociation(this);
1077 // Change the client window's extended style so we don't get a client edge
1078 // style when a child is maximised (a double border looks silly.)
1079 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1081 #if defined(__WIN95__)
1082 RECT
*rect
= (RECT
*)vrect
;
1083 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1084 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1085 if (!pChild
|| (pChild
== this))
1087 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1088 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1089 DWORD dwNewStyle
= dwStyle
;
1090 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1091 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1093 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1095 if (dwStyle
!= dwNewStyle
)
1097 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1098 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1099 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1100 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1101 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1102 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1105 ::GetClientRect(hwnd
, rect
);
1115 // ===========================================================================
1116 // wxMDIClientWindow: the window of predefined (by Windows) class which
1117 // contains the child frames
1118 // ===========================================================================
1120 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1122 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1124 CLIENTCREATESTRUCT ccs
;
1125 m_windowStyle
= style
;
1128 ccs
.hWindowMenu
= (HMENU
) 0;
1129 if (parent
->GetWindowMenu())
1130 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1131 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1133 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1134 if ( style
& wxHSCROLL
)
1135 msStyle
|= WS_HSCROLL
;
1136 if ( style
& wxVSCROLL
)
1137 msStyle
|= WS_VSCROLL
;
1139 #if defined(__WIN95__)
1140 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1146 m_hWnd
= (WXHWND
)::CreateWindowEx
1156 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1159 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1164 SubclassWin(m_hWnd
);
1170 // Explicitly call default scroll behaviour
1171 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1173 // Note: for client windows, the scroll position is not set in
1174 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1175 // scroll position we're at.
1176 // This makes it hard to paint patterns or bitmaps in the background,
1177 // and have the client area scrollable as well.
1179 if ( event
.GetOrientation() == wxHORIZONTAL
)
1180 m_scrollX
= event
.GetPosition(); // Always returns zero!
1182 m_scrollY
= event
.GetPosition(); // Always returns zero!
1187 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1189 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1190 // client area, you can end up with a non-refreshed portion in the client window
1191 // (see OGL studio sample). So check if the position is changed and if so,
1192 // redraw the MDI child frames.
1194 wxPoint oldPos
= GetPosition();
1196 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1198 wxPoint newPos
= GetPosition();
1200 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1204 wxNode
* node
= GetParent()->GetChildren().First();
1207 wxWindow
* child
= (wxWindow
*) node
->Data();
1208 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1210 HWND hWnd
= (HWND
) child
->GetHWND();
1211 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1213 node
= node
->Next();
1219 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1221 // MDI child frames get their WM_SIZE when they're constructed but at this
1222 // moment they don't have any children yet so all child windows will be
1223 // positioned incorrectly when they are added later - to fix this, we
1224 // generate an artificial size event here
1225 if ( m_needsResize
)
1227 m_needsResize
= FALSE
; // avoid any possibility of recursion
1235 // ---------------------------------------------------------------------------
1236 // non member functions
1237 // ---------------------------------------------------------------------------
1239 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1241 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1243 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1245 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1249 // update menu bar of the parent window
1250 wxWindow
*parent
= win
->GetParent();
1251 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1253 ::DrawMenuBar(GetWinHwnd(parent
));
1256 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1258 // Try to insert Window menu in front of Help, otherwise append it.
1259 HMENU hmenu
= (HMENU
)menu
;
1263 int N
= GetMenuItemCount(hmenu
);
1264 bool success
= FALSE
;
1265 for ( int i
= 0; i
< N
; i
++ )
1268 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1271 wxLogLastError(wxT("GetMenuString"));
1276 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1279 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1280 (UINT
)subMenu
, _("&Window"));
1287 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1291 MDISetMenu(win
, hmenu
, subMenu
);
1294 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1296 // Try to insert Window menu in front of Help, otherwise append it.
1297 HMENU hmenu
= (HMENU
)menu
;
1298 int N
= GetMenuItemCount(hmenu
);
1299 bool success
= FALSE
;
1300 for ( int i
= 0; i
< N
; i
++ )
1303 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1306 wxLogLastError(wxT("GetMenuString"));
1311 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Window")) )
1314 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1319 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1320 MDISetMenu(win
, hmenu
, 0);
1323 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1324 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1328 *hwndAct
= (WXHWND
)lParam
;
1329 *hwndDeact
= (WXHWND
)wParam
;
1331 *activate
= (WXWORD
)wParam
;
1332 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1333 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1334 #endif // Win32/Win16