virtual event func ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

virtual event func ?

Post by gpu » Tue Sep 09, 2014 6:45 am

1. can I inhrite from wxPanel a MyPanel that is an abstract class?
2. in MyPanel i have a virtual func PaintEvent() for EVT_PAINT, and in MyPnael's child MyChildPanel, I override PaintEvent()...both in MyPanel and MyChildPanel,i declare BEGIN_EVENT_TABLE, EVT_PAINT, is it OK?
Will the MyChildPanel object implement PaintEvent() twice if I called MyPanel::PaintEvent() in MyChildPanel::PaintEvent()?
If this method is wrong... what is the normal way to make a event func virtual ?
3. in MyChildPanel's PaintEvent(), is calling event.Skip() equals to calling MyPanel::PaintEvent()?
4. the efficient is important in my application, so if nothing more is done in MyChildPanel, which one is more effciant? and does the use of virtual func affect the efficient? (1)only call MyPanel::PaintEvent() in MyChildPanel::PaintEvent(); (2)not override MyPanel::PaintEvent() and so no EVT_PAINT in MyChildPanel, just use the MyPanel::PaintEvent() for MyChildPanel; (3)not use virtual event func, just use EVT_PAINT in MyChildPanel and no EVT_PAINT in MyPanel;

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: virtual event func ?

Post by doublemax » Tue Sep 09, 2014 8:17 am

1. can I inhrite from wxPanel a MyPanel that is an abstract class?
You want MyPanel to be an abstract class? Yes, by adding a pure virtual method.
2. in MyPanel i have a virtual func PaintEvent() for EVT_PAINT, and in MyPnael's child MyChildPanel, I override PaintEvent()...both in MyPanel and MyChildPanel,i declare BEGIN_EVENT_TABLE, EVT_PAINT, is it OK?
I would have an event table only in the base class, e.g. pointing to a non-virtual method like OnPaint(wxPaintEvent &event). From there i'd call the a virtual method like DoPaint(wxPaintEvent &event) which you can override in the inherited classes.
3. in MyChildPanel's PaintEvent(), is calling event.Skip() equals to calling MyPanel::PaintEvent()?
No. event.Skip() only sets a flag in the event structure which is checked by the wxWidgets event handling code. But this code knows nothing about your virtual methods. You'd have to call the method in the base class yourself.
4. the efficient is important in my application, so if nothing more is done in MyChildPanel, which one is more effciant?
As all this is happens only once per redraw, i'm pretty sure it's not relevant for overall performance.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: virtual event func ?

Post by gpu » Tue Sep 09, 2014 10:25 am

You want MyPanel to be an abstract class? Yes, by adding a pure virtual method.
is the wxPanel not abstract, but its child abstrct and child's child not abstract OK?
2. & 3. so I should call the virtual func and then event.Skip() in the abstract class and then overrider the virtual func in its child, right?
and I saw the comment, but still not sure what exactly it does ?
As all this is happens only once per redraw, i'm pretty sure it's not relevant for overall performance.
but in some situation, virtual func is not fast as not virtual ones..

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: virtual event func ?

Post by doublemax » Tue Sep 09, 2014 11:03 am

2. & 3. so I should call the virtual func and then event.Skip() in the abstract class and then overrider the virtual func in its child, right?
Like already said, event.Skip() is only relevant inside the wxWidgets event hierarchy. It doesn't know about your virtual methods.
but in some situation, virtual func is not fast as not virtual ones..
Yes, it's a few clock cycles slower. But it's totally irrelevant from a performance point of view here.
Use the source, Luke!

Post Reply