gapp_service.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) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #ifndef GAPPSERVICE_H
00029 #define GAPPSERVICE_H
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 #include <config.h>
00035 #include <libgnome/libgnome.h>
00036 #include <gtk/gtk.h>
00037 
00038 #include <gdk/gdk.h>
00039 
00040 #include "meldungen.h"
00041 #include "unit.h"
00042 
00043 // Used Ressource Types
00044 typedef enum
00045   {
00046     RES_BOOL, RES_STRING, RES_INT, RES_FLOAT, RES_IGNORE_INFO, RES_ENDE
00047   } RES_TYPE;
00048 
00049 
00050 // first startup behaviour
00051 typedef enum
00052   {
00053     RES_LEVEL_AUTO, RES_LEVEL_ASKFOR, RES_LEVEL_ASKFOR_DEPEND, RES_LEVEL_IGNORE, RES_LEVEL_INFOTEXT
00054   } RES_LEVEL;
00055 
00056 // Resource entry descriptor
00057 typedef struct
00058 {
00059   RES_TYPE type;          /* RES_BOOL, ...                        */
00060   const gchar *path;      /* resource path/name                   */
00061   const gchar *vdefault;  /* resource default                     */
00062   void *var;              /* address for the variable             */
00063   const gchar **options;  /* NULL, or list of option strings      */
00064   const gchar *group;     /* Group number, eg. page no used by folder */
00065   const gchar *comment;   /* comment: explanation for user        */
00066   RES_LEVEL level;        /* how to handle by first startup       */
00067   GtkWidget *entry;       /* Edit Entry */
00068   gchar *tmp;             /* temporary variable storage as text */
00069   gint (*depend_func)();  /* to figure out dependencies for asking */
00070 } RES_ENTRY;
00071 
00072 typedef void (*GappBrowseFunc)(gchar *fname, gpointer user_data);
00073 
00074 #define MYGTK_LSIZE 100
00075 #define MYGTK_ESIZE 100
00076 
00077 class MyGnomeTools{
00078 public:
00079         MyGnomeTools(){ };
00080         virtual ~MyGnomeTools(){ };
00081 
00082         /* My helper functions used for App Creation Stuff */
00083         // setup a nice input field
00084         static GtkWidget* mygtk_create_input(const char* labeltxt, GtkWidget* vbox, 
00085                                              GtkWidget* &hbox, 
00086                                              int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00087         // add a input field beside
00088         static GtkWidget* mygtk_add_input(GtkWidget *hbox, int esize=MYGTK_ESIZE);
00089         // add a input field beside with extra label
00090         static GtkWidget* mygtk_add_input(const gchar *labeltxt, GtkWidget *hbox, int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00091         // add a scale widget for quick mouse adjustment an wheel useage
00092         static GtkWidget* SetupScale(GtkObject *adj, GtkWidget *hbox, int sklsize=150);
00093         // add a spinbutton
00094         static GtkWidget* mygtk_create_spin_input(const gchar* labeltxt, GtkWidget* vbox, GtkWidget* &hbox, int lsize=MYGTK_LSIZE, int esize=-1);
00095         static GtkWidget* mygtk_add_spin(GtkWidget *hbox, int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00096         static GtkWidget* mygtk_add_spin(const gchar *labeltxt, GtkWidget *hbox, int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00097         // add a selectionlist
00098         static GtkWidget* mygtk_add_list(GtkWidget *hbox, int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00099         static GtkWidget* mygtk_add_list(const gchar *labeltxt, GtkWidget *hbox, int lsize=MYGTK_LSIZE, int esize=MYGTK_ESIZE);
00100 
00101         static void show_info_callback (GtkWidget *widget, gchar *message);
00102 
00103         /* Create an Arrow widget with the specified parameters
00104          * and pack it into a button */
00105         static GtkWidget *create_arrow_button( GtkArrowType  arrow_type,
00106                                                GtkShadowType shadow_type );
00107   
00108 
00109         GtkWidget *LookupMenuItem(GtkWidget *gmenu, gchar *menupath);
00110         int ActivateMenuItem(GtkWidget *gmenu, gchar *menupath);
00111         int SetupToggleMenuItem(GtkWidget *gmenu, gchar *menupath,
00112                                 gint select_toggle_indicator = TRUE );
00113 };
00114 
00115 class AppBase;
00116 
00117 #ifndef GNOME_PAD
00118 #define GNOME_PAD          8
00119 #endif
00120 
00121 class AppBase : public MyGnomeTools{
00122 public:
00123         AppBase(int InWindow=TRUE, int bw=GNOME_PAD);
00124         virtual ~AppBase();
00125   
00126         // Basic Setup Window/Widget
00127         virtual void AppWidgetInit(gchar *title, int InWindow=TRUE);
00128 
00129         /* Res Management */
00130         int SetResName(const gchar *respath, const gchar *defaultval, gint defaultgeomman=FALSE);
00131 
00132         static void SaveGeometryCallback(AppBase *apb);
00133 
00134         int SaveGeometry(int savealways=TRUE);
00135         int LoadGeometry();
00136 
00137         /* some default cb actions */
00138         static gint do_hide_callback (GtkWidget *window, GdkEventAny* e, AppBase *ab);
00139         static gint askfor_close_callback (GtkWidget *window, GdkEventAny* e, AppBase *ab);
00140 
00141         /* Window actions */
00142         void hide(){  gtk_widget_hide (widget); showstate=FALSE; };
00143         void show(){  gtk_widget_show (widget); showstate=TRUE; };
00144 
00145         /* sorry, but I need this for external access form main only... */  
00146         GtkWidget* GetWidget() { return widget; };
00147 
00148 protected:
00149         void destroy(){ gtk_widget_destroy (widget); widget=NULL; nodestroy=TRUE; };
00150         int nodestroy;
00151         int BorderWidth;
00152         int InWindowFlg;
00153         GtkWidget* widget;
00154         GtkWidget* vbox;
00155 
00156 private:
00157 
00158         int showstate;
00159         gchar *ResName;
00160         gchar *ResShow;
00161         gchar *ResGeomMan;
00162         gchar *ResGeom;
00163 };
00164 
00165 class DlgBase : public MyGnomeTools{
00166 public:
00167         DlgBase(){ runflg=FALSE; };
00168         virtual ~DlgBase(){};
00169 
00170         virtual void run()=0;
00171         int running(){ return runflg; };
00172 
00173 protected:
00174         void DlgStart(){ runflg=TRUE; };
00175         void DlgDone(){ runflg=FALSE; };
00176 
00177 private:
00178         int runflg;
00179 };
00180 
00181 
00182 class GnomeAppService : public AppBase{
00183 private:
00184         GtkWidget *app;
00185 public:
00186         GnomeAppService(GtkWidget *App=NULL){ app=App; fname = NULL; progress_dialog=NULL; };
00187         virtual ~GnomeAppService(){ 
00188                 if(fname){ g_free(fname); fname=NULL; }
00189                 choice(NULL, NULL, NULL, 0, NULL, NULL, NULL, 0);
00190                 progress_info_close (); 
00191         };
00192 
00193         void GnomeAppServiceSetApp(GtkWidget *App){ app=App; };
00194 
00195         GtkWidget *getApp(){ return app; };
00196 
00197         inline void check_events(){ while(gtk_events_pending()) gtk_main_iteration(); };
00198 
00199 /* FixMe !!!! */
00200         void flash(const char *mld){
00201                 std::cout << "************" << mld << "************" << std::endl;
00202         };
00203         void warning(const char *mld){
00204                 if(app){
00205                         GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(app),
00206                                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00207                                                                     GTK_MESSAGE_WARNING,
00208                                                                     GTK_BUTTONS_CLOSE,
00209                                                                     mld);
00210                         gtk_dialog_run (GTK_DIALOG (dialog));
00211                         gtk_widget_destroy (dialog);
00212                 }
00213         };
00214         void alert(const char *s1, const char *s2, const char *s3, int c){
00215                 if(app){
00216                         GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(app),
00217                                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00218                                                                     GTK_MESSAGE_WARNING,
00219                                                                     GTK_BUTTONS_CLOSE,
00220                                                                     "%s\n%s\n%s", s1, s2, s3);
00221                         gtk_dialog_run (GTK_DIALOG (dialog));
00222                         gtk_widget_destroy (dialog);
00223                 }
00224         };
00225         void errormsg(const char *mld){
00226                 if(app){
00227                         GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(app),
00228                                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00229                                                                     GTK_MESSAGE_ERROR,
00230                                                                     GTK_BUTTONS_CLOSE,
00231                                                                     mld);
00232                         gtk_dialog_run (GTK_DIALOG (dialog));
00233                         gtk_widget_destroy (dialog);
00234                 }
00235         };
00236         void message(const char *mld){
00237                 if(app){
00238                         GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(app),
00239                                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00240                                                                     GTK_MESSAGE_INFO,
00241                                                                     GTK_BUTTONS_CLOSE,
00242                                                                     mld);
00243                         gtk_dialog_run (GTK_DIALOG (dialog));
00244                         gtk_widget_destroy (dialog);
00245                 }
00246         };
00247         void messages(const char *s1, const char *s2, const char *s3){
00248                 gchar *mld = g_strconcat( s1, "\n", s2, "\n", s3, NULL);
00249                 message((const char*) mld);
00250                 g_free(mld);
00251         };
00252 
00253         static void questioncallback(int reply, GnomeAppService *p);
00254 
00255         int question(const gchar *question, int wait=FALSE);
00256 
00257         int dialog(const char *title, const char *content, 
00258                    const char *b1, const char *b2, const char *b3, 
00259                    int wait=FALSE);
00260 
00261         int choice(const char *s1, const char *s2, const char *s3, int numb, const char *b1, const char *b2, const char *b3, int def);
00262 
00263         const char *input(const char *lab, const char *defs){
00264                 gchar *string=NULL;
00265                 return string;
00266         }
00267   
00268         // returns TRUE if file does not exists or user decided to overwrite file
00269         // else FALSE
00270         int check_file(gchar *fn);
00271 
00272         static void file_ok_sel (GtkFileSelection *gw, GnomeAppService *p);
00273         static void string_cb (gchar *string, gpointer data);
00274 
00275         static void destroy (GtkWidget *widget, GnomeAppService *p);
00276 
00277         // File Dialog
00278         gchar *file_dialog (const gchar *title, 
00279                             const gchar *path, 
00280                             const gchar *mask, 
00281                             const gchar *name, 
00282                             const gchar *historyid=NULL, 
00283                             GappBrowseFunc browsefkt = NULL, 
00284                             gpointer data = NULL);
00285 
00286         // Value Request
00287         void ValueRequest(const gchar *title, const gchar *label, const gchar *infotxt, 
00288                           UnitObj *u, double minv, double maxv, gchar *vfmt,
00289                           double *value);
00290 
00291   
00292         // Progress Dialog
00293         GtkWidget* progress_info_new (const gchar *title=NULL, gint levels=1);
00294         int progress_info_set_bar_fraction (gdouble fraction=0., gint level=1);
00295         int progress_info_set_bar_pulse (gint level=1, gdouble fraction=-1.);
00296         int progress_info_set_bar_text (const gchar* text=NULL, gint level=1);
00297         int progress_info_add_info (const gchar* info);
00298         void progress_info_close ();
00299 
00300         GtkWidget* progress_dialog;
00301         GtkWidget* progress_bar[3];
00302 
00303         GtkWidget *filew;
00304         int  fdlg;
00305         gchar *fname;
00306         int  qreply;
00307   int  dlgreply, lastbutton;
00308 };
00309 
00310 #endif

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