
/* Provide links to for text tags */
/* WJG 27/12/07 */
int gnoclOptOnEvent( Tcl_Interp *interp, GnoclOption *opt, 
	GObject *obj, Tcl_Obj **ret )
{	
	return gnoclConnectOptCmd( interp, obj,"event", 
		G_CALLBACK( doOnEvent ), opt, NULL, ret );
}

/* function called from the event handler */
static void doOnEvent (
	GtkTextTag *texttag,
	GObject *arg1, 
	GdkEvent *event,
	GtkTextIter *arg2,
	gpointer data )
{
   GnoclCommandData *cs = (GnoclCommandData *)data;
	
   GnoclPercSubst ps[] = {
      { 't', GNOCL_STRING },
      { 'w', GNOCL_STRING },
      { 'x', GNOCL_INT },
      { 'y', GNOCL_INT },  
	{ 'b', GNOCL_INT },	
	  { 'X', GNOCL_INT },
	  { 'Y', GNOCL_INT },
	  { 's', GNOCL_INT },
      { 0 }
   };	
	
   /* most of these events are not reported by the tag */
   switch( event->type )
   {   	   

   /* these are reported */
   case GDK_MOTION_NOTIFY: 	ps[0].val.str = "motionNotify"; break;
	case GDK_BUTTON_PRESS:  
	case GDK_2BUTTON_PRESS: 
	case GDK_3BUTTON_PRESS:  
  	case GDK_BUTTON_RELEASE: 
		switch ( event->type ) {
			case GDK_BUTTON_PRESS:  	ps[0].val.str = "buttonPress"; break;
			case GDK_2BUTTON_PRESS: 	ps[0].val.str = "doubleButtonPress"; break;
			case GDK_3BUTTON_PRESS:  	ps[0].val.str = "tripleButtonPress"; break;
  			case GDK_BUTTON_RELEASE:	ps[0].val.str = "buttonRelease"; break;
			default:  assert( 0 ); break;
			}			
			// ps[1].val.str = ((GdkEventButton*)event)->window ; 
			ps[2].val.i = ((GdkEventButton*)event)->x;
   			ps[3].val.i = ((GdkEventButton*)event)->y;
   			ps[4].val.i = ((GdkEventButton*)event)->button;
   			ps[5].val.i = ((GdkEventButton*)event)->x_root;
   			ps[6].val.i = ((GdkEventButton*)event)->y_root;
   			ps[7].val.i = ((GdkEventButton*)event)->state;
			break;

   / * these are not */
	case GDK_NOTHING:   		ps[0].val.str = "nothing"; break;
	case GDK_DELETE:   			ps[0].val.str = "delete"; break;
	case GDK_DESTROY:   		ps[0].val.str = "destroy"; break;
	case GDK_EXPOSE:   			ps[0].val.str = "expose"; break;			
  	case GDK_KEY_PRESS:   		ps[0].val.str = "keyPress"; break;
  	case GDK_KEY_RELEASE:   	ps[0].val.str = "keyRelease"; break;
  	case GDK_ENTER_NOTIFY:   	ps[0].val.str = "enterNotify"; break;
  	case GDK_LEAVE_NOTIFY:   	ps[0].val.str = "leaveNotify"; break;
  	case GDK_FOCUS_CHANGE:   	ps[0].val.str = "focusChange"; break;
  	case GDK_CONFIGURE:   		ps[0].val.str = "configure"; break;
  	case GDK_MAP:   			ps[0].val.str = "map"; break;
  	case GDK_UNMAP:   			ps[0].val.str = "unmap"; break;
  	case GDK_PROPERTY_NOTIFY:   ps[0].val.str = "propertyNotify"; break;
  	case GDK_SELECTION_CLEAR:   ps[0].val.str = "selectionClear"; break;
  	case GDK_SELECTION_REQUEST: ps[0].val.str = "selectrionRequest"; break;
  	case GDK_SELECTION_NOTIFY:  ps[0].val.str = "selectionNotify"; break;
  	case GDK_PROXIMITY_IN:   	ps[0].val.str = "proximityIn"; break;
  	case GDK_PROXIMITY_OUT:   	ps[0].val.str = "proximityOut"; break;
  	case GDK_DRAG_ENTER:   		ps[0].val.str = "dragEnter"; break;
  	case GDK_DRAG_LEAVE:	   	ps[0].val.str = "dragLeave"; break;
  	case GDK_DRAG_MOTION:   	ps[0].val.str = "dragMotion"; break;
  	case GDK_DRAG_STATUS:   	ps[0].val.str = "dragStatus"; break;
  	case GDK_DROP_START:   		ps[0].val.str = "dropStart"; break;
  	case GDK_DROP_FINISHED:   	ps[0].val.str = "dropFinished"; break;
  	case GDK_CLIENT_EVENT:   	ps[0].val.str = "clientEvent"; break;
  	case GDK_VISIBILITY_NOTIFY: ps[0].val.str = "visibilityNotify"; break;
  	case GDK_NO_EXPOSE:   		ps[0].val.str = "noExpose"; break;
  	case GDK_SCROLL:   			ps[0].val.str = "scroll"; break;
  	case GDK_WINDOW_STATE:   	ps[0].val.str = "windowState"; break;
  	case GDK_SETTING:   		ps[0].val.str = "setting"; break;
  	case GDK_OWNER_CHANGE:   	ps[0].val.str = "ownerChange"; break;
  	case GDK_GRAB_BROKEN:   	ps[0].val.str = "grabBroken"; break;
    default: assert( 1 ); break;
   }
    
   /* other settings, mouse pointer etc can be obtained from the window structure */     
   gnoclPercentSubstAndEval( cs->interp, ps, cs->command, 1 );   
}
