Ejemplo n.º 1
0
static int itemConfigure( Tcl_Interp *interp, int objc, 
      Tcl_Obj * const objv[], CanvasParams *param, GPtrArray *items )
{
   /* canvas itemConfigure tag-or-id ?option val ...? */
   guint k;
   int   ret = TCL_ERROR;

   if( items == NULL )
      return TCL_OK;

   for( k = 0; k < items->len; ++k )
   {
      Gnocl_CanvasItemInfo *info = GET_INFO( items, k );
      if( gnoclParseOptions( interp, objc - 2, objv + 2, info->options ) 
            != TCL_OK )
         goto cleanExit;
   }
   for( k = 0; k < items->len; ++k )
   {
      Gnocl_CanvasItemInfo *info = GET_INFO( items, k );
      if( (*info->setOptions)( interp, info ) != TCL_OK )
         goto cleanExit;
   }

   ret = TCL_OK;

cleanExit:
   for( k = 0; k < items->len; ++k )
   {
      Gnocl_CanvasItemInfo *info = GET_INFO( items, k );
      gnoclClearOptions( info->options );
   }

   return ret;
}
Ejemplo n.º 2
0
Archivo: socket.c Proyecto: zdia/gnocl
/***f* socket/gnoclSocketCmd
 * AUTHOR
 *	PGB
 * SOURCE
 */
