wxControl, wxPanel, wxFrame or wxWindow?

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

wxControl, wxPanel, wxFrame or wxWindow?

Post by MoonKid » Fri Apr 03, 2015 2:03 pm

When I create my own control (e.g. for entering data) I derived it from wxControl. I do it just because of the matching words "control". ;)

In the past (with wxWidgets 2.4. and C++) I sometimes used a wxPanel for that - don't know why.

Thinking about it bring me to the point, that I don't know nothing about the difference between this classes. What is the difference? When should I use which one?

btw: I am using wxWidgets in Python3 (wxPhoenix, the next generation wxPhyton) but I think this doesn't matter for this question.

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

Re: wxControl, wxPanel, wxFrame or wxWindow?

Post by tierra » Fri Apr 03, 2015 10:48 pm

wxControl provides API for handling (and sometimes automatically handling) clipboard operations, and keyboard mnemonics. As a general rule of thumb, think about how data could be copied from the clipboard into your "control". If there's only one single location for it to logically go, and there's also only one possible low-level window to set focus to given you only have one single keyboard mnemonic to assign, then it's pretty likely that you want to derive from wxControl. However, you still always want to contain any and all wxControl-derived windows inside of a wxPanel since wxPanel provides tab-index keyboard navigation functionality.

On the other hand, if your "control" is actually the logical grouping of more than one unique control (for example: a button, checkbox, and a text control, or a couple listboxes like the new wxAddRemoveCtrl) that can each be assigned a unique keyboard mnemonic for setting focus, that's when you likely should use a wxPanel. It's technically not a control itself, just a set of rules you're enforcing around a combination of controls, but lots of developers (confusingly) still call it a "control". Conveniently, when you use that "control", it's already contained in a panel, so you usually don't need to worry about adding it to another one if it ends up in it's own top level window.

Post Reply