1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_MDI && !defined(__WXUNIVERSAL__)
39 #include "wx/dialog.h"
41 #include "wx/statusbr.h"
43 #include "wx/settings.h"
49 #include "wx/msw/private.h"
51 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
52 #include "wx/msw/statbr95.h"
56 #include "wx/toolbar.h"
57 #endif // wxUSE_TOOLBAR
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 extern wxMenu
*wxCurrentPopupMenu
;
67 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
68 extern const wxChar
*wxMDIChildFrameClassName
;
69 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
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;
85 static const int IDM_WINDOWPREV
= 4006;
87 // This range gives a maximum of 500 MDI children. Should be enough :-)
88 static const int wxFIRST_MDI_CHILD
= 4100;
89 static const int wxLAST_MDI_CHILD
= 4600;
91 // Status border dimensions
92 static const int wxTHICK_LINE_BORDER
= 3;
93 static const int wxTHICK_LINE_WIDTH
= 1;
95 // ---------------------------------------------------------------------------
97 // ---------------------------------------------------------------------------
99 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
100 // of the parent of win (which is supposed to be the MDI client window)
101 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
103 // insert the window menu (subMenu) into menu just before "Help" submenu or at
104 // the very end if not found
105 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
107 // Remove the window menu
108 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
110 // is this an id of an MDI child?
111 inline bool IsMdiCommandId(int id
)
113 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
116 // unpack the parameters of WM_MDIACTIVATE message
117 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
118 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
120 // return the HMENU of the MDI menu
121 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
123 wxMenu
*menu
= frame
->GetWindowMenu();
124 return menu
? GetHmenuOf(menu
) : 0;
127 // ===========================================================================
129 // ===========================================================================
131 // ---------------------------------------------------------------------------
133 // ---------------------------------------------------------------------------
135 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
136 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
137 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
139 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
140 EVT_SIZE(wxMDIParentFrame::OnSize
)
141 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
144 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
145 EVT_IDLE(wxMDIChildFrame::OnIdle
)
148 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
149 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
152 // ===========================================================================
153 // wxMDIParentFrame: the frame which contains the client window which manages
155 // ===========================================================================
157 wxMDIParentFrame::wxMDIParentFrame()
159 m_clientWindow
= NULL
;
160 m_currentChild
= NULL
;
161 m_windowMenu
= (wxMenu
*) NULL
;
162 m_parentFrameActive
= true;
165 bool wxMDIParentFrame::Create(wxWindow
*parent
,
167 const wxString
& title
,
171 const wxString
& name
)
173 m_clientWindow
= NULL
;
174 m_currentChild
= NULL
;
176 // this style can be used to prevent a window from having the standard MDI
178 if ( style
& wxFRAME_NO_WINDOW_MENU
)
180 m_windowMenu
= (wxMenu
*)NULL
;
182 else // normal case: we have the window menu, so construct it
184 m_windowMenu
= new wxMenu
;
186 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
187 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
188 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
189 m_windowMenu
->AppendSeparator();
190 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
191 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
192 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
195 m_parentFrameActive
= true;
198 wxTopLevelWindows
.Append(this);
201 m_windowStyle
= style
;
204 parent
->AddChild(this);
206 if ( id
!= wxID_ANY
)
209 m_windowId
= NewControlId();
212 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
213 msflags
&= ~WS_VSCROLL
;
214 msflags
&= ~WS_HSCROLL
;
216 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
225 // unlike (almost?) all other windows, frames are created hidden
231 wxMDIParentFrame::~wxMDIParentFrame()
233 // see comment in ~wxMDIChildFrame
235 m_frameToolBar
= NULL
;
238 m_frameStatusBar
= NULL
;
239 #endif // wxUSE_STATUSBAR
246 m_windowMenu
= (wxMenu
*) NULL
;
249 // the MDI frame menubar is not automatically deleted by Windows unlike for
253 ::DestroyMenu((HMENU
)m_hMenu
);
254 m_hMenu
= (WXHMENU
)NULL
;
257 if ( m_clientWindow
)
259 if ( m_clientWindow
->MSWGetOldWndProc() )
260 m_clientWindow
->UnsubclassWin();
262 m_clientWindow
->SetHWND(0);
263 delete m_clientWindow
;
267 #if wxUSE_MENUS_NATIVE
269 void wxMDIParentFrame::InternalSetMenuBar()
271 m_parentFrameActive
= true;
273 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
276 #endif // wxUSE_MENUS_NATIVE
278 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
284 // Remove old window menu
285 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
289 m_windowMenu
= (wxMenu
*) NULL
;
297 InsertWindowMenu(GetClientWindow(), m_hMenu
,
298 GetHmenuOf(m_windowMenu
));
303 void wxMDIParentFrame::DoMenuUpdates(wxMenu
* menu
)
305 wxMDIChildFrame
*child
= GetActiveChild();
308 wxEvtHandler
* source
= child
->GetEventHandler();
309 wxMenuBar
* bar
= child
->GetMenuBar();
313 menu
->UpdateUI(source
);
319 int nCount
= bar
->GetMenuCount();
320 for (int n
= 0; n
< nCount
; n
++)
321 bar
->GetMenu(n
)->UpdateUI(source
);
327 wxFrameBase::DoMenuUpdates(menu
);
331 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
333 if ( GetClientWindow() )
336 GetClientSize(&width
, &height
);
338 GetClientWindow()->SetSize(0, 0, width
, height
);
342 // Returns the active MDI child window
343 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
345 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
346 WM_MDIGETACTIVE
, 0, 0L);
350 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
353 // Create the client window class (don't Create the window, just return a new
355 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
357 return new wxMDIClientWindow
;
360 // Responds to colour changes, and passes event on to children.
361 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
363 if ( m_clientWindow
)
365 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
366 m_clientWindow
->Refresh();
372 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
374 // we don't have any standard icons (any more)
378 // ---------------------------------------------------------------------------
380 // ---------------------------------------------------------------------------
382 void wxMDIParentFrame::Cascade()
384 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
387 void wxMDIParentFrame::Tile(wxOrientation orient
)
389 wxASSERT_MSG( orient
== wxHORIZONTAL
|| orient
== wxVERTICAL
,
390 _T("invalid orientation value") );
392 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
,
393 orient
== wxHORIZONTAL
? MDITILE_HORIZONTAL
394 : MDITILE_VERTICAL
, 0);
397 void wxMDIParentFrame::ArrangeIcons()
399 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
402 void wxMDIParentFrame::ActivateNext()
404 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
407 void wxMDIParentFrame::ActivatePrevious()
409 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
412 // ---------------------------------------------------------------------------
413 // the MDI parent frame window proc
414 // ---------------------------------------------------------------------------
416 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
421 bool processed
= false;
427 WXWORD state
, minimized
;
429 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
431 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
439 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
441 (void)HandleCommand(id
, cmd
, hwnd
);
443 // even if the frame didn't process it, there is no need to try it
444 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
445 // so pretend we processed the message anyhow
449 // always pass this message DefFrameProc(), otherwise MDI menu
450 // commands (and sys commands - more surprisingly!) won't work
451 MSWDefWindowProc(message
, wParam
, lParam
);
455 m_clientWindow
= OnCreateClient();
456 // Uses own style for client style
457 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
459 wxLogMessage(_("Failed to create MDI parent frame."));
470 // we erase background ourselves
478 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
480 if ( m_parentFrameActive
)
482 processed
= HandleMenuSelect(item
, flags
, hmenu
);
484 else if (m_currentChild
)
486 processed
= m_currentChild
->
487 HandleMenuSelect(item
, flags
, hmenu
);
493 // as we don't (usually) resize the MDI client to exactly fit the
494 // client area (we put it below the toolbar, above statusbar &c),
495 // we should not pass this one to DefFrameProc
500 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
505 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
507 bool processed
= false;
509 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
515 // If this window is an MDI parent, we must also send an OnActivate message
516 // to the current child.
517 if ( (m_currentChild
!= NULL
) &&
518 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
520 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
521 event
.SetEventObject( m_currentChild
);
522 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
529 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
531 // In case it's e.g. a toolbar.
534 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
536 return win
->MSWCommand(cmd
, id
);
539 // is it one of standard MDI commands?
545 case IDM_WINDOWCASCADE
:
547 wParam
= MDITILE_SKIPDISABLED
;
550 case IDM_WINDOWTILEHOR
:
551 wParam
|= MDITILE_HORIZONTAL
;
554 case IDM_WINDOWTILEVERT
:
556 wParam
= MDITILE_VERTICAL
;
558 wParam
|= MDITILE_SKIPDISABLED
;
561 case IDM_WINDOWICONS
:
562 msg
= WM_MDIICONARRANGE
;
567 lParam
= 0; // next child
572 lParam
= 1; // previous child
581 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
586 // FIXME VZ: what does this test do??
589 return false; // Get WndProc to call default proc
592 if ( IsMdiCommandId(id
) )
594 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
597 wxWindow
*child
= node
->GetData();
598 if ( child
->GetHWND() )
600 long childId
= wxGetWindowId(child
->GetHWND());
601 if (childId
== (long)id
)
603 ::SendMessage( GetWinHwnd(GetClientWindow()),
605 (WPARAM
)child
->GetHWND(), 0);
609 node
= node
->GetNext();
612 else if ( m_parentFrameActive
)
614 return ProcessCommand(id
);
616 else if ( m_currentChild
)
618 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
622 // this shouldn't happen because it means that our messages are being
623 // lost (they're not sent to the parent frame nor to the children)
624 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
630 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
635 if ( GetClientWindow() )
636 clientWnd
= GetClientWindow()->GetHWND();
640 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
643 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
645 MSG
*pMsg
= (MSG
*)msg
;
647 // first let the current child get it
648 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
649 m_currentChild
->MSWTranslateMessage(msg
) )
654 // then try out accel table (will also check the menu accels)
655 if ( wxFrame::MSWTranslateMessage(msg
) )
660 // finally, check for MDI specific built in accel keys
661 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
663 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
670 // ===========================================================================
672 // ===========================================================================
674 void wxMDIChildFrame::Init()
676 m_needsResize
= true;
677 m_needsInitialShow
= true;
680 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
682 const wxString
& title
,
686 const wxString
& name
)
690 if ( id
!= wxID_ANY
)
693 m_windowId
= (int)NewControlId();
697 parent
->AddChild(this);
707 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
708 ? wxMDIChildFrameClassName
709 : wxMDIChildFrameClassNameNoRedraw
;
711 mcs
.hOwner
= wxGetInstance();
712 if (x
!= wxDefaultCoord
)
715 mcs
.x
= CW_USEDEFAULT
;
717 if (y
!= wxDefaultCoord
)
720 mcs
.y
= CW_USEDEFAULT
;
722 if (width
!= wxDefaultCoord
)
725 mcs
.cx
= CW_USEDEFAULT
;
727 if (height
!= wxDefaultCoord
)
730 mcs
.cy
= CW_USEDEFAULT
;
732 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
733 if (style
& wxMINIMIZE_BOX
)
734 msflags
|= WS_MINIMIZEBOX
;
735 if (style
& wxMAXIMIZE_BOX
)
736 msflags
|= WS_MAXIMIZEBOX
;
737 if (style
& wxTHICK_FRAME
)
738 msflags
|= WS_THICKFRAME
;
739 if (style
& wxSYSTEM_MENU
)
740 msflags
|= WS_SYSMENU
;
741 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
742 msflags
|= WS_MINIMIZE
;
743 if (style
& wxMAXIMIZE
)
744 msflags
|= WS_MAXIMIZE
;
745 if (style
& wxCAPTION
)
746 msflags
|= WS_CAPTION
;
752 wxWindowCreationHook
hook(this);
754 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
755 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
757 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
762 wxMDIChildFrame::~wxMDIChildFrame()
764 // will be destroyed by DestroyChildren() but reset them before calling it
765 // to avoid using dangling pointers if a callback comes in the meanwhile
767 m_frameToolBar
= NULL
;
770 m_frameStatusBar
= NULL
;
771 #endif // wxUSE_STATUSBAR
775 RemoveWindowMenu(NULL
, m_hMenu
);
780 bool wxMDIChildFrame::Show(bool show
)
782 m_needsInitialShow
= false;
783 return wxFrame::Show(show
);
786 // Set the client size (i.e. leave the calculation of borders etc.
788 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
790 HWND hWnd
= GetHwnd();
793 ::GetClientRect(hWnd
, &rect
);
796 GetWindowRect(hWnd
, &rect2
);
798 // Find the difference between the entire window (title bar and all)
799 // and the client area; add this to the new client size to move the
801 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
802 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
805 if (GetStatusBar() && GetStatusBar()->IsShown())
808 GetStatusBar()->GetSize(&sx
, &sy
);
811 #endif // wxUSE_STATUSBAR
814 point
.x
= rect2
.left
;
817 // If there's an MDI parent, must subtract the parent's top left corner
818 // since MoveWindow moves relative to the parent
819 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
820 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
822 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
824 wxSize
size(width
, height
);
825 wxSizeEvent
event(size
, m_windowId
);
826 event
.SetEventObject( this );
827 GetEventHandler()->ProcessEvent(event
);
830 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
833 GetWindowRect(GetHwnd(), &rect
);
838 // Since we now have the absolute screen coords,
839 // if there's a parent we must subtract its top left corner
840 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
841 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
847 void wxMDIChildFrame::InternalSetMenuBar()
849 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
851 InsertWindowMenu(parent
->GetClientWindow(),
852 m_hMenu
, GetMDIWindowMenu(parent
));
854 parent
->m_parentFrameActive
= false;
857 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
859 // we don't have any standard icons (any more)
863 // ---------------------------------------------------------------------------
865 // ---------------------------------------------------------------------------
867 void wxMDIChildFrame::Maximize(bool maximize
)
869 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
870 if ( parent
&& parent
->GetClientWindow() )
872 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
873 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
874 (WPARAM
)GetHwnd(), 0);
878 void wxMDIChildFrame::Restore()
880 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
881 if ( parent
&& parent
->GetClientWindow() )
883 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
884 (WPARAM
) GetHwnd(), 0);
888 void wxMDIChildFrame::Activate()
890 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
891 if ( parent
&& parent
->GetClientWindow() )
893 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
894 (WPARAM
) GetHwnd(), 0);
898 // ---------------------------------------------------------------------------
899 // MDI window proc and message handlers
900 // ---------------------------------------------------------------------------
902 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
907 bool processed
= false;
915 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
918 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
922 case WM_GETMINMAXINFO
:
923 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
929 WXHWND hwndAct
, hwndDeact
;
930 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
932 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
937 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
938 // scrollbars if necessary
943 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
945 MSWDefWindowProc(message
, wParam
, lParam
);
949 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
950 // the message (the base class version does not)
951 return MSWDefWindowProc(message
, wParam
, lParam
);
953 case WM_WINDOWPOSCHANGING
:
954 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
959 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
964 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
966 // In case it's e.g. a toolbar.
969 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
971 return win
->MSWCommand(cmd
, id
);
974 if (wxCurrentPopupMenu
)
976 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
977 wxCurrentPopupMenu
= NULL
;
978 if (popupMenu
->MSWCommand(cmd
, id
))
983 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
985 processed
= ProcessCommand(id
);
995 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
999 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1001 HMENU menuToSet
= 0;
1005 if ( m_hWnd
== hwndAct
)
1008 parent
->m_currentChild
= this;
1010 HMENU child_menu
= (HMENU
)GetWinMenu();
1013 parent
->m_parentFrameActive
= false;
1015 menuToSet
= child_menu
;
1018 else if ( m_hWnd
== hwndDeact
)
1020 wxASSERT_MSG( parent
->m_currentChild
== this,
1021 wxT("can't deactivate MDI child which wasn't active!") );
1024 parent
->m_currentChild
= NULL
;
1026 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
1028 // activate the the parent menu only when there is no other child
1029 // that has been activated
1030 if ( parent_menu
&& !hwndAct
)
1032 parent
->m_parentFrameActive
= true;
1034 menuToSet
= parent_menu
;
1039 // we have nothing to do with it
1045 MDISetMenu(parent
->GetClientWindow(),
1046 menuToSet
, GetMDIWindowMenu(parent
));
1049 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1050 event
.SetEventObject( this );
1052 ResetWindowStyle((void *)NULL
);
1054 return GetEventHandler()->ProcessEvent(event
);
1057 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1059 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1060 #if defined(__WIN95__)
1061 if (!(lpPos
->flags
& SWP_NOSIZE
))
1064 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1065 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1066 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1068 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1069 lpPos
->x
= rectClient
.left
;
1070 lpPos
->y
= rectClient
.top
;
1071 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1072 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1075 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1076 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1078 pFrameWnd
->GetToolBar()->Refresh();
1087 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1089 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1091 // let the default window proc calculate the size of MDI children
1092 // frames because it is based on the size of the MDI client window,
1093 // not on the values specified in wxWindow m_max variables
1094 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1096 int minWidth
= GetMinWidth(),
1097 minHeight
= GetMinHeight();
1099 // but allow GetSizeHints() to set the min size
1100 if ( minWidth
!= -1 )
1102 info
->ptMinTrackSize
.x
= minWidth
;
1107 if ( minHeight
!= -1 )
1109 info
->ptMinTrackSize
.y
= minHeight
;
1117 // ---------------------------------------------------------------------------
1118 // MDI specific message translation/preprocessing
1119 // ---------------------------------------------------------------------------
1121 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1123 return DefMDIChildProc(GetHwnd(),
1124 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1127 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1129 return wxFrame::MSWTranslateMessage(msg
);
1132 // ---------------------------------------------------------------------------
1134 // ---------------------------------------------------------------------------
1136 void wxMDIChildFrame::MSWDestroyWindow()
1138 invalidHandle
= GetHwnd();
1140 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1142 // Must make sure this handle is invalidated (set to NULL) since all sorts
1143 // of things could happen after the child client is destroyed, but before
1144 // the wxFrame is destroyed.
1146 HWND oldHandle
= (HWND
)GetHWND();
1147 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1148 (WPARAM
)oldHandle
, 0);
1150 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1151 ResetWindowStyle((void*) NULL
);
1157 ::DestroyMenu((HMENU
) m_hMenu
);
1160 wxRemoveHandleAssociation(this);
1164 // Change the client window's extended style so we don't get a client edge
1165 // style when a child is maximised (a double border looks silly.)
1166 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1168 #if defined(__WIN95__)
1169 RECT
*rect
= (RECT
*)vrect
;
1170 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1171 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1172 if (!pChild
|| (pChild
== this))
1174 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1175 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1177 // we want to test whether there is a maximized child, so just set
1178 // dwThisStyle to 0 if there is no child at all
1179 DWORD dwThisStyle
= pChild
1180 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1181 DWORD dwNewStyle
= dwStyle
;
1182 if ( dwThisStyle
& WS_MAXIMIZE
)
1183 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1185 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1187 if (dwStyle
!= dwNewStyle
)
1189 // force update of everything
1190 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1191 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1192 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1193 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1194 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1195 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1198 ::GetClientRect(hwndClient
, rect
);
1208 // ===========================================================================
1209 // wxMDIClientWindow: the window of predefined (by Windows) class which
1210 // contains the child frames
1211 // ===========================================================================
1213 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1215 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1217 CLIENTCREATESTRUCT ccs
;
1218 m_windowStyle
= style
;
1221 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1222 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1224 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1225 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1227 if ( style
& wxHSCROLL
)
1228 msStyle
|= WS_HSCROLL
;
1229 if ( style
& wxVSCROLL
)
1230 msStyle
|= WS_VSCROLL
;
1232 #if defined(__WIN95__)
1233 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1238 wxWindowCreationHook
hook(this);
1239 m_hWnd
= (WXHWND
)::CreateWindowEx
1249 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1252 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1257 SubclassWin(m_hWnd
);
1262 // Explicitly call default scroll behaviour
1263 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1265 // Note: for client windows, the scroll position is not set in
1266 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1267 // scroll position we're at.
1268 // This makes it hard to paint patterns or bitmaps in the background,
1269 // and have the client area scrollable as well.
1271 if ( event
.GetOrientation() == wxHORIZONTAL
)
1272 m_scrollX
= event
.GetPosition(); // Always returns zero!
1274 m_scrollY
= event
.GetPosition(); // Always returns zero!
1279 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1281 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1282 // client area, you can end up with a non-refreshed portion in the client window
1283 // (see OGL studio sample). So check if the position is changed and if so,
1284 // redraw the MDI child frames.
1286 wxPoint oldPos
= GetPosition();
1288 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1290 wxPoint newPos
= GetPosition();
1292 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1296 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1299 wxWindow
*child
= node
->GetData();
1300 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1302 ::RedrawWindow(GetHwndOf(child
),
1309 node
= node
->GetNext();
1315 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1317 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1318 // in flicker e.g. when the frame contained controls with non-trivial
1319 // layout. Since 2.5.3, the frame is created hidden as all other top level
1320 // windows. In order to maintain backward compatibility, the frame is shown
1321 // in OnIdle, unless Show(false) was called by the programmer before.
1322 if ( m_needsInitialShow
)
1327 // MDI child frames get their WM_SIZE when they're constructed but at this
1328 // moment they don't have any children yet so all child windows will be
1329 // positioned incorrectly when they are added later - to fix this, we
1330 // generate an artificial size event here
1331 if ( m_needsResize
)
1333 m_needsResize
= false; // avoid any possibility of recursion
1341 // ---------------------------------------------------------------------------
1342 // non member functions
1343 // ---------------------------------------------------------------------------
1345 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1347 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1349 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1351 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1355 // update menu bar of the parent window
1356 wxWindow
*parent
= win
->GetParent();
1357 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1359 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1361 ::DrawMenuBar(GetWinHwnd(parent
));
1364 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1366 // Try to insert Window menu in front of Help, otherwise append it.
1367 HMENU hmenu
= (HMENU
)menu
;
1371 int N
= GetMenuItemCount(hmenu
);
1372 bool success
= false;
1373 for ( int i
= 0; i
< N
; i
++ )
1376 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1379 wxLogLastError(wxT("GetMenuString"));
1384 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1387 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1388 (UINT
)subMenu
, _("&Window"));
1395 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1399 MDISetMenu(win
, hmenu
, subMenu
);
1402 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1404 HMENU hMenu
= (HMENU
)menu
;
1410 int N
= ::GetMenuItemCount(hMenu
);
1411 for ( int i
= 0; i
< N
; i
++ )
1413 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1415 // Ignore successful read of menu string with length 0 which
1416 // occurs, for example, for a maximized MDI childs system menu
1417 if ( ::GetLastError() != 0 )
1419 wxLogLastError(wxT("GetMenuString"));
1425 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1427 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1429 wxLogLastError(wxT("RemoveMenu"));
1439 // we don't change the windows menu, but we update the main one
1440 MDISetMenu(win
, hMenu
, NULL
);
1444 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1445 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1448 *hwndAct
= (WXHWND
)lParam
;
1449 *hwndDeact
= (WXHWND
)wParam
;
1452 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)