
/*
 * gnoclAppBar.c --
 *
 * This file implements the appBar 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
{
   Gnocl_BoolBool   hasStatus;
   Gnocl_BoolBool   hasProgress;
   Gnocl_StringBool interactivity;

   GnomeAppBar *widget;
} AppBarParams;

static const GnoclWidgetOptions appBarOptions[] =
{
   { "-hasStatus", GNOCL_BOOL, GNOCL_OFFSET( AppBarParams, hasStatus ) },
   { "-hasProgress", GNOCL_BOOL, GNOCL_OFFSET( AppBarParams, hasProgress ) },
   { "-interactivity", GNOCL_STRING, GNOCL_OFFSET( AppBarParams, 
         interactivity ) },
   { NULL, 0, 0 }
};

/*
int appBarConfigure( Tcl_Interp *interp, AppBarParams *pp )
{

   return TCL_OK;
}
*/

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

   static char *cmds[] = { GNOCL_STD_CMD_NAMES,
         "configure", "push", "pop", "clear",
         NULL };
   enum cmdIdx { GNOCL_STD_CMD_ENUMS,
         ConfigureIdx, PushIdx, PopIdx, ClearIdx };
   AppBarParams *pp = (AppBarParams *)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, "appBar can not be configured.",
                     TCL_STATIC );
               return TCL_ERROR;
               /*
               if( appBarConfigure( interp, pp ) != TCL_OK )
                  return TCL_ERROR;
               gtk_widget_show_all( GTK_WIDGET( pp->widget ) );
               */
            }
            break;
     case PushIdx:
            {
               if( objc != 3 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "status" );
                  return TCL_ERROR;
               }
               gnome_appbar_push( pp->widget, Tcl_GetString( objv[2] ) );
            }
            break;
      case PopIdx:
            {
               if( objc != 2 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "t" );
                  return TCL_ERROR;
               }
               gnome_appbar_pop( pp->widget );
            }
            break;
      case ClearIdx:
            {
               if( objc != 2 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, "t" );
                  return TCL_ERROR;
               }
               gnome_appbar_clear_stack( pp->widget );
            }
            break;
   }

   return TCL_OK;
}

int gnoclAppBarCmd( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   AppBarParams *pp = g_new( AppBarParams, 1 );
   GnomePreferencesType interactivity = GNOME_PREFERENCES_USER;
   char *name = gnoclGetAutoWidgetId();
   
   memset( pp, 0, sizeof( *pp ) );
   if( gnoclParseAllWidgetOpts( interp, objc, objv, 0,
         appBarOptions, (char *)pp ) != TCL_OK )
      return TCL_ERROR;

   if( pp->interactivity.changed )
   {
      if( !strcmp( pp->interactivity.val, "never" ) )
         interactivity = GNOME_PREFERENCES_NEVER;
      else if( !strcmp( pp->interactivity.val, "user" ) )
         interactivity = GNOME_PREFERENCES_USER;
      else if( !strcmp( pp->interactivity.val, "always" ) )
         interactivity = GNOME_PREFERENCES_ALWAYS;
      else
      {
         Tcl_AppendResult( interp, "wrong parameter \"", 
               pp->interactivity.val, "\" for option interactivity. "
               "Must be one of never, user, or always", (char *)NULL );
         return TCL_ERROR;

      }
   }

   if( !pp->hasProgress.changed )
      pp->hasProgress.val = 1;
   if( !pp->hasStatus.changed )
      pp->hasStatus.val = 1;

   pp->widget = GNOME_APPBAR( gnome_appbar_new( pp->hasProgress.val, 
         pp->hasStatus.val, interactivity ) );

   /*
   if( appBarConfigure( 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, appBarFunc, pp, NULL );
   Tcl_SetObjResult( interp, Tcl_NewStringObj( name, -1 ) );

   return TCL_OK;
}

