From c86de1b46e1f322ca4ad49bfda61f8101314fb41 Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 17 Apr 2007 14:32:27 +0000 Subject: Standardize function definition format. --- ChangeLog | 7 + generic/tkFont.c | 173 ++++++++++++---------- generic/tkListbox.c | 357 ++++++++++++++++++++++----------------------- win/ttkWinMonitor.c | 42 ++++-- win/ttkWinTheme.c | 409 ++++++++++++++++++++++++++++++++-------------------- win/ttkWinXPTheme.c | 360 ++++++++++++++++++++++++--------------------- 6 files changed, 746 insertions(+), 602 deletions(-) diff --git a/ChangeLog b/ChangeLog index a52eaef..b9dcbef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-04-17 Donal K. Fellows + + * generic/tkFont.c, generic/tkListbox.c, unix/tkUnixSelect.c: + * win/ttkWinMonitor.c, win/ttkWinTheme.c, win/ttkWinXPTheme.c: Make + the format of declarations much more standardized (removing K&R-isms + and other things like that). + 2007-04-13 Donal K. Fellows * macosx/tkMacOSXInt.h (LOG_MSG, LOG_ON_ERROR): Added macros to make diff --git a/generic/tkFont.c b/generic/tkFont.c index 4a9fa37..217efaa 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkFont.c,v 1.32 2007/01/18 23:56:43 nijtmans Exp $ + * RCS: @(#) $Id: tkFont.c,v 1.33 2007/04/17 14:32:28 dkf Exp $ */ #include "tkPort.h" @@ -502,27 +502,28 @@ Tk_FontObjCmd( switch ((enum options) index) { case FONT_ACTUAL: { - int skip, result; - int n; - const char* s; + int skip, result, n; + const char *s; Tk_Font tkfont; - Tcl_Obj *optPtr; - Tcl_Obj *charPtr; - Tcl_Obj *resultPtr; + Tcl_Obj *optPtr, *charPtr, *resultPtr; Tcl_UniChar uniChar = 0; const TkFontAttributes *faPtr; TkFontAttributes fa; - /* - * Params 0 and 1 are 'font actual'. Param 2 is the - * font name. 3-4 may be '-displayof $window' + /* + * Params 0 and 1 are 'font actual'. Param 2 is the font name. 3-4 may + * be '-displayof $window' */ + skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); if (skip < 0) { return TCL_ERROR; } - /* Next parameter may be an option */ + /* + * Next parameter may be an option. + */ + n = skip + 3; optPtr = NULL; charPtr = NULL; @@ -536,33 +537,45 @@ Tk_FontObjCmd( } } - /* Next parameter may be '--' to mark end of options */ + /* + * Next parameter may be '--' to mark end of options. + */ + if (n < objc) { if (!strcmp(Tcl_GetString(objv[n]), "--")) { ++n; } } - /* Next parameter is the character to get font information for */ + /* + * Next parameter is the character to get font information for. + */ + if (n < objc) { charPtr = objv[n]; ++n; } - /* If there were fewer than 3 args, or args remain, that's an error */ + /* + * If there were fewer than 3 args, or args remain, that's an error. + */ + if (objc < 3 || n < objc) { Tcl_WrongNumArgs(interp, 2, objv, "font ?-displayof window? ?option? ?--? ?char?"); return TCL_ERROR; } - /* The 'charPtr' arg must be a single Unicode */ + /* + * The 'charPtr' arg must be a single Unicode. + */ + if (charPtr != NULL) { if (Tcl_GetCharLength(charPtr) != 1) { - resultPtr = Tcl_NewStringObj("expected a single character " - "but got \"", -1); + resultPtr = Tcl_NewStringObj( + "expected a single character but got \"", -1); Tcl_AppendLimitedToObj(resultPtr, Tcl_GetString(charPtr), - -1, 40, "..."); + -1, 40, "..."); Tcl_AppendToObj(resultPtr, "\"", -1); Tcl_SetObjResult(interp, resultPtr); return TCL_ERROR; @@ -570,15 +583,21 @@ Tk_FontObjCmd( uniChar = Tcl_GetUniChar(charPtr, 0); } - /* Find the font */ + /* + * Find the font. + */ + tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); if (tkfont == NULL) { return TCL_ERROR; } - - /* Determine the font attributes */ + + /* + * Determine the font attributes. + */ + if (charPtr == NULL) { - faPtr = GetFontAttributes(tkfont); + faPtr = GetFontAttributes(tkfont); } else { TkpGetFontAttrsForChar(tkwin, tkfont, uniChar, &fa); faPtr = &fa; @@ -1391,7 +1410,7 @@ Tk_FreeFont( if (prevPtr == fontPtr) { if (fontPtr->nextPtr == NULL) { Tcl_DeleteHashEntry(fontPtr->cacheHashPtr); - } else { + } else { Tcl_SetHashValue(fontPtr->cacheHashPtr, fontPtr->nextPtr); } } else { @@ -1778,13 +1797,12 @@ Tk_TextWidth( * * Tk_UnderlineChars, TkUnderlineCharsInContext -- * - * These procedures draw an underline for a given range of - * characters in a given string. They don't draw the characters - * (which are assumed to have been displayed previously); they - * just draw the underline. These procedures would mainly be - * used to quickly underline a few characters without having to - * construct an underlined font. To produce properly underlined - * text, the appropriate underlined font should be constructed + * These procedures draw an underline for a given range of characters in + * a given string. They don't draw the characters (which are assumed to + * have been displayed previously); they just draw the underline. These + * procedures would mainly be used to quickly underline a few characters + * without having to construct an underlined font. To produce properly + * underlined text, the appropriate underlined font should be constructed * and used. * * Results: @@ -1822,30 +1840,28 @@ Tk_UnderlineChars( } void -TkUnderlineCharsInContext(display, drawable, gc, tkfont, string, numBytes, - x, y, firstByte, lastByte) - - Display *display; /* Display on which to draw. */ - Drawable drawable; /* Window or pixmap in which to draw. */ - GC gc; /* Graphics context for actually drawing +TkUnderlineCharsInContext( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for actually drawing * line. */ - Tk_Font tkfont; /* Font used in GC; must have been allocated - * by Tk_GetFont(). Used for character + Tk_Font tkfont, /* Font used in GC; must have been allocated + * by Tk_GetFont(). Used for character * dimensions, etc. */ - const char *string; /* String containing characters to be + const char *string, /* String containing characters to be * underlined or overstruck. */ - int numBytes; /* Number of bytes in string. */ - int x, y; /* Coordinates at which the first character - * of the whole string would be drawn. */ - int firstByte; /* Index of first byte of first character. */ - int lastByte; /* Index of first byte after the last + int numBytes, /* Number of bytes in string. */ + int x, int y, /* Coordinates at which the first character of + * the whole string would be drawn. */ + int firstByte, /* Index of first byte of first character. */ + int lastByte) /* Index of first byte after the last * character. */ { TkFont *fontPtr; int startX, endX; - + fontPtr = (TkFont *) tkfont; - + TkpMeasureCharsInContext(tkfont, string, numBytes, 0, firstByte, -1, 0, &startX); TkpMeasureCharsInContext(tkfont, string, numBytes, 0, lastByte, -1, 0, @@ -1906,14 +1922,12 @@ Tk_ComputeTextLayout( { TkFont *fontPtr; const char *start, *end, *special; - int n, y, bytesThisChunk, maxChunks; - int baseline, height, curX, newX, maxWidth; + int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight; + int baseline, height, curX, newX, maxWidth, *lineLengths; TextLayout *layoutPtr; LayoutChunk *chunkPtr; const TkFontMetrics *fmPtr; Tcl_DString lineBuffer; - int *lineLengths; - int curLine, layoutHeight; Tcl_DStringInit(&lineBuffer); @@ -1941,11 +1955,11 @@ Tk_ComputeTextLayout( maxChunks = 1; - layoutPtr = (TextLayout *) ckalloc(sizeof(TextLayout) - + (maxChunks - 1) * sizeof(LayoutChunk)); - layoutPtr->tkfont = tkfont; - layoutPtr->string = string; - layoutPtr->numChunks = 0; + layoutPtr = (TextLayout *) + ckalloc(sizeof(TextLayout) + (maxChunks-1) * sizeof(LayoutChunk)); + layoutPtr->tkfont = tkfont; + layoutPtr->string = string; + layoutPtr->numChunks = 0; baseline = fmPtr->ascent; maxWidth = 0; @@ -2010,8 +2024,8 @@ Tk_ComputeTextLayout( /* * Handle the special character. * - * INTL: Special will be pointing at a 7-bit character so we - * can safely treat it as a single byte. + * INTL: Special will be pointing at a 7-bit character so we can + * safely treat it as a single byte. */ chunkPtr = NULL; @@ -2423,7 +2437,7 @@ Tk_PointToChar( */ lastPtr = chunkPtr; - while ((i < layoutPtr->numChunks) && (chunkPtr->y == baseline)) { + while ((i < layoutPtr->numChunks) && (chunkPtr->y == baseline)) { if (x < chunkPtr->x + chunkPtr->totalWidth) { /* * Point falls on one of the characters in this chunk. @@ -2549,7 +2563,7 @@ Tk_CharBbox( end = Tcl_UtfAtIndex(chunkPtr->start, index); if (xPtr != NULL) { Tk_MeasureChars(tkfont, chunkPtr->start, - end - chunkPtr->start, -1, 0, &x); + end - chunkPtr->start, -1, 0, &x); x += chunkPtr->x; } if (widthPtr != NULL) { @@ -2561,19 +2575,19 @@ Tk_CharBbox( index -= chunkPtr->numChars; chunkPtr++; } - if (index == 0) { - /* - * Special case to get location just past last char in layout. - */ - - chunkPtr--; - x = chunkPtr->x + chunkPtr->totalWidth; - w = 0; - } else { + if (index != 0) { return 0; } /* + * Special case to get location just past last char in layout. + */ + + chunkPtr--; + x = chunkPtr->x + chunkPtr->totalWidth; + w = 0; + + /* * Ensure that the bbox lies within the text layout. This forces all chars * that extend off the right edge of the text layout to have truncated * widths, and all chars that are completely off the right edge of the @@ -2629,9 +2643,9 @@ int Tk_DistanceToTextLayout( Tk_TextLayout layout, /* Layout information, from a previous call * to Tk_ComputeTextLayout(). */ - int x, int y) /* Coordinates of point to check, with - * respect to the upper-left corner of the - * text layout (in pixels). */ + int x, int y) /* Coordinates of point to check, with respect + * to the upper-left corner of the text layout + * (in pixels). */ { int i, x1, x2, y1, y2, xDiff, yDiff, dist, minDist, ascent, descent; LayoutChunk *chunkPtr; @@ -2823,15 +2837,12 @@ Tk_TextLayoutToPostscript( Tk_TextLayout layout) /* The layout to be rendered. */ { #define MAXUSE 128 - char buf[MAXUSE+30]; + char buf[MAXUSE+30], uindex[5] = "\0\0\0\0", one_char[5]; LayoutChunk *chunkPtr; - int i, j, used, c, baseline; + int i, j, used, c, baseline, charsize; Tcl_UniChar ch; - const char *p, *last_p,*glyphname; + const char *p, *last_p, *glyphname; TextLayout *layoutPtr; - char uindex[5]="\0\0\0\0"; - char one_char[5]; - int charsize; int bytecount=0; layoutPtr = (TextLayout *) layout; @@ -2890,8 +2901,10 @@ Tk_TextLayoutToPostscript( * This character doesn't belong to system character set. * So, we must use full glyph name. */ - sprintf(uindex,"%04X",ch); /* endianness? */ - if ((glyphname = Tcl_GetVar2(interp , "::tk::psglyphs",uindex,0))) { + + sprintf(uindex, "%04X", ch); /* endianness? */ + glyphname = Tcl_GetVar2(interp,"::tk::psglyphs",uindex,0); + if (glyphname) { if (used > 0 && buf [used-1] == '(') { --used; } else { @@ -3810,7 +3823,7 @@ TkFontGetFirstTextLayout( Tk_Font *font, char *dst) { - TextLayout *layoutPtr; + TextLayout *layoutPtr; LayoutChunk *chunkPtr; int numBytesInChunk; diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 9e7d575..f5ade9f 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -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: tkListbox.c,v 1.38 2007/01/12 10:41:23 dkf Exp $ + * RCS: @(#) $Id: tkListbox.c,v 1.39 2007/04/17 14:32:28 dkf Exp $ */ #include "tkPort.h" @@ -340,7 +340,7 @@ static const Tk_OptionSpec itemAttrOptionSpecs[] = { * dispatch the listbox widget command. */ -static CONST char *commandNames[] = { +static const char *commandNames[] = { "activate", "bbox", "cget", "configure", "curselection", "delete", "get", "index", "insert", "itemcget", "itemconfigure", "nearest", "scan", "see", "selection", "size", "xview", "yview", NULL @@ -353,21 +353,21 @@ enum command { COMMAND_SIZE, COMMAND_XVIEW, COMMAND_YVIEW }; -static CONST char *selCommandNames[] = { +static const char *selCommandNames[] = { "anchor", "clear", "includes", "set", NULL }; enum selcommand { SELECTION_ANCHOR, SELECTION_CLEAR, SELECTION_INCLUDES, SELECTION_SET }; -static CONST char *scanCommandNames[] = { +static const char *scanCommandNames[] = { "mark", "dragto", NULL }; enum scancommand { SCAN_MARK, SCAN_DRAGTO }; -static CONST char *indexNames[] = { +static const char *indexNames[] = { "active", "anchor", "end", NULL }; enum indices { @@ -381,10 +381,10 @@ enum indices { static void ChangeListboxOffset(Listbox *listPtr, int offset); static void ChangeListboxView(Listbox *listPtr, int index); static int ConfigureListbox(Tcl_Interp *interp, Listbox *listPtr, - int objc, Tcl_Obj *CONST objv[], int flags); + int objc, Tcl_Obj *const objv[], int flags); static int ConfigureListboxItem(Tcl_Interp *interp, Listbox *listPtr, ItemAttr *attrs, int objc, - Tcl_Obj *CONST objv[], int index); + Tcl_Obj *const objv[], int index); static int ListboxDeleteSubCmd(Listbox *listPtr, int first, int last); static void DestroyListbox(char *memPtr); @@ -394,7 +394,7 @@ static void DisplayListbox(ClientData clientData); static int GetListboxIndex(Tcl_Interp *interp, Listbox *listPtr, Tcl_Obj *index, int endIsSize, int *indexPtr); static int ListboxInsertSubCmd(Listbox *listPtr, - int index, int objc, Tcl_Obj *CONST objv[]); + int index, int objc, Tcl_Obj *const objv[]); static void ListboxCmdDeletedProc(ClientData clientData); static void ListboxComputeGeometry(Listbox *listPtr, int fontChanged, int maxIsStale, int updateGrid); @@ -412,22 +412,22 @@ static void ListboxUpdateHScrollbar(Listbox *listPtr); static void ListboxUpdateVScrollbar(Listbox *listPtr); static int ListboxWidgetObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, - Tcl_Obj *CONST objv[]); + Tcl_Obj *const objv[]); static int ListboxBboxSubCmd(Tcl_Interp *interp, Listbox *listPtr, int index); static int ListboxSelectionSubCmd(Tcl_Interp *interp, - Listbox *listPtr, int objc, Tcl_Obj *CONST objv[]); + Listbox *listPtr, int objc, Tcl_Obj *const objv[]); static int ListboxXviewSubCmd(Tcl_Interp *interp, - Listbox *listPtr, int objc, Tcl_Obj *CONST objv[]); + Listbox *listPtr, int objc, Tcl_Obj *const objv[]); static int ListboxYviewSubCmd(Tcl_Interp *interp, - Listbox *listPtr, int objc, Tcl_Obj *CONST objv[]); + Listbox *listPtr, int objc, Tcl_Obj *const objv[]); static ItemAttr * ListboxGetItemAttributes(Tcl_Interp *interp, Listbox *listPtr, int index); static void ListboxWorldChanged(ClientData instanceData); static int NearestListboxElement(Listbox *listPtr, int y); static char * ListboxListVarProc(ClientData clientData, - Tcl_Interp *interp, CONST char *name1, - CONST char *name2, int flags); + Tcl_Interp *interp, const char *name1, + const char *name2, int flags); static void MigrateHashEntries(Tcl_HashTable *table, int first, int last, int offset); @@ -459,11 +459,11 @@ static Tk_ClassProcs listboxClass = { */ int -Tk_ListboxObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* NULL. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +Tk_ListboxObjCmd( + ClientData clientData, /* NULL. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { register Listbox *listPtr; Tk_Window tkwin; @@ -516,7 +516,7 @@ Tk_ListboxObjCmd(clientData, interp, objc, objv) */ listPtr = (Listbox *) ckalloc(sizeof(Listbox)); - memset((void *) listPtr, 0, (sizeof(Listbox))); + memset(listPtr, 0, (sizeof(Listbox))); listPtr->tkwin = tkwin; listPtr->display = Tk_Display(tkwin); @@ -591,11 +591,11 @@ Tk_ListboxObjCmd(clientData, interp, objc, objv) */ static int -ListboxWidgetObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Information about listbox widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Arguments as Tcl_Obj's. */ +ListboxWidgetObjCmd( + ClientData clientData, /* Information about listbox widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Arguments as Tcl_Obj's. */ { register Listbox *listPtr = (Listbox *) clientData; int cmdIndex, index; @@ -774,9 +774,8 @@ ListboxWidgetObjCmd(clientData, interp, objc, objv) } case COMMAND_GET: { - int first, last; + int first, last, listLen; Tcl_Obj **elemPtrs; - int listLen; if (objc != 3 && objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?"); @@ -1071,10 +1070,10 @@ ListboxWidgetObjCmd(clientData, interp, objc, objv) */ static int -ListboxBboxSubCmd(interp, listPtr, index) - Tcl_Interp *interp; /* Pointer to the calling Tcl interpreter */ - Listbox *listPtr; /* Information about the listbox */ - int index; /* Index of the element to get bbox info on */ +ListboxBboxSubCmd( + Tcl_Interp *interp, /* Pointer to the calling Tcl interpreter */ + Listbox *listPtr, /* Information about the listbox */ + int index) /* Index of the element to get bbox info on */ { int lastVisibleIndex; @@ -1139,11 +1138,11 @@ ListboxBboxSubCmd(interp, listPtr, index) */ static int -ListboxSelectionSubCmd(interp, listPtr, objc, objv) - Tcl_Interp *interp; /* Pointer to the calling Tcl interpreter */ - Listbox *listPtr; /* Information about the listbox */ - int objc; /* Number of arguments in the objv array */ - Tcl_Obj *CONST objv[]; /* Array of arguments to the procedure */ +ListboxSelectionSubCmd( + Tcl_Interp *interp, /* Pointer to the calling Tcl interpreter */ + Listbox *listPtr, /* Information about the listbox */ + int objc, /* Number of arguments in the objv array */ + Tcl_Obj *const objv[]) /* Array of arguments to the procedure */ { int selCmdIndex, first, last; int result = TCL_OK; @@ -1230,11 +1229,11 @@ ListboxSelectionSubCmd(interp, listPtr, objc, objv) */ static int -ListboxXviewSubCmd(interp, listPtr, objc, objv) - Tcl_Interp *interp; /* Pointer to the calling Tcl interpreter */ - Listbox *listPtr; /* Information about the listbox */ - int objc; /* Number of arguments in the objv array */ - Tcl_Obj *CONST objv[]; /* Array of arguments to the procedure */ +ListboxXviewSubCmd( + Tcl_Interp *interp, /* Pointer to the calling Tcl interpreter */ + Listbox *listPtr, /* Information about the listbox */ + int objc, /* Number of arguments in the objv array */ + Tcl_Obj *const objv[]) /* Array of arguments to the procedure */ { int index, count, type, windowWidth, windowUnits; @@ -1306,11 +1305,11 @@ ListboxXviewSubCmd(interp, listPtr, objc, objv) */ static int -ListboxYviewSubCmd(interp, listPtr, objc, objv) - Tcl_Interp *interp; /* Pointer to the calling Tcl interpreter */ - Listbox *listPtr; /* Information about the listbox */ - int objc; /* Number of arguments in the objv array */ - Tcl_Obj *CONST objv[]; /* Array of arguments to the procedure */ +ListboxYviewSubCmd( + Tcl_Interp *interp, /* Pointer to the calling Tcl interpreter */ + Listbox *listPtr, /* Information about the listbox */ + int objc, /* Number of arguments in the objv array */ + Tcl_Obj *const objv[]) /* Array of arguments to the procedure */ { int index, count, type; double fraction, fraction2; @@ -1377,10 +1376,10 @@ ListboxYviewSubCmd(interp, listPtr, objc, objv) */ static ItemAttr * -ListboxGetItemAttributes(interp, listPtr, index) - Tcl_Interp *interp; /* Pointer to the calling Tcl interpreter */ - Listbox *listPtr; /* Information about the listbox */ - int index; /* Index of the item to retrieve attributes +ListboxGetItemAttributes( + Tcl_Interp *interp, /* Pointer to the calling Tcl interpreter */ + Listbox *listPtr, /* Information about the listbox */ + int index) /* Index of the item to retrieve attributes * for. */ { int isNew; @@ -1421,8 +1420,8 @@ ListboxGetItemAttributes(interp, listPtr, index) */ static void -DestroyListbox(memPtr) - char *memPtr; /* Info about listbox widget. */ +DestroyListbox( + char *memPtr) /* Info about listbox widget. */ { register Listbox *listPtr = (Listbox *) memPtr; Tcl_HashEntry *entry; @@ -1502,11 +1501,11 @@ DestroyListbox(memPtr) */ static void -DestroyListboxOptionTables(clientData, interp) - ClientData clientData; /* Pointer to the OptionTables struct */ - Tcl_Interp *interp; /* Pointer to the calling interp */ +DestroyListboxOptionTables( + ClientData clientData, /* Pointer to the OptionTables struct */ + Tcl_Interp *interp) /* Pointer to the calling interp */ { - ckfree((char *)clientData); + ckfree((char *) clientData); return; } @@ -1531,13 +1530,13 @@ DestroyListboxOptionTables(clientData, interp) */ static int -ConfigureListbox(interp, listPtr, objc, objv, flags) - Tcl_Interp *interp; /* Used for error reporting. */ - register Listbox *listPtr; /* Information about widget; may or may not +ConfigureListbox( + Tcl_Interp *interp, /* Used for error reporting. */ + register Listbox *listPtr, /* Information about widget; may or may not * already have values for some fields. */ - int objc; /* Number of valid entries in argv. */ - Tcl_Obj *CONST objv[]; /* Arguments. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ + int objc, /* Number of valid entries in argv. */ + Tcl_Obj *const objv[], /* Arguments. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { Tk_SavedOptions savedOptions; Tcl_Obj *oldListObj = NULL; @@ -1694,14 +1693,14 @@ ConfigureListbox(interp, listPtr, objc, objv, flags) */ static int -ConfigureListboxItem(interp, listPtr, attrs, objc, objv, index) - Tcl_Interp *interp; /* Used for error reporting. */ - register Listbox *listPtr; /* Information about widget; may or may not +ConfigureListboxItem( + Tcl_Interp *interp, /* Used for error reporting. */ + register Listbox *listPtr, /* Information about widget; may or may not * already have values for some fields. */ - ItemAttr *attrs; /* Information about the item to configure */ - int objc; /* Number of valid entries in argv. */ - Tcl_Obj *CONST objv[]; /* Arguments. */ - int index; /* Index of the listbox item being configure */ + ItemAttr *attrs, /* Information about the item to configure */ + int objc, /* Number of valid entries in argv. */ + Tcl_Obj *const objv[], /* Arguments. */ + int index) /* Index of the listbox item being configure */ { Tk_SavedOptions savedOptions; @@ -1739,8 +1738,8 @@ ConfigureListboxItem(interp, listPtr, attrs, objc, objv, index) */ static void -ListboxWorldChanged(instanceData) - ClientData instanceData; /* Information about widget. */ +ListboxWorldChanged( + ClientData instanceData) /* Information about widget. */ { XGCValues gcValues; GC gc; @@ -1813,18 +1812,17 @@ ListboxWorldChanged(instanceData) */ static void -DisplayListbox(clientData) - ClientData clientData; /* Information about window. */ +DisplayListbox( + ClientData clientData) /* Information about window. */ { register Listbox *listPtr = (Listbox *) clientData; register Tk_Window tkwin = listPtr->tkwin; GC gc; - int i, limit, x, y, prevSelected, freeGC; + int i, limit, x, y, prevSelected, freeGC, stringLen; Tk_FontMetrics fm; Tcl_Obj *curElement; Tcl_HashEntry *entry; char *stringRep; - int stringLen; ItemAttr *attrs; Tk_3DBorder selectedBg; XGCValues gcValues; @@ -2180,26 +2178,24 @@ DisplayListbox(clientData) */ static void -ListboxComputeGeometry(listPtr, fontChanged, maxIsStale, updateGrid) - Listbox *listPtr; /* Listbox whose geometry is to be +ListboxComputeGeometry( + Listbox *listPtr, /* Listbox whose geometry is to be * recomputed. */ - int fontChanged; /* Non-zero means the font may have changed so + int fontChanged, /* Non-zero means the font may have changed so * per-element width information also has to * be computed. */ - int maxIsStale; /* Non-zero means the "maxWidth" field may no + int maxIsStale, /* Non-zero means the "maxWidth" field may no * longer be up-to-date and must be * recomputed. If fontChanged is 1 then this * must be 1. */ - int updateGrid; /* Non-zero means call Tk_SetGrid or + int updateGrid) /* Non-zero means call Tk_SetGrid or * Tk_UnsetGrid to update gridding for the * window. */ { - int width, height, pixelWidth, pixelHeight; + int width, height, pixelWidth, pixelHeight, textLength, i, result; Tk_FontMetrics fm; Tcl_Obj *element; - int textLength; char *text; - int i, result; if (fontChanged || maxIsStale) { listPtr->xScrollUnit = Tk_TextWidth(listPtr->tkfont, "0", 1); @@ -2276,19 +2272,16 @@ ListboxComputeGeometry(listPtr, fontChanged, maxIsStale, updateGrid) */ static int -ListboxInsertSubCmd(listPtr, index, objc, objv) - register Listbox *listPtr; /* Listbox that is to get the new elements. */ - int index; /* Add the new elements before this +ListboxInsertSubCmd( + register Listbox *listPtr, /* Listbox that is to get the new elements. */ + int index, /* Add the new elements before this * element. */ - int objc; /* Number of new elements to add. */ - Tcl_Obj *CONST objv[]; /* New elements (one per entry). */ + int objc, /* Number of new elements to add. */ + Tcl_Obj *const objv[]) /* New elements (one per entry). */ { - int i, oldMaxWidth; + int i, oldMaxWidth, pixelWidth, result, length; Tcl_Obj *newListObj; - int pixelWidth; - int result; char *stringRep; - int length; oldMaxWidth = listPtr->maxWidth; for (i = 0; i < objc; i++) { @@ -2329,18 +2322,18 @@ ListboxInsertSubCmd(listPtr, index, objc, objv) } /* - * Replace the current object and set attached listvar, if any. - * This may error if listvar points to a var in a deleted namespace, but - * we ignore those errors. If the namespace is recreated, it will - * auto-sync with the current value. [Bug 1424513] + * Replace the current object and set attached listvar, if any. This may + * error if listvar points to a var in a deleted namespace, but we ignore + * those errors. If the namespace is recreated, it will auto-sync with the + * current value. [Bug 1424513] */ Tcl_IncrRefCount(newListObj); Tcl_DecrRefCount(listPtr->listObj); listPtr->listObj = newListObj; if (listPtr->listVarName != NULL) { - Tcl_SetVar2Ex(listPtr->interp, listPtr->listVarName, - (char *) NULL, listPtr->listObj, TCL_GLOBAL_ONLY); + Tcl_SetVar2Ex(listPtr->interp, listPtr->listVarName, NULL, + listPtr->listObj, TCL_GLOBAL_ONLY); } /* @@ -2395,18 +2388,14 @@ ListboxInsertSubCmd(listPtr, index, objc, objv) */ static int -ListboxDeleteSubCmd(listPtr, first, last) - register Listbox *listPtr; /* Listbox widget to modify. */ - int first; /* Index of first element to delete. */ - int last; /* Index of last element to delete. */ +ListboxDeleteSubCmd( + register Listbox *listPtr, /* Listbox widget to modify. */ + int first, /* Index of first element to delete. */ + int last) /* Index of last element to delete. */ { - int count, i, widthChanged; - Tcl_Obj *newListObj; - Tcl_Obj *element; - int length; + int count, i, widthChanged, length, result, pixelWidth; + Tcl_Obj *newListObj, *element; char *stringRep; - int result; - int pixelWidth; Tcl_HashEntry *entry; /* @@ -2492,18 +2481,18 @@ ListboxDeleteSubCmd(listPtr, first, last) } /* - * Replace the current object and set attached listvar, if any. - * This may error if listvar points to a var in a deleted namespace, but - * we ignore those errors. If the namespace is recreated, it will - * auto-sync with the current value. [Bug 1424513] + * Replace the current object and set attached listvar, if any. This may + * error if listvar points to a var in a deleted namespace, but we ignore + * those errors. If the namespace is recreated, it will auto-sync with the + * current value. [Bug 1424513] */ Tcl_IncrRefCount(newListObj); Tcl_DecrRefCount(listPtr->listObj); listPtr->listObj = newListObj; if (listPtr->listVarName != NULL) { - Tcl_SetVar2Ex(listPtr->interp, listPtr->listVarName, - (char *) NULL, listPtr->listObj, TCL_GLOBAL_ONLY); + Tcl_SetVar2Ex(listPtr->interp, listPtr->listVarName, NULL, + listPtr->listObj, TCL_GLOBAL_ONLY); } /* @@ -2573,9 +2562,9 @@ ListboxDeleteSubCmd(listPtr, first, last) */ static void -ListboxEventProc(clientData, eventPtr) - ClientData clientData; /* Information about window. */ - XEvent *eventPtr; /* Information about event. */ +ListboxEventProc( + ClientData clientData, /* Information about window. */ + XEvent *eventPtr) /* Information about event. */ { Listbox *listPtr = (Listbox *) clientData; @@ -2649,8 +2638,8 @@ ListboxEventProc(clientData, eventPtr) */ static void -ListboxCmdDeletedProc(clientData) - ClientData clientData; /* Pointer to widget record for widget. */ +ListboxCmdDeletedProc( + ClientData clientData) /* Pointer to widget record for widget. */ { Listbox *listPtr = (Listbox *) clientData; @@ -2685,18 +2674,17 @@ ListboxCmdDeletedProc(clientData) */ static int -GetListboxIndex(interp, listPtr, indexObj, endIsSize, indexPtr) - Tcl_Interp *interp; /* For error messages. */ - Listbox *listPtr; /* Listbox for which the index is being +GetListboxIndex( + Tcl_Interp *interp, /* For error messages. */ + Listbox *listPtr, /* Listbox for which the index is being * specified. */ - Tcl_Obj *indexObj; /* Specifies an element in the listbox. */ - int endIsSize; /* If 1, "end" refers to the number of entries + Tcl_Obj *indexObj, /* Specifies an element in the listbox. */ + int endIsSize, /* If 1, "end" refers to the number of entries * in the listbox. If 0, "end" refers to 1 * less than the number of entries. */ - int *indexPtr; /* Where to store converted index. */ + int *indexPtr) /* Where to store converted index. */ { - int result; - int index; + int result, index; char *stringRep; /* @@ -2795,9 +2783,9 @@ GetListboxIndex(interp, listPtr, indexObj, endIsSize, indexPtr) */ static void -ChangeListboxView(listPtr, index) - register Listbox *listPtr; /* Information about widget. */ - int index; /* Index of element in listPtr that should now +ChangeListboxView( + register Listbox *listPtr, /* Information about widget. */ + int index) /* Index of element in listPtr that should now * appear at the top of the listbox. */ { if (index >= (listPtr->nElements - listPtr->fullLines)) { @@ -2830,10 +2818,9 @@ ChangeListboxView(listPtr, index) */ static void -ChangeListboxOffset(listPtr, offset) - register Listbox *listPtr; /* Information about widget. */ - int offset; /* Desired new "xOffset" for - * listbox. */ +ChangeListboxOffset( + register Listbox *listPtr, /* Information about widget. */ + int offset) /* Desired new "xOffset" for listbox. */ { int maxOffset; @@ -2881,10 +2868,10 @@ ChangeListboxOffset(listPtr, offset) */ static void -ListboxScanTo(listPtr, x, y) - register Listbox *listPtr; /* Information about widget. */ - int x; /* X-coordinate to use for scan operation. */ - int y; /* Y-coordinate to use for scan operation. */ +ListboxScanTo( + register Listbox *listPtr, /* Information about widget. */ + int x, /* X-coordinate to use for scan operation. */ + int y) /* Y-coordinate to use for scan operation. */ { int newTopIndex, newOffset, maxIndex, maxOffset; @@ -2950,9 +2937,9 @@ ListboxScanTo(listPtr, x, y) */ static int -NearestListboxElement(listPtr, y) - register Listbox *listPtr; /* Information about widget. */ - int y; /* Y-coordinate in listPtr's window. */ +NearestListboxElement( + register Listbox *listPtr, /* Information about widget. */ + int y) /* Y-coordinate in listPtr's window. */ { int index; @@ -2991,18 +2978,17 @@ NearestListboxElement(listPtr, y) */ static int -ListboxSelect(listPtr, first, last, select) - register Listbox *listPtr; /* Information about widget. */ - int first; /* Index of first element to select or +ListboxSelect( + register Listbox *listPtr, /* Information about widget. */ + int first, /* Index of first element to select or * deselect. */ - int last; /* Index of last element to select or + int last, /* Index of last element to select or * deselect. */ - int select; /* 1 means select items, 0 means deselect + int select) /* 1 means select items, 0 means deselect * them. */ { - int i, firstRedisplay, oldCount; + int i, firstRedisplay, oldCount, isNew; Tcl_HashEntry *entry; - int isNew; if (last < first) { i = first; @@ -3084,23 +3070,21 @@ ListboxSelect(listPtr, first, last, select) */ static int -ListboxFetchSelection(clientData, offset, buffer, maxBytes) - ClientData clientData; /* Information about listbox widget. */ - int offset; /* Offset within selection of first byte to be +ListboxFetchSelection( + ClientData clientData, /* Information about listbox widget. */ + int offset, /* Offset within selection of first byte to be * returned. */ - char *buffer; /* Location in which to place selection. */ - int maxBytes; /* Maximum number of bytes to place at buffer, + char *buffer, /* Location in which to place selection. */ + int maxBytes) /* Maximum number of bytes to place at buffer, * not including terminating NULL * character. */ { register Listbox *listPtr = (Listbox *) clientData; Tcl_DString selection; - int length, count, needNewline; + int length, count, needNewline, stringLen, i; Tcl_Obj *curElement; char *stringRep; - int stringLen; Tcl_HashEntry *entry; - int i; if (!listPtr->exportSelection) { return -1; @@ -3142,9 +3126,7 @@ ListboxFetchSelection(clientData, offset, buffer, maxBytes) if (count > maxBytes) { count = maxBytes; } - memcpy((VOID *) buffer, - (VOID *) (Tcl_DStringValue(&selection) + offset), - (size_t) count); + memcpy(buffer, Tcl_DStringValue(&selection) + offset, (size_t) count); } buffer[count] = '\0'; Tcl_DStringFree(&selection); @@ -3170,8 +3152,8 @@ ListboxFetchSelection(clientData, offset, buffer, maxBytes) */ static void -ListboxLostSelection(clientData) - ClientData clientData; /* Information about listbox widget. */ +ListboxLostSelection( + ClientData clientData) /* Information about listbox widget. */ { register Listbox *listPtr = (Listbox *) clientData; @@ -3198,11 +3180,11 @@ ListboxLostSelection(clientData) */ static void -EventuallyRedrawRange(listPtr, first, last) - register Listbox *listPtr; /* Information about widget. */ - int first; /* Index of first element in list that needs +EventuallyRedrawRange( + register Listbox *listPtr, /* Information about widget. */ + int first, /* Index of first element in list that needs * to be redrawn. */ - int last; /* Index of last element in list that needs to + int last) /* Index of last element in list that needs to * be redrawn. May be less than first; these * just bracket a range. */ { @@ -3241,8 +3223,8 @@ EventuallyRedrawRange(listPtr, first, last) */ static void -ListboxUpdateVScrollbar(listPtr) - register Listbox *listPtr; /* Information about widget. */ +ListboxUpdateVScrollbar( + register Listbox *listPtr) /* Information about widget. */ { char string[TCL_DOUBLE_SPACE * 2]; double first, last; @@ -3302,8 +3284,8 @@ ListboxUpdateVScrollbar(listPtr) */ static void -ListboxUpdateHScrollbar(listPtr) - register Listbox *listPtr; /* Information about widget. */ +ListboxUpdateHScrollbar( + register Listbox *listPtr) /* Information about widget. */ { char string[TCL_DOUBLE_SPACE * 2]; int result, windowWidth; @@ -3361,17 +3343,16 @@ ListboxUpdateHScrollbar(listPtr) */ static char * -ListboxListVarProc(clientData, interp, name1, name2, flags) - ClientData clientData; /* Information about button. */ - Tcl_Interp *interp; /* Interpreter containing variable. */ - CONST char *name1; /* Not used. */ - CONST char *name2; /* Not used. */ - int flags; /* Information about what happened. */ +ListboxListVarProc( + ClientData clientData, /* Information about button. */ + Tcl_Interp *interp, /* Interpreter containing variable. */ + const char *name1, /* Not used. */ + const char *name2, /* Not used. */ + int flags) /* Information about what happened. */ { Listbox *listPtr = (Listbox *)clientData; Tcl_Obj *oldListObj, *varListObj; - int oldLength; - int i; + int oldLength, i; Tcl_HashEntry *entry; /* @@ -3428,17 +3409,23 @@ ListboxListVarProc(clientData, interp, name1, name2, flags) Tcl_ListObjLength(listPtr->interp, listPtr->listObj, &listPtr->nElements); if (listPtr->nElements < oldLength) { for (i = listPtr->nElements; i < oldLength; i++) { - /* Clean up selection */ + /* + * Clean up selection. + */ + entry = Tcl_FindHashEntry(listPtr->selection, (char *)i); if (entry != NULL) { listPtr->numSelected--; Tcl_DeleteHashEntry(entry); } - /* Clean up attributes */ + /* + * Clean up attributes. + */ + entry = Tcl_FindHashEntry(listPtr->itemAttrTable, (char *)i); if (entry != NULL) { - ckfree((char *)Tcl_GetHashValue(entry)); + ckfree((char *) Tcl_GetHashValue(entry)); Tcl_DeleteHashEntry(entry); } } @@ -3488,11 +3475,11 @@ ListboxListVarProc(clientData, interp, name1, name2, flags) */ static void -MigrateHashEntries(table, first, last, offset) - Tcl_HashTable *table; - int first; - int last; - int offset; +MigrateHashEntries( + Tcl_HashTable *table, + int first, + int last, + int offset) { int i, isNew; Tcl_HashEntry *entry; diff --git a/win/ttkWinMonitor.c b/win/ttkWinMonitor.c index 3dc2cad..b6c5a15 100644 --- a/win/ttkWinMonitor.c +++ b/win/ttkWinMonitor.c @@ -1,4 +1,4 @@ -/* $Id: ttkWinMonitor.c,v 1.9 2007/04/10 18:05:48 jenglish Exp $ +/* $Id: ttkWinMonitor.c,v 1.10 2007/04/17 14:32:28 dkf Exp $ */ #ifdef _MSC_VER @@ -58,7 +58,9 @@ static SystemColorEntry sysColors[] = { { NULL, 0 } }; -static void RegisterSystemColors(Tcl_Interp *interp) +static void +RegisterSystemColors( + Tcl_Interp *interp) { Ttk_ResourceCache cache = Ttk_GetResourceCache(interp); SystemColorEntry *sysColor; @@ -74,12 +76,14 @@ static void RegisterSystemColors(Tcl_Interp *interp) } static HWND -CreateThemeMonitorWindow(HINSTANCE hinst, Tcl_Interp *interp) +CreateThemeMonitorWindow( + HINSTANCE hinst, + Tcl_Interp *interp) { WNDCLASSEX wc; - HWND hwnd = NULL; - CHAR title[32] = "TtkMonitorWindow"; - CHAR name[32] = "TtkMonitorClass"; + HWND hwnd = NULL; + CHAR title[32] = "TtkMonitorWindow"; + CHAR name[32] = "TtkMonitorClass"; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; @@ -95,9 +99,9 @@ CreateThemeMonitorWindow(HINSTANCE hinst, Tcl_Interp *interp) wc.lpszClassName = name; if (RegisterClassEx(&wc)) { - hwnd = CreateWindow( name, title, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - NULL, NULL, hinst, NULL ); + hwnd = CreateWindow(name, title, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, hinst, NULL); #ifdef _WIN64 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)interp); #else @@ -110,14 +114,20 @@ CreateThemeMonitorWindow(HINSTANCE hinst, Tcl_Interp *interp) } static void -DestroyThemeMonitorWindow(void *clientData) +DestroyThemeMonitorWindow( + void *clientData) { HWND hwnd = (HWND)clientData; + DestroyWindow(hwnd); } static LRESULT WINAPI -WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) +WndProc( + HWND hwnd, + UINT msg, + WPARAM wp, + LPARAM lp) { #ifdef _WIN64 Tcl_Interp *interp = (Tcl_Interp *)GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -136,9 +146,8 @@ WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) case WM_THEMECHANGED: /* - * Reset the application theme to 'xpnative' if present, - * which will in turn fall back to 'winnative' if XP theming - * is disabled. + * Reset the application theme to 'xpnative' if present, which will in + * turn fall back to 'winnative' if XP theming is disabled. */ theme = Ttk_GetTheme(interp, "xpnative"); if (theme) { @@ -157,7 +166,9 @@ WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) MODULE_SCOPE int TtkWinTheme_Init(Tcl_Interp *, HWND hwnd); MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *, HWND hwnd); -MODULE_SCOPE int Ttk_WinPlatformInit(Tcl_Interp *interp) +MODULE_SCOPE int +Ttk_WinPlatformInit( + Tcl_Interp *interp) { HWND hwnd; @@ -169,4 +180,3 @@ MODULE_SCOPE int Ttk_WinPlatformInit(Tcl_Interp *interp) return TCL_OK; } - diff --git a/win/ttkWinTheme.c b/win/ttkWinTheme.c index f080c8c..c0c04ff 100644 --- a/win/ttkWinTheme.c +++ b/win/ttkWinTheme.c @@ -1,6 +1,6 @@ /* winTheme.c - Copyright (C) 2004 Pat Thoyts * - * $Id: ttkWinTheme.c,v 1.4 2007/01/11 19:59:26 jenglish Exp $ + * $Id: ttkWinTheme.c,v 1.5 2007/04/17 14:32:28 dkf Exp $ */ #ifdef _MSC_VER @@ -17,14 +17,18 @@ #endif #include "ttk/ttkTheme.h" - + /* * BoxToRect -- * Helper routine. Converts a Ttk_Box to a Win32 RECT. */ -static RECT BoxToRect(Ttk_Box b) + +static RECT +BoxToRect( + Ttk_Box b) { RECT rc; + rc.top = b.y; rc.left = b.x; rc.bottom = b.y + b.height; @@ -34,31 +38,39 @@ static RECT BoxToRect(Ttk_Box b) /* * ReliefToEdge -- - * Convert a Tk "relief" value into an Windows "edge" value. - * NB: Caller must check for RELIEF_FLAT and RELIEF_SOLID, - * which must be handled specially. + * Convert a Tk "relief" value into an Windows "edge" value. NB: Caller + * must check for RELIEF_FLAT and RELIEF_SOLID, which must be handled + * specially. * - * Passing the BF_FLAT flag to DrawEdge() yields something similar - * to TK_RELIEF_SOLID. TK_RELIEF_FLAT can be implemented by not - * drawing anything. + * Passing the BF_FLAT flag to DrawEdge() yields something similar to + * TK_RELIEF_SOLID. TK_RELIEF_FLAT can be implemented by not drawing + * anything. */ -static unsigned int ReliefToEdge(int relief) + +static unsigned int +ReliefToEdge( + int relief) { switch (relief) { - case TK_RELIEF_RAISED: return EDGE_RAISED; - case TK_RELIEF_SUNKEN: return EDGE_SUNKEN; - case TK_RELIEF_RIDGE: return EDGE_BUMP; - case TK_RELIEF_GROOVE: return EDGE_ETCHED; - case TK_RELIEF_SOLID: return BDR_RAISEDOUTER; - default: - case TK_RELIEF_FLAT: return BDR_RAISEDOUTER; + case TK_RELIEF_RAISED: + return EDGE_RAISED; + case TK_RELIEF_SUNKEN: + return EDGE_SUNKEN; + case TK_RELIEF_RIDGE: + return EDGE_BUMP; + case TK_RELIEF_GROOVE: + return EDGE_ETCHED; + case TK_RELIEF_SOLID: + return BDR_RAISEDOUTER; + default: + case TK_RELIEF_FLAT: + return BDR_RAISEDOUTER; } } /* ---------------------------------------------------------------------- */ -static Ttk_StateTable checkbutton_statemap[] = -{ +static Ttk_StateTable checkbutton_statemap[] = { { DFCS_CHECKED|DFCS_INACTIVE, TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0 }, { DFCS_CHECKED|DFCS_PUSHED, TTK_STATE_SELECTED|TTK_STATE_PRESSED, 0 }, { DFCS_CHECKED, TTK_STATE_SELECTED, 0 }, @@ -67,27 +79,24 @@ static Ttk_StateTable checkbutton_statemap[] = { 0, 0, 0 } }; -static Ttk_StateTable pushbutton_statemap[] = -{ +static Ttk_StateTable pushbutton_statemap[] = { { DFCS_INACTIVE, TTK_STATE_DISABLED, 0 }, { DFCS_PUSHED, TTK_STATE_PRESSED, 0 }, { DFCS_HOT, TTK_STATE_ACTIVE, 0 }, { 0, 0, 0 } }; -static Ttk_StateTable arrow_statemap[] = -{ +static Ttk_StateTable arrow_statemap[] = { { DFCS_INACTIVE, TTK_STATE_DISABLED, 0 }, { DFCS_PUSHED | DFCS_FLAT, TTK_STATE_PRESSED, 0 }, { 0, 0, 0 } }; - + /*------------------------------------------------------------------------ * +++ FrameControlElement -- * General-purpose element for things drawn with DrawFrameControl */ -typedef struct -{ +typedef struct { const char *name; /* element name */ int classId; /* class id for DrawFrameControl */ int partId; /* part id for DrawFrameControl */ @@ -97,8 +106,7 @@ typedef struct Ttk_Padding padding; /* additional placement padding */ } FrameControlElementData; -static FrameControlElementData FrameControlElements[] = -{ +static FrameControlElementData FrameControlElements[] = { { "Checkbutton.indicator", DFC_BUTTON, DFCS_BUTTONCHECK, SM_CYMENUCHECK, SM_CYMENUCHECK, checkbutton_statemap, {0,0,4,0} }, @@ -126,46 +134,55 @@ static FrameControlElementData FrameControlElements[] = /* ---------------------------------------------------------------------- */ -static void FrameControlElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +FrameControlElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { FrameControlElementData *elementData = clientData; + *widthPtr = GetSystemMetrics(elementData->cxId); *heightPtr = GetSystemMetrics(elementData->cyId); *paddingPtr = elementData->padding; } -static void FrameControlElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +FrameControlElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { FrameControlElementData *elementData = clientData; RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); - DrawFrameControl(hdc, &rc, - elementData->classId, - elementData->partId|Ttk_StateTableLookup(elementData->stateMap, state)); + DrawFrameControl(hdc, &rc, elementData->classId, + elementData->partId|Ttk_StateTableLookup(elementData->stateMap,state)); TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec FrameControlElementSpec = -{ +static Ttk_ElementSpec FrameControlElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, FrameControlElementGeometry, FrameControlElementDraw }; - + /*---------------------------------------------------------------------- * +++ Border element implementation. */ typedef struct { - Tcl_Obj *reliefObj; + Tcl_Obj *reliefObj; } BorderElement; static Ttk_ElementOptionSpec BorderElementOptions[] = { @@ -173,17 +190,27 @@ static Ttk_ElementOptionSpec BorderElementOptions[] = { {NULL} }; -static void BorderElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +BorderElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE); paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE); } -static void BorderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +BorderElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { BorderElement *border = elementRecord; RECT rc = BoxToRect(b); @@ -195,33 +222,31 @@ static void BorderElementDraw( if (relief != TK_RELIEF_FLAT) { UINT xFlags = (relief == TK_RELIEF_SOLID) ? BF_FLAT : 0; + hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, ReliefToEdge(relief), BF_RECT | xFlags); TkWinReleaseDrawableDC(d, hdc, &dcState); } } -static Ttk_ElementSpec BorderElementSpec = -{ +static Ttk_ElementSpec BorderElementSpec = { TK_STYLE_VERSION_2, sizeof(BorderElement), BorderElementOptions, BorderElementGeometry, BorderElementDraw }; - + /* * Entry field borders: * Sunken border; also fill with window color. */ -typedef struct -{ - Tcl_Obj *backgroundObj; +typedef struct { + Tcl_Obj *backgroundObj; } FieldElement; -static Ttk_ElementOptionSpec FieldElementOptions[] = -{ +static Ttk_ElementOptionSpec FieldElementOptions[] = { { "-fieldbackground", TK_OPTION_BORDER, Tk_Offset(FieldElement,backgroundObj), "white" }, {NULL} @@ -229,8 +254,12 @@ static Ttk_ElementOptionSpec FieldElementOptions[] = static void FieldElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE); paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE); @@ -238,8 +267,12 @@ FieldElementGeometry( static void FieldElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { FieldElement *field = elementRecord; Tk_3DBorder bg = Tk_Get3DBorderFromObj(tkwin, field->backgroundObj); @@ -247,32 +280,32 @@ FieldElementDraw( TkWinDCState dcState; HDC hdc; - Tk_Fill3DRectangle( - tkwin, d, bg, b.x, b.y, b.width, b.height, 0, TK_RELIEF_FLAT); + Tk_Fill3DRectangle(tkwin, d, bg, b.x, b.y, b.width, b.height, 0, + TK_RELIEF_FLAT); hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT); TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec FieldElementSpec = -{ +static Ttk_ElementSpec FieldElementSpec = { TK_STYLE_VERSION_2, sizeof(FieldElement), FieldElementOptions, FieldElementGeometry, FieldElementDraw }; - + /*------------------------------------------------------------------------ * +++ Button borders. * Drawn with DrawFrameControl instead of DrawEdge; * Also draw default indicator and focus ring. */ + typedef struct { - Tcl_Obj *reliefObj; - Tcl_Obj *highlightColorObj; - Tcl_Obj *defaultStateObj; + Tcl_Obj *reliefObj; + Tcl_Obj *highlightColorObj; + Tcl_Obj *defaultStateObj; } ButtonBorderElement; static Ttk_ElementOptionSpec ButtonBorderElementOptions[] = { @@ -285,9 +318,14 @@ static Ttk_ElementOptionSpec ButtonBorderElementOptions[] = { {NULL} }; -static void ButtonBorderElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +ButtonBorderElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { ButtonBorderElement *bd = elementRecord; int relief = TK_RELIEF_RAISED; @@ -302,7 +340,8 @@ static void ButtonBorderElementGeometry( /* Space for default indicator: */ if (defaultState != TTK_BUTTON_DEFAULT_DISABLED) { - ++cx; ++cy; + ++cx; + ++cy; } /* Space for focus ring: @@ -313,9 +352,14 @@ static void ButtonBorderElementGeometry( *paddingPtr = Ttk_MakePadding(cx,cy,cx,cy); } -static void ButtonBorderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +ButtonBorderElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { ButtonBorderElement *bd = elementRecord; int relief = TK_RELIEF_FLAT; @@ -329,7 +373,7 @@ static void ButtonBorderElementDraw( if (defaultState == TTK_BUTTON_DEFAULT_ACTIVE) { XColor *highlightColor = - Tk_GetColorFromObj(tkwin, bd->highlightColorObj); + Tk_GetColorFromObj(tkwin, bd->highlightColorObj); GC gc = Tk_GCForColor(highlightColor, d); XDrawRectangle(Tk_Display(tkwin), d, gc, b.x,b.y,b.width-1,b.height-1); } @@ -340,56 +384,65 @@ static void ButtonBorderElementDraw( hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); rc = BoxToRect(b); - DrawFrameControl(hdc, &rc, - DFC_BUTTON, /* classId */ - DFCS_BUTTONPUSH | Ttk_StateTableLookup(pushbutton_statemap, state)); + DrawFrameControl(hdc, &rc, DFC_BUTTON, /* classId */ + DFCS_BUTTONPUSH|Ttk_StateTableLookup(pushbutton_statemap, state)); /* Draw focus ring: */ if (state & TTK_STATE_FOCUS) { short int borderWidth = 3; /* @@@ Use GetSystemMetrics?*/ + rc = BoxToRect(Ttk_PadBox(b, Ttk_UniformPadding(borderWidth))); DrawFocusRect(hdc, &rc); } TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec ButtonBorderElementSpec = -{ +static Ttk_ElementSpec ButtonBorderElementSpec = { TK_STYLE_VERSION_2, sizeof(ButtonBorderElement), ButtonBorderElementOptions, ButtonBorderElementGeometry, ButtonBorderElementDraw }; - + /*------------------------------------------------------------------------ * +++ Focus element. * Draw dashed focus rectangle. */ -static void FocusElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +FocusElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { *paddingPtr = Ttk_UniformPadding(1); } -static void FocusElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +FocusElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { if (state & TTK_STATE_FOCUS) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); + DrawFocusRect(hdc, &rc); TkWinReleaseDrawableDC(d, hdc, &dcState); } } -static Ttk_ElementSpec FocusElementSpec = -{ +static Ttk_ElementSpec FocusElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -412,11 +465,17 @@ static Ttk_ElementOptionSpec FillFocusElementOptions[] = { }; /* @@@ FIX THIS */ -static void FillFocusElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +FillFocusElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { FillFocusElement *focus = elementRecord; + if (state & TTK_STATE_FOCUS) { RECT rc = BoxToRect(b); TkWinDCState dcState; @@ -435,61 +494,77 @@ static void FillFocusElementDraw( * ComboboxFocusElement -- * Read-only comboboxes have a filled focus ring, editable ones do not. */ -static void ComboboxFocusElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + +static void +ComboboxFocusElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { if (state & TTK_STATE_READONLY) { FillFocusElementDraw(clientData, elementRecord, tkwin, d, b, state); } } -static Ttk_ElementSpec ComboboxFocusElementSpec = -{ +static Ttk_ElementSpec ComboboxFocusElementSpec = { TK_STYLE_VERSION_2, sizeof(FillFocusElement), FillFocusElementOptions, FocusElementGeometry, ComboboxFocusElementDraw }; - + /*---------------------------------------------------------------------- * +++ Scrollbar trough element. * * The native windows scrollbar is drawn using a pattern brush giving a - * stippled appearance when the trough might otherwise be invisible. - * We can deal with this here. + * stippled appearance when the trough might otherwise be invisible. We can + * deal with this here. */ -typedef struct { /* clientData for Trough element */ - HBRUSH PatternBrush; - HBITMAP PatternBitmap; +typedef struct { /* clientData for Trough element */ + HBRUSH PatternBrush; + HBITMAP PatternBitmap; } TroughClientData; static const WORD Pattern[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa }; -static void TroughClientDataDeleteProc(void *clientData) +static void +TroughClientDataDeleteProc( + void *clientData) { TroughClientData *cd = clientData; + DeleteObject(cd->PatternBrush); DeleteObject(cd->PatternBitmap); ckfree(clientData); } -static TroughClientData *TroughClientDataInit(Tcl_Interp *interp) +static TroughClientData * +TroughClientDataInit( + Tcl_Interp *interp) { - TroughClientData *cd = (TroughClientData*)ckalloc(sizeof(*cd)); + TroughClientData *cd = (TroughClientData *) ckalloc(sizeof(*cd)); + cd->PatternBitmap = CreateBitmap(8, 8, 1, 1, Pattern); - cd->PatternBrush = CreatePatternBrush(cd->PatternBitmap); + cd->PatternBrush = CreatePatternBrush(cd->PatternBitmap); Ttk_RegisterCleanup(interp, cd, TroughClientDataDeleteProc); return cd; } -static void TroughElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +TroughElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { TroughClientData *cd = clientData; TkWinDCState dcState; @@ -515,33 +590,34 @@ static void TroughElementDraw( TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec TroughElementSpec = -{ +static Ttk_ElementSpec TroughElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, TtkNullElementGeometry, TroughElementDraw }; - + /*------------------------------------------------------------------------ * +++ Thumb element. */ -typedef struct -{ +typedef struct { Tcl_Obj *orientObj; } ThumbElement; -static Ttk_ElementOptionSpec ThumbElementOptions[] = -{ +static Ttk_ElementOptionSpec ThumbElementOptions[] = { { "-orient", TK_OPTION_ANY,Tk_Offset(ThumbElement,orientObj),"horizontal"}, { NULL } }; static void ThumbElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { ThumbElement *thumbPtr = elementRecord; int orient; @@ -556,52 +632,60 @@ static void ThumbElementGeometry( } } -static void ThumbElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +ThumbElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc; /* Windows doesn't show a thumb when the scrollbar is disabled */ - if (state & TTK_STATE_DISABLED) + if (state & TTK_STATE_DISABLED) { return; + } hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_MIDDLE); TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec ThumbElementSpec = -{ +static Ttk_ElementSpec ThumbElementSpec = { TK_STYLE_VERSION_2, sizeof(ThumbElement), ThumbElementOptions, ThumbElementGeometry, ThumbElementDraw }; - + /* ---------------------------------------------------------------------- * The slider element is the shaped thumb used in the slider widget. * Windows likes to call this a trackbar. */ -typedef struct -{ +typedef struct { Tcl_Obj *orientObj; /* orientation of the slider widget */ } SliderElement; -static Ttk_ElementOptionSpec SliderElementOptions[] = -{ +static Ttk_ElementOptionSpec SliderElementOptions[] = { { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj), "horizontal" }, { NULL } }; -static void SliderElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +SliderElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { SliderElement *slider = elementRecord; int orient; @@ -616,9 +700,14 @@ static void SliderElementGeometry( } } -static void SliderElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +SliderElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { RECT rc = BoxToRect(b); TkWinDCState dcState; @@ -629,47 +718,56 @@ static void SliderElementDraw( TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec SliderElementSpec = -{ +static Ttk_ElementSpec SliderElementSpec = { TK_STYLE_VERSION_2, sizeof(SliderElement), SliderElementOptions, SliderElementGeometry, SliderElementDraw }; - + /*------------------------------------------------------------------------ * +++ Notebook elements. */ -static void ClientElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +ClientElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE); paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE); } -static void ClientElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +ClientElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); + DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_SOFT); TkWinReleaseDrawableDC(d, hdc, &dcState); } -static Ttk_ElementSpec ClientElementSpec = -{ +static Ttk_ElementSpec ClientElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, ClientElementGeometry, ClientElementDraw }; - + /*------------------------------------------------------------------------ * +++ Layouts. */ @@ -687,11 +785,13 @@ TTK_BEGIN_LAYOUT(ComboboxLayout) TTK_GROUP("Combobox.focus", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_BOTH, TTK_NODE("Combobox.textarea", TTK_FILL_BOTH)))) TTK_END_LAYOUT - - + /* ---------------------------------------------------------------------- */ -MODULE_SCOPE int TtkWinTheme_Init(Tcl_Interp *interp, HWND hwnd) +MODULE_SCOPE int +TtkWinTheme_Init( + Tcl_Interp *interp, + HWND hwnd) { Ttk_Theme themePtr, parentPtr; FrameControlElementData *fce = FrameControlElements; @@ -704,15 +804,15 @@ MODULE_SCOPE int TtkWinTheme_Init(Tcl_Interp *interp, HWND hwnd) Ttk_RegisterElementSpec(themePtr, "border", &BorderElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "Button.border", - &ButtonBorderElementSpec, NULL); + &ButtonBorderElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "field", &FieldElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "focus", &FocusElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "Combobox.focus", - &ComboboxFocusElementSpec, NULL); + &ComboboxFocusElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "thumb", &ThumbElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "slider", &SliderElementSpec, NULL); Ttk_RegisterElementSpec(themePtr, "Scrollbar.trough", &TroughElementSpec, - TroughClientDataInit(interp)); + TroughClientDataInit(interp)); Ttk_RegisterElementSpec(themePtr, "client", &ClientElementSpec, NULL); @@ -727,4 +827,3 @@ MODULE_SCOPE int TtkWinTheme_Init(Tcl_Interp *interp, HWND hwnd) Tcl_PkgProvide(interp, "ttk::theme::winnative", TTK_VERSION); return TCL_OK; } - diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index c10e964..38e373b 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -1,5 +1,5 @@ /* - * $Id: ttkWinXPTheme.c,v 1.11 2007/04/10 18:14:24 jenglish Exp $ + * $Id: ttkWinXPTheme.c,v 1.12 2007/04/17 14:32:28 dkf Exp $ * * Tk theme engine which uses the Windows XP "Visual Styles" API * Adapted from Georgios Petasis' XP theme patch. @@ -53,8 +53,7 @@ typedef HRESULT (STDAPICALLTYPE DrawThemeTextProc)(HTHEME hTheme, HDC hdc, typedef BOOL (STDAPICALLTYPE IsThemeActiveProc)(VOID); typedef BOOL (STDAPICALLTYPE IsAppThemedProc)(VOID); -typedef struct -{ +typedef struct { OpenThemeDataProc *OpenThemeData; CloseThemeDataProc *CloseThemeData; GetThemePartSizeProc *GetThemePartSize; @@ -67,8 +66,7 @@ typedef struct HWND stubWindow; } XPThemeProcs; -typedef struct -{ +typedef struct { HINSTANCE hlibrary; XPThemeProcs *procs; } XPThemeData; @@ -88,39 +86,39 @@ typedef struct */ static XPThemeProcs * -LoadXPThemeProcs(HINSTANCE *phlib) +LoadXPThemeProcs( + HINSTANCE *phlib) { /* - * Load the library "uxtheme.dll", where the native widget - * drawing routines are implemented. This will only succeed - * if we are running at least on Windows XP. + * Load the library "uxtheme.dll", where the native widget drawing + * routines are implemented. This will only succeed if we are running at + * least on Windows XP. */ + HINSTANCE handle; + *phlib = handle = LoadLibrary("uxtheme.dll"); - if (handle != 0) - { + if (handle != 0) { /* * We have successfully loaded the library. Proceed in storing the * addresses of the functions we want to use. */ - XPThemeProcs *procs = (XPThemeProcs*)ckalloc(sizeof(XPThemeProcs)); + XPThemeProcs *procs = (XPThemeProcs *) ckalloc(sizeof(XPThemeProcs)); #define LOADPROC(name) \ (0 != (procs->name = (name ## Proc *)GetProcAddress(handle, #name) )) - if ( LOADPROC(OpenThemeData) - && LOADPROC(CloseThemeData) - && LOADPROC(GetThemePartSize) - && LOADPROC(DrawThemeBackground) - && LOADPROC(GetThemeTextExtent) - && LOADPROC(DrawThemeText) - && LOADPROC(IsThemeActive) - && LOADPROC(IsAppThemed) - ) - { + if ( LOADPROC(OpenThemeData) && + LOADPROC(CloseThemeData) && + LOADPROC(GetThemePartSize) && + LOADPROC(DrawThemeBackground) && + LOADPROC(GetThemeTextExtent) && + LOADPROC(DrawThemeText) && + LOADPROC(IsThemeActive) && + LOADPROC(IsAppThemed)) { return procs; } #undef LOADPROC - ckfree((char*)procs); + ckfree((char *) procs); } return 0; } @@ -132,7 +130,8 @@ LoadXPThemeProcs(HINSTANCE *phlib) */ static void -XPThemeDeleteProc(void *clientData) +XPThemeDeleteProc( + void *clientData) { XPThemeData *themeData = clientData; FreeLibrary(themeData->hlibrary); @@ -140,7 +139,9 @@ XPThemeDeleteProc(void *clientData) } static int -XPThemeEnabled(Ttk_Theme theme, void *clientData) +XPThemeEnabled( + Ttk_Theme theme, + void *clientData) { XPThemeData *themeData = clientData; int active = themeData->procs->IsThemeActive(); @@ -153,7 +154,8 @@ XPThemeEnabled(Ttk_Theme theme, void *clientData) * Helper routine. Returns a RECT data structure. */ static RECT -BoxToRect(Ttk_Box b) +BoxToRect( + Ttk_Box b) { RECT rc; rc.top = b.y; @@ -358,44 +360,38 @@ static Ttk_StateTable tabitem_statemap[] = * BP_PUSHBUTTONS). Set the IGNORE_THEMESIZE flag to skip this call. */ -typedef struct /* XP element specifications */ -{ - const char *elementName; /* Tk theme engine element name */ +typedef struct { /* XP element specifications */ + const char *elementName; /* Tk theme engine element name */ Ttk_ElementSpec *elementSpec; /* Element spec (usually GenericElementSpec) */ - LPCWSTR className; /* Windows window class name */ - int partId; /* BP_PUSHBUTTON, BP_CHECKBUTTON, etc. */ + LPCWSTR className; /* Windows window class name */ + int partId; /* BP_PUSHBUTTON, BP_CHECKBUTTON, etc. */ Ttk_StateTable *statemap; /* Map Tk states to XP states */ Ttk_Padding padding; /* See NOTE-GetThemeMargins */ - int flags; -# define IGNORE_THEMESIZE 0x1 /* See NOTE-GetThemePartSize */ -# define PAD_MARGINS 0x2 /* See NOTE-GetThemeMargins */ + int flags; +#define IGNORE_THEMESIZE 0x1 /* See NOTE-GetThemePartSize */ +#define PAD_MARGINS 0x2 /* See NOTE-GetThemeMargins */ } ElementInfo; -typedef struct -{ - /* - * Static data, initialized when element is registered: - */ +typedef struct { + /* Static data, initialized when element is registered: */ ElementInfo *info; XPThemeProcs *procs; /* Pointer to theme procedure table */ - - /* - * Dynamic data, allocated by InitElementData: - */ - HTHEME hTheme; - HDC hDC; - HWND hwnd; - + /* Dynamic data, allocated by InitElementData: */ + HTHEME hTheme; + HDC hDC; + HWND hwnd; /* For TkWinDrawableReleaseDC: */ - Drawable drawable; + Drawable drawable; TkWinDCState dcState; } ElementData; static ElementData * -NewElementData(XPThemeProcs *procs, ElementInfo *info) +NewElementData( + XPThemeProcs *procs, + ElementInfo *info) { - ElementData *elementData = (ElementData*)ckalloc(sizeof(ElementData)); + ElementData *elementData = (ElementData *) ckalloc(sizeof(ElementData)); elementData->procs = procs; elementData->info = info; @@ -404,24 +400,29 @@ NewElementData(XPThemeProcs *procs, ElementInfo *info) return elementData; } -static void DestroyElementData(void *elementData) +static void +DestroyElementData( + void *elementData) { ckfree(elementData); } /* * InitElementData -- - * Looks up theme handle. If Drawable argument is non-NULL, - * also initializes DC. + * Looks up theme handle. If Drawable argument is non-NULL, also + * initializes DC. * * Returns: * 1 on success, 0 on error. - * Caller must later call FreeElementData() so this element - * can be reused. + * Caller must later call FreeElementData() so this element can be + * reused. */ static int -InitElementData(ElementData *elementData, Tk_Window tkwin, Drawable d) +InitElementData( + ElementData *elementData, + Tk_Window tkwin, + Drawable d) { Window win = Tk_WindowId(tkwin); @@ -447,7 +448,8 @@ InitElementData(ElementData *elementData, Tk_Window tkwin, Drawable d) } static void -FreeElementData(ElementData *elementData) +FreeElementData( + ElementData *elementData) { elementData->procs->CloseThemeData(elementData->hTheme); if (elementData->drawable != 0) { @@ -465,25 +467,26 @@ FreeElementData(ElementData *elementData) static void GenericElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { ElementData *elementData = clientData; HRESULT result; SIZE size; - if (!InitElementData(elementData, tkwin, 0)) + if (!InitElementData(elementData, tkwin, 0)) { return; + } if (!(elementData->info->flags & IGNORE_THEMESIZE)) { - result = elementData->procs->GetThemePartSize( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, - Ttk_StateTableLookup(elementData->info->statemap, 0), - NULL /*RECT *prc*/, - TS_TRUE, - &size); + result = elementData->procs->GetThemePartSize(elementData->hTheme, + elementData->hDC, elementData->info->partId, + Ttk_StateTableLookup(elementData->info->statemap, 0), + NULL /*RECT *prc*/, TS_TRUE, &size); if (SUCCEEDED(result)) { *widthPtr = size.cx; @@ -498,8 +501,12 @@ GenericElementGeometry( static void GenericElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { ElementData *elementData = clientData; RECT rc; @@ -513,19 +520,15 @@ GenericElementDraw( } rc = BoxToRect(b); - elementData->procs->DrawThemeBackground( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, - Ttk_StateTableLookup(elementData->info->statemap, state), - &rc, - NULL/*pContentRect*/); + elementData->procs->DrawThemeBackground(elementData->hTheme, + elementData->hDC, elementData->info->partId, + Ttk_StateTableLookup(elementData->info->statemap, state), + &rc, NULL/*pContentRect*/); FreeElementData(elementData); } -static Ttk_ElementSpec GenericElementSpec = -{ +static Ttk_ElementSpec GenericElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -540,31 +543,35 @@ static Ttk_ElementSpec GenericElementSpec = static void ThumbElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { ElementData *elementData = clientData; - unsigned stateId = Ttk_StateTableLookup(elementData->info->statemap, state); + unsigned stateId = Ttk_StateTableLookup(elementData->info->statemap,state); RECT rc = BoxToRect(b); /* * Don't draw the thumb if we are disabled. */ - if (state & TTK_STATE_DISABLED) + if (state & TTK_STATE_DISABLED) { return; + } - if (!InitElementData(elementData, tkwin, d)) + if (!InitElementData(elementData, tkwin, d)) { return; + } elementData->procs->DrawThemeBackground(elementData->hTheme, - elementData->hDC, elementData->info->partId, stateId, - &rc, NULL); + elementData->hDC, elementData->info->partId, stateId, &rc, NULL); FreeElementData(elementData); } -static Ttk_ElementSpec ThumbElementSpec = -{ +static Ttk_ElementSpec ThumbElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -578,15 +585,20 @@ static Ttk_ElementSpec ThumbElementSpec = * so that indeterminate progress bars show 3 bars instead of 1. */ -static void PbarElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) +static void +PbarElementGeometry( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { ElementData *elementData = clientData; int nBars = 3; GenericElementGeometry(clientData, elementRecord, tkwin, - widthPtr, heightPtr, paddingPtr); + widthPtr, heightPtr, paddingPtr); if (elementData->info->partId == PP_CHUNK) { *widthPtr *= nBars; @@ -595,8 +607,7 @@ static void PbarElementGeometry( } } -static Ttk_ElementSpec PbarElementSpec = -{ +static Ttk_ElementSpec PbarElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -606,38 +617,46 @@ static Ttk_ElementSpec PbarElementSpec = /*---------------------------------------------------------------------- * +++ Notebook tab element. - * Same as generic element, with additional logic to select - * proper iPartID for the leftmost tab. + + * Same as generic element, with additional logic to select proper + * iPartID for the leftmost tab. * - * Notes: TABP_TABITEMRIGHTEDGE (or TABP_TOPTABITEMRIGHTEDGE, - * which appears to be identical) should be used if the - * tab is exactly at the right edge of the notebook, but - * not if it's simply the rightmost tab. This information - * is not available. + * Notes: TABP_TABITEMRIGHTEDGE (or TABP_TOPTABITEMRIGHTEDGE, which + * appears to be identical) should be used if the tab is exactly at the + * right edge of the notebook, but not if it's simply the rightmost tab. + * This information is not available. * - * The TIS_* and TILES_* definitions are identical, so - * we can use the same statemap no matter what the partId. + * The TIS_* and TILES_* definitions are identical, so we can use the + * same statemap no matter what the partId. */ -static void TabElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + +static void +TabElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { ElementData *elementData = clientData; int partId = elementData->info->partId; RECT rc = BoxToRect(b); - if (!InitElementData(elementData, tkwin, d)) + if (!InitElementData(elementData, tkwin, d)) { return; - if (state & TTK_STATE_USER1) + } + if (state & TTK_STATE_USER1) { partId = TABP_TABITEMLEFTEDGE; - elementData->procs->DrawThemeBackground( - elementData->hTheme, elementData->hDC, partId, - Ttk_StateTableLookup(elementData->info->statemap, state), &rc, NULL); + } + elementData->procs->DrawThemeBackground(elementData->hTheme, + elementData->hDC, partId, + Ttk_StateTableLookup(elementData->info->statemap, state), &rc, + NULL); FreeElementData(elementData); } -static Ttk_ElementSpec TabElementSpec = -{ +static Ttk_ElementSpec TabElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -648,36 +667,39 @@ static Ttk_ElementSpec TabElementSpec = /*---------------------------------------------------------------------- * +++ Tree indicator element. * - * Generic element, but don't display at all if TTK_STATE_LEAF (=USER2) set + * Generic element, but don't display at all if TTK_STATE_LEAF (=USER2) + * set */ #define TTK_STATE_OPEN TTK_STATE_USER1 #define TTK_STATE_LEAF TTK_STATE_USER2 -static Ttk_StateTable header_statemap[] = -{ +static Ttk_StateTable header_statemap[] = { { HIS_PRESSED, TTK_STATE_PRESSED, 0 }, { HIS_HOT, TTK_STATE_ACTIVE, 0 }, { HIS_NORMAL, 0,0 }, }; -static Ttk_StateTable tvpglyph_statemap[] = -{ +static Ttk_StateTable tvpglyph_statemap[] = { { GLPS_OPENED, TTK_STATE_OPEN, 0 }, { GLPS_CLOSED, 0,0 }, }; -static void TreeIndicatorElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) +static void +TreeIndicatorElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { if (!(state & TTK_STATE_LEAF)) { GenericElementDraw(clientData,elementRecord,tkwin,d,b,state); } } -static Ttk_ElementSpec TreeIndicatorElementSpec = -{ +static Ttk_ElementSpec TreeIndicatorElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, @@ -691,21 +713,18 @@ static Ttk_ElementSpec TreeIndicatorElementSpec = *---------------------------------------------------------------------- * Text element (does not work yet). * - * According to "Using Windows XP Visual Styles", we need to select - * a font into the DC before calling DrawThemeText(). - * There's just no easy way to get an HFONT out of a Tk_Font. - * Maybe GetThemeFont() would work? + * According to "Using Windows XP Visual Styles", we need to select a font + * into the DC before calling DrawThemeText(). There's just no easy way to get + * an HFONT out of a Tk_Font. Maybe GetThemeFont() would work? * */ -typedef struct -{ +typedef struct { Tcl_Obj *textObj; Tcl_Obj *fontObj; } TextElement; -static Ttk_ElementOptionSpec TextElementOptions[] = -{ +static Ttk_ElementOptionSpec TextElementOptions[] = { { "-text", TK_OPTION_STRING, Tk_Offset(TextElement,textObj), "" }, { "-font", TK_OPTION_FONT, @@ -715,66 +734,70 @@ static Ttk_ElementOptionSpec TextElementOptions[] = static void TextElementGeometry( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *widthPtr, + int *heightPtr, + Ttk_Padding *paddingPtr) { TextElement *element = elementRecord; ElementData *elementData = clientData; RECT rc = {0, 0}; HRESULT hr = S_OK; - if (!InitElementData(elementData, tkwin, 0)) + if (!InitElementData(elementData, tkwin, 0)) { return; + } - hr = elementData->procs->GetThemeTextExtent( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, + hr = elementData->procs->GetThemeTextExtent(elementData->hTheme, + elementData->hDC, elementData->info->partId, Ttk_StateTableLookup(elementData->info->statemap, 0), - Tcl_GetUnicode(element->textObj), - -1, - DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX, - NULL, - &rc); + Tcl_GetUnicode(element->textObj), -1, + DT_LEFT,/*| DT_BOTTOM | DT_NOPREFIX,*/ NULL, &rc); if (SUCCEEDED(hr)) { *widthPtr = rc.right - rc.left; *heightPtr = rc.bottom - rc.top; } - if (*widthPtr < 80) *widthPtr = 80; - if (*heightPtr < 20) *heightPtr = 20; + if (*widthPtr < 80) { + *widthPtr = 80; + } + if (*heightPtr < 20) { + *heightPtr = 20; + } FreeElementData(elementData); } static void TextElementDraw( - ClientData clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, unsigned int state) + ClientData clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + unsigned int state) { TextElement *element = elementRecord; ElementData *elementData = clientData; RECT rc = BoxToRect(b); HRESULT hr = S_OK; - if (!InitElementData(elementData, tkwin, d)) + if (!InitElementData(elementData, tkwin, d)) { return; + } - hr = elementData->procs->DrawThemeText( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, + hr = elementData->procs->DrawThemeText(elementData->hTheme, + elementData->hDC, elementData->info->partId, Ttk_StateTableLookup(elementData->info->statemap, state), - Tcl_GetUnicode(element->textObj), - -1, - DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX, - (state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0, - &rc); + Tcl_GetUnicode(element->textObj), -1, + DT_LEFT,/*| DT_BOTTOM | DT_NOPREFIX,*/ + (state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0, &rc); FreeElementData(elementData); } -static Ttk_ElementSpec TextElementSpec = -{ +static Ttk_ElementSpec TextElementSpec = { TK_STYLE_VERSION_2, sizeof(TextElement), TextElementOptions, @@ -926,7 +949,10 @@ static ElementInfo ElementInfoTable[] = { * +++ Initialization routine: */ -MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) +MODULE_SCOPE int +TtkXPTheme_Init( + Tcl_Interp *interp, + HWND hwnd) { XPThemeData *themeData; XPThemeProcs *procs; @@ -935,8 +961,9 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) ElementInfo *infoPtr; procs = LoadXPThemeProcs(&hlibrary); - if (!procs) + if (!procs) { return TCL_ERROR; + } procs->stubWindow = hwnd; /* @@ -945,8 +972,9 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) parentPtr = Ttk_GetTheme(interp, "winnative"); themePtr = Ttk_CreateTheme(interp, "xpnative", parentPtr); - if (!themePtr) + if (!themePtr) { return TCL_ERROR; + } /* * Set theme data and cleanup proc @@ -964,8 +992,8 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) */ for (infoPtr = ElementInfoTable; infoPtr->elementName != 0; ++infoPtr) { ClientData clientData = NewElementData(procs, infoPtr); - Ttk_RegisterElementSpec( - themePtr, infoPtr->elementName, infoPtr->elementSpec, clientData); + Ttk_RegisterElementSpec(themePtr, infoPtr->elementName, + infoPtr->elementSpec, clientData); Ttk_RegisterCleanup(interp, clientData, DestroyElementData); } @@ -977,9 +1005,9 @@ MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) Ttk_RegisterLayout(themePtr, "TButton", ButtonLayout); Ttk_RegisterLayout(themePtr, "TMenubutton", MenubuttonLayout); Ttk_RegisterLayout(themePtr, "Vertical.TScrollbar", - VerticalScrollbarLayout); + VerticalScrollbarLayout); Ttk_RegisterLayout(themePtr, "Horizontal.TScrollbar", - HorizontalScrollbarLayout); + HorizontalScrollbarLayout); Ttk_RegisterLayout(themePtr, "Vertical.TScale", VerticalScaleLayout); Ttk_RegisterLayout(themePtr, "Horizontal.TScale", HorizontalScaleLayout); -- cgit v0.12