int gnoclSocketCmd ( ClientData data, Tcl_Interp *interp,
					 int objc, Tcl_Obj * const objv[] )
{
	int       ret;
	GtkSocket *socket;

	if ( gnoclParseOptions ( interp, objc, objv, socketOptions ) != TCL_OK )
	{
		gnoclClearOptions ( socketOptions );
		return TCL_ERROR;
	}

	socket = GTK_SOCKET ( gtk_socket_new() );

	gtk_widget_show ( GTK_WIDGET ( socket ) );

	ret = gnoclSetOptions ( interp, socketOptions, G_OBJECT ( socket ), -1 );

	if ( ret == TCL_OK )
		ret = configure ( interp, socket, socketOptions );

	gnoclClearOptions ( socketOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( socket ) );
		return TCL_ERROR;
	}

	return gnoclRegisterWidget ( interp, GTK_WIDGET ( socket ), socketFunc );
}
Ejemplo n.º 3
0
int gnoclMenuSeparatorCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   int        ret;
   GtkSeparatorMenuItem *separator;

   if( gnoclParseOptions( interp, objc - 1, objv + 1, separatorOptions ) 
         != TCL_OK )
   {
      gnoclClearOptions( separatorOptions );
      return TCL_ERROR;
   }

   separator = GTK_SEPARATOR_MENU_ITEM( gtk_separator_menu_item_new( ) );
   gtk_widget_show( GTK_WIDGET( separator ) );
   /* gtk_widget_set_sensitive( GTK_WIDGET( para->menuItem ), 0 ); */

   ret = gnoclSetOptions( interp, separatorOptions, G_OBJECT( separator ), -1 );
   gnoclClearOptions( separatorOptions );

   if( ret != TCL_OK )
   {
      gtk_widget_destroy( GTK_WIDGET( separator ) );
      return TCL_ERROR;
   }


   return gnoclRegisterWidget( interp, GTK_WIDGET( separator ), separatorFunc );
}
Ejemplo n.º 4
0
Archivo: entry.c Proyecto: zdia/gnocl
/**
\brief
    Function associated with the widget.
*/
int gnoclEntryCmd (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
#ifdef DEBUG_ENTRY
	printf ( "entry/staticFuncs/gnoclEntryCmd\n" );
#endif

	EntryParams *para;
	int ret;

	if ( gnoclParseOptions ( interp, objc, objv, entryOptions ) != TCL_OK )
	{
		gnoclClearOptions ( entryOptions );
		return TCL_ERROR;
	}

	para = g_new ( EntryParams, 1 );

	para->entry = GTK_ENTRY ( gtk_entry_new( ) );
	para->interp = interp;
	para->variable = NULL;
	para->onChanged = NULL;
	para->inSetVar = 0;

	gtk_entry_set_activates_default ( para->entry, TRUE );


	gtk_widget_show ( GTK_WIDGET ( para->entry ) );

	ret = gnoclSetOptions ( interp, entryOptions, G_OBJECT ( para->entry ), -1 );

	if ( ret == TCL_OK )
	{
		ret = configure ( interp, para, entryOptions );
	}

	gnoclClearOptions ( entryOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( para->entry ) );
		g_free ( para );
		return TCL_ERROR;
	}

	para->name = gnoclGetAutoWidgetId();

	g_signal_connect ( G_OBJECT ( para->entry ), "destroy", G_CALLBACK ( destroyFunc ), para );

	gnoclMemNameAndWidget ( para->name, GTK_WIDGET ( para->entry ) );

	Tcl_CreateObjCommand ( interp, para->name, entryFunc, para, NULL );

	Tcl_SetObjResult ( interp, Tcl_NewStringObj ( para->name, -1 ) );

	return TCL_OK;
}
Ejemplo n.º 5
0
static int addItemTcl( ComboParams *para, Tcl_Interp *interp, 
      int objc, Tcl_Obj * const objv[] )
{
   GnoclOption addOption[] = 
   {
      { "-value", GNOCL_OBJ, NULL },    /* 0 */
      /* { "-icon", GNOCL_OBJ, NULL },     1 */
      { NULL }
   };
   /* static const int addValueIdx = 0; */ 

   int ret;

   /* id add text ? opt ...? */
   if( objc < 3 )
   {
      Tcl_WrongNumArgs( interp, 2, objv, "text ?option val ...?" );
      return TCL_ERROR;
   }

   if( gnoclParseOptions( interp, objc - 2, objv + 2, addOption ) != TCL_OK )
   {
      gnoclClearOptions( addOption );
      return TCL_ERROR;
   }

#if 0
   ret = addItem( para, objv[2], 
         addOption[addValueIdx].status == GNOCL_STATUS_CHANGED ?
               addOption[addValueIdx].val.obj : NULL );
#endif

   return ret;
}
Ejemplo n.º 6
0
int gnoclMenuBarCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   int        ret;
   GtkMenuBar *menuBar;
   
   if( gnoclParseOptions( interp, objc, objv, menuBarOptions ) 
         != TCL_OK )
   {
      gnoclClearOptions( menuBarOptions );
      return TCL_ERROR;
   }

   menuBar = GTK_MENU_BAR( gtk_menu_bar_new( ) );
   gtk_widget_show( GTK_WIDGET( menuBar ) );

   ret = gnoclSetOptions( interp, menuBarOptions, G_OBJECT( menuBar ), -1 );
   if( ret == TCL_OK )
      ret = configure( interp, menuBar, menuBarOptions );
   gnoclClearOptions( menuBarOptions );

   if( ret != TCL_OK )
   {
      gtk_widget_destroy( GTK_WIDGET( menuBar ) );
      return TCL_ERROR;
   }

   return gnoclRegisterWidget( interp, GTK_WIDGET( menuBar ), menuBarFunc );
}
Ejemplo n.º 7
0
/**
/brief
/author     William J Giddings
**/
int gnoclFontButtonCmd ( ClientData data, Tcl_Interp *interp,
						 int objc, Tcl_Obj * const objv[] )
{
	int       ret;
	GtkFontButton *button;

	if ( gnoclParseOptions ( interp, objc, objv, fontButtonOptions ) != TCL_OK )
	{
		gnoclClearOptions ( fontButtonOptions );
		return TCL_ERROR;
	}

	button = GTK_FONT_BUTTON ( gtk_font_button_new( ) );

	gtk_widget_show ( GTK_WIDGET ( button ) );

	ret = gnoclSetOptions ( interp, fontButtonOptions, G_OBJECT ( button ), -1 );
	gnoclClearOptions ( fontButtonOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( button ) );
		return TCL_ERROR;
	}

	return gnoclRegisterWidget ( interp, GTK_WIDGET ( button ), fontButtonFunc );
}
Ejemplo n.º 8
0
/**
\brief
    Description yet to be added.
**/
int gnoclNotebookCmd ( ClientData data, Tcl_Interp *interp,
					   int objc, Tcl_Obj * const objv[] )
{
	int ret;
	GtkWidget *widget;

	if ( gnoclParseOptions ( interp, objc, objv, notebookOptions )
			!= TCL_OK )
	{
		gnoclClearOptions ( notebookOptions );
		return TCL_ERROR;
	}

	widget = gtk_notebook_new();

	ret = gnoclSetOptions ( interp, notebookOptions,
							G_OBJECT ( widget ), -1 );

	if ( ret == TCL_OK )
		ret = configure ( interp, GTK_NOTEBOOK ( widget ), notebookOptions );

	gnoclClearOptions ( notebookOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( widget );
		return TCL_ERROR;
	}

	gtk_widget_show ( widget );

	return gnoclRegisterWidget ( interp, widget, notebookFunc );
}
Ejemplo n.º 9
0
/**
/brief
/author William J Giddings
/date   2008-08
**/
int gnoclDrawingAreaCmd (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
	int       ret;
	GtkWidget *widget;

	if ( gnoclParseOptions ( interp, objc, objv, drawingAreaOptions ) != TCL_OK )
	{
		gnoclClearOptions ( drawingAreaOptions );
		return TCL_ERROR;
	}

	widget = gtk_drawing_area_new ();

	gtk_widget_show ( GTK_WIDGET ( widget ) );

	gnoclSetOptions ( interp, drawingAreaOptions, G_OBJECT ( widget ), -1 );

	gnoclClearOptions ( drawingAreaOptions );


	/* register the new widget for use with the Tcl interpretor */
	return gnoclRegisterWidget ( interp, GTK_WIDGET ( widget ), drawingAreaFunc );

}
Ejemplo n.º 10
0
static int makeComboBox( Tcl_Interp *interp, int objc, 
      Tcl_Obj * const objv[], int isEntry )
{
   ComboParams     *para;
   GtkTreeModel    *model;
   int             ret;
   
   if( gnoclParseOptions( interp, objc, objv, boxOptions ) != TCL_OK )
   {
      gnoclClearOptions( boxOptions );
      return TCL_ERROR;
   }

   model = GTK_TREE_MODEL( gtk_list_store_new( 3, G_TYPE_STRING, 
         G_TYPE_STRING, GDK_TYPE_PIXBUF ) );

   para = g_new( ComboParams, 1 );
   para->interp = interp;
   para->onChanged = NULL;
   para->variable = NULL;
   para->name = gnoclGetAutoWidgetId();
   para->comboBox = GTK_COMBO_BOX( 
         isEntry ? gtk_combo_box_entry_new_with_model( model, VALUE_COLUMN ) 
                 : gtk_combo_box_new_with_model( model ) ); 
   para->inSetVar = 0;

   if( isEntry == 0 )
   {
      GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
      gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( para->comboBox ), 
            renderer, TEXT_COLUMN );
      gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( para->comboBox ), 
            renderer, "text", TEXT_COLUMN, NULL );
   }

   gtk_widget_show( GTK_WIDGET( para->comboBox ) ); 

   ret = gnoclSetOptions( interp, boxOptions, G_OBJECT( para->comboBox ), -1 );
   if( ret == TCL_OK )
      ret = configure( interp, para, boxOptions );
   gnoclClearOptions( boxOptions );

   if( ret != TCL_OK )
   {
      gtk_widget_destroy( GTK_WIDGET( para->comboBox ) );
      g_free( para );
      return TCL_ERROR;
   }
   g_signal_connect( GTK_OBJECT( para->comboBox ), "destroy", 
         G_CALLBACK( destroyFunc ), para );

   gnoclMemNameAndWidget( para->name, GTK_WIDGET( para->comboBox ) );

   Tcl_CreateObjCommand( interp, para->name, comboBoxFunc, para, NULL );
   Tcl_SetObjResult( interp, Tcl_NewStringObj( para->name, -1 ) );

   return TCL_OK;
}
Ejemplo n.º 11
0
Archivo: table.c Proyecto: zdia/gnocl
/**
/brief
/author     Peter G Baum, William J Giddings
**/
int gnoclTableCmd ( ClientData data, Tcl_Interp *interp,
					int objc, Tcl_Obj * const objv[] )
{
	int            ret = TCL_OK;
	GtkTable       *table;
	GtkFrame       *frame = NULL;
	GtkWidget      *widget;

	assert ( strcmp ( tableOptions[startFrameOpts].optName, "-label" ) == 0 );
	assert ( strcmp ( tableOptions[startCommonOpts].optName, "-name" ) == 0 );

	if ( gnoclParseOptions ( interp, objc, objv, tableOptions )
			!= TCL_OK )
	{
		gnoclClearOptions ( tableOptions );
		return TCL_ERROR;
	}

	table = GTK_TABLE ( gtk_table_new ( 1, 1, 0 ) );

	if ( needFrame ( tableOptions ) )
	{
		frame = GTK_FRAME ( gtk_frame_new ( NULL ) );
		gtk_container_add ( GTK_CONTAINER ( frame ), GTK_WIDGET ( table ) );
		widget = GTK_WIDGET ( frame );
	}

	else
		widget = GTK_WIDGET ( table );

	/* set default values */
	gtk_table_set_row_spacings ( table, GNOCL_PAD_TINY );

	gtk_table_set_col_spacings ( table, GNOCL_PAD );

	gtk_container_set_border_width ( GTK_CONTAINER ( table ), GNOCL_PAD_TINY );

	ret = configure ( interp, frame, table, tableOptions );

	gnoclClearOptions ( tableOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( widget );
		return TCL_ERROR;
	}

	gtk_widget_show_all ( widget );

	return gnoclRegisterWidget ( interp, widget, tableFunc );
}
Ejemplo n.º 12
0
Archivo: combo.c Proyecto: zdia/gnocl
int gnoclComboCmd ( ClientData data, Tcl_Interp *interp,
					int objc, Tcl_Obj * const objv[] )
{
	ComboParams *para;
	int ret;

	if ( gnoclParseOptions ( interp, objc, objv, comboOptions )
			!= TCL_OK )
	{
		gnoclClearOptions ( comboOptions );
		return TCL_ERROR;
	}

	para = g_new ( ComboParams, 1 );

	para->interp = interp;
	para->combo = GTK_COMBO ( gtk_combo_new( ) );
	para->variable = NULL;
	para->onChanged = NULL;
	para->inSetVar = 0;

	ret = gnoclSetOptions ( interp, comboOptions,
							G_OBJECT ( para->combo ), -1 );

	if ( ret == TCL_OK )
		ret = configure ( interp, para, comboOptions );

	gnoclClearOptions ( comboOptions );

	if ( ret != TCL_OK )
	{
		g_free ( para );
		gtk_widget_destroy ( GTK_WIDGET ( para->combo ) );
		return TCL_ERROR;
	}

	para->name = gnoclGetAutoWidgetId();

	g_signal_connect ( G_OBJECT ( para->combo ), "destroy",
					   G_CALLBACK ( destroyFunc ), para );

	gnoclMemNameAndWidget ( para->name, GTK_WIDGET ( para->combo ) );
	gtk_widget_show ( GTK_WIDGET ( para->combo ) );

	Tcl_CreateObjCommand ( interp, para->name, comboFunc, para, NULL );

	Tcl_SetObjResult ( interp, Tcl_NewStringObj ( para->name, -1 ) );

	return TCL_OK;
}
Ejemplo n.º 13
0
/**
\brief
\author
\date
**/
int gnoclFontSelectionCmd ( ClientData data, Tcl_Interp *interp,
                            int objc, Tcl_Obj * const objv[] )
{


    int ret = TCL_OK;
    GtkWidget *widget;


    if ( gnoclParseOptions ( interp, objc, objv, fontSelectOptions ) != TCL_OK )
    {
        gnoclClearOptions ( fontSelectOptions );
        return TCL_ERROR;
    }


    widget = gtk_font_selection_new() ;

    gtk_widget_show ( GTK_WIDGET ( widget ) );



    ret = gnoclSetOptions ( interp, fontSelectOptions, G_OBJECT ( widget ), -1 );

    if ( ret == TCL_OK )
    {
        ret = configure ( interp, G_OBJECT ( widget ), fontSelectOptions );
    }


    gnoclClearOptions ( fontSelectOptions );

    /* STEP 3)  -show the widget */

    if ( ret != TCL_OK )
    {
        gtk_widget_destroy ( GTK_WIDGET ( widget ) );
        return TCL_ERROR;
    }


    /* STEP 4)  -everything has worked, register the widget with the Tcl interpretor. */
    return gnoclRegisterWidget ( interp, GTK_WIDGET ( widget ), fontSelFunc );


    return ret;
}
Ejemplo n.º 14
0
int gnoclSpinButtonCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   SpinButtonParams *para;

   if( gnoclParseOptions( interp, objc, objv, spinButtonOptions ) != TCL_OK )
   {
      gnoclClearOptions( spinButtonOptions );
      return TCL_ERROR;
   }

   para = g_new( SpinButtonParams, 1 );
   para->spinButton = GTK_SPIN_BUTTON( gtk_spin_button_new( 
            GTK_ADJUSTMENT( gtk_adjustment_new( 0, 0, 100, 
            1, 10, 20 ) ), 1.0, 1 ) );
   para->interp = interp;
   para->variable = NULL;
   para->onValueChanged = NULL;
   para->inSetVar = 0;

   gtk_spin_button_set_numeric( para->spinButton, 1 );

   gtk_widget_show( GTK_WIDGET( para->spinButton ) );

   if( configure( interp, para, spinButtonOptions ) != TCL_OK )
   {
      g_free( para );
      gtk_widget_destroy( GTK_WIDGET( para->spinButton ) );
      gnoclClearOptions( spinButtonOptions );
      return TCL_ERROR;
   }
   gnoclClearOptions( spinButtonOptions );

   para->name = gnoclGetAutoWidgetId();

   g_signal_connect( G_OBJECT( para->spinButton ), "destroy", 
         G_CALLBACK( spinButtonDestroyFunc ), para );

   gnoclMemNameAndWidget( para->name, GTK_WIDGET( para->spinButton ) );

   Tcl_CreateObjCommand( interp, para->name, spinButtonFunc, para, NULL );

   Tcl_SetObjResult( interp, Tcl_NewStringObj( para->name, -1 ) );

   return TCL_OK;
}
Ejemplo n.º 15
0
/**
\brief
\author
\date
**/
int gnoclCalendarCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{

	int            ret = TCL_OK;
	GtkWidget      *calendar;

	if ( 0 )
	{
		if ( gnoclParseOptions ( interp, objc, objv, calendarOptions ) != TCL_OK )
		{
			gnoclClearOptions ( calendarOptions );
			return TCL_ERROR;
		}
	}

	calendar = gtk_calendar_new() ;

	gtk_widget_show ( GTK_WIDGET ( calendar ) );


	if ( 0 )
	{
		ret = gnoclSetOptions ( interp, calendarOptions, G_OBJECT ( calendar ), -1 );

		if ( ret == TCL_OK )
		{
			ret = configure ( interp, G_OBJECT ( calendar ), calendarOptions );
		}

		gnoclClearOptions ( calendarOptions );

		/* STEP 3)  -show the widget */

		if ( ret != TCL_OK )
		{
			gtk_widget_destroy ( GTK_WIDGET ( calendar ) );
			return TCL_ERROR;
		}
	}

	/* STEP 4)  -everything has worked, register the widget with the Tcl interpretor. */
	return gnoclRegisterWidget ( interp, GTK_WIDGET ( calendar ), calendarFunc );
}
Ejemplo n.º 16
0
Archivo: button.c Proyecto: zdia/gnocl
/**
\brief     Function to create and configure an new instance of the button widget.
**/
int gnoclButtonCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	int  ret;
	GtkButton *button;

	/* step 1) check validity of switches */

	if ( gnoclParseOptions ( interp, objc, objv, buttonOptions ) != TCL_OK )
	{
		gnoclClearOptions ( buttonOptions );
		return TCL_ERROR;
	}

	/* step 2) create an instance of the widget and 'show' it*/
	button = GTK_BUTTON ( gtk_button_new( ) );

	gtk_widget_show ( GTK_WIDGET ( button ) );


	/* step 3) check the options passed for the creation of the widget */
	ret = gnoclSetOptions ( interp, buttonOptions, G_OBJECT ( button ), -1 );

	/* step 4) if this is ok, then configure the new widget */
	if ( ret == TCL_OK )
	{
		ret = configure ( interp, button, buttonOptions );
	}

	/* step 5) clear the memory set assigned to the options */
	gnoclClearOptions ( buttonOptions );

	/* step 6) if the options passed were incorrect, then delete the widget */
	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( button ) );
		return TCL_ERROR;
	}

	/* step 7) the process has been successful, so 'register' the widget with the interpreter */
	return gnoclRegisterWidget ( interp, GTK_WIDGET ( button ), buttonFunc );
}
Ejemplo n.º 17
0
static int spinButtonFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   static const char *cmds[] = { "delete", "configure", "cget",
         "onValueChanged", NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx,
         OnValueChangedIdx };
   SpinButtonParams *para = (SpinButtonParams *)data;
   GtkWidget *widget = GTK_WIDGET( para->spinButton );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseOptions( interp, objc - 1, objv + 1, 
                     spinButtonOptions ) == TCL_OK )
               {
                  ret = configure( interp, para, spinButtonOptions );
               }
               gnoclClearOptions( spinButtonOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;

               switch( gnoclCget( interp, objc, objv, 
                     G_OBJECT( para->spinButton ), spinButtonOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para, spinButtonOptions, idx );
               }
            }
      case OnValueChangedIdx:
            {
               if( objc != 2 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, NULL );
                  return TCL_ERROR;
               }
               return doCommand( para, getObjValue( para->spinButton ), 0 );
            }
   }

   return TCL_OK;
}
Ejemplo n.º 18
0
Archivo: table.c Proyecto: zdia/gnocl
/**
/brief
/author     Peter G Baum, William J Giddings
**/
static int tableFunc ( ClientData data, Tcl_Interp *interp,
					   int objc, Tcl_Obj * const objv[] )
{
	const char *cmds[] = { "delete", "configure", "add", "addRow", "addColumn", "class", NULL };
	enum cmdIdx { DeleteIdx, ConfigureIdx, AddIdx, AddRowIdx, AddColumnIdx, ClassIdx };

	int idx;

	GtkWidget *widget = GTK_WIDGET ( data );
	GtkFrame *frame;
	GtkTable  *table;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( GTK_IS_FRAME ( widget ) )
	{
		frame = GTK_FRAME ( widget );
		table = GTK_TABLE ( gtk_bin_get_child ( GTK_BIN ( frame ) ) );
	}

	else
	{
		frame = NULL;
		table = GTK_TABLE ( widget );
	}

	/* For debugging purposes
	{
	   guint rows, columns;

	   g_object_get( G_OBJECT( table ), "n_rows", &rows, NULL );
	   g_object_get( G_OBJECT( table ), "n_columns", &columns, NULL );
	   printf( "rows: %d cols: %d\n", (int)rows, (int)columns );
	}
	*/

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
							   TCL_EXACT, &idx ) != TCL_OK )
		return TCL_ERROR;

	switch ( idx )
	{
		case ClassIdx:
			Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "table", -1 ) );
			break;
		case DeleteIdx:
			return gnoclDelete ( interp, widget, objc, objv );

		case ConfigureIdx:
			{
				int ret = TCL_ERROR;

				if ( gnoclParseOptions ( interp, objc - 1, objv + 1,
										 tableOptions ) == TCL_OK )
				{
					ret = configure ( interp, frame, table, tableOptions );
				}

				gnoclClearOptions ( tableOptions );

				return ret;
			}

			break;
		case AddIdx:
			return tableFuncAdd ( table, interp, objc, objv );
		case AddColumnIdx:
		case AddRowIdx:
			return addRowCol ( table, interp, objc, objv, idx == AddRowIdx );
	}

	return TCL_OK;
}
Ejemplo n.º 19
0
static int affine( Tcl_Interp *interp, int objc, Tcl_Obj * const objv[], 
      CanvasParams *param, GPtrArray *items, int type )
{
   GnoclOption options[] = {
      { "-absolute", GNOCL_BOOL, NULL },
      { "-reverseOrder", GNOCL_BOOL, NULL },
      { NULL }
   };
   static const int absoluteIdx     = 0;
   static const int reverseOrderIdx = 1;

   guint m; 
   int   noCoords;
   int   absolute = 0; 
   int   reverse = 0;

   if( objc < 4  )
   {
      /* canvas (affine|move|scale|rotate) tag-or-id  coords ?options ? */
      Tcl_WrongNumArgs( interp, 3, objv, 
            "list-of-coordinates ?option val ...?" );
      return TCL_ERROR;
   }
   if( gnoclParseOptions( interp, objc - 3, objv + 3, options ) != TCL_OK )
      return TCL_ERROR;

   if( options[absoluteIdx].status == GNOCL_STATUS_CHANGED )
      absolute = options[absoluteIdx].val.b;
   if( options[reverseOrderIdx].status == GNOCL_STATUS_CHANGED )
      reverse = options[reverseOrderIdx].val.b;
   gnoclClearOptions( options );

   if( absolute && reverse )
   {
      Tcl_SetResult( interp, "Options \"-reverseOrder\" is only valid "
            "for relative transformations.", TCL_STATIC );
      return TCL_ERROR;
   }

   if( Tcl_ListObjLength( interp, objv[3], &noCoords ) != TCL_OK )
      return TCL_ERROR;

   for( m = 0; m < items->len; ++m )
   {
      Gnocl_CanvasItemInfo *info = GET_INFO( items, m );
      int k;
      double af[6];
      Tcl_Obj *tp;

      for( k = 0; k < 6 && k < noCoords; ++k )
      {
         if( Tcl_ListObjIndex( interp, objv[3], k, &tp ) != TCL_OK )
            return TCL_ERROR;
         if( Tcl_GetDoubleFromObj( interp, tp, &af[k] ) != TCL_OK )
            return TCL_ERROR;
      }

      /*
         x' = af[0] * x + af[2] * y + af[4];
         y' = af[1] * x + af[3] * y + af[5];
      */
      switch( type )
      {
         case Affine:
               if( noCoords != 6 )
               {
                  Tcl_SetResult( interp, 
                        "size of list-of-coordinates must be 6", TCL_STATIC );
                  return TCL_ERROR;
               }
               break;
         case Move:
               if( noCoords != 2 )
               {
                  Tcl_SetResult( interp, "size of list-of-coordinates must "
                        "be 2 (delta-x and delta-y)", TCL_STATIC );
                  return TCL_ERROR;
               }
               af[4] = af[0];
               af[5] = af[1];

               af[0] = 1.; af[2] = 0.;
               af[1] = 0.; af[3] = 1.;
               break;
         case Scale:
               if( noCoords != 3 && noCoords != 4 )
               {
                  Tcl_SetResult( interp, "size of list-of-coordinates must "
                        "be 3 or 4 (center, x-scale and y-scale)", 
                        TCL_STATIC );
                  return TCL_ERROR;
               }
               else
               {
                  double x = af[0];
                  double y = af[1];
                  double scalex = af[2];
                  double scaley = (noCoords == 4) ? af[3] : scalex;
                  af[0] = scalex; af[2] = .0;     af[4] = x * (1. - scalex);
                  af[1] = .0;     af[3] = scaley; af[5] = y * (1. - scaley);
               }
               break;
         case Rotate:
               /* there seems to be some problems with the 
                  canvas without antialiasing and rotating 
                  (bizarre drawings)
               */
               if( noCoords != 3 )
               {
                  Tcl_SetResult( interp, "size of list-of-coordinates must "
                        "be 3 (center and angle)", TCL_STATIC );
                  return TCL_ERROR;
               }
               else
               {
                  double x = af[0];
                  double y = af[1];
                  double w = af[2];
                  const double cw = cos( w );
                  const double sw = sin( w );

                  af[0] = cw; af[2] = -sw; af[4] = x - x * cw + y * sw;
                  af[1] = sw; af[3] =  cw; af[5] = y - x * sw - y * cw;
               }
               break;
      }

      /*
      printf( "\nitem: %p absolute: %d\n", info->item, absolute );
      printf( "before:\n" );
      {
         int k;
         double af[6];
         gnome_canvas_item_i2c_affine( info->item, af );
         for( k = 0; k < 6; k += 2 )
            printf( "%d: %f ", k, af[k] );
         printf( "\n" );
         for( k = 1; k < 6; k += 2 )
            printf( "%d: %f ", k, af[k] );
         printf( "\n" );
      }
      printf( "affine:\n" );
      for( k = 0; k < 6; k += 2 )
         printf( "%d: %f ", k, af[k] );
      printf( "\n" );
      for( k = 1; k < 6; k += 2 )
         printf( "%d: %f ", k, af[k] );
      printf( "\n" );
      */

      if( absolute )
         gnome_canvas_item_affine_absolute( info->item, af );
      else
      {
         /* Well, *I* think this is a bug in gnome: 
            affine_relative should not be the reverse of what one
            would expect. Or do I have wrong expectations? */
         if( reverse )
            gnome_canvas_item_affine_relative( info->item, af );
         else
         {
            double bf[6];
            gnome_canvas_item_i2w_affine( info->item, bf );
            gnome_canvas_item_affine_absolute( info->item, af );
            gnome_canvas_item_affine_relative( info->item, bf );
         }
      }
   }

   return TCL_OK;
}
Ejemplo n.º 20
0
Archivo: table.c Proyecto: zdia/gnocl
/**
/brief
/author     Peter G Baum, William J Giddings
**/
static int tableFuncAdd ( GtkTable *table, Tcl_Interp *interp,
						  int objc, Tcl_Obj * const objv[] )
{
	int row, column;
	char *childName;
	GtkWidget *childWidget;
	AttachOptions ao;
	/* default is expand, fill and shrink */
	int ret = TCL_ERROR;

	if ( objc < 5 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv,
						   "add widget column row ?option val ...?" );
		return TCL_ERROR;
	}

	childName = Tcl_GetString ( objv[2] );

	childWidget = gnoclGetWidgetFromName ( childName, interp );

	if ( childWidget == NULL )
		return TCL_ERROR;

	column = getIntOrEnd ( interp, table, objv[3], 0 );

	if ( column < 0 )
		return TCL_ERROR;

	row = getIntOrEnd ( interp, table, objv[4], 1 );

	if ( row < 0 )
		return TCL_ERROR;

	/* packOptions to skip startIdx */
	if ( gnoclParseOptions ( interp, objc - 4, objv + 4, packOptions + 1 )
			== TCL_OK )
		ret = parsePackOptions ( interp, packOptions, &ao );

	if ( ret == TCL_OK )
	{
		if ( ao.useAlign )
		{
			GtkWidget *alignment = gtk_alignment_new ( ao.xAlign, ao.yAlign,
								   ao.xScale, ao.yScale );

			/* alignment is deleted on deletion of childWidget
			   only necessary, if not whole box is destroyed */
			g_signal_connect ( G_OBJECT ( childWidget ), "destroy",
							   G_CALLBACK ( alignDestroyFunc ), alignment );

			gtk_container_add ( GTK_CONTAINER ( alignment ), childWidget );
			gtk_widget_show ( alignment );
			childWidget = alignment;
		}

		gtk_table_attach ( table, childWidget,

						   column, column + ao.columnSpan,
						   row, row + ao.rowSpan,
						   ao.xOptions, ao.yOptions,
						   ao.xPad, ao.yPad );
	}

	return ret;
}
Ejemplo n.º 21
0
/**
\author     Peter G. Baum
**/
int gnoclClipboardCmd (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
	GnoclOption options[] =
	{
		{ "-primary", GNOCL_BOOL, NULL },
		{ NULL }
	};
	const int usePrimaryIdx = 0;

	static const char *cmd[] = { "hasText", "setText", "getText", "clear",
								 NULL
							   };
	enum optIdx { HasTextIdx, SetTextIdx, GetTextIdx, ClearIdx };
	int idx;
	int optNum;
	GtkClipboard *clip;
	int usePrimary = 0;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "option" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmd, "option", TCL_EXACT,
							   &idx ) != TCL_OK )
		return TCL_ERROR;

	if ( idx == SetTextIdx )
	{
		optNum = 2;

		if ( objc < 3 )
		{
			Tcl_WrongNumArgs ( interp, 1, objv, "text ?option value?" );
			return TCL_ERROR;
		}
	}

	else
	{
		optNum = 1;

		if ( objc < 2 )
		{
			Tcl_WrongNumArgs ( interp, 1, objv, NULL );
			return TCL_ERROR;
		}
	}

	if ( gnoclParseOptions ( interp, objc - optNum, objv + optNum, options )
			!= TCL_OK )
		return TCL_ERROR;

	if ( options[usePrimaryIdx].status == GNOCL_STATUS_CHANGED )
		usePrimary = options[usePrimaryIdx].val.b;

	clip = gtk_clipboard_get ( usePrimary ? gdk_atom_intern ( "PRIMARY", 1 )
							   : GDK_NONE );

	switch ( idx )
	{
		case HasTextIdx:
			{
				int ret = gtk_clipboard_wait_is_text_available ( clip );
				Tcl_SetObjResult ( interp, Tcl_NewBooleanObj ( ret ) );
			}

			break;
		case SetTextIdx:
			gtk_clipboard_set_text ( clip, Tcl_GetString ( objv[2] ), -1 );
			break;
		case GetTextIdx:
			{
				char *txt = gtk_clipboard_wait_for_text ( clip );

				if ( txt )
				{
					Tcl_SetObjResult ( interp, Tcl_NewStringObj ( txt, -1 ) );
					g_free ( txt );
				}

				/* FIXME? else error? */
			}

			break;
		case ClearIdx:
			gtk_clipboard_clear ( clip );
			break;
	}

	return TCL_OK;
}
Ejemplo n.º 22
0
int gnoclConfigureCmd (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
	GnoclOption options[] =
	{
		{ "-tooltip", GNOCL_BOOL, NULL },
		{ "-defaultIcon", GNOCL_OBJ, NULL },
		{ NULL }
	};
	const int tooltipIdx     = 0;
	const int defaultIconIdx = 1;

	int ret = TCL_ERROR;

	if ( gnoclParseOptions ( interp, objc, objv, options ) != TCL_OK )
		goto cleanExit;

	if ( options[defaultIconIdx].status == GNOCL_STATUS_CHANGED )
	{
		GnoclStringType type = gnoclGetStringType (
								   options[defaultIconIdx].val.obj );

		switch ( type )
		{
			case GNOCL_STR_EMPTY:
				gtk_window_set_default_icon_list ( NULL );
				break;
			case GNOCL_STR_FILE:
				{
					GdkPixbuf *pix = gnoclPixbufFromObj ( interp,
														  options + defaultIconIdx );
					GList *list = NULL;

					if ( pix == NULL )
						goto cleanExit;

					list = g_list_append ( list, pix );

					gtk_window_set_default_icon_list ( list );

					g_list_free ( list );
				}

				break;
			default:
				Tcl_AppendResult ( interp, "Unknown type for \"",
								   Tcl_GetString ( options[defaultIconIdx].val.obj ),
								   "\" must be of type FILE (%/) or empty", NULL );
				goto cleanExit;
		}
	}

	if ( options[tooltipIdx].status == GNOCL_STATUS_CHANGED )
	{
		if ( options[tooltipIdx].val.b )
			gtk_tooltips_enable ( gnoclGetTooltips() );
		else
			gtk_tooltips_disable ( gnoclGetTooltips() );
	}

	ret = TCL_OK;

cleanExit:
	gnoclClearOptions ( options );
	return ret;
}
Ejemplo n.º 23
0
int gnoclCanvasCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   CanvasParams *para;
   int          ret;

   if( gnoclParseOptions( interp, objc, objv, canvasOptions ) != TCL_OK )
   {
      gnoclClearOptions( canvasOptions );
      return TCL_ERROR;
   }

   para = g_new( CanvasParams, 1 );

   /* what is that for? Found in canvas demos. */
   gtk_widget_push_colormap( gdk_rgb_get_cmap() );

   /* antialiased is default */
   if( canvasOptions[antialiasedIdx].status == GNOCL_STATUS_CHANGED &&
         canvasOptions[antialiasedIdx].val.b == 0 )
   {
      para->canvas = GNOME_CANVAS( gnome_canvas_new( ) );
   }
   else
      para->canvas = GNOME_CANVAS( gnome_canvas_new_aa( ) );

   gtk_widget_show( GTK_WIDGET( para->canvas ) );

   /*
   TODO: what is that for? Found in canvas demos. 
   gtk_widget_pop_colormap(); 
   */

   gnome_canvas_set_center_scroll_region( para->canvas, 0 );
   ret = gnoclSetOptions( interp, canvasOptions, 
         G_OBJECT( para->canvas ), -1 );
   if( ret == TCL_OK )
      ret = configure( interp, para, canvasOptions );
   gnoclClearOptions( canvasOptions );

   if( ret != TCL_OK )
   {
      gtk_widget_destroy( GTK_WIDGET( para->canvas ) );
      g_free( para );
      return TCL_ERROR;
   }

   para->name = gnoclGetAutoWidgetId();
   gnoclMemNameAndWidget( para->name, GTK_WIDGET( para->canvas ) );

   /* TODO: g_hash_table_new_full */
   para->tagToItems = g_hash_table_new_full( g_str_hash, g_str_equal,
         g_free, ptrArrayFree );
   para->interp = interp;
   g_signal_connect_after( G_OBJECT( para->canvas ), "destroy", 
         G_CALLBACK( destroyFunc ), para );

   Tcl_CreateObjCommand( interp, para->name, canvasFunc, para, NULL );

   Tcl_SetObjResult( interp, Tcl_NewStringObj( para->name, -1 ) );

   return TCL_OK;
}
Ejemplo n.º 24
0
Archivo: table.c Proyecto: zdia/gnocl
/**
/brief
/author     Peter G Baum, William J Giddings
**/
static int addRowCol ( GtkTable *table, Tcl_Interp *interp,
					   int objc, Tcl_Obj * const objv[], int addRowFlag )
{
	int              ret = TCL_ERROR;
	AttachOptions    ao;
	int              start = -1;

	if ( objc < 2 )
	{
		/* id add{Row,Column} list ... */
		Tcl_WrongNumArgs ( interp, 2, objv,
						   "widget-list ?option val ...?" );
		return TCL_ERROR;
	}

	if ( gnoclParseOptions ( interp, objc - 2, objv + 2, packOptions ) == TCL_OK )
	{
		ret = parsePackOptions ( interp, packOptions, &ao );

		if ( packOptions[startIdx].status == GNOCL_STATUS_CHANGED )
			start = packOptions[startIdx].val.i;
	}

	gnoclClearOptions ( packOptions );

	if ( ret == TCL_OK )
	{
		int    noChilds;
		int    n;
		int    column = 0,
						row = 0;

		if ( start >= 0 )
		{
			if ( addRowFlag )
				column = start;
			else
				row = start;
		}

		else
		{
			if ( addRowFlag )
				row = getMaxRowCol ( table, 1 );
			else
				column = getMaxRowCol ( table, 0 );
		}

		if ( Tcl_ListObjLength ( interp, objv[2], &noChilds ) != TCL_OK
				|| noChilds < 1 )
		{
			Tcl_SetResult ( interp, "widget-list must be proper list",
							TCL_STATIC );
			noChilds = 0;
			ret = TCL_ERROR;
		}

		for ( n = 0; n < noChilds; ++n )
		{
			GtkWidget *childWidget;
			Tcl_Obj *tp;
			const char *childName;

			if ( Tcl_ListObjIndex ( interp, objv[2], n, &tp ) != TCL_OK )
			{
				ret = TCL_ERROR;
				break;
			}

			/* TODO? if list object: options */
			childName = Tcl_GetString ( tp );

			/* empty widget-ID: skip this row/column */
			if ( *childName )
			{
				childWidget = gnoclChildNotPacked ( childName, interp );

				if ( childWidget == NULL )
				{
					ret = TCL_ERROR;
					break;
				}

				if ( ao.useAlign )
				{
					GtkWidget *alignment = gtk_alignment_new ( ao.xAlign, ao.yAlign,
										   ao.xScale, ao.yScale );
					/* alignment is deleted on deletion of childWidget
					   only necessary, if not whole box is destroyed */
					g_signal_connect ( G_OBJECT ( childWidget ), "destroy",
									   G_CALLBACK ( alignDestroyFunc ), alignment );

					gtk_container_add ( GTK_CONTAINER ( alignment ), childWidget );
					gtk_widget_show ( alignment );
					childWidget = alignment;
				}

				gtk_table_attach ( table, childWidget,

								   column, column + ao.columnSpan,
								   row, row + ao.rowSpan,
								   ao.xOptions, ao.yOptions,
								   ao.xPad, ao.yPad );
			}

			if ( addRowFlag )
				column += ao.columnSpan;
			else
				row += ao.rowSpan;
		}
	}

	return ret;
}
Ejemplo n.º 25
0
/****f* widget/gnoclLinkButtonCmd
 * AUTHOR
 *  PGB
 * SOURCE
 */
int gnoclLinkButtonCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	int         ret;
	GtkWidget   *widget;
	int         k, a, b;
	GnoclOption *pop;
	char        *str_label, *str_uri ;

	/* determine which type of linkButton to create... */
	/*
	 * Do some pre-checking on the options set.
	 * The gtk library has two forms of linkbutton, on with a label or one that simply shows the uri
	 * these values are set at initialisation and so the argument line needs to be parsed so
	 * that a decision can be made as to which type of widget to create.
	 *
	 */

	/*
	 * Parse all Options
	 * Picking out individual options from the active script command line.
	 */

	for ( k = 1; k < objc; k += 2 )
	{
		int idx;

		if ( gnoclGetIndexFromObjStruct (
					interp, objv[k],
					( char ** ) &linkButtonOptions[0].optName,
					sizeof ( GnoclOption ),
					"option",
					TCL_EXACT, &idx ) != TCL_OK )
		{
			return -1;
		}


		/* originally, commented out */
		/*
		printf( "parsing %s -> %s\n", Tcl_GetString( objv[k] ), linkButtonOptions[idx].optName);
		*/

		if ( strcmp ( Tcl_GetString ( objv[k] ), "-text" ) == 0 )
		{
			str_label = Tcl_GetString ( objv[k+1] );
			a = 1;
		}

		if ( strcmp ( Tcl_GetString ( objv[k] ), "-uri" ) == 0 )
		{
			str_uri = Tcl_GetString ( objv[k+1] );
			b = 1;
		}


	}   /* decide what to do based on above values in step 2*/


	/* STEP 1)  -check validity of switches */

	if ( gnoclParseOptions ( interp, objc, objv, linkButtonOptions ) != TCL_OK )
	{
		gnoclClearOptions ( linkButtonOptions );
		return TCL_ERROR;
	}

	/* STEP 2)  -create widget, configure it, then clear memory */

	/*
	 * a== 1 and b == 1, then create a button with a label.
	 * if a!= 1 and b == 1, then create a button with the URI as label
	 * if b != 1, then this is an error. -uri is a mandatory option.
	 */

	if ( a == 1 && b == 1 )
	{
		//printf ("label %s and URI %s\n", str_label, str_uri );
		widget = GTK_WIDGET ( gtk_link_button_new_with_label ( str_uri, str_label ) );
	}

	else if ( b == 1 )
	{
		//printf ("URI %s\n", str_uri );
		widget = gtk_link_button_new ( str_uri );
	}

	else
	{
		//printf ("error\n" );
	}

	a = 0; b = 0;


	gtk_widget_show ( GTK_WIDGET ( widget ) );

	ret = gnoclSetOptions ( interp, linkButtonOptions, G_OBJECT ( widget ), -1 );

	if ( ret == TCL_OK )
	{
		ret = configure ( interp, G_OBJECT ( widget ), linkButtonOptions );
	}

	gnoclClearOptions ( linkButtonOptions );

	/* STEP 3)  -show the widget */

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( widget ) );
		return TCL_ERROR;
	}

	/* STEP 4)  -everything has worked, register the widget with the Tcl interpretor. */
	return gnoclRegisterWidget ( interp, GTK_WIDGET ( widget ), linkButtonFunc );
}
Ejemplo n.º 26
0
Archivo: label.c Proyecto: zdia/gnocl
/**
\brief
\author     Peter G Baum, William J Giddings
\date
**/
int gnoclLabelCmd (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
#ifdef DEBUG_LABEL
	printf ( "label/staticFuncs/gnoclLabelCmd\n" );
#endif

	LabelParams *para;
	int ret;

	if ( gnoclParseOptions ( interp, objc, objv, labelOptions ) != TCL_OK )
	{
		gnoclClearOptions ( labelOptions );
		return TCL_ERROR;
	}

	para = g_new ( LabelParams, 1 );

	para->label = GTK_LABEL ( gtk_label_new ( NULL ) );
	para->interp = interp;
	para->textVariable = NULL;
	para->onChanged = NULL;
	para->inSetVar = 0;

	gtk_widget_show ( GTK_WIDGET ( para->label ) );

	/* added 14/Jan/2010 */
	gtk_label_set_use_markup ( para->label, TRUE );


	ret = gnoclSetOptions ( interp, labelOptions, G_OBJECT ( para->label ), -1 );

	if ( ret == TCL_OK )
	{
		ret = configure ( interp, para, labelOptions );
	}

	gnoclClearOptions ( labelOptions );

	if ( ret != TCL_OK )
	{
		gtk_widget_destroy ( GTK_WIDGET ( para->label ) );
		g_free ( para );
		return TCL_ERROR;
	}

	para->name = gnoclGetAutoWidgetId();

	g_signal_connect ( G_OBJECT ( para->label ), "destroy", G_CALLBACK ( destroyFunc ), para );

	gnoclMemNameAndWidget ( para->name, GTK_WIDGET ( para->label ) );

	Tcl_CreateObjCommand ( interp, para->name, labelFunc, para, NULL );

	Tcl_SetObjResult ( interp, Tcl_NewStringObj ( para->name, -1 ) );

	return TCL_OK;
}
Ejemplo n.º 27
0
/****f* callback/create
 * AUTHOR
 *	PGB
 * SOURCE
 */
