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 USE_NATIVE_STATUSBAR
38 #include <wx/msw/statbr95.h>
43 extern wxList wxModelessWindows
;
45 #define IDM_WINDOWTILE 4001
46 #define IDM_WINDOWCASCADE 4002
47 #define IDM_WINDOWICONS 4003
48 #define IDM_WINDOWNEXT 4004
49 // This range gives a maximum of 500
50 // MDI children. Should be enough :-)
51 #define wxFIRST_MDI_CHILD 4100
52 #define wxLAST_MDI_CHILD 4600
54 // Status border dimensions
55 #define wxTHICK_LINE_BORDER 3
56 #define wxTHICK_LINE_WIDTH 1
58 extern char wxMDIFrameClassName
[];
59 extern char wxMDIChildFrameClassName
[];
60 extern wxWindow
*wxWndHook
;
62 #if !USE_SHARED_LIBRARY
63 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
64 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
65 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
67 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
68 EVT_SIZE(wxMDIParentFrame::OnSize
)
69 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
70 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
73 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
74 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
79 wxMDIParentFrame::wxMDIParentFrame(void)
81 m_clientWindow
= NULL
;
82 m_currentChild
= NULL
;
84 m_parentFrameActive
= TRUE
;
85 m_frameToolBar
= NULL
;
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_frameToolBar
= NULL
;
99 m_clientWindow
= NULL
;
100 m_currentChild
= NULL
;
102 m_parentFrameActive
= TRUE
;
105 wxTopLevelWindows
.Append(this);
108 m_windowStyle
= style
;
110 if (parent
) parent
->AddChild(this);
115 m_windowId
= (int)NewControlId();
122 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), "wxWindowMenu");
125 wxDebugMsg("Loaded m_windowMenu %d\n", m_windowMenu
);
128 DWORD msflags
= WS_OVERLAPPED
;
129 if (style
& wxMINIMIZE_BOX
)
130 msflags
|= WS_MINIMIZEBOX
;
131 if (style
& wxMAXIMIZE_BOX
)
132 msflags
|= WS_MAXIMIZEBOX
;
133 if (style
& wxTHICK_FRAME
)
134 msflags
|= WS_THICKFRAME
;
135 if (style
& wxSYSTEM_MENU
)
136 msflags
|= WS_SYSMENU
;
137 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
138 msflags
|= WS_MINIMIZE
;
139 if (style
& wxMAXIMIZE
)
140 msflags
|= WS_MAXIMIZE
;
141 if (style
& wxCAPTION
)
142 msflags
|= WS_CAPTION
;
144 // Adding WS_CLIPCHILDREN causes children not to be properly
145 // drawn when first displaying them.
146 // if (style & wxCLIP_CHILDREN)
147 // msflags |= WS_CLIPCHILDREN;
149 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
152 wxModelessWindows
.Append(this);
157 wxMDIParentFrame::~wxMDIParentFrame(void)
161 DestroyMenu((HMENU
) m_windowMenu
); // Destroy dummy "Window" menu
164 if (m_clientWindow
->MSWGetOldWndProc())
165 m_clientWindow
->UnsubclassWin();
167 m_clientWindow
->m_hWnd
= 0;
168 delete m_clientWindow
;
171 // Get size *available for subwindows* i.e. excluding menu bar.
172 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
175 GetClientRect((HWND
) GetHWND(), &rect
);
177 int cwidth
= rect
.right
;
178 int cheight
= rect
.bottom
;
183 m_frameToolBar->GetSize(&tw, &th);
187 if ( GetStatusBar() )
190 GetStatusBar()->GetSize(&sw
, &sh
);
198 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
202 m_frameMenuBar
= NULL
;
206 if (menu_bar
->m_menuBarFrame
)
210 HMENU menu
= CreateMenu();
212 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
214 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
216 // After looking Bounds Checker result, it seems that all
217 // menus must be individually destroyed. So, don't reset m_hMenu,
218 // to allow ~wxMenu to do the job.
220 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
221 // Uncommenting for the moment... JACS
222 menu_bar
->m_menus
[i
]->m_hMenu
= (WXHMENU
) NULL
;
223 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
226 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
228 delete m_frameMenuBar
;
230 this->m_hMenu
= (WXHMENU
) menu
;
232 // MDI parent-specific code follows
234 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
236 // Try to insert Window menu in front of Help, otherwise append it.
237 int N
= GetMenuItemCount(menu
);
238 bool success
= FALSE
;
239 for (i
= 0; i
< N
; i
++)
242 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
243 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
244 strcmp(buf
, "Help") == 0))
247 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
248 (UINT
)subMenu
, "&Window");
253 AppendMenu(menu
, MF_POPUP
,
256 m_parentFrameActive
= TRUE
;
258 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
262 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
263 MAKELPARAM(menu
, subMenu
));
265 DrawMenuBar((HWND
) GetHWND());
267 m_frameMenuBar
= menu_bar
;
268 menu_bar
->m_menuBarFrame
= this;
271 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
280 GetClientSize(&width
, &height
);
284 GetToolBar()->GetSize(&wt
, &ht
);
287 GetToolBar()->SetSize(0, 0, width
, ht
);
290 if ( GetClientWindow() )
291 GetClientWindow()->SetSize(x
, y
, width
, height
);
293 // forward WM_SIZE to status bar control
294 #if USE_NATIVE_STATUSBAR
295 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
296 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
300 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
305 #if WXWIN_COMPATIBILITY
306 void wxMDIParentFrame::OldOnSize(int x
, int y
)
308 #if WXWIN_COMPATIBILITY == 1
309 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
310 event
.SetEventObject( this );
311 GetEventHandler()->ProcessEvent(event
);
321 GetClientSize(&width
, &height
);
325 GetToolBar()->GetSize(&wt
, &ht
);
330 if ( GetClientWindow() )
331 GetClientWindow()->SetSize(x
, y
, width
, height
);
336 // Default activation behaviour - nothing.
337 // Default activation behaviour - override dedault wxFrame behaviour
338 void wxMDIParentFrame::OldOnActivate(bool flag
)
340 #if WXWIN_COMPATIBILITY == 1
341 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
342 event
.SetEventObject( this );
343 GetEventHandler()->ProcessEvent(event
);
350 // Returns the active MDI child window
351 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
353 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
354 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
358 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
361 // Create the client window class (don't Create the window,
362 // just return a new class)
363 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
365 return new wxMDIClientWindow
;
368 // Responds to colour changes, and passes event on to children.
369 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
371 if ( m_clientWindow
)
373 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
374 m_clientWindow
->Refresh();
377 if ( m_frameToolBar )
379 wxSysColourChangedEvent event2;
380 event2.eventObject = m_frameToolBar;
381 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
385 // Propagate the event to the non-top-level children
386 wxFrame::OnSysColourChanged(event
);
390 void wxMDIParentFrame::Cascade(void)
392 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
395 void wxMDIParentFrame::Tile(void)
397 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
400 void wxMDIParentFrame::ArrangeIcons(void)
402 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
405 void wxMDIParentFrame::ActivateNext(void)
407 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
410 void wxMDIParentFrame::ActivatePrevious(void)
412 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
417 // Returns a style for the client window - usually 0
418 // or, for example, wxHSCROLL | wxVSCROLL
419 long wxMDIParentFrame::GetClientStyle(void) const
421 return wxHSCROLL | wxVSCROLL ;
425 bool wxMDIParentFrame::MSWOnDestroy(void)
430 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
432 m_clientWindow
= new wxMDIClientWindow
;
433 // Uses own style for client style
434 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
437 void wxMDIParentFrame::MSWOnSize(const int x
, const int y
, const WXUINT id
)
452 // forward WM_SIZE to status bar control
453 #if USE_NATIVE_STATUSBAR
454 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
456 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
457 event
.SetEventObject( m_frameStatusBar
);
459 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
465 GetEventHandler()->OldOnSize(x
, y
);
469 bool wxMDIParentFrame::MSWOnActivate(const int state
, const bool minimized
, const WXHWND activate
)
471 wxWindow::MSWOnActivate(state
, minimized
, activate
);
473 // If this window is an MDI parent, we must also send an OnActivate message
474 // to the current child.
475 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
477 #if WXWIN_COMPATIBILITY
478 m_currentChild
->GetEventHandler()->OldOnActivate(TRUE
);
480 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
,
481 m_currentChild
.m_windowId
);
482 event
.eventObject
= m_currentChild
;
483 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
489 bool wxMDIParentFrame::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND control
)
493 // In case it's e.g. a toolbar.
494 wxWindow
*win
= wxFindWinFromHandle(control
);
496 return win
->MSWCommand(cmd
, id
);
500 case IDM_WINDOWCASCADE
:
501 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, MDITILE_SKIPDISABLED
, 0);
504 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
506 case IDM_WINDOWICONS
:
507 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
510 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
518 wxDebugMsg("wxMDIFrame::OnCommand %d: system command: calling default window proc\n", GetHWND());
520 return FALSE
; // Get WndProc to call default proc
523 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
528 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
531 wxDebugMsg("wxMDIFrame::MSWOnCommand %d: calling child OnCommand\n", GetHWND());
533 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
536 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
538 wxNode
* node
= GetChildren()->First();
541 wxWindow
* child
= (wxWindow
*) node
->Data();
542 if (child
->GetHWND())
545 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
547 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
551 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
558 wxWindow* child = FindItem(id);
561 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
570 void wxMDIParentFrame::MSWOnMenuHighlight(const WXWORD nItem
, const WXWORD nFlags
, const WXHMENU hSysMenu
)
572 if (m_parentFrameActive
)
575 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
576 GetEventHandler()->OldOnMenuSelect(-1);
577 else if (nFlags
!= MF_SEPARATOR
)
578 GetEventHandler()->OldOnMenuSelect(nItem
);
580 else if (m_currentChild
)
582 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
586 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
589 if ( GetClientWindow() )
590 clientWnd
= GetClientWindow()->GetHWND();
594 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
597 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
599 MSG
*pMsg
= (MSG
*)msg
;
601 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
604 if (m_acceleratorTable
!= (WXHANDLE
) NULL
&&
605 ::TranslateAccelerator((HWND
) GetHWND(), (HANDLE
) m_acceleratorTable
, pMsg
))
608 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
610 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
617 bool wxMDIParentFrame::MSWOnEraseBkgnd(const WXHDC
WXUNUSED(pDC
))
622 extern wxWindow
*wxWndHook
;
623 extern wxList
*wxWinHandleList
;
625 wxMDIChildFrame::wxMDIChildFrame(void)
630 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
632 const wxString
& title
,
636 const wxString
& name
)
638 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
645 m_windowId
= (int)NewControlId();
647 if (parent
) parent
->AddChild(this);
658 mcs
.szClass
= wxMDIChildFrameClassName
;
660 mcs
.hOwner
= wxGetInstance();
661 if (x
> -1) mcs
.x
= x
;
662 else mcs
.x
= CW_USEDEFAULT
;
664 if (y
> -1) mcs
.y
= y
;
665 else mcs
.y
= CW_USEDEFAULT
;
667 if (width
> -1) mcs
.cx
= width
;
668 else mcs
.cx
= CW_USEDEFAULT
;
670 if (height
> -1) mcs
.cy
= height
;
671 else mcs
.cy
= CW_USEDEFAULT
;
673 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
674 if (style
& wxMINIMIZE_BOX
)
675 msflags
|= WS_MINIMIZEBOX
;
676 if (style
& wxMAXIMIZE_BOX
)
677 msflags
|= WS_MAXIMIZEBOX
;
678 if (style
& wxTHICK_FRAME
)
679 msflags
|= WS_THICKFRAME
;
680 if (style
& wxSYSTEM_MENU
)
681 msflags
|= WS_SYSMENU
;
682 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
683 msflags
|= WS_MINIMIZE
;
684 if (style
& wxMAXIMIZE
)
685 msflags
|= WS_MAXIMIZE
;
686 if (style
& wxCAPTION
)
687 msflags
|= WS_CAPTION
;
693 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
694 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
696 //handle = (HWND)LOWORD(Return);
697 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
698 m_hWnd
= (WXHWND
)Return
;
700 // This gets reassigned so can't be stored
701 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
704 wxWinHandleList
->Append((long)GetHWND(), this);
706 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
708 wxModelessWindows
.Append(this);
712 wxMDIChildFrame::~wxMDIChildFrame(void)
716 ResetWindowStyle(NULL
);
719 // Set the client size (i.e. leave the calculation of borders etc.
721 void wxMDIChildFrame::SetClientSize(const int width
, const int height
)
723 HWND hWnd
= (HWND
) GetHWND();
726 GetClientRect(hWnd
, &rect
);
729 GetWindowRect(hWnd
, &rect2
);
731 // Find the difference between the entire window (title bar and all)
732 // and the client area; add this to the new client size to move the
734 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
735 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
740 GetStatusBar()->GetSize(&sx
, &sy
);
745 point
.x
= rect2
.left
;
748 // If there's an MDI parent, must subtract the parent's top left corner
749 // since MoveWindow moves relative to the parent
750 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
751 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
753 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
754 #if WXWIN_COMPATIBILITY
755 GetEventHandler()->OldOnSize(width
, height
);
757 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
758 event
.eventObject
= this;
759 GetEventHandler()->ProcessEvent(event
);
763 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
766 GetWindowRect((HWND
) GetHWND(), &rect
);
771 // Since we now have the absolute screen coords,
772 // if there's a parent we must subtract its top left corner
773 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
774 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
780 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
784 m_frameMenuBar
= NULL
;
788 if (menu_bar
->m_menuBarFrame
)
792 HMENU menu
= CreateMenu();
794 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
796 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
798 // After looking Bounds Checker result, it seems that all
799 // menus must be individually destroyed. So, don't reset m_hMenu,
800 // to allow ~wxMenu to do the job.
802 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
803 // Uncommenting for the moment... JACS
804 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
805 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
808 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
810 delete m_frameMenuBar
;
812 this->m_hMenu
= (WXHMENU
) menu
;
814 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
816 parent
->m_parentFrameActive
= FALSE
;
817 HMENU subMenu
= GetSubMenu((HWND
) parent
->GetWindowMenu(), 0);
819 // Try to insert Window menu in front of Help, otherwise append it.
820 int N
= GetMenuItemCount(menu
);
821 bool success
= FALSE
;
822 for (i
= 0; i
< N
; i
++)
825 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
826 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
827 strcmp(buf
, "Help") == 0))
830 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
831 (UINT
)subMenu
, "&Window");
836 AppendMenu(menu
, MF_POPUP
,
840 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
844 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
845 MAKELPARAM(menu
, subMenu
));
848 DrawMenuBar((HWND
) parent
->GetHWND());
849 m_frameMenuBar
= menu_bar
;
850 menu_bar
->m_menuBarFrame
= this;
854 void wxMDIChildFrame::Maximize(void)
856 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
857 if ( parent
&& parent
->GetClientWindow() )
858 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
861 void wxMDIChildFrame::Restore(void)
863 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
864 if ( parent
&& parent
->GetClientWindow() )
865 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
868 void wxMDIChildFrame::Activate(void)
870 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
871 if ( parent
&& parent
->GetClientWindow() )
872 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
875 static HWND invalidHandle
= 0;
876 void wxMDIChildFrame::MSWOnSize(const int x
, const int y
, const WXUINT id
)
878 if (!GetHWND()) return;
880 if (invalidHandle
== (HWND
) GetHWND())
883 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
888 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
903 // forward WM_SIZE to status bar control
904 #if USE_NATIVE_STATUSBAR
905 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
907 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
908 event
.SetEventObject( m_frameStatusBar
);
910 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
916 wxWindow::MSWOnSize(x
, y
, id
);
920 bool wxMDIChildFrame::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND control
)
923 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
925 if ((cmd
== 0) && GetHWND())
927 // In case it's e.g. a toolbar.
928 wxWindow
*win
= wxFindWinFromHandle(control
);
930 return win
->MSWCommand(cmd
, id
);
932 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
945 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
948 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
952 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
954 MSG
*pMsg
= (MSG
*)msg
;
955 if (m_acceleratorTable
&& GetHWND())
957 wxFrame
*parent
= (wxFrame
*)GetParent();
958 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
959 return (::TranslateAccelerator(parent_hwnd
, (HANDLE
) m_acceleratorTable
, pMsg
) != 0);
964 long wxMDIChildFrame::MSWOnMDIActivate(const long activate
, const WXHWND
WXUNUSED(one
), const WXHWND
WXUNUSED(two
))
966 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
967 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
969 wxDebugMsg("Parent menu is %d\n", parent_menu
);
971 HMENU child_menu
= (HMENU
) GetWinMenu();
973 wxDebugMsg("Child menu is %d\n", child_menu
);
979 parent
->m_currentChild
= this;
982 parent
->m_parentFrameActive
= FALSE
;
983 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
985 wxDebugMsg("Window submenu is %d\n", subMenu
);
987 // HMENU subMenu = 0;
989 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
993 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
994 MAKELONG(child_menu
, subMenu
));
997 ::DrawMenuBar((HWND
) parent
->GetHWND());
999 GetEventHandler()->OldOnActivate(TRUE
);
1003 if (parent
->m_currentChild
== this)
1004 parent
->m_currentChild
= NULL
;
1005 GetEventHandler()->OldOnActivate(FALSE
);
1007 // m_active = FALSE;
1010 parent
->m_parentFrameActive
= TRUE
;
1011 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1013 wxDebugMsg("Window submenu is %d\n", subMenu
);
1015 // HMENU subMenu = 0;
1017 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1018 (WPARAM
)parent_menu
,
1021 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1022 MAKELONG(parent_menu
, subMenu
));
1025 ::DrawMenuBar((HWND
) parent
->GetHWND());
1029 bool flag
= (activate
!= 0);
1030 GetEventHandler()->OldOnActivate(flag
);
1032 wxDebugMsg("Finished (de)activating\n");
1037 void wxMDIChildFrame::MSWDestroyWindow(void)
1039 MSWDetachWindowMenu();
1040 invalidHandle
= (HWND
) GetHWND();
1042 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1044 // Must make sure this handle is invalidated (set to NULL)
1045 // since all sorts of things could happen after the
1046 // child client is destroyed, but before the wxFrame is
1049 HWND oldHandle
= (HWND
)GetHWND();
1051 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1054 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1056 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1059 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1065 ::DestroyMenu((HMENU
) m_hMenu
);
1071 // Change the client window's extended style so we don't
1072 // get a client edge style when a child is maximised (a double
1073 // border looks silly.)
1074 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1076 #if defined(__WIN95__)
1077 RECT
*rect
= (RECT
*)vrect
;
1078 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1079 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1080 if (!pChild
|| (pChild
== this))
1082 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1083 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1084 DWORD dwNewStyle
= dwStyle
;
1085 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1086 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1088 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1090 if (dwStyle
!= dwNewStyle
)
1092 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1093 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1094 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1095 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1097 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1107 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1109 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1110 #if defined(__WIN95__)
1111 if (!(lpPos
->flags
& SWP_NOSIZE
))
1114 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1115 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1116 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1118 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1119 lpPos
->x
= rectClient
.left
;
1120 lpPos
->y
= rectClient
.top
;
1121 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1122 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1124 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1125 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1127 pFrameWnd
->GetToolBar()->Refresh();
1135 wxMDIClientWindow::wxMDIClientWindow(void)
1141 wxMDIClientWindow::~wxMDIClientWindow(void)
1145 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, const long style
)
1147 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1149 CLIENTCREATESTRUCT ccs
;
1150 m_windowStyle
= style
;
1151 m_windowParent
= parent
;
1153 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1154 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1156 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1157 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1158 msStyle
|= WS_HSCROLL
;
1159 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1160 msStyle
|= WS_VSCROLL
;
1162 #if defined(__WIN95__)
1163 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1169 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1170 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1171 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1172 SubclassWin(m_hWnd
);
1175 return (m_hWnd
!= 0) ;
1178 // Window procedure: here for debugging purposes
1179 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1181 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1182 // return MSWDefWindowProc(nMsg, wParam, lParam);
1185 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1187 if ( MSWGetOldWndProc() != 0)
1188 return ::CallWindowProc(CASTWNDPROC (FARPROC
) MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1190 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1193 // Explicitly call default scroll behaviour
1194 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1196 // Note: for client windows, the scroll position is not set in
1197 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1198 // scroll position we're at.
1199 // This makes it hard to paint patterns or bitmaps in the background,
1200 // and have the client area scrollable as well.
1202 if ( event
.GetOrientation() == wxHORIZONTAL
)
1203 m_scrollX
= event
.GetPosition(); // Always returns zero!
1205 m_scrollY
= event
.GetPosition(); // Always returns zero!
1210 // Should hand the message to the default proc
1211 long wxMDIClientWindow::MSWOnMDIActivate(const long bActivate
, const WXHWND
, const WXHWND
)