gnome-res.h

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 2001,2002,2003 Percy Zahl
00006  *
00007  * WWW Home: http://garm.sf.net
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00025 
00026 #ifndef __GNOME_RES_H__
00027 #define __GNOME_RES_H__
00028 
00029 #include <gtk/gtk.h>
00030 #include <libgnome/libgnome.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif /* __cplusplus */
00035 
00036 /*
00037  * Gnome Ressource Types 
00038  */
00039 typedef enum {
00040         GNOME_RES_FIRST,          /* mark of first record, all other field are empty/NULL */
00041         GNOME_RES_BOOL,           /* variable of gint type, but only boolean values true/false allowed */
00042         GNOME_RES_STRING,         /* variable of gchar* type */
00043         GNOME_RES_INT,            /* variable of gint type */
00044         GNOME_RES_FLOAT,          /* variable of float type */
00045         GNOME_RES_FLOAT_W_UNIT,   /* variable of float type, with unit, unit Alias Symbol/String hold in options field */
00046         GNOME_RES_FLOAT_VEC3,     /* variable of float[3] type */
00047         GNOME_RES_FLOAT_VEC4,     /* variable of float[4] type */
00048         GNOME_RES_IGNORE_INFO,    /* variable not used, only infotext in comment field is of interest */
00049         GNOME_RES_SEPARATOR,      /* just a separator */
00050         GNOME_RES_LAST            /* mark of last record, all other field are empty/NULL */
00051 } GnomeResType;
00052 
00053 /*
00054  * Gnome Ressource Edit Types 
00055  */
00056 typedef enum {
00057         GNOME_RES_EDIT_NO,        /* not editable */
00058         GNOME_RES_EDIT_ENTRY,     /* use Gtk Text Entry */
00059         GNOME_RES_EDIT_OPTIONS,   /* use Gtk Options Menu */
00060         GNOME_RES_EDIT_VALSLIDER, /* use Gtk Value Slider, only for skalar numeric data (_INT, _FLOAT) !!
00061                                      options string format = {"Minval","Maxval","Step", "Page", "Digits"}
00062                                    */
00063         GNOME_RES_EDIT_COLORSEL,  /* use GtkColorSelection, use _FLOAT_VEC3 */
00064         GNOME_RES_EDIT_FONTSEL    /* use GtkFontSelection, use _STRING */
00065 } GnomeResEditType;
00066 
00067 /*
00068  * Define handlingmodes if Gnome Druids are running to configure at first startup
00069  */
00070 typedef enum {
00071         GNOME_RES_LEVEL_AUTO,          /* do not ask user, just use default value */
00072         GNOME_RES_LEVEL_ASKFOR,        /* ask user for value, prompt with default/current value */
00073         GNOME_RES_LEVEL_ASKFOR_DEPEND, /* ask user for value if depend function returns true */
00074         GNOME_RES_LEVEL_IGNORE,        /* do not care about this entry */
00075         GNOME_RES_LEVEL_INFOTEXT       /* just show comment */
00076 } GnomeResLevel;
00077         
00078 /*
00079  * Gnome Resource Entry descriptor 
00080  */
00081 typedef struct {
00082         GnomeResType type;      /* Entry Type                           */
00083         GnomeResEditType edit_type; /* Entry Type                           */
00084         const gchar *path;      /* resource path/name                   */
00085         const gchar *name;      /* variable name, if not NULL, it's used instead of path */
00086         const gchar *vdefault;  /* variables default value              */
00087         void *var;              /* pointer to the variable, type must match Entry Type   */
00088         gchar **options;  /* NULL, or list of option strings      */
00089         const gchar *option_text_format; /* NULL, or formatting string */
00090         float *option_data;     /* NULL or data for formatting string */
00091         const gchar *group;     /* Group number, eg. page no used by folder */
00092         const gchar *comment;   /* comment: explanation for user        */
00093         GnomeResLevel level;        /* how to handle by first startup       */
00094         gint (*depend_func)();  /* to figure out dependencies for asking */
00095         void (*changed_callback)(gpointer);  /* called if nonnull and entry changes */
00096         gpointer moreinfo;      /* special future use, depends on type  */
00097         GtkWidget *entry;       /* Edit Entry - internal use, init with NULL! */
00098         gchar *tmp;             /* temporary variable storage as text - internal use, init with NULL! */
00099 } GnomeResEntryInfoType;
00100 
00101 
00102 /* Macros to simplify usage, do use at least the GNOME_RES_ENTRY_NAME macro! */
00103 
00104 #define GNOME_RES_ENTRY(type, edit_type, path, name, vdefault, var, options, option_text_format, option_data, group, comment, level, depend_func, changed_callback, moreinfo) \
00105    { type, edit_type, path, name, vdefault, var, options, option_text_format, option_data, group, comment, level, depend_func, changed_callback, moreinfo, NULL, NULL }
00106 
00107 #define GNOME_RES_ENTRY_NAME(type, edit_type, path, name, vdefault, var, options, group, comment, level, depend_func, moreinfo) \
00108    GNOME_RES_ENTRY(type, edit_type, path, name, vdefault, var, options, NULL, NULL, group, comment, level, depend_func, NULL, moreinfo )
00109 
00110 #define GNOME_RES_ENTRY_FLOAT(path, name, vdefault, var, group, comment, changed_callback) \
00111    GNOME_RES_ENTRY(GNOME_RES_FLOAT, GNOME_RES_EDIT_ENTRY, path, name, vdefault, var, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00112 
00113 #define GNOME_RES_ENTRY_FLOAT_VEC3(path, name, vdefault, var, group, comment, changed_callback) \
00114    GNOME_RES_ENTRY(GNOME_RES_FLOAT_VEC3, GNOME_RES_EDIT_ENTRY, path, name, vdefault, var, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00115 
00116 #define GNOME_RES_ENTRY_FLOAT_VEC4(path, name, vdefault, var, group, comment, changed_callback) \
00117    GNOME_RES_ENTRY(GNOME_RES_FLOAT_VEC4, GNOME_RES_EDIT_ENTRY, path, name, vdefault, var, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00118 
00119 #define GNOME_RES_ENTRY_FLOATSLIDER(path, name, vdefault, var, options, group, comment, changed_callback) \
00120    GNOME_RES_ENTRY(GNOME_RES_FLOAT, GNOME_RES_EDIT_VALSLIDER, path, name, vdefault, var, options, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00121 
00122 #define GNOME_RES_ENTRY_COLORSEL(path, name, vdefault, var, group, comment, changed_callback) \
00123    GNOME_RES_ENTRY(GNOME_RES_FLOAT_VEC4, GNOME_RES_EDIT_COLORSEL, path, name, vdefault, var, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00124 
00125 #define GNOME_RES_ENTRY_FONTSEL(path, name, vdefault, var, group, comment, changed_callback) \
00126    GNOME_RES_ENTRY(GNOME_RES_STRING, GNOME_RES_EDIT_FONTSEL, path, name, vdefault, var, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, changed_callback, NULL)
00127 
00128 #define GNOME_RES_ENTRY_OPTION(type, path, vdefault, var, options, group, comment) \
00129    GNOME_RES_ENTRY(type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, NULL, NULL )
00130 
00131 #define GNOME_RES_ENTRY_MARK(type) \
00132    GNOME_RES_ENTRY(type, GNOME_RES_EDIT_NO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, GNOME_RES_LEVEL_IGNORE, NULL, NULL, NULL )
00133 
00134 #define GNOME_RES_ENTRY_MARK_NAME(type,pathname) \
00135    GNOME_RES_ENTRY(type, GNOME_RES_EDIT_NO, pathname, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, GNOME_RES_LEVEL_IGNORE, NULL, NULL, NULL )
00136 
00137 #define GNOME_RES_ENTRY_FIRST \
00138    GNOME_RES_ENTRY_MARK (GNOME_RES_FIRST)
00139 
00140 #define GNOME_RES_ENTRY_FIRST_NAME(pathname) \
00141    GNOME_RES_ENTRY_MARK_NAME (GNOME_RES_FIRST, pathname)
00142 
00143 #define GNOME_RES_ENTRY_LAST \
00144    GNOME_RES_ENTRY_MARK (GNOME_RES_LAST)
00145 
00146 #define GNOME_RES_ENTRY_PATH(type, path, vdefault, var, options, group, comment, level, depend_func) \
00147    GNOME_RES_ENTRY_NAME( type, GNOME_RES_EDIT_ENTRY, path, NULL, vdefault, var, options, group, comment, level, depend_func, NULL )
00148 
00149 #define GNOME_RES_ENTRY_PATH_OPTION(type, path, vdefault, var, options, group, comment, level, depend_func) \
00150    GNOME_RES_ENTRY_NAME( type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, group, comment, level, depend_func, NULL )
00151 
00152 #define GNOME_RES_ENTRY_INFOTEXT(group, comment) \
00153    GNOME_RES_ENTRY_NAME( GNOME_RES_IGNORE_INFO, GNOME_RES_EDIT_NO, NULL, NULL, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_INFOTEXT, NULL, NULL )
00154 
00155 #define GNOME_RES_ENTRY_SEPARATOR(group, comment) \
00156    GNOME_RES_ENTRY_NAME( GNOME_RES_SEPARATOR, GNOME_RES_EDIT_NO, NULL, NULL, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL, NULL )
00157 
00158 #define GNOME_RES_ENTRY_INFOTEXT_DEPEND(group, comment, depend_func) \
00159    GNOME_RES_ENTRY_NAME( GNOME_RES_IGNORE_INFO, GNOME_RES_EDIT_NO, NULL, NULL, NULL, NULL, NULL, group, comment, GNOME_RES_LEVEL_INFOTEXT, depend_func, NULL )
00160 
00161 #define GNOME_RES_ENTRY_AUTO_PATH(type, path, vdefault, var, group, comment) \
00162    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, NULL, group, comment, GNOME_RES_LEVEL_AUTO, NULL )
00163 
00164 #define GNOME_RES_ENTRY_AUTO_PATH_UNIT(type, path, vdefault, var, option_unit, group, comment) \
00165    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, option_unit, group, comment, GNOME_RES_LEVEL_AUTO, NULL )
00166 
00167 #define GNOME_RES_ENTRY_AUTO_PATH_OPTION(type, path, vdefault, var, options, group, comment) \
00168    GNOME_RES_ENTRY_PATH_OPTION(type, path, vdefault, var, options, group, comment, GNOME_RES_LEVEL_AUTO, NULL )
00169 
00170 #define GNOME_RES_ENTRY_AUTO_PATH_OPTION_FMT(type, path, vdefault, var, options, option_text_format, option_data, group, comment) \
00171    GNOME_RES_ENTRY( type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, option_text_format, option_data, group, comment, GNOME_RES_LEVEL_AUTO, NULL, NULL, NULL )
00172 
00173 #define GNOME_RES_ENTRY_ASK_PATH(type, path, vdefault, var, group, comment) \
00174    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, NULL, group, comment, GNOME_RES_LEVEL_ASKFOR, NULL )
00175 
00176 #define GNOME_RES_ENTRY_ASK_PATH_UNIT(type, path, vdefault, var, option_unit, group, comment) \
00177    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, option_unit, group, comment, GNOME_RES_LEVEL_ASKFOR, NULL )
00178 
00179 #define GNOME_RES_ENTRY_ASK_PATH_OPTION(type, path, vdefault, var, options, group, comment) \
00180    GNOME_RES_ENTRY_PATH_OPTION(type, path, vdefault, var, options, group, comment, GNOME_RES_LEVEL_ASKFOR, NULL )
00181 
00182 #define GNOME_RES_ENTRY_ASK_PATH_OPTION_FMT(type, path, vdefault, var, options, option_text_format, option_data, group, comment) \
00183    GNOME_RES_ENTRY( type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, option_text_format, option_data, group, comment, GNOME_RES_LEVEL_ASKFOR, NULL, NULL, NULL )
00184 
00185 #define GNOME_RES_ENTRY_ASK_PATH_DEPEND(type, path, vdefault, var, group, comment, depend_func) \
00186    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, NULL, group, comment, GNOME_RES_LEVEL_ASKFOR_DEPEND, depend_func )
00187 
00188 #define GNOME_RES_ENTRY_ASK_PATH_DEPEND_UNIT(type, path, vdefault, var, option_unit, group, comment, depend_func) \
00189    GNOME_RES_ENTRY_PATH(type, path, vdefault, var, option_unit, group, comment, GNOME_RES_LEVEL_ASKFOR_DEPEND, depend_func )
00190 
00191 #define GNOME_RES_ENTRY_ASK_PATH_OPTION_DEPEND(type, path, vdefault, var, options, group, comment, depend_func) \
00192    GNOME_RES_ENTRY(type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, NULL, NULL, group, comment, GNOME_RES_LEVEL_ASKFOR_DEPEND, depend_func, NULL, NULL )
00193 
00194 #define GNOME_RES_ENTRY_ASK_PATH_OPTION_FMT_DEPEND(type, path, vdefault, var, options, option_text_format, option_data, group, comment, depend_func) \
00195    GNOME_RES_ENTRY( type, GNOME_RES_EDIT_OPTIONS, path, NULL, vdefault, var, options, option_text_format, option_data, group, comment, GNOME_RES_LEVEL_ASKFOR_DEPEND, depend_func, NULL, NULL )
00196 
00197 
00198 /*
00199  * User Configuration Dialog
00200  */
00201 
00202 typedef struct {
00203         GnomeResEntryInfoType *res_def;
00204         gchar *pref_ok_message;
00205         gchar *pref_apply_message;
00206         GtkWidget *dialog;
00207         int destroy_on_close;
00208         int running;
00209         void (*pref_apply_callback)(gpointer);
00210         gpointer pref_apply_callback_data;
00211 } GnomeResPreferences;
00212 
00213 GnomeResPreferences *gnome_res_preferences_new (GnomeResEntryInfoType *res_def);
00214 void gnome_res_set_ok_message (GnomeResPreferences *gnome_res_pref, const gchar *ok_msg);
00215 void gnome_res_set_apply_message (GnomeResPreferences *gnome_res_pref, const gchar *apply_msg);
00216 void gnome_res_set_apply_callback (GnomeResPreferences *self, void (*cb)(gpointer), gpointer data);
00217 void gnome_res_run_change_user_config(GnomeResPreferences *gnome_res_pref, const gchar *dialog_title);
00218 void gnome_res_set_destroy_on_close (GnomeResPreferences *self, int flg);
00219 void gnome_res_destroy (GnomeResPreferences *gnome_res_pref);
00220 
00221 void gnome_res_read_user_config (GnomeResPreferences *gnome_res_pref);
00222 void gnome_res_write_user_config (GnomeResPreferences *gnome_res_pref);
00223 
00224 /*
00225  * New User Druid
00226  */
00227 
00228 typedef enum {
00229         GNOME_RES_DRUID_RUNNING,
00230         GNOME_RES_DRUID_FINISH,
00231         GNOME_RES_DRUID_CANCEL,
00232 } GnomeResDruidFinishType;
00233 
00234 typedef struct {
00235         GnomeResPreferences *res_pref;
00236         
00237         GtkWidget *window;
00238         GtkWidget *druid;
00239         GtkWidget *startpage, *page, *finishpage;
00240         GnomeResEntryInfoType *res_current;
00241         
00242         GdkPixbuf *logo, *watermark;
00243         gchar *title, *welcome, *intro_text, *finish, *final_text;
00244 
00245         gint pageindex, pagescreated;
00246         GnomeResDruidFinishType finishmode;
00247 } GnomeResNewUserDruid;
00248 
00249 GnomeResNewUserDruid *gnome_res_new_user_druid_new (GnomeResEntryInfoType *res_def, const gchar *title);
00250 GnomeResNewUserDruid *gnome_res_new_user_druid_new_with_vals (GnomeResEntryInfoType *res_def, 
00251                                                               const gchar *title,
00252                                                               GdkPixbuf *logo,
00253                                                               GdkPixbuf *watermark,
00254                                                               const gchar *welcome, 
00255                                                               const gchar *intro_text, 
00256                                                               const gchar *finish, 
00257                                                               const gchar *final_text
00258                                                               );
00259 GnomeResDruidFinishType gnome_res_new_user_druid_run_druids (GnomeResNewUserDruid *self);
00260 void gnome_res_new_user_druid_destroy (GnomeResNewUserDruid *self);
00261 
00262 #ifdef __cplusplus
00263 }
00264 #endif /* __cplusplus */
00265 
00266 
00267 #endif /* __GNOME_RES_H__ */

Generated on Sat Apr 1 09:03:55 2006 for GXSM by  doxygen 1.4.6