fixed "missing" initial resize of wxMDIChildFrame

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7630 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-06-21 21:10:38 +00:00
parent 2ed1896868
commit 26eb0ba5b8
5 changed files with 59 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: mdi.h // Name: wx/msw/mdi.h
// Purpose: MDI (Multiple Document Interface) classes // Purpose: MDI (Multiple Document Interface) classes
// Author: Julian Smart // Author: Julian Smart
// Modified by: // Modified by:
@@ -121,7 +121,7 @@ private:
class WXDLLEXPORT wxMDIChildFrame : public wxFrame class WXDLLEXPORT wxMDIChildFrame : public wxFrame
{ {
public: public:
wxMDIChildFrame(); wxMDIChildFrame() { Init(); }
wxMDIChildFrame(wxMDIParentFrame *parent, wxMDIChildFrame(wxMDIParentFrame *parent,
wxWindowID id, wxWindowID id,
const wxString& title, const wxString& title,
@@ -130,6 +130,8 @@ public:
long style = wxDEFAULT_FRAME_STYLE, long style = wxDEFAULT_FRAME_STYLE,
const wxString& name = wxFrameNameStr) const wxString& name = wxFrameNameStr)
{ {
Init();
Create(parent, id, title, pos, size, style, name); Create(parent, id, title, pos, size, style, name);
} }
@@ -150,8 +152,10 @@ public:
virtual void Restore(); virtual void Restore();
virtual void Activate(); virtual void Activate();
// Handlers // Implementation only from now on
// -------------------------------
// Handlers
bool HandleMDIActivate(long bActivate, WXHWND, WXHWND); bool HandleMDIActivate(long bActivate, WXHWND, WXHWND);
bool HandleWindowPosChanging(void *lpPos); bool HandleWindowPosChanging(void *lpPos);
bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
@@ -162,14 +166,22 @@ public:
virtual void MSWDestroyWindow(); virtual void MSWDestroyWindow();
// Implementation
bool ResetWindowStyle(void *vrect); bool ResetWindowStyle(void *vrect);
void OnIdle(wxIdleEvent& event);
protected: protected:
virtual void DoGetPosition(int *x, int *y) const; virtual void DoGetPosition(int *x, int *y) const;
virtual void DoSetClientSize(int width, int height); virtual void DoSetClientSize(int width, int height);
virtual void InternalSetMenuBar(); 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) DECLARE_DYNAMIC_CLASS(wxMDIChildFrame)
}; };
@@ -179,8 +191,6 @@ protected:
class WXDLLEXPORT wxMDIClientWindow : public wxWindow class WXDLLEXPORT wxMDIClientWindow : public wxWindow
{ {
DECLARE_DYNAMIC_CLASS(wxMDIClientWindow)
public: public:
wxMDIClientWindow() { Init(); } wxMDIClientWindow() { Init(); }
wxMDIClientWindow(wxMDIParentFrame *parent, long style = 0) wxMDIClientWindow(wxMDIParentFrame *parent, long style = 0)
@@ -207,6 +217,7 @@ protected:
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxMDIClientWindow)
}; };
#endif #endif

View File

@@ -161,6 +161,10 @@ public:
wxWindow* GetWindowChild1(wxWindowID id); wxWindow* GetWindowChild1(wxWindowID id);
wxWindow* GetWindowChild(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 // implementation from now on
// -------------------------- // --------------------------

View File

@@ -132,6 +132,10 @@ BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
EVT_IDLE(wxMDIChildFrame::OnIdle)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
EVT_SCROLL(wxMDIClientWindow::OnScroll) EVT_SCROLL(wxMDIClientWindow::OnScroll)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -612,8 +616,9 @@ bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg)
// wxMDIChildFrame // wxMDIChildFrame
// =========================================================================== // ===========================================================================
wxMDIChildFrame::wxMDIChildFrame() void wxMDIChildFrame::Init()
{ {
m_needsResize = TRUE;
} }
bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, 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 // non member functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -108,10 +108,7 @@
// private function prototypes // private function prototypes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// send a dummy WM_SIZE to the given window: this is used to relayout the frame // adjust toolbar bitmap colours
// which contains us
static void SendResizeMessage(HWND hwnd);
static void wxMapBitmap(HBITMAP hBitmap, int width, int height); static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -270,7 +267,7 @@ wxToolBar::~wxToolBar()
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame && wxTopLevelWindows.Find(frame) ) if ( frame && wxTopLevelWindows.Find(frame) )
{ {
SendResizeMessage(GetHwndOf(frame)); frame->SendSizeEvent();
} }
if ( m_hBitmap ) if ( m_hBitmap )
@@ -895,7 +892,7 @@ void wxToolBar::UpdateSize()
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame ) if ( frame )
{ {
SendResizeMessage(GetHwndOf(frame)); frame->SendSizeEvent();
} }
} }
@@ -1005,19 +1002,6 @@ long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
// private functions // 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 // 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 // system colors. Note that they are in BGR format because this is what Windows
// wants (and not RGB) // wants (and not RGB)

View File

@@ -3061,6 +3061,19 @@ bool wxWindow::HandleGetMinMaxInfo(void *mmInfo)
return rc; 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 // command messages
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------