gapp_service.C

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 #include <locale.h>
00029 #include <libintl.h>
00030 
00031 #include <libgen.h>
00032 
00033 #include <config.h>
00034 #include <libgnome/libgnome.h>
00035 
00036 #include <gdk/gdk.h>
00037 
00038 #include "gtkspinbuttonsci.h"
00039 #include "gapp_service.h"
00040 #include "pcs.h"
00041 #include "glbvars.h"
00042 
00043 
00044 // ============================================================
00045 // MyGnomeTools
00046 // ============================================================
00047 
00048 GtkWidget *MyGnomeTools::LookupMenuItem(GtkWidget *gmenu, gchar *menupath){
00049   GtkWidget *menushell;
00050   GtkWidget *menuitem;
00051   gint pos;
00052 
00053   menushell = gnome_app_find_menu_pos (gmenu, menupath, &pos);
00054   --pos;
00055   if(! menushell) return NULL;
00056 
00057   menuitem = (GtkWidget*)g_list_nth_data(GTK_MENU_SHELL (menushell) -> children, pos);
00058   if(! menuitem) return NULL;
00059 
00060   return(menuitem);
00061 }
00062 
00063 int MyGnomeTools::ActivateMenuItem(GtkWidget *gmenu, gchar *menupath){
00064   GdkEvent event;
00065   gint return_val;
00066   GtkWidget *menuitem = LookupMenuItem(gmenu, menupath);
00067 
00068   gtk_signal_emit (GTK_OBJECT(GTK_MENU_ITEM (menuitem) ), 
00069                    gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (GTK_OBJECT(menuitem))),
00070                    &event, &return_val);
00071   return 0;
00072 }
00073 
00074 int MyGnomeTools::SetupToggleMenuItem(GtkWidget *gmenu, gchar *menupath,  
00075                                     gint select_toggle_indicator ){
00076   gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( LookupMenuItem(gmenu, menupath) ), 
00077                                    select_toggle_indicator );
00078   return 0;
00079 }
00080 
00081 void MyGnomeTools::show_info_callback (GtkWidget *widget, gchar *message){
00082         GtkWidget *dialog = gtk_message_dialog_new (NULL,
00083                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00084                                                     GTK_MESSAGE_INFO,
00085                                                     GTK_BUTTONS_OK,
00086                                                     message);
00087         gtk_dialog_run (GTK_DIALOG (dialog));
00088         gtk_widget_destroy (dialog);
00089 }
00090 
00091 GtkWidget *MyGnomeTools::create_arrow_button( GtkArrowType  arrow_type,
00092                                                  GtkShadowType shadow_type ){
00093   GtkWidget *button;
00094   GtkWidget *arrow;
00095   
00096   button = gtk_button_new();
00097   arrow = gtk_arrow_new (arrow_type, shadow_type);
00098   
00099   gtk_container_add (GTK_CONTAINER (button), arrow);
00100   
00101   gtk_widget_show(button);
00102   gtk_widget_show(arrow);
00103   
00104   return(button);
00105 }
00106 
00107 
00108 GtkWidget* MyGnomeTools::mygtk_create_input(const gchar* labeltxt, GtkWidget* vbox,
00109                                        GtkWidget* &hbox, int lsize, int esize){
00110   GtkWidget *label, *entry;
00111 
00112 //  g_print ("GXSM: mygtk_create_input: %s\n", labeltxt); // used to locate trouble
00113   
00114   hbox = gtk_hbox_new (FALSE, 0);
00115   gtk_widget_show (hbox);
00116 //  gtk_container_add (GTK_CONTAINER (vbox), hbox);
00117   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00118   
00119   label = gtk_label_new (labeltxt);
00120   gtk_widget_show (label);
00121   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, lsize ? TRUE:FALSE, lsize ? 0:GNOME_PAD);
00122 
00123   if (lsize)  
00124           gtk_widget_set_size_request (label, lsize, -1);
00125   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
00126 
00127   if (esize == -1) return NULL;
00128 
00129   entry = gtk_entry_new ();
00130   if (esize)
00131           gtk_widget_set_size_request (entry, esize, -1);
00132   gtk_widget_show (entry);
00133   gtk_container_add (GTK_CONTAINER (hbox), entry);
00134   
00135   return entry;
00136 }
00137 
00138 GtkWidget* MyGnomeTools::mygtk_add_input(GtkWidget *hbox, int esize){
00139   GtkWidget *entry;
00140 
00141   entry = gtk_entry_new ();
00142   if (esize)
00143           gtk_widget_set_size_request (entry, esize, -1);
00144   gtk_widget_show (entry);
00145   gtk_container_add (GTK_CONTAINER (hbox), entry);
00146   
00147   return entry;
00148 }
00149 
00150 GtkWidget* MyGnomeTools::mygtk_add_input(const gchar *labeltxt, GtkWidget *hbox, 
00151                                     int lsize, int esize){
00152   GtkWidget *label, *entry;
00153 
00154   label = gtk_label_new (labeltxt);
00155   gtk_widget_show (label);
00156   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, lsize ? TRUE:FALSE, lsize ? 0:GNOME_PAD);
00157   if (lsize)
00158           gtk_widget_set_size_request (label, lsize, -1);
00159   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
00160 
00161   entry = gtk_entry_new ();
00162   if (esize)
00163           gtk_widget_set_size_request (entry, esize, -1);
00164   gtk_widget_show (entry);
00165   gtk_container_add (GTK_CONTAINER (hbox), entry);
00166   
00167   return entry;
00168 }
00169 
00170 GtkWidget* MyGnomeTools::SetupScale(GtkObject *adj, GtkWidget *hbox, int sklsize){
00171   GtkWidget *skl = gtk_hscale_new( GTK_ADJUSTMENT(adj));
00172   if (sklsize)
00173           gtk_widget_set_size_request (skl, sklsize, -1);
00174   gtk_scale_set_value_pos (GTK_SCALE (skl), GTK_POS_LEFT);
00175   gtk_scale_set_draw_value(GTK_SCALE(skl), FALSE);
00176   gtk_widget_show (skl); 
00177   gtk_container_add (GTK_CONTAINER (hbox), skl);
00178   return skl;
00179 }
00180 
00181 GtkWidget* MyGnomeTools::mygtk_create_spin_input(const gchar* labeltxt, GtkWidget* vbox,
00182                                        GtkWidget* &hbox, int lsize, int esize){
00183         mygtk_create_input(labeltxt, vbox, hbox, lsize, -1);
00184         return mygtk_add_spin (hbox);
00185 }
00186 
00187 GtkWidget* MyGnomeTools::mygtk_add_spin (GtkWidget *hbox, 
00188                                          int lsize, int esize){
00189   GtkObject *adjust;
00190   GtkWidget *spin;
00191 
00192   adjust = gtk_adjustment_new (0., -10., 10., 1., 10., 10.);
00193   spin   = gtk_spin_button_sci_new (GTK_ADJUSTMENT (adjust), 1, 0);
00194   gtk_widget_show (spin);
00195   gtk_container_add (GTK_CONTAINER (hbox), spin);
00196   
00197   gtk_object_set_data( GTK_OBJECT (spin), "Adjustment", adjust);
00198   if (esize)
00199           gtk_widget_set_size_request (spin, esize, -1);
00200   
00201   return spin;
00202 }
00203 
00204 GtkWidget* MyGnomeTools::mygtk_add_spin(const gchar *labeltxt, GtkWidget *hbox, 
00205                                     int lsize, int esize){
00206   GtkObject *adjust;
00207   GtkWidget *spin;
00208   GtkWidget *label;
00209 
00210   label = gtk_label_new (labeltxt);
00211   gtk_widget_show (label);
00212   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, lsize ? TRUE:FALSE, lsize ? 0:GNOME_PAD);
00213   if (lsize)
00214           gtk_widget_set_size_request (label, lsize, -1);
00215   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
00216 
00217   adjust = gtk_adjustment_new (0., -10., 10., 1., 10., 10.);
00218   spin   = gtk_spin_button_sci_new (GTK_ADJUSTMENT (adjust), 1, 1);
00219   gtk_widget_show (spin);
00220   gtk_container_add (GTK_CONTAINER (hbox), spin);
00221   
00222   gtk_object_set_data( GTK_OBJECT (spin), "Adjustment", adjust);
00223   
00224   return spin;
00225 }
00226 
00227 GtkWidget* MyGnomeTools::mygtk_add_list(const gchar *labeltxt, GtkWidget *hbox, 
00228                                     int lsize, int esize){
00229   GtkWidget *label, *list;
00230 
00231   label = gtk_label_new (labeltxt);
00232   gtk_widget_show (label);
00233   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, lsize ? TRUE:FALSE, lsize ? 0:GNOME_PAD);
00234   if (lsize)
00235           gtk_widget_set_size_request (label, lsize, -1);
00236   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
00237 
00238   list  = gtk_list_new ();
00239   gtk_widget_show (list);
00240   gtk_container_add (GTK_CONTAINER (hbox), list);
00241   
00242   return list;
00243 }
00244 
00245 
00246 // ============================================================
00247 // GnomeAppService
00248 // ============================================================
00249 
00250 void GnomeAppService::questioncallback(int reply, GnomeAppService *p){
00251         switch(reply){
00252         case GNOME_YES: p->qreply=TRUE; break;
00253         case GNOME_NO:  p->qreply=FALSE; break;
00254         default: p->qreply=FALSE; break;
00255         }
00256 }
00257 
00258 int GnomeAppService::question(const gchar *question, int wait){ // Yes / No ?
00259         qreply = 999;
00260         //    GtkWidget *gq = ...
00261         gnome_app_question 
00262                 ( GNOME_APP (app) , question , 
00263                   (GnomeReplyCallback) questioncallback,
00264                   (gpointer) this);
00265         
00266         while(wait && qreply == 999) 
00267                 check_events();
00268         
00269         return qreply;
00270 }
00271 
00272 int GnomeAppService::choice(const char *s1, const char *s2, const char *s3, int numb, const char *b1, const char *b2, const char *b3, int def){
00273         static gchar *s = NULL;
00274         if(s){ g_free(s); s=NULL; }
00275         if(!s1 && !s2) return 0;
00276         s = g_strconcat( s2, "\n", s3, NULL);
00277         return dialog(s1, s, b1, b2, b3, TRUE);
00278 }
00279 
00280 int GnomeAppService::dialog(const char *title, const char *content, 
00281                             const char *b1, const char *b2, const char *b3, 
00282                             int wait){
00283         GtkWidget *label = gtk_label_new (_(content));
00284         gtk_widget_show (label);
00285         
00286         GtkWidget *dialog = gtk_dialog_new_with_buttons (_(title),
00287                                                          NULL,
00288                                                          (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
00289                                                          _(b1), 1,
00290                                                          _(b2), 2,
00291                                                          _(b3), 3,
00292 //                                      GTK_STOCK_OK,
00293 //                                      GTK_RESPONSE_ACCEPT,
00294 //                                      GTK_STOCK_CANCEL,
00295 //                                      GTK_RESPONSE_REJECT,
00296                                                          NULL);
00297 
00298         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
00299                            label, TRUE, TRUE, GNOME_PAD);
00300 
00301         gint result = gtk_dialog_run (GTK_DIALOG (dialog));
00302         gtk_widget_destroy (dialog);
00303         return result;
00304 }
00305 
00306 GtkWidget* GnomeAppService::progress_info_new (const gchar *title, gint levels){
00307         if (progress_dialog)
00308                 gtk_widget_destroy (progress_dialog);
00309 
00310         progress_dialog = gtk_dialog_new_with_buttons (_(title?title:"Progress"), NULL, (GtkDialogFlags)(GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT), NULL);
00311 
00312 //      Add GtkProgressBar
00313         for (int i=0; i<3; ++i)
00314                 progress_bar[i] = NULL;
00315 
00316         if (levels>0)
00317                 for (int i=0; i<levels && i<3; ++i){
00318                         progress_bar[i] = gtk_progress_bar_new ();
00319                         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(progress_dialog)->vbox), progress_bar[i], TRUE, TRUE, GNOME_PAD);
00320 //                      gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (progress_bar[i]), PANGO_ELLIPSIZE_START);
00321                 }
00322 
00323         gtk_widget_show_all (progress_dialog);
00324         check_events();
00325         return progress_dialog;
00326 }
00327 
00328 int GnomeAppService::progress_info_set_bar_fraction (gdouble fraction, gint level){
00329         if (!progress_dialog) return -1;
00330         if (level<1 || level > 3) return -1;
00331 
00332         if (progress_bar[level-1] && fraction >= 0.)
00333                 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar[level-1]), fraction);
00334 
00335         check_events();
00336         return 0;
00337 }
00338 
00339 int GnomeAppService::progress_info_set_bar_pulse (gint level, gdouble fraction){
00340         if (!progress_dialog) return -1;
00341         if (level<1 || level > 3) return -1;
00342 
00343         if (progress_bar[level-1]){
00344                 if (fraction >= 0.)
00345                         gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progress_bar[level-1]), fraction);
00346                 else
00347                         gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar[level-1]));
00348                 check_events();
00349         }
00350         return 0;
00351 }
00352 
00353 int GnomeAppService::progress_info_set_bar_text (const gchar* text, gint level){
00354         if (!progress_dialog) return -1;
00355         if (level<1 || level > 3) return -1;
00356 
00357         if (progress_bar[level-1])
00358                 gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar[level-1]), text);
00359 
00360         check_events();
00361         return 0;
00362 }
00363 
00364 int GnomeAppService::progress_info_add_info (const gchar* info){
00365         if (!progress_dialog) 
00366                 return -1;
00367 
00368         GtkWidget *label = gtk_label_new (_(info));
00369         gtk_widget_show (label);
00370         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(progress_dialog)->vbox), label, TRUE, TRUE, GNOME_PAD);
00371         check_events();
00372         return 0;
00373 }
00374 
00375 void GnomeAppService::progress_info_close (){
00376         if (progress_dialog){
00377                 gtk_widget_destroy (progress_dialog);
00378                 progress_dialog=NULL;
00379         }
00380 }
00381 
00382 
00383 /* The file selection widget and the string to store the chosen filename */
00384 /*
00385 void GnomeAppService::file_ok_sel (GtkFileSelection *file_selector, GnomeAppService *p) {
00386         p->fname = g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector)));
00387         XSM_DEBUG(DBG_L2, "File was clicked->Selection:" << p->fname );
00388 }
00389 */
00390 // strange... docu is bad:-( but this works
00391 void file_ok (gpointer junk, GtkFileSelection *file_selector) {
00392         gchar **fname = (gchar**)gtk_object_get_data (GTK_OBJECT (file_selector), "P_FNAME");
00393         *fname = g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector)));
00394         XSM_DEBUG(DBG_L2, "File was clicked->Selection:" << fname );
00395 }
00396 
00397 gchar *GnomeAppService::file_dialog (const gchar *title, 
00398                                      const gchar *path, 
00399                                      const gchar *mask, 
00400                                      const gchar *name, 
00401                                      const gchar *historyid, 
00402                                      GappBrowseFunc browsefkt,
00403                                      gpointer data){
00404 #ifdef USE_GNOME_FENTRY
00405         GtkWidget * dialog;
00406   
00407         dialog = gnome_dialog_new(title, 
00408                                   GNOME_STOCK_BUTTON_OK,
00409                                   GNOME_STOCK_BUTTON_CANCEL,
00410                                   NULL);
00411 
00412         gnome_dialog_set_close(GNOME_DIALOG(dialog), TRUE);
00413         gnome_dialog_close_hides(GNOME_DIALOG(dialog), TRUE);
00414 
00415         GtkWidget *gfe = gnome_file_entry_new (historyid, title);
00416         if (path)
00417                 gnome_file_entry_set_default_path (GNOME_FILE_ENTRY (gfe), path);
00418         if (name)
00419                 gnome_file_entry_set_filename (GNOME_FILE_ENTRY (gfe), name);
00420 
00421         gnome_dialog_editable_enters(GNOME_DIALOG(dialog), 
00422                                      GTK_EDITABLE(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(gfe))));
00423         gnome_dialog_set_default(GNOME_DIALOG(dialog), GNOME_OK);
00424         gnome_file_entry_set_modal (GNOME_FILE_ENTRY (gfe), TRUE);
00425         
00426         gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
00427                            gfe,
00428                            TRUE, TRUE, GNOME_PAD);
00429   
00430 
00431         gtk_widget_show_all(dialog);
00432 
00433         int reply = gnome_dialog_run(GNOME_DIALOG(dialog));
00434   
00435         g_free(fname);
00436         fname = NULL;
00437 
00438         if (reply == GNOME_OK)
00439                 fname = g_strdup (gnome_file_entry_get_full_path (GNOME_FILE_ENTRY (gfe), FALSE));
00440         
00441         gtk_widget_destroy(dialog);  
00442 
00443         return fname;
00444 
00445 #else
00446 
00447         gchar *historyid_gconf_path = NULL;
00448         GtkWidget *file_selector;
00449 
00450         /* Create the selector */
00451         file_selector = gtk_file_selection_new (title);
00452    
00453         /* Choose *.nc for list display */
00454         if (mask)
00455                 gtk_file_selection_complete (GTK_FILE_SELECTION(file_selector), mask);
00456         
00457 //      name = gtk_file_chooser_run_open (parent_window, "Select a file");
00458 //      gtk_file_chooser_set_preview_widget_active (GTK_FILE_SELECTION(file_selector), TRUE);
00459 
00460         /* Lets set the filename, as if this were a save dialog, and we are giving
00461            a default filename */
00462         
00463         // automatic path/file historty mechanism
00464         if (historyid)
00465                 g_strdelimit (historyid_gconf_path = g_strdup (historyid), " ", '-');
00466 
00467         if (historyid_gconf_path){
00468                 gchar *p = path ? g_strdup (path) : mask ? g_strdup (mask) : g_strdup ("");
00469                 XsmRescourceManager xrm("FilePathSelectionHistory", historyid_gconf_path);
00470                 gchar *pf = xrm.GetStr("LastFile-0", p);
00471                 gchar *p1 = xrm.GetStr("LastFile-1", "");
00472                 gchar *p2 = xrm.GetStr("LastFile-2", "");
00473                 gchar *p3 = xrm.GetStr("LastFile-3", "");
00474                 xrm.Put("LastFile-4", p3);
00475                 xrm.Put("LastFile-3", p2);
00476                 xrm.Put("LastFile-2", p1);
00477                 xrm.Put("LastFile-1", pf);
00478                 if (name && pf){
00479                         gchar *pathname = strdup (pf);
00480                         g_free (pf);
00481                         pf = g_strconcat (dirname (pathname), "/", name, NULL);
00482                         free (pathname);
00483                 } 
00484                 if (pf)
00485                         gtk_file_selection_set_filename (GTK_FILE_SELECTION(file_selector), pf);
00486                 g_free (pf);
00487                 g_free (p);
00488 
00489         } else if (path && name){
00490                 gchar *pf = g_strconcat (path, "/", name, NULL);
00491                 gtk_file_selection_set_filename (GTK_FILE_SELECTION(file_selector), pf);
00492                 g_free (pf);
00493 
00494         } else if (name)
00495                 gtk_file_selection_set_filename (GTK_FILE_SELECTION(file_selector), name);
00496 
00497         /* Connect file storage func */
00498         gtk_object_set_data (GTK_OBJECT (file_selector), "P_FNAME", &fname);
00499         g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector)->ok_button),
00500                           "clicked",
00501 //                        G_CALLBACK (&GnomeAppService::file_ok_sel),
00502                           G_CALLBACK (file_ok),
00503                           (gpointer) file_selector); 
00504                            
00505         /* Ensure that the dialog box is destroyed when the user clicks a button. */
00506         g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector)->ok_button),
00507                                   "clicked",
00508                                   G_CALLBACK (gtk_widget_destroy), 
00509                                   (gpointer) file_selector); 
00510 
00511         g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector)->cancel_button),
00512                                   "clicked",
00513                                   G_CALLBACK (gtk_widget_destroy),
00514                                   (gpointer) file_selector); 
00515 
00516         if(fname)
00517                 g_free(fname);
00518         fname = NULL;
00519 
00520         XSM_DEBUG(DBG_L2, "Running Fsel Dialog modal" );
00521         gtk_dialog_run (GTK_DIALOG (GTK_FILE_SELECTION (file_selector)));
00522 //      gtk_window_set_modal (GTK_WINDOW (GTK_FILE_SELECTION (file_selector)), TRUE);
00523         XSM_DEBUG(DBG_L2, "Fsel done with:" << fname );
00524 
00525         if (fname && historyid_gconf_path){
00526                 XsmRescourceManager xrm("FilePathSelectionHistory", historyid_gconf_path);
00527                 xrm.Put("LastFile-0", fname);
00528         }
00529 
00530         if (historyid_gconf_path)
00531                 g_free (historyid_gconf_path);
00532         
00533         return fname;
00534 #endif
00535 }
00536 
00537 
00538 
00539 void  GnomeAppService::string_cb (gchar *string, gpointer data){
00540 }
00541 
00542 void GnomeAppService::destroy (GtkWidget *widget, GnomeAppService *p){
00543   if(p->fdlg == -1)
00544     p->fname=NULL;
00545   p->fdlg=0;
00546 }
00547 
00548 int GnomeAppService::check_file(gchar *fn){
00549         int r = 3;
00550         while (fn && r==3){
00551                 std::ifstream f;
00552                 f.open(fn, std::ios::in);
00553                 if(f.good()){
00554                         f.close();
00555                         if((r=choice(WRN_WARNING, fn, WRN_FILEEXISTS, 2, L_CANCEL, L_OVERWRITE, L_RETRY, 1)) == 1)
00556                                 return FALSE;
00557                         else if(r == 2)
00558                                 return TRUE;
00559                 }
00560                 else 
00561                         return TRUE;
00562         }
00563         return FALSE;
00564 }
00565 
00566 void GnomeAppService::ValueRequest(const gchar *title, const gchar *label, const gchar *infotxt, 
00567                                    UnitObj *uobj, double minv, double maxv, gchar *vfmt,
00568                                    double *value){
00569   GtkWidget *vbox;
00570   GtkWidget *hbox;
00571   GtkWidget *info;
00572   GtkWidget *input;
00573 
00574   GtkWidget *dialog = gtk_dialog_new_with_buttons (_(title),
00575                                                    NULL,
00576                                                    (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
00577                                                    GTK_STOCK_OK,
00578                                                    GTK_RESPONSE_ACCEPT,
00579                                                    NULL);
00580        
00581   vbox = gtk_vbox_new (FALSE, 0);
00582   gtk_widget_show (vbox);
00583 
00584   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
00585                      vbox, TRUE, TRUE, GNOME_PAD);
00586 
00587   if(infotxt){
00588     info = gtk_label_new (infotxt);
00589     gtk_widget_show (info);
00590     gtk_box_pack_start(GTK_BOX(vbox), info, TRUE, TRUE, GNOME_PAD);
00591   }
00592 
00593   input = mygtk_create_input(label, vbox, hbox);
00594   XSM_DEBUG(DBG_L2, "ValueRequest 2" );
00595   Gtk_EntryControl ECvar(uobj, "Value out of range !", value,
00596                          minv, maxv, vfmt, input);
00597 
00598 
00599   XSM_DEBUG(DBG_L2, "ValueRequest 3" );
00600   gtk_widget_show(dialog);
00601 
00602   gtk_dialog_run(GTK_DIALOG(dialog));
00603   gtk_widget_destroy (dialog);
00604 }
00605 
00606 // ============================================================
00607 // AppBase
00608 // ============================================================
00609 
00610 AppBase::AppBase(int InWindow, int bw){ 
00611         XSM_DEBUG(DBG_L2, "AppBase" ); 
00612         BorderWidth=bw; 
00613         ResName=NULL; 
00614         ResShow=NULL; 
00615         ResGeom=NULL; 
00616         ResGeomMan=NULL; 
00617         showstate=FALSE; 
00618         nodestroy=FALSE;
00619 }
00620 
00621 AppBase::~AppBase(){ 
00622         XSM_DEBUG(DBG_L2, "AppBase::~AppBase: " << (ResName?ResName:"--") << "..." ); 
00623         if(ResName){ // autosave show/hide state
00624                 XsmRescourceManager xrm ("Windows", ResName);
00625                 xrm.PutBool ("show", showstate);
00626 
00627                 SaveGeometry();
00628     
00629                 g_free(ResName);
00630         }
00631         if(!nodestroy){
00632                 XSM_DEBUG(DBG_L2, "  calling widget destroy" ); 
00633                 while(gtk_events_pending()) gtk_main_iteration();
00634                 destroy();
00635                 while(gtk_events_pending()) gtk_main_iteration();
00636         }
00637         XSM_DEBUG(DBG_L2, "AppBase::~AppBase done." );
00638 }
00639 
00640 void AppBase::AppWidgetInit(gchar *title, int InWindow){
00641         XSM_DEBUG(DBG_L2, "AppBase::WidgetInit: " << title );
00642         InWindowFlg = InWindow;
00643         // we have our own window
00644         if(InWindowFlg){
00645                 widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00646                 gtk_object_set_data (GTK_OBJECT (widget), "widget", widget);
00647                 gtk_window_set_title (GTK_WINDOW (widget), title);
00648                 gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, FALSE);
00649                 gtk_signal_connect(GTK_OBJECT(widget),
00650                                    "delete_event",
00651                                    GTK_SIGNAL_FUNC(AppBase::do_hide_callback),
00652                                    this);
00653                 gtk_container_border_width (GTK_CONTAINER (widget), BorderWidth);
00654         }else{
00655                 nodestroy = TRUE;
00656                 widget    = NULL;
00657         }
00658         vbox = gtk_vbox_new (FALSE, 0);
00659         gtk_object_set_data (GTK_OBJECT (widget), "vbox", vbox);
00660         gtk_widget_show (vbox);
00661         
00662         if(widget)
00663                 gtk_container_add (GTK_CONTAINER (widget), vbox);
00664         else
00665                 // we are only a pure widget
00666                 widget=vbox;
00667 }
00668 
00669 int AppBase::SetResName(const gchar *respath, const gchar *defaultval, gint defaultgeomman){ 
00670         ResName = g_strdup(respath);
00671 
00672         XsmRescourceManager xrm ("Windows", ResName);
00673         if (xrm.GetBool ("show", strcasecmp (defaultval, "true") == 0))
00674                 show ();
00675 
00676         LoadGeometry();
00677   
00678         xrm.PutBool ("Geometry-Manual", defaultgeomman);
00679   
00680         return 0;
00681 }
00682 
00683 gint AppBase::do_hide_callback (GtkWidget *window, GdkEventAny* e, AppBase *ab){
00684         ab->hide();
00685         return TRUE;
00686 }
00687 
00688 
00689 gint AppBase::askfor_close_callback (GtkWidget *window, GdkEventAny* e, AppBase *ab){
00690         ab->hide();
00691         return TRUE;
00692 }
00693 
00694 void AppBase::SaveGeometryCallback(AppBase *apb){
00695         apb->SaveGeometry();
00696 }
00697 
00698 int AppBase::SaveGeometry(int savealways){
00699         XsmRescourceManager xrm ("Windows", ResName);
00700 
00701         if(savealways || xrm.GetBool ("Geometry-Manual", TRUE)){
00702                 gint x,y;
00703                 gdk_window_get_root_origin (widget->window, &x, &y);
00704 
00705                 xrm.Put ("Geometry/x", x);
00706                 xrm.Put ("Geometry/y", y);
00707                 xrm.Put ("Geometry/w", -1);
00708                 xrm.Put ("Geometry/h", -1);
00709 
00710         }
00711   return 0;
00712 }
00713 
00714 int AppBase::LoadGeometry(){
00715         XsmRescourceManager xrm ("Windows", ResName);
00716 
00717         if (xrm.GetBool ("Geometry-Manual", TRUE)){
00718                 gint x,y,w,h;
00719                 xrm.Get ("Geometry/x", &x, "0");
00720                 xrm.Get ("Geometry/y", &y, "0");
00721                 xrm.Get ("Geometry/w", &w, "-1");
00722                 xrm.Get ("Geometry/h", &h, "-1");
00723                 if (x>0 && y>0)
00724                         gtk_widget_set_uposition (widget, x, y);
00725                 gtk_widget_set_size_request (widget, w, h);
00726         }
00727 
00728         return 0;
00729 }
00730 

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