Deactivate menu behaviour of Fl_Choice?

63 views
Skip to first unread message

Edzard Egberts

unread,
Feb 27, 2014, 4:23:36 AM2/27/14
to fltkg...@googlegroups.com
One more time I'm running into problems, because Fl_Choice mangles my
strings. I really want to choose between strings and not to create a
menu structure, but Fl_Choice makes it impossible to choose between
paths (will be scrambled to menu like nonsense) or strings containing
special characters like '&'.

This annoying problem appears again and again and I really would like to
deactivate the menu behaviour of the choice. Is there an easy way to
achieve this (I don't even find the code which mangles), or should I
build my own choice? I know, that I can mask special characters with
'\\', but this is just another way of mangling my strings and I need
them unchanged.

MacArthur, Ian (Selex ES, UK)

unread,
Feb 27, 2014, 5:04:54 AM2/27/14
to fltkg...@googlegroups.com
I don't know about "easy", but there is a workaround of sorts...

When you want to add a menu item with slashes, but not have the slashes "magically" interpreted as submenu dividers, then you can do something like this:

- Add your new item with a dummy name that has no slashes
- find the item in the menu
- change its label, using the full string including the slashes

So it turns out that once the item exists in the menu hierarchy, changing its label *does not* then insert new submenus for slashes...

menu_bar->add("Next/test");
Fl_Menu_Item *p;
p = (Fl_Menu_Item*)menu_bar->find_item("Next/test");
if ( p ) p->label("add/entry/with/slash");

I don't know if that's any use for you?



Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

Edzard Egberts

unread,
Feb 27, 2014, 5:46:36 AM2/27/14
to fltkg...@googlegroups.com
MacArthur, Ian (Selex ES, UK) schrieb:
>> One more time I'm running into problems, because Fl_Choice mangles
>> my strings.

> I don't know about "easy", but there is a workaround of sorts...
>
> When you want to add a menu item with slashes

This time my problem is to add a string containing '&'.

> - Add your new item with a dummy name that has no slashes - find the
> item in the menu - change its label, using the full string including
> the slashes
>
> So it turns out that once the item exists in the menu hierarchy,
> changing its label *does not* then insert new submenus for
> slashes...

Now the menu continues to show the mangled string, but the choice gives
back the original string. For me this is not much more useful.

Okay, what is the hard way to deactivate this? I need to patch
Fl_Menu_.cxx? This will be the third or forth time, that I try to
achieve this - I did some workarounds before, but the basic problem
always comes back. ;o(

MacArthur, Ian (Selex ES, UK)

unread,
Feb 27, 2014, 9:03:33 AM2/27/14
to fltkg...@googlegroups.com

> Okay, what is the hard way to deactivate this? I need to patch
> Fl_Menu_.cxx? This will be the third or forth time, that I try to
> achieve this - I did some workarounds before, but the basic problem
> always comes back. ;o(

Hmm, OK...

Well, the actual removing of the & symbol (and the insertion of the underscore on the next symbol) happens in fl_expand_text() in fl_draw.cxx.

That, in turn, depends on the state of the global var fl_draw_shortcut that gets set and cleared by *many* widgets just before they do their drawing...

For example, Fl_Widget internal flags_ variable (not readily accessible) has a SHORTCUT_LABEL bit that, if set, will cause Fl_Widget to set fl_draw_shortcut non-zero before calling the label draw method... (see Fl_Widget::draw_label() in fl_labeltype.cxx for example.)


So, if you don't mind hacking away at your fltk lib, there's a few places you could attack this.

Modifying fl_expand_text() might be one way, or setting about Fl_Widget to allow for suppression of the SHORTCUT_LABEL and/or fl_draw_shortcut flags might do the trick.

Or, some other thing...

One annoying feature of this is that Fl_Choice sets fl_draw_shortcut non-zero for its labels whether SHORTCUT_LABEL is set or not, so simply defeating SHORTCUT_LABEL may not be enough... I mention this because I had a subclass of Fl_Choice that cleared SHORTCUT_LABEL, but the draw method still went ahead and set fl_draw_shortcut non-zero anyway.


Anyway; as a quick hack, always setting fl_draw_shortcut = 0; at the start of fl_expand_text() will likely do the trick... I suppose you could add a method to allow that to be done in a more controlled fashion - though it sounds like you'd be happy if it was always off!

Edzard Egberts

unread,
Feb 27, 2014, 9:33:16 AM2/27/14
to fltkg...@googlegroups.com
MacArthur, Ian (Selex ES, UK) schrieb:
>
>> Okay, what is the hard way to deactivate this? I need to patch
>> Fl_Menu_.cxx? This will be the third or forth time, that I try to
>> achieve this - I did some workarounds before, but the basic
>> problem always comes back. ;o(
>
> Hmm, OK...
>
> Well, the actual removing of the & symbol (and the insertion of the
> underscore on the next symbol) happens in fl_expand_text() in
> fl_draw.cxx.

I looked for it in Fl_Menu_add and found it very complicated regarding
to signs '/', '\' and '_' - no way to just deactivate the "magic". :o(

> That, in turn, depends on the state of the global var
> fl_draw_shortcut that gets set and cleared by *many* widgets just
> before they do their drawing..

Some times ago I implemented a colour chooser widget based on a browser
(it shows lines with different background colours) and I will reuse it
for making a non mangling choice - this seems to be the most easy
solution...
Reply all
Reply to author
Forward
0 new messages