static int create ( Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	GnoclOption options[] =
	{
		{ "-interval", GNOCL_OBJ, NULL },    /* 0 */
		{ "-priority", GNOCL_INT, NULL },    /* 1 */
		{ NULL }
	};
	const int intervalIdx = 0;
	const int priorityIdx = 1;

	int interval = -1;
	int priority = 0;
	int id;
	GnoclCommandData *cs;

	if ( objc < 3 )
	{
		Tcl_WrongNumArgs ( interp, 2, objv, "script" );
		return TCL_ERROR;
	}

	if ( gnoclParseOptions ( interp, objc - 2, objv + 2, options ) != TCL_OK )
		goto errorExit;

	if ( options[priorityIdx].status == GNOCL_STATUS_CHANGED )
		priority = options[priorityIdx].val.i;

	/* TODO? test priority range? */

	if ( options[intervalIdx].status == GNOCL_STATUS_CHANGED )
	{
		Tcl_Obj * const obj = options[intervalIdx].val.obj;

		if ( Tcl_GetIntFromObj ( NULL, obj, &interval ) != TCL_OK )
		{
			if ( strcmp ( Tcl_GetString ( obj ), "idle" ) != 0 )
			{
				Tcl_AppendResult ( interp,
								   "Expected integer or \"idle\", but got \"",
								   Tcl_GetString ( obj ), "\"", NULL );
				goto errorExit;
			}
		}

		else if ( interval <= 0 )
		{
			Tcl_SetResult ( interp, "interval must be greater zero.",
							TCL_STATIC );
			goto errorExit;
		}

	}

	gnoclClearOptions ( options );

	cs = g_new ( GnoclCommandData, 1 );
	cs->command = g_strdup ( Tcl_GetString ( objv[2] ) );
	cs->interp = interp;


	if ( interval <= 0 ) /* idle */
	{
		id = g_idle_add_full ( G_PRIORITY_DEFAULT_IDLE - priority,
							   doCommand, cs, destroyCmd );
	}

	else
	{
		id = g_timeout_add_full ( G_PRIORITY_DEFAULT_IDLE - priority, interval,
								  doCommand, cs, destroyCmd );
	}

	Tcl_SetObjResult ( interp, Tcl_NewIntObj ( id ) );

	return TCL_OK;


errorExit:
	gnoclClearOptions ( options );

	return TCL_ERROR;
}
Ejemplo n.º 28
0
static int canvasCreateItem( Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[], CanvasParams *param )
{
   const char *items[] = { "line", "rectangle", "ellipse", "bPath",
         "text", "richText", "widget", "image", "polygon", "clipGroup", 
         NULL };
   enum itemIdx { LineIdx, RectangleIdx, EllipseIdx,  BPathIdx,
         TextIdx, RichTextIdx, WidgetIdx, ImageIdx, PolygonIdx, ClipGroupIdx };

   static int noItems = 0;

   Gnocl_CanvasItemInfo *info;
   GnoclItemCreateFunc *func;
   int  idx;
   int  k;
   char buffer[64];

   if( objc < 3 )
   {
      Tcl_WrongNumArgs( interp, 2, objv, 
            /* canvas create */ "type ?option val ...?" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[2], items, "item type", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case LineIdx:        func = gnoclCanvasCreateLine; break;
      case RectangleIdx:   func = gnoclCanvasCreateRectangle; break;
      case EllipseIdx:     func = gnoclCanvasCreateEllipse; break;
      case BPathIdx:       func = gnoclCanvasCreateBPath; break;
      case TextIdx:        func = gnoclCanvasCreateText; break;
      case RichTextIdx:    func = gnoclCanvasCreateRichText; break;
      case WidgetIdx:      func = gnoclCanvasCreateWidget; break;
      case ImageIdx:       func = gnoclCanvasCreateImage; break;
      case PolygonIdx:     func = gnoclCanvasCreatePolygon; break;
      case ClipGroupIdx:   func = gnoclCanvasCreateClipGroup; break;
      default:             assert( 0 );
                           return TCL_ERROR; /* should never happen */
   }

   info = (*func)( interp, objc, objv, gnome_canvas_root( param->canvas ) );
   if( info == NULL )
      return TCL_ERROR;

   gnoclParseOptions( NULL, 0, NULL, info->options );

   g_object_set_data( G_OBJECT( info->item ), "gnocl::info", info );

   info->id = ++noItems;
   info->tags = g_ptr_array_new( );
   info->canvasParams = param;
   for( k = 0; k < GNOCL_CANVAS_ON_COUNT; ++k )
      info->scripts[k] = NULL;

   sprintf( buffer, "%d", noItems );
   gnoclCanvasAddTag( interp, param, info, buffer );
   gnoclCanvasAddTag( interp, param, info, "all" );

   gnoclClearOptions( info->options );
   if( gnoclParseOptions( interp, objc - 2, objv + 2, info->options ) )
      return TCL_ERROR; /* TODO: free all */

   if( (*info->setOptions)( interp, info ) != TCL_OK )
      return TCL_ERROR; /* TODO: free all */

   gnoclClearOptions( info->options );
   
   g_signal_connect( G_OBJECT( info->item ), "destroy", 
         G_CALLBACK( destroyItemFunc ), info );

   /* gnome_canvas_update_now( param->canvas ); */
   Tcl_SetObjResult( interp, Tcl_NewIntObj( noItems ) );

   return TCL_OK;
}