Custom control OnPaint when control is disabled 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
vikram731
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Apr 08, 2014 4:54 am

Custom control OnPaint when control is disabled

Post by vikram731 »

Hi,
I have a custom control derived from wxControl. I am overriding the EVT_PAINT and doing all the drawing there, How should I handle the Disabled state of the control.
Do I need to check if control is disabled inside the OnPaint function and then change all the colors accordingly.
Is there no way of easily handling this?

Thanks,
Vikram
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: Custom control OnPaint when control is disabled

Post by tierra »

wxWindow::Enable() is a virtual method, and calling Disable() just calls Enable(false). So I believe that if you override this method while still calling the parent method, you have the ability to tie into that, and trigger a repaint with your control disabled if you need to.
vikram731
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Apr 08, 2014 4:54 am

Re: Custom control OnPaint when control is disabled

Post by vikram731 »

Thanks tierra. Seems to be a good suggestion. I will try this.

Just a doubt: If I call Enable() function on a window, does it call Enable() recursively to all of its children?
I am guessing the answer should be yes but it would be great if you can confirm it.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: Custom control OnPaint when control is disabled

Post by tierra »

vikram731 wrote:Just a doubt: If I call Enable() function on a window, does it call Enable() recursively to all of its children?
I am guessing the answer should be yes but it would be great if you can confirm it.
wxMSW and wxOSX/Carbon are the only two platforms I'm not entirely sure this is true. They have some automatic, native implementation for disabling their child windows where wxWindow::Enable() might not be called directly. wxWidgets recursively disables child windows itself on all other platforms.

In any case, this should be rather simple to test out in just about any sample that derives a new control of any kind.
Post Reply