1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/dialog.h"
30 #include "wx/statusbr.h"
31 #include "wx/settings.h"
35 #include "wx/msw/private.h"
37 #if wxUSE_NATIVE_STATUSBAR
38 #include <wx/msw/statbr95.h>
43 extern wxList wxModelessWindows
;
44 extern wxMenu
*wxCurrentPopupMenu
;
46 #define IDM_WINDOWTILE 4001
47 #define IDM_WINDOWCASCADE 4002
48 #define IDM_WINDOWICONS 4003
49 #define IDM_WINDOWNEXT 4004
50 // This range gives a maximum of 500
51 // MDI children. Should be enough :-)
52 #define wxFIRST_MDI_CHILD 4100
53 #define wxLAST_MDI_CHILD 4600
55 // Status border dimensions
56 #define wxTHICK_LINE_BORDER 3
57 #define wxTHICK_LINE_WIDTH 1
59 extern char wxMDIFrameClassName
[];
60 extern char wxMDIChildFrameClassName
[];
61 extern wxWindow
*wxWndHook
;
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
65 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
66 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
68 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
69 EVT_SIZE(wxMDIParentFrame::OnSize
)
70 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
71 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
74 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
75 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
80 wxMDIParentFrame::wxMDIParentFrame(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");
123 DWORD msflags
= WS_OVERLAPPED
;
124 if (style
& wxMINIMIZE_BOX
)
125 msflags
|= WS_MINIMIZEBOX
;
126 if (style
& wxMAXIMIZE_BOX
)
127 msflags
|= WS_MAXIMIZEBOX
;
128 if (style
& wxTHICK_FRAME
)
129 msflags
|= WS_THICKFRAME
;
130 if (style
& wxSYSTEM_MENU
)
131 msflags
|= WS_SYSMENU
;
132 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
133 msflags
|= WS_MINIMIZE
;
134 if (style
& wxMAXIMIZE
)
135 msflags
|= WS_MAXIMIZE
;
136 if (style
& wxCAPTION
)
137 msflags
|= WS_CAPTION
;
139 // Adding WS_CLIPCHILDREN causes children not to be properly
140 // drawn when first displaying them.
141 // if (style & wxCLIP_CHILDREN)
142 // msflags |= WS_CLIPCHILDREN;
144 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
147 wxModelessWindows
.Append(this);
152 wxMDIParentFrame::~wxMDIParentFrame(void)
156 DestroyMenu((HMENU
) m_windowMenu
); // Destroy dummy "Window" menu
159 if (m_clientWindow
->MSWGetOldWndProc())
160 m_clientWindow
->UnsubclassWin();
162 m_clientWindow
->m_hWnd
= 0;
163 delete m_clientWindow
;
166 // Get size *available for subwindows* i.e. excluding menu bar.
167 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
170 GetClientRect((HWND
) GetHWND(), &rect
);
172 int cwidth
= rect
.right
;
173 int cheight
= rect
.bottom
;
175 if ( GetStatusBar() )
178 GetStatusBar()->GetSize(&sw
, &sh
);
182 wxPoint
pt(GetClientAreaOrigin());
190 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
194 m_frameMenuBar
= NULL
;
198 if (menu_bar
->m_menuBarFrame
)
202 HMENU menu
= CreateMenu();
204 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
206 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
208 // After looking Bounds Checker result, it seems that all
209 // menus must be individually destroyed. So, don't reset m_hMenu,
210 // to allow ~wxMenu to do the job.
212 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
213 // Uncommenting for the moment... JACS
214 menu_bar
->m_menus
[i
]->m_hMenu
= (WXHMENU
) NULL
;
215 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
218 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
220 delete m_frameMenuBar
;
222 this->m_hMenu
= (WXHMENU
) menu
;
224 // MDI parent-specific code follows
226 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
228 // Try to insert Window menu in front of Help, otherwise append it.
229 int N
= GetMenuItemCount(menu
);
230 bool success
= FALSE
;
231 for (i
= 0; i
< N
; i
++)
234 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
235 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
236 strcmp(buf
, "Help") == 0))
239 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
240 (UINT
)subMenu
, "&Window");
245 AppendMenu(menu
, MF_POPUP
,
248 m_parentFrameActive
= TRUE
;
250 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
254 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
255 MAKELPARAM(menu
, subMenu
));
257 DrawMenuBar((HWND
) GetHWND());
259 m_frameMenuBar
= menu_bar
;
260 menu_bar
->m_menuBarFrame
= this;
263 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
265 #if wxUSE_CONSTRAINTS
272 GetClientSize(&width
, &height
);
274 if ( GetClientWindow() )
275 GetClientWindow()->SetSize(x
, y
, width
, height
);
277 /* Already done in MSWOnSize
278 // forward WM_SIZE to status bar control
279 #if wxUSE_NATIVE_STATUSBAR
280 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
281 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
287 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
292 #if WXWIN_COMPATIBILITY
294 void wxMDIParentFrame::OldOnSize(int x, int y)
296 #if WXWIN_COMPATIBILITY == 1
297 wxSizeEvent event(wxSize(x, y), m_windowId);
298 event.SetEventObject( this );
299 GetEventHandler()->ProcessEvent(event);
302 #if wxUSE_CONSTRAINTS
309 GetClientSize(&width, &height);
313 GetToolBar()->GetSize(&wt, &ht);
318 if ( GetClientWindow() )
319 GetClientWindow()->SetSize(x, y, width, height);
324 // Default activation behaviour - nothing.
325 // Default activation behaviour - override dedault wxFrame behaviour
326 void wxMDIParentFrame::OldOnActivate(bool flag)
328 #if WXWIN_COMPATIBILITY == 1
329 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
330 event.SetEventObject( this );
331 GetEventHandler()->ProcessEvent(event);
339 // Returns the active MDI child window
340 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
342 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
343 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
347 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
350 // Create the client window class (don't Create the window,
351 // just return a new class)
352 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
354 return new wxMDIClientWindow
;
357 // Responds to colour changes, and passes event on to children.
358 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
360 if ( m_clientWindow
)
362 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
363 m_clientWindow
->Refresh();
366 if ( m_frameToolBar )
368 wxSysColourChangedEvent event2;
369 event2.eventObject = m_frameToolBar;
370 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
374 // Propagate the event to the non-top-level children
375 wxFrame::OnSysColourChanged(event
);
379 void wxMDIParentFrame::Cascade(void)
381 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
384 void wxMDIParentFrame::Tile(void)
386 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
389 void wxMDIParentFrame::ArrangeIcons(void)
391 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
394 void wxMDIParentFrame::ActivateNext(void)
396 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
399 void wxMDIParentFrame::ActivatePrevious(void)
401 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
406 // Returns a style for the client window - usually 0
407 // or, for example, wxHSCROLL | wxVSCROLL
408 long wxMDIParentFrame::GetClientStyle(void) const
410 return wxHSCROLL | wxVSCROLL ;
414 bool wxMDIParentFrame::MSWOnDestroy(void)
419 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
421 m_clientWindow
= OnCreateClient();
422 // Uses own style for client style
423 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
426 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
441 // forward WM_SIZE to status bar control
442 #if wxUSE_NATIVE_STATUSBAR
443 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
445 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
446 event
.SetEventObject( m_frameStatusBar
);
448 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
455 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
456 event
.SetEventObject( this );
457 if (!GetEventHandler()->ProcessEvent(event
))
462 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
464 wxWindow::MSWOnActivate(state
, minimized
, activate
);
466 // If this window is an MDI parent, we must also send an OnActivate message
467 // to the current child.
468 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
470 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
471 event
.SetEventObject( m_currentChild
);
472 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
477 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
479 // if (cmd == 0) // Why did I do this test?
481 // In case it's e.g. a toolbar.
482 wxWindow
*win
= wxFindWinFromHandle(control
);
484 return win
->MSWCommand(cmd
, id
);
487 if (wxCurrentPopupMenu)
489 wxMenu *popupMenu = wxCurrentPopupMenu;
490 wxCurrentPopupMenu = NULL;
491 if (!popupMenu->MSWCommand(cmd, id))
498 case IDM_WINDOWCASCADE
:
499 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, MDITILE_SKIPDISABLED
, 0);
502 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
504 case IDM_WINDOWICONS
:
505 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
508 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
515 return FALSE
; // Get WndProc to call default proc
518 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
523 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
525 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
528 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
530 wxNode
* node
= GetChildren()->First();
533 wxWindow
* child
= (wxWindow
*) node
->Data();
534 if (child
->GetHWND())
537 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
539 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
543 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
550 wxWindow* child = FindItem(id);
553 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
562 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
564 if (m_parentFrameActive
)
566 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
568 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
569 event
.SetEventObject( this );
570 GetEventHandler()->ProcessEvent(event
);
572 else if (nFlags
!= MF_SEPARATOR
)
574 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
575 event
.SetEventObject( this );
576 GetEventHandler()->ProcessEvent(event
);
579 else if (m_currentChild
)
581 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
585 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
588 if ( GetClientWindow() )
589 clientWnd
= GetClientWindow()->GetHWND();
593 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
596 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
598 MSG
*pMsg
= (MSG
*)msg
;
600 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
606 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
608 MSG
*pMsg
= (MSG
*)msg
;
610 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
613 if (m_acceleratorTable
.Ok() &&
614 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
617 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
619 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
627 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
632 extern wxWindow
*wxWndHook
;
633 extern wxList
*wxWinHandleList
;
635 wxMDIChildFrame::wxMDIChildFrame(void)
640 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
642 const wxString
& title
,
646 const wxString
& name
)
648 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
655 m_windowId
= (int)NewControlId();
657 if (parent
) parent
->AddChild(this);
668 mcs
.szClass
= wxMDIChildFrameClassName
;
670 mcs
.hOwner
= wxGetInstance();
671 if (x
> -1) mcs
.x
= x
;
672 else mcs
.x
= CW_USEDEFAULT
;
674 if (y
> -1) mcs
.y
= y
;
675 else mcs
.y
= CW_USEDEFAULT
;
677 if (width
> -1) mcs
.cx
= width
;
678 else mcs
.cx
= CW_USEDEFAULT
;
680 if (height
> -1) mcs
.cy
= height
;
681 else mcs
.cy
= CW_USEDEFAULT
;
683 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
684 if (style
& wxMINIMIZE_BOX
)
685 msflags
|= WS_MINIMIZEBOX
;
686 if (style
& wxMAXIMIZE_BOX
)
687 msflags
|= WS_MAXIMIZEBOX
;
688 if (style
& wxTHICK_FRAME
)
689 msflags
|= WS_THICKFRAME
;
690 if (style
& wxSYSTEM_MENU
)
691 msflags
|= WS_SYSMENU
;
692 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
693 msflags
|= WS_MINIMIZE
;
694 if (style
& wxMAXIMIZE
)
695 msflags
|= WS_MAXIMIZE
;
696 if (style
& wxCAPTION
)
697 msflags
|= WS_CAPTION
;
703 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
704 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
706 //handle = (HWND)LOWORD(Return);
707 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
708 m_hWnd
= (WXHWND
)Return
;
710 // This gets reassigned so can't be stored
711 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
714 wxWinHandleList
->Append((long)GetHWND(), this);
716 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
718 wxModelessWindows
.Append(this);
722 wxMDIChildFrame::~wxMDIChildFrame(void)
726 ResetWindowStyle(NULL
);
729 // Set the client size (i.e. leave the calculation of borders etc.
731 void wxMDIChildFrame::SetClientSize(int width
, int height
)
733 HWND hWnd
= (HWND
) GetHWND();
736 GetClientRect(hWnd
, &rect
);
739 GetWindowRect(hWnd
, &rect2
);
741 // Find the difference between the entire window (title bar and all)
742 // and the client area; add this to the new client size to move the
744 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
745 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
750 GetStatusBar()->GetSize(&sx
, &sy
);
755 point
.x
= rect2
.left
;
758 // If there's an MDI parent, must subtract the parent's top left corner
759 // since MoveWindow moves relative to the parent
760 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
761 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
763 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
765 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
766 event
.SetEventObject( this );
767 GetEventHandler()->ProcessEvent(event
);
770 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
773 GetWindowRect((HWND
) GetHWND(), &rect
);
778 // Since we now have the absolute screen coords,
779 // if there's a parent we must subtract its top left corner
780 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
781 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
787 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
791 m_frameMenuBar
= NULL
;
795 if (menu_bar
->m_menuBarFrame
)
799 HMENU menu
= CreateMenu();
801 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
803 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
805 // After looking Bounds Checker result, it seems that all
806 // menus must be individually destroyed. So, don't reset m_hMenu,
807 // to allow ~wxMenu to do the job.
809 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
810 // Uncommenting for the moment... JACS
811 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
812 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
815 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
817 delete m_frameMenuBar
;
819 this->m_hMenu
= (WXHMENU
) menu
;
821 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
823 parent
->m_parentFrameActive
= FALSE
;
824 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
826 // Try to insert Window menu in front of Help, otherwise append it.
827 int N
= GetMenuItemCount(menu
);
828 bool success
= FALSE
;
829 for (i
= 0; i
< N
; i
++)
832 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
833 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
834 strcmp(buf
, "Help") == 0))
837 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
838 (UINT
)subMenu
, "&Window");
843 AppendMenu(menu
, MF_POPUP
,
847 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
851 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
852 MAKELPARAM(menu
, subMenu
));
855 DrawMenuBar((HWND
) parent
->GetHWND());
856 m_frameMenuBar
= menu_bar
;
857 menu_bar
->m_menuBarFrame
= this;
861 void wxMDIChildFrame::Maximize(void)
863 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
864 if ( parent
&& parent
->GetClientWindow() )
865 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
868 void wxMDIChildFrame::Restore(void)
870 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
871 if ( parent
&& parent
->GetClientWindow() )
872 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
875 void wxMDIChildFrame::Activate(void)
877 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
878 if ( parent
&& parent
->GetClientWindow() )
879 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
882 static HWND invalidHandle
= 0;
883 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
885 if (!GetHWND()) return;
887 if (invalidHandle
== (HWND
) GetHWND())
892 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
907 // forward WM_SIZE to status bar control
908 #if wxUSE_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
);
921 wxWindow::MSWOnSize(x
, y
, id
);
925 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
927 // if ((cmd == 0) && GetHWND())
930 // In case it's e.g. a toolbar.
931 wxWindow
*win
= wxFindWinFromHandle(control
);
933 return win
->MSWCommand(cmd
, id
);
935 if (wxCurrentPopupMenu
)
937 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
938 wxCurrentPopupMenu
= NULL
;
939 if (popupMenu
->MSWCommand(cmd
, id
))
943 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
956 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
959 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
963 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
968 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
970 MSG
*pMsg
= (MSG
*)msg
;
971 if (m_acceleratorTable
.Ok())
973 wxFrame
*parent
= (wxFrame
*)GetParent();
974 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
975 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
981 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
983 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
984 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
985 HMENU child_menu
= (HMENU
) GetWinMenu();
990 parent
->m_currentChild
= this;
993 parent
->m_parentFrameActive
= FALSE
;
994 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
996 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1000 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1001 MAKELONG(child_menu
, subMenu
));
1004 ::DrawMenuBar((HWND
) parent
->GetHWND());
1006 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1007 event
.SetEventObject( this );
1008 GetEventHandler()->ProcessEvent(event
);
1012 if (parent
->m_currentChild
== this)
1013 parent
->m_currentChild
= NULL
;
1015 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1016 event
.SetEventObject( this );
1017 GetEventHandler()->ProcessEvent(event
);
1019 // m_active = FALSE;
1022 parent
->m_parentFrameActive
= TRUE
;
1023 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1025 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1026 (WPARAM
)parent_menu
,
1029 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1030 MAKELONG(parent_menu
, subMenu
));
1033 ::DrawMenuBar((HWND
) parent
->GetHWND());
1036 bool flag
= (activate
!= 0);
1037 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1038 event
.SetEventObject( this );
1039 GetEventHandler()->ProcessEvent(event
);
1043 void wxMDIChildFrame::MSWDestroyWindow(void)
1045 MSWDetachWindowMenu();
1046 invalidHandle
= (HWND
) GetHWND();
1048 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1050 // Must make sure this handle is invalidated (set to NULL)
1051 // since all sorts of things could happen after the
1052 // child client is destroyed, but before the wxFrame is
1055 HWND oldHandle
= (HWND
)GetHWND();
1057 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1059 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
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
, 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
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(long bActivate
, WXHWND
, WXHWND
)