51 #if defined ( _WIN32 ) || defined ( MAC_TCL ) 56 #define malloc ckalloc 57 #define free( m ) ckfree( (char *) m ) 58 #define realloc ckrealloc 59 #define calloc ckcalloc 61 #if defined ( _WIN32 ) || defined ( MAC_TCL ) 70 #define ckalloc malloc 81 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_tkwin =
"tkwin:New tk driver:1:tkwin:45:tkwin\n";
84 void *
ckcalloc(
size_t nmemb,
size_t size );
95 #define XSynchronize( display, bool ) { display->request++; } 96 #define XSync( display, bool ) { display->request++; } 97 #define XFlush( display ) 118 void CopyColour( XColor* from, XColor* to );
120 static int pltk_AreWeGrayscale(
PlPlotter *plf );
133 #define PHYSICAL 0 // Enables physical scaling.. 151 #define XWM_COLORS 70 152 #define CMAP0_COLORS 16 153 #define CMAP1_COLORS 50 154 #define MAX_COLORS 256 160 static int sxwm_colors_set;
161 static XColor sxwm_colors[MAX_COLORS];
168 #if !defined ( MAC_TCL ) && !defined ( _WIN32 ) 169 static unsigned char CreatePixmapStatus;
170 static int CreatePixmapErrorHandler( Display *
display, XErrorEvent *
error );
194 #ifdef USING_PLESC_COPY 207 void plD_line_tkwin(
PLStream *,
short,
short,
short,
short );
208 void plD_polyline_tkwin(
PLStream *,
short *,
short *,
PLINT );
219 #ifndef ENABLE_DYNDRIVERS 262 if ( pls->
dev == NULL )
271 dev->
xlen = (short) ( xmax - xmin );
272 dev->
ylen = (short) ( ymax - ymin );
312 if ( pls->
dev != NULL )
313 plwarn(
"plD_open_tkw: device pointer is already set" );
316 if ( pls->
dev == NULL )
317 plexit(
"plD_init_tkw: Out of memory." );
331 if ( tkwDisplay[i] == NULL )
337 dev->
tkwd = tkwDisplay[i];
344 else if ( strcmp( tkwDisplay[i]->displayName, pls->
FileName ) == 0 )
346 dev->
tkwd = tkwDisplay[i];
353 if ( dev->
tkwd == NULL )
356 if ( dev->
tkwd == NULL )
357 plexit(
"Init: Out of memory." );
361 if ( tkwDisplay[i] == NULL )
364 if ( i == PLTKDISPLAYS )
365 plexit(
"Init: Out of tkwDisplay's." );
376 plexit(
"No tk plframe widget to connect to" );
386 #if defined ( MAC_TCL ) || defined ( _WIN32 ) 402 plexit(
"Can't open display" );
408 XSynchronize( tkwd->
display, 1 );
452 plD_line_tkwin(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
457 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
459 if ( dev->
flags & 1 )
465 x1 = (int) ( x1 * dev->
xscale );
466 x2 = (int) ( x2 * dev->
xscale );
467 y1 = (int) ( y1 * dev->
yscale );
468 y2 = (int) ( y2 * dev->
yscale );
484 plD_polyline_tkwin(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
493 if ( dev->
flags & 1 )
498 pts = (XPoint *) malloc(
sizeof ( XPoint ) * (size_t) npts );
505 for ( i = 0; i < npts; i++ )
507 pts[i].x = (short) ( dev->
xscale * xa[i] );
508 pts[i].y = (short) ( dev->
yscale * ( dev->
ylen - ya[i] ) );
538 if ( dev->
flags & 1 )
543 ExposeCmd( pls, NULL );
559 if ( dev->
flags & 1 )
583 plwarn(
"WaitForPage: Illegal call --- driver can't find enclosing PlPlotter" );
588 while ( !( dev->
flags ) && !Tcl_InterpDeleted( plf->
interp ) && ( Tk_GetNumMainWindows() > 0 ) )
593 if ( Tcl_InterpDeleted( plf->
interp ) || ( Tk_GetNumMainWindows() <= 0 ) )
615 xrect.x = 0; xrect.y = 0;
616 xrect.width = (
short unsigned) dev->
width;
617 xrect.height = (
short unsigned) dev->
height;
620 if ( dev->
flags & 1 )
662 int ixwd = tkwd->
ixwd;
664 #if !defined ( MAC_TCL ) && !defined ( _WIN32 ) 665 XCloseDisplay( tkwd->
display );
692 if ( dev->
flags & 1 )
701 int icol0 = pls->
icol0;
726 if ( tkwd->
ncol1 == 0 )
729 if ( tkwd->
ncol1 < 2 )
777 if ( dev->
flags & 1 )
793 FillPolygonCmd( pls );
818 #ifdef USING_PLESC_COPY 826 #ifdef USING_PLESC_COPY 837 int x0, w, x1, y0, h, y1;
850 x0, y0, w, h, x1, y1 );
854 x0, y0, w, h, x1, y1 );
876 pts = (XPoint *) malloc(
sizeof ( XPoint ) * (size_t) ( pls->
dev_npts ) );
883 for ( i = 0; i < pls->
dev_npts; i++ )
885 pts[i].x = (short) ( dev->
xscale * pls->
dev_x[i] );
893 pts, pls->
dev_npts, Nonconvex, CoordModeOrigin );
897 pts, pls->
dev_npts, Nonconvex, CoordModeOrigin );
950 plwarn(
"Init: Illegal call --- driver can't find enclosing PlPlotter" );
971 gcValues.background = tkwd->
cmap0[0].pixel;
972 gcValues.foreground = 0xFF;
973 gcValues.function = GXxor;
974 mask = GCForeground | GCBackground | GCFunction;
980 dev->
width = (
unsigned int) Tk_Width( plf->
tkwin );
981 dev->
height = (
unsigned int) Tk_Height( plf->
tkwin );
982 dev->
border = (
unsigned int) Tk_InternalBorderWidth( plf->
tkwin );
983 tkwd->
depth = (
unsigned int) Tk_Depth( plf->
tkwin );
1005 CreatePixmap( pls );
1035 plwarn(
"ExposeCmd: Illegal call -- driver uninitialized" );
1041 if ( pldis == NULL )
1045 width = (int) dev->
width;
1046 height = (
int) dev->
height;
1052 width = (int) pldis->
width;
1053 height = (
int) pldis->
height;
1063 x, y, (
unsigned int) width, (
unsigned int) height, x, y );
1069 int x0 = x, x1 = x +
width, y0 = y, y1 = y +
height;
1070 pts[0].x = (short) x0; pts[0].y = (short) y0;
1071 pts[1].x = (short) x1; pts[1].y = (short) y0;
1072 pts[2].x = (short) x1; pts[2].y = (short) y1;
1073 pts[3].x = (short) x0; pts[3].y = (short) y1;
1074 pts[4].x = (short) x0; pts[4].y = (short) y0;
1107 plwarn(
"ResizeCmd: Illegal call -- driver uninitialized" );
1113 if ( pldis == NULL )
1115 plwarn(
"ResizeCmd: Illegal call -- window pointer uninitialized" );
1149 #if defined ( _WIN32 ) || defined ( MAC_TCL ) 1171 CreatePixmap( pls );
1176 plD_bop_tkwin( pls );
1211 plwarn(
"RedrawCmd: Illegal call -- driver uninitialized" );
1220 plD_bop_tkwin( pls );
1250 #if !defined ( MAC_TCL ) && !defined ( _WIN32 ) 1251 int ( *oldErrorHandler )( Display *, XErrorEvent * );
1252 oldErrorHandler = XSetErrorHandler( CreatePixmapErrorHandler );
1253 CreatePixmapStatus = Success;
1258 if ( dev->
width == 0 )
1267 pldebug(
"CreatePixmap",
1268 "creating pixmap: width = %d, height = %d, depth = %d\n",
1285 dev->
pixmap = Tk_GetPixmap( tkwd->
display, Tk_WindowId( tkwin ),
1286 Tk_Width( tkwin ), Tk_Height( tkwin ),
1287 DefaultDepthOfScreen( Tk_Screen( tkwin ) ) );
1289 #if !defined ( MAC_TCL ) && !defined ( _WIN32 ) 1290 if ( CreatePixmapStatus != Success )
1295 fprintf( stderr,
"\n\ 1296 Warning: pixmap could not be allocated (insufficient memory on server).\n\ 1297 Driver will redraw the entire plot to handle expose events.\n" );
1300 XSetErrorHandler( oldErrorHandler );
1328 tkwd->
depth = (
unsigned int) depth;
1347 unsigned long plane_masks[1], pixels[MAX_COLORS];
1359 if ( XAllocColorCells( tkwd->
display, tkwd->
map, False,
1360 plane_masks, 0, pixels, 1 ) )
1362 tkwd->
cmap0[0].pixel = pixels[0];
1366 plexit(
"couldn't allocate background color cell" );
1371 npixels = MAX_COLORS;
1374 if ( XAllocColorCells( tkwd->
display, tkwd->
map, False,
1375 plane_masks, 0, pixels, npixels ) )
1385 for ( i = 0; i < npixels - 1; i++ )
1387 if ( pixels[i] == ( ~tkwd->
cmap0[0].pixel & 0xFF ) )
1393 tkwd->
fgcolor.pixel = pixels[i];
1394 for ( j = 0; j < npixels; j++ )
1397 XFreeColors( tkwd->
display, tkwd->
map, &pixels[j], 1, 0 );
1415 int gslevbg, gslevfg;
1430 gslevbg = (int) ( ( (
long) pls->
cmap0[0].
r +
1432 (
long) pls->
cmap0[0].
b ) / 3 );
1446 if ( gslevbg > 0x7F )
1451 fgcolor.
r = fgcolor.
g = fgcolor.
b = (
unsigned char) gslevfg;
1494 AllocCustomMap( pls );
1535 XColor xwm_colors[MAX_COLORS];
1539 unsigned long plane_masks[1], pixels[MAX_COLORS];
1546 for ( i = 0; i < MAX_COLORS; i++ )
1548 xwm_colors[i].pixel = (
long unsigned) i;
1551 XQueryColors( tkwd->
display, tkwd->
map, xwm_colors, MAX_COLORS );
1565 tkwd->
visual, AllocNone );
1570 npixels = MAX_COLORS;
1573 if ( XAllocColorCells( tkwd->
display, tkwd->
map, False,
1574 plane_masks, 0, pixels, npixels ) )
1578 plexit(
"couldn't allocate any colors" );
1583 for ( i = 0; i < XWM_COLORS; i++ )
1585 XStoreColor( tkwd->
display, tkwd->
map, &xwm_colors[i] );
1586 pixels[xwm_colors[i].pixel] = 0;
1591 for ( i = 0; i < tkwd->
ncol0; i++ )
1594 pixels[tkwd->
cmap0[i].pixel] = 0;
1603 if ( sxwm_colors_set )
1605 for ( i = 0; i < MAX_COLORS; i++ )
1607 if ( ( xwm_colors[i].red != sxwm_colors[i].red ) ||
1608 ( xwm_colors[i].green != sxwm_colors[i].green ) ||
1609 ( xwm_colors[i].blue != sxwm_colors[i].blue ) )
1611 if ( pixels[i] != 0 )
1613 XStoreColor( tkwd->
display, tkwd->
map, &xwm_colors[i] );
1622 for ( i = 0; i < npixels; i++ )
1624 if ( pixels[i] != 0 )
1625 XFreeColors( tkwd->
display, tkwd->
map, &pixels[i], 1, 0 );
1648 unsigned long plane_masks[1], pixels[MAX_COLORS];
1656 npixels = pls->
ncol0 - 1;
1659 if ( XAllocColorCells( tkwd->
display, tkwd->
map, False,
1660 plane_masks, 0, &pixels[1], npixels ) )
1664 plexit(
"couldn't allocate any colors" );
1667 tkwd->
ncol0 = npixels + 1;
1668 for ( i = 1; i < tkwd->
ncol0; i++ )
1670 tkwd->
cmap0[i].pixel = pixels[i];
1695 unsigned long plane_masks[1], pixels[MAX_COLORS];
1702 npixels =
MAX( 2,
MIN( CMAP1_COLORS, pls->
ncol1 ) );
1706 if ( XAllocColorCells( tkwd->
display, tkwd->
map, False,
1707 plane_masks, 0, pixels, npixels ) )
1718 "Warning: unable to allocate sufficient colors in cmap1\n" );
1723 tkwd->
ncol1 = npixels;
1725 fprintf( stderr,
"AllocCmap1 (xwin.c): Allocated %d colors in cmap1\n", npixels );
1731 for ( j = i = 0; i < tkwd->
ncol1; i++ )
1733 while ( pixels[j] == 0 )
1736 tkwd->
cmap1[i].pixel = pixels[j];
1740 if ( j >= tkwd->
ncol1 )
1744 tkwd->
ncol1 = npixels;
1765 for ( i = 1; i < tkwd->
ncol0; i++ )
1776 void CopyColour( XColor* from, XColor* to )
1778 to->pixel = from->pixel;
1779 to->red = from->red;
1780 to->blue = from->blue;
1781 to->green = from->green;
1782 to->flags = from->flags;
1803 for ( i = 0; i < tkwd->
ncol1; i++ )
1819 XStoreColor( tkwd->
display, tkwd->
map, col );
1824 CopyColour( xc, col );
1836 #define ToXColor( a ) ( ( ( 0xFF & ( a ) ) << 8 ) | ( a ) ) 1837 #define ToPLColor( a ) ( ( (U_LONG) a ) >> 8 ) 1842 xcolor->red = (
short unsigned) ToXColor( plcolor->
r );
1843 xcolor->green = (
short unsigned) ToXColor( plcolor->
g );
1844 xcolor->blue = (
short unsigned) ToXColor( plcolor->
b );
1845 xcolor->flags = DoRed | DoGreen | DoBlue;
1858 plcolor->
r = (
unsigned char) ToPLColor( xcolor->red );
1859 plcolor->
g = (
unsigned char) ToPLColor( xcolor->green );
1860 plcolor->
b = (
unsigned char) ToPLColor( xcolor->blue );
1877 color = ToPLColor( xcolor->red );
1879 if ( plcolor->
r != color )
1882 plcolor->
r = (
unsigned char) color;
1884 color = ToPLColor( xcolor->green );
1885 if ( plcolor->
g != color )
1888 plcolor->
g = (
unsigned char) color;
1890 color = ToPLColor( xcolor->blue );
1891 if ( plcolor->
b != color )
1894 plcolor->
b = (
unsigned char) color;
1910 #if defined ( __cplusplus ) || defined ( c_plusplus ) 1911 #define THING c_class 1918 visual = Tk_Visual( plf->
tkwin );
1919 if ( ( visual->THING != GrayScale ) && ( visual->THING != StaticGray ) )
1925 #if !defined ( MAC_TCL ) && !defined ( _WIN32 ) 1935 CreatePixmapErrorHandler( Display *
display, XErrorEvent *
error )
1937 if ( error->error_code == BadAlloc )
1939 CreatePixmapStatus = error->error_code;
1944 XGetErrorText( display, error->error_code, buffer, 256 );
1945 fprintf( stderr,
"Error in XCreatePixmap: %s.\n", buffer );
1965 ptr = (
long *) malloc( size );
1971 for ( size = ( size /
sizeof (
long ) ) + 1, p = ptr; --size; )
1976 for ( size = ( size /
sizeof (
long ) ) + 1, p = ptr - 1; --size; )
void plexit(PLCHAR_VECTOR errormsg)
void PLColor_to_TkColor(PLColor *plcolor, XColor *xcolor)
static int plplot_tkwin_ccmap
void * ckcalloc(size_t nmemb, size_t size)
void(* plD_tidy_fp)(struct PLStream_struct *)
void plcol_interp(PLStream *pls, PLColor *newcolor, int i, int ncol)
void(* plD_init_fp)(struct PLStream_struct *)
void PlplotterAtBop(Tcl_Interp *interp, register PlPlotter *plPlotterPtr)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_wait_fp)(struct PLStream_struct *)
void plD_open_tkwin(PLStream *pls)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
int PLColor_from_TkColor_Changed(PLColor *plcolor, XColor *xcolor)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
struct PlPlotter PlPlotter
PLDLLIMPEXP_DRIVER void plD_dispatch_init_tkwin(PLDispatchTable *pdt)
void PlplotterAtEop(Tcl_Interp *interp, register PlPlotter *plPlotterPtr)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
#define PLDLLIMPEXP_DRIVER
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
char PLDLLIMPEXP * plstrdup(PLCHAR_VECTOR src)
void plRemakePlot(PLStream *pls)
void(* plD_bop_fp)(struct PLStream_struct *)
void PLColor_from_TkColor(PLColor *plcolor, XColor *xcolor)
struct PlPlotter * plPlotterPtr
void plwarn(PLCHAR_VECTOR errormsg)
void pltkwin_setBGFG(PLStream *pls)
plD_polyline_fp pl_polyline
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void Tkw_StoreColor(PLStream *pls, TkwDisplay *tkwd, XColor *col)