add PostSizeEvent() and use it in wxMSW status bar code (#9795)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54837 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-07-29 23:07:24 +00:00
parent 44d0f703f9
commit ecdc118383
8 changed files with 93 additions and 22 deletions

View File

@ -92,7 +92,7 @@ public:
#endif // tooltips
// override the base class function to handle iconized/maximized frames
virtual void SendSizeEvent();
virtual void SendSizeEvent(int flags = 0);
virtual wxPoint GetClientAreaOrigin() const;

View File

@ -66,7 +66,7 @@ public:
virtual bool IsMaximized(void) const;
virtual void Maximize(bool bMaximize = true);
virtual void Restore(void);
virtual void SendSizeEvent(void);
virtual void SendSizeEvent(int flags = 0);
virtual void SetIcons(const wxIconBundle& rIcons);
virtual bool Show(bool bShow = true);

View File

@ -131,6 +131,12 @@ enum wxShowEffect
wxSHOW_EFFECT_MAX
};
// flags for SendSizeEvent()
enum
{
wxSEND_EVENT_POST = 1
};
// ----------------------------------------------------------------------------
// (pseudo)template list classes
// ----------------------------------------------------------------------------
@ -538,14 +544,24 @@ public:
// sends a size event to the window using its current size -- this has an
// effect of refreshing the window layout
virtual void SendSizeEvent();
//
// by default the event is sent, i.e. processed immediately, but if flags
// value includes wxSEND_EVENT_POST then it's posted, i.e. only schedule
// for later processing
virtual void SendSizeEvent(int flags = 0);
// this is a safe wrapper for GetParent()->SendSizeEvent(): it checks that
// we have a parent window and it's not in process of being deleted
//
// this is used by controls such as tool/status bars changes to which must
// also result in parent re-layout
void SendSizeEventToParent();
void SendSizeEventToParent(int flags = 0);
// this is a more readable synonym for SendSizeEvent(wxSEND_EVENT_POST)
void PostSizeEvent() { SendSizeEvent(wxSEND_EVENT_POST); }
// this is the same as SendSizeEventToParent() but using PostSizeEvent()
void PostSizeEventToParent() { SendSizeEventToParent(wxSEND_EVENT_POST); }
// window state

View File

@ -1588,6 +1588,21 @@ public:
bool PopupMenu(wxMenu* menu, int x, int y);
//@}
/**
Posts a size event to the window.
This is the same as SendSizeEvent() with @c wxSEND_EVENT_POST argument.
*/
void PostSizeEvent();
/**
Posts a size event to the parent of this window.
This is the same as SendSizeEventToParent() with @c wxSEND_EVENT_POST
argument.
*/
void PostSizeEventToParent();
/**
Pushes this event handler onto the event stack for the window.
@ -1793,8 +1808,16 @@ public:
if the frame is using either sizers or constraints for the children
layout, it is enough to call wxWindow::Layout() directly and this
function should not be used in this case.
If @a flags includes @c wxSEND_EVENT_POST value, this function posts
the event, i.e. schedules it for later processing, instead of
dispatching it directly. You can also use PostSizeEvent() as a more
readable equivalent of calling this function with this flag.
@param flags
May include @c wxSEND_EVENT_POST. Default value is 0.
*/
void SendSizeEvent();
void SendSizeEvent(int flags = 0);
/**
Safe wrapper for GetParent()->SendSizeEvent().
@ -1804,8 +1827,13 @@ public:
used internally by windows such as toolbars changes to whose state
should result in parent re-layout (e.g. when a toolbar is added to the
top of the window, all the other windows must be shifted down).
@see PostSizeEventToParent()
@param flags
See description of this parameter in SendSizeEvent() documentation.
*/
void SendSizeEventToParent();
void SendSizeEventToParent(int flags = 0);
/**
Sets the accelerator table for this window. See wxAcceleratorTable.

View File

@ -841,18 +841,21 @@ void wxWindowBase::DoGetScreenPosition(int *x, int *y) const
ClientToScreen(x, y);
}
void wxWindowBase::SendSizeEvent()
void wxWindowBase::SendSizeEvent(int flags)
{
wxSizeEvent event(GetSize(), GetId());
event.SetEventObject(this);
HandleWindowEvent(event);
if ( flags & wxSEND_EVENT_POST )
wxPostEvent(this, event);
else
HandleWindowEvent(event);
}
void wxWindowBase::SendSizeEventToParent()
void wxWindowBase::SendSizeEventToParent(int flags)
{
wxWindow * const parent = GetParent();
if ( parent && !parent->IsBeingDeleted() )
parent->SendSizeEvent();
parent->SendSizeEvent(flags);
}
// ----------------------------------------------------------------------------

View File

@ -310,15 +310,24 @@ void wxFrame::Raise()
}
// generate an artificial resize event
void wxFrame::SendSizeEvent()
void wxFrame::SendSizeEvent(int flags)
{
if ( !m_iconized )
{
RECT r = wxGetWindowRect(GetHwnd());
(void)::SendMessage(GetHwnd(), WM_SIZE,
IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
if ( flags & wxSEND_EVENT_POST )
{
::PostMessage(GetHwnd(), WM_SIZE,
IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
}
else // send it
{
::SendMessage(GetHwnd(), WM_SIZE,
IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
}
}
}

View File

@ -125,7 +125,11 @@ bool wxStatusBar::Create(wxWindow *parent,
// we must refresh the frame size when the statusbar is created, because
// its client area might change
SendSizeEventToParent();
//
// notice that we must post the event, not send it, as the frame doesn't
// know that we're its status bar yet so laying it out right now wouldn't
// work correctly, we need to wait until we return to the main loop
PostSizeEventToParent();
return true;
}
@ -135,7 +139,7 @@ wxStatusBar::~wxStatusBar()
// we must refresh the frame size when the statusbar is deleted but the
// frame is not - otherwise statusbar leaves a hole in the place it used to
// occupy
SendSizeEventToParent();
PostSizeEventToParent();
}
void wxStatusBar::SetFieldsCount(int nFields, const int *widths)

View File

@ -872,17 +872,28 @@ void wxTopLevelWindowOS2::Restore()
} // end of wxTopLevelWindowOS2::Restore
// generate an artificial resize event
void wxTopLevelWindowOS2::SendSizeEvent()
void wxTopLevelWindowOS2::SendSizeEvent(int flags)
{
if (!m_bIconized)
{
RECTL vRect = wxGetWindowRect(GetHwnd());
(void)::WinPostMsg( m_hFrame
,WM_SIZE
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
);
if ( flags & wxSEND_EVENT_POST )
{
(void)::WinPostMsg( m_hFrame
,WM_SIZE
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
);
}
else // send it
{
(void)::WinSendMsg( m_hFrame
,WM_SIZE
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
);
}
}
} // end of wxTopLevelWindowOS2::SendSizeEvent