FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_Menu_.H
1//
2// Menu base class header file for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 1998-2024 by Bill Spitzak and others.
5//
6// This library is free software. Distribution and use rights are outlined in
7// the file "COPYING" which should have been included with this file. If this
8// file is missing or damaged, see the license at:
9//
10// https://www.fltk.org/COPYING.php
11//
12// Please see the following page on how to report bugs and issues:
13//
14// https://www.fltk.org/bugs.php
15//
16
17/* \file
18 Fl_Menu_ widget . */
19
20#ifndef Fl_Menu__H
21#define Fl_Menu__H
22
23#ifndef Fl_Widget_H
24#include "Fl_Widget.H"
25#endif
26#include "Fl_Menu_Item.H"
27
53class FL_EXPORT Fl_Menu_ : public Fl_Widget {
54
55 Fl_Menu_Item *menu_;
56 const Fl_Menu_Item *value_;
57 const Fl_Menu_Item *prev_value_;
58
59protected:
60
61 uchar alloc; // flag indicates if menu_ is a dynamic copy (=1) or not (=0)
62 uchar down_box_;
63 Fl_Boxtype menu_box_;
64 Fl_Font textfont_;
65 Fl_Fontsize textsize_;
66 Fl_Color textcolor_;
67
68 int item_pathname_(char *name, int namelen, const Fl_Menu_Item *finditem,
69 const Fl_Menu_Item *menu=0) const;
70public:
71 Fl_Menu_(int,int,int,int,const char * =0);
72 ~Fl_Menu_();
73
74 int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
75 const Fl_Menu_Item* picked(const Fl_Menu_Item*);
76 const Fl_Menu_Item* find_item(const char *name);
77 const Fl_Menu_Item* find_item(Fl_Callback*);
78 const Fl_Menu_Item* find_item_with_user_data(void*);
79 const Fl_Menu_Item* find_item_with_argument(long);
80 int find_index(const char *name) const;
81 int find_index(const Fl_Menu_Item *item) const;
82 int find_index(Fl_Callback *cb) const;
83
95 const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
96 void global();
97
133 const Fl_Menu_Item *menu() const {return menu_;}
134 const Fl_Menu_Item *menu_end(); // in src/Fl_Menu_add.cxx
135 void menu(const Fl_Menu_Item *m);
136 void copy(const Fl_Menu_Item *m, void* user_data = 0);
137 int insert(int index, const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
138 int add(const char*, int shortcut, Fl_Callback*, void* = 0, int = 0); // see src/Fl_Menu_add.cxx
140 int add(const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
141 return add(a,fl_old_shortcut(b),c,d,e);
142 }
144 int insert(int index, const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
145 return insert(index,a,fl_old_shortcut(b),c,d,e);
146 }
147 int add(const char *);
148 int size() const ;
149 void size(int W, int H) { Fl_Widget::size(W, H); }
150 void clear();
151 int clear_submenu(int index);
152 void replace(int,const char *);
153 void remove(int);
155 void shortcut(int i, int s) {menu_[i].shortcut(s);}
157 void mode(int i,int fl) {menu_[i].flags = fl;}
159 int mode(int i) const {return menu_[i].flags;}
160
162 const Fl_Menu_Item *mvalue() const {return value_;}
163
167 const Fl_Menu_Item *prev_mvalue() const {return prev_value_;}
168 // Return the index into the menu() of the last item chosen by the user or -1.
169 int value() const;
170 // Set the internal value_ of the menu to the given Fl_Menu_Item.
171 int value(const Fl_Menu_Item*);
205 int value(int i) {
206 if (!menu_ || i < 0 || i >= size())
207 return 0;
208 return value(menu_ + i);
209 }
210
212 const char *text() const {return value_ ? value_->text : 0;}
214 const char *text(int i) const {return menu_[i].text;}
215
217 Fl_Font textfont() const {return textfont_;}
219 void textfont(Fl_Font c) {textfont_=c;}
221 Fl_Fontsize textsize() const {return textsize_;}
223 void textsize(Fl_Fontsize c) {textsize_=c;}
225 Fl_Color textcolor() const {return textcolor_;}
227 void textcolor(Fl_Color c) {textcolor_=c;}
228
233 Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
235 void down_box(Fl_Boxtype b) {down_box_ = b;}
236
240 Fl_Boxtype menu_box() const { return menu_box_; }
245 void menu_box(Fl_Boxtype b) { menu_box_ = b; }
246
250 void down_color(unsigned c) {selection_color(c);}
251 void setonly(Fl_Menu_Item* item);
252};
253
254#endif
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1046
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1103
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1075
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:627
Fl_Widget and Fl_Label classes.
void Fl_Callback(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition Fl_Widget.H:33
Base class of all widgets that have a menu in FLTK.
Definition Fl_Menu_.H:53
Fl_Color down_color() const
For back compatibility, same as selection_color()
Definition Fl_Menu_.H:248
void mode(int i, int fl)
Set the flags of item i.
Definition Fl_Menu_.H:157
void down_color(unsigned c)
For back compatibility, same as selection_color()
Definition Fl_Menu_.H:250
const Fl_Menu_Item * prev_mvalue() const
Return a pointer to the menu item that was picked before the current one was picked.
Definition Fl_Menu_.H:167
void menu_box(Fl_Boxtype b)
Set the box type for the menu popup windows.
Definition Fl_Menu_.H:245
Fl_Font textfont() const
Gets the current font of menu item labels.
Definition Fl_Menu_.H:217
void textsize(Fl_Fontsize c)
Sets the font size of menu item labels.
Definition Fl_Menu_.H:223
void down_box(Fl_Boxtype b)
Sets the box type used to surround the currently-selected items in the menus.
Definition Fl_Menu_.H:235
int insert(int index, const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
See int Fl_Menu_::insert(const char* label, int shortcut, Fl_Callback*, void *user_data=0,...
Definition Fl_Menu_.H:144
int value(int i)
Set the value of the menu to index i.
Definition Fl_Menu_.H:205
const char * text(int i) const
Returns the title of item i.
Definition Fl_Menu_.H:214
Fl_Fontsize textsize() const
Gets the font size of menu item labels.
Definition Fl_Menu_.H:221
const Fl_Menu_Item * menu() const
Returns a pointer to the array of Fl_Menu_Items.
Definition Fl_Menu_.H:133
void textcolor(Fl_Color c)
Sets the current color of menu item labels.
Definition Fl_Menu_.H:227
int add(const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
See int Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0,...
Definition Fl_Menu_.H:140
void shortcut(int i, int s)
Change the shortcut of item i to s.
Definition Fl_Menu_.H:155
const Fl_Menu_Item * mvalue() const
Return a pointer to the last menu item that was picked.
Definition Fl_Menu_.H:162
Fl_Boxtype menu_box() const
Get the box type for the menu popup windows.
Definition Fl_Menu_.H:240
const char * text() const
Returns the title of the last item chosen.
Definition Fl_Menu_.H:212
int mode(int i) const
Get the flags of item i.
Definition Fl_Menu_.H:159
Fl_Boxtype down_box() const
This box type is used to surround the currently-selected items in the menus.
Definition Fl_Menu_.H:233
const Fl_Menu_Item * test_shortcut()
Returns the menu item with the entered shortcut (key value).
Definition Fl_Menu_.H:95
void textfont(Fl_Font c)
Sets the current font of menu item labels.
Definition Fl_Menu_.H:219
Fl_Color textcolor() const
Get the current color of menu item labels.
Definition Fl_Menu_.H:225
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:104
Fl_Color selection_color() const
Gets the selection color.
Definition Fl_Widget.H:465
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:410
unsigned char uchar
unsigned char
Definition fl_types.h:30
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:115
const char * text
menu item text, returned by label()
Definition Fl_Menu_Item.H:116