1 /* 2 * bltObjConfig.h -- 3 * 4 * This file contains the Tcl_Obj based versions of the old 5 * Tk_ConfigureWidget procedures. 6 * 7 * Copyright (c) 1990-1994 The Regents of the University of California. 8 * Copyright (c) 1994-1997 Sun Microsystems, Inc. 9 * 10 * See the file "license.terms" for information on usage and redistribution 11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12 * 13 */ 14 15 #ifndef BLT_OBJCONFIG_H 16 #define BLT_OBJCONFIG_H 17 18 /* 19 * This is a Tcl_Obj based replacement for the widget configuration 20 * functions in Tk. 21 * 22 * What not use the new Tk_Option interface? 23 * 24 * There were design changes in the new Tk_Option interface that 25 * make it unwieldy. 26 * 27 * o You have to dynamically allocate, store, and deallocate 28 * your option table. 29 * o The Tk_FreeConfigOptions routine requires a tkwin argument. 30 * Unfortunately, most widgets save the display pointer and 31 * deference their tkwin when the window is destroyed. 32 * o There's no TK_CONFIG_CUSTOM functionality. This means that 33 * save special options must be saved as strings by 34 * Tk_ConfigureWidget and processed later, thus losing the 35 * benefits of Tcl_Objs. It also make error handling 36 * problematic, since you don't pick up certain errors like 37 * 38 * .widget configure -myoption bad -myoption good 39 * 40 * You will never see the first "bad" value. 41 * o Especially compared to the former Tk_ConfigureWidget calls, 42 * the new interface is overly complex. If there was a big 43 * performance win, it might be worth the effort. But let's 44 * face it, this biggest wins are in processing custom options 45 * values with thousands of elements. Most common resources 46 * (font, color, etc) have string tokens anyways. 47 * 48 * On the other hand, the replacement functions in this file fell 49 * into place quite easily both from the aspect of API writer and 50 * user. The biggest benefit is that you don't need to change lots 51 * of working code just to get the benefits of Tcl_Objs. 52 * 53 */ 54 #define SIDE_LEFT (0) 55 #define SIDE_TOP (1) 56 #define SIDE_RIGHT (2) 57 #define SIDE_BOTTOM (3) 58 59 #define SIDE_HORIZONTAL(s) (!((s) & 0x1)) 60 #define SIDE_VERTICAL(s) ((s) & 0x1) 61 62 #ifndef Blt_Offset 63 #ifdef offsetof 64 #define Blt_Offset(type, field) ((int) offsetof(type, field)) 65 #else 66 #define Blt_Offset(type, field) ((int) ((char *) &((type *) 0)->field)) 67 #endif 68 #endif /* Blt_Offset */ 69 70 typedef int (Blt_OptionParseProc) _ANSI_ARGS_((ClientData clientData, 71 Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, char *widgRec, 72 int offset)); 73 typedef Tcl_Obj *(Blt_OptionPrintProc) _ANSI_ARGS_((ClientData clientData, 74 Tcl_Interp *interp, Tk_Window tkwin, char *widgRec, int offset)); 75 typedef int (Blt_OptionFreeProc) _ANSI_ARGS_((ClientData clientData, 76 Display *display, char *widgRec, int offset, char *oldPtr)); 77 78 typedef struct Blt_CustomOption { 79 Blt_OptionParseProc *parseProc; /* Procedure to call to parse an 80 * option and store it in converted 81 * form. */ 82 Blt_OptionPrintProc *printProc; /* Procedure to return a printable 83 * string describing an existing 84 * option. */ 85 Blt_OptionFreeProc *freeProc; /* Procedure to free the value. */ 86 87 ClientData clientData; /* Arbitrary one-word value used by 88 * option parser: passed to 89 * parseProc and printProc. */ 90 } Blt_CustomOption; 91 92 /* 93 * Structure used to specify information for Tk_ConfigureWidget. Each 94 * structure gives complete information for one option, including 95 * how the option is specified on the command line, where it appears 96 * in the option database, etc. 97 */ 98 99 typedef struct { 100 int type; /* Type of option, such as BLT_CONFIG_COLOR; 101 * see definitions below. Last option in 102 * table must have type BLT_CONFIG_END. */ 103 char *switchName; /* Switch used to specify option in argv. 104 * NULL means this spec is part of a group. */ 105 Tk_Uid dbName; /* Name for option in option database. */ 106 Tk_Uid dbClass; /* Class for option in database. */ 107 Tk_Uid defValue; /* Default value for option if not 108 * specified in command line or database. */ 109 int offset; /* Where in widget record to store value; 110 * use Tk_Offset macro to generate values 111 * for this. */ 112 int specFlags; /* Any combination of the values defined 113 * below; other bits are used internally 114 * by tkConfig.c. */ 115 Blt_CustomOption *customPtr; /* If type is BLT_CONFIG_CUSTOM then this is 116 * a pointer to info about how to parse and 117 * print the option. Otherwise it is 118 * irrelevant. */ 119 } Blt_ConfigSpec; 120 121 /* 122 * Type values for Blt_ConfigSpec structures. See the user 123 * documentation for details. 124 */ 125 126 typedef enum { 127 BLT_CONFIG_ACTIVE_CURSOR, 128 BLT_CONFIG_ANCHOR, 129 BLT_CONFIG_BITMAP, 130 BLT_CONFIG_BOOLEAN, 131 BLT_CONFIG_BORDER, 132 BLT_CONFIG_CAP_STYLE, 133 BLT_CONFIG_COLOR, 134 BLT_CONFIG_CURSOR, 135 BLT_CONFIG_CUSTOM, 136 BLT_CONFIG_DOUBLE, 137 BLT_CONFIG_FONT, 138 BLT_CONFIG_INT, 139 BLT_CONFIG_JOIN_STYLE, 140 BLT_CONFIG_JUSTIFY, 141 BLT_CONFIG_MM, 142 BLT_CONFIG_PIXELS, 143 BLT_CONFIG_RELIEF, 144 BLT_CONFIG_STRING, 145 BLT_CONFIG_SYNONYM, 146 BLT_CONFIG_UID, 147 BLT_CONFIG_WINDOW, 148 149 BLT_CONFIG_BITFLAG, 150 BLT_CONFIG_DASHES, 151 BLT_CONFIG_DISTANCE, /* */ 152 BLT_CONFIG_FILL, 153 BLT_CONFIG_FLOAT, 154 BLT_CONFIG_LIST, 155 BLT_CONFIG_LISTOBJ, 156 BLT_CONFIG_PAD, 157 BLT_CONFIG_POS_DISTANCE, /* */ 158 BLT_CONFIG_SHADOW, /* */ 159 BLT_CONFIG_SIDE, 160 BLT_CONFIG_STATE, 161 BLT_CONFIG_TILE, 162 BLT_CONFIG_OBJ, 163 BLT_CONFIG_OBJCMD, 164 BLT_CONFIG_ARROW, 165 166 BLT_CONFIG_END 167 } Blt_ConfigTypes; 168 169 /* 170 * Possible values for flags argument to Tk_ConfigureWidget: 171 */ 172 173 #define BLT_CONFIG_OBJV_ONLY 1 174 #define BLT_CONFIG_OBJS 0x80 175 176 /* 177 * Possible flag values for Blt_ConfigSpec structures. Any bits at 178 * or above BLT_CONFIG_USER_BIT may be used by clients for selecting 179 * certain entries. Before changing any values here, coordinate with 180 * tkOldConfig.c (internal-use-only flags are defined there). 181 */ 182 183 #define BLT_CONFIG_NULL_OK 1 184 #define BLT_CONFIG_COLOR_ONLY 2 185 #define BLT_CONFIG_MONO_ONLY 4 186 #define BLT_CONFIG_DONT_SET_DEFAULT 8 187 #define BLT_CONFIG_OPTION_SPECIFIED 0x10 188 #define BLT_CONFIG_USER_BIT 0x100 189 190 /* 191 * Values for "flags" field of Blt_ConfigSpec structures. Be sure 192 * to coordinate these values with those defined in tk.h 193 * (BLT_CONFIG_COLOR_ONLY, etc.). There must not be overlap! 194 * 195 * INIT - Non-zero means (char *) things have been 196 * converted to Tk_Uid's. 197 */ 198 199 #define INIT 0x20 200 201 EXTERN int Blt_ConfigureInfoFromObj _ANSI_ARGS_((Tcl_Interp *interp, 202 Tk_Window tkwin, Blt_ConfigSpec *specs, char *widgRec, 203 Tcl_Obj *objPtr, int flags)); 204 EXTERN int Blt_ConfigureValueFromObj _ANSI_ARGS_((Tcl_Interp *interp, 205 Tk_Window tkwin, Blt_ConfigSpec *specs, char * widgRec, 206 Tcl_Obj *objPtr, int flags)); 207 EXTERN int Blt_ConfigureWidgetFromObj _ANSI_ARGS_((Tcl_Interp *interp, 208 Tk_Window tkwin, Blt_ConfigSpec *specs, int objc, Tcl_Obj *CONST *objv, 209 char *widgRec, int flags, Tk_Window subwin)); 210 EXTERN int Blt_ConfigureComponentFromObj _ANSI_ARGS_((Tcl_Interp *interp, 211 Tk_Window tkwin, char *name, char *className, Blt_ConfigSpec *specs, 212 int objc, Tcl_Obj *CONST *objv, char *widgRec, int flags)); 213 EXTERN int Blt_FormatSpecOptions _ANSI_ARGS_(( Tcl_Interp *interp, Blt_ConfigSpec *specs)); 214 215 EXTERN int Blt_ObjConfigModified _ANSI_ARGS_(TCL_VARARGS(Blt_ConfigSpec *, specs)); 216 EXTERN void Blt_FreeObjOptions _ANSI_ARGS_((Tcl_Interp *interp, Blt_ConfigSpec *specs, 217 char *widgetRec, Display *display, int needFlags)); 218 219 EXTERN int Blt_ObjIsOption _ANSI_ARGS_((Tcl_Interp* interp, Blt_ConfigSpec *specs, Tcl_Obj *objPtr, 220 int flags)); 221 222 EXTERN int Blt_GetPositionFromObj _ANSI_ARGS_((Tcl_Interp *interp, 223 Tcl_Obj *objPtr, int *indexPtr)); 224 225 EXTERN int Blt_GetPositionSizeFromObj _ANSI_ARGS_((Tcl_Interp *interp, 226 Tcl_Obj *objPtr, int size, int *indexPtr)); 227 228 EXTERN int Blt_GetPixelsFromObj _ANSI_ARGS_((Tcl_Interp *interp, 229 Tk_Window tkwin, Tcl_Obj *objPtr, int flags, int *valuePtr)); 230 231 EXTERN int Blt_GetPadFromObj _ANSI_ARGS_((Tcl_Interp *interp, 232 Tk_Window tkwin, Tcl_Obj *objPtr, Blt_Pad *padPtr)); 233 234 EXTERN int Blt_GetShadowFromObj _ANSI_ARGS_((Tcl_Interp *interp, 235 Tk_Window tkwin, Tcl_Obj *objPtr, Shadow *shadowPtr)); 236 237 EXTERN int Blt_GetStateFromObj _ANSI_ARGS_((Tcl_Interp *interp, 238 Tcl_Obj *objPtr, int *statePtr)); 239 240 EXTERN int Blt_GetFillFromObj _ANSI_ARGS_((Tcl_Interp *interp, 241 Tcl_Obj *objPtr, int *fillPtr)); 242 243 EXTERN int Blt_GetDashesFromObj _ANSI_ARGS_((Tcl_Interp *interp, 244 Tcl_Obj *objPtr, Blt_Dashes *dashesPtr)); 245 246 EXTERN Blt_ConfigSpec * Blt_GetCachedBltSpecs _ANSI_ARGS_((Tcl_Interp *interp, 247 const Blt_ConfigSpec *staticSpecs)); 248 249 #if ((TK_VERSION_NUMBER >= _VERSION(8,0,0)) && \ 250 (TK_VERSION_NUMBER < _VERSION(8,1,0))) 251 EXTERN int Tk_GetAnchorFromObj _ANSI_ARGS_((Tcl_Interp *interp, 252 Tcl_Obj *objPtr, Tk_Anchor *anchorPtr)); 253 EXTERN int Tk_GetJustifyFromObj _ANSI_ARGS_((Tcl_Interp *interp, 254 Tcl_Obj *objPtr, Tk_Justify *justifyPtr)); 255 EXTERN int Tk_GetReliefFromObj _ANSI_ARGS_((Tcl_Interp *interp, 256 Tcl_Obj *objPtr, int *reliefPtr)); 257 EXTERN int Tk_GetMMFromObj _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin, 258 Tcl_Obj *objPtr, double *doublePtr)); 259 EXTERN int Tk_GetPixelsFromObj _ANSI_ARGS_((Tcl_Interp *interp, 260 Tk_Window tkwin, Tcl_Obj *objPtr, int *intPtr)); 261 EXTERN Tk_3DBorder Tk_Alloc3DBorderFromObj _ANSI_ARGS_((Tcl_Interp *interp, 262 Tk_Window tkwin, Tcl_Obj *objPtr)); 263 EXTERN Pixmap Tk_AllocBitmapFromObj _ANSI_ARGS_((Tcl_Interp *interp, 264 Tk_Window tkwin, Tcl_Obj *objPtr)); 265 EXTERN Tk_Font Tk_AllocFontFromObj _ANSI_ARGS_((Tcl_Interp *interp, 266 Tk_Window tkwin, Tcl_Obj *objPtr)); 267 EXTERN Tk_Cursor Tk_AllocCursorFromObj _ANSI_ARGS_((Tcl_Interp *interp, 268 Tk_Window tkwin, Tcl_Obj *objPtr)); 269 EXTERN XColor *Tk_AllocColorFromObj _ANSI_ARGS_((Tcl_Interp *interp, 270 Tk_Window tkwin, Tcl_Obj *objPtr)); 271 #endif /* 8.0 */ 272 273 #endif /* BLT_OBJCONFIG_H */ 274