1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/dialog.h"
30 #include "wx/statusbr.h"
31 #include "wx/settings.h"
35 #include "wx/msw/private.h"
37 #if wxUSE_NATIVE_STATUSBAR
38 #include <wx/msw/statbr95.h>
43 extern wxList wxModelessWindows
;
44 extern wxMenu
*wxCurrentPopupMenu
;
46 #define IDM_WINDOWTILE 4001
47 #define IDM_WINDOWCASCADE 4002
48 #define IDM_WINDOWICONS 4003
49 #define IDM_WINDOWNEXT 4004
50 // This range gives a maximum of 500
51 // MDI children. Should be enough :-)
52 #define wxFIRST_MDI_CHILD 4100
53 #define wxLAST_MDI_CHILD 4600
55 // Status border dimensions
56 #define wxTHICK_LINE_BORDER 3
57 #define wxTHICK_LINE_WIDTH 1
59 extern char wxMDIFrameClassName
[];
60 extern char wxMDIChildFrameClassName
[];
61 extern wxWindow
*wxWndHook
;
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
65 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
66 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
68 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
69 EVT_SIZE(wxMDIParentFrame::OnSize
)
70 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
71 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
74 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
75 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
80 wxMDIParentFrame::wxMDIParentFrame()
82 m_clientWindow
= NULL
;
83 m_currentChild
= NULL
;
85 m_parentFrameActive
= TRUE
;
88 bool wxMDIParentFrame::Create(wxWindow
*parent
,
90 const wxString
& title
,
96 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
98 m_clientWindow
= NULL
;
99 m_currentChild
= NULL
;
101 m_parentFrameActive
= TRUE
;
104 wxTopLevelWindows
.Append(this);
107 m_windowStyle
= style
;
109 if (parent
) parent
->AddChild(this);
114 m_windowId
= (int)NewControlId();
121 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), "wxWindowMenu");
123 DWORD msflags
= WS_OVERLAPPED
;
124 if (style
& wxMINIMIZE_BOX
)
125 msflags
|= WS_MINIMIZEBOX
;
126 if (style
& wxMAXIMIZE_BOX
)
127 msflags
|= WS_MAXIMIZEBOX
;
128 if (style
& wxTHICK_FRAME
)
129 msflags
|= WS_THICKFRAME
;
130 if (style
& wxSYSTEM_MENU
)
131 msflags
|= WS_SYSMENU
;
132 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
133 msflags
|= WS_MINIMIZE
;
134 if (style
& wxMAXIMIZE
)
135 msflags
|= WS_MAXIMIZE
;
136 if (style
& wxCAPTION
)
137 msflags
|= WS_CAPTION
;
139 // Adding WS_CLIPCHILDREN causes children not to be properly
140 // drawn when first displaying them.
141 // if (style & wxCLIP_CHILDREN)
142 // msflags |= WS_CLIPCHILDREN;
144 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
147 wxModelessWindows
.Append(this);
152 wxMDIParentFrame::~wxMDIParentFrame()
156 DestroyMenu((HMENU
) m_windowMenu
); // Destroy dummy "Window" menu
159 if (m_clientWindow
->MSWGetOldWndProc())
160 m_clientWindow
->UnsubclassWin();
162 m_clientWindow
->m_hWnd
= 0;
163 delete m_clientWindow
;
166 // Get size *available for subwindows* i.e. excluding menu bar.
167 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
170 ::GetClientRect((HWND
) GetHWND(), &rect
);
172 int cwidth
= rect
.right
;
173 int cheight
= rect
.bottom
;
175 if ( GetStatusBar() )
178 GetStatusBar()->GetSize(&sw
, &sh
);
182 wxPoint
pt(GetClientAreaOrigin());
190 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
194 m_frameMenuBar
= NULL
;
198 if ( menu_bar
->IsAttached() )
201 m_hMenu
= menu_bar
->Create();
204 delete m_frameMenuBar
;
206 // MDI parent-specific code follows
208 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
210 // Try to insert Window menu in front of Help, otherwise append it.
211 HMENU menu
= (HMENU
)m_hMenu
;
212 int N
= GetMenuItemCount(menu
);
213 bool success
= FALSE
;
214 for (int i
= 0; i
< N
; i
++)
217 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
218 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
219 strcmp(buf
, "Help") == 0))
222 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
223 (UINT
)subMenu
, "&Window");
228 AppendMenu(menu
, MF_POPUP
,
231 m_parentFrameActive
= TRUE
;
233 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
237 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
238 MAKELPARAM(menu
, subMenu
));
240 DrawMenuBar((HWND
) GetHWND());
242 m_frameMenuBar
= menu_bar
;
243 menu_bar
->Attach(this);
246 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
248 #if wxUSE_CONSTRAINTS
255 GetClientSize(&width
, &height
);
257 if ( GetClientWindow() )
258 GetClientWindow()->SetSize(x
, y
, width
, height
);
260 /* Already done in MSWOnSize
261 // forward WM_SIZE to status bar control
262 #if wxUSE_NATIVE_STATUSBAR
263 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
264 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
270 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
275 // Returns the active MDI child window
276 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
278 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
279 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
283 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
286 // Create the client window class (don't Create the window,
287 // just return a new class)
288 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
290 return new wxMDIClientWindow
;
293 // Responds to colour changes, and passes event on to children.
294 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
296 if ( m_clientWindow
)
298 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
299 m_clientWindow
->Refresh();
302 if ( m_frameToolBar )
304 wxSysColourChangedEvent event2;
305 event2.eventObject = m_frameToolBar;
306 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
310 // Propagate the event to the non-top-level children
311 wxFrame::OnSysColourChanged(event
);
315 void wxMDIParentFrame::Cascade()
317 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
320 void wxMDIParentFrame::Tile()
322 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
325 void wxMDIParentFrame::ArrangeIcons()
327 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
330 void wxMDIParentFrame::ActivateNext()
332 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
335 void wxMDIParentFrame::ActivatePrevious()
337 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
342 // Returns a style for the client window - usually 0
343 // or, for example, wxHSCROLL | wxVSCROLL
344 long wxMDIParentFrame::GetClientStyle() const
346 return wxHSCROLL | wxVSCROLL ;
350 bool wxMDIParentFrame::MSWOnDestroy()
355 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
357 m_clientWindow
= OnCreateClient();
358 // Uses own style for client style
359 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
362 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
377 // forward WM_SIZE to status bar control
378 #if wxUSE_NATIVE_STATUSBAR
379 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
381 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
382 event
.SetEventObject( m_frameStatusBar
);
384 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
391 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
392 event
.SetEventObject( this );
393 if (!GetEventHandler()->ProcessEvent(event
))
398 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
400 wxWindow::MSWOnActivate(state
, minimized
, activate
);
402 // If this window is an MDI parent, we must also send an OnActivate message
403 // to the current child.
404 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
406 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
407 event
.SetEventObject( m_currentChild
);
408 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
413 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
415 // if (cmd == 0) // Why did I do this test?
417 // In case it's e.g. a toolbar.
418 wxWindow
*win
= wxFindWinFromHandle(control
);
420 return win
->MSWCommand(cmd
, id
);
423 if (wxCurrentPopupMenu)
425 wxMenu *popupMenu = wxCurrentPopupMenu;
426 wxCurrentPopupMenu = NULL;
427 if (!popupMenu->MSWCommand(cmd, id))
434 case IDM_WINDOWCASCADE
:
435 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, MDITILE_SKIPDISABLED
, 0);
438 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
440 case IDM_WINDOWICONS
:
441 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
444 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
451 return FALSE
; // Get WndProc to call default proc
454 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
459 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
461 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
464 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
466 wxNode
* node
= GetChildren().First();
469 wxWindow
* child
= (wxWindow
*) node
->Data();
470 if (child
->GetHWND())
473 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
475 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
479 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
486 wxWindow* child = FindItem(id);
489 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
495 return wxWindow::MSWOnCommand(id
, cmd
, control
);
498 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
500 if (m_parentFrameActive
)
502 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
504 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
505 event
.SetEventObject( this );
506 GetEventHandler()->ProcessEvent(event
);
508 else if (nFlags
!= MF_SEPARATOR
)
510 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
511 event
.SetEventObject( this );
512 GetEventHandler()->ProcessEvent(event
);
515 else if (m_currentChild
)
517 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
521 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
524 if ( GetClientWindow() )
525 clientWnd
= GetClientWindow()->GetHWND();
529 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
532 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
534 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
540 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
542 MSG
*pMsg
= (MSG
*)msg
;
544 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
547 if (m_acceleratorTable
.Ok() &&
548 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
551 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
553 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
561 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
566 extern wxWindow
*wxWndHook
;
567 extern wxList
*wxWinHandleList
;
569 wxMDIChildFrame::wxMDIChildFrame()
574 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
576 const wxString
& title
,
580 const wxString
& name
)
582 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
589 m_windowId
= (int)NewControlId();
591 if (parent
) parent
->AddChild(this);
602 mcs
.szClass
= wxMDIChildFrameClassName
;
604 mcs
.hOwner
= wxGetInstance();
605 if (x
> -1) mcs
.x
= x
;
606 else mcs
.x
= CW_USEDEFAULT
;
608 if (y
> -1) mcs
.y
= y
;
609 else mcs
.y
= CW_USEDEFAULT
;
611 if (width
> -1) mcs
.cx
= width
;
612 else mcs
.cx
= CW_USEDEFAULT
;
614 if (height
> -1) mcs
.cy
= height
;
615 else mcs
.cy
= CW_USEDEFAULT
;
617 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
618 if (style
& wxMINIMIZE_BOX
)
619 msflags
|= WS_MINIMIZEBOX
;
620 if (style
& wxMAXIMIZE_BOX
)
621 msflags
|= WS_MAXIMIZEBOX
;
622 if (style
& wxTHICK_FRAME
)
623 msflags
|= WS_THICKFRAME
;
624 if (style
& wxSYSTEM_MENU
)
625 msflags
|= WS_SYSMENU
;
626 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
627 msflags
|= WS_MINIMIZE
;
628 if (style
& wxMAXIMIZE
)
629 msflags
|= WS_MAXIMIZE
;
630 if (style
& wxCAPTION
)
631 msflags
|= WS_CAPTION
;
637 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
638 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
640 //handle = (HWND)LOWORD(Return);
641 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
642 m_hWnd
= (WXHWND
)Return
;
644 // This gets reassigned so can't be stored
645 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
648 wxWinHandleList
->Append((long)GetHWND(), this);
650 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
652 wxModelessWindows
.Append(this);
656 wxMDIChildFrame::~wxMDIChildFrame()
660 ResetWindowStyle(NULL
);
663 // Set the client size (i.e. leave the calculation of borders etc.
665 void wxMDIChildFrame::SetClientSize(int width
, int height
)
667 HWND hWnd
= (HWND
) GetHWND();
670 ::GetClientRect(hWnd
, &rect
);
673 GetWindowRect(hWnd
, &rect2
);
675 // Find the difference between the entire window (title bar and all)
676 // and the client area; add this to the new client size to move the
678 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
679 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
684 GetStatusBar()->GetSize(&sx
, &sy
);
689 point
.x
= rect2
.left
;
692 // If there's an MDI parent, must subtract the parent's top left corner
693 // since MoveWindow moves relative to the parent
694 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
695 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
697 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
699 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
700 event
.SetEventObject( this );
701 GetEventHandler()->ProcessEvent(event
);
704 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
707 GetWindowRect((HWND
) GetHWND(), &rect
);
712 // Since we now have the absolute screen coords,
713 // if there's a parent we must subtract its top left corner
714 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
715 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
721 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
725 m_frameMenuBar
= NULL
;
729 if ( menu_bar
->IsAttached() )
732 m_hMenu
= menu_bar
->Create();
735 delete m_frameMenuBar
;
737 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
739 parent
->m_parentFrameActive
= FALSE
;
740 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
742 // Try to insert Window menu in front of Help, otherwise append it.
743 HMENU menu
= (HMENU
)m_hMenu
;
744 int N
= GetMenuItemCount(menu
);
745 bool success
= FALSE
;
746 for (int i
= 0; i
< N
; i
++)
749 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
750 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
751 strcmp(buf
, "Help") == 0))
754 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
755 (UINT
)subMenu
, "&Window");
760 AppendMenu(menu
, MF_POPUP
,
764 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
768 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
769 MAKELPARAM(menu
, subMenu
));
772 DrawMenuBar((HWND
) parent
->GetHWND());
773 m_frameMenuBar
= menu_bar
;
774 menu_bar
->Attach(this);
778 void wxMDIChildFrame::Maximize()
780 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
781 if ( parent
&& parent
->GetClientWindow() )
782 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
785 void wxMDIChildFrame::Restore()
787 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
788 if ( parent
&& parent
->GetClientWindow() )
789 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
792 void wxMDIChildFrame::Activate()
794 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
795 if ( parent
&& parent
->GetClientWindow() )
796 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
799 static HWND invalidHandle
= 0;
800 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
802 if (!GetHWND()) return;
804 if (invalidHandle
== (HWND
) GetHWND())
809 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
824 // forward WM_SIZE to status bar control
825 #if wxUSE_NATIVE_STATUSBAR
826 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
828 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
829 event
.SetEventObject( m_frameStatusBar
);
831 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
838 wxWindow::MSWOnSize(x
, y
, id
);
842 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
844 // if ((cmd == 0) && GetHWND())
847 // In case it's e.g. a toolbar.
848 wxWindow
*win
= wxFindWinFromHandle(control
);
850 return win
->MSWCommand(cmd
, id
);
852 if (wxCurrentPopupMenu
)
854 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
855 wxCurrentPopupMenu
= NULL
;
856 if (popupMenu
->MSWCommand(cmd
, id
))
860 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
870 return wxWindow::MSWOnCommand(id
, cmd
, control
);
873 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
876 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
880 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
885 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
887 MSG
*pMsg
= (MSG
*)msg
;
888 if (m_acceleratorTable
.Ok())
890 wxFrame
*parent
= (wxFrame
*)GetParent();
891 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
892 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
898 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
900 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
901 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
902 HMENU child_menu
= (HMENU
) GetWinMenu();
907 parent
->m_currentChild
= this;
910 parent
->m_parentFrameActive
= FALSE
;
911 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
913 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
917 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
918 MAKELONG(child_menu
, subMenu
));
921 ::DrawMenuBar((HWND
) parent
->GetHWND());
923 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
924 event
.SetEventObject( this );
925 GetEventHandler()->ProcessEvent(event
);
929 if (parent
->m_currentChild
== this)
930 parent
->m_currentChild
= NULL
;
932 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
933 event
.SetEventObject( this );
934 GetEventHandler()->ProcessEvent(event
);
939 parent
->m_parentFrameActive
= TRUE
;
940 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
942 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
946 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
947 MAKELONG(parent_menu
, subMenu
));
950 ::DrawMenuBar((HWND
) parent
->GetHWND());
953 bool flag
= (activate
!= 0);
954 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
955 event
.SetEventObject( this );
956 GetEventHandler()->ProcessEvent(event
);
960 void wxMDIChildFrame::MSWDestroyWindow()
962 MSWDetachWindowMenu();
963 invalidHandle
= (HWND
) GetHWND();
965 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
967 // Must make sure this handle is invalidated (set to NULL)
968 // since all sorts of things could happen after the
969 // child client is destroyed, but before the wxFrame is
972 HWND oldHandle
= (HWND
)GetHWND();
974 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
976 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
982 ::DestroyMenu((HMENU
) m_hMenu
);
988 // Change the client window's extended style so we don't
989 // get a client edge style when a child is maximised (a double
990 // border looks silly.)
991 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
993 #if defined(__WIN95__)
994 RECT
*rect
= (RECT
*)vrect
;
995 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
996 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
997 if (!pChild
|| (pChild
== this))
999 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1000 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1001 DWORD dwNewStyle
= dwStyle
;
1002 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1003 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1005 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1007 if (dwStyle
!= dwNewStyle
)
1009 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1010 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1011 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1012 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1014 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1024 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1026 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1027 #if defined(__WIN95__)
1028 if (!(lpPos
->flags
& SWP_NOSIZE
))
1031 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1032 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1033 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1035 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1036 lpPos
->x
= rectClient
.left
;
1037 lpPos
->y
= rectClient
.top
;
1038 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1039 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1041 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1042 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1044 pFrameWnd
->GetToolBar()->Refresh();
1052 wxMDIClientWindow::wxMDIClientWindow()
1058 wxMDIClientWindow::~wxMDIClientWindow()
1062 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1064 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1066 CLIENTCREATESTRUCT ccs
;
1067 m_windowStyle
= style
;
1068 m_windowParent
= parent
;
1070 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1071 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1073 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1074 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1075 msStyle
|= WS_HSCROLL
;
1076 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1077 msStyle
|= WS_VSCROLL
;
1079 #if defined(__WIN95__)
1080 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1086 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1087 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1088 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1089 SubclassWin(m_hWnd
);
1092 return (m_hWnd
!= 0) ;
1095 // Window procedure: here for debugging purposes
1096 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1098 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1099 // return MSWDefWindowProc(nMsg, wParam, lParam);
1102 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1104 if ( MSWGetOldWndProc() != 0)
1105 return ::CallWindowProc(CASTWNDPROC
MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1107 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1110 // Explicitly call default scroll behaviour
1111 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1113 // Note: for client windows, the scroll position is not set in
1114 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1115 // scroll position we're at.
1116 // This makes it hard to paint patterns or bitmaps in the background,
1117 // and have the client area scrollable as well.
1119 if ( event
.GetOrientation() == wxHORIZONTAL
)
1120 m_scrollX
= event
.GetPosition(); // Always returns zero!
1122 m_scrollY
= event
.GetPosition(); // Always returns zero!
1127 // Should hand the message to the default proc
1128 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)