From 8d003d21a450eebb0355405912b6996416763adb Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 18 Jun 2002 23:51:46 +0000 Subject: Added TIP#48 style engine implementation Frederic Bonnet to supply docs+tests as soon as possible. --- ChangeLog | 23 + generic/tk.decls | 407 ++++++------ generic/tk.h | 79 ++- generic/tkConfig.c | 176 +++++- generic/tkDecls.h | 133 +++- generic/tkInt.decls | 9 +- generic/tkInt.h | 5 +- generic/tkIntDecls.h | 16 +- generic/tkStubInit.c | 20 +- generic/tkStyle.c | 1663 ++++++++++++++++++++++++++++++++++++++++++++++++++ generic/tkWindow.c | 4 +- unix/Makefile.in | 15 +- win/Makefile.in | 3 +- win/makefile.vc | 3 +- 14 files changed, 2339 insertions(+), 217 deletions(-) create mode 100644 generic/tkStyle.c diff --git a/ChangeLog b/ChangeLog index 230cb17..8e54491 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2002-06-19 Donal K. Fellows + + * generic/tkStyle.c: TIP#48 style engine. + See http://purl.org/tcl/tip/48.html for details. + + * generic/tkConfig.c (GetOptionFromObj): Split to allow for access + to option tables via name as well as via object. + (TkGetOptionSpec): Semi-public interface to GetOption functionality. + (DoObjConfig, Tk_RestoreSavedOptions, FreeResources) + (GetObjectForOption): Basic style support for configure. + + * generic/tkWindow.c (TkCreateMainWindow, Tk_DestroyWindow): Added + calls to set up and tear down the style subsystem. + + * generic/tk.decls, generic/tk.h: Many declarations forming TIP#48 + public interface. + + * generic/tkInt.decls (TkStylePkgInit,TkStylePkgFree): + * generic/tkInt.h (TkGetOptionSpec): Supporting declarations. + + * unix/Makefile.in, win/Makefile.in, win/makefile.vc: Added + tkStyle.c to list of generic source files. + 2002-06-18 Donal K. Fellows * tests/defs.tcl (makeFile): Defined the return value of this diff --git a/generic/tk.decls b/generic/tk.decls index 317baca..0d2ce92 100644 --- a/generic/tk.decls +++ b/generic/tk.decls @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tk.decls,v 1.21 2002/06/15 00:21:41 hobbs Exp $ +# RCS: @(#) $Id: tk.decls,v 1.22 2002/06/18 23:51:46 dkf Exp $ library tk @@ -36,48 +36,48 @@ declare 1 generic { } declare 2 generic { - GC Tk_3DBorderGC (Tk_Window tkwin, Tk_3DBorder border, \ + GC Tk_3DBorderGC (Tk_Window tkwin, Tk_3DBorder border, int which) } declare 3 generic { - void Tk_3DHorizontalBevel (Tk_Window tkwin, \ - Drawable drawable, Tk_3DBorder border, int x, \ - int y, int width, int height, int leftIn, \ + void Tk_3DHorizontalBevel (Tk_Window tkwin, + Drawable drawable, Tk_3DBorder border, int x, + int y, int width, int height, int leftIn, int rightIn, int topBevel, int relief) } declare 4 generic { - void Tk_3DVerticalBevel (Tk_Window tkwin, \ - Drawable drawable, Tk_3DBorder border, int x, \ - int y, int width, int height, int leftBevel, \ + void Tk_3DVerticalBevel (Tk_Window tkwin, + Drawable drawable, Tk_3DBorder border, int x, + int y, int width, int height, int leftBevel, int relief) } declare 5 generic { - void Tk_AddOption (Tk_Window tkwin, CONST char *name, \ + void Tk_AddOption (Tk_Window tkwin, CONST char *name, CONST char *value, int priority) } declare 6 generic { - void Tk_BindEvent (Tk_BindingTable bindingTable, \ - XEvent *eventPtr, Tk_Window tkwin, int numObjects, \ + void Tk_BindEvent (Tk_BindingTable bindingTable, + XEvent *eventPtr, Tk_Window tkwin, int numObjects, ClientData *objectPtr) } declare 7 generic { - void Tk_CanvasDrawableCoords (Tk_Canvas canvas, \ - double x, double y, short *drawableXPtr, \ + void Tk_CanvasDrawableCoords (Tk_Canvas canvas, + double x, double y, short *drawableXPtr, short *drawableYPtr) } declare 8 generic { - void Tk_CanvasEventuallyRedraw (Tk_Canvas canvas, int x1, int y1, \ + void Tk_CanvasEventuallyRedraw (Tk_Canvas canvas, int x1, int y1, int x2, int y2) } declare 9 generic { - int Tk_CanvasGetCoord (Tcl_Interp *interp, \ + int Tk_CanvasGetCoord (Tcl_Interp *interp, Tk_Canvas canvas, CONST char *str, double *doublePtr) } @@ -86,28 +86,28 @@ declare 10 generic { } declare 11 generic { - int Tk_CanvasPsBitmap (Tcl_Interp *interp, \ - Tk_Canvas canvas, Pixmap bitmap, int x, int y, \ + int Tk_CanvasPsBitmap (Tcl_Interp *interp, + Tk_Canvas canvas, Pixmap bitmap, int x, int y, int width, int height) } declare 12 generic { - int Tk_CanvasPsColor (Tcl_Interp *interp, \ + int Tk_CanvasPsColor (Tcl_Interp *interp, Tk_Canvas canvas, XColor *colorPtr) } declare 13 generic { - int Tk_CanvasPsFont (Tcl_Interp *interp, \ + int Tk_CanvasPsFont (Tcl_Interp *interp, Tk_Canvas canvas, Tk_Font font) } declare 14 generic { - void Tk_CanvasPsPath (Tcl_Interp *interp, \ + void Tk_CanvasPsPath (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr, int numPoints) } declare 15 generic { - int Tk_CanvasPsStipple (Tcl_Interp *interp, \ + int Tk_CanvasPsStipple (Tcl_Interp *interp, Tk_Canvas canvas, Pixmap bitmap) } @@ -120,12 +120,12 @@ declare 17 generic { } declare 18 generic { - int Tk_CanvasTagsParseProc (ClientData clientData, Tcl_Interp *interp, \ + int Tk_CanvasTagsParseProc (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, char *value, char *widgRec, int offset) } declare 19 generic { - char * Tk_CanvasTagsPrintProc (ClientData clientData, Tk_Window tkwin, \ + char * Tk_CanvasTagsPrintProc (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) } @@ -134,17 +134,17 @@ declare 20 generic { } declare 21 generic { - void Tk_CanvasWindowCoords (Tk_Canvas canvas, double x, double y, \ + void Tk_CanvasWindowCoords (Tk_Canvas canvas, double x, double y, short *screenXPtr, short *screenYPtr) } declare 22 generic { - void Tk_ChangeWindowAttributes (Tk_Window tkwin, unsigned long valueMask, \ + void Tk_ChangeWindowAttributes (Tk_Window tkwin, unsigned long valueMask, XSetWindowAttributes *attsPtr) } declare 23 generic { - int Tk_CharBbox (Tk_TextLayout layout, int index, int *xPtr, \ + int Tk_CharBbox (Tk_TextLayout layout, int index, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr) } @@ -153,7 +153,7 @@ declare 24 generic { } declare 25 generic { - int Tk_ClipboardAppend (Tcl_Interp *interp,Tk_Window tkwin, \ + int Tk_ClipboardAppend (Tcl_Interp *interp,Tk_Window tkwin, Atom target, Atom format, char* buffer) } @@ -162,33 +162,33 @@ declare 26 generic { } declare 27 generic { - int Tk_ConfigureInfo (Tcl_Interp *interp, \ - Tk_Window tkwin, Tk_ConfigSpec *specs, \ + int Tk_ConfigureInfo (Tcl_Interp *interp, + Tk_Window tkwin, Tk_ConfigSpec *specs, char *widgRec, char *argvName, int flags) } declare 28 generic { - int Tk_ConfigureValue (Tcl_Interp *interp, \ - Tk_Window tkwin, Tk_ConfigSpec *specs, \ + int Tk_ConfigureValue (Tcl_Interp *interp, + Tk_Window tkwin, Tk_ConfigSpec *specs, char *widgRec, char *argvName, int flags) } declare 29 generic { - int Tk_ConfigureWidget (Tcl_Interp *interp, \ - Tk_Window tkwin, Tk_ConfigSpec *specs, \ - int argc, char **argv, char *widgRec, \ + int Tk_ConfigureWidget (Tcl_Interp *interp, + Tk_Window tkwin, Tk_ConfigSpec *specs, + int argc, char **argv, char *widgRec, int flags) } declare 30 generic { - void Tk_ConfigureWindow (Tk_Window tkwin, \ + void Tk_ConfigureWindow (Tk_Window tkwin, unsigned int valueMask, XWindowChanges *valuePtr) } declare 31 generic { - Tk_TextLayout Tk_ComputeTextLayout (Tk_Font font, \ - CONST char *str, int numChars, int wrapLength, \ - Tk_Justify justify, int flags, int *widthPtr, \ + Tk_TextLayout Tk_ComputeTextLayout (Tk_Font font, + CONST char *str, int numChars, int wrapLength, + Tk_Justify justify, int flags, int *widthPtr, int *heightPtr) } @@ -197,8 +197,8 @@ declare 32 generic { } declare 33 generic { - unsigned long Tk_CreateBinding (Tcl_Interp *interp, \ - Tk_BindingTable bindingTable, ClientData object, \ + unsigned long Tk_CreateBinding (Tcl_Interp *interp, + Tk_BindingTable bindingTable, ClientData object, char *eventStr, char *command, int append) } @@ -207,14 +207,14 @@ declare 34 generic { } declare 35 generic { - Tk_ErrorHandler Tk_CreateErrorHandler (Display *display, \ - int errNum, int request, int minorCode, \ + Tk_ErrorHandler Tk_CreateErrorHandler (Display *display, + int errNum, int request, int minorCode, Tk_ErrorProc *errorProc, ClientData clientData) } declare 36 generic { - void Tk_CreateEventHandler (Tk_Window token, \ - unsigned long mask, Tk_EventProc *proc, \ + void Tk_CreateEventHandler (Tk_Window token, + unsigned long mask, Tk_EventProc *proc, ClientData clientData) } @@ -235,24 +235,24 @@ declare 40 generic { } declare 41 generic { - void Tk_CreateSelHandler (Tk_Window tkwin, \ - Atom selection, Atom target, \ - Tk_SelectionProc *proc, ClientData clientData, \ + void Tk_CreateSelHandler (Tk_Window tkwin, + Atom selection, Atom target, + Tk_SelectionProc *proc, ClientData clientData, Atom format) } declare 42 generic { - Tk_Window Tk_CreateWindow (Tcl_Interp *interp, \ + Tk_Window Tk_CreateWindow (Tcl_Interp *interp, Tk_Window parent, char *name, char *screenName) } declare 43 generic { - Tk_Window Tk_CreateWindowFromPath (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_Window Tk_CreateWindowFromPath (Tcl_Interp *interp, Tk_Window tkwin, char *pathName, char *screenName) } declare 44 generic { - int Tk_DefineBitmap (Tcl_Interp *interp, CONST char *name, char *source, \ + int Tk_DefineBitmap (Tcl_Interp *interp, CONST char *name, char *source, int width, int height) } @@ -265,8 +265,8 @@ declare 46 generic { } declare 47 generic { - int Tk_DeleteBinding (Tcl_Interp *interp, \ - Tk_BindingTable bindingTable, ClientData object, \ + int Tk_DeleteBinding (Tcl_Interp *interp, + Tk_BindingTable bindingTable, ClientData object, char *eventStr) } @@ -279,8 +279,8 @@ declare 49 generic { } declare 50 generic { - void Tk_DeleteEventHandler (Tk_Window token, \ - unsigned long mask, Tk_EventProc *proc, \ + void Tk_DeleteEventHandler (Tk_Window token, + unsigned long mask, Tk_EventProc *proc, ClientData clientData) } @@ -309,45 +309,45 @@ declare 56 generic { } declare 57 generic { - void Tk_Draw3DPolygon (Tk_Window tkwin, \ - Drawable drawable, Tk_3DBorder border, \ - XPoint *pointPtr, int numPoints, int borderWidth, \ + void Tk_Draw3DPolygon (Tk_Window tkwin, + Drawable drawable, Tk_3DBorder border, + XPoint *pointPtr, int numPoints, int borderWidth, int leftRelief) } declare 58 generic { - void Tk_Draw3DRectangle (Tk_Window tkwin, Drawable drawable, \ - Tk_3DBorder border, int x, int y, int width, int height, \ + void Tk_Draw3DRectangle (Tk_Window tkwin, Drawable drawable, + Tk_3DBorder border, int x, int y, int width, int height, int borderWidth, int relief) } declare 59 generic { - void Tk_DrawChars (Display *display, Drawable drawable, GC gc, \ + void Tk_DrawChars (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, CONST char *source, int numBytes, int x, int y) } declare 60 generic { - void Tk_DrawFocusHighlight (Tk_Window tkwin, GC gc, int width, \ + void Tk_DrawFocusHighlight (Tk_Window tkwin, GC gc, int width, Drawable drawable) } declare 61 generic { - void Tk_DrawTextLayout (Display *display, \ - Drawable drawable, GC gc, Tk_TextLayout layout, \ + void Tk_DrawTextLayout (Display *display, + Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int firstChar, int lastChar) } declare 62 generic { - void Tk_Fill3DPolygon (Tk_Window tkwin, \ - Drawable drawable, Tk_3DBorder border, \ - XPoint *pointPtr, int numPoints, int borderWidth, \ + void Tk_Fill3DPolygon (Tk_Window tkwin, + Drawable drawable, Tk_3DBorder border, + XPoint *pointPtr, int numPoints, int borderWidth, int leftRelief) } declare 63 generic { - void Tk_Fill3DRectangle (Tk_Window tkwin, \ - Drawable drawable, Tk_3DBorder border, int x, \ - int y, int width, int height, int borderWidth, \ + void Tk_Fill3DRectangle (Tk_Window tkwin, + Drawable drawable, Tk_3DBorder border, int x, + int y, int width, int height, int borderWidth, int relief) } @@ -392,7 +392,7 @@ declare 73 generic { } declare 74 generic { - void Tk_FreeOptions (Tk_ConfigSpec *specs, \ + void Tk_FreeOptions (Tk_ConfigSpec *specs, char *widgRec, Display *display, int needFlags) } @@ -417,17 +417,17 @@ declare 79 generic { } declare 80 generic { - Tk_3DBorder Tk_Get3DBorder (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_3DBorder Tk_Get3DBorder (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid colorName) } declare 81 generic { - void Tk_GetAllBindings (Tcl_Interp *interp, \ + void Tk_GetAllBindings (Tcl_Interp *interp, Tk_BindingTable bindingTable, ClientData object) } declare 82 generic { - int Tk_GetAnchor (Tcl_Interp *interp, \ + int Tk_GetAnchor (Tcl_Interp *interp, char *str, Tk_Anchor *anchorPtr) } @@ -436,8 +436,8 @@ declare 83 generic { } declare 84 generic { - char * Tk_GetBinding (Tcl_Interp *interp, \ - Tk_BindingTable bindingTable, ClientData object, \ + char * Tk_GetBinding (Tcl_Interp *interp, + Tk_BindingTable bindingTable, ClientData object, char *eventStr) } @@ -446,7 +446,7 @@ declare 85 generic { } declare 86 generic { - Pixmap Tk_GetBitmapFromData (Tcl_Interp *interp, \ + Pixmap Tk_GetBitmapFromData (Tcl_Interp *interp, Tk_Window tkwin, char *source, int width, int height) } @@ -467,19 +467,19 @@ declare 90 generic { } declare 91 generic { - Tk_Cursor Tk_GetCursor (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_Cursor Tk_GetCursor (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid str) } declare 92 generic { - Tk_Cursor Tk_GetCursorFromData (Tcl_Interp *interp, \ - Tk_Window tkwin, char *source, char *mask, \ - int width, int height, int xHot, int yHot, \ + Tk_Cursor Tk_GetCursorFromData (Tcl_Interp *interp, + Tk_Window tkwin, char *source, char *mask, + int width, int height, int xHot, int yHot, Tk_Uid fg, Tk_Uid bg) } declare 93 generic { - Tk_Font Tk_GetFont (Tcl_Interp *interp, \ + Tk_Font Tk_GetFont (Tcl_Interp *interp, Tk_Window tkwin, CONST char *str) } @@ -496,12 +496,12 @@ declare 96 generic { } declare 97 generic { - Tk_Image Tk_GetImage (Tcl_Interp *interp, Tk_Window tkwin, char *name, \ + Tk_Image Tk_GetImage (Tcl_Interp *interp, Tk_Window tkwin, char *name, Tk_ImageChangedProc *changeProc, ClientData clientData) } declare 98 generic { - ClientData Tk_GetImageMasterData (Tcl_Interp *interp, \ + ClientData Tk_GetImageMasterData (Tcl_Interp *interp, char *name, Tk_ImageType **typePtrPtr) } @@ -514,7 +514,7 @@ declare 100 generic { } declare 101 generic { - int Tk_GetJustify (Tcl_Interp *interp, \ + int Tk_GetJustify (Tcl_Interp *interp, char *str, Tk_Justify *justifyPtr) } @@ -527,12 +527,12 @@ declare 103 generic { } declare 104 generic { - int Tk_GetPixels (Tcl_Interp *interp, \ + int Tk_GetPixels (Tcl_Interp *interp, Tk_Window tkwin, CONST char *str, int *intPtr) } declare 105 generic { - Pixmap Tk_GetPixmap (Display *display, Drawable d, \ + Pixmap Tk_GetPixmap (Display *display, Drawable d, int width, int height, int depth) } @@ -545,18 +545,18 @@ declare 107 generic { } declare 108 generic { - int Tk_GetScrollInfo (Tcl_Interp *interp, \ + int Tk_GetScrollInfo (Tcl_Interp *interp, int argc, char **argv, double *dblPtr, int *intPtr) } declare 109 generic { - int Tk_GetScreenMM (Tcl_Interp *interp, \ + int Tk_GetScreenMM (Tcl_Interp *interp, Tk_Window tkwin, CONST char *str, double *doublePtr) } declare 110 generic { - int Tk_GetSelection (Tcl_Interp *interp, \ - Tk_Window tkwin, Atom selection, Atom target, \ + int Tk_GetSelection (Tcl_Interp *interp, + Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc *proc, ClientData clientData) } @@ -565,13 +565,13 @@ declare 111 generic { } declare 112 generic { - Visual * Tk_GetVisual (Tcl_Interp *interp, \ - Tk_Window tkwin, char *str, int *depthPtr, \ + Visual * Tk_GetVisual (Tcl_Interp *interp, + Tk_Window tkwin, char *str, int *depthPtr, Colormap *colormapPtr) } declare 113 generic { - void Tk_GetVRootGeometry (Tk_Window tkwin, \ + void Tk_GetVRootGeometry (Tk_Window tkwin, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr) } @@ -588,7 +588,7 @@ declare 116 generic { } declare 117 generic { - void Tk_ImageChanged (Tk_ImageMaster master, int x, int y, \ + void Tk_ImageChanged (Tk_ImageMaster master, int x, int y, int width, int height, int imageWidth, int imageHeight) } @@ -601,12 +601,12 @@ declare 119 generic { } declare 120 generic { - int Tk_IntersectTextLayout (Tk_TextLayout layout, int x, int y, \ + int Tk_IntersectTextLayout (Tk_TextLayout layout, int x, int y, int width, int height) } declare 121 generic { - void Tk_MaintainGeometry (Tk_Window slave, \ + void Tk_MaintainGeometry (Tk_Window slave, Tk_Window master, int x, int y, int width, int height) } @@ -619,7 +619,7 @@ declare 123 generic { } declare 124 generic { - void Tk_ManageGeometry (Tk_Window tkwin, \ + void Tk_ManageGeometry (Tk_Window tkwin, Tk_GeomMgr *mgrPtr, ClientData clientData) } @@ -628,13 +628,13 @@ declare 125 generic { } declare 126 generic { - int Tk_MeasureChars (Tk_Font tkfont, \ - CONST char *source, int numBytes, int maxPixels, \ + int Tk_MeasureChars (Tk_Font tkfont, + CONST char *source, int numBytes, int maxPixels, int flags, int *lengthPtr) } declare 127 generic { - void Tk_MoveResizeWindow (Tk_Window tkwin, \ + void Tk_MoveResizeWindow (Tk_Window tkwin, int x, int y, int width, int height) } @@ -691,32 +691,32 @@ declare 140 generic { } declare 141 generic { - Tk_Window Tk_NameToWindow (Tcl_Interp *interp, \ + Tk_Window Tk_NameToWindow (Tcl_Interp *interp, CONST char *pathName, Tk_Window tkwin) } declare 142 generic { - void Tk_OwnSelection (Tk_Window tkwin, \ - Atom selection, Tk_LostSelProc *proc, \ + void Tk_OwnSelection (Tk_Window tkwin, + Atom selection, Tk_LostSelProc *proc, ClientData clientData) } declare 143 generic { - int Tk_ParseArgv (Tcl_Interp *interp, \ - Tk_Window tkwin, int *argcPtr, CONST84 char **argv, \ + int Tk_ParseArgv (Tcl_Interp *interp, + Tk_Window tkwin, int *argcPtr, CONST84 char **argv, Tk_ArgvInfo *argTable, int flags) } declare 144 generic { - void Tk_PhotoPutBlock_NoComposite (Tk_PhotoHandle handle, \ - Tk_PhotoImageBlock *blockPtr, int x, int y, \ + void Tk_PhotoPutBlock_NoComposite (Tk_PhotoHandle handle, + Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height) } declare 145 generic { - void Tk_PhotoPutZoomedBlock_NoComposite (Tk_PhotoHandle handle, \ - Tk_PhotoImageBlock *blockPtr, int x, int y, \ - int width, int height, int zoomX, int zoomY, \ + void Tk_PhotoPutZoomedBlock_NoComposite (Tk_PhotoHandle handle, + Tk_PhotoImageBlock *blockPtr, int x, int y, + int width, int height, int zoomX, int zoomY, int subsampleX, int subsampleY) } @@ -757,8 +757,8 @@ declare 154 generic { } declare 155 generic { - void Tk_RedrawImage (Tk_Image image, int imageX, \ - int imageY, int width, int height, \ + void Tk_RedrawImage (Tk_Image image, int imageX, + int imageY, int width, int height, Drawable drawable, int drawableX, int drawableY) } @@ -771,7 +771,7 @@ declare 157 generic { } declare 158 generic { - Tk_RestrictProc *Tk_RestrictEvents (Tk_RestrictProc *proc, \ + Tk_RestrictProc *Tk_RestrictEvents (Tk_RestrictProc *proc, ClientData arg, ClientData *prevArgPtr) } @@ -792,7 +792,7 @@ declare 162 generic { } declare 163 generic { - void Tk_SetGrid (Tk_Window tkwin, int reqWidth, int reqHeight, \ + void Tk_SetGrid (Tk_Window tkwin, int reqWidth, int reqHeight, int gridWidth, int gridHeight) } @@ -825,12 +825,12 @@ declare 170 generic { } declare 171 generic { - int Tk_SetWindowVisual (Tk_Window tkwin, Visual *visual, int depth,\ + int Tk_SetWindowVisual (Tk_Window tkwin, Visual *visual, int depth, Colormap colormap) } declare 172 generic { - void Tk_SizeOfBitmap (Display *display, Pixmap bitmap, int *widthPtr, \ + void Tk_SizeOfBitmap (Display *display, Pixmap bitmap, int *widthPtr, int *heightPtr) } @@ -855,15 +855,15 @@ declare 177 generic { } declare 178 generic { - void Tk_UnderlineChars (Display *display, \ - Drawable drawable, GC gc, Tk_Font tkfont, \ - CONST char *source, int x, int y, int firstByte, \ + void Tk_UnderlineChars (Display *display, + Drawable drawable, GC gc, Tk_Font tkfont, + CONST char *source, int x, int y, int firstByte, int lastByte) } declare 179 generic { - void Tk_UnderlineTextLayout (Display *display, Drawable drawable, GC gc, \ - Tk_TextLayout layout, int x, int y, \ + void Tk_UnderlineTextLayout (Display *display, Drawable drawable, GC gc, + Tk_TextLayout layout, int x, int y, int underline) } @@ -890,33 +890,33 @@ declare 184 generic { # new functions for 8.1 declare 185 generic { - Pixmap Tk_AllocBitmapFromObj (Tcl_Interp *interp, Tk_Window tkwin, \ + Pixmap Tk_AllocBitmapFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) } declare 186 generic { - Tk_3DBorder Tk_Alloc3DBorderFromObj (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_3DBorder Tk_Alloc3DBorderFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) } declare 187 generic { - XColor * Tk_AllocColorFromObj (Tcl_Interp *interp, Tk_Window tkwin, \ + XColor * Tk_AllocColorFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) } declare 188 generic { - Tk_Cursor Tk_AllocCursorFromObj (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_Cursor Tk_AllocCursorFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) } declare 189 generic { - Tk_Font Tk_AllocFontFromObj (Tcl_Interp *interp, Tk_Window tkwin, \ + Tk_Font Tk_AllocFontFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) } declare 190 generic { - Tk_OptionTable Tk_CreateOptionTable (Tcl_Interp *interp, \ + Tk_OptionTable Tk_CreateOptionTable (Tcl_Interp *interp, CONST Tk_OptionSpec *templatePtr) } @@ -937,7 +937,7 @@ declare 194 generic { } declare 195 generic { - void Tk_FreeConfigOptions (char *recordPtr, Tk_OptionTable optionToken, \ + void Tk_FreeConfigOptions (char *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin) } @@ -959,7 +959,7 @@ declare 199 generic { } declare 200 generic { - int Tk_GetAnchorFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr, \ + int Tk_GetAnchorFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr, Tk_Anchor *anchorPtr) } @@ -976,49 +976,48 @@ declare 203 generic { } declare 204 generic { - Tcl_Obj * Tk_GetOptionInfo (Tcl_Interp *interp, \ - char *recordPtr, Tk_OptionTable optionTable, \ + Tcl_Obj * Tk_GetOptionInfo (Tcl_Interp *interp, + char *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin) } declare 205 generic { - Tcl_Obj * Tk_GetOptionValue (Tcl_Interp *interp, char *recordPtr, \ + Tcl_Obj * Tk_GetOptionValue (Tcl_Interp *interp, char *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin) } declare 206 generic { - int Tk_GetJustifyFromObj (Tcl_Interp *interp, \ + int Tk_GetJustifyFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr, Tk_Justify *justifyPtr) } declare 207 generic { - int Tk_GetMMFromObj (Tcl_Interp *interp, \ + int Tk_GetMMFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, double *doublePtr) } declare 208 generic { - int Tk_GetPixelsFromObj (Tcl_Interp *interp, \ + int Tk_GetPixelsFromObj (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, int *intPtr) } declare 209 generic { - int Tk_GetReliefFromObj (Tcl_Interp *interp, \ + int Tk_GetReliefFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr) } declare 210 generic { - int Tk_GetScrollInfoObj (Tcl_Interp *interp, \ + int Tk_GetScrollInfoObj (Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], double *dblPtr, int *intPtr) } declare 211 generic { - int Tk_InitOptions ( - Tcl_Interp *interp, char *recordPtr, \ - Tk_OptionTable optionToken, Tk_Window tkwin) + int Tk_InitOptions (Tcl_Interp *interp, char *recordPtr, + Tk_OptionTable optionToken, Tk_Window tkwin) } declare 212 generic { - void Tk_MainEx (int argc, char **argv, Tcl_AppInitProc *appInitProc, \ + void Tk_MainEx (int argc, char **argv, Tcl_AppInitProc *appInitProc, Tcl_Interp *interp) } @@ -1027,9 +1026,9 @@ declare 213 generic { } declare 214 generic { - int Tk_SetOptions (Tcl_Interp *interp, char *recordPtr, \ - Tk_OptionTable optionTable, int objc, \ - Tcl_Obj *CONST objv[], Tk_Window tkwin, \ + int Tk_SetOptions (Tcl_Interp *interp, char *recordPtr, + Tk_OptionTable optionTable, int objc, + Tcl_Obj *CONST objv[], Tk_Window tkwin, Tk_SavedOptions *savePtr, int *maskPtr) } @@ -1063,67 +1062,67 @@ declare 222 generic { void Tk_DeleteOutline (Display *display, Tk_Outline *outline) } declare 223 generic { - int Tk_ConfigOutlineGC (XGCValues *gcValues, Tk_Canvas canvas, \ + int Tk_ConfigOutlineGC (XGCValues *gcValues, Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline) } declare 224 generic { - int Tk_ChangeOutlineGC (Tk_Canvas canvas, Tk_Item *item, \ + int Tk_ChangeOutlineGC (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline) } declare 225 generic { - int Tk_ResetOutlineGC (Tk_Canvas canvas, Tk_Item *item, \ + int Tk_ResetOutlineGC (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline) } declare 226 generic { - int Tk_CanvasPsOutline (Tk_Canvas canvas, Tk_Item *item, \ + int Tk_CanvasPsOutline (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline) } declare 227 generic { void Tk_SetTSOrigin (Tk_Window tkwin, GC gc, int x, int y) } declare 228 generic { - int Tk_CanvasGetCoordFromObj (Tcl_Interp *interp, Tk_Canvas canvas, \ + int Tk_CanvasGetCoordFromObj (Tcl_Interp *interp, Tk_Canvas canvas, Tcl_Obj *obj, double *doublePtr) } declare 229 generic { void Tk_CanvasSetOffset (Tk_Canvas canvas, GC gc, Tk_TSOffset *offset) } declare 230 generic { - void Tk_DitherPhoto (Tk_PhotoHandle handle, int x, int y, int width, \ + void Tk_DitherPhoto (Tk_PhotoHandle handle, int x, int y, int width, int height) } declare 231 generic { - int Tk_PostscriptBitmap (Tcl_Interp *interp, Tk_Window tkwin, \ - Tk_PostscriptInfo psInfo, Pixmap bitmap, int startX, \ + int Tk_PostscriptBitmap (Tcl_Interp *interp, Tk_Window tkwin, + Tk_PostscriptInfo psInfo, Pixmap bitmap, int startX, int startY, int width, int height) } declare 232 generic { - int Tk_PostscriptColor (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, \ + int Tk_PostscriptColor (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, XColor *colorPtr) } declare 233 generic { - int Tk_PostscriptFont (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, \ + int Tk_PostscriptFont (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, Tk_Font font) } declare 234 generic { - int Tk_PostscriptImage (Tk_Image image, Tcl_Interp *interp, \ - Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y, \ + int Tk_PostscriptImage (Tk_Image image, Tcl_Interp *interp, + Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y, int width, int height, int prepass) } declare 235 generic { - void Tk_PostscriptPath (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, \ + void Tk_PostscriptPath (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, double *coordPtr, int numPoints) } declare 236 generic { - int Tk_PostscriptStipple (Tcl_Interp *interp, Tk_Window tkwin, \ + int Tk_PostscriptStipple (Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psInfo, Pixmap bitmap) } declare 237 generic { double Tk_PostscriptY (double y, Tk_PostscriptInfo psInfo) } declare 238 generic { - int Tk_PostscriptPhoto (Tcl_Interp *interp, \ - Tk_PhotoImageBlock *blockPtr, Tk_PostscriptInfo psInfo, \ + int Tk_PostscriptPhoto (Tcl_Interp *interp, + Tk_PhotoImageBlock *blockPtr, Tk_PostscriptInfo psInfo, int width, int height) } @@ -1139,23 +1138,23 @@ declare 240 generic { # New in 8.4a2 # declare 241 generic { - Tk_Window Tk_CreateAnonymousWindow (Tcl_Interp *interp, \ + Tk_Window Tk_CreateAnonymousWindow (Tcl_Interp *interp, Tk_Window parent, char *screenName) } declare 242 generic { - void Tk_SetClassProcs (Tk_Window tkwin, \ + void Tk_SetClassProcs (Tk_Window tkwin, Tk_ClassProcs *procs, ClientData instanceData) } # New in 8.4a4 # declare 243 generic { - void Tk_SetInternalBorderEx (Tk_Window tkwin, int left, int right, \ - int top, int bottom) + void Tk_SetInternalBorderEx (Tk_Window tkwin, int left, int right, + int top, int bottom) } declare 244 generic { - void Tk_SetMinimumRequestSize (Tk_Window tkwin, \ - int minWidth, int minHeight) + void Tk_SetMinimumRequestSize (Tk_Window tkwin, + int minWidth, int minHeight) } # New in 8.4a5 @@ -1180,6 +1179,68 @@ declare 248 generic { int Tk_CollapseMotionEvents (Display *display, int collapse) } +# Style engine +declare 249 generic { + Tk_StyleEngine Tk_RegisterStyleEngine (char *name, Tk_StyleEngine parent) +} +declare 250 generic { + Tk_StyleEngine Tk_GetStyleEngine (char *name) +} +declare 251 generic { + int Tk_RegisterStyledElement (Tk_StyleEngine engine, + Tk_ElementSpec *templatePtr) +} +declare 252 generic { + int Tk_GetElementId (char *name) +} +declare 253 generic { + Tk_Style Tk_CreateStyle (CONST char *name, Tk_StyleEngine engine, + ClientData clientData) +} +declare 254 generic { + Tk_Style Tk_GetStyle (Tcl_Interp *interp, CONST char *name) +} +declare 255 generic { + void Tk_FreeStyle (Tk_Style style) +} +declare 256 generic { + CONST char * Tk_NameOfStyle (Tk_Style style) +} +declare 257 generic { + Tk_Style Tk_AllocStyleFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr) +} +declare 258 generic { + Tk_Style Tk_GetStyleFromObj (Tcl_Obj *objPtr) +} +declare 259 generic { + void Tk_FreeStyleFromObj (Tcl_Obj *objPtr) +} +declare 260 generic { + Tk_StyledElement Tk_GetStyledElement (Tk_Style style, int elementId, + Tk_OptionTable optionTable) +} +declare 261 generic { + void Tk_GetElementSize (Tk_Style style, Tk_StyledElement element, + char *recordPtr, Tk_Window tkwin, int width, int height, + int inner, int *widthPtr, int *heightPtr) +} +declare 262 generic { + void Tk_GetElementBox (Tk_Style style, Tk_StyledElement element, + char *recordPtr, Tk_Window tkwin, int x, int y, int width, + int height, int inner, int *xPtr, int *yPtr, int *widthPtr, + int *heightPtr) +} +declare 263 generic { + int Tk_GetElementBorderWidth (Tk_Style style, Tk_StyledElement element, + char *recordPtr, Tk_Window tkwin) +} +declare 264 generic { + void Tk_DrawElement (Tk_Style style, Tk_StyledElement element, + char *recordPtr, Tk_Window tkwin, Drawable d, int x, int y, + int width, int height, int state) +} + + # Define the platform specific public Tk interface. These functions are # only available on the designated platform. @@ -1211,18 +1272,18 @@ declare 4 win { } declare 5 win { - int Tk_TranslateWinEvent (HWND hwnd, \ + int Tk_TranslateWinEvent (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result) } # Mac specific functions declare 0 mac { - void Tk_MacSetEmbedHandler ( \ - Tk_MacEmbedRegisterWinProc *registerWinProcPtr, \ - Tk_MacEmbedGetGrafPortProc *getPortProcPtr, \ - Tk_MacEmbedMakeContainerExistProc *containerExistProcPtr, \ - Tk_MacEmbedGetClipProc *getClipProc, \ + void Tk_MacSetEmbedHandler ( + Tk_MacEmbedRegisterWinProc *registerWinProcPtr, + Tk_MacEmbedGetGrafPortProc *getPortProcPtr, + Tk_MacEmbedMakeContainerExistProc *containerExistProcPtr, + Tk_MacEmbedGetClipProc *getClipProc, Tk_MacEmbedGetOffsetInParentProc *getOffsetProc) } @@ -1251,7 +1312,7 @@ declare 6 mac { } declare 7 mac { - void TkGenWMConfigureEvent (Tk_Window tkwin, \ + void TkGenWMConfigureEvent (Tk_Window tkwin, int x, int y, int width, int height, int flags) } diff --git a/generic/tk.h b/generic/tk.h index 666d978..6f7bbb9 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tk.h,v 1.62 2002/06/18 00:34:45 davygrvy Exp $ + * RCS: @(#) $Id: tk.h,v 1.63 2002/06/18 23:51:46 dkf Exp $ */ #ifndef _TK @@ -116,6 +116,9 @@ typedef struct Tk_PostscriptInfo_ *Tk_PostscriptInfo; typedef struct Tk_TextLayout_ *Tk_TextLayout; typedef struct Tk_Window_ *Tk_Window; typedef struct Tk_3DBorder_ *Tk_3DBorder; +typedef struct Tk_Style_ *Tk_Style; +typedef struct Tk_StyleEngine_ *Tk_StyleEngine; +typedef struct Tk_StyledElement_ *Tk_StyledElement; /* * Additional types exported to clients. @@ -146,7 +149,8 @@ typedef enum { TK_OPTION_PIXELS, TK_OPTION_WINDOW, TK_OPTION_END, - TK_OPTION_CUSTOM + TK_OPTION_CUSTOM, + TK_OPTION_STYLE } Tk_OptionType; /* @@ -1389,6 +1393,77 @@ EXTERN void Tk_CreateOldPhotoImageFormat _ANSI_ARGS_(( /* *-------------------------------------------------------------- * + * Procedure prototypes and structures used for managing styles: + * + *-------------------------------------------------------------- + */ + +/* + * Style support version tag. + */ +#define TK_STYLE_VERSION_1 0x1 +#define TK_STYLE_VERSION TK_STYLE_VERSION_1 + +/* + * The following structures and prototypes are used as static templates to + * declare widget elements. + */ + +typedef void (Tk_GetElementSizeProc) _ANSI_ARGS_((ClientData clientData, + char *recordPtr, CONST Tk_OptionSpec **optionsPtr, Tk_Window tkwin, + int width, int height, int inner, int *widthPtr, int *heightPtr)); +typedef void (Tk_GetElementBoxProc) _ANSI_ARGS_((ClientData clientData, + char *recordPtr, CONST Tk_OptionSpec **optionsPtr, Tk_Window tkwin, + int x, int y, int width, int height, int inner, int *xPtr, int *yPtr, + int *widthPtr, int *heightPtr)); +typedef int (Tk_GetElementBorderWidthProc) _ANSI_ARGS_((ClientData clientData, + char *recordPtr, CONST Tk_OptionSpec **optionsPtr, Tk_Window tkwin)); +typedef void (Tk_DrawElementProc) _ANSI_ARGS_((ClientData clientData, + char *recordPtr, CONST Tk_OptionSpec **optionsPtr, Tk_Window tkwin, + Drawable d, int x, int y, int width, int height, int state)); + +typedef struct Tk_ElementOptionSpec { + char *name; /* Name of the required option. */ + Tk_OptionType type; /* Accepted option type. TK_OPTION_END means + * any. */ +} Tk_ElementOptionSpec; + +typedef struct Tk_ElementSpec { + int version; /* Version of the style support. */ + char *name; /* Name of element. */ + Tk_ElementOptionSpec *options; + /* List of required options. Last one's name + * must be NULL. */ + + /* + * Hooks + */ + + Tk_GetElementSizeProc *getSize; + /* Compute the external (resp. internal) size of + * the element from its desired internal (resp. + * external) size. */ + Tk_GetElementBoxProc *getBox; + /* Compute the inscribed or bounding boxes + * within a given area. */ + Tk_GetElementBorderWidthProc *getBorderWidth; + /* Return the element's internal border width. + * Mostly useful for widgets. */ + Tk_DrawElementProc *draw; /* Draw the element in the given bounding box.*/ +} Tk_ElementSpec; + +/* + * Element state flags. Can be OR'ed. + */ + +#define TK_ELEMENT_STATE_ACTIVE 1<<0 +#define TK_ELEMENT_STATE_DISABLED 1<<1 +#define TK_ELEMENT_STATE_FOCUS 1<<2 +#define TK_ELEMENT_STATE_PRESSED 1<<3 + +/* + *-------------------------------------------------------------- + * * The definitions below provide backward compatibility for * functions and types related to event handling that used to * be in Tk but have moved to Tcl. diff --git a/generic/tkConfig.c b/generic/tkConfig.c index e82b2ed..6572e23 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkConfig.c,v 1.16 2002/01/17 05:13:11 dgp Exp $ + * RCS: @(#) $Id: tkConfig.c,v 1.17 2002/06/18 23:51:46 dkf Exp $ */ /* @@ -127,6 +127,8 @@ static Tcl_Obj * GetConfigList _ANSI_ARGS_((char *recordPtr, Option *optionPtr, Tk_Window tkwin)); static Tcl_Obj * GetObjectForOption _ANSI_ARGS_((char *recordPtr, Option *optionPtr, Tk_Window tkwin)); +static Option * GetOption _ANSI_ARGS_((CONST char *name, + OptionTable *tablePtr)); static Option * GetOptionFromObj _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *objPtr, OptionTable *tablePtr)); static int ObjectIsEmpty _ANSI_ARGS_((Tcl_Obj *objPtr)); @@ -789,6 +791,24 @@ DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin, savedOptionPtr) } break; } + case TK_OPTION_STYLE: { + Tk_Style new; + + if (nullOK && ObjectIsEmpty(valuePtr)) { + valuePtr = NULL; + new = NULL; + } else { + new = Tk_AllocStyleFromObj(interp, valuePtr); + if (new == NULL) { + return TCL_ERROR; + } + } + if (internalPtr != NULL) { + *((Tk_Style *) oldInternalPtr) = *((Tk_Style *) internalPtr); + *((Tk_Style *) internalPtr) = new; + } + break; + } case TK_OPTION_BITMAP: { Pixmap new; @@ -1004,53 +1024,38 @@ ObjectIsEmpty(objPtr) /* *---------------------------------------------------------------------- * - * GetOptionFromObj -- + * GetOption -- * * This procedure searches through a chained option table to find * the entry for a particular option name. * * Results: * The return value is a pointer to the matching entry, or NULL - * if no matching entry could be found. If NULL is returned and - * interp is not NULL than an error message is left in its result. + * if no matching entry could be found. * Note: if the matching entry is a synonym then this procedure * returns a pointer to the synonym entry, *not* the "real" entry * that the synonym refers to. * * Side effects: - * Information about the matching entry is cached in the object - * containing the name, so that future lookups can proceed more - * quickly. + * None. * *---------------------------------------------------------------------- */ static Option * -GetOptionFromObj(interp, objPtr, tablePtr) - Tcl_Interp *interp; /* Used only for error reporting; if NULL - * no message is left after an error. */ - Tcl_Obj *objPtr; /* Object whose string value is to be - * looked up in the option table. */ - OptionTable *tablePtr; /* Table in which to look up objPtr. */ +GetOption(name, tablePtr) + CONST char *name; /* String balue to be looked up in the + * option table. */ + OptionTable *tablePtr; /* Table in which to look up name. */ { Option *bestPtr, *optionPtr; OptionTable *tablePtr2; - char *p1, *p2, *name; + CONST char *p1, *p2; int count; /* - * First, check to see if the object already has the answer cached. - */ - - if (objPtr->typePtr == &tkOptionObjType) { - if (objPtr->internalRep.twoPtrValue.ptr1 == (VOID *) tablePtr) { - return (Option *) objPtr->internalRep.twoPtrValue.ptr2; - } - } - - /* - * The answer isn't cached. Search through all of the option tables - * in the chain to find the best match. Some tricky aspects: + * Search through all of the option tables in the chain to find the + * best match. Some tricky aspects: * * 1. We have to accept unique abbreviations. * 2. The same name could appear in different tables in the chain. @@ -1060,7 +1065,6 @@ GetOptionFromObj(interp, objPtr, tablePtr) */ bestPtr = NULL; - name = Tcl_GetStringFromObj(objPtr, (int *) NULL); for (tablePtr2 = tablePtr; tablePtr2 != NULL; tablePtr2 = tablePtr2->nextPtr) { for (optionPtr = tablePtr2->options, count = tablePtr2->numOptions; @@ -1097,11 +1101,69 @@ GetOptionFromObj(interp, objPtr, tablePtr) } } } + + done: + return bestPtr; + + error: + return NULL; +} + +/* + *---------------------------------------------------------------------- + * + * GetOptionFromObj -- + * + * This procedure searches through a chained option table to find + * the entry for a particular option name. + * + * Results: + * The return value is a pointer to the matching entry, or NULL + * if no matching entry could be found. If NULL is returned and + * interp is not NULL than an error message is left in its result. + * Note: if the matching entry is a synonym then this procedure + * returns a pointer to the synonym entry, *not* the "real" entry + * that the synonym refers to. + * + * Side effects: + * Information about the matching entry is cached in the object + * containing the name, so that future lookups can proceed more + * quickly. + * + *---------------------------------------------------------------------- + */ + +static Option * +GetOptionFromObj(interp, objPtr, tablePtr) + Tcl_Interp *interp; /* Used only for error reporting; if NULL + * no message is left after an error. */ + Tcl_Obj *objPtr; /* Object whose string value is to be + * looked up in the option table. */ + OptionTable *tablePtr; /* Table in which to look up objPtr. */ +{ + Option *bestPtr; + char *name; + + /* + * First, check to see if the object already has the answer cached. + */ + + if (objPtr->typePtr == &tkOptionObjType) { + if (objPtr->internalRep.twoPtrValue.ptr1 == (VOID *) tablePtr) { + return (Option *) objPtr->internalRep.twoPtrValue.ptr2; + } + } + + /* + * The answer isn't cached. + */ + + name = Tcl_GetStringFromObj(objPtr, (int *) NULL); + bestPtr = GetOption(name, tablePtr); if (bestPtr == NULL) { goto error; } - done: if ((objPtr->typePtr != NULL) && (objPtr->typePtr->freeIntRepProc != NULL)) { objPtr->typePtr->freeIntRepProc(objPtr); @@ -1122,6 +1184,44 @@ GetOptionFromObj(interp, objPtr, tablePtr) /* *---------------------------------------------------------------------- * + * TkGetOptionSpec -- + * + * This procedure searches through a chained option table to find + * the option spec for a particular option name. + * + * Results: + * The return value is a pointer to the option spec of the matching + * entry, or NULL if no matching entry could be found. + * Note: if the matching entry is a synonym then this procedure + * returns a pointer to the option spec of the synonym entry, *not* + * the "real" entry that the synonym refers to. + * Note: this call is primarily used by the style management code + * (tkStyle.c) to look up an element's option spec into a widget's + * option table. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +CONST Tk_OptionSpec * +TkGetOptionSpec(name, optionTable) + CONST char *name; /* String value to be looked up. */ + Tk_OptionTable optionTable; /* Table in which to look up name. */ +{ + Option *optionPtr; + + optionPtr = GetOption(name, (OptionTable *) optionTable); + if (optionPtr == NULL) { + return NULL; + } + return optionPtr->specPtr; +} + +/* + *---------------------------------------------------------------------- + * * SetOptionFromAny -- * * This procedure is called to convert a Tcl object to option @@ -1397,6 +1497,11 @@ Tk_RestoreSavedOptions(savePtr) = *((Tk_Font *) &savePtr->items[i].internalForm); break; } + case TK_OPTION_STYLE: { + *((Tk_Style *) internalPtr) + = *((Tk_Style *) &savePtr->items[i].internalForm); + break; + } case TK_OPTION_BITMAP: { *((Pixmap *) internalPtr) = *((Pixmap *) &savePtr->items[i].internalForm); @@ -1627,6 +1732,14 @@ FreeResources(optionPtr, objPtr, internalPtr, tkwin) Tk_FreeFontFromObj(tkwin, objPtr); } break; + case TK_OPTION_STYLE: + if (internalFormExists) { + Tk_FreeStyle(*((Tk_Style *) internalPtr)); + *((Tk_Style *) internalPtr) = NULL; + } else if (objPtr != NULL) { + Tk_FreeStyleFromObj(objPtr); + } + break; case TK_OPTION_BITMAP: if (internalFormExists) { if (*((Pixmap *) internalPtr) != None) { @@ -1900,6 +2013,13 @@ GetObjectForOption(recordPtr, optionPtr, tkwin) } break; } + case TK_OPTION_STYLE: { + Tk_Style style = *((Tk_Style *) internalPtr); + if (style != NULL) { + objPtr = Tcl_NewStringObj(Tk_NameOfStyle(style), -1); + } + break; + } case TK_OPTION_BITMAP: { Pixmap pixmap = *((Pixmap *) internalPtr); if (pixmap != None) { diff --git a/generic/tkDecls.h b/generic/tkDecls.h index 8c7daa4..c0d55bc 100644 --- a/generic/tkDecls.h +++ b/generic/tkDecls.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkDecls.h,v 1.21 2002/06/15 00:21:41 hobbs Exp $ + * RCS: @(#) $Id: tkDecls.h,v 1.22 2002/06/18 23:51:46 dkf Exp $ */ #ifndef _TKDECLS @@ -860,6 +860,57 @@ EXTERN void Tk_PhotoPutZoomedBlock _ANSI_ARGS_(( /* 248 */ EXTERN int Tk_CollapseMotionEvents _ANSI_ARGS_(( Display * display, int collapse)); +/* 249 */ +EXTERN Tk_StyleEngine Tk_RegisterStyleEngine _ANSI_ARGS_((char * name, + Tk_StyleEngine parent)); +/* 250 */ +EXTERN Tk_StyleEngine Tk_GetStyleEngine _ANSI_ARGS_((char * name)); +/* 251 */ +EXTERN int Tk_RegisterStyledElement _ANSI_ARGS_(( + Tk_StyleEngine engine, + Tk_ElementSpec * templatePtr)); +/* 252 */ +EXTERN int Tk_GetElementId _ANSI_ARGS_((char * name)); +/* 253 */ +EXTERN Tk_Style Tk_CreateStyle _ANSI_ARGS_((CONST char * name, + Tk_StyleEngine engine, ClientData clientData)); +/* 254 */ +EXTERN Tk_Style Tk_GetStyle _ANSI_ARGS_((Tcl_Interp * interp, + CONST char * name)); +/* 255 */ +EXTERN void Tk_FreeStyle _ANSI_ARGS_((Tk_Style style)); +/* 256 */ +EXTERN CONST char * Tk_NameOfStyle _ANSI_ARGS_((Tk_Style style)); +/* 257 */ +EXTERN Tk_Style Tk_AllocStyleFromObj _ANSI_ARGS_(( + Tcl_Interp * interp, Tcl_Obj * objPtr)); +/* 258 */ +EXTERN Tk_Style Tk_GetStyleFromObj _ANSI_ARGS_((Tcl_Obj * objPtr)); +/* 259 */ +EXTERN void Tk_FreeStyleFromObj _ANSI_ARGS_((Tcl_Obj * objPtr)); +/* 260 */ +EXTERN Tk_StyledElement Tk_GetStyledElement _ANSI_ARGS_((Tk_Style style, + int elementId, Tk_OptionTable optionTable)); +/* 261 */ +EXTERN void Tk_GetElementSize _ANSI_ARGS_((Tk_Style style, + Tk_StyledElement element, char * recordPtr, + Tk_Window tkwin, int width, int height, + int inner, int * widthPtr, int * heightPtr)); +/* 262 */ +EXTERN void Tk_GetElementBox _ANSI_ARGS_((Tk_Style style, + Tk_StyledElement element, char * recordPtr, + Tk_Window tkwin, int x, int y, int width, + int height, int inner, int * xPtr, + int * yPtr, int * widthPtr, int * heightPtr)); +/* 263 */ +EXTERN int Tk_GetElementBorderWidth _ANSI_ARGS_((Tk_Style style, + Tk_StyledElement element, char * recordPtr, + Tk_Window tkwin)); +/* 264 */ +EXTERN void Tk_DrawElement _ANSI_ARGS_((Tk_Style style, + Tk_StyledElement element, char * recordPtr, + Tk_Window tkwin, Drawable d, int x, int y, + int width, int height, int state)); typedef struct TkStubHooks { struct TkPlatStubs *tkPlatStubs; @@ -1121,6 +1172,22 @@ typedef struct TkStubs { void (*tk_PhotoPutBlock) _ANSI_ARGS_((Tk_PhotoHandle handle, Tk_PhotoImageBlock * blockPtr, int x, int y, int width, int height, int compRule)); /* 246 */ void (*tk_PhotoPutZoomedBlock) _ANSI_ARGS_((Tk_PhotoHandle handle, Tk_PhotoImageBlock * blockPtr, int x, int y, int width, int height, int zoomX, int zoomY, int subsampleX, int subsampleY, int compRule)); /* 247 */ int (*tk_CollapseMotionEvents) _ANSI_ARGS_((Display * display, int collapse)); /* 248 */ + Tk_StyleEngine (*tk_RegisterStyleEngine) _ANSI_ARGS_((char * name, Tk_StyleEngine parent)); /* 249 */ + Tk_StyleEngine (*tk_GetStyleEngine) _ANSI_ARGS_((char * name)); /* 250 */ + int (*tk_RegisterStyledElement) _ANSI_ARGS_((Tk_StyleEngine engine, Tk_ElementSpec * templatePtr)); /* 251 */ + int (*tk_GetElementId) _ANSI_ARGS_((char * name)); /* 252 */ + Tk_Style (*tk_CreateStyle) _ANSI_ARGS_((CONST char * name, Tk_StyleEngine engine, ClientData clientData)); /* 253 */ + Tk_Style (*tk_GetStyle) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * name)); /* 254 */ + void (*tk_FreeStyle) _ANSI_ARGS_((Tk_Style style)); /* 255 */ + CONST char * (*tk_NameOfStyle) _ANSI_ARGS_((Tk_Style style)); /* 256 */ + Tk_Style (*tk_AllocStyleFromObj) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Obj * objPtr)); /* 257 */ + Tk_Style (*tk_GetStyleFromObj) _ANSI_ARGS_((Tcl_Obj * objPtr)); /* 258 */ + void (*tk_FreeStyleFromObj) _ANSI_ARGS_((Tcl_Obj * objPtr)); /* 259 */ + Tk_StyledElement (*tk_GetStyledElement) _ANSI_ARGS_((Tk_Style style, int elementId, Tk_OptionTable optionTable)); /* 260 */ + void (*tk_GetElementSize) _ANSI_ARGS_((Tk_Style style, Tk_StyledElement element, char * recordPtr, Tk_Window tkwin, int width, int height, int inner, int * widthPtr, int * heightPtr)); /* 261 */ + void (*tk_GetElementBox) _ANSI_ARGS_((Tk_Style style, Tk_StyledElement element, char * recordPtr, Tk_Window tkwin, int x, int y, int width, int height, int inner, int * xPtr, int * yPtr, int * widthPtr, int * heightPtr)); /* 262 */ + int (*tk_GetElementBorderWidth) _ANSI_ARGS_((Tk_Style style, Tk_StyledElement element, char * recordPtr, Tk_Window tkwin)); /* 263 */ + void (*tk_DrawElement) _ANSI_ARGS_((Tk_Style style, Tk_StyledElement element, char * recordPtr, Tk_Window tkwin, Drawable d, int x, int y, int width, int height, int state)); /* 264 */ } TkStubs; #ifdef __cplusplus @@ -2127,6 +2194,70 @@ extern TkStubs *tkStubsPtr; #define Tk_CollapseMotionEvents \ (tkStubsPtr->tk_CollapseMotionEvents) /* 248 */ #endif +#ifndef Tk_RegisterStyleEngine +#define Tk_RegisterStyleEngine \ + (tkStubsPtr->tk_RegisterStyleEngine) /* 249 */ +#endif +#ifndef Tk_GetStyleEngine +#define Tk_GetStyleEngine \ + (tkStubsPtr->tk_GetStyleEngine) /* 250 */ +#endif +#ifndef Tk_RegisterStyledElement +#define Tk_RegisterStyledElement \ + (tkStubsPtr->tk_RegisterStyledElement) /* 251 */ +#endif +#ifndef Tk_GetElementId +#define Tk_GetElementId \ + (tkStubsPtr->tk_GetElementId) /* 252 */ +#endif +#ifndef Tk_CreateStyle +#define Tk_CreateStyle \ + (tkStubsPtr->tk_CreateStyle) /* 253 */ +#endif +#ifndef Tk_GetStyle +#define Tk_GetStyle \ + (tkStubsPtr->tk_GetStyle) /* 254 */ +#endif +#ifndef Tk_FreeStyle +#define Tk_FreeStyle \ + (tkStubsPtr->tk_FreeStyle) /* 255 */ +#endif +#ifndef Tk_NameOfStyle +#define Tk_NameOfStyle \ + (tkStubsPtr->tk_NameOfStyle) /* 256 */ +#endif +#ifndef Tk_AllocStyleFromObj +#define Tk_AllocStyleFromObj \ + (tkStubsPtr->tk_AllocStyleFromObj) /* 257 */ +#endif +#ifndef Tk_GetStyleFromObj +#define Tk_GetStyleFromObj \ + (tkStubsPtr->tk_GetStyleFromObj) /* 258 */ +#endif +#ifndef Tk_FreeStyleFromObj +#define Tk_FreeStyleFromObj \ + (tkStubsPtr->tk_FreeStyleFromObj) /* 259 */ +#endif +#ifndef Tk_GetStyledElement +#define Tk_GetStyledElement \ + (tkStubsPtr->tk_GetStyledElement) /* 260 */ +#endif +#ifndef Tk_GetElementSize +#define Tk_GetElementSize \ + (tkStubsPtr->tk_GetElementSize) /* 261 */ +#endif +#ifndef Tk_GetElementBox +#define Tk_GetElementBox \ + (tkStubsPtr->tk_GetElementBox) /* 262 */ +#endif +#ifndef Tk_GetElementBorderWidth +#define Tk_GetElementBorderWidth \ + (tkStubsPtr->tk_GetElementBorderWidth) /* 263 */ +#endif +#ifndef Tk_DrawElement +#define Tk_DrawElement \ + (tkStubsPtr->tk_DrawElement) /* 264 */ +#endif #endif /* defined(USE_TK_STUBS) && !defined(USE_TK_STUB_PROCS) */ diff --git a/generic/tkInt.decls b/generic/tkInt.decls index d0e2fd7..992b5b1 100644 --- a/generic/tkInt.decls +++ b/generic/tkInt.decls @@ -9,7 +9,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tkInt.decls,v 1.27 2002/06/14 13:35:48 dkf Exp $ +# RCS: @(#) $Id: tkInt.decls,v 1.28 2002/06/18 23:51:46 dkf Exp $ library tk @@ -661,6 +661,13 @@ declare 145 {mac win} { void TkSubtractRegion (TkRegion sra, TkRegion srcb, TkRegion dr_return) } +declare 146 generic { + void TkStylePkgInit (TkMainInfo *mainPtr) +} +declare 147 generic { + void TkStylePkgFree (TkMainInfo *mainPtr) +} + ############################################################################## # Define the platform specific internal Tcl interface. These functions are diff --git a/generic/tkInt.h b/generic/tkInt.h index f6576d8..a6e887a 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: $Id: tkInt.h,v 1.50 2002/06/17 20:09:01 hobbs Exp $ + * RCS: $Id: tkInt.h,v 1.51 2002/06/18 23:51:46 dkf Exp $ */ #ifndef _TKINT @@ -1110,6 +1110,9 @@ EXTERN char * TkCanvasDashPrintProc _ANSI_ARGS_(( EXTERN int TkGetDoublePixels _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin, CONST char *string, double *doublePtr)); +EXTERN CONST Tk_OptionSpec * + TkGetOptionSpec _ANSI_ARGS_((CONST char *name, + Tk_OptionTable optionTable)); EXTERN int TkOffsetParseProc _ANSI_ARGS_(( ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, CONST char *value, char *widgRec, diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h index 4fcdf63..7a3a325 100644 --- a/generic/tkIntDecls.h +++ b/generic/tkIntDecls.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkIntDecls.h,v 1.18 2002/06/14 13:35:49 dkf Exp $ + * RCS: @(#) $Id: tkIntDecls.h,v 1.19 2002/06/18 23:51:46 dkf Exp $ */ #ifndef _TKINTDECLS @@ -499,6 +499,10 @@ EXTERN void TkSubtractRegion _ANSI_ARGS_((TkRegion sra, EXTERN void TkSubtractRegion _ANSI_ARGS_((TkRegion sra, TkRegion srcb, TkRegion dr_return)); #endif /* MAC_TCL */ +/* 146 */ +EXTERN void TkStylePkgInit _ANSI_ARGS_((TkMainInfo * mainPtr)); +/* 147 */ +EXTERN void TkStylePkgFree _ANSI_ARGS_((TkMainInfo * mainPtr)); typedef struct TkIntStubs { int magic; @@ -738,6 +742,8 @@ typedef struct TkIntStubs { #ifdef MAC_TCL void (*tkSubtractRegion) _ANSI_ARGS_((TkRegion sra, TkRegion srcb, TkRegion dr_return)); /* 145 */ #endif /* MAC_TCL */ + void (*tkStylePkgInit) _ANSI_ARGS_((TkMainInfo * mainPtr)); /* 146 */ + void (*tkStylePkgFree) _ANSI_ARGS_((TkMainInfo * mainPtr)); /* 147 */ } TkIntStubs; #ifdef __cplusplus @@ -1369,6 +1375,14 @@ extern TkIntStubs *tkIntStubsPtr; (tkIntStubsPtr->tkSubtractRegion) /* 145 */ #endif #endif /* MAC_TCL */ +#ifndef TkStylePkgInit +#define TkStylePkgInit \ + (tkIntStubsPtr->tkStylePkgInit) /* 146 */ +#endif +#ifndef TkStylePkgFree +#define TkStylePkgFree \ + (tkIntStubsPtr->tkStylePkgFree) /* 147 */ +#endif #endif /* defined(USE_TK_STUBS) && !defined(USE_TK_STUB_PROCS) */ diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index 43a081f..e92d4f5 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkStubInit.c,v 1.36 2002/06/15 00:21:42 hobbs Exp $ + * RCS: @(#) $Id: tkStubInit.c,v 1.37 2002/06/18 23:51:46 dkf Exp $ */ #include "tkInt.h" @@ -281,6 +281,8 @@ TkIntStubs tkIntStubs = { #ifdef MAC_TCL TkSubtractRegion, /* 145 */ #endif /* MAC_TCL */ + TkStylePkgInit, /* 146 */ + TkStylePkgFree, /* 147 */ }; TkIntPlatStubs tkIntPlatStubs = { @@ -899,6 +901,22 @@ TkStubs tkStubs = { Tk_PhotoPutBlock, /* 246 */ Tk_PhotoPutZoomedBlock, /* 247 */ Tk_CollapseMotionEvents, /* 248 */ + Tk_RegisterStyleEngine, /* 249 */ + Tk_GetStyleEngine, /* 250 */ + Tk_RegisterStyledElement, /* 251 */ + Tk_GetElementId, /* 252 */ + Tk_CreateStyle, /* 253 */ + Tk_GetStyle, /* 254 */ + Tk_FreeStyle, /* 255 */ + Tk_NameOfStyle, /* 256 */ + Tk_AllocStyleFromObj, /* 257 */ + Tk_GetStyleFromObj, /* 258 */ + Tk_FreeStyleFromObj, /* 259 */ + Tk_GetStyledElement, /* 260 */ + Tk_GetElementSize, /* 261 */ + Tk_GetElementBox, /* 262 */ + Tk_GetElementBorderWidth, /* 263 */ + Tk_DrawElement, /* 264 */ }; /* !END!: Do not edit above this line. */ diff --git a/generic/tkStyle.c b/generic/tkStyle.c new file mode 100644 index 0000000..bb48e21 --- /dev/null +++ b/generic/tkStyle.c @@ -0,0 +1,1663 @@ +/* + * tkStyle.c -- + * + * This file implements the widget styles and themes support. + * + * Copyright (c) 1990-1993 The Regents of the University of California. + * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: tkStyle.c,v 1.1 2002/06/18 23:51:46 dkf Exp $ + */ + +#include "tkInt.h" + +/* + * The following structure is used to cache widget option specs matching an + * element's required options defined by Tk_ElementOptionSpecs. It also holds + * information behind Tk_StyledElement opaque tokens. + */ + +typedef struct StyledWidgetSpec { + struct StyledElement *elementPtr; /* Pointer to the element holding this + * structure. */ + Tk_OptionTable optionTable; /* Option table for the widget class + * using the element. */ + CONST Tk_OptionSpec **optionsPtr; /* Table of option spec pointers, + * matching the option list provided + * during element registration. + * Malloc'd. */ +} StyledWidgetSpec; + +/* + * Elements are declared using static templates. But static + * information must be completed by dynamic information only + * accessible at runtime. For each registered element, an instance of + * the following structure is stored in each style engine and used to + * cache information about the widget types (identified by their + * optionTable) that use the given element. + */ + +typedef struct StyledElement { + struct Tk_ElementSpec *specPtr; + /* Filled with template provided during + * registration. NULL means no implementation + * is available for the current engine. */ + int nbWidgetSpecs; /* Size of the array below. Number of distinct + * widget classes (actually, distinct option + * tables) that used the element so far. */ + StyledWidgetSpec *widgetSpecs; + /* See above for the structure definition. + * Table grows dynamically as new widgets + * use the element. Malloc'd. */ +} StyledElement; + +/* + * The following structure holds information behind Tk_StyleEngine opaque + * tokens. + */ + +typedef struct StyleEngine { + CONST char *name; /* Name of engine. Points to a hash key. */ + StyledElement *elements; /* Table of widget element descriptors. Each + * element is indexed by a unique system-wide + * ID. Table grows dynamically as new elements + * are registered. Malloc'd*/ + struct StyleEngine *parentPtr; + /* Parent engine. Engines may be layered to form + * a fallback chain, terminated by the default + * system engine. */ +} StyleEngine; + +/* + * Styles are instances of style engines. The following structure holds + * information behind Tk_Style opaque tokens. + */ + +typedef struct Style { + int refCount; /* Number of active uses of this style. + * If this count is 0, then this Style + * structure is no longer valid. */ + Tcl_HashEntry *hashPtr; /* Entry in style table for this structure, + * used when deleting it. */ + CONST char *name; /* Name of style. Points to a hash key. */ + StyleEngine *enginePtr; /* Style engine of which the style is an + * instance. */ + ClientData clientData; /* Data provided during registration. */ +} Style; + +/* + * Each registered element uses an instance of the following structure. + */ + +typedef struct Element { + CONST char *name; /* Name of element. Points to a hash key. */ + int id; /* Id of element. */ + int genericId; /* Id of generic element. */ + int created; /* Boolean, whether the element was created + * explicitly (was registered) or implicitly + * (by a derived element). */ +} Element; + +/* + * Thread-local data. + */ + +typedef struct ThreadSpecificData { + int nbInit; /* Number of calls to the init proc. */ + Tcl_HashTable engineTable; /* Map a name to a style engine. Keys are + * strings, values are Tk_StyleEngine + * pointers. */ + StyleEngine *defaultEnginePtr; + /* Default, core-defined style engine. Global + * fallback for all engines. */ + Tcl_HashTable styleTable; /* Map a name to a style. Keys are strings, + * values are Tk_Style pointers.*/ + int nbElements; /* Size of the below tables. */ + Tcl_HashTable elementTable; /* Map a name to an element Id. Keys are + * strings, values are integer element IDs. */ + Element *elements; /* Array of Elements. */ +} ThreadSpecificData; + +static Tcl_ThreadDataKey dataKey; + +/* + * Forward declarations for procedures defined later in this file: + */ + +/* TODO: sort alpha. */ +static int CreateElement _ANSI_ARGS_((char *name, int create)); +static void DupStyleObjProc _ANSI_ARGS_((Tcl_Obj *srcObjPtr, + Tcl_Obj *dupObjPtr)); +static void FreeElement _ANSI_ARGS_((Element *elementPtr)); +static void FreeStyle _ANSI_ARGS_((Style *stylePtr)); +static void FreeStyledElement _ANSI_ARGS_(( + StyledElement *elementPtr)); +static void FreeStyleEngine _ANSI_ARGS_(( + StyleEngine *enginePtr)); +static void FreeStyleObjProc _ANSI_ARGS_((Tcl_Obj *objPtr)); +static void FreeWidgetSpec _ANSI_ARGS_(( + StyledWidgetSpec *widgetSpecPtr)); +static StyledElement * GetStyledElement _ANSI_ARGS_(( + StyleEngine *enginePtr, int elementId)); +static StyledWidgetSpec * GetWidgetSpec _ANSI_ARGS_((StyledElement *elementPtr, + Tk_OptionTable optionTable)); +static void InitElement _ANSI_ARGS_((Element *elementPtr, + CONST char *name, int id, int genericId, + int created)); +static void InitStyle _ANSI_ARGS_((Style *stylePtr, + Tcl_HashEntry *hashPtr, CONST char *name, + StyleEngine *enginePtr, ClientData clientData)); +static void InitStyledElement _ANSI_ARGS_(( + StyledElement *elementPtr)); +static void InitStyleEngine _ANSI_ARGS_((StyleEngine *enginePtr, + CONST char *name, StyleEngine *parentPtr)); +static void InitWidgetSpec _ANSI_ARGS_(( + StyledWidgetSpec *widgetSpecPtr, + StyledElement *elementPtr, + Tk_OptionTable optionTable)); +static int SetStyleFromAny _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *objPtr)); + +/* + * The following structure defines the implementation of the "style" Tcl + * object, used for drawing. The internalRep.otherValuePtr field of + * each style object points to the Style structure for the stylefont, or + * NULL. + */ + +static Tcl_ObjType styleObjType = { + "style", /* name */ + FreeStyleObjProc, /* freeIntRepProc */ + DupStyleObjProc, /* dupIntRepProc */ + NULL, /* updateStringProc */ + SetStyleFromAny /* setFromAnyProc */ +}; + +/* + *--------------------------------------------------------------------------- + * + * TkStylePkgInit -- + * + * This procedure is called when an application is created. It + * initializes all the structures that are used by the style + * package on a per application basis. + * + * Results: + * Stores data in thread-local storage. + * + * Side effects: + * Memory allocated. + * + *--------------------------------------------------------------------------- + */ + +void +TkStylePkgInit(mainPtr) + TkMainInfo *mainPtr; /* The application being created. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + + if (tsdPtr->nbInit != 0) return; + + /* + * Initialize tables. + */ + + Tcl_InitHashTable(&tsdPtr->engineTable, TCL_STRING_KEYS); + Tcl_InitHashTable(&tsdPtr->styleTable, TCL_STRING_KEYS); + Tcl_InitHashTable(&tsdPtr->elementTable, TCL_STRING_KEYS); + tsdPtr->nbElements = 0; + tsdPtr->elements = NULL; + + /* + * Create the default system engine. + */ + + tsdPtr->defaultEnginePtr = + (StyleEngine *) Tk_RegisterStyleEngine(NULL, NULL); + + /* + * Create the default system style. + */ + + Tk_CreateStyle(NULL, (Tk_StyleEngine) tsdPtr->defaultEnginePtr, + (ClientData) 0); + + tsdPtr->nbInit++; +} + +/* + *--------------------------------------------------------------------------- + * + * TkStylePkgFree -- + * + * This procedure is called when an application is deleted. It + * deletes all the structures that were used by the style package + * for this application. + * + * Results: + * None. + * + * Side effects: + * Memory freed. + * + *--------------------------------------------------------------------------- + */ + +void +TkStylePkgFree(mainPtr) + TkMainInfo *mainPtr; /* The application being deleted. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashSearch search; + Tcl_HashEntry *entryPtr; + StyleEngine *enginePtr; + int i; + + tsdPtr->nbInit--; + if (tsdPtr->nbInit != 0) return; + + /* + * Free styles. + */ + + entryPtr = Tcl_FirstHashEntry(&tsdPtr->styleTable, &search); + while (entryPtr != NULL) { + ckfree((char *) Tcl_GetHashValue(entryPtr)); + entryPtr = Tcl_NextHashEntry(&search); + } + Tcl_DeleteHashTable(&tsdPtr->styleTable); + + /* + * Free engines. + */ + + entryPtr = Tcl_FirstHashEntry(&tsdPtr->engineTable, &search); + while (entryPtr != NULL) { + enginePtr = (StyleEngine *) Tcl_GetHashValue(entryPtr); + FreeStyleEngine(enginePtr); + ckfree((char *) enginePtr); + entryPtr = Tcl_NextHashEntry(&search); + } + Tcl_DeleteHashTable(&tsdPtr->engineTable); + + /* + * Free elements. + */ + + for (i = 0; i < tsdPtr->nbElements; i++) { + FreeElement(tsdPtr->elements+i); + } + Tcl_DeleteHashTable(&tsdPtr->elementTable); + ckfree((char *) tsdPtr->elements); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_RegisterStyleEngine -- + * + * This procedure is called to register a new style engine. Style engines + * are stored in thread-local space. + * + * Results: + * The newly allocated engine. + * + * Side effects: + * Memory allocated. Data added to thread-local table. + * + *--------------------------------------------------------------------------- + */ + +Tk_StyleEngine +Tk_RegisterStyleEngine(name, parent) + char *name; /* Name of the engine to create. NULL or empty + * means the default system engine. */ + Tk_StyleEngine parent; /* The engine's parent. NULL means the default + * system engine. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr; + int newEntry; + StyleEngine *enginePtr; + + /* + * Attempt to create a new entry in the engine table. + */ + + entryPtr = Tcl_CreateHashEntry(&tsdPtr->engineTable, (name?name:""), + &newEntry); + if (!newEntry) { + /* + * An engine was already registered by that name. + */ + + return NULL; + } + + /* + * Allocate and intitialize a new engine. + */ + + enginePtr = (StyleEngine *) ckalloc(sizeof(StyleEngine)); + InitStyleEngine(enginePtr, Tcl_GetHashKey(&tsdPtr->engineTable, entryPtr), + (StyleEngine *) parent); + Tcl_SetHashValue(entryPtr, (ClientData) enginePtr); + + return (Tk_StyleEngine) enginePtr; +} + +/* + *--------------------------------------------------------------------------- + * + * InitStyleEngine -- + * + * Initialize a newly allocated style engine. + * + * Results: + * None. + * + * Side effects: + * Memory allocated. + * + *--------------------------------------------------------------------------- + */ + +static void +InitStyleEngine(enginePtr, name, parentPtr) + StyleEngine *enginePtr; /* Points to an uninitialized engine. */ + CONST char *name; /* Name of the registered engine. NULL or empty + * means the default system engine. Usually + * points to the hash key. */ + StyleEngine *parentPtr; /* The engine's parent. NULL means the default + * system engine. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + int elementId; + + if (name == NULL || *name == '\0') { + /* + * This is the default style engine. + */ + + enginePtr->parentPtr = NULL; + + } else if (parentPtr == NULL) { + /* + * The default style engine is the parent. + */ + + enginePtr->parentPtr = tsdPtr->defaultEnginePtr; + + } else { + enginePtr->parentPtr = parentPtr; + } + + /* + * Allocate and initialize elements array. + */ + + if (tsdPtr->nbElements > 0) { + enginePtr->elements = (StyledElement *) ckalloc( + sizeof(StyledElement) * tsdPtr->nbElements); + for (elementId = 0; elementId < tsdPtr->nbElements; elementId++) { + InitStyledElement(enginePtr->elements+elementId); + } + } else { + enginePtr->elements = NULL; + } +} + +/* + *--------------------------------------------------------------------------- + * + * FreeStyleEngine -- + * + * Free an engine and its associated data. + * + * Results: + * None + * + * Side effects: + * Memory freed. + * + *--------------------------------------------------------------------------- + */ + +static void +FreeStyleEngine(enginePtr) + StyleEngine *enginePtr; /* The style engine to free. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + int elementId; + + /* + * Free allocated elements. + */ + + for (elementId = 0; elementId < tsdPtr->nbElements; elementId++) { + FreeStyledElement(enginePtr->elements+elementId); + } + ckfree((char *) enginePtr->elements); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetStyleEngine -- + * + * Retrieve a registered style engine by its name. + * + * Results: + * A pointer to the style engine, or NULL if none found. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +Tk_StyleEngine +Tk_GetStyleEngine(name) + char *name; /* Name of the engine to retrieve. NULL or + * empty means the default system engine. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr; + + if (name == NULL) { + return (Tk_StyleEngine) tsdPtr->defaultEnginePtr; + } + + entryPtr = Tcl_FindHashEntry(&tsdPtr->engineTable, (name?name:"")); + if (!entryPtr) { + return NULL; + } + + return (Tk_StyleEngine) Tcl_GetHashValue(entryPtr); +} + +/* + *--------------------------------------------------------------------------- + * + * InitElement -- + * + * Initialize a newly allocated element. + * + * Results: + * None. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +static void +InitElement(elementPtr, name, id, genericId, created) + Element *elementPtr; /* Points to an uninitialized element.*/ + CONST char *name; /* Name of the registered element. Usually + * points to the hash key. */ + int id; /* Unique element ID. */ + int genericId; /* ID of generic element. -1 means none. */ + int created; /* Boolean, whether the element was created + * explicitly (was registered) or implicitly + * (by a derived element). */ +{ + elementPtr->name = name; + elementPtr->id = id; + elementPtr->genericId = genericId; + elementPtr->created = (created?1:0); +} + +/* + *--------------------------------------------------------------------------- + * + * FreeElement -- + * + * Free an element and its associated data. + * + * Results: + * None. + * + * Side effects: + * Memory freed. + * + *--------------------------------------------------------------------------- + */ + +static void +FreeElement(elementPtr) + Element *elementPtr; /* The element to free. */ +{ + /* Nothing to do. */ +} + +/* + *--------------------------------------------------------------------------- + * + * InitStyledElement -- + * + * Initialize a newly allocated styled element. + * + * Results: + * None. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +static void +InitStyledElement(elementPtr) + StyledElement *elementPtr; /* Points to an uninitialized element.*/ +{ + memset(elementPtr, 0, sizeof(StyledElement)); +} + +/* + *--------------------------------------------------------------------------- + * + * FreeStyledElement -- + * + * Free a styled element and its associated data. + * + * Results: + * None. + * + * Side effects: + * Memory freed. + * + *--------------------------------------------------------------------------- + */ + +static void +FreeStyledElement(elementPtr) + StyledElement *elementPtr; /* The styled element to free. */ +{ + int i; + + /* + * Free allocated widget specs. + */ + + for (i = 0; i < elementPtr->nbWidgetSpecs; i++) { + FreeWidgetSpec(elementPtr->widgetSpecs+i); + } + ckfree((char *) elementPtr->widgetSpecs); +} + +/* + *--------------------------------------------------------------------------- + * + * CreateElement -- + * + * Find an existing or create a new element. + * + * Results: + * The unique ID for the created or found element. + * + * Side effects: + * Memory allocated. + * + *--------------------------------------------------------------------------- + */ + +static int +CreateElement(name, create) + char *name; /* Name of the element. */ + int create; /* Boolean, whether the element is being created + * explicitly (being registered) or implicitly (by a + * derived element). */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr, *engineEntryPtr; + Tcl_HashSearch search; + int newEntry; + int elementId, genericId = -1; + char *dot; + StyleEngine *enginePtr; + + /* + * Find or create the element. + */ + + entryPtr = Tcl_CreateHashEntry(&tsdPtr->elementTable, name, &newEntry); + if (!newEntry) { + elementId = (int) Tcl_GetHashValue(entryPtr); + if (create) { + tsdPtr->elements[elementId].created = 1; + } + return elementId; + } + + /* + * The element didn't exist. If it's a derived element, find or + * create its generic element ID. + */ + + dot = strchr(name, '.'); + if (dot) { + genericId = CreateElement(dot+1, 0); + } + + elementId = tsdPtr->nbElements++; + Tcl_SetHashValue(entryPtr, (ClientData) elementId); + + /* + * Reallocate element table. + */ + + tsdPtr->elements = (Element *) ckrealloc((char *) tsdPtr->elements, + sizeof(Element) * tsdPtr->nbElements); + InitElement(tsdPtr->elements+elementId, + Tcl_GetHashKey(&tsdPtr->elementTable, entryPtr), elementId, + genericId, create); + + /* + * Reallocate style engines' element table. + */ + + engineEntryPtr = Tcl_FirstHashEntry(&tsdPtr->engineTable, &search); + while (engineEntryPtr != NULL) { + enginePtr = (StyleEngine *) Tcl_GetHashValue(engineEntryPtr); + + enginePtr->elements = (StyledElement *) ckrealloc( + (char *) enginePtr->elements, + sizeof(StyledElement) * tsdPtr->nbElements); + InitStyledElement(enginePtr->elements+elementId); + + engineEntryPtr = Tcl_NextHashEntry(&search); + } + + return elementId; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetElementId -- + * + * Find an existing element. + * + * Results: + * The unique ID for the found element, or -1 if not found. + * + * Side effects: + * Generic elements may be created. + * + *--------------------------------------------------------------------------- + */ + +int +Tk_GetElementId(name) + char *name; /* Name of the element. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr; + int genericId = -1; + char *dot; + + /* + * Find the element Id. + */ + + entryPtr = Tcl_FindHashEntry(&tsdPtr->elementTable, name); + if (entryPtr) { + return (int) Tcl_GetHashValue(entryPtr); + } + + /* + * Element not found. If the given name was derived, then first search for + * the generic element. If found, create the new derived element. + */ + + dot = strchr(name, '.'); + if (!dot) { + return -1; + } + genericId = Tk_GetElementId(dot+1); + if (genericId == -1) { + return -1; + } + if (!tsdPtr->elements[genericId].created) { + /* + * The generic element was created implicitly and thus has no real + * existence. + */ + + return -1; + } else { + /* + * The generic element was created explicitly. Create the derived + * element. + */ + + return CreateElement(name, 1); + } +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_RegisterStyledElement -- + * + * Register an implementation of a new or existing element for the + * given style engine. + * + * Results: + * The unique ID for the created or found element. + * + * Side effects: + * Elements may be created. Memory allocated. + * + *--------------------------------------------------------------------------- + */ + +int +Tk_RegisterStyledElement(engine, templatePtr) + Tk_StyleEngine engine; /* Style engine providing the + * implementation. */ + Tk_ElementSpec *templatePtr; /* Static template information about + * the element. */ +{ + int elementId; + StyledElement *elementPtr; + Tk_ElementSpec *specPtr; + int nbOptions; + register Tk_ElementOptionSpec *srcOptions, *dstOptions; + + if (templatePtr->version != TK_STYLE_VERSION_1) { + /* + * Version mismatch. Do nothing. + */ + + return -1; + } + + if (engine == NULL) { + engine = Tk_GetStyleEngine(NULL); + } + + /* + * Register the element, allocating storage in the various engines if + * necessary. + */ + + elementId = CreateElement(templatePtr->name, 1); + + /* + * Initialize the styled element. + */ + + elementPtr = ((StyleEngine *) engine)->elements+elementId; + + specPtr = (Tk_ElementSpec *) ckalloc(sizeof(Tk_ElementSpec)); + specPtr->version = templatePtr->version; + specPtr->name = ckalloc(strlen(templatePtr->name)+1); + strcpy(specPtr->name, templatePtr->name); + nbOptions = 0; + for (nbOptions = 0, srcOptions = templatePtr->options; + srcOptions->name != NULL; + nbOptions++, srcOptions++); + specPtr->options = (Tk_ElementOptionSpec *) ckalloc( + sizeof(Tk_ElementOptionSpec) * (nbOptions+1)); + for (srcOptions = templatePtr->options, dstOptions = specPtr->options; + /* End condition within loop */; + srcOptions++, dstOptions++) { + if (srcOptions->name == NULL) { + dstOptions->name = NULL; + break; + } + + dstOptions->name = ckalloc(strlen(srcOptions->name)+1); + strcpy(dstOptions->name, srcOptions->name); + dstOptions->type = srcOptions->type; + } + specPtr->getSize = templatePtr->getSize; + specPtr->getBox = templatePtr->getBox; + specPtr->getBorderWidth = templatePtr->getBorderWidth; + specPtr->draw = templatePtr->draw; + + elementPtr->specPtr = specPtr; + elementPtr->nbWidgetSpecs = 0; + elementPtr->widgetSpecs = NULL; + + return elementId; +} + +/* + *--------------------------------------------------------------------------- + * + * GetStyledElement -- + * + * Get a registered implementation of an existing element for the + * given style engine. + * + * Results: + * The styled element descriptor, or NULL if not found. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +static StyledElement * +GetStyledElement(enginePtr, elementId) + StyleEngine *enginePtr; /* Style engine providing the implementation. + * NULL means the default system engine. */ + int elementId; /* Unique element ID */{ + StyledElement *elementPtr; + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + StyleEngine *enginePtr2; + + if (enginePtr == NULL) { + enginePtr = tsdPtr->defaultEnginePtr; + } + + while (elementId >= 0 && elementId < tsdPtr->nbElements) { + /* + * Look for an implemented element through the engine chain. + */ + + enginePtr2 = enginePtr; + do { + elementPtr = enginePtr2->elements+elementId; + if (elementPtr->specPtr != NULL) { + return elementPtr; + } + enginePtr2 = enginePtr2->parentPtr; + } while (enginePtr2 != NULL); + + /* + * None found, try with the generic element. + */ + + elementId = tsdPtr->elements[elementId].genericId; + } + + /* + * No matching element found. + */ + + return NULL; +} + +/* + *--------------------------------------------------------------------------- + * + * InitWidgetSpec -- + * + * Initialize a newly allocated widget spec. + * + * Results: + * None. + * + * Side effects: + * Memory allocated. + * + *--------------------------------------------------------------------------- + */ + +static void +InitWidgetSpec(widgetSpecPtr, elementPtr, optionTable) + StyledWidgetSpec *widgetSpecPtr; /* Points to an uninitialized widget + * spec. */ + StyledElement *elementPtr; /* Styled element descriptor. */ + Tk_OptionTable optionTable; /* The widget's option table. */ +{ + int i, nbOptions; + Tk_ElementOptionSpec *elementOptionPtr; + CONST Tk_OptionSpec *widgetOptionPtr; + + widgetSpecPtr->elementPtr = elementPtr; + widgetSpecPtr->optionTable = optionTable; + + /* + * Count the number of options. + */ + + for (nbOptions = 0, elementOptionPtr = elementPtr->specPtr->options; + elementOptionPtr->name != NULL; + nbOptions++, elementOptionPtr++) { + } + + /* + * Build the widget option list. + */ + + widgetSpecPtr->optionsPtr = (CONST Tk_OptionSpec **) ckalloc( + sizeof(Tk_OptionSpec *) * nbOptions); + for (i = 0, elementOptionPtr = elementPtr->specPtr->options; + i < nbOptions; + i++, elementOptionPtr++) { + widgetOptionPtr = TkGetOptionSpec(elementOptionPtr->name, optionTable); + + /* + * Check that the widget option type is compatible with one of the + * element's required types. + */ + + if ( elementOptionPtr->type == TK_OPTION_END + || elementOptionPtr->type == widgetOptionPtr->type) { + widgetSpecPtr->optionsPtr[i] = widgetOptionPtr; + } else { + widgetSpecPtr->optionsPtr[i] = NULL; + } + } +} + +/* + *--------------------------------------------------------------------------- + * + * FreeWidgetSpec -- + * + * Free a widget spec and its associated data. + * + * Results: + * None + * + * Side effects: + * Memory freed. + * + *--------------------------------------------------------------------------- + */ + +static void +FreeWidgetSpec(widgetSpecPtr) + StyledWidgetSpec *widgetSpecPtr; /* The widget spec to free. */ +{ + ckfree((char *) widgetSpecPtr->optionsPtr); +} + +/* + *--------------------------------------------------------------------------- + * + * GetWidgetSpec -- + * + * Return a new or existing widget spec for the given element and + * widget type (identified by its option table). + * + * Results: + * A pointer to the matching widget spec. + * + * Side effects: + * Memory may be allocated. + * + *--------------------------------------------------------------------------- + */ + +static StyledWidgetSpec * +GetWidgetSpec(elementPtr, optionTable) + StyledElement *elementPtr; /* Styled element descriptor. */ + Tk_OptionTable optionTable; /* The widget's option table. */ +{ + StyledWidgetSpec *widgetSpecPtr; + int i; + + /* + * Try to find an existing widget spec. + */ + + for (i = 0; i < elementPtr->nbWidgetSpecs; i++) { + widgetSpecPtr = elementPtr->widgetSpecs+i; + if (widgetSpecPtr->optionTable == optionTable) { + return widgetSpecPtr; + } + } + + /* + * Create and initialize a new widget spec. + */ + + i = elementPtr->nbWidgetSpecs++; + elementPtr->widgetSpecs = (StyledWidgetSpec *) ckrealloc( + (char *) elementPtr->widgetSpecs, + sizeof(StyledWidgetSpec) * elementPtr->nbWidgetSpecs); + widgetSpecPtr = elementPtr->widgetSpecs+i; + InitWidgetSpec(widgetSpecPtr, elementPtr, optionTable); + + return widgetSpecPtr; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetStyledElement -- + * + * This procedure returns a styled instance of the given element. + * + * Results: + * None. + * + * Side effects: + * Cached data may be allocated or updated. + * + *--------------------------------------------------------------------------- + */ + +Tk_StyledElement +Tk_GetStyledElement(style, elementId, optionTable) + Tk_Style style; /* The widget style. */ + int elementId; /* Unique element ID. */ + Tk_OptionTable optionTable; /* Option table for the widget. */ +{ + Style *stylePtr = (Style *) style; + StyledElement *elementPtr; + + /* + * Get an element implementation and call corresponding hook. + */ + + elementPtr = GetStyledElement((stylePtr?stylePtr->enginePtr:NULL), + elementId); + if (!elementPtr) { + return NULL; + } + + return (Tk_StyledElement) GetWidgetSpec(elementPtr, optionTable); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetElementSize -- + * + * This procedure computes the size of the given widget element according + * to its style. + * + * Results: + * None. + * + * Side effects: + * Cached data may be allocated or updated. + * + *--------------------------------------------------------------------------- + */ + +void +Tk_GetElementSize(style, element, recordPtr, tkwin, width, height, inner, widthPtr, + heightPtr) + Tk_Style style; /* The widget style. */ + Tk_StyledElement element; /* The styled element, previously + * returned by Tk_GetStyledElement. */ + char *recordPtr; /* The widget record. */ + Tk_Window tkwin; /* The widget window. */ + int width, height; /* Requested size. */ + int inner; /* Boolean. If TRUE, compute the outer + * size according to the requested + * minimum inner size. If FALSE, compute + * the inner size according to the + * requested maximum outer size. */ + int *widthPtr, *heightPtr; /* Returned size. */ +{ + Style *stylePtr = (Style *) style; + StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element; + + widgetSpecPtr->elementPtr->specPtr->getSize(stylePtr->clientData, + recordPtr, widgetSpecPtr->optionsPtr, tkwin, width, height, inner, + widthPtr, heightPtr); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetElementBox -- + * + * This procedure computes the bounding or inscribed box coordinates + * of the given widget element according to its style and within the + * given limits. + * + * Results: + * None. + * + * Side effects: + * Cached data may be allocated or updated. + * + *--------------------------------------------------------------------------- + */ + +void +Tk_GetElementBox(style, element, recordPtr, tkwin, x, y, width, height, inner, + xPtr, yPtr, widthPtr, heightPtr) + Tk_Style style; /* The widget style. */ + Tk_StyledElement element; /* The styled element, previously + * returned by Tk_GetStyledElement. */ + char *recordPtr; /* The widget record. */ + Tk_Window tkwin; /* The widget window. */ + int x, y; /* Top left corner of available area. */ + int width, height; /* Size of available area. */ + int inner; /* Boolean. If TRUE, compute the + * bounding box according to the + * requested inscribed box size. If + * FALSE, compute the inscribed box + * according to the requested bounding + * box. */ + int *xPtr, *yPtr; /* Returned top left corner. */ + int *widthPtr, *heightPtr; /* Returned size. */ +{ + Style *stylePtr = (Style *) style; + StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element; + + widgetSpecPtr->elementPtr->specPtr->getBox(stylePtr->clientData, + recordPtr, widgetSpecPtr->optionsPtr, tkwin, x, y, width, height, + inner, xPtr, yPtr, widthPtr, heightPtr); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetElementBorderWidth -- + * + * This procedure computes the border widthof the given widget element + * according to its style and within the given limits. + * + * Results: + * Border width in pixels. This value is uniform for all four sides. + * + * Side effects: + * Cached data may be allocated or updated. + * + *--------------------------------------------------------------------------- + */ + +int +Tk_GetElementBorderWidth(style, element, recordPtr, tkwin) + Tk_Style style; /* The widget style. */ + Tk_StyledElement element; /* The styled element, previously + * returned by Tk_GetStyledElement. */ + char *recordPtr; /* The widget record. */ + Tk_Window tkwin; /* The widget window. */ +{ + Style *stylePtr = (Style *) style; + StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element; + + return widgetSpecPtr->elementPtr->specPtr->getBorderWidth( + stylePtr->clientData, recordPtr, widgetSpecPtr->optionsPtr, tkwin); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_DrawElement -- + * + * This procedure draw the given widget element in a given drawable area. + * + * Results: + * None + * + * Side effects: + * Cached data may be allocated or updated. + * + *--------------------------------------------------------------------------- + */ + +void +Tk_DrawElement(style, element, recordPtr, tkwin, d, x, y, width, height, state) + Tk_Style style; /* The widget style. */ + Tk_StyledElement element; /* The styled element, previously + * returned by Tk_GetStyledElement. */ + char *recordPtr; /* The widget record. */ + Tk_Window tkwin; /* The widget window. */ + Drawable d; /* Where to draw element. */ + int x, y; /* Top left corner of element. */ + int width, height; /* Size of element. */ + int state; /* Drawing state flags. */ +{ + Style *stylePtr = (Style *) style; + StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element; + + widgetSpecPtr->elementPtr->specPtr->draw(stylePtr->clientData, + recordPtr, widgetSpecPtr->optionsPtr, tkwin, d, x, y, width, + height, state); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_CreateStyle -- + * + * This procedure is called to create a new style as an instance of the + * given engine. Styles are stored in thread-local space. + * + * Results: + * The newly allocated style. + * + * Side effects: + * Memory allocated. Data added to thread-local table. The style's + * refCount is incremented. + * + *--------------------------------------------------------------------------- + */ + +Tk_Style +Tk_CreateStyle(name, engine, clientData) + CONST char *name; /* Name of the style to create. NULL or empty + * means the default system style. */ + Tk_StyleEngine engine; /* The style engine. */ + ClientData clientData; /* Private data passed as is to engine code. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr; + int newEntry; + Style *stylePtr; + + /* + * Attempt to create a new entry in the style table. + */ + + entryPtr = Tcl_CreateHashEntry(&tsdPtr->styleTable, (name?name:""), + &newEntry); + if (!newEntry) { + /* + * A style was already registered by that name. + */ + + return NULL; + } + + /* + * Allocate and intitialize a new style. + */ + + stylePtr = (Style *) ckalloc(sizeof(Style)); + InitStyle(stylePtr, entryPtr, Tcl_GetHashKey(&tsdPtr->styleTable, entryPtr), + (engine?(StyleEngine *) engine:tsdPtr->defaultEnginePtr), clientData); + Tcl_SetHashValue(entryPtr, (ClientData) stylePtr); + stylePtr->refCount++; + + return (Tk_Style) stylePtr; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_NameOfStyle -- + * + * Given a style, return its registered name. + * + * Results: + * The return value is the name that was passed to Tk_CreateStyle() to + * create the style. The storage for the returned string is private + * (it points to the corresponding hash key) The caller should not modify + * this string. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +CONST char * +Tk_NameOfStyle(style) + Tk_Style style; /* Style whose name is desired. */ +{ + Style *stylePtr = (Style *) style; + + return stylePtr->name; +} + +/* + *--------------------------------------------------------------------------- + * + * InitStyle -- + * + * Initialize a newly allocated style. + * + * Results: + * None. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +static void +InitStyle(stylePtr, hashPtr, name, enginePtr, clientData) + Style *stylePtr; /* Points to an uninitialized style. */ + Tcl_HashEntry *hashPtr; /* Hash entry for the registered style. */ + CONST char *name; /* Name of the registered style. NULL or empty + * means the default system style. Usually + * points to the hash key. */ + StyleEngine *enginePtr; /* The style engine. */ + ClientData clientData; /* Private data passed as is to engine code. */ +{ + stylePtr->refCount = 0; + stylePtr->hashPtr = hashPtr; + stylePtr->name = name; + stylePtr->enginePtr = enginePtr; + stylePtr->clientData = clientData; +} + +/* + *--------------------------------------------------------------------------- + * + * FreeStyle -- + * + * Free a style and its associated data. + * + * Results: + * None + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +static void +FreeStyle(stylePtr) + Style *stylePtr; /* The style to free. */ +{ + /* Nothing to do. */ +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetStyle -- + * + * Retrieve a registered style by its name. + * + * Results: + * A pointer to the style engine, or NULL if none found. In the latter + * case and if the interp is not NULL, an error message is left in the + * interp's result. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ + +Tk_Style +Tk_GetStyle(interp, name) + Tcl_Interp *interp; /* Interp for error return. */ + CONST char *name; /* Name of the style to retrieve. NULL or empty + * means the default system style. */ +{ + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); + Tcl_HashEntry *entryPtr; + Style *stylePtr; + + /* + * Search for a corresponding entry in the style table. + */ + + entryPtr = Tcl_FindHashEntry(&tsdPtr->styleTable, (name?name:"")); + if (entryPtr == NULL) { + if (interp != NULL) { + Tcl_AppendResult(interp, "style \"", name, "\" doesn't exist", NULL); + } + return (Tk_Style) NULL; + } + stylePtr = (Style *) Tcl_GetHashValue(entryPtr); + stylePtr->refCount++; + + return (Tk_Style) stylePtr; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_FreeStyle -- + * + * Free a style previously created by Tk_CreateStyle. + * + * Results: + * None + * + * Side effects: + * The style's refCount is decremented. If it reaches zero, the style + * is freed. + * + *--------------------------------------------------------------------------- + */ + +void +Tk_FreeStyle(style) + Tk_Style style; /* The style to free. */ +{ + Style *stylePtr = (Style *) style; + + if (stylePtr == NULL) { + return; + } + stylePtr->refCount--; + if (stylePtr->refCount > 0) { + return; + } + + /* + * Keep the default style alive. + */ + + if (*stylePtr->name == '\0') { + stylePtr->refCount = 1; + return; + } + + Tcl_DeleteHashEntry(stylePtr->hashPtr); + FreeStyle(stylePtr); + ckfree((char *) stylePtr); +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_AllocStyleFromObj -- + * + * Map the string name of a style to a corresponding Tk_Style. The style + * must have already been created by Tk_CreateStyle. + * + * Results: + * The return value is a token for the style that matches objPtr, or + * NULL if none found. If NULL is returned, an error message will be + * left in interp's result object. + * + * Side effects: + * The style's reference count is incremented. For each call to this + * procedure, there should eventually be a call to Tk_FreeStyle() or + * Tk_FreeStyleFromObj() so that the database is cleaned up when styles + * aren't in use anymore. + * + *--------------------------------------------------------------------------- + */ + +Tk_Style +Tk_AllocStyleFromObj(interp, objPtr) + Tcl_Interp *interp; /* Interp for error return. */ + Tcl_Obj *objPtr; /* Object containing name of the style to + * retrieve. */ +{ + Style *stylePtr; + + if (objPtr->typePtr != &styleObjType) { + SetStyleFromAny(interp, objPtr); + stylePtr = (Style *) objPtr->internalRep.otherValuePtr; + } else { + stylePtr = (Style *) objPtr->internalRep.otherValuePtr; + stylePtr->refCount++; + } + + return (Tk_Style) stylePtr; +} + +/* + *---------------------------------------------------------------------- + * + * Tk_GetStyleFromObj -- + * + * Find the style that corresponds to a given object. The style must + * have already been created by Tk_CreateStyle. + * + * Results: + * The return value is a token for the style that matches objPtr, or + * NULL if none found. + * + * Side effects: + * If the object is not already a style ref, the conversion will free + * any old internal representation. + * + *---------------------------------------------------------------------- + */ + +Tk_Style +Tk_GetStyleFromObj(objPtr) + Tcl_Obj *objPtr; /* The object from which to get the style. */ +{ + if (objPtr->typePtr != &styleObjType) { + SetStyleFromAny((Tcl_Interp *) NULL, objPtr); + } + + return (Tk_Style) objPtr->internalRep.otherValuePtr; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_FreeStyleFromObj -- + * + * Called to release a style inside a Tcl_Obj *. + * + * Results: + * None. + * + * Side effects: + * If the object is a style ref, the conversion will free its + * internal representation. + * + *--------------------------------------------------------------------------- + */ + +void +Tk_FreeStyleFromObj(objPtr) + Tcl_Obj *objPtr; /* The Tcl_Obj * to be freed. */ +{ + if (objPtr->typePtr == &styleObjType) { + FreeStyleObjProc(objPtr); + } +} + +/* + *---------------------------------------------------------------------- + * + * SetStyleFromAny -- + * + * Convert the internal representation of a Tcl object to the + * style internal form. + * + * Results: + * Always returns TCL_OK. If an error occurs is returned (e.g. the + * style doesn't exist), an error message will be left in interp's + * result. + * + * Side effects: + * The object is left with its typePtr pointing to styleObjType. + * The reference count is incremented (in Tk_GetStyle()). + * + *---------------------------------------------------------------------- + */ + +static int +SetStyleFromAny(interp, objPtr) + Tcl_Interp *interp; /* Used for error reporting if not NULL. */ + Tcl_Obj *objPtr; /* The object to convert. */ +{ + Tcl_ObjType *typePtr; + char *name; + + /* + * Free the old internalRep before setting the new one. + */ + + name = Tcl_GetString(objPtr); + typePtr = objPtr->typePtr; + if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { + (*typePtr->freeIntRepProc)(objPtr); + } + + objPtr->typePtr = &styleObjType; + objPtr->internalRep.otherValuePtr = (VOID *) Tk_GetStyle(interp, name); + + return TCL_OK; +} + +/* + *--------------------------------------------------------------------------- + * + * FreeStyleObjProc -- + * + * This proc is called to release an object reference to a style. + * Called when the object's internal rep is released. + * + * Results: + * None. + * + * Side effects: + * The reference count is decremented (in Tk_FreeStyle()). + * + *--------------------------------------------------------------------------- + */ + +static void +FreeStyleObjProc(objPtr) + Tcl_Obj *objPtr; /* The object we are releasing. */ +{ + Style *stylePtr = (Style *) objPtr->internalRep.otherValuePtr; + + if (stylePtr != NULL) { + Tk_FreeStyle((Tk_Style) stylePtr); + objPtr->internalRep.otherValuePtr = NULL; + } +} + +/* + *--------------------------------------------------------------------------- + * + * DupStyleObjProc -- + * + * When a cached style object is duplicated, this is called to + * update the internal reps. + * + * Results: + * None. + * + * Side effects: + * The style's refCount is incremented and the internal rep of the copy + * is set to point to it. + * + *--------------------------------------------------------------------------- + */ + +static void +DupStyleObjProc(srcObjPtr, dupObjPtr) + Tcl_Obj *srcObjPtr; /* The object we are copying from. */ + Tcl_Obj *dupObjPtr; /* The object we are copying to. */ +{ + Style *stylePtr = (Style *) srcObjPtr->internalRep.otherValuePtr; + + dupObjPtr->typePtr = srcObjPtr->typePtr; + dupObjPtr->internalRep.otherValuePtr = (VOID *) stylePtr; + + if (stylePtr != NULL) { + stylePtr->refCount++; + } +} diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 03addc0..e778e40 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWindow.c,v 1.48 2002/06/15 21:06:07 mdejong Exp $ + * RCS: @(#) $Id: tkWindow.c,v 1.49 2002/06/18 23:51:46 dkf Exp $ */ #include "tkPort.h" @@ -864,6 +864,7 @@ TkCreateMainWindow(interp, screenName, baseName) TkEventInit(); TkBindInit(mainPtr); TkFontPkgInit(mainPtr); + TkStylePkgInit(mainPtr); mainPtr->tlFocusPtr = NULL; mainPtr->displayFocusPtr = NULL; mainPtr->optionRootPtr = NULL; @@ -1446,6 +1447,7 @@ Tk_DestroyWindow(tkwin) TkDeleteAllImages(winPtr->mainPtr); TkFontPkgFree(winPtr->mainPtr); TkFocusFree(winPtr->mainPtr); + TkStylePkgFree(winPtr->mainPtr); /* * When embedding Tk into other applications, make sure diff --git a/unix/Makefile.in b/unix/Makefile.in index 5704ebe..dd2f1fa 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -5,7 +5,7 @@ # "autoconf" program (constructs like "@foo@" will get replaced in the # actual Makefile. # -# RCS: @(#) $Id: Makefile.in,v 1.68 2002/06/17 20:17:55 hobbs Exp $ +# RCS: @(#) $Id: Makefile.in,v 1.69 2002/06/18 23:51:46 dkf Exp $ # Current Tk version; used in various names. @@ -289,7 +289,7 @@ OBJS = tk3d.o tkArgv.o tkAtom.o tkBind.o tkBitmap.o tkClipboard.o tkCmds.o \ tkColor.o tkConfig.o tkConsole.o tkCursor.o tkError.o tkEvent.o \ tkFocus.o tkFont.o tkGet.o tkGC.o tkGeometry.o tkGrab.o tkGrid.o \ tkMain.o tkObj.o tkOldConfig.o tkOption.o tkPack.o tkPlace.o \ - tkSelect.o tkUtil.o tkVisual.o tkWindow.o \ + tkSelect.o tkStyle.o tkUtil.o tkVisual.o tkWindow.o \ $(UNIXOBJS) $(WIDGOBJS) $(CANVOBJS) $(IMAGEOBJS) $(TEXTOBJS) TK_DECLS = \ @@ -309,14 +309,14 @@ SRCS = \ $(GENERIC_DIR)/tkGrid.c $(GENERIC_DIR)/tkConsole.c \ $(GENERIC_DIR)/tkMain.c $(GENERIC_DIR)/tkOption.c \ $(GENERIC_DIR)/tkPack.c $(GENERIC_DIR)/tkPlace.c \ - $(GENERIC_DIR)/tkSelect.c $(GENERIC_DIR)/tkUtil.c \ - $(GENERIC_DIR)/tkVisual.c $(GENERIC_DIR)/tkWindow.c \ + $(GENERIC_DIR)/tkSelect.c $(GENERIC_DIR)/tkStyle.c \ + $(GENERIC_DIR)/tkUtil.c $(GENERIC_DIR)/tkVisual.c \ + $(GENERIC_DIR)/tkWindow.c \ $(GENERIC_DIR)/tkButton.c $(GENERIC_DIR)/tkObj.c \ $(GENERIC_DIR)/tkEntry.c $(GENERIC_DIR)/tkFrame.c \ $(GENERIC_DIR)/tkListbox.c $(GENERIC_DIR)/tkMenu.c \ $(GENERIC_DIR)/tkMenubutton.c $(GENERIC_DIR)/tkMenuDraw.c \ - $(GENERIC_DIR)/tkMessage.c \ - $(GENERIC_DIR)/tkPanedWindow.c \ + $(GENERIC_DIR)/tkMessage.c $(GENERIC_DIR)/tkPanedWindow.c \ $(GENERIC_DIR)/tkScale.c $(GENERIC_DIR)/tkScrollbar.c \ $(GENERIC_DIR)/tkCanvas.c $(GENERIC_DIR)/tkCanvArc.c \ $(GENERIC_DIR)/tkCanvBmap.c $(GENERIC_DIR)/tkCanvImg.c \ @@ -749,6 +749,9 @@ tkPlace.o: $(GENERIC_DIR)/tkPlace.c tkSelect.o: $(GENERIC_DIR)/tkSelect.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkSelect.c +tkStyle.o: $(GENERIC_DIR)/tkStyle.c + $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkStyle.c + tkUtil.o: $(GENERIC_DIR)/tkUtil.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkUtil.c diff --git a/win/Makefile.in b/win/Makefile.in index 7e191bb..f3a9c33 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -4,7 +4,7 @@ # "autoconf" program (constructs like "@foo@" will get replaced in the # actual Makefile. # -# RCS: @(#) $Id: Makefile.in,v 1.50 2002/04/23 00:20:08 hobbs Exp $ +# RCS: @(#) $Id: Makefile.in,v 1.51 2002/06/18 23:51:46 dkf Exp $ TCLVERSION = @TCL_VERSION@ VERSION = @TK_VERSION@ @@ -330,6 +330,7 @@ TK_OBJS = \ tkScale.$(OBJEXT) \ tkScrollbar.$(OBJEXT) \ tkSelect.$(OBJEXT) \ + tkStyle.$(OBJEXT) \ tkText.$(OBJEXT) \ tkTextBTree.$(OBJEXT) \ tkTextDisp.$(OBJEXT) \ diff --git a/win/makefile.vc b/win/makefile.vc index d8752da..834b4c7 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -12,7 +12,7 @@ # Copyright (c) 2001-2002 David Gravereaux. # #------------------------------------------------------------------------------ -# RCS: @(#) $Id: makefile.vc,v 1.60 2002/06/10 22:45:51 davygrvy Exp $ +# RCS: @(#) $Id: makefile.vc,v 1.61 2002/06/18 23:51:46 dkf Exp $ #------------------------------------------------------------------------------ !if "$(MSVCDIR)" == "" @@ -351,6 +351,7 @@ TKOBJS = \ $(TMP_DIR)\tkScale.obj \ $(TMP_DIR)\tkScrollbar.obj \ $(TMP_DIR)\tkSelect.obj \ + $(TMP_DIR)\tkStyle.obj \ $(TMP_DIR)\tkText.obj \ $(TMP_DIR)\tkTextBTree.obj \ $(TMP_DIR)\tkTextDisp.obj \ -- cgit v0.12