source: NonGTP/FLTK/include/fltk/Menu.h @ 773

Revision 773, 5.2 KB checked in by gumbau, 19 years ago (diff)

FLTK imported to SVN repository to be linked agains the GeoTool? application

Line 
1// "$Id: Menu.h 4319 2005-05-08 19:18:50Z spitzak $"
2//
3// Copyright 1998-2005 by Bill Spitzak and others.
4//
5// This library is free software; you can redistribute it and/or
6// modify it under the terms of the GNU Library General Public
7// License as published by the Free Software Foundation; either
8// version 2 of the License, or (at your option) any later version.
9//
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13// Library General Public License for more details.
14//
15// You should have received a copy of the GNU Library General Public
16// License along with this library; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18// USA.
19//
20// Please report all bugs and problems to "fltk-bugs@fltk.org".
21
22#ifndef fltk_Menu_h
23#define fltk_Menu_h
24
25#include "Group.h"
26
27namespace fltk {
28
29class FL_API Menu;
30
31class FL_API List {
32public:
33  virtual int children(const Menu*, const int* indexes, int level);
34  virtual Widget* child(const Menu*, const int* indexes, int level);
35  virtual void flags_changed(const Menu*, Widget*);
36  //virtual ~List() {} // not done as it slows program exit
37};
38
39enum { // Special flag values for add(), you can also use Flags.h values
40  // These match values from Fl_Menu_Item in fltk 1.0:
41  MENU_TOGGLE = 2,
42  MENU_RADIO = 8,
43  SUBMENU = 0x40,
44  MENU_DIVIDER = 0x80
45};
46
47class FL_API Menu : public Group {
48
49public:
50
51  Menu(int,int,int,int, const char* l=0);
52  List* list() const {return list_;}
53  void list(List* l) {list_ = l;}
54  void layout();
55
56  static NamedStyle* default_style;
57
58  int children(const int* indexes, int level) const ;
59  int children(int index) const;
60  int children() const ;
61  Widget* child(const int* indexes, int level) const ;
62  Widget* child(int index) const ;
63
64  Widget* item() const {return item_;}
65  Widget* item(Widget* v) {return item_ = v;}
66
67  bool set_item(const int* indexes, int level);
68  Widget* get_item();
69  int value() const {return Group::focus_index();}
70  bool value(int v);
71  int  size() const {return children();}
72
73  void layout_in(Widget*,const int* indexes, int level) const;
74  void draw_in(Widget*,const int* indexes, int level, int, int) const;
75  int find_selected(Widget*,const int* indexes, int level, int, int) const;
76  Rectangle get_location(Widget*,const int* indexes, int level, int) const;
77
78  int popup(const Rectangle&, const char* title=0,bool menubar=false);
79  int handle_shortcut();
80  static void default_callback(Widget*, void*);
81  void execute(Widget*);
82  void global();
83
84  Widget* find(const char*) const;
85  void remove(const char* l) { delete find(l); }
86  Widget* add(const char*, unsigned shortcut, Callback*, void* = 0, int = 0);
87  Widget* replace(const char*, unsigned shortcut, Callback*, void* = 0, int = 0);
88  Widget* insert(int n, const char*, unsigned shortcut, Callback*, void* = 0, int = 0);
89  Widget* add(const char*, void* = 0);
90  Widget* add_many(const char*);
91  Widget* replace(const char*, void* = 0);
92  Widget* insert(int n, const char*, void* = 0);
93
94  // Undo the overrides of stuff from Group:
95  void add(Widget& o) {Group::add(o);}
96  void add(Widget* o) {add(*o);}
97  void insert(Widget& o, int n) {Group::insert(o, n);}
98  void replace(int index, Widget& o) {Group::replace(index, o);}
99  void replace(Widget& old, Widget& o) {Group::replace(old,o);}
100  void remove(int index) {Group::remove(index);}
101  void remove(Widget& o) {Group::remove(o);}
102  void remove(Widget* o) {Group::remove(o);}
103
104#ifdef Fl_Menu_Item_h
105  // Commented-out methods cannot be emulated.
106//const Fl_Menu_Item* test_shortcut();
107//Fl_Menu_Item* menu() const;
108  void copy(const Fl_Menu_Item* m, void* data = 0) {clear(); m->add_to(this,data);}
109  void menu(const Fl_Menu_Item* m) {copy(m,0);}
110  void replace(int n, const char* s) { child(n)->label(s); }
111  void replace(const char* l, const char* s) { find(l)->label(s); }
112  void shortcut(const char* l, unsigned s) { find(l)->shortcut(s); }
113  void shortcut(unsigned s) {Widget::shortcut(s);}
114  unsigned shortcut() const {return Widget::shortcut();}
115  void shortcut(int i, unsigned s) { child(i)->shortcut(s); }
116//int index(Fl_Menu_Item* m) const { return m - menu_; }
117//int index(const char* label) const;
118//void replace(Fl_Menu_Item* m, const char* s) { replace(index(m), s); }
119//void remove(Fl_Menu_Item* m) { remove(index(m)); }
120//void shortcut(Fl_Menu_Item* m, unsigned s) {shortcut(index(m), s);}
121//void mode(int i,int x);
122//void mode(Fl_Menu_Item* m, int x) {mode(index(m), x);}
123//void mode(const char* l, int x) {mode(index(l), x);}
124  unsigned mode(int i) const {return child(i)->flags() >> 8;}
125//unsigned mode(Fl_Menu_Item* m) const {return mode(index(m));}
126  unsigned mode(const char* l) const {return find(l)->flags() >> 8;}
127
128  // in fltk 1.0 these returned/took an Fl_Menu_Item*:
129  Widget* mvalue() {return item();}
130//void value(Widget* o) {set_item(o);}
131
132  const char *text(int i) const {return i >= 0 ? child(i)->label() : 0;}
133  const char *text() const {Widget* w = item(); return w ? w->label() : 0;}
134#endif
135
136protected:
137  Widget *try_popup(const Rectangle&,const char* title=0,bool menubar=false);
138       
139private:
140  List* list_;
141  Widget* item_;
142};
143
144}
145
146#endif
147
148//
149// End of "$Id: Menu.h 4319 2005-05-08 19:18:50Z spitzak $".
150//
Note: See TracBrowser for help on using the repository browser.