Fl_Sys_Menu_Bar.H 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // "$Id: Fl_Sys_Menu_Bar.H 12596 2017-12-18 15:19:15Z manolo $"
  3. //
  4. // MacOS system menu bar header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #ifndef Fl_Sys_Menu_Bar_H
  19. #define Fl_Sys_Menu_Bar_H
  20. #include <FL/Fl_Menu_Bar.H>
  21. class Fl_Sys_Menu_Bar_Driver;
  22. /**
  23. A class to create and modify menus that appear on Mac OS X in the menu bar at the top of the screen.
  24. To use this class, just replace Fl_Menu_Bar by Fl_Sys_Menu_Bar, and, on the Mac platform,
  25. a system menu at the top of the screen will be available. This menu will match an array
  26. of Fl_Menu_Item's exactly as in all other FLTK menus.
  27. On other than Mac OS X platforms, Fl_Sys_Menu_Bar is a synonym of class Fl_Menu_Bar.
  28. On the MacOS platform, the system menu bar of any FLTK app begins with the Application
  29. menu which the FLTK library automatically constructs. Functions
  30. Fl_Mac_App_Menu::custom_application_menu_items() and fl_mac_set_about() can be used to further customize
  31. the Application menu. The FLTK library also automatically constructs and handles a Window menu which can be
  32. further customized (or even removed) calling
  33. Fl_Sys_Menu_Bar::window_menu_style(window_menu_style_enum style).
  34. Other member functions of this class allow the app to generate the rest of the system menu bar.
  35. It is recommended to localize the system menu bar using the standard Mac OS X localization procedure
  36. (see \ref osissues_localize).
  37. Changes to the menu state are immediately visible in the menubar when they are made
  38. using member functions of the Fl_Sys_Menu_Bar class. Other changes (e.g., by a call to
  39. Fl_Menu_Item::set()) should be followed by a call to update() to be
  40. visible in the menubar across all platforms.
  41. A few FLTK menu features are not supported by the Mac System menu:
  42. \li no symbolic labels
  43. \li no embossed labels
  44. \li no font sizes
  45. */
  46. class FL_EXPORT Fl_Sys_Menu_Bar : public Fl_Menu_Bar {
  47. protected:
  48. virtual void draw();
  49. public:
  50. /** Possible styles of the Window menu in the system menu bar */
  51. typedef enum {
  52. no_window_menu = 0, ///< No Window menu in the system menu bar
  53. tabbing_mode_none, ///< No tabbed windows, but the system menu bar contains a Window menu
  54. tabbing_mode_automatic, ///< Windows are created by themselves but can be tabbed later
  55. tabbing_mode_preferred ///< Windows are tabbed when created
  56. } window_menu_style_enum;
  57. Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0);
  58. virtual ~Fl_Sys_Menu_Bar();
  59. static Fl_Sys_Menu_Bar_Driver *driver();
  60. /** Return the system menu's array of Fl_Menu_Item's
  61. */
  62. const Fl_Menu_Item *menu() const {return Fl_Menu_::menu();}
  63. void menu(const Fl_Menu_Item *m);
  64. virtual void update();
  65. int add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0);
  66. /** Adds a new menu item.
  67. \see Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0)
  68. */
  69. int add(const char* label, const char* shortcut, Fl_Callback* cb, void *user_data=0, int flags=0) {
  70. return add(label, fl_old_shortcut(shortcut), cb, user_data, flags);
  71. }
  72. int add(const char* str);
  73. int insert(int index, const char* label, int shortcut, Fl_Callback *cb, void *user_data=0, int flags=0);
  74. /** Insert a new menu item.
  75. \see Fl_Menu_::insert(int index, const char* label, const char* shortcut, Fl_Callback *cb, void *user_data=0, int flags=0)
  76. */
  77. int insert(int index, const char* label, const char* shortcut, Fl_Callback *cb, void *user_data=0, int flags=0) {
  78. return insert(index, label, fl_old_shortcut(shortcut), cb, user_data, flags);
  79. }
  80. void remove(int n);
  81. void replace(int index, const char *name);
  82. void clear();
  83. int clear_submenu(int index);
  84. void mode (int i, int fl);
  85. /** Gets the flags of item i.
  86. */
  87. int mode(int i) const { return Fl_Menu_::mode(i); }
  88. void shortcut (int i, int s);
  89. void setonly (Fl_Menu_Item *item);
  90. static void about(Fl_Callback *cb, void *data);
  91. static window_menu_style_enum window_menu_style();
  92. static void window_menu_style(window_menu_style_enum style);
  93. static void create_window_menu();
  94. };
  95. extern Fl_Sys_Menu_Bar *fl_sys_menu_bar;
  96. /**
  97. * Attaches a callback to the "About myprog" item of the system application menu.
  98. For back-compatibility. Equivalent to Fl_Sys_Menu_Bar::about(cb, user_data).
  99. */
  100. inline void fl_mac_set_about(Fl_Callback *cb, void *user_data, int shortcut = 0) { Fl_Sys_Menu_Bar::about(cb, user_data);}
  101. #endif // Fl_Sys_Menu_Bar_H
  102. //
  103. // End of "$Id: Fl_Sys_Menu_Bar.H 12596 2017-12-18 15:19:15Z manolo $".
  104. //