
/*
 * gnoclStatusbar.c --
 *
 * This file implements the statusbar widget
 *
 * Copyright (c) 2001 P.G. Baum
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

/*
   History:
   2001-03: Begin of developement
 */

#include "gnocl.h"
#include <string.h>
#include <assert.h>

typedef struct
{
   GtkStatusbar *widget;
} StatusbarParams;
/*
static const StatusbarParams defaultParams = { 
   }; 
*/

static const GnoclWidgetOptions statusbarOptions[] =
{
   { NULL, 0, 0 }
};

/*
int statusbarConfigure( Tcl_Interp *interp, StatusbarParams *pp )
{
   GtkJustification justify = GTK_JUSTIFY_CENTER;

   if( pp->text )
      gtk_statusbar_set_text( pp->widget, pp->text );

   if( pp->justify )
   {
      if( !strcmp( pp->justify, "left" ) )
         justify = GTK_JUSTIFY_LEFT;
      else if( !strcmp( pp->justify, "right" ) )
         justify = GTK_JUSTIFY_RIGHT;
      else if( !strcmp( pp->justify, "center" ) )
         justify = GTK_JUSTIFY_CENTER;
      else if( !strcmp( pp->justify, "fill" ) )
         justify = GTK_JUSTIFY_FILL;
      else
      {
        Tcl_AppendResult( interp, "wrong parameter \"", 
               pp->justify, "\" for option justify. Must be one of"
               "left, right, center, or fill", (char *)NULL );
         return TCL_ERROR;
      }
   }
printf( "FIXME: doesn't work? justify: %d\n", justify );
   gtk_statusbar_set_justify( pp->widget, justify );

   gtk_statusbar_set_line_wrap( pp->widget, pp->lineWrap );

   return TCL_OK;
}
*/

static int statusbarFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{

   static char *cmds[] = { GNOCL_STD_CMD_NAMES,
         "configure", "push", "pop", "remove",
         NULL };
   enum cmdIdx {        GNOCL_STD_CMD_ENUMS, 
         ConfigureIdx, PushIdx, PopIdx, RemoveIdx };
   StatusbarParams *pp = (StatusbarParams *)data;
   int idx;

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

   switch( idx )
   {
      GNCOL_STD_CMD_CASE( interp, objc, objv, GTK_WIDGET( pp->widget ) );
            break;
      case ConfigureIdx:
            {
               Tcl_SetResult( interp, "statusbar can not be configured.",
                     TCL_STATIC );
               return TCL_ERROR;
               /*
               if( statusbarConfigure( interp, pp ) != TCL_OK )
                  return TCL_ERROR;
               gtk_widget_show_all( GTK_WIDGET( pp->widget ) );
               */
            }
            break;
     case PushIdx:
            {
               int contextId;
               int ret;
               if( objc != 4 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "context text" );
                  return TCL_ERROR;
               }
               contextId = gtk_statusbar_get_context_id( pp->widget,
                     Tcl_GetString( objv[2] ) );
               ret = gtk_statusbar_push( pp->widget, contextId, 
                     Tcl_GetString( objv[3] ) );
               Tcl_SetObjResult( interp, Tcl_NewIntObj( ret ) );
            }
            break;
      case PopIdx:
            {
               int contextId;
               if( objc != 3 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "context" );
                  return TCL_ERROR;
               }
               contextId = gtk_statusbar_get_context_id( pp->widget,
                     Tcl_GetString( objv[2] ) );
               gtk_statusbar_pop( pp->widget, contextId );
            }
            break;
      case RemoveIdx:
            {
               int contextId;
               int msgId;
               if( objc != 4 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "context id" );
                  return TCL_ERROR;
               }
               if( Tcl_GetIntFromObj( interp, objv[3], &msgId ) != TCL_OK )
                  return TCL_ERROR;
               contextId = gtk_statusbar_get_context_id( pp->widget,
                     Tcl_GetString( objv[2] ) );
               gtk_statusbar_remove( pp->widget, contextId, msgId );
            }
   }

   return TCL_OK;
}

int gnoclStatusbarCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   StatusbarParams *pp = g_new( StatusbarParams, 1 );
   char *name = gnoclGetAutoWidgetId();
   
   /*
   *pp = defaultParams;
   if( gnoclParseAllWidgetOpts( interp, objc, objv, 0,
         statusbarOptions, (char *)pp ) != TCL_OK )
      return TCL_ERROR;
   */
   if( objc != 1 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "" );
      return TCL_ERROR;
   }

   pp->widget = GTK_STATUSBAR( gtk_statusbar_new( ) );

   /*
   if( statusbarConfigure( interp, pp ) != TCL_OK )
   {
      gtk_widget_destroy( GTK_WIDGET( pp->widget ) );
      return TCL_ERROR;
   }
   */

   gnoclMemNameAndWidget( name, GTK_WIDGET( pp->widget ) );
   gtk_widget_show( GTK_WIDGET( pp->widget ) );

   Tcl_CreateObjCommand( interp, name, statusbarFunc, pp, NULL );
   Tcl_SetObjResult( interp, Tcl_NewStringObj( name, -1 ) );

   return TCL_OK;
}

