Events.c

Go to the documentation of this file.
00001 /*
00002  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
00003  * Copyright (C) 1998-2001 - ENPC - Jean-Philipe Chancelier
00004  * 
00005  * This file must be used under the terms of the CeCILL.
00006  * This source file is licensed as described in the file COPYING, which
00007  * you should have received as part of this distribution.  The terms
00008  * are also available at    
00009  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
00010  *
00011  */
00012 
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include "WindowList.h"
00016 #include "Events.h"
00017 #include "GetProperty.h"
00018 #include "dynamic_menus.h"
00019 
00020 typedef struct but
00021 { int win; /* graphic window containing the locator */
00022   int x,y; /* Locator position  coordinates */
00023   int ibutton; /*mouse button or key*/
00024   int motion; /* is it a move event */
00025   int  release; /* is it a release event */
00026 } But;
00027 
00028 
00029 
00030 int demo_menu_activate=0; /* add a demo menu in the graphic Window */
00031 
00032 
00033 #define MaxCB 50 /* We keep the last  MaxCB click events on a queue just in case */
00034 static But ClickBuf[MaxCB];
00035 static int lastc = 0;
00036 static int wait_for_click=0; /* set to 1 when in xclick or xgetmouse to disable event handler*/
00037 static int event_select=5;/* record only press and release events, ignoring move*/
00038 
00039 /* next used to prevent the user from destroying a graphic window 
00040  * when acquiring for example a zoom rectangle */
00041 static int sci_graphic_protect = 0;
00042 static Scig_deletegwin_handler scig_deletegwin_handler = scig_deletegwin_handler_sci;
00043 
00044 /*--------------------------------------------------------------------------*/
00045 
00046 int scig_click_handler_none (int win,int x,int y,int ibut,
00047                              int motion,int release) 
00048 {return 0;}
00049 /*--------------------------------------------------------------------------*/
00050 
00051 int scig_click_handler_sci (int win,int x,int y,int ibut,int motion,int release)
00052 {
00053   static char buf[256];
00054   sciPointObj * pFigure = NULL ;
00055 
00056   pFigure = getFigureFromIndex(win);
00057 
00058   if(pFigure == NULL)
00059   {
00060     return 0;
00061   }
00062 
00063   if (   sciGetIsEventHandlerEnable(pFigure)
00064       && strlen(sciGetEventHandler(pFigure)) > 0 )
00065   {
00066     sprintf(buf,"%s(%d,%d,%d,%d)",sciGetEventHandler(pFigure),win,x,y,ibut);
00067     StoreCommand(buf);
00068     return 1;
00069   }
00070   else
00071   {
00072     return 0;
00073   }
00074 }
00075 
00076 /*--------------------------------------------------------------------------*/
00077 static Scig_click_handler scig_click_handler = scig_click_handler_sci;
00078 
00079 /*--------------------------------------------------------------------------*/
00080 
00081 Scig_click_handler set_scig_click_handler( Scig_click_handler f) 
00082 {
00083   Scig_click_handler old = scig_click_handler;
00084   scig_click_handler = f;
00085   return old;
00086 }
00087 /*--------------------------------------------------------------------------*/
00088 
00089 void reset_scig_click_handler() 
00090 {
00091   scig_click_handler = scig_click_handler_sci;
00092 }
00093 /*--------------------------------------------------------------------------*/
00094 void scig_deletegwin_handler_none (int win)
00095 {
00096 }
00097 /*--------------------------------------------------------------------------*/
00098 void scig_deletegwin_handler_sci (int win)
00099 {
00100   static char buf[256];
00101   sciPointObj * pFigure = NULL ;
00102 
00103   pFigure = getFigureFromIndex(win);
00104   if (   pFigure != NULL
00105       && sciGetIsEventHandlerEnable(pFigure)
00106       && strlen(sciGetEventHandler(pFigure)) > 0 )
00107   {
00108     sprintf(buf,"%s(%d,0,0,-1000)",sciGetEventHandler(pFigure),win);
00109     StoreCommand(buf);
00110   }
00111 }
00112 /*--------------------------------------------------------------------------*/
00113 
00114 
00115 
00116 /*--------------------------------------------------------------------------*/
00117 Scig_deletegwin_handler set_scig_deletegwin_handler(Scig_deletegwin_handler f) 
00118      
00119 {
00120   Scig_deletegwin_handler old = scig_deletegwin_handler;
00121   scig_deletegwin_handler = f;
00122   return old;
00123 }
00124 /*--------------------------------------------------------------------------*/
00125 Scig_deletegwin_handler get_scig_deletegwin_handler( void )
00126 {
00127   return scig_deletegwin_handler ;
00128 }
00129 /*--------------------------------------------------------------------------*/
00130 void reset_scig_deletegwin_handler() 
00131 {
00132   scig_deletegwin_handler = scig_deletegwin_handler_sci;
00133 }
00134 
00135 /*--------------------------------------------------------------------------*/
00136 void set_delete_win_mode(void) {  sci_graphic_protect = 0 ;}
00137 /*--------------------------------------------------------------------------*/
00138 void set_no_delete_win_mode(void)  {  sci_graphic_protect = 1 ;}
00139 /*--------------------------------------------------------------------------*/
00140 int  get_delete_win_mode(void) {  return sci_graphic_protect;}
00141 /*--------------------------------------------------------------------------*/
00142 
00143 /*---------------------------------------------------------
00144  * Mouse queue Handling 
00145  * the default behaviour is to store mouse clicks in a queue. 
00146  * But one can also set a handler to deal with 
00147  * mouse motion and click: the handler returns 1 
00148  * if he take care of the click and returns 0 if 
00149  * he want the queue to be used 
00150  ---------------------------------------------------------*/
00151 int PushClickQueue(int win,int x,int y,int ibut, int motion,int release) 
00152 {
00153   /* first let a click_handler do the job  */
00154   if ( ( wait_for_click == 0 ) && ( scig_click_handler(win,x,y,ibut,motion,release) == 1 ) ) return 0;
00155   if (  event_select==0 &&(motion == 1 || release == 1) ) return 0;
00156                 
00157   if (((event_select&2)&&motion)||((event_select&4)&&release)||(motion==0&&release==0))
00158         {
00159                 /* store click event in a queue */
00160           if ( lastc == MaxCB ) 
00161     {
00162       int i;
00163       for ( i= 1 ; i < MaxCB ; i ++ ) 
00164                         {
00165                                 ClickBuf[i-1]=ClickBuf[i];
00166                         }
00167       ClickBuf[lastc-1].win = win;
00168       ClickBuf[lastc-1].x = x;
00169       ClickBuf[lastc-1].y = y;
00170       ClickBuf[lastc-1].ibutton = ibut;
00171       ClickBuf[lastc-1].motion = motion;
00172       ClickBuf[lastc-1].release = release;
00173     }
00174                 else 
00175     {
00176       ClickBuf[lastc].win = win;
00177       ClickBuf[lastc].x = x;
00178       ClickBuf[lastc].y = y;
00179       ClickBuf[lastc].ibutton = ibut;
00180       ClickBuf[lastc].motion = motion;
00181       ClickBuf[lastc].release = release;
00182       lastc++;
00183     }
00184   }
00185   return(0);
00186 }
00187 /*--------------------------------------------------------------------------*/
00188 int CheckClickQueue(int *win,int *x,int *y,int *ibut,int *motion,int *release)
00189 {
00190   int i;
00191   for ( i = 0 ; i < lastc ; i++ )
00192     {
00193       int j ;
00194       if ( ClickBuf[i].win == *win || *win == -1 ) 
00195         {
00196           *win = ClickBuf[i].win;
00197           *x= ClickBuf[i].x ;
00198           *y= ClickBuf[i].y ;
00199           *ibut= ClickBuf[i].ibutton; 
00200           *motion= ClickBuf[i].motion ;
00201           *release= ClickBuf[i].release ;
00202           for ( j = i+1 ; j < lastc ; j++ ) 
00203             {
00204               ClickBuf[j-1].win = ClickBuf[j].win ;
00205               ClickBuf[j-1].x   = ClickBuf[j].x ;
00206               ClickBuf[j-1].y =  ClickBuf[j].y ;
00207               ClickBuf[j-1].ibutton = ClickBuf[j].ibutton ;
00208               ClickBuf[j-1].motion =  ClickBuf[j].motion ;
00209               ClickBuf[j-1].release = ClickBuf[j].release ;
00210             }
00211           lastc--;
00212           return(1);
00213         }
00214     }
00215   return(0);
00216 }
00217 /*--------------------------------------------------------------------------*/
00218 int ClearClickQueue(int win)
00219 {
00220   int i;
00221   if ( win == -1 ) 
00222     {
00223       lastc = 0;
00224       return 0;
00225     }
00226   for ( i = 0 ; i < lastc ; i++ )
00227     {
00228       int j ;
00229       if ( ClickBuf[i].win == win  ) 
00230         {
00231           for ( j = i+1 ; j < lastc ; j++ ) 
00232             {
00233               ClickBuf[j-1].win = ClickBuf[j].win ;
00234               ClickBuf[j-1].x   = ClickBuf[j].x ;
00235               ClickBuf[j-1].y =  ClickBuf[j].y ;
00236               ClickBuf[j-1].ibutton = ClickBuf[j].ibutton ;
00237               ClickBuf[j-1].motion =  ClickBuf[j].motion ;
00238               ClickBuf[j-1].release = ClickBuf[j].release ;
00239             }
00240           lastc--;
00241         }
00242     }
00243   lastc=0;
00244   return(0);
00245 }
00246 /*--------------------------------------------------------------------------*/
00247 void set_wait_click(int val)
00248 {  
00249   if (val==1) {
00250     wait_for_click=val;
00251   }else
00252     wait_for_click=val;
00253 }
00254 
00255 /*--------------------------------------------------------------------------*/
00256 int get_wait_click()
00257 {  
00258   return wait_for_click;
00259 }
00260 
00261 void set_event_select(int val)
00262 {  
00263     event_select=val;
00264 }
00265 
00266 /*--------------------------------------------------------------------------*/
00267 int get_event_select()
00268 {  
00269   return event_select;
00270 }
00271 

Generated on Tue Sep 9 17:48:22 2008 for Scilab [trunk] by  doxygen 1.5.5