diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index 319d880da3..385659df1c 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: mdi.h +// Name: wx/msw/mdi.h // Purpose: MDI (Multiple Document Interface) classes // Author: Julian Smart // Modified by: @@ -121,7 +121,7 @@ private: class WXDLLEXPORT wxMDIChildFrame : public wxFrame { public: - wxMDIChildFrame(); + wxMDIChildFrame() { Init(); } wxMDIChildFrame(wxMDIParentFrame *parent, wxWindowID id, const wxString& title, @@ -130,6 +130,8 @@ public: long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxFrameNameStr) { + Init(); + Create(parent, id, title, pos, size, style, name); } @@ -150,8 +152,10 @@ public: virtual void Restore(); virtual void Activate(); - // Handlers + // Implementation only from now on + // ------------------------------- + // Handlers bool HandleMDIActivate(long bActivate, WXHWND, WXHWND); bool HandleWindowPosChanging(void *lpPos); bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); @@ -162,14 +166,22 @@ public: virtual void MSWDestroyWindow(); - // Implementation bool ResetWindowStyle(void *vrect); + void OnIdle(wxIdleEvent& event); + protected: virtual void DoGetPosition(int *x, int *y) const; virtual void DoSetClientSize(int width, int height); virtual void InternalSetMenuBar(); + // common part of all ctors + void Init(); + +private: + bool m_needsResize; // flag which tells us to artificially resize the frame + + DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(wxMDIChildFrame) }; @@ -179,8 +191,6 @@ protected: class WXDLLEXPORT wxMDIClientWindow : public wxWindow { - DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) - public: wxMDIClientWindow() { Init(); } wxMDIClientWindow(wxMDIParentFrame *parent, long style = 0) @@ -207,6 +217,7 @@ protected: private: DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) }; #endif diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 20f6cbb2aa..72126d5668 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -161,6 +161,10 @@ public: wxWindow* GetWindowChild1(wxWindowID id); wxWindow* GetWindowChild(wxWindowID id); + // a MSW only function which sends a size event to the window using its + // current size - this has an effect of refreshing the window layout + void SendSizeEvent(); + // implementation from now on // -------------------------- diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index ef6f8e502c..7b551b6a4d 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -132,6 +132,10 @@ BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) END_EVENT_TABLE() +BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) + EVT_IDLE(wxMDIChildFrame::OnIdle) +END_EVENT_TABLE() + BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) EVT_SCROLL(wxMDIClientWindow::OnScroll) END_EVENT_TABLE() @@ -612,8 +616,9 @@ bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) // wxMDIChildFrame // =========================================================================== -wxMDIChildFrame::wxMDIChildFrame() +void wxMDIChildFrame::Init() { + m_needsResize = TRUE; } bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, @@ -1201,6 +1206,22 @@ void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeF } } +void wxMDIChildFrame::OnIdle(wxIdleEvent& event) +{ + // MDI child frames get their WM_SIZE when they're constructed but at this + // moment they don't have any children yet so all child windows will be + // positioned incorrectly when they are added later - to fix this, we + // generate an artificial size event here + if ( m_needsResize ) + { + m_needsResize = FALSE; // avoid any possibility of recursion + + SendSizeEvent(); + } + + event.Skip(); +} + // --------------------------------------------------------------------------- // non member functions // --------------------------------------------------------------------------- diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index ab94b91434..2a1a5e7ce1 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -108,10 +108,7 @@ // private function prototypes // ---------------------------------------------------------------------------- -// send a dummy WM_SIZE to the given window: this is used to relayout the frame -// which contains us -static void SendResizeMessage(HWND hwnd); - +// adjust toolbar bitmap colours static void wxMapBitmap(HBITMAP hBitmap, int width, int height); // ---------------------------------------------------------------------------- @@ -270,7 +267,7 @@ wxToolBar::~wxToolBar() wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); if ( frame && wxTopLevelWindows.Find(frame) ) { - SendResizeMessage(GetHwndOf(frame)); + frame->SendSizeEvent(); } if ( m_hBitmap ) @@ -895,7 +892,7 @@ void wxToolBar::UpdateSize() wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); if ( frame ) { - SendResizeMessage(GetHwndOf(frame)); + frame->SendSizeEvent(); } } @@ -1005,19 +1002,6 @@ long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) // private functions // ---------------------------------------------------------------------------- -static void SendResizeMessage(HWND hwnd) -{ - // don't change the size, we just need to generate a WM_SIZE - RECT r; - if ( !::GetWindowRect(hwnd, &r) ) - { - wxLogLastError(_T("GetWindowRect")); - } - - (void)::PostMessage(hwnd, WM_SIZE, SIZE_RESTORED, - MAKELPARAM(r.right - r.left, r.bottom - r.top)); -} - // These are the default colors used to map the bitmap colors to the current // system colors. Note that they are in BGR format because this is what Windows // wants (and not RGB) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 854cc01d92..4b7e7370d5 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3061,6 +3061,19 @@ bool wxWindow::HandleGetMinMaxInfo(void *mmInfo) return rc; } +// generate an artificial resize event +void wxWindow::SendSizeEvent() +{ + RECT r; + if ( !::GetWindowRect(GetHwnd(), &r) ) + { + wxLogLastError(_T("GetWindowRect")); + } + + (void)::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, + MAKELPARAM(r.right - r.left, r.bottom - r.top)); +} + // --------------------------------------------------------------------------- // command messages // ---------------------------------------------------------------------------