When can you trust a window size?
Volker Bartheld
dr_versaeg at freenet.de
Thu Nov 16 04:15:31 PST 2006
Hi Troels!
> > But I still have a question: Why do you create a new event type plus
> > handler for it and push this into the wxWindow's list event handlers?
> > Wouldn't it be good enough to
>It's to stand on the shoulders of EVT_IDLE, piggybacking it, letting the
>idle mechanism make the decision of when things are stable.
OK, understood. That makes perfect sense.
>I've rearranged the code a little:
>http://wxforum.shadonet.com/viewtopic.php?p=49422#49422
>Now it itself takes care of calling RemoveEventHandler.
You might also want it to take care of automatically inserting itself in
the list of the parent's event handlers. Here's the code - it's
basically the same approach in the c'tor as you've taken it in the
d'tor. So just a m_idleonce=new wxIdleOnceEvtHandler(this); in the
parent's c'tor and a delete m_idleonce; in the d'tor should be enough.
<idleonce.cpp>
#define EVT_IDLE_ONCE(func) wx__DECLARE_EVT0(wxEVT_IDLE_ONCE, wxIdleEventHandler(func))
static wxEventType wxEVT_IDLE_ONCE=wxNewEventType();
/**
* define a new handler type that will deal with the wxEVT_IDLE event when it arrives in the queue for the *FIRST* time
*/
class wxIdleOnceEvtHandler : public wxEvtHandler
{
public:
wxEvtHandler* m_target;
wxIdleOnceEvtHandler::wxIdleOnceEvtHandler(wxEvtHandler* target) : m_target(target), wxEvtHandler()
{
if(wxIS_KIND_OF(m_target, wxWindow) && GetEvtHandlerEnabled()) ((wxWindow*)m_target)->PushEventHandler(this); // push event handler into parent's list
}
void wxIdleOnceEvtHandler::Stop(void)
{
if(wxIS_KIND_OF(m_target, wxWindow) && GetEvtHandlerEnabled()) ((wxWindow*)m_target)->RemoveEventHandler(this); // remove handler from parent's list
SetEvtHandlerEnabled(false);
} // void wxIdleOnceEvtHandler::Stop(void)
wxIdleOnceEvtHandler::~wxIdleOnceEvtHandler() { Stop(); }
bool wxIdleOnceEvtHandler::ProcessEvent(wxEvent& event) // event handle "hook"
{
if(wxEVT_IDLE==event.GetEventType() && GetEvtHandlerEnabled()) // is it the wxEVT_IDLE and it arrived for the first time (event handler still enabled)?
{
Stop(); // stop the handler
wxEvent* temp=event.Clone(); // duplicate the event
temp->SetEventType(wxEVT_IDLE_ONCE); // set correct event type
wxPostEvent(m_target, *temp); // and reinsert it into parent's queue
delete temp;
} // if(wxEVT_IDLE==event.GetEventType() && GetEvtHandlerEnabled())
return wxEvtHandler::ProcessEvent(event);
} // bool wxIdleOnceEvtHandler::ProcessEvent(wxEvent& event)
};
</idleonce.cpp>
HTH & happy coding,
Volker
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list