Flu_Helpers.H 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // $Id: Flu_Helpers.h,v 1.7 2005/01/14 18:03:33 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #ifndef _FLU_HELPERS_H
  13. #define _FLU_HELPERS_H
  14. #include <FL/Fl.H>
  15. #include <FL/Fl_Window.H>
  16. #include <FL/Fl_Button.H>
  17. #include <FL/Fl_Valuator.H>
  18. #include <FL/Fl_Menu_.H>
  19. #include <FL/Fl_Menu_Item.H>
  20. #include "FLU/Flu_Enumerations.H"
  21. /* Convenience routine to hide all open windows. This will (eventually) cause FLTK to exit() */
  22. inline static void fl_exit()
  23. { while( Fl::first_window() ) Fl::first_window()->hide(); }
  24. /* Return the index of the full menu entry 'fullname' in the menu 'menu', or
  25. -1 if 'fullname' does not exist in 'menu'.
  26. */
  27. FLU_EXPORT int fl_Full_Find_In_Menu( const Fl_Menu_* menu, const char* fullname );
  28. inline int fl_Full_Find_In_Menu( const Fl_Menu_& menu, const char* fullname )
  29. { return fl_Full_Find_In_Menu( &menu, fullname ); }
  30. /* Return the menu item at the full menu entry 'fullname' in the menu 'menu', or
  31. NULL if 'fullname' does not exist in 'menu'.
  32. */
  33. inline const Fl_Menu_Item *fl_Full_Find_Item_In_Menu( const Fl_Menu_* menu, const char* fullname )
  34. {
  35. int index = fl_Full_Find_In_Menu( menu, fullname );
  36. return (index != -1) ? &(((Fl_Menu_Item*)menu->menu())[index]) : 0;
  37. }
  38. inline const Fl_Menu_Item *fl_Full_Find_Item_In_Menu( const Fl_Menu_& menu, const char* fullname )
  39. { return fl_Full_Find_Item_In_Menu( &menu, fullname ); }
  40. /* Return the index of the menu entry 'name' in the menu 'menu', or
  41. -1 if 'name' does not exist in 'menu'.
  42. */
  43. FLU_EXPORT int fl_Find_In_Menu( const Fl_Menu_* menu, const char* name );
  44. inline int fl_Find_In_Menu( const Fl_Menu_& menu, const char* name )
  45. { return fl_Find_In_Menu( &menu, name ); }
  46. /* Convenience callback for an Fl_Widget to show an Fl_Window. "arg" MUST be an instance or descendent of Fl_Window */
  47. inline static void fl_Show_Window_Callback( Fl_Widget* w, void* arg )
  48. { ((Fl_Window*)arg)->show(); }
  49. /* Convenience callback for an Fl_Widget to hide an Fl_Window. "arg" MUST be an instnace or descendent of Fl_Window */
  50. inline static void fl_Hide_Window_Callback( Fl_Widget* w, void* arg )
  51. { ((Fl_Window*)arg)->hide(); }
  52. /* Convenience callback for an Fl_Button to activate/deactivate another widget based on its value. "w" MUST be an instance or descendent of Fl_Button. "arg" MUST be an instance or descendent of Fl_Widget. */
  53. inline static void fl_Activate_On_Value_Callback( Fl_Widget* w, void *arg )
  54. { if( ((Fl_Button*)w)->value() ) ((Fl_Widget*)arg)->activate(); else ((Fl_Widget*)arg)->deactivate(); }
  55. /* Convenience callback for an Fl_Widget to hide an Fl_Window. "arg" MUST be an instance or descendent of Fl_Window.
  56. Before the window is hidden, its user_data() field is set to the widget that invoked the callback.
  57. The user_data() can then be used to determine which widget closed the window.
  58. */
  59. inline static void fl_Hide_Window_And_Set_User_Data_Callback( Fl_Widget* w, void* arg )
  60. { ((Fl_Window*)arg)->user_data( w ); ((Fl_Window*)arg)->hide(); }
  61. /* Convenience callback to get the value of an Fl_Button and store it (as an int) into "arg". ONLY use this for an Fl_Button and "arg" MUST point to an int. */
  62. inline static void fl_Get_Button_Value_Callback( Fl_Widget* w, void* arg )
  63. { *((int*)arg) = ((Fl_Button*)w)->value(); }
  64. /* Convenience callback to get the value of an Fl_Valuator and store it (as a float) into "arg". ONLY use this for an Fl_Valuator and "arg" MUST point to a float. */
  65. inline static void fl_Get_Valuator_Value_Callback( Fl_Widget* w, void* arg )
  66. { *((float*)arg) = ((Fl_Valuator*)w)->value(); }
  67. #endif