Main Page | Data Structures | Directories | File List | Data Fields | Globals

ProgMeter.c

Go to the documentation of this file.
00001 
00017 /* This file is part of tclSadie.
00018 
00019    tclSadie is free software; you can redistribute it and/or modify it
00020    under the terms of the GNU General Public License as published by
00021    the Free Software Foundation; either version 2 of the License, or
00022    (at your option) any later version.
00023 
00024    tclSadie is distributed in the hope that it will be useful, but
00025    WITHOUT ANY WARRANTY; without even the implied warranty of
00026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027    General Public License for more details.
00028 
00029    You should have received a copy of the GNU General Public License
00030    along with tclSadie; if not, write to the Free Software Foundation,
00031    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.  */
00032 
00033 #if HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif /* HAVE_CONFIG_H */
00036 #include <tcl.h>
00037 #include <tk.h>
00038 #include "tclsadie.h"
00039 
00041 enum create_template_index
00042 {
00043   ADD_GUICMD, ADD_TITLE, max_add_index
00044 };
00045 
00047 enum update_template_index
00048 {
00049   UPD_GUICMD, UPD_GNUM, UPD_VALUE, max_upd_index
00050 };
00051 
00053 enum destroy_template_index
00054 {
00055   DEL_GUICMD, DEL_GNUM, max_del_index
00056 };
00057 
00068 static Tcl_Interp *
00069 recover_interp (void * data)
00070 {
00071   tclsadie_app_datap_t private_data;
00072 
00073   if (data == NULL)
00074     return NULL;
00075   private_data = (tclsadie_app_datap_t) data;
00076   return private_data->main_interp;
00077 }
00078 
00088 int
00089 ProgMeter_Create (const char * title, void * data)
00090 {
00091   Tcl_Interp *interp;
00092   Tcl_Obj *tclcmd[max_add_index];
00093   int gaugenum = 0;
00094   int err = 1;
00095 
00096   interp = recover_interp (data);
00097   if (interp == NULL)
00098     return 0;
00099   tclcmd[ADD_GUICMD] = Tcl_NewStringObj ("gauge_gui_add", -1);
00100   if (tclcmd[ADD_GUICMD] != NULL)
00101     {
00102       Tcl_IncrRefCount (tclcmd[ADD_GUICMD]);
00103       tclcmd[ADD_TITLE] = Tcl_NewStringObj (title, -1);
00104       if (tclcmd[ADD_TITLE] != NULL)
00105         {
00106           Tcl_IncrRefCount (tclcmd[ADD_TITLE]);
00107           if ((Tcl_EvalObjv (interp, max_add_index, tclcmd, TCL_EVAL_GLOBAL)
00108                != TCL_OK)
00109               || (Tcl_GetIntFromObj (interp,
00110                                      Tcl_GetObjResult (interp),
00111                                      &gaugenum)
00112                   != TCL_OK))
00113             gaugenum = 0;
00114           else
00115             err = 0;
00116           Tcl_DecrRefCount (tclcmd[ADD_TITLE]);
00117         }
00118       Tcl_DecrRefCount (tclcmd[ADD_GUICMD]);
00119     }
00120   if (err)
00121     Tcl_BackgroundError (interp);
00122   return gaugenum;
00123 }
00124 
00137 int
00138 ProgMeter_Update (int gaugenum, double value, void * data)
00139 {
00140   Tcl_Interp * interp;
00141   Tcl_Obj * tclcmd[max_upd_index];
00142   int cancelval = -1;
00143   int err = 1;
00144 
00145   interp = recover_interp (data);
00146   if (interp == NULL)
00147     return 0;
00148   tclcmd[UPD_GUICMD] = Tcl_NewStringObj ("gauge_gui_update", -1);
00149   if (tclcmd[UPD_GUICMD] != NULL)
00150     {
00151       Tcl_IncrRefCount (tclcmd[UPD_GUICMD]);
00152       tclcmd[UPD_GNUM] = Tcl_NewIntObj (gaugenum);
00153       if (tclcmd[UPD_GNUM] != NULL)
00154         {
00155           Tcl_IncrRefCount (tclcmd[UPD_GNUM]);
00156           tclcmd[UPD_VALUE] = Tcl_NewDoubleObj (value);
00157           if (tclcmd[UPD_VALUE] != NULL)
00158             {
00159               Tcl_IncrRefCount (tclcmd[UPD_VALUE]);
00160               if ((Tcl_EvalObjv (interp, max_upd_index, tclcmd,
00161                                  TCL_EVAL_GLOBAL)
00162                    != TCL_OK)
00163                   || (Tcl_GetIntFromObj (interp,
00164                                          Tcl_GetObjResult (interp),
00165                                          &cancelval)
00166                       != TCL_OK))
00167                 cancelval = -1;
00168               else
00169                 err = 0;
00170               Tcl_DecrRefCount (tclcmd[UPD_VALUE]);
00171             }
00172           Tcl_DecrRefCount (tclcmd[UPD_GNUM]);
00173         }
00174       Tcl_DecrRefCount (tclcmd[UPD_GUICMD]);
00175     }
00176   if (err)
00177     Tcl_BackgroundError (interp);
00178   return cancelval;
00179 }
00180 
00181 
00191 int
00192 ProgMeter_Destroy (int gaugenum, void * data)
00193 {
00194   Tcl_Interp * interp;
00195   Tcl_Obj * tclcmd[max_del_index];
00196   int status = 0;
00197 
00198   interp = recover_interp (data);
00199   if (interp == NULL)
00200     return 0;
00201   tclcmd[DEL_GUICMD] = Tcl_NewStringObj ("gauge_gui_delete", -1);
00202   if (tclcmd[DEL_GUICMD] != NULL)
00203     {
00204       Tcl_IncrRefCount (tclcmd[DEL_GUICMD]);
00205       tclcmd[DEL_GNUM] = Tcl_NewIntObj (gaugenum);
00206       if (tclcmd[DEL_GNUM] != NULL)
00207         {
00208           Tcl_IncrRefCount (tclcmd[DEL_GNUM]);
00209           status = (Tcl_EvalObjv (interp, max_del_index, tclcmd,
00210                                   TCL_EVAL_GLOBAL)
00211                     == TCL_OK);
00212           Tcl_DecrRefCount (tclcmd[DEL_GNUM]);
00213         }
00214       Tcl_DecrRefCount (tclcmd[DEL_GUICMD]);
00215     }
00216   if (!status)
00217     Tcl_BackgroundError (interp);
00218   return status;
00219 }

Generated on Fri Jul 8 14:55:00 2005 for tclSadie by  doxygen 1.4.2