From add808d7c28d572090846322575f0a85a1f70ff4 Mon Sep 17 00:00:00 2001
From: Bill Spitzak The class contains a pointer to an array of structures of type
-Fl_Menu_Item. These describe the contents of the menu.
- Usually the array is a large initialization constant, but there are
-methods to build it dynamically. The class contains a pointer to an array of structures of type Fl_Menu_Item. The
+array may either be supplied directly by the user program, or it may
+be "private": a dynamically allocated array managed by the Fl_Menu_.
+
Text is a string of the form "foo/bar/baz", this example
+will result in a submenu called "foo" and one in that called
+"bar" and and entry called "baz". The text is
+copied to new memory and can be freed. The other arguments (including
+the shortcut) are copied into the menu item unchanged. If an item exists already with that name then it is replaced with
+this new one. Otherwise this new one is added to the end of the
+correct menu or submenu. The return value is the offset into the array
+that the new entry was placed at. The return value is the index into the array that the entry was put. The passed string is split at any '|' characters and then
+add(s,0,0,0,0) is done with each section. This is often useful
+if you are just using the value, and is compatable with Forms
+and other GL programs. Currently there can be only one global()menu. Setting a new
one will replace the old one. There is no way to remove the
-global() setting (including destroying the menu). Methods
@@ -68,26 +70,104 @@ methods to build it dynamically.
Fl_Menu_::Fl_Menu_(int x, int y, int w,
int h, const char *label = 0)
- Creates a new Fl_Menu_ widget using the given position, size,
-and label string. The default boxtype is FL_NO_BOX.
+
+Creates a new Fl_Menu_ widget using the given position, size,
+and label string. menu() is initialized to null.
+
virtual Fl_Menu_::~Fl_Menu_()
- Destroys the menu and its items.
-const Fl_Menu_Item* Fl_Menu_::menu() const
-
- Get or set the menu array directly. Setting it to NULL
- indicates that you want the widget to allocate its own array.
-
void Fl_Menu_::menu(const Fl_Menu_Item*)void Fl_Menu_::copy(const Fl_Menu_Item*)
- Set the menu array to a copy of the passed array. This copy will be
- deleted when the Fl_Menu_ is deleted.
+
+If the menu array is private the memory it uses is freed.
+
+const Fl_Menu_Item* Fl_Menu_::menu()
+const
+
+Returns a pointer to the array of Fl_Menu_Items. This will either be
+the value passed to menu(value) or the private copy.
+
+void Fl_Menu_::menu(const Fl_Menu_Item*)
+Set the menu array pointer directly. If the old menu is private it is
+deleted. NULL is allowed and acts the same as a zero-length
+menu. If you try to modify the array (with add(), replace(), or
+delete()) a private copy is automatically done.
+
+void Fl_Menu_::copy(const
+Fl_Menu_Item*)
+The menu is set to a private copy of the passed Fl_Menu_Item array.
+This is useful if you want to modify the flags of the menu items.
+
+void Fl_Menu_::clear()
+Same as menu(NULL), set the array pointer to null, indicating
+a zero-length menu.
+
+int Fl_Menu_::size() const
+
+This returns the number of Fl_Menu_Item structures that make up the
+menu, correctly counting submenus. This includes the "terminator"
+item at the end. To copy a menu array you need to copy
+size()*sizeof(Fl_Menu_Item) bytes. If the menu is
+NULL this returns zero (an empty menu will return 1).
+
+int Fl_Menu_::add(const char* label, const
+char* shortcut, Fl_Callback*, void *user_data=0, int flags=0)
+
+Adds a new menu item, with a title string, shortcut
+string, callback, argument to the callback, and flags. If
+the menu array was directly set with menu(x) then copy() is done to
+make a private array.
+
+int Fl_Menu_::add(const char *)
+
+void Fl_Menu_::replace(int n, const char *)
+
+
+Changes the text of item n. This is the only way to get
+slash into an add()'ed menu item. If the menu array was directly set
+with menu(x) then copy() is done to make a private array.
+
+void Fl_Menu_::remove(int n)
+
+Deletes item n from the menu. If the menu array was directly
+set with menu(x) then copy() is done to make a private array.
+
+void Fl_Menu_::shortcut(int i, int n);
+
+Changes the shortcut of item i to n.
+
+void Fl_Menu_::mode(int i, int x);
+
+Changes the flags of item i. For a list of the flags, see Fl_Menu_Item.
+
int Fl_Menu_::value() const
The value is the index into menu() of the last item chosen by
the user. It is zero initially. You can set it as an integer, or set
it with a pointer to a menu item. The set routines return non-zero if
the new value is different than the old one.
+
int Fl_Menu_::value(int)
+
const Fl_Menu_Item* mvalue() const
int Fl_Menu_::value(const Fl_Menu_Item*)const Fl_Menu_Item*
Fl_Menu_::test_shortcut()
Only call this in response to FL_SHORTCUT events. If the
@@ -102,56 +182,11 @@ have to be visible (ie the window it is in can be hidden, or it does
not have to be put in a window at all).
The second form splits the string at any | characters and then does -add(s,0,0,0,0) with each section. This is often useful if you are -just using the value, and is compatable with some Forms programs.
-Text is a string of the form "foo/bar/baz", this example will result -in a submenu called "foo" and one in that called "bar" and and entry -called "baz". The text is copied to new memory and can be freed. The -other arguments are copied into the menu item unchanged.
-If an item exists already with that name then it is replaced with -this new one. Otherwise this new one is added to the end of the -correct menu or submenu. The return value is the offset into the array -that the new entry was placed at.
-No bounds checking is done, the table must be big enough for all the -entries you plan to add. Don't forget that there is a NULL - terminator on the end, and the first time a item is added to a submenu -three items are added (the title and the NULL terminator, as -well as the actual menu item)
-The return value is the index into the array that the entry was put.
-The title and menubar arguments are used -internally by the Fl_Menu_ widget.
+internally by the Fl_Menu_Bar widget.