/ src / hal / utils / miscgtk.h
miscgtk.h
  1  #ifndef MISCGTK_H
  2  #define MISCGTK_H
  3  
  4  /** This file, 'miscgtk.h', contains declarations for generic
  5      code used by GTK based programs.  This includes new widgets
  6      and other items of a general nature.
  7  
  8      It is also used for "compatibility code" needed to support
  9      different versions of GTK.  Currently, GTK-1.2 is the oldest
 10      version supported.  As GTK progresses and more version 1.2 APIs
 11      are deprecated, support for pre-2.0 versions may eventually be
 12      dropped.
 13  */
 14  
 15  /** Copyright (C) 2003 John Kasunich
 16                         <jmkasunich AT users DOT sourceforge DOT net>
 17  */
 18  
 19  /** This program is free software; you can redistribute it and/or
 20      modify it under the terms of version 2 of the GNU General
 21      Public License as published by the Free Software Foundation.
 22      This library is distributed in the hope that it will be useful,
 23      but WITHOUT ANY WARRANTY; without even the implied warranty of
 24      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 25      GNU General Public License for more details.
 26  
 27      You should have received a copy of the GNU General Public
 28      License along with this library; if not, write to the Free Software
 29      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 30  
 31      THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR
 32      ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE
 33      TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of
 34      harming persons must have provisions for completely removing power
 35      from all motors, etc, before persons enter any danger area.  All
 36      machinery must be designed to comply with local and national safety
 37      codes, and the authors of this software can not, and do not, take
 38      any responsibility for such compliance.
 39  
 40      This code was written as part of the EMC HAL project.  For more
 41      information, go to www.linuxcnc.org.
 42  */
 43  
 44  /***********************************************************************
 45  *                      FUNCTIONS PROVIDED BY MISCGTK.C                 *
 46  ************************************************************************/
 47  
 48  /** these provide similar functionality to the corresponding gtk2.0+ functions
 49  */
 50  #if !GTK_CHECK_VERSION(2,0,0)
 51  void gtk_widget_set_double_buffered( GtkWidget *widget, gboolean double_buffered);
 52  void gtk_widget_modify_fg( GtkWidget *widget, GtkStateType state, const GdkColor *color);
 53  void gtk_widget_modify_bg( GtkWidget *widget, GtkStateType state, const GdkColor *color);
 54  GdkFont* gtk_style_get_font(GtkStyle *style);
 55  #endif
 56  #if !GTK_CHECK_VERSION(2,8,0)
 57  void gtk_window_set_urgency_hint( GtkWindow *window, gboolean state );
 58  gboolean gtk_window_is_active( GtkWindow *window );
 59  #endif
 60  
 61  /** gtk_label_new_in_box() is used to create a label and pack it into
 62      a box.  It simply calls other GTK functions that do the real work.
 63      Normally it would take 4-5 lines of code to do the same thing.
 64  */
 65  GtkWidget *gtk_label_new_in_box(const gchar * text, GtkWidget * box,
 66      gboolean expand, gboolean fill, guint padding);
 67  
 68  /** more convenience functions - vertical and horizontal separators
 69      These functions set expand and fill to FALSE - if you don't like
 70      that, do it yourself.
 71  */
 72  void gtk_vseparator_new_in_box(GtkWidget * box, guint padding);
 73  void gtk_hseparator_new_in_box(GtkWidget * box, guint padding);
 74  
 75  /** convenience functions for nesting boxes.  homogeneous and spacing
 76      apply to the new box, expand, fill, and padding apply to the box
 77      it is going into
 78  */
 79  GtkWidget *gtk_vbox_new_in_box(gboolean homogeneous, guint spacing,
 80      guint border, GtkWidget * box, gboolean expand, gboolean fill,
 81      guint padding);
 82  GtkWidget *gtk_hbox_new_in_box(gboolean homogeneous, guint spacing,
 83      guint border, GtkWidget * box, gboolean expand, gboolean fill,
 84      guint padding);
 85  
 86  /** convenience functions for nesting boxes.  the new box is placed
 87      in a frame, which is in turn placed in the parent box.  'name'
 88      is the name displayed by the frame
 89  */
 90  GtkWidget *gtk_vbox_framed_new_in_box(const gchar * name, gboolean homogeneous,
 91      guint spacing, guint border, GtkWidget * box, gboolean expand,
 92      gboolean fill, guint padding);
 93  GtkWidget *gtk_hbox_framed_new_in_box(const gchar * name, gboolean homogeneous,
 94      guint spacing, guint border, GtkWidget * box, gboolean expand,
 95      gboolean fill, guint padding);
 96  
 97  /** yet another convenience function - this one works exactly like
 98      'gtk_label_set_text() except that if 'label' is null it returns
 99      without doing anything - handy for refreshing displays that may
100      or may not be valid, for instance if they are part of a dialog
101      that might not be active.
102  */
103  void gtk_label_set_text_if(GtkWidget * label, const gchar * text);
104  
105  /** gtk_label_size_to_fit() sets the size of the label to fit the
106      the string "str".  It is useful when you want the size of a
107      label to remain constant, even if it's contents change.
108  */
109  void gtk_label_size_to_fit(GtkLabel * label, const gchar * str);
110  
111  /* generic dialog typedef */
112  typedef struct {
113      GtkWidget *window;
114      int retval;
115      void *app_data;
116  } dialog_generic_t;
117  
118  /** dialog_generic_msg() generates a modal dialog box with a message
119      and up two four buttons.  It returns an integer indicating which
120      button the user pressed, or zero if the dialog was closed.
121      'parent' is the parent window - may be NULL if there is no parent.
122      'title' is the title for the dialog - if NULL, "Dialog" will be
123      used.
124      'msg' is the message text, if NULL, no message will be displayed.
125      'button1' thru 'button4' are the text for the buttons.  Only
126      buttons that are not NULL will be displayed - for a two button
127      dialog, supply two valid pointers and two NULLs.
128  */
129  int dialog_generic_msg(GtkWidget * parent, const gchar * title, const gchar * msg,
130      const gchar * button1, const gchar * button2, const gchar * button3, const gchar * button4);
131  
132  /** the following functions are used by the generic dialog functions,
133      but may also be useful for custom dialogs, so they are made public
134      here.
135  */
136  void dialog_generic_button1(GtkWidget * widget, dialog_generic_t * dptr);
137  void dialog_generic_button2(GtkWidget * widget, dialog_generic_t * dptr);
138  void dialog_generic_button3(GtkWidget * widget, dialog_generic_t * dptr);
139  void dialog_generic_button4(GtkWidget * widget, dialog_generic_t * dptr);
140  void dialog_generic_destroyed(GtkWidget * widget, dialog_generic_t * dptr);
141  
142  #endif /* MISCGTK_H */