You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
6.2KB

  1. //
  2. // "$Id: Fl_Menu_.H 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Menu base class header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Menu_ widget . */
  29. #ifndef Fl_Menu__H
  30. #define Fl_Menu__H
  31. #ifndef Fl_Widget_H
  32. #include "Fl_Widget.H"
  33. #endif
  34. #include "Fl_Menu_Item.H"
  35. /**
  36. Base class of all widgets that have a menu in FLTK.
  37. Currently FLTK provides you with
  38. Fl_Menu_Button, Fl_Menu_Bar, and Fl_Choice.
  39. <P>The class contains a pointer to an array of structures of type Fl_Menu_Item. The
  40. array may either be supplied directly by the user program, or it may
  41. be "private": a dynamically allocated array managed by the Fl_Menu_.
  42. */
  43. class FL_EXPORT Fl_Menu_ : public Fl_Widget {
  44. Fl_Menu_Item *menu_;
  45. const Fl_Menu_Item *value_;
  46. protected:
  47. uchar alloc; // flag indicates if menu_ is a dynamic copy (=1) or not (=0)
  48. uchar down_box_;
  49. Fl_Font textfont_;
  50. Fl_Fontsize textsize_;
  51. Fl_Color textcolor_;
  52. public:
  53. Fl_Menu_(int,int,int,int,const char * =0);
  54. ~Fl_Menu_();
  55. int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
  56. const Fl_Menu_Item* picked(const Fl_Menu_Item*);
  57. const Fl_Menu_Item* find_item(const char *name);
  58. const Fl_Menu_Item* find_item(Fl_Callback*);
  59. int find_index(const char *name) const;
  60. int find_index(const Fl_Menu_Item *item) const;
  61. int find_index(Fl_Callback *cb) const;
  62. /**
  63. Returns the menu item with the entered shortcut (key value).
  64. This searches the complete menu() for a shortcut that matches the
  65. entered key value. It must be called for a FL_KEYBOARD or FL_SHORTCUT
  66. event.
  67. If a match is found, the menu's callback will be called.
  68. \return matched Fl_Menu_Item or NULL.
  69. */
  70. const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
  71. void global();
  72. /**
  73. Returns a pointer to the array of Fl_Menu_Items. This will either be
  74. the value passed to menu(value) or the private copy.
  75. */
  76. const Fl_Menu_Item *menu() const {return menu_;}
  77. void menu(const Fl_Menu_Item *m);
  78. void copy(const Fl_Menu_Item *m, void* user_data = 0);
  79. int insert(int index, const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
  80. int add(const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
  81. /** See int Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0) */
  82. int add(const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
  83. return add(a,fl_old_shortcut(b),c,d,e);
  84. }
  85. /** See int Fl_Menu_::insert(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0) */
  86. int insert(int index, const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
  87. return insert(index,a,fl_old_shortcut(b),c,d,e);
  88. }
  89. int add(const char *);
  90. int size() const ;
  91. void size(int W, int H) { Fl_Widget::size(W, H); }
  92. void clear();
  93. int clear_submenu(int index);
  94. void replace(int,const char *);
  95. void remove(int);
  96. /** Changes the shortcut of item i to n. */
  97. void shortcut(int i, int s) {menu_[i].shortcut(s);}
  98. /** Sets the flags of item i. For a list of the flags, see Fl_Menu_Item. */
  99. void mode(int i,int fl) {menu_[i].flags = fl;}
  100. /** Gets the flags of item i. For a list of the flags, see Fl_Menu_Item. */
  101. int mode(int i) const {return menu_[i].flags;}
  102. /** Returns a pointer to the last menu item that was picked. */
  103. const Fl_Menu_Item *mvalue() const {return value_;}
  104. /** Returns the index into menu() of the last item chosen by the user. It is zero initially. */
  105. int value() const {return value_ ? (int)(value_-menu_) : -1;}
  106. int value(const Fl_Menu_Item*);
  107. /**
  108. The value is the index into menu() of the last item chosen by
  109. the user. It is zero initially. You can set it as an integer, or set
  110. it with a pointer to a menu item. The set routines return non-zero if
  111. the new value is different than the old one.
  112. */
  113. int value(int i) {return value(menu_+i);}
  114. /** Returns the title of the last item chosen. */
  115. const char *text() const {return value_ ? value_->text : 0;}
  116. /** Returns the title of item i. */
  117. const char *text(int i) const {return menu_[i].text;}
  118. /** Gets the current font of menu item labels. */
  119. Fl_Font textfont() const {return textfont_;}
  120. /** Sets the current font of menu item labels. */
  121. void textfont(Fl_Font c) {textfont_=c;}
  122. /** Gets the font size of menu item labels. */
  123. Fl_Fontsize textsize() const {return textsize_;}
  124. /** Sets the font size of menu item labels. */
  125. void textsize(Fl_Fontsize c) {textsize_=c;}
  126. /** Get the current color of menu item labels. */
  127. Fl_Color textcolor() const {return textcolor_;}
  128. /** Sets the current color of menu item labels. */
  129. void textcolor(Fl_Color c) {textcolor_=c;}
  130. /**
  131. This box type is used to surround the currently-selected items in the
  132. menus. If this is FL_NO_BOX then it acts like
  133. FL_THIN_UP_BOX and selection_color() acts like
  134. FL_WHITE, for back compatibility.
  135. */
  136. Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
  137. /** See Fl_Boxtype Fl_Menu_::down_box() const */
  138. void down_box(Fl_Boxtype b) {down_box_ = b;}
  139. /** For back compatibility, same as selection_color() */
  140. Fl_Color down_color() const {return selection_color();}
  141. /** For back compatibility, same as selection_color() */
  142. void down_color(unsigned c) {selection_color(c);}
  143. };
  144. #endif
  145. //
  146. // End of "$Id: Fl_Menu_.H 7903 2010-11-28 21:06:39Z matt $".
  147. //