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
;
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(void)
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");
124 wxDebugMsg("Loaded m_windowMenu %d\n", m_windowMenu
);
127 DWORD msflags
= WS_OVERLAPPED
;
128 if (style
& wxMINIMIZE_BOX
)
129 msflags
|= WS_MINIMIZEBOX
;
130 if (style
& wxMAXIMIZE_BOX
)
131 msflags
|= WS_MAXIMIZEBOX
;
132 if (style
& wxTHICK_FRAME
)
133 msflags
|= WS_THICKFRAME
;
134 if (style
& wxSYSTEM_MENU
)
135 msflags
|= WS_SYSMENU
;
136 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
137 msflags
|= WS_MINIMIZE
;
138 if (style
& wxMAXIMIZE
)
139 msflags
|= WS_MAXIMIZE
;
140 if (style
& wxCAPTION
)
141 msflags
|= WS_CAPTION
;
143 // Adding WS_CLIPCHILDREN causes children not to be properly
144 // drawn when first displaying them.
145 // if (style & wxCLIP_CHILDREN)
146 // msflags |= WS_CLIPCHILDREN;
148 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
151 wxModelessWindows
.Append(this);
156 wxMDIParentFrame::~wxMDIParentFrame(void)
160 DestroyMenu((HMENU
) m_windowMenu
); // Destroy dummy "Window" menu
163 if (m_clientWindow
->MSWGetOldWndProc())
164 m_clientWindow
->UnsubclassWin();
166 m_clientWindow
->m_hWnd
= 0;
167 delete m_clientWindow
;
170 // Get size *available for subwindows* i.e. excluding menu bar.
171 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
174 GetClientRect((HWND
) GetHWND(), &rect
);
176 int cwidth
= rect
.right
;
177 int cheight
= rect
.bottom
;
179 if ( GetStatusBar() )
182 GetStatusBar()->GetSize(&sw
, &sh
);
186 wxPoint
pt(GetClientAreaOrigin());
194 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
198 m_frameMenuBar
= NULL
;
202 if (menu_bar
->m_menuBarFrame
)
206 HMENU menu
= CreateMenu();
208 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
210 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
212 // After looking Bounds Checker result, it seems that all
213 // menus must be individually destroyed. So, don't reset m_hMenu,
214 // to allow ~wxMenu to do the job.
216 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
217 // Uncommenting for the moment... JACS
218 menu_bar
->m_menus
[i
]->m_hMenu
= (WXHMENU
) NULL
;
219 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
222 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
224 delete m_frameMenuBar
;
226 this->m_hMenu
= (WXHMENU
) menu
;
228 // MDI parent-specific code follows
230 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
232 // Try to insert Window menu in front of Help, otherwise append it.
233 int N
= GetMenuItemCount(menu
);
234 bool success
= FALSE
;
235 for (i
= 0; i
< N
; i
++)
238 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
239 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
240 strcmp(buf
, "Help") == 0))
243 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
244 (UINT
)subMenu
, "&Window");
249 AppendMenu(menu
, MF_POPUP
,
252 m_parentFrameActive
= TRUE
;
254 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
258 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
259 MAKELPARAM(menu
, subMenu
));
261 DrawMenuBar((HWND
) GetHWND());
263 m_frameMenuBar
= menu_bar
;
264 menu_bar
->m_menuBarFrame
= this;
267 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
276 GetClientSize(&width
, &height
);
278 if ( GetClientWindow() )
279 GetClientWindow()->SetSize(x
, y
, width
, height
);
281 /* Already done in MSWOnSize
282 // forward WM_SIZE to status bar control
283 #if USE_NATIVE_STATUSBAR
284 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
285 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
291 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
296 #if WXWIN_COMPATIBILITY
298 void wxMDIParentFrame::OldOnSize(int x, int y)
300 #if WXWIN_COMPATIBILITY == 1
301 wxSizeEvent event(wxSize(x, y), m_windowId);
302 event.SetEventObject( this );
303 GetEventHandler()->ProcessEvent(event);
313 GetClientSize(&width, &height);
317 GetToolBar()->GetSize(&wt, &ht);
322 if ( GetClientWindow() )
323 GetClientWindow()->SetSize(x, y, width, height);
328 // Default activation behaviour - nothing.
329 // Default activation behaviour - override dedault wxFrame behaviour
330 void wxMDIParentFrame::OldOnActivate(bool flag)
332 #if WXWIN_COMPATIBILITY == 1
333 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
334 event.SetEventObject( this );
335 GetEventHandler()->ProcessEvent(event);
343 // Returns the active MDI child window
344 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
346 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
347 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
351 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
354 // Create the client window class (don't Create the window,
355 // just return a new class)
356 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
358 return new wxMDIClientWindow
;
361 // Responds to colour changes, and passes event on to children.
362 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
364 if ( m_clientWindow
)
366 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
367 m_clientWindow
->Refresh();
370 if ( m_frameToolBar )
372 wxSysColourChangedEvent event2;
373 event2.eventObject = m_frameToolBar;
374 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
378 // Propagate the event to the non-top-level children
379 wxFrame::OnSysColourChanged(event
);
383 void wxMDIParentFrame::Cascade(void)
385 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
388 void wxMDIParentFrame::Tile(void)
390 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
393 void wxMDIParentFrame::ArrangeIcons(void)
395 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
398 void wxMDIParentFrame::ActivateNext(void)
400 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
403 void wxMDIParentFrame::ActivatePrevious(void)
405 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
410 // Returns a style for the client window - usually 0
411 // or, for example, wxHSCROLL | wxVSCROLL
412 long wxMDIParentFrame::GetClientStyle(void) const
414 return wxHSCROLL | wxVSCROLL ;
418 bool wxMDIParentFrame::MSWOnDestroy(void)
423 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
425 m_clientWindow
= OnCreateClient();
426 // Uses own style for client style
427 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
430 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
445 // forward WM_SIZE to status bar control
446 #if USE_NATIVE_STATUSBAR
447 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
449 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
450 event
.SetEventObject( m_frameStatusBar
);
452 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
459 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
460 event
.SetEventObject( this );
461 if (!GetEventHandler()->ProcessEvent(event
))
466 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
468 wxWindow::MSWOnActivate(state
, minimized
, activate
);
470 // If this window is an MDI parent, we must also send an OnActivate message
471 // to the current child.
472 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
474 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
475 event
.SetEventObject( m_currentChild
);
476 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
481 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
483 // if (cmd == 0) // Why did I do this test?
485 // In case it's e.g. a toolbar.
486 wxWindow
*win
= wxFindWinFromHandle(control
);
488 return win
->MSWCommand(cmd
, id
);
490 if (wxCurrentPopupMenu
)
492 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
493 wxCurrentPopupMenu
= NULL
;
494 if (!popupMenu
->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
))
614 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
616 MSG
*pMsg
= (MSG
*)msg
;
618 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
621 if (m_acceleratorTable
.Ok() &&
622 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
625 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
627 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
635 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
640 extern wxWindow
*wxWndHook
;
641 extern wxList
*wxWinHandleList
;
643 wxMDIChildFrame::wxMDIChildFrame(void)
648 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
650 const wxString
& title
,
654 const wxString
& name
)
656 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
663 m_windowId
= (int)NewControlId();
665 if (parent
) parent
->AddChild(this);
676 mcs
.szClass
= wxMDIChildFrameClassName
;
678 mcs
.hOwner
= wxGetInstance();
679 if (x
> -1) mcs
.x
= x
;
680 else mcs
.x
= CW_USEDEFAULT
;
682 if (y
> -1) mcs
.y
= y
;
683 else mcs
.y
= CW_USEDEFAULT
;
685 if (width
> -1) mcs
.cx
= width
;
686 else mcs
.cx
= CW_USEDEFAULT
;
688 if (height
> -1) mcs
.cy
= height
;
689 else mcs
.cy
= CW_USEDEFAULT
;
691 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
692 if (style
& wxMINIMIZE_BOX
)
693 msflags
|= WS_MINIMIZEBOX
;
694 if (style
& wxMAXIMIZE_BOX
)
695 msflags
|= WS_MAXIMIZEBOX
;
696 if (style
& wxTHICK_FRAME
)
697 msflags
|= WS_THICKFRAME
;
698 if (style
& wxSYSTEM_MENU
)
699 msflags
|= WS_SYSMENU
;
700 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
701 msflags
|= WS_MINIMIZE
;
702 if (style
& wxMAXIMIZE
)
703 msflags
|= WS_MAXIMIZE
;
704 if (style
& wxCAPTION
)
705 msflags
|= WS_CAPTION
;
711 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
712 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
714 //handle = (HWND)LOWORD(Return);
715 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
716 m_hWnd
= (WXHWND
)Return
;
718 // This gets reassigned so can't be stored
719 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
722 wxWinHandleList
->Append((long)GetHWND(), this);
724 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
726 wxModelessWindows
.Append(this);
730 wxMDIChildFrame::~wxMDIChildFrame(void)
734 ResetWindowStyle(NULL
);
737 // Set the client size (i.e. leave the calculation of borders etc.
739 void wxMDIChildFrame::SetClientSize(int width
, int height
)
741 HWND hWnd
= (HWND
) GetHWND();
744 GetClientRect(hWnd
, &rect
);
747 GetWindowRect(hWnd
, &rect2
);
749 // Find the difference between the entire window (title bar and all)
750 // and the client area; add this to the new client size to move the
752 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
753 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
758 GetStatusBar()->GetSize(&sx
, &sy
);
763 point
.x
= rect2
.left
;
766 // If there's an MDI parent, must subtract the parent's top left corner
767 // since MoveWindow moves relative to the parent
768 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
769 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
771 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
773 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
774 event
.SetEventObject( this );
775 GetEventHandler()->ProcessEvent(event
);
778 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
781 GetWindowRect((HWND
) GetHWND(), &rect
);
786 // Since we now have the absolute screen coords,
787 // if there's a parent we must subtract its top left corner
788 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
789 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
795 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
799 m_frameMenuBar
= NULL
;
803 if (menu_bar
->m_menuBarFrame
)
807 HMENU menu
= CreateMenu();
809 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
811 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
813 // After looking Bounds Checker result, it seems that all
814 // menus must be individually destroyed. So, don't reset m_hMenu,
815 // to allow ~wxMenu to do the job.
817 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
818 // Uncommenting for the moment... JACS
819 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
820 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
823 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
825 delete m_frameMenuBar
;
827 this->m_hMenu
= (WXHMENU
) menu
;
829 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
831 parent
->m_parentFrameActive
= FALSE
;
832 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
834 // Try to insert Window menu in front of Help, otherwise append it.
835 int N
= GetMenuItemCount(menu
);
836 bool success
= FALSE
;
837 for (i
= 0; i
< N
; i
++)
840 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
841 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
842 strcmp(buf
, "Help") == 0))
845 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
846 (UINT
)subMenu
, "&Window");
851 AppendMenu(menu
, MF_POPUP
,
855 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
859 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
860 MAKELPARAM(menu
, subMenu
));
863 DrawMenuBar((HWND
) parent
->GetHWND());
864 m_frameMenuBar
= menu_bar
;
865 menu_bar
->m_menuBarFrame
= this;
869 void wxMDIChildFrame::Maximize(void)
871 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
872 if ( parent
&& parent
->GetClientWindow() )
873 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
876 void wxMDIChildFrame::Restore(void)
878 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
879 if ( parent
&& parent
->GetClientWindow() )
880 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
883 void wxMDIChildFrame::Activate(void)
885 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
886 if ( parent
&& parent
->GetClientWindow() )
887 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
890 static HWND invalidHandle
= 0;
891 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
893 if (!GetHWND()) return;
895 if (invalidHandle
== (HWND
) GetHWND())
898 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
903 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
918 // forward WM_SIZE to status bar control
919 #if USE_NATIVE_STATUSBAR
920 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
922 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
923 event
.SetEventObject( m_frameStatusBar
);
925 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
932 wxWindow::MSWOnSize(x
, y
, id
);
936 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
939 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
941 // if ((cmd == 0) && GetHWND())
944 // In case it's e.g. a toolbar.
945 wxWindow
*win
= wxFindWinFromHandle(control
);
947 return win
->MSWCommand(cmd
, id
);
949 if (wxCurrentPopupMenu
)
951 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
952 wxCurrentPopupMenu
= NULL
;
953 if (popupMenu
->MSWCommand(cmd
, id
))
957 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
970 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
973 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
977 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
982 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
984 MSG
*pMsg
= (MSG
*)msg
;
985 if (m_acceleratorTable
.Ok())
987 wxFrame
*parent
= (wxFrame
*)GetParent();
988 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
989 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
995 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
997 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
998 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
1000 wxDebugMsg("Parent menu is %d\n", parent_menu
);
1002 HMENU child_menu
= (HMENU
) GetWinMenu();
1004 wxDebugMsg("Child menu is %d\n", child_menu
);
1010 parent
->m_currentChild
= this;
1013 parent
->m_parentFrameActive
= FALSE
;
1014 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1016 wxDebugMsg("Window submenu is %d\n", subMenu
);
1018 // HMENU subMenu = 0;
1020 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1024 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1025 MAKELONG(child_menu
, subMenu
));
1028 ::DrawMenuBar((HWND
) parent
->GetHWND());
1030 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1031 event
.SetEventObject( this );
1032 GetEventHandler()->ProcessEvent(event
);
1036 if (parent
->m_currentChild
== this)
1037 parent
->m_currentChild
= NULL
;
1039 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1040 event
.SetEventObject( this );
1041 GetEventHandler()->ProcessEvent(event
);
1043 // m_active = FALSE;
1046 parent
->m_parentFrameActive
= TRUE
;
1047 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1049 wxDebugMsg("Window submenu is %d\n", subMenu
);
1051 // HMENU subMenu = 0;
1053 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1054 (WPARAM
)parent_menu
,
1057 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1058 MAKELONG(parent_menu
, subMenu
));
1061 ::DrawMenuBar((HWND
) parent
->GetHWND());
1064 bool flag
= (activate
!= 0);
1065 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1066 event
.SetEventObject( this );
1067 GetEventHandler()->ProcessEvent(event
);
1070 wxDebugMsg("Finished (de)activating\n");
1075 void wxMDIChildFrame::MSWDestroyWindow(void)
1077 MSWDetachWindowMenu();
1078 invalidHandle
= (HWND
) GetHWND();
1080 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1082 // Must make sure this handle is invalidated (set to NULL)
1083 // since all sorts of things could happen after the
1084 // child client is destroyed, but before the wxFrame is
1087 HWND oldHandle
= (HWND
)GetHWND();
1089 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1092 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1094 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1097 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1103 ::DestroyMenu((HMENU
) m_hMenu
);
1109 // Change the client window's extended style so we don't
1110 // get a client edge style when a child is maximised (a double
1111 // border looks silly.)
1112 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1114 #if defined(__WIN95__)
1115 RECT
*rect
= (RECT
*)vrect
;
1116 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1117 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1118 if (!pChild
|| (pChild
== this))
1120 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1121 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1122 DWORD dwNewStyle
= dwStyle
;
1123 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1124 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1126 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1128 if (dwStyle
!= dwNewStyle
)
1130 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1131 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1132 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1133 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1135 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1145 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1147 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1148 #if defined(__WIN95__)
1149 if (!(lpPos
->flags
& SWP_NOSIZE
))
1152 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1153 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1154 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1156 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1157 lpPos
->x
= rectClient
.left
;
1158 lpPos
->y
= rectClient
.top
;
1159 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1160 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1162 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1163 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1165 pFrameWnd
->GetToolBar()->Refresh();
1173 wxMDIClientWindow::wxMDIClientWindow(void)
1179 wxMDIClientWindow::~wxMDIClientWindow(void)
1183 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1185 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1187 CLIENTCREATESTRUCT ccs
;
1188 m_windowStyle
= style
;
1189 m_windowParent
= parent
;
1191 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1192 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1194 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1195 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1196 msStyle
|= WS_HSCROLL
;
1197 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1198 msStyle
|= WS_VSCROLL
;
1200 #if defined(__WIN95__)
1201 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1207 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1208 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1209 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1210 SubclassWin(m_hWnd
);
1213 return (m_hWnd
!= 0) ;
1216 // Window procedure: here for debugging purposes
1217 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1219 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1220 // return MSWDefWindowProc(nMsg, wParam, lParam);
1223 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1225 if ( MSWGetOldWndProc() != 0)
1226 return ::CallWindowProc(CASTWNDPROC
MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1228 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1231 // Explicitly call default scroll behaviour
1232 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1234 // Note: for client windows, the scroll position is not set in
1235 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1236 // scroll position we're at.
1237 // This makes it hard to paint patterns or bitmaps in the background,
1238 // and have the client area scrollable as well.
1240 if ( event
.GetOrientation() == wxHORIZONTAL
)
1241 m_scrollX
= event
.GetPosition(); // Always returns zero!
1243 m_scrollY
= event
.GetPosition(); // Always returns zero!
1248 // Should hand the message to the default proc
1249 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)