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
;
87 bool wxMDIParentFrame::Create(wxWindow
*parent
,
89 const wxString
& title
,
95 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
97 m_clientWindow
= NULL
;
98 m_currentChild
= NULL
;
100 m_parentFrameActive
= TRUE
;
103 wxTopLevelWindows
.Append(this);
106 m_windowStyle
= style
;
108 if (parent
) parent
->AddChild(this);
113 m_windowId
= (int)NewControlId();
120 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), "wxWindowMenu");
123 wxDebugMsg("Loaded m_windowMenu %d\n", m_windowMenu
);
126 DWORD msflags
= WS_OVERLAPPED
;
127 if (style
& wxMINIMIZE_BOX
)
128 msflags
|= WS_MINIMIZEBOX
;
129 if (style
& wxMAXIMIZE_BOX
)
130 msflags
|= WS_MAXIMIZEBOX
;
131 if (style
& wxTHICK_FRAME
)
132 msflags
|= WS_THICKFRAME
;
133 if (style
& wxSYSTEM_MENU
)
134 msflags
|= WS_SYSMENU
;
135 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
136 msflags
|= WS_MINIMIZE
;
137 if (style
& wxMAXIMIZE
)
138 msflags
|= WS_MAXIMIZE
;
139 if (style
& wxCAPTION
)
140 msflags
|= WS_CAPTION
;
142 // Adding WS_CLIPCHILDREN causes children not to be properly
143 // drawn when first displaying them.
144 // if (style & wxCLIP_CHILDREN)
145 // msflags |= WS_CLIPCHILDREN;
147 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
150 wxModelessWindows
.Append(this);
155 wxMDIParentFrame::~wxMDIParentFrame(void)
159 DestroyMenu((HMENU
) m_windowMenu
); // Destroy dummy "Window" menu
162 if (m_clientWindow
->MSWGetOldWndProc())
163 m_clientWindow
->UnsubclassWin();
165 m_clientWindow
->m_hWnd
= 0;
166 delete m_clientWindow
;
169 // Get size *available for subwindows* i.e. excluding menu bar.
170 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
173 GetClientRect((HWND
) GetHWND(), &rect
);
175 int cwidth
= rect
.right
;
176 int cheight
= rect
.bottom
;
178 if ( GetStatusBar() )
181 GetStatusBar()->GetSize(&sw
, &sh
);
185 wxPoint
pt(GetClientAreaOrigin());
193 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
197 m_frameMenuBar
= NULL
;
201 if (menu_bar
->m_menuBarFrame
)
205 HMENU menu
= CreateMenu();
207 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
209 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
211 // After looking Bounds Checker result, it seems that all
212 // menus must be individually destroyed. So, don't reset m_hMenu,
213 // to allow ~wxMenu to do the job.
215 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
216 // Uncommenting for the moment... JACS
217 menu_bar
->m_menus
[i
]->m_hMenu
= (WXHMENU
) NULL
;
218 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
221 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
223 delete m_frameMenuBar
;
225 this->m_hMenu
= (WXHMENU
) menu
;
227 // MDI parent-specific code follows
229 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
231 // Try to insert Window menu in front of Help, otherwise append it.
232 int N
= GetMenuItemCount(menu
);
233 bool success
= FALSE
;
234 for (i
= 0; i
< N
; i
++)
237 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
238 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
239 strcmp(buf
, "Help") == 0))
242 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
243 (UINT
)subMenu
, "&Window");
248 AppendMenu(menu
, MF_POPUP
,
251 m_parentFrameActive
= TRUE
;
253 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
257 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
258 MAKELPARAM(menu
, subMenu
));
260 DrawMenuBar((HWND
) GetHWND());
262 m_frameMenuBar
= menu_bar
;
263 menu_bar
->m_menuBarFrame
= this;
266 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
275 GetClientSize(&width
, &height
);
277 if ( GetClientWindow() )
278 GetClientWindow()->SetSize(x
, y
, width
, height
);
280 /* Already done in MSWOnSize
281 // forward WM_SIZE to status bar control
282 #if USE_NATIVE_STATUSBAR
283 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
284 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
290 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
295 #if WXWIN_COMPATIBILITY
297 void wxMDIParentFrame::OldOnSize(int x, int y)
299 #if WXWIN_COMPATIBILITY == 1
300 wxSizeEvent event(wxSize(x, y), m_windowId);
301 event.SetEventObject( this );
302 GetEventHandler()->ProcessEvent(event);
312 GetClientSize(&width, &height);
316 GetToolBar()->GetSize(&wt, &ht);
321 if ( GetClientWindow() )
322 GetClientWindow()->SetSize(x, y, width, height);
327 // Default activation behaviour - nothing.
328 // Default activation behaviour - override dedault wxFrame behaviour
329 void wxMDIParentFrame::OldOnActivate(bool flag)
331 #if WXWIN_COMPATIBILITY == 1
332 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
333 event.SetEventObject( this );
334 GetEventHandler()->ProcessEvent(event);
342 // Returns the active MDI child window
343 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
345 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
346 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
350 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
353 // Create the client window class (don't Create the window,
354 // just return a new class)
355 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
357 return new wxMDIClientWindow
;
360 // Responds to colour changes, and passes event on to children.
361 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
363 if ( m_clientWindow
)
365 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
366 m_clientWindow
->Refresh();
369 if ( m_frameToolBar )
371 wxSysColourChangedEvent event2;
372 event2.eventObject = m_frameToolBar;
373 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
377 // Propagate the event to the non-top-level children
378 wxFrame::OnSysColourChanged(event
);
382 void wxMDIParentFrame::Cascade(void)
384 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
387 void wxMDIParentFrame::Tile(void)
389 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
392 void wxMDIParentFrame::ArrangeIcons(void)
394 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
397 void wxMDIParentFrame::ActivateNext(void)
399 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
402 void wxMDIParentFrame::ActivatePrevious(void)
404 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
409 // Returns a style for the client window - usually 0
410 // or, for example, wxHSCROLL | wxVSCROLL
411 long wxMDIParentFrame::GetClientStyle(void) const
413 return wxHSCROLL | wxVSCROLL ;
417 bool wxMDIParentFrame::MSWOnDestroy(void)
422 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
424 m_clientWindow
= OnCreateClient();
425 // Uses own style for client style
426 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
429 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
444 // forward WM_SIZE to status bar control
445 #if USE_NATIVE_STATUSBAR
446 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
448 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
449 event
.SetEventObject( m_frameStatusBar
);
451 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
458 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
459 event
.SetEventObject( this );
460 if (!GetEventHandler()->ProcessEvent(event
))
465 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
467 wxWindow::MSWOnActivate(state
, minimized
, activate
);
469 // If this window is an MDI parent, we must also send an OnActivate message
470 // to the current child.
471 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
473 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
474 event
.SetEventObject( m_currentChild
);
475 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
480 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
482 // if (cmd == 0) // Why did I do this test?
484 // In case it's e.g. a toolbar.
485 wxWindow
*win
= wxFindWinFromHandle(control
);
487 return win
->MSWCommand(cmd
, id
);
491 case IDM_WINDOWCASCADE
:
492 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, MDITILE_SKIPDISABLED
, 0);
495 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
497 case IDM_WINDOWICONS
:
498 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
501 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
509 wxDebugMsg("wxMDIFrame::OnCommand %d: system command: calling default window proc\n", GetHWND());
511 return FALSE
; // Get WndProc to call default proc
514 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
519 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
522 wxDebugMsg("wxMDIFrame::MSWOnCommand %d: calling child OnCommand\n", GetHWND());
524 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
527 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
529 wxNode
* node
= GetChildren()->First();
532 wxWindow
* child
= (wxWindow
*) node
->Data();
533 if (child
->GetHWND())
536 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
538 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
542 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
549 wxWindow* child = FindItem(id);
552 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
561 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
563 if (m_parentFrameActive
)
565 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
567 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
568 event
.SetEventObject( this );
569 GetEventHandler()->ProcessEvent(event
);
571 else if (nFlags
!= MF_SEPARATOR
)
573 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
574 event
.SetEventObject( this );
575 GetEventHandler()->ProcessEvent(event
);
578 else if (m_currentChild
)
580 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
584 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
587 if ( GetClientWindow() )
588 clientWnd
= GetClientWindow()->GetHWND();
592 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
595 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
597 MSG
*pMsg
= (MSG
*)msg
;
599 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
605 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
607 MSG
*pMsg
= (MSG
*)msg
;
609 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
612 if (m_acceleratorTable
.Ok() &&
613 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
616 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
618 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
626 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
631 extern wxWindow
*wxWndHook
;
632 extern wxList
*wxWinHandleList
;
634 wxMDIChildFrame::wxMDIChildFrame(void)
639 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
641 const wxString
& title
,
645 const wxString
& name
)
647 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
654 m_windowId
= (int)NewControlId();
656 if (parent
) parent
->AddChild(this);
667 mcs
.szClass
= wxMDIChildFrameClassName
;
669 mcs
.hOwner
= wxGetInstance();
670 if (x
> -1) mcs
.x
= x
;
671 else mcs
.x
= CW_USEDEFAULT
;
673 if (y
> -1) mcs
.y
= y
;
674 else mcs
.y
= CW_USEDEFAULT
;
676 if (width
> -1) mcs
.cx
= width
;
677 else mcs
.cx
= CW_USEDEFAULT
;
679 if (height
> -1) mcs
.cy
= height
;
680 else mcs
.cy
= CW_USEDEFAULT
;
682 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
683 if (style
& wxMINIMIZE_BOX
)
684 msflags
|= WS_MINIMIZEBOX
;
685 if (style
& wxMAXIMIZE_BOX
)
686 msflags
|= WS_MAXIMIZEBOX
;
687 if (style
& wxTHICK_FRAME
)
688 msflags
|= WS_THICKFRAME
;
689 if (style
& wxSYSTEM_MENU
)
690 msflags
|= WS_SYSMENU
;
691 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
692 msflags
|= WS_MINIMIZE
;
693 if (style
& wxMAXIMIZE
)
694 msflags
|= WS_MAXIMIZE
;
695 if (style
& wxCAPTION
)
696 msflags
|= WS_CAPTION
;
702 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
703 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
705 //handle = (HWND)LOWORD(Return);
706 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
707 m_hWnd
= (WXHWND
)Return
;
709 // This gets reassigned so can't be stored
710 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
713 wxWinHandleList
->Append((long)GetHWND(), this);
715 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
717 wxModelessWindows
.Append(this);
721 wxMDIChildFrame::~wxMDIChildFrame(void)
725 ResetWindowStyle(NULL
);
728 // Set the client size (i.e. leave the calculation of borders etc.
730 void wxMDIChildFrame::SetClientSize(int width
, int height
)
732 HWND hWnd
= (HWND
) GetHWND();
735 GetClientRect(hWnd
, &rect
);
738 GetWindowRect(hWnd
, &rect2
);
740 // Find the difference between the entire window (title bar and all)
741 // and the client area; add this to the new client size to move the
743 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
744 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
749 GetStatusBar()->GetSize(&sx
, &sy
);
754 point
.x
= rect2
.left
;
757 // If there's an MDI parent, must subtract the parent's top left corner
758 // since MoveWindow moves relative to the parent
759 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
760 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
762 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
764 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
765 event
.SetEventObject( this );
766 GetEventHandler()->ProcessEvent(event
);
769 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
772 GetWindowRect((HWND
) GetHWND(), &rect
);
777 // Since we now have the absolute screen coords,
778 // if there's a parent we must subtract its top left corner
779 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
780 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
786 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
790 m_frameMenuBar
= NULL
;
794 if (menu_bar
->m_menuBarFrame
)
798 HMENU menu
= CreateMenu();
800 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
802 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
804 // After looking Bounds Checker result, it seems that all
805 // menus must be individually destroyed. So, don't reset m_hMenu,
806 // to allow ~wxMenu to do the job.
808 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
809 // Uncommenting for the moment... JACS
810 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
811 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
814 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
816 delete m_frameMenuBar
;
818 this->m_hMenu
= (WXHMENU
) menu
;
820 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
822 parent
->m_parentFrameActive
= FALSE
;
823 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
825 // Try to insert Window menu in front of Help, otherwise append it.
826 int N
= GetMenuItemCount(menu
);
827 bool success
= FALSE
;
828 for (i
= 0; i
< N
; i
++)
831 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
832 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
833 strcmp(buf
, "Help") == 0))
836 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
837 (UINT
)subMenu
, "&Window");
842 AppendMenu(menu
, MF_POPUP
,
846 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
850 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
851 MAKELPARAM(menu
, subMenu
));
854 DrawMenuBar((HWND
) parent
->GetHWND());
855 m_frameMenuBar
= menu_bar
;
856 menu_bar
->m_menuBarFrame
= this;
860 void wxMDIChildFrame::Maximize(void)
862 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
863 if ( parent
&& parent
->GetClientWindow() )
864 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
867 void wxMDIChildFrame::Restore(void)
869 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
870 if ( parent
&& parent
->GetClientWindow() )
871 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
874 void wxMDIChildFrame::Activate(void)
876 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
877 if ( parent
&& parent
->GetClientWindow() )
878 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
881 static HWND invalidHandle
= 0;
882 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
884 if (!GetHWND()) return;
886 if (invalidHandle
== (HWND
) GetHWND())
889 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
894 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
909 // forward WM_SIZE to status bar control
910 #if USE_NATIVE_STATUSBAR
911 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
913 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
914 event
.SetEventObject( m_frameStatusBar
);
916 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
923 wxWindow::MSWOnSize(x
, y
, id
);
927 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
930 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
932 // if ((cmd == 0) && GetHWND())
935 // In case it's e.g. a toolbar.
936 wxWindow
*win
= wxFindWinFromHandle(control
);
938 return win
->MSWCommand(cmd
, id
);
940 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
953 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
956 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
960 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
965 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
967 MSG
*pMsg
= (MSG
*)msg
;
968 if (m_acceleratorTable
.Ok())
970 wxFrame
*parent
= (wxFrame
*)GetParent();
971 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
972 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
978 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
980 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
981 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
983 wxDebugMsg("Parent menu is %d\n", parent_menu
);
985 HMENU child_menu
= (HMENU
) GetWinMenu();
987 wxDebugMsg("Child menu is %d\n", child_menu
);
993 parent
->m_currentChild
= this;
996 parent
->m_parentFrameActive
= FALSE
;
997 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
999 wxDebugMsg("Window submenu is %d\n", subMenu
);
1001 // HMENU subMenu = 0;
1003 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1007 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1008 MAKELONG(child_menu
, subMenu
));
1011 ::DrawMenuBar((HWND
) parent
->GetHWND());
1013 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1014 event
.SetEventObject( this );
1015 GetEventHandler()->ProcessEvent(event
);
1019 if (parent
->m_currentChild
== this)
1020 parent
->m_currentChild
= NULL
;
1022 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1023 event
.SetEventObject( this );
1024 GetEventHandler()->ProcessEvent(event
);
1026 // m_active = FALSE;
1029 parent
->m_parentFrameActive
= TRUE
;
1030 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1032 wxDebugMsg("Window submenu is %d\n", subMenu
);
1034 // HMENU subMenu = 0;
1036 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1037 (WPARAM
)parent_menu
,
1040 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1041 MAKELONG(parent_menu
, subMenu
));
1044 ::DrawMenuBar((HWND
) parent
->GetHWND());
1047 bool flag
= (activate
!= 0);
1048 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1049 event
.SetEventObject( this );
1050 GetEventHandler()->ProcessEvent(event
);
1053 wxDebugMsg("Finished (de)activating\n");
1058 void wxMDIChildFrame::MSWDestroyWindow(void)
1060 MSWDetachWindowMenu();
1061 invalidHandle
= (HWND
) GetHWND();
1063 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1065 // Must make sure this handle is invalidated (set to NULL)
1066 // since all sorts of things could happen after the
1067 // child client is destroyed, but before the wxFrame is
1070 HWND oldHandle
= (HWND
)GetHWND();
1072 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1075 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1077 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1080 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1086 ::DestroyMenu((HMENU
) m_hMenu
);
1092 // Change the client window's extended style so we don't
1093 // get a client edge style when a child is maximised (a double
1094 // border looks silly.)
1095 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1097 #if defined(__WIN95__)
1098 RECT
*rect
= (RECT
*)vrect
;
1099 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1100 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1101 if (!pChild
|| (pChild
== this))
1103 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1104 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1105 DWORD dwNewStyle
= dwStyle
;
1106 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1107 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1109 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1111 if (dwStyle
!= dwNewStyle
)
1113 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1114 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1115 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1116 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1118 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1128 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1130 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1131 #if defined(__WIN95__)
1132 if (!(lpPos
->flags
& SWP_NOSIZE
))
1135 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1136 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1137 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1139 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1140 lpPos
->x
= rectClient
.left
;
1141 lpPos
->y
= rectClient
.top
;
1142 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1143 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1145 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1146 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1148 pFrameWnd
->GetToolBar()->Refresh();
1156 wxMDIClientWindow::wxMDIClientWindow(void)
1162 wxMDIClientWindow::~wxMDIClientWindow(void)
1166 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1168 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1170 CLIENTCREATESTRUCT ccs
;
1171 m_windowStyle
= style
;
1172 m_windowParent
= parent
;
1174 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1175 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1177 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1178 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1179 msStyle
|= WS_HSCROLL
;
1180 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1181 msStyle
|= WS_VSCROLL
;
1183 #if defined(__WIN95__)
1184 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1190 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1191 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1192 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1193 SubclassWin(m_hWnd
);
1196 return (m_hWnd
!= 0) ;
1199 // Window procedure: here for debugging purposes
1200 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1202 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1203 // return MSWDefWindowProc(nMsg, wParam, lParam);
1206 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1208 if ( MSWGetOldWndProc() != 0)
1209 return ::CallWindowProc(CASTWNDPROC (FARPROC
) MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1211 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1214 // Explicitly call default scroll behaviour
1215 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1217 // Note: for client windows, the scroll position is not set in
1218 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1219 // scroll position we're at.
1220 // This makes it hard to paint patterns or bitmaps in the background,
1221 // and have the client area scrollable as well.
1223 if ( event
.GetOrientation() == wxHORIZONTAL
)
1224 m_scrollX
= event
.GetPosition(); // Always returns zero!
1226 m_scrollY
= event
.GetPosition(); // Always returns zero!
1231 // Should hand the message to the default proc
1232 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)