Term-Gnuplot

 view release on metacpan or  search on metacpan

gnuterm/mousing.c  view on Meta::CPAN

#include "mousing.h"


/************************************************************************
		DECLARATIONS
************************************************************************/


/* which mouse coordinates:
	- real (coords of x1, y1 axes in gnuplot)
	- pixels (relative to the terminal window in pixels)
	- screen (relative to the terminal window normalized to (0..1,0..1))
	- x axis is date or time
*/
#define   MOUSE_COORDINATES_REAL	0
#define   MOUSE_COORDINATES_PIXELS	1
#define   MOUSE_COORDINATES_SCREEN	2
#define   MOUSE_COORDINATES_XDATE	3
#define   MOUSE_COORDINATES_XTIME	4
#define   MOUSE_COORDINATES_XDATETIME	5

/* useMouse is set to 1 when user switches mousing on, e.g. the mouse is 
   allowed
*/
static int useMouse = 0;


/* mousePolarDistance is set to 1 if user wants to see the distance between
   the ruler and mouse pointer in polar coordinates too (otherwise, distance 
   in cartesian coordinates only is shown)
*/
static int mousePolarDistance = 0;


static long mouse_mode = MOUSE_COORDINATES_REAL;

/* gnuplot's PM terminal sends 'm' message from its init routine, which
   sets the variable below to 1. Then we are sure that we talk to the
   mouseable terminal and can read the mouseable data from the pipe. 
   Non-mouseable versions of PM terminal or non-new-gnuplot programs 
   using gnupmdrv will let this variable set to 0, thus no mousing occurs.
*/
static char mouseTerminal = 0;


/* Lock (hide) mouse when building the plot (redrawing screen).
   Otherwise gnupmdrv would crash when trying to display mouse position
   in a window not yet plotted.
*/
static char lock_mouse = 1;


#ifndef GNUPMDRV /* gnupmdrv: they are available as menu items */
const  char *( MouseCoordinatesHelpStrings[] ) = {
		"real", "pixels", "screen", "x date / y real",
		"x time / y real", "x date+time / y real"
		 };
#endif


/* formats for saving the mouse position into clipboard / print to screen
   (double click of mouse button 1).
   Important: do not change this unless you update the appropriate items 
   in os2/gnupmdrv.rc
*/
#ifndef GNUPMDRV
int mouseSprintfFormat = 1;
#endif
const  int	nMouseSprintfFormats = IDM_MOUSE_FORMAT_LABEL - IDM_MOUSE_FORMAT;
const  char  *( MouseSprintfFormats[ /*nMouseSprintfFormats*/ ] ) = {
		"%g %g","%g,%g","%g;%g",
		"%g,%g,","%g,%g;",
		"[%g:%g]","[%g,%g]","[%g;%g]",
		"set label \"\" at %g,%g"
		 };

/* Zoom queue
*/
struct t_zoom {
  double xmin, ymin, xmax, ymax;
  struct t_zoom *prev, *next;
};

struct t_zoom *zoom_head = NULL,
	      *zoom_now = NULL;


/* Structure for the ruler: on/off, position,...
*/
static struct {
   int on;
   double x, y;  /* ruler position in real units of the graph */
   long px, py;  /* ruler position in the viewport units */
} ruler;


#ifdef OS2
char mouseShareMemName[40];
PVOID input_from_PM_Terminal;
  /* pointer to shared memory for storing the command to be executed */
HEV semInputReady = 0;
  /* handle to event semaphore (post an event to gnuplot that the shared 
     memory contains a command to be executed) */
int pausing = 0;
  /* avoid passing data back to gnuplot in `pause' mode */
#ifdef GNUPMDRV
  extern ULONG ppidGnu;
#else
  ULONG ppidGnu = 0;
#endif
#endif



/************************************************************************
		DECLARATION OF ROUTINES
************************************************************************/

#define OK fprintf(stderr,"LINE %3i in file %s is OK\n",(int)__LINE__,__FILE__);

#ifdef OS2

gnuterm/mousing.c  view on Meta::CPAN

} else /* overwrite next item */
    z = zoom_now->next;
z->xmin = xmin; z->ymin = ymin;
z->xmax = xmax; z->ymax = ymax;
apply_zoom( z );
}


