Special characters in menu

27 views
Skip to first unread message

holm.h...@gmail.com

unread,
Jul 23, 2016, 3:58:11 PM7/23/16
to fltk.general


Hello,

I want to display an URL in a menu, eg.
     http://www.cnn.com

I run into trouble when I set this in a menu. 'www.cnn.com' becomes an undermenu.

How to make this work ??

Best regards
Håvard Holm

Greg Ercolano

unread,
Jul 23, 2016, 5:58:01 PM7/23/16
to fltkg...@googlegroups.com
On 07/23/16 12:58, holm.h...@gmail.com wrote:
>
>
> Hello,
>
> I want to display an URL in a menu, eg.
> http://www.cnn.com
>
> I run into trouble when I set this in a menu. 'www.cnn.com' becomes an undermenu.
>
> How to make this work ??

Try: "http:\\/\\/www.cnn.com", e.g.

Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
menu->add("File/Open");
menu->add("File/New");
menu->add("File/http:\\/\\/www.cnn.com"); // <-- this
menu->add("File/Quit", FL_CTRL+'q', Quit_CB);

Since front slashes are used to create submenus, you have to
escape each front slash with a backslash.

And since the C compiler uses backslashes as escape characters,
to specify a backslash, you have to double them up (just like
specifying DOS pathnames).

Greg Ercolano

unread,
Jul 23, 2016, 6:15:34 PM7/23/16
to fltkg...@googlegroups.com
On 07/23/16 14:57, Greg Ercolano wrote:
> Try: "http:\\/\\/www.cnn.com", e.g.
>
> Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
> menu->add("File/Open");
> menu->add("File/New");
> menu->add("File/http:\\/\\/www.cnn.com"); // <-- this
> menu->add("File/Quit", FL_CTRL+'q', Quit_CB);

BTW, another way to do it is to create a dummy item first,
then change the item's label() afterwards, e.g.

int i = menu->add("File/xxx");
((Fl_Menu_Item*)&menu->menu()[i])->label("http://www.cnn.com");

So used in context:

Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
menu->add("File/Open");
menu->add("File/New");
int i = menu->add("File/xxx"); // add 'xxx' to the File menu..
((Fl_Menu_Item*)&menu->menu()[i])->label("http://www.cnn.com"); // then change the 'xxx' item to the url
menu->add("File/Quit");

The reason this works is '/'s indicate submenus only in the Fl_Menu_::add() methods.
They have no such meaning in the menu item's label() method.


holm.h...@gmail.com

unread,
Jul 24, 2016, 5:54:50 AM7/24/16
to fltk.general


Thanks,

The

  menu->add("File/http:\\/\\/www.cnn.com");  
works like a charm

What about the "@" sign how to show this ?

Albrecht Schlosser

unread,
Jul 25, 2016, 5:59:48 AM7/25/16
to fltkg...@googlegroups.com
On 24.07.2016 11:54 holm.h...@gmail.com wrote:
> The
> menu->add("File/http:\\/\\/www.cnn.com <http://www.cnn.com>");
> works like a charm
>
> What about the "@" sign how to show this ?

Probably "@@" or (less likely) "\@", I'm not sure.

Greg Ercolano

unread,
Jul 25, 2016, 8:45:17 AM7/25/16
to fltkg...@googlegroups.com
Pretty sure @@ should do it.

Or just turn off @ symbols globally with:
http://seriss.com/people/erco/fltk/#DisableSymbols
Reply all
Reply to author
Forward
0 new messages