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
)
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
))
602 if (m_acceleratorTable
!= (WXHANDLE
) NULL
&&
603 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
, pMsg
))
606 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
608 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
615 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
620 extern wxWindow
*wxWndHook
;
621 extern wxList
*wxWinHandleList
;
623 wxMDIChildFrame::wxMDIChildFrame(void)
628 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
630 const wxString
& title
,
634 const wxString
& name
)
636 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
643 m_windowId
= (int)NewControlId();
645 if (parent
) parent
->AddChild(this);
656 mcs
.szClass
= wxMDIChildFrameClassName
;
658 mcs
.hOwner
= wxGetInstance();
659 if (x
> -1) mcs
.x
= x
;
660 else mcs
.x
= CW_USEDEFAULT
;
662 if (y
> -1) mcs
.y
= y
;
663 else mcs
.y
= CW_USEDEFAULT
;
665 if (width
> -1) mcs
.cx
= width
;
666 else mcs
.cx
= CW_USEDEFAULT
;
668 if (height
> -1) mcs
.cy
= height
;
669 else mcs
.cy
= CW_USEDEFAULT
;
671 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
672 if (style
& wxMINIMIZE_BOX
)
673 msflags
|= WS_MINIMIZEBOX
;
674 if (style
& wxMAXIMIZE_BOX
)
675 msflags
|= WS_MAXIMIZEBOX
;
676 if (style
& wxTHICK_FRAME
)
677 msflags
|= WS_THICKFRAME
;
678 if (style
& wxSYSTEM_MENU
)
679 msflags
|= WS_SYSMENU
;
680 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
681 msflags
|= WS_MINIMIZE
;
682 if (style
& wxMAXIMIZE
)
683 msflags
|= WS_MAXIMIZE
;
684 if (style
& wxCAPTION
)
685 msflags
|= WS_CAPTION
;
691 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
692 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
694 //handle = (HWND)LOWORD(Return);
695 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
696 m_hWnd
= (WXHWND
)Return
;
698 // This gets reassigned so can't be stored
699 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
702 wxWinHandleList
->Append((long)GetHWND(), this);
704 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
706 wxModelessWindows
.Append(this);
710 wxMDIChildFrame::~wxMDIChildFrame(void)
714 ResetWindowStyle(NULL
);
717 // Set the client size (i.e. leave the calculation of borders etc.
719 void wxMDIChildFrame::SetClientSize(int width
, int height
)
721 HWND hWnd
= (HWND
) GetHWND();
724 GetClientRect(hWnd
, &rect
);
727 GetWindowRect(hWnd
, &rect2
);
729 // Find the difference between the entire window (title bar and all)
730 // and the client area; add this to the new client size to move the
732 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
733 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
738 GetStatusBar()->GetSize(&sx
, &sy
);
743 point
.x
= rect2
.left
;
746 // If there's an MDI parent, must subtract the parent's top left corner
747 // since MoveWindow moves relative to the parent
748 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
749 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
751 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
753 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
754 event
.SetEventObject( this );
755 GetEventHandler()->ProcessEvent(event
);
758 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
761 GetWindowRect((HWND
) GetHWND(), &rect
);
766 // Since we now have the absolute screen coords,
767 // if there's a parent we must subtract its top left corner
768 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
769 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
775 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
779 m_frameMenuBar
= NULL
;
783 if (menu_bar
->m_menuBarFrame
)
787 HMENU menu
= CreateMenu();
789 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
791 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
793 // After looking Bounds Checker result, it seems that all
794 // menus must be individually destroyed. So, don't reset m_hMenu,
795 // to allow ~wxMenu to do the job.
797 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
798 // Uncommenting for the moment... JACS
799 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
800 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
803 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
805 delete m_frameMenuBar
;
807 this->m_hMenu
= (WXHMENU
) menu
;
809 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
811 parent
->m_parentFrameActive
= FALSE
;
812 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
814 // Try to insert Window menu in front of Help, otherwise append it.
815 int N
= GetMenuItemCount(menu
);
816 bool success
= FALSE
;
817 for (i
= 0; i
< N
; i
++)
820 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
821 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
822 strcmp(buf
, "Help") == 0))
825 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
826 (UINT
)subMenu
, "&Window");
831 AppendMenu(menu
, MF_POPUP
,
835 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
839 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
840 MAKELPARAM(menu
, subMenu
));
843 DrawMenuBar((HWND
) parent
->GetHWND());
844 m_frameMenuBar
= menu_bar
;
845 menu_bar
->m_menuBarFrame
= this;
849 void wxMDIChildFrame::Maximize(void)
851 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
852 if ( parent
&& parent
->GetClientWindow() )
853 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
856 void wxMDIChildFrame::Restore(void)
858 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
859 if ( parent
&& parent
->GetClientWindow() )
860 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
863 void wxMDIChildFrame::Activate(void)
865 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
866 if ( parent
&& parent
->GetClientWindow() )
867 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
870 static HWND invalidHandle
= 0;
871 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
873 if (!GetHWND()) return;
875 if (invalidHandle
== (HWND
) GetHWND())
878 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
883 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
898 // forward WM_SIZE to status bar control
899 #if USE_NATIVE_STATUSBAR
900 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
902 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
903 event
.SetEventObject( m_frameStatusBar
);
905 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
912 wxWindow::MSWOnSize(x
, y
, id
);
916 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
919 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
921 if ((cmd
== 0) && GetHWND())
923 // In case it's e.g. a toolbar.
924 wxWindow
*win
= wxFindWinFromHandle(control
);
926 return win
->MSWCommand(cmd
, id
);
928 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
941 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
944 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
948 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
950 MSG
*pMsg
= (MSG
*)msg
;
951 if (m_acceleratorTable
&& GetHWND())
953 wxFrame
*parent
= (wxFrame
*)GetParent();
954 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
955 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
, pMsg
) != 0);
960 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
962 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
963 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
965 wxDebugMsg("Parent menu is %d\n", parent_menu
);
967 HMENU child_menu
= (HMENU
) GetWinMenu();
969 wxDebugMsg("Child menu is %d\n", child_menu
);
975 parent
->m_currentChild
= this;
978 parent
->m_parentFrameActive
= FALSE
;
979 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
981 wxDebugMsg("Window submenu is %d\n", subMenu
);
983 // HMENU subMenu = 0;
985 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
989 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
990 MAKELONG(child_menu
, subMenu
));
993 ::DrawMenuBar((HWND
) parent
->GetHWND());
995 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
996 event
.SetEventObject( this );
997 GetEventHandler()->ProcessEvent(event
);
1001 if (parent
->m_currentChild
== this)
1002 parent
->m_currentChild
= NULL
;
1004 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1005 event
.SetEventObject( this );
1006 GetEventHandler()->ProcessEvent(event
);
1008 // m_active = FALSE;
1011 parent
->m_parentFrameActive
= TRUE
;
1012 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1014 wxDebugMsg("Window submenu is %d\n", subMenu
);
1016 // HMENU subMenu = 0;
1018 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1019 (WPARAM
)parent_menu
,
1022 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1023 MAKELONG(parent_menu
, subMenu
));
1026 ::DrawMenuBar((HWND
) parent
->GetHWND());
1029 bool flag
= (activate
!= 0);
1030 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1031 event
.SetEventObject( this );
1032 GetEventHandler()->ProcessEvent(event
);
1035 wxDebugMsg("Finished (de)activating\n");
1040 void wxMDIChildFrame::MSWDestroyWindow(void)
1042 MSWDetachWindowMenu();
1043 invalidHandle
= (HWND
) GetHWND();
1045 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1047 // Must make sure this handle is invalidated (set to NULL)
1048 // since all sorts of things could happen after the
1049 // child client is destroyed, but before the wxFrame is
1052 HWND oldHandle
= (HWND
)GetHWND();
1054 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1057 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1059 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1062 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1068 ::DestroyMenu((HMENU
) m_hMenu
);
1074 // Change the client window's extended style so we don't
1075 // get a client edge style when a child is maximised (a double
1076 // border looks silly.)
1077 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1079 #if defined(__WIN95__)
1080 RECT
*rect
= (RECT
*)vrect
;
1081 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1082 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1083 if (!pChild
|| (pChild
== this))
1085 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1086 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1087 DWORD dwNewStyle
= dwStyle
;
1088 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1089 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1091 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1093 if (dwStyle
!= dwNewStyle
)
1095 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1096 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1097 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1098 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1100 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1110 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1112 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1113 #if defined(__WIN95__)
1114 if (!(lpPos
->flags
& SWP_NOSIZE
))
1117 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1118 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1119 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1121 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1122 lpPos
->x
= rectClient
.left
;
1123 lpPos
->y
= rectClient
.top
;
1124 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1125 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1127 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1128 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1130 pFrameWnd
->GetToolBar()->Refresh();
1138 wxMDIClientWindow::wxMDIClientWindow(void)
1144 wxMDIClientWindow::~wxMDIClientWindow(void)
1148 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1150 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1152 CLIENTCREATESTRUCT ccs
;
1153 m_windowStyle
= style
;
1154 m_windowParent
= parent
;
1156 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1157 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1159 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1160 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1161 msStyle
|= WS_HSCROLL
;
1162 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1163 msStyle
|= WS_VSCROLL
;
1165 #if defined(__WIN95__)
1166 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1172 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1173 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1174 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1175 SubclassWin(m_hWnd
);
1178 return (m_hWnd
!= 0) ;
1181 // Window procedure: here for debugging purposes
1182 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1184 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1185 // return MSWDefWindowProc(nMsg, wParam, lParam);
1188 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1190 if ( MSWGetOldWndProc() != 0)
1191 return ::CallWindowProc(CASTWNDPROC (FARPROC
) MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1193 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1196 // Explicitly call default scroll behaviour
1197 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1199 // Note: for client windows, the scroll position is not set in
1200 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1201 // scroll position we're at.
1202 // This makes it hard to paint patterns or bitmaps in the background,
1203 // and have the client area scrollable as well.
1205 if ( event
.GetOrientation() == wxHORIZONTAL
)
1206 m_scrollX
= event
.GetPosition(); // Always returns zero!
1208 m_scrollY
= event
.GetPosition(); // Always returns zero!
1213 // Should hand the message to the default proc
1214 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)