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");
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
)
269 #if wxUSE_CONSTRAINTS
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 wxUSE_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);
306 #if wxUSE_CONSTRAINTS
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 wxUSE_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
);
491 if (wxCurrentPopupMenu)
493 wxMenu *popupMenu = wxCurrentPopupMenu;
494 wxCurrentPopupMenu = NULL;
495 if (!popupMenu->MSWCommand(cmd, id))
502 case IDM_WINDOWCASCADE
:
503 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, MDITILE_SKIPDISABLED
, 0);
506 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
508 case IDM_WINDOWICONS
:
509 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
512 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
520 wxDebugMsg("wxMDIFrame::OnCommand %d: system command: calling default window proc\n", GetHWND());
522 return FALSE
; // Get WndProc to call default proc
525 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
530 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
533 wxDebugMsg("wxMDIFrame::MSWOnCommand %d: calling child OnCommand\n", GetHWND());
535 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
538 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
540 wxNode
* node
= GetChildren()->First();
543 wxWindow
* child
= (wxWindow
*) node
->Data();
544 if (child
->GetHWND())
547 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
549 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
553 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
560 wxWindow* child = FindItem(id);
563 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
572 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
574 if (m_parentFrameActive
)
576 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
578 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
579 event
.SetEventObject( this );
580 GetEventHandler()->ProcessEvent(event
);
582 else if (nFlags
!= MF_SEPARATOR
)
584 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
585 event
.SetEventObject( this );
586 GetEventHandler()->ProcessEvent(event
);
589 else if (m_currentChild
)
591 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
595 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
598 if ( GetClientWindow() )
599 clientWnd
= GetClientWindow()->GetHWND();
603 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
606 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
608 MSG
*pMsg
= (MSG
*)msg
;
610 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
616 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
618 MSG
*pMsg
= (MSG
*)msg
;
620 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWTranslateMessage(msg
))
623 if (m_acceleratorTable
.Ok() &&
624 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
))
627 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
629 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
637 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
642 extern wxWindow
*wxWndHook
;
643 extern wxList
*wxWinHandleList
;
645 wxMDIChildFrame::wxMDIChildFrame(void)
650 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
652 const wxString
& title
,
656 const wxString
& name
)
658 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
665 m_windowId
= (int)NewControlId();
667 if (parent
) parent
->AddChild(this);
678 mcs
.szClass
= wxMDIChildFrameClassName
;
680 mcs
.hOwner
= wxGetInstance();
681 if (x
> -1) mcs
.x
= x
;
682 else mcs
.x
= CW_USEDEFAULT
;
684 if (y
> -1) mcs
.y
= y
;
685 else mcs
.y
= CW_USEDEFAULT
;
687 if (width
> -1) mcs
.cx
= width
;
688 else mcs
.cx
= CW_USEDEFAULT
;
690 if (height
> -1) mcs
.cy
= height
;
691 else mcs
.cy
= CW_USEDEFAULT
;
693 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
694 if (style
& wxMINIMIZE_BOX
)
695 msflags
|= WS_MINIMIZEBOX
;
696 if (style
& wxMAXIMIZE_BOX
)
697 msflags
|= WS_MAXIMIZEBOX
;
698 if (style
& wxTHICK_FRAME
)
699 msflags
|= WS_THICKFRAME
;
700 if (style
& wxSYSTEM_MENU
)
701 msflags
|= WS_SYSMENU
;
702 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
703 msflags
|= WS_MINIMIZE
;
704 if (style
& wxMAXIMIZE
)
705 msflags
|= WS_MAXIMIZE
;
706 if (style
& wxCAPTION
)
707 msflags
|= WS_CAPTION
;
713 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
714 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
716 //handle = (HWND)LOWORD(Return);
717 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
718 m_hWnd
= (WXHWND
)Return
;
720 // This gets reassigned so can't be stored
721 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
724 wxWinHandleList
->Append((long)GetHWND(), this);
726 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
728 wxModelessWindows
.Append(this);
732 wxMDIChildFrame::~wxMDIChildFrame(void)
736 ResetWindowStyle(NULL
);
739 // Set the client size (i.e. leave the calculation of borders etc.
741 void wxMDIChildFrame::SetClientSize(int width
, int height
)
743 HWND hWnd
= (HWND
) GetHWND();
746 GetClientRect(hWnd
, &rect
);
749 GetWindowRect(hWnd
, &rect2
);
751 // Find the difference between the entire window (title bar and all)
752 // and the client area; add this to the new client size to move the
754 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
755 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
760 GetStatusBar()->GetSize(&sx
, &sy
);
765 point
.x
= rect2
.left
;
768 // If there's an MDI parent, must subtract the parent's top left corner
769 // since MoveWindow moves relative to the parent
770 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
771 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
773 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
775 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
776 event
.SetEventObject( this );
777 GetEventHandler()->ProcessEvent(event
);
780 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
783 GetWindowRect((HWND
) GetHWND(), &rect
);
788 // Since we now have the absolute screen coords,
789 // if there's a parent we must subtract its top left corner
790 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
791 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
797 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
801 m_frameMenuBar
= NULL
;
805 if (menu_bar
->m_menuBarFrame
)
809 HMENU menu
= CreateMenu();
811 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
813 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
815 // After looking Bounds Checker result, it seems that all
816 // menus must be individually destroyed. So, don't reset m_hMenu,
817 // to allow ~wxMenu to do the job.
819 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
820 // Uncommenting for the moment... JACS
821 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
822 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
825 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
827 delete m_frameMenuBar
;
829 this->m_hMenu
= (WXHMENU
) menu
;
831 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
833 parent
->m_parentFrameActive
= FALSE
;
834 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
836 // Try to insert Window menu in front of Help, otherwise append it.
837 int N
= GetMenuItemCount(menu
);
838 bool success
= FALSE
;
839 for (i
= 0; i
< N
; i
++)
842 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
843 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
844 strcmp(buf
, "Help") == 0))
847 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
848 (UINT
)subMenu
, "&Window");
853 AppendMenu(menu
, MF_POPUP
,
857 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
861 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
862 MAKELPARAM(menu
, subMenu
));
865 DrawMenuBar((HWND
) parent
->GetHWND());
866 m_frameMenuBar
= menu_bar
;
867 menu_bar
->m_menuBarFrame
= this;
871 void wxMDIChildFrame::Maximize(void)
873 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
874 if ( parent
&& parent
->GetClientWindow() )
875 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
878 void wxMDIChildFrame::Restore(void)
880 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
881 if ( parent
&& parent
->GetClientWindow() )
882 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
885 void wxMDIChildFrame::Activate(void)
887 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
888 if ( parent
&& parent
->GetClientWindow() )
889 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
892 static HWND invalidHandle
= 0;
893 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
895 if (!GetHWND()) return;
897 if (invalidHandle
== (HWND
) GetHWND())
900 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
905 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
920 // forward WM_SIZE to status bar control
921 #if wxUSE_NATIVE_STATUSBAR
922 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
924 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
925 event
.SetEventObject( m_frameStatusBar
);
927 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
934 wxWindow::MSWOnSize(x
, y
, id
);
938 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
941 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
943 // if ((cmd == 0) && GetHWND())
946 // In case it's e.g. a toolbar.
947 wxWindow
*win
= wxFindWinFromHandle(control
);
949 return win
->MSWCommand(cmd
, id
);
951 if (wxCurrentPopupMenu
)
953 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
954 wxCurrentPopupMenu
= NULL
;
955 if (popupMenu
->MSWCommand(cmd
, id
))
959 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
972 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
975 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
979 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
984 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
986 MSG
*pMsg
= (MSG
*)msg
;
987 if (m_acceleratorTable
.Ok())
989 wxFrame
*parent
= (wxFrame
*)GetParent();
990 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
991 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
.GetHACCEL(), pMsg
) != 0);
997 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
999 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1000 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
1002 wxDebugMsg("Parent menu is %d\n", parent_menu
);
1004 HMENU child_menu
= (HMENU
) GetWinMenu();
1006 wxDebugMsg("Child menu is %d\n", child_menu
);
1012 parent
->m_currentChild
= this;
1015 parent
->m_parentFrameActive
= FALSE
;
1016 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1018 wxDebugMsg("Window submenu is %d\n", subMenu
);
1020 // HMENU subMenu = 0;
1022 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1026 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1027 MAKELONG(child_menu
, subMenu
));
1030 ::DrawMenuBar((HWND
) parent
->GetHWND());
1032 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1033 event
.SetEventObject( this );
1034 GetEventHandler()->ProcessEvent(event
);
1038 if (parent
->m_currentChild
== this)
1039 parent
->m_currentChild
= NULL
;
1041 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1042 event
.SetEventObject( this );
1043 GetEventHandler()->ProcessEvent(event
);
1045 // m_active = FALSE;
1048 parent
->m_parentFrameActive
= TRUE
;
1049 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1051 wxDebugMsg("Window submenu is %d\n", subMenu
);
1053 // HMENU subMenu = 0;
1055 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1056 (WPARAM
)parent_menu
,
1059 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1060 MAKELONG(parent_menu
, subMenu
));
1063 ::DrawMenuBar((HWND
) parent
->GetHWND());
1066 bool flag
= (activate
!= 0);
1067 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1068 event
.SetEventObject( this );
1069 GetEventHandler()->ProcessEvent(event
);
1072 wxDebugMsg("Finished (de)activating\n");
1077 void wxMDIChildFrame::MSWDestroyWindow(void)
1079 MSWDetachWindowMenu();
1080 invalidHandle
= (HWND
) GetHWND();
1082 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1084 // Must make sure this handle is invalidated (set to NULL)
1085 // since all sorts of things could happen after the
1086 // child client is destroyed, but before the wxFrame is
1089 HWND oldHandle
= (HWND
)GetHWND();
1091 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1094 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1096 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1099 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1105 ::DestroyMenu((HMENU
) m_hMenu
);
1111 // Change the client window's extended style so we don't
1112 // get a client edge style when a child is maximised (a double
1113 // border looks silly.)
1114 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1116 #if defined(__WIN95__)
1117 RECT
*rect
= (RECT
*)vrect
;
1118 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1119 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1120 if (!pChild
|| (pChild
== this))
1122 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1123 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1124 DWORD dwNewStyle
= dwStyle
;
1125 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1126 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1128 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1130 if (dwStyle
!= dwNewStyle
)
1132 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1133 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1134 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1135 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1137 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1147 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1149 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1150 #if defined(__WIN95__)
1151 if (!(lpPos
->flags
& SWP_NOSIZE
))
1154 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1155 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1156 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1158 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1159 lpPos
->x
= rectClient
.left
;
1160 lpPos
->y
= rectClient
.top
;
1161 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1162 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1164 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1165 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1167 pFrameWnd
->GetToolBar()->Refresh();
1175 wxMDIClientWindow::wxMDIClientWindow(void)
1181 wxMDIClientWindow::~wxMDIClientWindow(void)
1185 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1187 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1189 CLIENTCREATESTRUCT ccs
;
1190 m_windowStyle
= style
;
1191 m_windowParent
= parent
;
1193 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1194 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1196 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1197 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1198 msStyle
|= WS_HSCROLL
;
1199 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1200 msStyle
|= WS_VSCROLL
;
1202 #if defined(__WIN95__)
1203 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1209 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1210 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1211 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1212 SubclassWin(m_hWnd
);
1215 return (m_hWnd
!= 0) ;
1218 // Window procedure: here for debugging purposes
1219 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1221 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1222 // return MSWDefWindowProc(nMsg, wParam, lParam);
1225 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1227 if ( MSWGetOldWndProc() != 0)
1228 return ::CallWindowProc(CASTWNDPROC
MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1230 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1233 // Explicitly call default scroll behaviour
1234 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1236 // Note: for client windows, the scroll position is not set in
1237 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1238 // scroll position we're at.
1239 // This makes it hard to paint patterns or bitmaps in the background,
1240 // and have the client area scrollable as well.
1242 if ( event
.GetOrientation() == wxHORIZONTAL
)
1243 m_scrollX
= event
.GetPosition(); // Always returns zero!
1245 m_scrollY
= event
.GetPosition(); // Always returns zero!
1250 // Should hand the message to the default proc
1251 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)