/* Applies the zoom rectangle of  z  by sending the appropriate command
   to gnuplot
*/
void apply_zoom ( struct t_zoom *z )
{
char s[255];
if (zoom_now != NULL) { /* remember the current zoom */
  zoom_now->xmin = (!gp4mouse.is_log_x) ? gp4mouse.xmin : exp( gp4mouse.xmin * gp4mouse.log_base_log_x );
  zoom_now->ymin = (!gp4mouse.is_log_y) ? gp4mouse.ymin : exp( gp4mouse.ymin * gp4mouse.log_base_log_y );
  zoom_now->xmax = (!gp4mouse.is_log_x) ? gp4mouse.xmax : exp( gp4mouse.xmax * gp4mouse.log_base_log_x );
  zoom_now->ymax = (!gp4mouse.is_log_y) ? gp4mouse.ymax : exp( gp4mouse.ymax * gp4mouse.log_base_log_y );
}
zoom_now = z;
if (zoom_now == NULL) {
#ifdef GNUPMDRV
    DosBeep(444,111);
#else
    fprintf(stderr,"\a");
#endif
    return;
}

#ifdef GNUPMDRV
/* update menu items in gnupmdrv */
WinEnableMenuItem( /* can this situation be zoomed back? */
  WinWindowFromID( WinQueryWindow( hApp, QW_PARENT ), FID_MENU ),
  IDM_MOUSE_ZOOMNEXT, (zoom_now->next == NULL) ? FALSE : TRUE ) ;
WinEnableMenuItem( /* can this situation be unzoomed back? */
  WinWindowFromID( WinQueryWindow( hApp, QW_PARENT ), FID_MENU ),
  IDM_MOUSE_UNZOOM, (zoom_now->prev == NULL) ? FALSE : TRUE ) ;
WinEnableMenuItem( /* can this situation be unzoomed to the beginning? */
  WinWindowFromID( WinQueryWindow( hApp, QW_PARENT ), FID_MENU ),
  IDM_MOUSE_UNZOOMALL, (zoom_now == zoom_head) ? FALSE : TRUE ) ;
#endif

/* prepare the command for gnuplot */
sprintf(s,"set xr[%g:%g]; set yr[%g:%g]; replot",
	zoom_now->xmin, zoom_now->xmax, zoom_now->ymin, zoom_now->ymax);

/* and let gnuplot execute it */
gp_execute(s);
}


#ifdef OS2

void gp_execute ( char *s )
{
/* Copy the command to the shared memory and let gnuplot execute it.
	If this routine is called during a 'pause', then the command is
   ignored (shared memory is cleared). Needed for actions launched by a
   hotkey.
	Firstly, the command is copied from shared memory to clipboard
   if this option is set on.
	Secondly, gnuplot is informed that shared memory contains a command
   by posting semInputReady event semaphore.

   OS/2 specific: if (!s), then the command has been already sprintf'ed to
   the shared memory.
*/
    APIRET rc;
    if (input_from_PM_Terminal==NULL)
	return;
    if (s) /* copy the command to shared memory */
      strcpy(input_from_PM_Terminal,s);
    if (((char*)input_from_PM_Terminal)[0]==0)
	return;
    if (pausing) { /* no communication during pause */
	DosBeep(440,111);
	((char*)input_from_PM_Terminal)[0] = 0;
	return;
    }
#ifdef GNUPMDRV
    /* write the command to clipboard */
    if (bSend2gp == TRUE)
	TextToClipboard ( input_from_PM_Terminal );
#endif
    /* let the command in the shared memory be executed... */
    if (semInputReady == 0) { /* but it must be open for the first time */
	char semInputReadyName[40];
	sprintf( semInputReadyName, "\\SEM32\\GP%i_Input_Ready", (int)ppidGnu );
	DosOpenEventSem( semInputReadyName, &semInputReady);
    }
    rc = DosPostEventSem(semInputReady);
}

#else

void
gp_execute(char *s)
{
    if(!s)
	return;
    /* fprintf(stderr,"(gp_execute) |%s|\n",s); */
    /* write the command to stdout which corresponds to the ipc_back_fd,
     * that is write the command to the ipc fd which is read by gnuplot. */
    printf("%s\n", s); /* XXX note the newline, gnuplot relies on it! XXX */ 
    fflush(stdout); /* just in case ... */
}

#endif


/* eof mousing.c */



( run in 0.661 second using v1.01-cache-2.11-cpan-2398b32b56e )