From 3261805fee19e346b4d1f84b23816daa1628764a Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 16 Apr 2003 09:49:22 +0000 Subject: Update from the Windows port and general cleanup/restructure --- generic/Types.h | 468 ++++++++++++++++---------------------------------------- 1 file changed, 135 insertions(+), 333 deletions(-) (limited to 'generic/Types.h') diff --git a/generic/Types.h b/generic/Types.h index 41b1aff..b84350c 100644 --- a/generic/Types.h +++ b/generic/Types.h @@ -1,5 +1,5 @@ /* - * Types.h -- Types used by the Zinc widget. + * Types.h -- Some types and macros used by the Zinc widget. * * Authors : Patrick Lecoanet. * Creation date : Mon Feb 1 12:13:24 1999 @@ -30,321 +30,74 @@ #ifndef _Types_h #define _Types_h +#include "private.h" + +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN +# if defined(_MSC_VER) +# define DllEntryPoint DllMain +# endif +#endif + +#ifdef GL +# ifdef _WIN32 +# include +# else +# include +# endif +#endif + #define NEED_REAL_STDIO + #include +#include +#include #include #ifdef PTK -#include +# include +# include +# include +#else +# include #endif #include -#ifdef __CPLUSPLUS__ -extern "C" { +/* This EXTERN declaration is needed for Tcl < 8.0.3 */ +#ifndef EXTERN +# ifdef __cplusplus +# define EXTERN extern "C" +# else +# define EXTERN extern +# endif #endif +#ifdef TCL_STORAGE_CLASS +# undef TCL_STORAGE_CLASS +#endif +#ifdef BUILD_Tkzinc +# define TCL_STORAGE_CLASS DLLEXPORT +#else +# define TCL_STORAGE_CLASS DLLIMPORT +#endif -typedef void *ZnItemClassId; -typedef void *ZnItemId; - -typedef double ZnReal; /* Keep it a double for GL. */ -typedef int ZnBool; /* Keep it an int to keep Tk happy */ -typedef ZnReal ZnPos; -typedef ZnReal ZnDim; -typedef XColor *ZnColor; -typedef Tk_Font ZnFont; -typedef Tk_Window ZnWindow; -typedef void *ZnPtr; - -typedef struct { - ZnPos x, y; -} ZnPoint; - -typedef struct { - ZnPos x, y, w, h; -} ZnRect; - -typedef struct { - int num_points; - ZnPoint *points; - char *controls; - ZnBool cw; -} ZnContour; - -/* - * contour1 can be used to store a single contour - * without having to alloc the contours array. - */ -typedef struct { - int num_contours; - ZnContour *contours; - ZnContour contour1; -} ZnPoly; - -/* - * Keep this enum in sync with op_strings in Contour() - * in tkZinc.c. - */ -typedef enum { - ZN_CONTOUR_ADD, ZN_CONTOUR_REMOVE -} ZnContourCmd; - -typedef struct { - int num_points; - ZnPoint *points; - ZnBool fan; /* When using a fan, all contour vertices must be - * included to describe the contour as a polygon - * (clipping code use that to speed up region - * rendering) and the center must be the first - * vertex. */ -} ZnStrip; - -typedef struct { - int num_strips; - ZnStrip *strips; - ZnStrip strip1; -} ZnTriStrip; - -typedef struct _ZnCombineData { - ZnReal v[2]; - struct _ZnCombineData *next; -} ZnCombineData; - -/* - * ZnBBox: orig is into the area while corner is not. - * Thus the test: ((bbox.orig.x == bbox.corner.x) || - * (bbox.orig.y == bbox.corner.y)) - * tells whether the bbox is empty or not. - * When interpreting bboxes the X coordinate system is - * the norm. x goes from left toward the right and y - * goes from the top toward the bottom. Bboxes are - * always axes aligned. - */ -typedef struct { - ZnPoint orig, corner; -} ZnBBox; - -/* - * Operator constants for the coord method. - */ -#define COORDS_READ 0 -#define COORDS_READ_ALL 1 -#define COORDS_REPLACE 2 -#define COORDS_REPLACE_ALL 3 -#define COORDS_ADD 4 -#define COORDS_ADD_LAST 5 -#define COORDS_REMOVE 6 - -/* - * Types and constants for attribute processing. - */ -typedef struct { - int type; - char *name; - Tk_Uid uid; - int offset; - int bool_bit; - int flags; - ZnBool read_only; -} ZnAttrConfig; - -/* - * When adding new type in the following enum - * do not forget to update attribute_type_strings - * in Item.c. - */ -#define ZN_CONFIG_END 0 -#define ZN_CONFIG_BOOL 1 -#define ZN_CONFIG_BITMAP 2 -#define ZN_CONFIG_BITMAP_LIST 3 -#define ZN_CONFIG_STRING 4 -#define ZN_CONFIG_FONT 5 -#define ZN_CONFIG_EDGE_LIST 6 -#define ZN_CONFIG_RELIEF 7 -#define ZN_CONFIG_DIM 8 -#define ZN_CONFIG_PRI 9 -#define ZN_CONFIG_ALIGNMENT 10 -#define ZN_CONFIG_AUTO_ALIGNMENT 11 -#define ZN_CONFIG_LINE_END 12 -#define ZN_CONFIG_LABEL_FORMAT 13 -#define ZN_CONFIG_LINE_STYLE 14 -#define ZN_CONFIG_LINE_SHAPE 15 -#define ZN_CONFIG_ITEM 16 -#define ZN_CONFIG_ANGLE 17 -#define ZN_CONFIG_INT 18 -#define ZN_CONFIG_UINT 19 -#define ZN_CONFIG_POINT 20 -#define ZN_CONFIG_ANCHOR 21 -#define ZN_CONFIG_TAG_LIST 22 -#define ZN_CONFIG_MAP_INFO 23 -#define ZN_CONFIG_IMAGE 24 -#define ZN_CONFIG_LEADER_ANCHORS 25 -#define ZN_CONFIG_JOIN_STYLE 26 -#define ZN_CONFIG_CAP_STYLE 27 -#define ZN_CONFIG_GRADIENT 28 -#define ZN_CONFIG_GRADIENT_LIST 29 -#define ZN_CONFIG_WINDOW 30 -#define ZN_CONFIG_ALPHA 31 -#define ZN_CONFIG_FILL_RULE 32 - -#define ZN_DRAW_FLAG 1 << 0 -#define ZN_COORDS_FLAG 1 << 1 -#define ZN_TRANSFO_FLAG 1 << 2 -#define ZN_REPICK_FLAG 1 << 3 -#define ZN_BORDER_FLAG 1 << 4 -#define ZN_CLFC_FLAG 1 << 5 /* Clear Label Format Cache. */ -#define ZN_IMAGE_FLAG 1 << 6 /* Update image pointer. */ -#define ZN_VIS_FLAG 1 << 7 /* Visibility has changed. */ -#define ZN_MOVED_FLAG 1 << 8 /* Item has moved. */ -#define ZN_ITEM_FLAG 1 << 9 /* Signal a change in an item type attribute. */ -#define ZN_MAP_INFO_FLAG 1 << 10 /* Update mapinfo pointer. */ -#define ZN_LAYOUT_FLAG 1 << 10 /* A layout need update. */ -#define ZN_POLAR_FLAG 1 << 11 /* Signal a cartesian to polar change. */ -#define ZN_CARTESIAN_FLAG 1 << 12 /* Signal a polar to cartesian change. */ -#define ZN_TILE_FLAG 1 << 13 /* Update tile pointer. */ -#define ZN_WINDOW_FLAG 1 << 14 /* Signal a change in a window type attribute. */ - -/* - * Type and constant values for alignments. - */ -typedef char ZnJustify; -#define ZnJustifyLeft TK_JUSTIFY_LEFT -#define ZnJustifyRight TK_JUSTIFY_RIGHT -#define ZnJustifyCenter TK_JUSTIFY_CENTER - -/* - * Type and constant values for anchors. - */ -typedef Tk_Anchor ZnAnchor; -#define ZnAnchorN TK_ANCHOR_N -#define ZnAnchorS TK_ANCHOR_S -#define ZnAnchorE TK_ANCHOR_E -#define ZnAnchorW TK_ANCHOR_W -#define ZnAnchorNE TK_ANCHOR_NE -#define ZnAnchorNW TK_ANCHOR_NW -#define ZnAnchorSE TK_ANCHOR_SE -#define ZnAnchorSW TK_ANCHOR_SW -#define ZnAnchorCenter TK_ANCHOR_CENTER - -/* - * Type and constant values for borders. - */ -typedef unsigned char Border; -#define NO_BORDER 0 -#define LEFT_BORDER 1 -#define RIGHT_BORDER 2 -#define TOP_BORDER 4 -#define BOTTOM_BORDER 8 -#define CONTOUR_BORDER (LEFT_BORDER|RIGHT_BORDER|TOP_BORDER|BOTTOM_BORDER) -#define COUNTER_OBLIQUE 16 -#define OBLIQUE 32 - -#define LEFT_SPEC "left" -#define RIGHT_SPEC "right" -#define TOP_SPEC "top" -#define BOTTOM_SPEC "bottom" -#define CONTOUR_SPEC "contour" -#define COUNTER_OBLIQUE_SPEC "counteroblique" -#define OBLIQUE_SPEC "oblique" -#define NO_BORDER_SPEC "noborder" - -/* - * Type and constant values for line styles, line shapes and line ends. - */ -typedef unsigned char LineStyle; -typedef unsigned char LineEndStyle; -typedef unsigned char LineShape; - -/* LineStyle */ -#define LINE_SIMPLE 0 -#define LINE_DASHED 1 -#define LINE_MIXED 2 -#define LINE_DOTTED 3 -/* LineShape */ -#define LINE_STRAIGHT 0 -#define LINE_LEFT_LIGHTNING 1 -#define LINE_LEFT_CORNER 2 -#define LINE_DOUBLE_LEFT_CORNER 3 -#define LINE_RIGHT_LIGHTNING 4 -#define LINE_RIGHT_CORNER 5 -#define LINE_DOUBLE_RIGHT_CORNER 6 - -#define SIMPLE_SPEC "simple" -#define DASHED_SPEC "dashed" -#define DOTTED_SPEC "dotted" -#define MIXED_SPEC "mixed" -#define STRAIGHT_SPEC "straight" -#define RIGHT_LIGHTNING_SPEC "rightlightning" -#define LEFT_LIGHTNING_SPEC "leftlightning" -#define RIGHT_CORNER_SPEC "rightcorner" -#define LEFT_CORNER_SPEC "leftcorner" -#define DOUBLE_RIGHT_CORNER_SPEC "doublerightcorner" -#define DOUBLE_LEFT_CORNER_SPEC "doubleleftcorner" +#ifdef __CPLUSPLUS__ +extern "C" { +#endif -/* - * Type and constant values for relief styles. - */ -typedef int ReliefStyle; -#define RELIEF_FLAT 0 -#define RELIEF_RAISED 1 -#define RELIEF_SUNKEN 2 -#define RELIEF_GROOVE (RELIEF_TWO_FACES|RELIEF_SUNKEN) -#define RELIEF_RIDGE (RELIEF_TWO_FACES|RELIEF_RAISED) -#define RELIEF_ROUND_SUNKEN (RELIEF_ROUND|RELIEF_SUNKEN) -#define RELIEF_ROUND_RAISED (RELIEF_ROUND|RELIEF_RAISED) -#define RELIEF_ROUND_GROOVE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_SUNKEN) -#define RELIEF_ROUND_RIDGE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_RAISED) -#define RELIEF_SUNKEN_RULE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_SUNKEN|RELIEF_RULE) -#define RELIEF_RAISED_RULE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_RAISED|RELIEF_RULE) -#define RELIEF_ROUND 0x80 -#define RELIEF_TWO_FACES 0x40 -#define RELIEF_RULE 0x20 -#define RELIEF_MASK 0x3 -/* - * Number of steps for relief drawing. This translate in - * RELIEF_STEPS*2+1 color shades in the color gradient. - */ -#define RELIEF_STEPS 6 - -/* - * Types of gradients. - */ -#define ZN_AXIAL_GRADIENT 0 -#define ZN_RADIAL_GRADIENT 1 -#define ZN_PATH_GRADIENT 2 +typedef double ZnReal; /* Keep it a double for GL. */ +typedef int ZnBool; /* Keep it an int to keep Tk happy */ +typedef ZnReal ZnPos; +typedef ZnReal ZnDim; +typedef void *ZnPtr; -/* - * Type and constant values for automatic alignments. - */ -typedef struct { - ZnBool automatic; - ZnJustify align[3]; -} AutoAlign; -#define AA_LEFT 0 -#define AA_CENTER 1 -#define AA_RIGHT 2 -#define AA_LEFT_SPEC "l" -#define AA_CENTER_SPEC "c" -#define AA_RIGHT_SPEC "r" -#define AA_AUTO_SPEC "-" - -/* - * Type for leader anchors. - */ -typedef struct { - int left_x; /* left leader anchor field or percent of bbox */ - int right_x; /* right leader anchor field or percent of bbox */ - short left_y; /* left leader percent of bbox or < 0 if field */ - short right_y; /* right leader percent of bbox or < 0 if field */ -} LeaderAnchorsStruct, *LeaderAnchors; #define ZnPixel(color) ((color)->pixel) -#define ZnFontId(font) (Tk_FontId(font)) -#define ZnWindowId(win) (Tk_WindowId(win)) -#define ZnTextWidth(font, text, len) (Tk_TextWidth(font, text, len)) #define ZnMalloc(size) ((void *)ckalloc(size)) #define ZnFree(ptr) (ckfree((char *)(ptr))) #define ZnRealloc(ptr, size) ((void *)ckrealloc((void *)(ptr), size)) @@ -352,49 +105,98 @@ typedef struct { #define ZnUnspecifiedImage None #define ZnUnspecifiedColor NULL -#define ZN_OK TCL_OK -#define ZN_ERROR TCL_ERROR -#define ZN_NO_ITEM NULL - -/* - * Various constants used by items. - */ -#define ZN_ANY_CIRCLES -1 -/* - * Constants for item parts. The fields or item indexable parts are coded - * as positive or null integers. The item specific parts (not indexable) are - * coded as negatives begining at -2 up to -9 which is the current limit. The - * -1 value is reserved to indicate no part. - */ - -#define PART_NUMBER_TO_BIT(part) (1 << (ABS(part)-2)) -#define ZN_NO_PART -1 - -/* - * Constants used to specify circle approximation quality. - */ -#define ZN_CIRCLE_COARSE 0 -#define ZN_CIRCLE_MEDIUM ZN_CIRCLE_COARSE+1 -#define ZN_CIRCLE_FINE ZN_CIRCLE_MEDIUM+1 -#define ZN_CIRCLE_FINEST ZN_CIRCLE_FINE+1 - -/* - * Some flags macros. - */ -#define ISSET(var, mask) ((var) & (mask)) -#define ISCLEAR(var, mask) (((var) & (mask)) == 0) -#define SET(var,mask) ((var) |= (mask)) -#define CLEAR(var, mask) ((var) &= ~(mask)) -#define ASSIGN(var, mask, bool) ((bool) ? SET((var), (mask)) : CLEAR((var), (mask))) +#ifndef TCL_INTEGER_SPACE +# define TCL_INTEGER_SPACE 24 +#endif +#ifdef PTK /* * Macros for Tk8.4/perl/Tk utf compatibility */ -#ifdef PTK #define Tcl_NumUtfChars(str, len) ((len)<0?strlen(str):(len)) #define Tcl_UtfAtIndex(str, index) (&(str)[(index)]) #define Tcl_GetString(str) (Tcl_GetStringFromObj(str, NULL)) + +#define Tk_GetScrollInfoObj(interp, argc, args, fract, count) \ + Tk_GetScrollInfo(interp, argc, (Tcl_Obj **) args, fract, count) +#endif + +/* + * Macros for Windows compatibility + */ +#ifdef _WIN32 +# include +#undef XFillRectangle + void XFillRectangle(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height); +#undef XFillRectangles +void XFillRectangles(Display*display, Drawable d, GC gc, + XRectangle *rectangles, int nrectangles); +#undef XFillArc +void XFillArc(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int start, int extent); +#undef XFillPolygon +void XFillPolygon(Display* display, Drawable d, GC gc, + XPoint* points, int npoints, int shape, int mode); +#undef XDrawRectangle +void XDrawRectangle(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height); +#undef XDrawArc +void XDrawArc(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int start, int extent); +#undef XDrawLine + void XDrawLine(Display* display, Drawable d, GC gc, + int x1, int y1, int x2, int y2); +#undef XDrawLines +void XDrawLines(Display* display, Drawable d, GC gc, + XPoint* points, int npoints, int mode); + +void ZnUnionRegion(TkRegion sra, TkRegion srb, + TkRegion dr_return); +void ZnOffsetRegion(TkRegion reg, int dx, int dy); +TkRegion ZnPolygonRegion(XPoint *points, int n, + int fill_rule); +# ifdef GL +# define ZnGLContext HGLRC +# define ZnGLMakeCurrent(wi) \ +{ \ + wi->hdc = GetDC(wi->hwnd); \ + wglMakeCurrent(wi->hdc, wi->gl_context); \ +} +# define ZnGLRelease(wi) \ + ReleaseDC(wi->hwnd, wi->hdc); +# define ZnGLDestroyContext(wi) \ + wglDeleteContext(wi->gl_context) +# define ZnGLSwapBuffers(wi) \ + SwapBuffers(wi->hdc) +# define ZnGLWaitGL() +# define ZN_GL_LINE_WIDTH_RANGE GL_LINE_WIDTH_RANGE +# define ZN_GL_POINT_SIZE_RANGE GL_POINT_SIZE_RANGE +# endif +#else /* !_WIN32 */ +# define ZnPolygonRegion(points, npoints, fillrule) \ + ((TkRegion) XPolygonRegion(points, npoints, fillrule)) +# define ZnUnionRegion(sra, srb, rreturn) \ + XUnionRegion((Region) sra, (Region) srb, (Region) rreturn) +# define ZnOffsetRegion(reg, dx, dy) \ + XOffsetRegion((Region) reg, dx, dy) +# ifdef GL +# define ZnGLContext GLXContext +# define ZnGLMakeCurrent(wi) \ + glXMakeCurrent(wi->dpy, Tk_WindowId(wi->win), wi->gl_context); +# define ZnGLRelease(wi) +# define ZnGLDestroyContext(wi) \ + glXDestroyContext(wi->dpy, wi->gl_context); +# define ZnGLSwapBuffers(wi) \ + glXSwapBuffers(wi->dpy, Tk_WindowId(wi->win)) +# define ZnGLWaitGL() \ + glXWaitGL() +# define ZN_GL_LINE_WIDTH_RANGE GL_SMOOTH_LINE_WIDTH_RANGE +# define ZN_GL_POINT_SIZE_RANGE GL_SMOOTH_POINT_SIZE_RANGE +# endif #endif #ifdef __CPLUSPLUS__ -- cgit v1.1