unibutton: still necessary?

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
User avatar
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Dec 20, 2004 10:28 am
Location: Rome, Italy (EU)

unibutton: still necessary?

Post by dejudicibus » Fri Jan 26, 2007 8:58 am

I am extensively using unibutton component by Julian Smart in my code, since version 1.6.4 of wxWidgets did not fully supported Unicode text in push buttons. I wonder if it is still necessary in 2.8.0. By the way, that code does not compile anymore with the latest version of wxWidgets. In particular, it does not work the set of methods which takes care of default behaviour of button.

Here is the explanation why managing the default behaviour in unibutton is necessary. Is it still true in 2.8.0?
"Everything you ever wanted to know about the default buttons" or "Why do we
have to do all this?"

In MSW the default button should be activated when the user presses Enter
and the current control doesn't process Enter itself somehow. This is
handled by ::DefWindowProc() (or maybe ::DefDialogProc()) using DM_SETDEFID
Another aspect of "defaultness" is that the default button has different
appearance: this is due to BS_DEFPUSHBUTTON style which is completely
separate from DM_SETDEFID stuff (!). Also note that BS_DEFPUSHBUTTON should
be unset if our parent window is not active so it should be unset whenever
we lose activation and set back when we regain it.

Final complication is that when a button is active, it should be the default
one, i.e. pressing Enter on a button always activates it and not another

We handle this by maintaining a permanent and a temporary default items in
wxControlContainer (both may be NULL). When a button becomes the current
control (i.e. gets focus) it sets itself as the temporary default which
ensures that it has the right appearance and that Enter will be redirected
to it. When the button loses focus, it unsets the temporary default and so
the default item will be the permanent default -- that is the default button
if any had been set or none otherwise, which is just what we want.

NB: all this is quite complicated by now and the worst is that normally
it shouldn't be necessary at all as for the normal Windows programs
DefWindowProc() and IsDialogMessage() take care of all this
automatically -- however in wxWindows programs this doesn't work for
nested hierarchies (i.e. a notebook inside a notebook) for unknown
reason and so we have to reproduce all this code ourselves. It would be
very nice if we could avoid doing it.
unibutton code
(22.71 KiB) Downloaded 74 times
unibutton header file
(2.99 KiB) Downloaded 79 times
unidrawtextw code
(33.47 KiB) Downloaded 50 times

User avatar
Ryan Norton
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Sat Feb 10, 2007 5:29 pm

It sounds to me like this is mostly ancient history and wxWidgets should have good unicode support - I'd try it with the unicode build and see if it meets your needs :D.
[Mostly retired moderator, still check in to clean up some stuff]

Post Reply