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
);
72 static HWND invalidHandle
= 0;
74 // ---------------------------------------------------------------------------
76 // ---------------------------------------------------------------------------
78 static const int IDM_WINDOWTILE
= 4001;
79 static const int IDM_WINDOWTILEHOR
= 4001;
80 static const int IDM_WINDOWCASCADE
= 4002;
81 static const int IDM_WINDOWICONS
= 4003;
82 static const int IDM_WINDOWNEXT
= 4004;
83 static const int IDM_WINDOWTILEVERT
= 4005;
85 // This range gives a maximum of 500 MDI children. Should be enough :-)
86 static const int wxFIRST_MDI_CHILD
= 4100;
87 static const int wxLAST_MDI_CHILD
= 4600;
89 // Status border dimensions
90 static const int wxTHICK_LINE_BORDER
= 3;
91 static const int wxTHICK_LINE_WIDTH
= 1;
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
98 // of the parent of win (which is supposed to be the MDI client window)
99 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
101 // insert the window menu (subMenu) into menu just before "Help" submenu or at
102 // the very end if not found
103 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
105 // Remove the window menu
106 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
108 // is this an id of an MDI child?
109 inline bool IsMdiCommandId(int id
)
111 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
114 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
115 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
117 // ===========================================================================
119 // ===========================================================================
121 // ---------------------------------------------------------------------------
123 // ---------------------------------------------------------------------------
125 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
126 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
127 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
129 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
130 EVT_SIZE(wxMDIParentFrame::OnSize
)
131 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
134 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
135 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
138 // ===========================================================================
139 // wxMDIParentFrame: the frame which contains the client window which manages
141 // ===========================================================================
143 wxMDIParentFrame::wxMDIParentFrame()
145 m_clientWindow
= NULL
;
146 m_currentChild
= NULL
;
147 m_windowMenu
= (wxMenu
*) NULL
;
148 m_parentFrameActive
= TRUE
;
151 bool wxMDIParentFrame::Create(wxWindow
*parent
,
153 const wxString
& title
,
157 const wxString
& name
)
159 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
161 m_clientWindow
= NULL
;
162 m_currentChild
= NULL
;
164 if (style
& wxFRAME_NO_WINDOW_MENU
)
165 m_windowMenu
= (wxMenu
*) NULL
;
168 // m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
169 m_windowMenu
= new wxMenu
;
172 m_windowMenu
->Append(4002, wxT("&Cascade"));
173 m_windowMenu
->Append(4001, wxT("Tile &Horizontally"));
174 m_windowMenu
->Append(4005, wxT("Tile &Vertically"));
175 m_windowMenu
->AppendSeparator();
176 m_windowMenu
->Append(4003, wxT("&Arrange Icons"));
177 m_windowMenu
->Append(4004, wxT("&Next"));
180 m_parentFrameActive
= TRUE
;
183 wxTopLevelWindows
.Append(this);
186 m_windowStyle
= style
;
188 if (parent
) parent
->AddChild(this);
193 m_windowId
= (int)NewControlId();
200 DWORD msflags
= WS_OVERLAPPED
;
201 if (style
& wxMINIMIZE_BOX
)
202 msflags
|= WS_MINIMIZEBOX
;
203 if (style
& wxMAXIMIZE_BOX
)
204 msflags
|= WS_MAXIMIZEBOX
;
205 if (style
& wxTHICK_FRAME
)
206 msflags
|= WS_THICKFRAME
;
207 if (style
& wxSYSTEM_MENU
)
208 msflags
|= WS_SYSMENU
;
209 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
210 msflags
|= WS_MINIMIZE
;
211 if (style
& wxMAXIMIZE
)
212 msflags
|= WS_MAXIMIZE
;
213 if (style
& wxCAPTION
)
214 msflags
|= WS_CAPTION
;
216 if (style
& wxCLIP_CHILDREN
)
217 msflags
|= WS_CLIPCHILDREN
;
219 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
222 wxModelessWindows
.Append(this);
227 wxMDIParentFrame::~wxMDIParentFrame()
230 // already delete by DestroyChildren()
231 m_frameToolBar
= NULL
;
233 // ::DestroyMenu((HMENU)m_windowMenu);
237 m_windowMenu
= (wxMenu
*) NULL
;
240 if ( m_clientWindow
)
242 if ( m_clientWindow
->MSWGetOldWndProc() )
243 m_clientWindow
->UnsubclassWin();
245 m_clientWindow
->SetHWND(0);
246 delete m_clientWindow
;
250 void wxMDIParentFrame::InternalSetMenuBar()
252 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
254 m_parentFrameActive
= TRUE
;
256 HMENU subMenu
= (HMENU
) 0;
258 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
260 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
263 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
269 // Remove old window menu
270 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
274 m_windowMenu
= (wxMenu
*) NULL
;
280 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
284 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
286 if ( GetClientWindow() )
289 GetClientSize(&width
, &height
);
291 GetClientWindow()->SetSize(0, 0, width
, height
);
295 // Returns the active MDI child window
296 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
298 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
299 WM_MDIGETACTIVE
, 0, 0L);
303 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
306 // Create the client window class (don't Create the window, just return a new
308 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
310 return new wxMDIClientWindow
;
313 // Responds to colour changes, and passes event on to children.
314 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
316 if ( m_clientWindow
)
318 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
319 m_clientWindow
->Refresh();
325 // ---------------------------------------------------------------------------
327 // ---------------------------------------------------------------------------
329 void wxMDIParentFrame::Cascade()
331 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
334 // TODO: add a direction argument (hor/vert)
335 void wxMDIParentFrame::Tile()
337 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
340 void wxMDIParentFrame::ArrangeIcons()
342 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
345 void wxMDIParentFrame::ActivateNext()
347 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
350 void wxMDIParentFrame::ActivatePrevious()
352 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
355 // ---------------------------------------------------------------------------
356 // the MDI parent frame window proc
357 // ---------------------------------------------------------------------------
359 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
364 bool processed
= FALSE
;
370 WXWORD state
, minimized
;
372 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
374 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
382 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
384 (void)HandleCommand(id
, cmd
, hwnd
);
386 // even if the frame didn't process it, there is no need to try it
387 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
388 // so pretend we processed the message anyhow
392 // always pass this message DefFrameProc(), otherwise MDI menu
393 // commands (and sys commands - more surprizingly!) won't work
394 MSWDefWindowProc(message
, wParam
, lParam
);
398 m_clientWindow
= OnCreateClient();
399 // Uses own style for client style
400 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
402 wxLogMessage(_("Failed to create MDI parent frame."));
413 // we erase background ourselves
421 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
423 if ( m_parentFrameActive
)
425 processed
= HandleMenuSelect(item
, flags
, hmenu
);
427 else if (m_currentChild
)
429 processed
= m_currentChild
->
430 HandleMenuSelect(item
, flags
, hmenu
);
436 // as we don't (usually) resize the MDI client to exactly fit the
437 // client area (we put it below the toolbar, above statusbar &c),
438 // we should not pass this one to DefFrameProc
443 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
448 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
450 bool processed
= FALSE
;
452 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
458 // If this window is an MDI parent, we must also send an OnActivate message
459 // to the current child.
460 if ( (m_currentChild
!= NULL
) &&
461 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
463 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
464 event
.SetEventObject( m_currentChild
);
465 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
472 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
474 // In case it's e.g. a toolbar.
477 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
479 return win
->MSWCommand(cmd
, id
);
482 // is it one of standard MDI commands?
487 case IDM_WINDOWCASCADE
:
489 wParam
= MDITILE_SKIPDISABLED
;
492 case IDM_WINDOWTILEHOR
:
493 wParam
|= MDITILE_HORIZONTAL
;
496 case IDM_WINDOWTILEVERT
:
498 wParam
= MDITILE_VERTICAL
;
500 wParam
|= MDITILE_SKIPDISABLED
;
503 case IDM_WINDOWICONS
:
504 msg
= WM_MDIICONARRANGE
;
517 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
522 // FIXME VZ: what does this test do??
525 return FALSE
; // Get WndProc to call default proc
528 if ( IsMdiCommandId(id
) )
530 wxWindowList::Node
* node
= GetChildren().GetFirst();
533 wxWindow
* child
= node
->GetData();
534 if ( child
->GetHWND() )
536 long childId
= wxGetWindowId(child
->GetHWND());
537 if (childId
== (long)id
)
539 ::SendMessage( GetWinHwnd(GetClientWindow()),
541 (WPARAM
)child
->GetHWND(), 0);
545 node
= node
->GetNext();
548 else if ( m_parentFrameActive
)
550 return ProcessCommand(id
);
552 else if ( m_currentChild
)
554 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
558 // this shouldn't happen because it means that our messages are being
559 // lost (they're not sent to the parent frame nor to the children)
560 wxFAIL_MSG(wxT("MDI parent frame is not active, "
561 "yet there is no active MDI child?"));
567 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
572 if ( GetClientWindow() )
573 clientWnd
= GetClientWindow()->GetHWND();
577 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
580 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
582 MSG
*pMsg
= (MSG
*)msg
;
584 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
585 m_currentChild
->MSWTranslateMessage(msg
) )
590 if ( m_acceleratorTable
.Translate(this, msg
) )
595 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
597 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
604 // ===========================================================================
606 // ===========================================================================
608 wxMDIChildFrame::wxMDIChildFrame()
612 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
614 const wxString
& title
,
618 const wxString
& name
)
620 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
621 : wxDEFAULT_MDICHILDFRAME_ICON
);
628 m_windowId
= (int)NewControlId();
632 parent
->AddChild(this);
644 mcs
.szClass
= wxMDIChildFrameClassName
;
646 mcs
.hOwner
= wxGetInstance();
650 mcs
.x
= CW_USEDEFAULT
;
655 mcs
.y
= CW_USEDEFAULT
;
660 mcs
.cx
= CW_USEDEFAULT
;
665 mcs
.cy
= CW_USEDEFAULT
;
667 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
668 if (style
& wxMINIMIZE_BOX
)
669 msflags
|= WS_MINIMIZEBOX
;
670 if (style
& wxMAXIMIZE_BOX
)
671 msflags
|= WS_MAXIMIZEBOX
;
672 if (style
& wxTHICK_FRAME
)
673 msflags
|= WS_THICKFRAME
;
674 if (style
& wxSYSTEM_MENU
)
675 msflags
|= WS_SYSMENU
;
676 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
677 msflags
|= WS_MINIMIZE
;
678 if (style
& wxMAXIMIZE
)
679 msflags
|= WS_MAXIMIZE
;
680 if (style
& wxCAPTION
)
681 msflags
|= WS_CAPTION
;
687 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
688 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
690 //handle = (HWND)LOWORD(Return);
691 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
692 m_hWnd
= (WXHWND
)Return
;
695 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
697 // VZ: what's this? an act of piracy?
698 //SetWindowLong(GetHwnd(), 0, (long)this);
700 wxModelessWindows
.Append(this);
704 wxMDIChildFrame::~wxMDIChildFrame()
709 // Set the client size (i.e. leave the calculation of borders etc.
711 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
713 HWND hWnd
= GetHwnd();
716 ::GetClientRect(hWnd
, &rect
);
719 GetWindowRect(hWnd
, &rect2
);
721 // Find the difference between the entire window (title bar and all)
722 // and the client area; add this to the new client size to move the
724 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
725 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
727 if (GetStatusBar() && GetStatusBar()->IsShown())
730 GetStatusBar()->GetSize(&sx
, &sy
);
735 point
.x
= rect2
.left
;
738 // If there's an MDI parent, must subtract the parent's top left corner
739 // since MoveWindow moves relative to the parent
740 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
741 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
743 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
745 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
746 event
.SetEventObject( this );
747 GetEventHandler()->ProcessEvent(event
);
750 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
753 GetWindowRect(GetHwnd(), &rect
);
758 // Since we now have the absolute screen coords,
759 // if there's a parent we must subtract its top left corner
760 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
761 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
767 void wxMDIChildFrame::InternalSetMenuBar()
769 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
771 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
772 HMENU subMenu
= (HMENU
) 0;
773 if (parent
->GetWindowMenu())
774 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
776 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
778 parent
->m_parentFrameActive
= FALSE
;
781 // ---------------------------------------------------------------------------
783 // ---------------------------------------------------------------------------
785 void wxMDIChildFrame::Maximize(bool maximize
)
787 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
788 if ( parent
&& parent
->GetClientWindow() )
790 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
791 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
792 (WPARAM
)GetHwnd(), 0);
796 void wxMDIChildFrame::Restore()
798 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
799 if ( parent
&& parent
->GetClientWindow() )
801 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
802 (WPARAM
) GetHwnd(), 0);
806 void wxMDIChildFrame::Activate()
808 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
809 if ( parent
&& parent
->GetClientWindow() )
811 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
812 (WPARAM
) GetHwnd(), 0);
816 // ---------------------------------------------------------------------------
817 // MDI window proc and message handlers
818 // ---------------------------------------------------------------------------
820 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
825 bool processed
= FALSE
;
833 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
836 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
840 case WM_GETMINMAXINFO
:
841 // let the default window proc calculate the size of MDI children
842 // frames because it is based on the size of the MDI client window,
843 // not on the values specified in wxWindow m_min/max variables
844 return MSWDefWindowProc(message
, wParam
, lParam
);
849 WXHWND hwndAct
, hwndDeact
;
850 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
852 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
857 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
858 // scrollbars if necessary
863 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
865 MSWDefWindowProc(message
, wParam
, lParam
);
869 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
870 // the message (the base class version does not)
871 return MSWDefWindowProc(message
, wParam
, lParam
);
873 case WM_WINDOWPOSCHANGING
:
874 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
879 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
884 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
886 // In case it's e.g. a toolbar.
889 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
891 return win
->MSWCommand(cmd
, id
);
894 if (wxCurrentPopupMenu
)
896 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
897 wxCurrentPopupMenu
= NULL
;
898 if (popupMenu
->MSWCommand(cmd
, id
))
902 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
913 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
917 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
923 if ( m_hWnd
== hwndAct
)
926 parent
->m_currentChild
= this;
928 HMENU child_menu
= (HMENU
)GetWinMenu();
931 parent
->m_parentFrameActive
= FALSE
;
933 menuToSet
= child_menu
;
936 else if ( m_hWnd
== hwndDeact
)
938 wxASSERT_MSG( parent
->m_currentChild
== this,
939 wxT("can't deactivate MDI child which wasn't active!") );
942 parent
->m_currentChild
= NULL
;
944 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
947 parent
->m_parentFrameActive
= TRUE
;
949 menuToSet
= parent_menu
;
954 // we have nothing to do with it
960 HMENU subMenu
= (HMENU
) 0;
961 if (parent
->GetWindowMenu())
962 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
964 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
967 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
968 event
.SetEventObject( this );
970 return GetEventHandler()->ProcessEvent(event
);
973 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
975 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
976 #if defined(__WIN95__)
977 if (!(lpPos
->flags
& SWP_NOSIZE
))
980 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
981 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
982 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
984 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
985 lpPos
->x
= rectClient
.left
;
986 lpPos
->y
= rectClient
.top
;
987 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
988 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
990 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
991 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
993 pFrameWnd
->GetToolBar()->Refresh();
1001 // ---------------------------------------------------------------------------
1002 // MDI specific message translation/preprocessing
1003 // ---------------------------------------------------------------------------
1005 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1007 return DefMDIChildProc(GetHwnd(),
1008 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1011 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1013 return m_acceleratorTable
.Translate(GetParent(), msg
);
1016 // ---------------------------------------------------------------------------
1018 // ---------------------------------------------------------------------------
1020 void wxMDIChildFrame::MSWDestroyWindow()
1022 MSWDetachWindowMenu();
1023 invalidHandle
= GetHwnd();
1025 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1027 // Must make sure this handle is invalidated (set to NULL) since all sorts
1028 // of things could happen after the child client is destroyed, but before
1029 // the wxFrame is destroyed.
1031 HWND oldHandle
= (HWND
)GetHWND();
1032 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1033 (WPARAM
)oldHandle
, 0);
1035 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1036 ResetWindowStyle((void*) NULL
);
1042 ::DestroyMenu((HMENU
) m_hMenu
);
1048 // Change the client window's extended style so we don't get a client edge
1049 // style when a child is maximised (a double border looks silly.)
1050 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1052 #if defined(__WIN95__)
1053 RECT
*rect
= (RECT
*)vrect
;
1054 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1055 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1056 if (!pChild
|| (pChild
== this))
1058 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1059 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1060 DWORD dwNewStyle
= dwStyle
;
1061 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1062 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1064 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1066 if (dwStyle
!= dwNewStyle
)
1068 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1069 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1070 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1071 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1072 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1073 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1076 ::GetClientRect(hwnd
, rect
);
1086 // ===========================================================================
1087 // wxMDIClientWindow: the window of predefined (by Windows) class which
1088 // contains the child frames
1089 // ===========================================================================
1091 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1093 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1095 CLIENTCREATESTRUCT ccs
;
1096 m_windowStyle
= style
;
1099 ccs
.hWindowMenu
= (HMENU
) 0;
1100 if (parent
->GetWindowMenu())
1101 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1102 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1104 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1105 if ( style
& wxHSCROLL
)
1106 msStyle
|= WS_HSCROLL
;
1107 if ( style
& wxVSCROLL
)
1108 msStyle
|= WS_VSCROLL
;
1110 #if defined(__WIN95__)
1111 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1117 m_hWnd
= (WXHWND
)::CreateWindowEx
1127 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1130 wxLogLastError("CreateWindowEx(MDI client)");
1135 SubclassWin(m_hWnd
);
1141 // Explicitly call default scroll behaviour
1142 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1144 // Note: for client windows, the scroll position is not set in
1145 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1146 // scroll position we're at.
1147 // This makes it hard to paint patterns or bitmaps in the background,
1148 // and have the client area scrollable as well.
1150 if ( event
.GetOrientation() == wxHORIZONTAL
)
1151 m_scrollX
= event
.GetPosition(); // Always returns zero!
1153 m_scrollY
= event
.GetPosition(); // Always returns zero!
1158 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1160 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1161 // client area, you can end up with a non-refreshed portion in the client window
1162 // (see OGL studio sample). So check if the position is changed and if so,
1163 // redraw the MDI child frames.
1165 wxPoint oldPos
= GetPosition();
1167 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1169 wxPoint newPos
= GetPosition();
1171 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1175 wxNode
* node
= GetParent()->GetChildren().First();
1178 wxWindow
* child
= (wxWindow
*) node
->Data();
1179 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1181 HWND hWnd
= (HWND
) child
->GetHWND();
1182 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1184 node
= node
->Next();
1190 // ---------------------------------------------------------------------------
1191 // non member functions
1192 // ---------------------------------------------------------------------------
1194 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1196 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1198 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1200 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1203 // update menu bar of the parent window
1204 wxWindow
*parent
= win
->GetParent();
1205 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1207 ::DrawMenuBar(GetWinHwnd(parent
));
1210 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1212 // Try to insert Window menu in front of Help, otherwise append it.
1213 HMENU hmenu
= (HMENU
)menu
;
1217 int N
= GetMenuItemCount(hmenu
);
1218 bool success
= FALSE
;
1219 for ( int i
= 0; i
< N
; i
++ )
1222 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1225 wxLogLastError(wxT("GetMenuString"));
1230 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Help")) )
1233 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1234 (UINT
)subMenu
, wxT("&Window"));
1241 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, wxT("&Window"));
1245 MDISetMenu(win
, hmenu
, subMenu
);
1248 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1250 // Try to insert Window menu in front of Help, otherwise append it.
1251 HMENU hmenu
= (HMENU
)menu
;
1252 int N
= GetMenuItemCount(hmenu
);
1253 bool success
= FALSE
;
1254 for ( int i
= 0; i
< N
; i
++ )
1257 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1260 wxLogLastError(wxT("GetMenuString"));
1265 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Window")) )
1268 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1273 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1274 MDISetMenu(win
, hmenu
, 0);
1277 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1278 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1282 *hwndAct
= (WXHWND
)lParam
;
1283 *hwndDeact
= (WXHWND
)wParam
;
1285 *activate
= (WXWORD
)wParam
;
1286 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1287 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1288 #endif // Win32/Win16