1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// Menubar test program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2020-01-16 17:59:00 +03:00
|
|
|
// Copyright 1998-2020 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl.H>
|
2016-03-26 14:38:38 +03:00
|
|
|
#ifdef __APPLE__
|
2018-02-01 00:17:17 +03:00
|
|
|
#include <FL/platform.H> // for Fl_Mac_App_Menu
|
2016-03-26 14:38:38 +03:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Box.H>
|
2009-04-21 13:09:37 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
2012-01-11 20:16:31 +04:00
|
|
|
#include <FL/Fl_Sys_Menu_Bar.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Toggle_Button.H>
|
|
|
|
#include <FL/Fl_Menu_Button.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
2018-03-31 20:17:37 +03:00
|
|
|
#include <FL/Fl_Value_Slider.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <FL/fl_draw.H>
|
2017-10-17 03:28:56 +03:00
|
|
|
#include <FL/Fl_Simple_Terminal.H>
|
2019-02-24 13:23:38 +03:00
|
|
|
#include <FL/fl_ask.H>
|
2020-07-22 06:15:41 +03:00
|
|
|
#include <FL/fl_string.h>
|
2017-10-17 03:28:56 +03:00
|
|
|
|
|
|
|
#define TERMINAL_HEIGHT 120
|
|
|
|
|
|
|
|
// Globals
|
|
|
|
Fl_Simple_Terminal *G_tty = 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-11-28 16:46:34 +03:00
|
|
|
void window_cb(Fl_Widget* w, void*) {
|
2020-07-01 19:03:10 +03:00
|
|
|
puts("window callback called"); // end of program, so stdout instead of G_tty
|
2009-04-21 13:09:37 +04:00
|
|
|
((Fl_Double_Window *)w)->hide();
|
2001-11-28 16:46:34 +03:00
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void test_cb(Fl_Widget* w, void*) {
|
|
|
|
Fl_Menu_* mw = (Fl_Menu_*)w;
|
|
|
|
const Fl_Menu_Item* m = mw->mvalue();
|
|
|
|
if (!m)
|
2017-10-17 03:28:56 +03:00
|
|
|
G_tty->printf("NULL\n");
|
1998-10-06 22:21:25 +04:00
|
|
|
else if (m->shortcut())
|
2017-10-17 03:28:56 +03:00
|
|
|
G_tty->printf("%s - %s\n", m->label(), fl_shortcut_label(m->shortcut()));
|
1998-10-06 22:21:25 +04:00
|
|
|
else
|
2017-10-17 03:28:56 +03:00
|
|
|
G_tty->printf("%s\n", m->label());
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void quit_cb(Fl_Widget*, void*) {exit(0);}
|
|
|
|
|
|
|
|
Fl_Menu_Item hugemenu[100];
|
|
|
|
|
|
|
|
Fl_Menu_Item menutable[] = {
|
|
|
|
{"foo",0,0,0,FL_MENU_INACTIVE},
|
|
|
|
{"&File",0,0,0,FL_SUBMENU},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&Open", FL_ALT+'o', 0, 0, FL_MENU_INACTIVE},
|
|
|
|
{"&Close", 0, 0},
|
|
|
|
{"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"shortcut",'a'},
|
|
|
|
{"shortcut",FL_SHIFT+'a'},
|
|
|
|
{"shortcut",FL_CTRL+'a'},
|
|
|
|
{"shortcut",FL_CTRL+FL_SHIFT+'a'},
|
|
|
|
{"shortcut",FL_ALT+'a'},
|
|
|
|
{"shortcut",FL_ALT+FL_SHIFT+'a'},
|
|
|
|
{"shortcut",FL_ALT+FL_CTRL+'a'},
|
|
|
|
{"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+'a', 0,0, FL_MENU_DIVIDER},
|
2000-01-16 07:30:39 +03:00
|
|
|
{"shortcut",'\r'/*FL_Enter*/},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"shortcut",FL_CTRL+FL_Enter, 0,0, FL_MENU_DIVIDER},
|
|
|
|
{"shortcut",FL_F+1},
|
|
|
|
{"shortcut",FL_SHIFT+FL_F+1},
|
|
|
|
{"shortcut",FL_CTRL+FL_F+1},
|
|
|
|
{"shortcut",FL_SHIFT+FL_CTRL+FL_F+1},
|
|
|
|
{"shortcut",FL_ALT+FL_F+1},
|
|
|
|
{"shortcut",FL_ALT+FL_SHIFT+FL_F+1},
|
|
|
|
{"shortcut",FL_ALT+FL_CTRL+FL_F+1},
|
|
|
|
{"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+FL_F+1, 0,0, FL_MENU_DIVIDER},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&Submenus", FL_ALT+'S', 0, (void*)"Submenu1", FL_SUBMENU},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"A very long menu item"},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&submenu",FL_CTRL+'S', 0, (void*)"submenu2", FL_SUBMENU},
|
|
|
|
{"item 1"},
|
|
|
|
{"item 2"},
|
|
|
|
{"item 3"},
|
|
|
|
{"item 4"},
|
|
|
|
{0},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"after submenu"},
|
|
|
|
{0},
|
|
|
|
{0},
|
2000-07-11 09:36:39 +04:00
|
|
|
{"&Edit",FL_F+2,0,0,FL_SUBMENU},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Undo", FL_ALT+'z', 0},
|
|
|
|
{"Redo", FL_ALT+'r', 0, 0, FL_MENU_DIVIDER},
|
|
|
|
{"Cut", FL_ALT+'x', 0},
|
|
|
|
{"Copy", FL_ALT+'c', 0},
|
|
|
|
{"Paste", FL_ALT+'v', 0},
|
|
|
|
{"Inactive", FL_ALT+'d', 0, 0, FL_MENU_INACTIVE},
|
|
|
|
{"Clear", 0, 0, 0, FL_MENU_DIVIDER},
|
|
|
|
{"Invisible", FL_ALT+'e', 0, 0, FL_MENU_INVISIBLE},
|
|
|
|
{"Preferences", 0, 0},
|
|
|
|
{"Size", 0, 0},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
2000-07-11 09:36:39 +04:00
|
|
|
{"&Checkbox",FL_F+3,0,0,FL_SUBMENU},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&Alpha", FL_F+2, 0, (void *)1, FL_MENU_TOGGLE},
|
|
|
|
{"&Beta", 0, 0, (void *)2, FL_MENU_TOGGLE},
|
|
|
|
{"&Gamma", 0, 0, (void *)3, FL_MENU_TOGGLE},
|
|
|
|
{"&Delta", 0, 0, (void *)4, FL_MENU_TOGGLE|FL_MENU_VALUE},
|
|
|
|
{"&Epsilon",0, 0, (void *)5, FL_MENU_TOGGLE},
|
|
|
|
{"&Pi", 0, 0, (void *)6, FL_MENU_TOGGLE},
|
|
|
|
{"&Mu", 0, 0, (void *)7, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
|
|
|
|
{"Red", 0, 0, (void *)1, FL_MENU_TOGGLE, 0, 0, 0, 1},
|
|
|
|
{"Black", 0, 0, (void *)1, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
|
|
|
|
{"00", 0, 0, (void *)1, FL_MENU_TOGGLE},
|
|
|
|
{"000", 0, 0, (void *)1, FL_MENU_TOGGLE},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
|
|
|
{"&Radio",0,0,0,FL_SUBMENU},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&Alpha", 0, 0, (void *)1, FL_MENU_RADIO},
|
|
|
|
{"&Beta", 0, 0, (void *)2, FL_MENU_RADIO},
|
|
|
|
{"&Gamma", 0, 0, (void *)3, FL_MENU_RADIO},
|
|
|
|
{"&Delta", 0, 0, (void *)4, FL_MENU_RADIO|FL_MENU_VALUE},
|
|
|
|
{"&Epsilon",0, 0, (void *)5, FL_MENU_RADIO},
|
|
|
|
{"&Pi", 0, 0, (void *)6, FL_MENU_RADIO},
|
|
|
|
{"&Mu", 0, 0, (void *)7, FL_MENU_RADIO|FL_MENU_DIVIDER},
|
|
|
|
{"Red", 0, 0, (void *)1, FL_MENU_RADIO},
|
|
|
|
{"Black", 0, 0, (void *)1, FL_MENU_RADIO|FL_MENU_DIVIDER},
|
|
|
|
{"00", 0, 0, (void *)1, FL_MENU_RADIO},
|
|
|
|
{"000", 0, 0, (void *)1, FL_MENU_RADIO},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
|
|
|
{"&Font",0,0,0,FL_SUBMENU /*, 0, FL_BOLD, 20*/},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Normal", 0, 0, 0, 0, 0, 0, 14},
|
|
|
|
{"Bold", 0, 0, 0, 0, 0, FL_BOLD, 14},
|
|
|
|
{"Italic", 0, 0, 0, 0, 0, FL_ITALIC, 14},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"BoldItalic",0,0,0, 0, 0, FL_BOLD+FL_ITALIC, 14},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Small", 0, 0, 0, 0, 0, FL_BOLD+FL_ITALIC, 10},
|
|
|
|
{"Emboss", 0, 0, 0, 0, (uchar)FL_EMBOSSED_LABEL},
|
|
|
|
{"Engrave", 0, 0, 0, 0, (uchar)FL_ENGRAVED_LABEL},
|
|
|
|
{"Shadow", 0, 0, 0, 0, (uchar)FL_SHADOW_LABEL},
|
|
|
|
{"@->", 0, 0, 0, 0, (uchar)FL_SYMBOL_LABEL},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
2009-09-18 00:40:02 +04:00
|
|
|
{"&International",0,0,0,FL_SUBMENU},
|
|
|
|
{"Sharp Ess",0x0000df},
|
|
|
|
{"A Umlaut",0x0000c4},
|
|
|
|
{"a Umlaut",0x0000e4},
|
2009-09-18 02:12:24 +04:00
|
|
|
{"Euro currency",FL_COMMAND+0x0020ac},
|
|
|
|
{"the &\xc3\xbc Umlaut"}, // ü
|
|
|
|
{"the capital &\xc3\x9c"}, // Ü
|
|
|
|
{"convert \xc2\xa5 to &\xc2\xa3"}, // Yen to GBP
|
|
|
|
{"convert \xc2\xa5 to &\xe2\x82\xac"}, // Yen to Euro
|
|
|
|
{"Hangul character Sios &\xe3\x85\x85"},
|
|
|
|
{"Hangul character Cieuc", 0x003148},
|
2009-09-18 00:40:02 +04:00
|
|
|
{0},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"E&mpty",0,0,0,FL_SUBMENU},
|
|
|
|
{0},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"&Inactive", 0, 0, 0, FL_MENU_INACTIVE|FL_SUBMENU},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"A very long menu item"},
|
|
|
|
{"A very long menu item"},
|
|
|
|
{0},
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Invisible",0, 0, 0, FL_MENU_INVISIBLE|FL_SUBMENU},
|
1998-10-06 22:21:25 +04:00
|
|
|
{"A very long menu item"},
|
|
|
|
{"A very long menu item"},
|
|
|
|
{0},
|
|
|
|
{"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER},
|
2000-07-30 04:31:44 +04:00
|
|
|
{"button",FL_F+4, 0, 0, FL_MENU_TOGGLE},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Menu_Item pulldown[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Red", FL_ALT+'r'},
|
|
|
|
{"Green", FL_ALT+'g'},
|
|
|
|
{"Blue", FL_ALT+'b'},
|
|
|
|
{"Strange", FL_ALT+'s', 0, 0, FL_MENU_INACTIVE},
|
|
|
|
{"&Charm", FL_ALT+'c'},
|
|
|
|
{"Truth", FL_ALT+'t'},
|
|
|
|
{"Beauty", FL_ALT+'b'},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2012-01-11 20:16:31 +04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
Fl_Menu_Item menu_location[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Fl_Menu_Bar", 0, 0, 0, FL_MENU_VALUE},
|
|
|
|
{"Fl_Sys_Menu_Bar", },
|
2012-01-11 20:16:31 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Sys_Menu_Bar* smenubar;
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
void menu_location_cb(Fl_Widget* w, void* data)
|
2012-01-11 20:16:31 +04:00
|
|
|
{
|
|
|
|
Fl_Menu_Bar *menubar = (Fl_Menu_Bar*)data;
|
|
|
|
if (((Fl_Choice*)w)->value() == 1) { // switch to system menu bar
|
|
|
|
menubar->hide();
|
|
|
|
const Fl_Menu_Item *menu = menubar->menu();
|
2020-07-01 19:03:10 +03:00
|
|
|
smenubar = new Fl_Sys_Menu_Bar(0,0,0,30);
|
2012-01-11 20:16:31 +04:00
|
|
|
smenubar->menu(menu);
|
|
|
|
smenubar->callback(test_cb);
|
|
|
|
}
|
|
|
|
else { // switch to window menu bar
|
2017-12-18 18:19:15 +03:00
|
|
|
menubar->menu(smenubar->menu());
|
2012-01-11 20:16:31 +04:00
|
|
|
smenubar->clear();
|
|
|
|
delete smenubar;
|
|
|
|
menubar->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
2018-03-31 20:17:37 +03:00
|
|
|
void menu_linespacing_cb(Fl_Widget* w, void*) {
|
|
|
|
Fl_Value_Slider *fvs = (Fl_Value_Slider*)w;
|
|
|
|
int val = (int)fvs->value();
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl::menu_linespacing(val); // takes effect when someone opens a new menu..
|
2018-03-31 20:17:37 +03:00
|
|
|
}
|
|
|
|
|
2009-09-18 00:40:02 +04:00
|
|
|
#define WIDTH 700
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
Fl_Menu_* menus[4];
|
|
|
|
|
2019-02-24 13:23:38 +03:00
|
|
|
void about_cb(Fl_Widget*, void*) {
|
|
|
|
fl_message("The menubar test app.");
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int main(int argc, char **argv) {
|
2000-04-11 12:11:56 +04:00
|
|
|
//Fl::set_color(Fl_Color(15),0,0,128);
|
1998-10-06 22:21:25 +04:00
|
|
|
for (int i=0; i<99; i++) {
|
|
|
|
char buf[100];
|
|
|
|
sprintf(buf,"item %d",i);
|
2020-07-22 06:15:41 +03:00
|
|
|
hugemenu[i].text = fl_strdup(buf);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2017-10-17 03:28:56 +03:00
|
|
|
Fl_Double_Window window(WIDTH,400+TERMINAL_HEIGHT);
|
|
|
|
G_tty = new Fl_Simple_Terminal(0,400,WIDTH,TERMINAL_HEIGHT);
|
|
|
|
|
2001-11-28 16:46:34 +03:00
|
|
|
window.callback(window_cb);
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Menu_Bar menubar(0,0,WIDTH,30); menubar.menu(menutable);
|
|
|
|
menubar.callback(test_cb);
|
|
|
|
menus[0] = &menubar;
|
|
|
|
Fl_Menu_Button mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown);
|
2006-06-14 14:48:36 +04:00
|
|
|
mb1.tooltip("this is a menu button");
|
1998-10-06 22:21:25 +04:00
|
|
|
mb1.callback(test_cb);
|
|
|
|
menus[1] = &mb1;
|
|
|
|
Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown);
|
2006-06-14 14:48:36 +04:00
|
|
|
ch.tooltip("this is a choice menu");
|
1998-10-06 22:21:25 +04:00
|
|
|
ch.callback(test_cb);
|
|
|
|
menus[2] = &ch;
|
|
|
|
Fl_Menu_Button mb(0,0,WIDTH,400,"&popup");
|
|
|
|
mb.type(Fl_Menu_Button::POPUP3);
|
2002-09-02 02:39:33 +04:00
|
|
|
mb.box(FL_NO_BOX);
|
1998-10-06 22:21:25 +04:00
|
|
|
mb.menu(menutable);
|
2000-01-16 07:30:39 +03:00
|
|
|
mb.remove(1); // delete the "File" submenu
|
1998-10-06 22:21:25 +04:00
|
|
|
mb.callback(test_cb);
|
|
|
|
menus[3] = &mb;
|
|
|
|
Fl_Box b(200,200,200,100,"Press right button\nfor a pop-up menu");
|
|
|
|
window.resizable(&mb);
|
2003-01-15 00:30:55 +03:00
|
|
|
window.size_range(300,400,0,400);
|
2012-01-11 20:16:31 +04:00
|
|
|
#ifdef __APPLE__
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Choice ch2(500,100,150,25,"Use:");
|
2012-01-11 20:16:31 +04:00
|
|
|
ch2.menu(menu_location);
|
|
|
|
ch2.callback(menu_location_cb, &menubar);
|
2017-12-18 18:19:15 +03:00
|
|
|
ch2.value(1);
|
|
|
|
menu_location_cb(&ch2, &menubar);
|
2012-01-11 20:16:31 +04:00
|
|
|
#endif
|
2018-03-31 20:17:37 +03:00
|
|
|
|
|
|
|
Fl_Value_Slider menu_linespacing_slider(500,150,150,20,"Fl::menu_linespacing()");
|
|
|
|
menu_linespacing_slider.tooltip("Changes the line spacing between all menu items");
|
|
|
|
menu_linespacing_slider.type(1);
|
|
|
|
//menu_linespacing_slider.labelsize(14);
|
|
|
|
menu_linespacing_slider.value(Fl::menu_linespacing());
|
|
|
|
menu_linespacing_slider.color((Fl_Color)46);
|
|
|
|
menu_linespacing_slider.selection_color((Fl_Color)1);
|
|
|
|
//menu_linespacing_slider.textsize(10);
|
|
|
|
menu_linespacing_slider.align(Fl_Align(FL_ALIGN_LEFT));
|
|
|
|
menu_linespacing_slider.range(0.1, 50.0);
|
|
|
|
menu_linespacing_slider.step(1.0);
|
|
|
|
menu_linespacing_slider.callback(menu_linespacing_cb);
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
window.end();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2019-02-24 13:23:38 +03:00
|
|
|
Fl_Sys_Menu_Bar::about(about_cb, NULL);
|
2015-11-26 19:34:58 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
Fl_Menu_Item custom[] = {
|
2020-07-01 19:03:10 +03:00
|
|
|
{"Preferences…", 0, test_cb, NULL, FL_MENU_DIVIDER},
|
|
|
|
{"Radio1", 0, test_cb, NULL, FL_MENU_RADIO | FL_MENU_VALUE},
|
|
|
|
{"Radio2", 0, test_cb, NULL, FL_MENU_RADIO},
|
2015-11-26 19:34:58 +03:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
Fl_Mac_App_Menu::custom_application_menu_items(custom);
|
2017-12-18 18:19:15 +03:00
|
|
|
//Fl_Sys_Menu_Bar::window_menu_style(Fl_Sys_Menu_Bar::no_window_menu);
|
2015-11-26 19:34:58 +03:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
window.show(argc, argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|