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
;
181 m_frameToolBar->GetSize(&tw, &th);
185 if ( GetStatusBar() )
188 GetStatusBar()->GetSize(&sw
, &sh
);
196 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
200 m_frameMenuBar
= NULL
;
204 if (menu_bar
->m_menuBarFrame
)
208 HMENU menu
= CreateMenu();
210 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
212 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
214 // After looking Bounds Checker result, it seems that all
215 // menus must be individually destroyed. So, don't reset m_hMenu,
216 // to allow ~wxMenu to do the job.
218 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
219 // Uncommenting for the moment... JACS
220 menu_bar
->m_menus
[i
]->m_hMenu
= (WXHMENU
) NULL
;
221 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
224 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
226 delete m_frameMenuBar
;
228 this->m_hMenu
= (WXHMENU
) menu
;
230 // MDI parent-specific code follows
232 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
234 // Try to insert Window menu in front of Help, otherwise append it.
235 int N
= GetMenuItemCount(menu
);
236 bool success
= FALSE
;
237 for (i
= 0; i
< N
; i
++)
240 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
241 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
242 strcmp(buf
, "Help") == 0))
245 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
246 (UINT
)subMenu
, "&Window");
251 AppendMenu(menu
, MF_POPUP
,
254 m_parentFrameActive
= TRUE
;
256 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
,
260 SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
261 MAKELPARAM(menu
, subMenu
));
263 DrawMenuBar((HWND
) GetHWND());
265 m_frameMenuBar
= menu_bar
;
266 menu_bar
->m_menuBarFrame
= this;
269 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
278 GetClientSize(&width
, &height
);
282 GetToolBar()->GetSize(&wt
, &ht
);
285 GetToolBar()->SetSize(0, 0, width
, ht
);
288 if ( GetClientWindow() )
289 GetClientWindow()->SetSize(x
, y
, width
, height
);
291 // forward WM_SIZE to status bar control
292 #if USE_NATIVE_STATUSBAR
293 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
294 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
298 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
303 #if WXWIN_COMPATIBILITY
305 void wxMDIParentFrame::OldOnSize(int x, int y)
307 #if WXWIN_COMPATIBILITY == 1
308 wxSizeEvent event(wxSize(x, y), m_windowId);
309 event.SetEventObject( this );
310 GetEventHandler()->ProcessEvent(event);
320 GetClientSize(&width, &height);
324 GetToolBar()->GetSize(&wt, &ht);
329 if ( GetClientWindow() )
330 GetClientWindow()->SetSize(x, y, width, height);
335 // Default activation behaviour - nothing.
336 // Default activation behaviour - override dedault wxFrame behaviour
337 void wxMDIParentFrame::OldOnActivate(bool flag)
339 #if WXWIN_COMPATIBILITY == 1
340 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
341 event.SetEventObject( this );
342 GetEventHandler()->ProcessEvent(event);
350 // Returns the active MDI child window
351 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
353 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
354 HWND hWnd
= (HWND
)SendMessage((HWND
) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE
, 0, 0L);
358 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
361 // Create the client window class (don't Create the window,
362 // just return a new class)
363 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
365 return new wxMDIClientWindow
;
368 // Responds to colour changes, and passes event on to children.
369 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
371 if ( m_clientWindow
)
373 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
374 m_clientWindow
->Refresh();
377 if ( m_frameToolBar )
379 wxSysColourChangedEvent event2;
380 event2.eventObject = m_frameToolBar;
381 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
385 // Propagate the event to the non-top-level children
386 wxFrame::OnSysColourChanged(event
);
390 void wxMDIParentFrame::Cascade(void)
392 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDICASCADE
, 0, 0);
395 void wxMDIParentFrame::Tile(void)
397 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
400 void wxMDIParentFrame::ArrangeIcons(void)
402 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE
, 0, 0);
405 void wxMDIParentFrame::ActivateNext(void)
407 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 0);
410 void wxMDIParentFrame::ActivatePrevious(void)
412 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDINEXT
, 0, 1);
417 // Returns a style for the client window - usually 0
418 // or, for example, wxHSCROLL | wxVSCROLL
419 long wxMDIParentFrame::GetClientStyle(void) const
421 return wxHSCROLL | wxVSCROLL ;
425 bool wxMDIParentFrame::MSWOnDestroy(void)
430 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
432 m_clientWindow
= OnCreateClient();
433 // Uses own style for client style
434 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
437 void wxMDIParentFrame::MSWOnSize(int x
, int y
, WXUINT id
)
452 // forward WM_SIZE to status bar control
453 #if USE_NATIVE_STATUSBAR
454 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
456 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
457 event
.SetEventObject( m_frameStatusBar
);
459 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
465 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
466 event
.SetEventObject( this );
467 if (!GetEventHandler()->ProcessEvent(event
))
472 bool wxMDIParentFrame::MSWOnActivate(int state
, bool minimized
, WXHWND activate
)
474 wxWindow::MSWOnActivate(state
, minimized
, activate
);
476 // If this window is an MDI parent, we must also send an OnActivate message
477 // to the current child.
478 if ((m_currentChild
!= NULL
) && ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)))
480 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
481 event
.SetEventObject( m_currentChild
);
482 m_currentChild
->GetEventHandler()->ProcessEvent(event
);
487 bool wxMDIParentFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
491 // In case it's e.g. a toolbar.
492 wxWindow
*win
= wxFindWinFromHandle(control
);
494 return win
->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);
516 wxDebugMsg("wxMDIFrame::OnCommand %d: system command: calling default window proc\n", GetHWND());
518 return FALSE
; // Get WndProc to call default proc
521 if (m_parentFrameActive
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
526 else if (m_currentChild
&& (id
< wxFIRST_MDI_CHILD
|| id
> wxLAST_MDI_CHILD
))
529 wxDebugMsg("wxMDIFrame::MSWOnCommand %d: calling child OnCommand\n", GetHWND());
531 return m_currentChild
->MSWOnCommand(id
, cmd
, control
);
534 if (id
>= wxFIRST_MDI_CHILD
&& id
<= wxLAST_MDI_CHILD
)
536 wxNode
* node
= GetChildren()->First();
539 wxWindow
* child
= (wxWindow
*) node
->Data();
540 if (child
->GetHWND())
543 long childId
= GetWindowLong((HWND
) child
->GetHWND(), GWL_ID
);
545 long childId
= GetWindowWord((HWND
) child
->GetHWND(), GWW_ID
);
549 ::SendMessage( (HWND
) GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) child
->GetHWND(), 0);
556 wxWindow* child = FindItem(id);
559 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
568 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem
, WXWORD nFlags
, WXHMENU hSysMenu
)
570 if (m_parentFrameActive
)
572 if (nFlags
== 0xFFFF && hSysMenu
== (WXHMENU
) NULL
)
574 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
575 event
.SetEventObject( this );
576 GetEventHandler()->ProcessEvent(event
);
578 else if (nFlags
!= MF_SEPARATOR
)
580 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
581 event
.SetEventObject( this );
582 GetEventHandler()->ProcessEvent(event
);
585 else if (m_currentChild
)
587 m_currentChild
->MSWOnMenuHighlight(nItem
, nFlags
, hSysMenu
);
591 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
594 if ( GetClientWindow() )
595 clientWnd
= GetClientWindow()->GetHWND();
599 return DefFrameProc((HWND
) GetHWND(), (HWND
) clientWnd
, message
, wParam
, lParam
);
602 bool wxMDIParentFrame::MSWProcessMessage(WXMSG
* msg
)
604 MSG
*pMsg
= (MSG
*)msg
;
606 if ((m_currentChild
!= (wxWindow
*)NULL
) && (m_currentChild
->GetHWND() != (WXHWND
) NULL
) && m_currentChild
->MSWProcessMessage(msg
))
609 if (m_acceleratorTable
!= (WXHANDLE
) NULL
&&
610 ::TranslateAccelerator((HWND
) GetHWND(), (HACCEL
) m_acceleratorTable
, pMsg
))
613 if (pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
615 if (::TranslateMDISysAccel((HWND
) GetClientWindow()->GetHWND(), pMsg
))
622 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC
WXUNUSED(pDC
))
627 extern wxWindow
*wxWndHook
;
628 extern wxList
*wxWinHandleList
;
630 wxMDIChildFrame::wxMDIChildFrame(void)
635 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
637 const wxString
& title
,
641 const wxString
& name
)
643 m_defaultIcon
= (WXHICON
) (wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
: wxDEFAULT_MDICHILDFRAME_ICON
);
650 m_windowId
= (int)NewControlId();
652 if (parent
) parent
->AddChild(this);
663 mcs
.szClass
= wxMDIChildFrameClassName
;
665 mcs
.hOwner
= wxGetInstance();
666 if (x
> -1) mcs
.x
= x
;
667 else mcs
.x
= CW_USEDEFAULT
;
669 if (y
> -1) mcs
.y
= y
;
670 else mcs
.y
= CW_USEDEFAULT
;
672 if (width
> -1) mcs
.cx
= width
;
673 else mcs
.cx
= CW_USEDEFAULT
;
675 if (height
> -1) mcs
.cy
= height
;
676 else mcs
.cy
= CW_USEDEFAULT
;
678 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
679 if (style
& wxMINIMIZE_BOX
)
680 msflags
|= WS_MINIMIZEBOX
;
681 if (style
& wxMAXIMIZE_BOX
)
682 msflags
|= WS_MAXIMIZEBOX
;
683 if (style
& wxTHICK_FRAME
)
684 msflags
|= WS_THICKFRAME
;
685 if (style
& wxSYSTEM_MENU
)
686 msflags
|= WS_SYSMENU
;
687 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
688 msflags
|= WS_MINIMIZE
;
689 if (style
& wxMAXIMIZE
)
690 msflags
|= WS_MAXIMIZE
;
691 if (style
& wxCAPTION
)
692 msflags
|= WS_CAPTION
;
698 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
699 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
701 //handle = (HWND)LOWORD(Return);
702 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
703 m_hWnd
= (WXHWND
)Return
;
705 // This gets reassigned so can't be stored
706 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
709 wxWinHandleList
->Append((long)GetHWND(), this);
711 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
713 wxModelessWindows
.Append(this);
717 wxMDIChildFrame::~wxMDIChildFrame(void)
721 ResetWindowStyle(NULL
);
724 // Set the client size (i.e. leave the calculation of borders etc.
726 void wxMDIChildFrame::SetClientSize(int width
, int height
)
728 HWND hWnd
= (HWND
) GetHWND();
731 GetClientRect(hWnd
, &rect
);
734 GetWindowRect(hWnd
, &rect2
);
736 // Find the difference between the entire window (title bar and all)
737 // and the client area; add this to the new client size to move the
739 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
740 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
745 GetStatusBar()->GetSize(&sx
, &sy
);
750 point
.x
= rect2
.left
;
753 // If there's an MDI parent, must subtract the parent's top left corner
754 // since MoveWindow moves relative to the parent
755 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
756 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
758 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
760 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
761 event
.SetEventObject( this );
762 GetEventHandler()->ProcessEvent(event
);
765 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
768 GetWindowRect((HWND
) GetHWND(), &rect
);
773 // Since we now have the absolute screen coords,
774 // if there's a parent we must subtract its top left corner
775 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
776 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
782 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
786 m_frameMenuBar
= NULL
;
790 if (menu_bar
->m_menuBarFrame
)
794 HMENU menu
= CreateMenu();
796 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
798 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
800 // After looking Bounds Checker result, it seems that all
801 // menus must be individually destroyed. So, don't reset m_hMenu,
802 // to allow ~wxMenu to do the job.
804 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
805 // Uncommenting for the moment... JACS
806 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
807 ::AppendMenu((HMENU
) menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
810 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
812 delete m_frameMenuBar
;
814 this->m_hMenu
= (WXHMENU
) menu
;
816 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
818 parent
->m_parentFrameActive
= FALSE
;
819 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
821 // Try to insert Window menu in front of Help, otherwise append it.
822 int N
= GetMenuItemCount(menu
);
823 bool success
= FALSE
;
824 for (i
= 0; i
< N
; i
++)
827 int chars
= GetMenuString(menu
, i
, buf
, 100, MF_BYPOSITION
);
828 if ((chars
> 0) && (strcmp(buf
, "&Help") == 0 ||
829 strcmp(buf
, "Help") == 0))
832 InsertMenu(menu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
833 (UINT
)subMenu
, "&Window");
838 AppendMenu(menu
, MF_POPUP
,
842 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
846 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
847 MAKELPARAM(menu
, subMenu
));
850 DrawMenuBar((HWND
) parent
->GetHWND());
851 m_frameMenuBar
= menu_bar
;
852 menu_bar
->m_menuBarFrame
= this;
856 void wxMDIChildFrame::Maximize(void)
858 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
859 if ( parent
&& parent
->GetClientWindow() )
860 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
863 void wxMDIChildFrame::Restore(void)
865 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
866 if ( parent
&& parent
->GetClientWindow() )
867 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
870 void wxMDIChildFrame::Activate(void)
872 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
873 if ( parent
&& parent
->GetClientWindow() )
874 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
877 static HWND invalidHandle
= 0;
878 void wxMDIChildFrame::MSWOnSize(int x
, int y
, WXUINT id
)
880 if (!GetHWND()) return;
882 if (invalidHandle
== (HWND
) GetHWND())
885 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
890 (void)MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
905 // forward WM_SIZE to status bar control
906 #if USE_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
);
918 wxWindow::MSWOnSize(x
, y
, id
);
922 bool wxMDIChildFrame::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
925 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
927 if ((cmd
== 0) && GetHWND())
929 // In case it's e.g. a toolbar.
930 wxWindow
*win
= wxFindWinFromHandle(control
);
932 return win
->MSWCommand(cmd
, id
);
934 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
947 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
950 return DefMDIChildProc((HWND
) GetHWND(), (UINT
) message
, (WPARAM
) wParam
, (LPARAM
) lParam
);
954 bool wxMDIChildFrame::MSWProcessMessage(WXMSG
*msg
)
956 MSG
*pMsg
= (MSG
*)msg
;
957 if (m_acceleratorTable
&& GetHWND())
959 wxFrame
*parent
= (wxFrame
*)GetParent();
960 HWND parent_hwnd
= (HWND
) parent
->GetHWND();
961 return (::TranslateAccelerator(parent_hwnd
, (HACCEL
) m_acceleratorTable
, pMsg
) != 0);
966 long wxMDIChildFrame::MSWOnMDIActivate(long activate
, WXHWND
WXUNUSED(one
), WXHWND
WXUNUSED(two
))
968 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
969 HMENU parent_menu
= (HMENU
) parent
->GetWinMenu();
971 wxDebugMsg("Parent menu is %d\n", parent_menu
);
973 HMENU child_menu
= (HMENU
) GetWinMenu();
975 wxDebugMsg("Child menu is %d\n", child_menu
);
981 parent
->m_currentChild
= this;
984 parent
->m_parentFrameActive
= FALSE
;
985 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
987 wxDebugMsg("Window submenu is %d\n", subMenu
);
989 // HMENU subMenu = 0;
991 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
995 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
996 MAKELONG(child_menu
, subMenu
));
999 ::DrawMenuBar((HWND
) parent
->GetHWND());
1001 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
1002 event
.SetEventObject( this );
1003 GetEventHandler()->ProcessEvent(event
);
1007 if (parent
->m_currentChild
== this)
1008 parent
->m_currentChild
= NULL
;
1010 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, m_windowId
);
1011 event
.SetEventObject( this );
1012 GetEventHandler()->ProcessEvent(event
);
1014 // m_active = FALSE;
1017 parent
->m_parentFrameActive
= TRUE
;
1018 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
1020 wxDebugMsg("Window submenu is %d\n", subMenu
);
1022 // HMENU subMenu = 0;
1024 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
,
1025 (WPARAM
)parent_menu
,
1028 ::SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDISETMENU
, 0,
1029 MAKELONG(parent_menu
, subMenu
));
1032 ::DrawMenuBar((HWND
) parent
->GetHWND());
1035 bool flag
= (activate
!= 0);
1036 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
1037 event
.SetEventObject( this );
1038 GetEventHandler()->ProcessEvent(event
);
1041 wxDebugMsg("Finished (de)activating\n");
1046 void wxMDIChildFrame::MSWDestroyWindow(void)
1048 MSWDetachWindowMenu();
1049 invalidHandle
= (HWND
) GetHWND();
1051 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1053 // Must make sure this handle is invalidated (set to NULL)
1054 // since all sorts of things could happen after the
1055 // child client is destroyed, but before the wxFrame is
1058 HWND oldHandle
= (HWND
)GetHWND();
1060 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle
);
1063 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1065 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1068 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle
);
1074 ::DestroyMenu((HMENU
) m_hMenu
);
1080 // Change the client window's extended style so we don't
1081 // get a client edge style when a child is maximised (a double
1082 // border looks silly.)
1083 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1085 #if defined(__WIN95__)
1086 RECT
*rect
= (RECT
*)vrect
;
1087 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1088 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1089 if (!pChild
|| (pChild
== this))
1091 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1092 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1093 DWORD dwNewStyle
= dwStyle
;
1094 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1095 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1097 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1099 if (dwStyle
!= dwNewStyle
)
1101 ::RedrawWindow((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1102 ::SetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
, dwNewStyle
);
1103 ::SetWindowPos((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), NULL
, 0, 0, 0, 0,
1104 SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOCOPYBITS
);
1106 ::GetClientRect((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), rect
);
1116 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos
)
1118 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1119 #if defined(__WIN95__)
1120 if (!(lpPos
->flags
& SWP_NOSIZE
))
1123 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
1124 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1125 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1127 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1128 lpPos
->x
= rectClient
.left
;
1129 lpPos
->y
= rectClient
.top
;
1130 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1131 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1133 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1134 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
1136 pFrameWnd
->GetToolBar()->Refresh();
1144 wxMDIClientWindow::wxMDIClientWindow(void)
1150 wxMDIClientWindow::~wxMDIClientWindow(void)
1154 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1156 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1158 CLIENTCREATESTRUCT ccs
;
1159 m_windowStyle
= style
;
1160 m_windowParent
= parent
;
1162 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu();
1163 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1165 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1166 if ( parent
->GetWindowStyleFlag() & wxHSCROLL
)
1167 msStyle
|= WS_HSCROLL
;
1168 if ( parent
->GetWindowStyleFlag() & wxVSCROLL
)
1169 msStyle
|= WS_VSCROLL
;
1171 #if defined(__WIN95__)
1172 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1178 m_hWnd
= (WXHWND
) ::CreateWindowEx(exStyle
, "mdiclient", NULL
,
1179 msStyle
, 0, 0, 0, 0, (HWND
) parent
->GetHWND(), NULL
,
1180 wxGetInstance(), (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1181 SubclassWin(m_hWnd
);
1184 return (m_hWnd
!= 0) ;
1187 // Window procedure: here for debugging purposes
1188 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1190 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1191 // return MSWDefWindowProc(nMsg, wParam, lParam);
1194 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1196 if ( MSWGetOldWndProc() != 0)
1197 return ::CallWindowProc(CASTWNDPROC (FARPROC
) MSWGetOldWndProc(), (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1199 return ::DefWindowProc((HWND
) m_hWnd
, (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1202 // Explicitly call default scroll behaviour
1203 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1205 // Note: for client windows, the scroll position is not set in
1206 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1207 // scroll position we're at.
1208 // This makes it hard to paint patterns or bitmaps in the background,
1209 // and have the client area scrollable as well.
1211 if ( event
.GetOrientation() == wxHORIZONTAL
)
1212 m_scrollX
= event
.GetPosition(); // Always returns zero!
1214 m_scrollY
= event
.GetPosition(); // Always returns zero!
1219 // Should hand the message to the default proc
1220 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate
, WXHWND
, WXHWND
)