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
307 void wxMDIParentFrame::OldOnSize(int x, int y)
309 #if WXWIN_COMPATIBILITY == 1
310 wxSizeEvent event(wxSize(x, y), m_windowId);
311 event.SetEventObject( this );
312 GetEventHandler()->ProcessEvent(event);
322 GetClientSize(&width, &height);
326 GetToolBar()->GetSize(&wt, &ht);
331 if ( GetClientWindow() )
332 GetClientWindow()->SetSize(x, y, width, height);
337 // Default activation behaviour - nothing.
338 // Default activation behaviour - override dedault wxFrame behaviour
339 void wxMDIParentFrame::OldOnActivate(bool flag)
341 #if WXWIN_COMPATIBILITY == 1
342 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
343 event.SetEventObject( this );
344 GetEventHandler()->ProcessEvent(event);
352 // Returns the active MDI child window
353 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
355 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
356 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
360 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
363 // Create the client window class (don't Create the window,
364 // just return a new class)
365 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
367 return new wxMDIClientWindow
;
370 // Responds to colour changes, and passes event on to children.
371 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
373 if ( m_clientWindow
)
375 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
376 m_clientWindow
->Refresh();
379 if ( m_frameToolBar )
381 wxSysColourChangedEvent event2;
382 event2.eventObject = m_frameToolBar;
383 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
387 // Propagate the event to the non-top-level children
388 wxFrame::OnSysColourChanged(event
);
392 void wxMDIParentFrame::Cascade(void)
394 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
397 void wxMDIParentFrame::Tile(void)
399 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
402 void wxMDIParentFrame::ArrangeIcons(void)
404 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
407 void wxMDIParentFrame::ActivateNext(void)
409 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
412 void wxMDIParentFrame::ActivatePrevious(void)
414 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
419 // Returns a style for the client window - usually 0
420 // or, for example, wxHSCROLL | wxVSCROLL
421 long wxMDIParentFrame::GetClientStyle(void) const
423 return wxHSCROLL | wxVSCROLL ;
427 bool wxMDIParentFrame::MSWOnDestroy(void)
432 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
434 m_clientWindow
= new wxMDIClientWindow
;
435 // Uses own style for client style
436 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
439 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
454 // forward WM_SIZE to status bar control
455 #if USE_NATIVE_STATUSBAR
456 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
458 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
459 event
.SetEventObject( m_frameStatusBar
);
461 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
467 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
468 event
.SetEventObject( this );
469 if (!GetEventHandler()->ProcessEvent(event
))
474 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
476 wxWindow::MSWOnActivate(state
, minimized
, activate
);
478 // If this window is an MDI parent, we must also send an OnActivate message
479 // to the current child.
480 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
482 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
483 event
.SetEventObject( m_currentChild
);
484 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
489 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, 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(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
572 if (m_parentFrameActive
)
574 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
576 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
577 event
.SetEventObject( this );
578 GetEventHandler()->ProcessEvent(event
);
580 else if (nFlags
!= MF_SEPARATOR
)
582 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
583 event
.SetEventObject( this );
584 GetEventHandler()->ProcessEvent(event
);
587 else if (m_currentChild
)
589 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
593 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
596 if ( GetClientWindow() )
597 clientWnd
= GetClientWindow()->GetHWND();
601 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
604 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
606 MSG
*pMsg
= (MSG
*)msg
;
608 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
611 if (m_acceleratorTable
!= (WXHANDLE
) NULL
&&
612 ::TranslateAccelerator((HWND
) GetHWND(), (HANDLE
) m_acceleratorTable
, pMsg
))
615 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
617 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
624 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
629 extern wxWindow
*wxWndHook
;
630 extern wxList
*wxWinHandleList
;
632 wxMDIChildFrame::wxMDIChildFrame(void)
637 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
639 const wxString
& title
,
643 const wxString
& name
)
645 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
652 m_windowId
= (int)NewControlId();
654 if (parent
) parent
->AddChild(this);
665 mcs
.szClass
= wxMDIChildFrameClassName
;
667 mcs
.hOwner
= wxGetInstance();
668 if (x
> -1) mcs
.x
= x
;
669 else mcs
.x
= CW_USEDEFAULT
;
671 if (y
> -1) mcs
.y
= y
;
672 else mcs
.y
= CW_USEDEFAULT
;
674 if (width
> -1) mcs
.cx
= width
;
675 else mcs
.cx
= CW_USEDEFAULT
;
677 if (height
> -1) mcs
.cy
= height
;
678 else mcs
.cy
= CW_USEDEFAULT
;
680 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
681 if (style
& wxMINIMIZE_BOX
)
682 msflags
|= WS_MINIMIZEBOX
;
683 if (style
& wxMAXIMIZE_BOX
)
684 msflags
|= WS_MAXIMIZEBOX
;
685 if (style
& wxTHICK_FRAME
)
686 msflags
|= WS_THICKFRAME
;
687 if (style
& wxSYSTEM_MENU
)
688 msflags
|= WS_SYSMENU
;
689 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
690 msflags
|= WS_MINIMIZE
;
691 if (style
& wxMAXIMIZE
)
692 msflags
|= WS_MAXIMIZE
;
693 if (style
& wxCAPTION
)
694 msflags
|= WS_CAPTION
;
700 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
701 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
703 //handle = (HWND)LOWORD(Return);
704 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
705 m_hWnd
= (WXHWND
)Return
;
707 // This gets reassigned so can't be stored
708 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
711 wxWinHandleList
->Append((long)GetHWND(), this);
713 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
715 wxModelessWindows
.Append(this);
719 wxMDIChildFrame::~wxMDIChildFrame(void)
723 ResetWindowStyle(NULL
);
726 // Set the client size (i.e. leave the calculation of borders etc.
728 void wxMDIChildFrame::SetClientSize(int width
, int height
)
730 HWND hWnd
= (HWND
) GetHWND();
733 GetClientRect(hWnd
, &rect
);
736 GetWindowRect(hWnd
, &rect2
);
738 // Find the difference between the entire window (title bar and all)
739 // and the client area; add this to the new client size to move the
741 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
742 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
747 GetStatusBar()->GetSize(&sx
, &sy
);
752 point
.x
= rect2
.left
;
755 // If there's an MDI parent, must subtract the parent's top left corner
756 // since MoveWindow moves relative to the parent
757 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
758 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
760 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
762 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
763 event
.SetEventObject( this );
764 GetEventHandler()->ProcessEvent(event
);
767 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
770 GetWindowRect((HWND
) GetHWND(), &rect
);
775 // Since we now have the absolute screen coords,
776 // if there's a parent we must subtract its top left corner
777 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
778 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
784 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
788 m_frameMenuBar
= NULL
;
792 if (menu_bar
->m_menuBarFrame
)
796 HMENU menu
= CreateMenu();
798 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
800 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
802 // After looking Bounds Checker result, it seems that all
803 // menus must be individually destroyed. So, don't reset m_hMenu,
804 // to allow ~wxMenu to do the job.
806 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
807 // Uncommenting for the moment... JACS
808 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
809 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
812 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
814 delete m_frameMenuBar
;
816 this->m_hMenu
= (WXHMENU
) menu
;
818 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
820 parent
->m_parentFrameActive
= FALSE
;
821 HMENU subMenu
= GetSubMenu((HWND
) parent
->GetWindowMenu(), 0);
823 // Try to insert Window menu in front of Help, otherwise append it.
824 int N
= GetMenuItemCount(menu
);
825 bool success
= FALSE
;
826 for (i
= 0; i
< N
; i
++)
829 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
830 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
831 strcmp(buf
, "Help") == 0))
834 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
835 (UINT
)subMenu
, "&Window");
840 AppendMenu(menu
, MF_POPUP
,
844 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
848 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
849 MAKELPARAM(menu
, subMenu
));
852 DrawMenuBar((HWND
) parent
->GetHWND());
853 m_frameMenuBar
= menu_bar
;
854 menu_bar
->m_menuBarFrame
= this;
858 void wxMDIChildFrame::Maximize(void)
860 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
861 if ( parent
&& parent
->GetClientWindow() )
862 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
865 void wxMDIChildFrame::Restore(void)
867 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
868 if ( parent
&& parent
->GetClientWindow() )
869 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
872 void wxMDIChildFrame::Activate(void)
874 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
875 if ( parent
&& parent
->GetClientWindow() )
876 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
879 static HWND invalidHandle
= 0;
880 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
882 if (!GetHWND()) return;
884 if (invalidHandle
== (HWND
) GetHWND())
887 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
892 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
907 // forward WM_SIZE to status bar control
908 #if USE_NATIVE_STATUSBAR
909 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
911 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
912 event
.SetEventObject( m_frameStatusBar
);
914 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
920 wxWindow::MSWOnSize(x
, y
, id
);
924 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
927 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
929 if ((cmd
== 0) && GetHWND())
931 // In case it's e.g. a toolbar.
932 wxWindow
*win
= wxFindWinFromHandle(control
);
934 return win
->MSWCommand(cmd
, id
);
936 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
949 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
952 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
956 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
958 MSG
*pMsg
= (MSG
*)msg
;
959 if (m_acceleratorTable
&& GetHWND())
961 wxFrame
*parent
= (wxFrame
*)GetParent();
962 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
963 return (::TranslateAccelerator(parent_hwnd
, (HANDLE
) m_acceleratorTable
, pMsg
) != 0);
968 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
970 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
971 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
973 wxDebugMsg("Parent menu is %d\n", parent_menu
);
975 HMENU child_menu
= (HMENU
) GetWinMenu();
977 wxDebugMsg("Child menu is %d\n", child_menu
);
983 parent
->m_currentChild
= this;
986 parent
->m_parentFrameActive
= FALSE
;
987 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
989 wxDebugMsg("Window submenu is %d\n", subMenu
);
991 // HMENU subMenu = 0;
993 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
997 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
998 MAKELONG(child_menu
, subMenu
));
1001 ::DrawMenuBar((HWND
) parent
->GetHWND());
1003 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1004 event
.SetEventObject( this );
1005 GetEventHandler()->ProcessEvent(event
);
1009 if (parent
->m_currentChild
== this)
1010 parent
->m_currentChild
= NULL
;
1012 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1013 event
.SetEventObject( this );
1014 GetEventHandler()->ProcessEvent(event
);
1016 // m_active = FALSE;
1019 parent
->m_parentFrameActive
= TRUE
;
1020 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1022 wxDebugMsg("Window submenu is %d\n", subMenu
);
1024 // HMENU subMenu = 0;
1026 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1027 (WPARAM
)parent_menu
,
1030 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1031 MAKELONG(parent_menu
, subMenu
));
1034 ::DrawMenuBar((HWND
) parent
->GetHWND());
1037 bool flag
= (activate
!= 0);
1038 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1039 event
.SetEventObject( this );
1040 GetEventHandler()->ProcessEvent(event
);
1043 wxDebugMsg("Finished (de)activating\n");
1048 void wxMDIChildFrame::MSWDestroyWindow(void)
1050 MSWDetachWindowMenu();
1051 invalidHandle
= (HWND
) GetHWND();
1053 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1055 // Must make sure this handle is invalidated (set to NULL)
1056 // since all sorts of things could happen after the
1057 // child client is destroyed, but before the wxFrame is
1060 HWND oldHandle
= (HWND
)GetHWND();
1062 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1065 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1067 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1070 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1076 ::DestroyMenu((HMENU
) m_hMenu
);
1082 // Change the client window's extended style so we don't
1083 // get a client edge style when a child is maximised (a double
1084 // border looks silly.)
1085 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1087 #if defined(__WIN95__)
1088 RECT
*rect
= (RECT
*)vrect
;
1089 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1090 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1091 if (!pChild
|| (pChild
== this))
1093 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1094 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1095 DWORD dwNewStyle
= dwStyle
;
1096 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1097 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1099 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1101 if (dwStyle
!= dwNewStyle
)
1103 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1104 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1105 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1106 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1108 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1118 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1120 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1121 #if defined(__WIN95__)
1122 if (!(lpPos
->flags
& SWP_NOSIZE
))
1125 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1126 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1127 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1129 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1130 lpPos
->x
= rectClient
.left
;
1131 lpPos
->y
= rectClient
.top
;
1132 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1133 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1135 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1136 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1138 pFrameWnd
->GetToolBar()->Refresh();
1146 wxMDIClientWindow::wxMDIClientWindow(void)
1152 wxMDIClientWindow::~wxMDIClientWindow(void)
1156 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1158 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1160 CLIENTCREATESTRUCT ccs
;
1161 m_windowStyle
= style
;
1162 m_windowParent
= parent
;
1164 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1165 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1167 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1168 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1169 msStyle
|= WS_HSCROLL
;
1170 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1171 msStyle
|= WS_VSCROLL
;
1173 #if defined(__WIN95__)
1174 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1180 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1181 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1182 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1183 SubclassWin(m_hWnd
);
1186 return (m_hWnd
!= 0) ;
1189 // Window procedure: here for debugging purposes
1190 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1192 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1193 // return MSWDefWindowProc(nMsg, wParam, lParam);
1196 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1198 if ( MSWGetOldWndProc() != 0)
1199 return ::CallWindowProc(CASTWNDPROC (FARPROC
) MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1201 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1204 // Explicitly call default scroll behaviour
1205 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1207 // Note: for client windows, the scroll position is not set in
1208 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1209 // scroll position we're at.
1210 // This makes it hard to paint patterns or bitmaps in the background,
1211 // and have the client area scrollable as well.
1213 if ( event
.GetOrientation() == wxHORIZONTAL
)
1214 m_scrollX
= event
.GetPosition(); // Always returns zero!
1216 m_scrollY
= event
.GetPosition(); // Always returns zero!
1221 // Should hand the message to the default proc
1222 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)