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 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
604 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
606 MSG
*pMsg
= (MSG
*)msg
;
608 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
611 if (m_acceleratorTable
.Ok() &&
612 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
615 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
617 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
625 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
630 extern wxWindow
*wxWndHook
;
631 extern wxList
*wxWinHandleList
;
633 wxMDIChildFrame::wxMDIChildFrame(void)
638 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
640 const wxString
& title
,
644 const wxString
& name
)
646 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
653 m_windowId
= (int)NewControlId();
655 if (parent
) parent
->AddChild(this);
666 mcs
.szClass
= wxMDIChildFrameClassName
;
668 mcs
.hOwner
= wxGetInstance();
669 if (x
> -1) mcs
.x
= x
;
670 else mcs
.x
= CW_USEDEFAULT
;
672 if (y
> -1) mcs
.y
= y
;
673 else mcs
.y
= CW_USEDEFAULT
;
675 if (width
> -1) mcs
.cx
= width
;
676 else mcs
.cx
= CW_USEDEFAULT
;
678 if (height
> -1) mcs
.cy
= height
;
679 else mcs
.cy
= CW_USEDEFAULT
;
681 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
682 if (style
& wxMINIMIZE_BOX
)
683 msflags
|= WS_MINIMIZEBOX
;
684 if (style
& wxMAXIMIZE_BOX
)
685 msflags
|= WS_MAXIMIZEBOX
;
686 if (style
& wxTHICK_FRAME
)
687 msflags
|= WS_THICKFRAME
;
688 if (style
& wxSYSTEM_MENU
)
689 msflags
|= WS_SYSMENU
;
690 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
691 msflags
|= WS_MINIMIZE
;
692 if (style
& wxMAXIMIZE
)
693 msflags
|= WS_MAXIMIZE
;
694 if (style
& wxCAPTION
)
695 msflags
|= WS_CAPTION
;
701 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
702 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
704 //handle = (HWND)LOWORD(Return);
705 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
706 m_hWnd
= (WXHWND
)Return
;
708 // This gets reassigned so can't be stored
709 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
712 wxWinHandleList
->Append((long)GetHWND(), this);
714 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
716 wxModelessWindows
.Append(this);
720 wxMDIChildFrame::~wxMDIChildFrame(void)
724 ResetWindowStyle(NULL
);
727 // Set the client size (i.e. leave the calculation of borders etc.
729 void wxMDIChildFrame::SetClientSize(int width
, int height
)
731 HWND hWnd
= (HWND
) GetHWND();
734 GetClientRect(hWnd
, &rect
);
737 GetWindowRect(hWnd
, &rect2
);
739 // Find the difference between the entire window (title bar and all)
740 // and the client area; add this to the new client size to move the
742 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
743 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
748 GetStatusBar()->GetSize(&sx
, &sy
);
753 point
.x
= rect2
.left
;
756 // If there's an MDI parent, must subtract the parent's top left corner
757 // since MoveWindow moves relative to the parent
758 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
759 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
761 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
763 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
764 event
.SetEventObject( this );
765 GetEventHandler()->ProcessEvent(event
);
768 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
771 GetWindowRect((HWND
) GetHWND(), &rect
);
776 // Since we now have the absolute screen coords,
777 // if there's a parent we must subtract its top left corner
778 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
779 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
785 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
789 m_frameMenuBar
= NULL
;
793 if (menu_bar
->m_menuBarFrame
)
797 HMENU menu
= CreateMenu();
799 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
801 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
803 // After looking Bounds Checker result, it seems that all
804 // menus must be individually destroyed. So, don't reset m_hMenu,
805 // to allow ~wxMenu to do the job.
807 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
808 // Uncommenting for the moment... JACS
809 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
810 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
813 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
815 delete m_frameMenuBar
;
817 this->m_hMenu
= (WXHMENU
) menu
;
819 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
821 parent
->m_parentFrameActive
= FALSE
;
822 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
824 // Try to insert Window menu in front of Help, otherwise append it.
825 int N
= GetMenuItemCount(menu
);
826 bool success
= FALSE
;
827 for (i
= 0; i
< N
; i
++)
830 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
831 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
832 strcmp(buf
, "Help") == 0))
835 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
836 (UINT
)subMenu
, "&Window");
841 AppendMenu(menu
, MF_POPUP
,
845 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
849 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
850 MAKELPARAM(menu
, subMenu
));
853 DrawMenuBar((HWND
) parent
->GetHWND());
854 m_frameMenuBar
= menu_bar
;
855 menu_bar
->m_menuBarFrame
= this;
859 void wxMDIChildFrame::Maximize(void)
861 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
862 if ( parent
&& parent
->GetClientWindow() )
863 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
866 void wxMDIChildFrame::Restore(void)
868 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
869 if ( parent
&& parent
->GetClientWindow() )
870 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
873 void wxMDIChildFrame::Activate(void)
875 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
876 if ( parent
&& parent
->GetClientWindow() )
877 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
880 static HWND invalidHandle
= 0;
881 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
883 if (!GetHWND()) return;
885 if (invalidHandle
== (HWND
) GetHWND())
890 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
905 // forward WM_SIZE to status bar control
906 #if wxUSE_NATIVE_STATUSBAR
907 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
909 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
910 event
.SetEventObject( m_frameStatusBar
);
912 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
919 wxWindow::MSWOnSize(x
, y
, id
);
923 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
925 // if ((cmd == 0) && GetHWND())
928 // In case it's e.g. a toolbar.
929 wxWindow
*win
= wxFindWinFromHandle(control
);
931 return win
->MSWCommand(cmd
, id
);
933 if (wxCurrentPopupMenu
)
935 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
936 wxCurrentPopupMenu
= NULL
;
937 if (popupMenu
->MSWCommand(cmd
, id
))
941 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
954 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
957 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
961 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
966 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
968 MSG
*pMsg
= (MSG
*)msg
;
969 if (m_acceleratorTable
.Ok())
971 wxFrame
*parent
= (wxFrame
*)GetParent();
972 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
973 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
979 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
981 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
982 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
983 HMENU child_menu
= (HMENU
) GetWinMenu();
988 parent
->m_currentChild
= this;
991 parent
->m_parentFrameActive
= FALSE
;
992 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
994 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
998 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
999 MAKELONG(child_menu
, subMenu
));
1002 ::DrawMenuBar((HWND
) parent
->GetHWND());
1004 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1005 event
.SetEventObject( this );
1006 GetEventHandler()->ProcessEvent(event
);
1010 if (parent
->m_currentChild
== this)
1011 parent
->m_currentChild
= NULL
;
1013 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1014 event
.SetEventObject( this );
1015 GetEventHandler()->ProcessEvent(event
);
1017 // m_active = FALSE;
1020 parent
->m_parentFrameActive
= TRUE
;
1021 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1023 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1024 (WPARAM
)parent_menu
,
1027 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1028 MAKELONG(parent_menu
, subMenu
));
1031 ::DrawMenuBar((HWND
) parent
->GetHWND());
1034 bool flag
= (activate
!= 0);
1035 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1036 event
.SetEventObject( this );
1037 GetEventHandler()->ProcessEvent(event
);
1041 void wxMDIChildFrame::MSWDestroyWindow(void)
1043 MSWDetachWindowMenu();
1044 invalidHandle
= (HWND
) GetHWND();
1046 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1048 // Must make sure this handle is invalidated (set to NULL)
1049 // since all sorts of things could happen after the
1050 // child client is destroyed, but before the wxFrame is
1053 HWND oldHandle
= (HWND
)GetHWND();
1055 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1057 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1063 ::DestroyMenu((HMENU
) m_hMenu
);
1069 // Change the client window's extended style so we don't
1070 // get a client edge style when a child is maximised (a double
1071 // border looks silly.)
1072 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1074 #if defined(__WIN95__)
1075 RECT
*rect
= (RECT
*)vrect
;
1076 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1077 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1078 if (!pChild
|| (pChild
== this))
1080 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1081 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1082 DWORD dwNewStyle
= dwStyle
;
1083 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1084 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1086 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1088 if (dwStyle
!= dwNewStyle
)
1090 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1091 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1092 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1093 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1095 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1105 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1107 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1108 #if defined(__WIN95__)
1109 if (!(lpPos
->flags
& SWP_NOSIZE
))
1112 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1113 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1114 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1116 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1117 lpPos
->x
= rectClient
.left
;
1118 lpPos
->y
= rectClient
.top
;
1119 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1120 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1122 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1123 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1125 pFrameWnd
->GetToolBar()->Refresh();
1133 wxMDIClientWindow::wxMDIClientWindow(void)
1139 wxMDIClientWindow::~wxMDIClientWindow(void)
1143 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1145 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1147 CLIENTCREATESTRUCT ccs
;
1148 m_windowStyle
= style
;
1149 m_windowParent
= parent
;
1151 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1152 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1154 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1155 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1156 msStyle
|= WS_HSCROLL
;
1157 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1158 msStyle
|= WS_VSCROLL
;
1160 #if defined(__WIN95__)
1161 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1167 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1168 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1169 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1170 SubclassWin(m_hWnd
);
1173 return (m_hWnd
!= 0) ;
1176 // Window procedure: here for debugging purposes
1177 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1179 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1180 // return MSWDefWindowProc(nMsg, wParam, lParam);
1183 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1185 if ( MSWGetOldWndProc() != 0)
1186 return ::CallWindowProc(CASTWNDPROC
MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1188 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1191 // Explicitly call default scroll behaviour
1192 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1194 // Note: for client windows, the scroll position is not set in
1195 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1196 // scroll position we're at.
1197 // This makes it hard to paint patterns or bitmaps in the background,
1198 // and have the client area scrollable as well.
1200 if ( event
.GetOrientation() == wxHORIZONTAL
)
1201 m_scrollX
= event
.GetPosition(); // Always returns zero!
1203 m_scrollY
= event
.GetPosition(); // Always returns zero!
1208 // Should hand the message to the default proc
1209 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)