Skip to content

Commit

Permalink
Fix [f91aa24bbe] for CanvImg, scrollbar and text
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Oct 13, 2024
2 parents 285b712 + 30e9b35 commit 03959bc
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 513 deletions.
52 changes: 25 additions & 27 deletions generic/tkCanvImg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ typedef struct ImageItem {
double x, y; /* Coordinates of positioning point for
* image. */
Tk_Anchor anchor; /* Where to anchor image relative to (x,y). */
char *imageString; /* String describing -image option
* (malloc-ed). NULL means no image right
* now. */
char *activeImageString; /* String describing -activeimage option.
Tcl_Obj *imageObj; /* -image option.
* NULL means no image right now. */
char *disabledImageString; /* String describing -disabledimage option.
Tcl_Obj *activeImageObj; /* -activeimage option.
* NULL means no image right now. */
Tcl_Obj *disabledImageObj; /* -disabledimage option.
* NULL means no image right now. */
Tk_Image image; /* Image to display in window, or NULL if no
* image at present. */
Expand All @@ -52,13 +51,13 @@ static const Tk_CustomOption tagsOption = {

static const Tk_ConfigSpec configSpecs[] = {
{TK_CONFIG_STRING, "-activeimage", NULL, NULL,
NULL, offsetof(ImageItem, activeImageString), TK_CONFIG_NULL_OK, NULL},
NULL, offsetof(ImageItem, activeImageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
"center", offsetof(ImageItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
{TK_CONFIG_STRING, "-disabledimage", NULL, NULL,
NULL, offsetof(ImageItem, disabledImageString), TK_CONFIG_NULL_OK, NULL},
NULL, offsetof(ImageItem, disabledImageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_STRING, "-image", NULL, NULL,
NULL, offsetof(ImageItem, imageString), TK_CONFIG_NULL_OK, NULL},
NULL, offsetof(ImageItem, imageObj), TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_CUSTOM, "-state", NULL, NULL,
NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
{TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
Expand Down Expand Up @@ -173,9 +172,9 @@ CreateImage(

imgPtr->canvas = canvas;
imgPtr->anchor = TK_ANCHOR_CENTER;
imgPtr->imageString = NULL;
imgPtr->activeImageString = NULL;
imgPtr->disabledImageString = NULL;
imgPtr->imageObj = NULL;
imgPtr->activeImageObj = NULL;
imgPtr->disabledImageObj = NULL;
imgPtr->image = NULL;
imgPtr->activeImage = NULL;
imgPtr->disabledImage = NULL;
Expand Down Expand Up @@ -302,7 +301,7 @@ ConfigureImage(

tkwin = Tk_CanvasTkwin(canvas);
if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
(const char **) objv, (char *) imgPtr, flags|TK_CONFIG_OBJS)) {
(const char **)objv, (char *)imgPtr, flags|TK_CONFIG_OBJS)) {
return TCL_ERROR;
}

Expand All @@ -313,13 +312,13 @@ ConfigureImage(
* changed.
*/

if (imgPtr->activeImageString != NULL) {
if (imgPtr->activeImageObj != NULL) {
itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT;
} else {
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
}
if (imgPtr->imageString != NULL) {
image = Tk_GetImage(interp, tkwin, imgPtr->imageString,
if (imgPtr->imageObj != NULL) {
image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->imageObj),
ImageChangedProc, imgPtr);
if (image == NULL) {
return TCL_ERROR;
Expand All @@ -331,8 +330,8 @@ ConfigureImage(
Tk_FreeImage(imgPtr->image);
}
imgPtr->image = image;
if (imgPtr->activeImageString != NULL) {
image = Tk_GetImage(interp, tkwin, imgPtr->activeImageString,
if (imgPtr->activeImageObj != NULL) {
image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->activeImageObj),
ImageChangedProc, imgPtr);
if (image == NULL) {
return TCL_ERROR;
Expand All @@ -344,8 +343,8 @@ ConfigureImage(
Tk_FreeImage(imgPtr->activeImage);
}
imgPtr->activeImage = image;
if (imgPtr->disabledImageString != NULL) {
image = Tk_GetImage(interp, tkwin, imgPtr->disabledImageString,
if (imgPtr->disabledImageObj != NULL) {
image = Tk_GetImage(interp, tkwin, Tcl_GetString(imgPtr->disabledImageObj),
ImageChangedProc, imgPtr);
if (image == NULL) {
return TCL_ERROR;
Expand Down Expand Up @@ -386,14 +385,14 @@ DeleteImage(
{
ImageItem *imgPtr = (ImageItem *) itemPtr;

if (imgPtr->imageString != NULL) {
ckfree(imgPtr->imageString);
if (imgPtr->imageObj != NULL) {
Tcl_DecrRefCount(imgPtr->imageObj);
}
if (imgPtr->activeImageString != NULL) {
ckfree(imgPtr->activeImageString);
if (imgPtr->activeImageObj != NULL) {
Tcl_DecrRefCount(imgPtr->activeImageObj);
}
if (imgPtr->disabledImageString != NULL) {
ckfree(imgPtr->disabledImageString);
if (imgPtr->disabledImageObj != NULL) {
Tcl_DecrRefCount(imgPtr->disabledImageObj);
}
if (imgPtr->image != NULL) {
Tk_FreeImage(imgPtr->image);
Expand Down Expand Up @@ -526,7 +525,7 @@ static void
DisplayImage(
Tk_Canvas canvas, /* Canvas that contains item. */
Tk_Item *itemPtr, /* Item to be displayed. */
Display *display, /* Display on which to draw item. */
TCL_UNUSED(Display *), /* Display on which to draw item. */
Drawable drawable, /* Pixmap or window in which to draw item. */
int x, int y, int width, int height)
/* Describes region of canvas that must be
Expand All @@ -536,7 +535,6 @@ DisplayImage(
short drawableX, drawableY;
Tk_Image image;
Tk_State state = itemPtr->state;
(void)display;

if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
Expand Down
29 changes: 17 additions & 12 deletions generic/tkScrollbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static const Tk_ConfigSpec configSpecs[] = {
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_SCROLLBAR_BORDER_WIDTH, offsetof(TkScrollbar, borderWidth), 0, NULL},
{TK_CONFIG_STRING, "-command", "command", "Command",
DEF_SCROLLBAR_COMMAND, offsetof(TkScrollbar, command),
TK_CONFIG_NULL_OK, NULL},
DEF_SCROLLBAR_COMMAND, offsetof(TkScrollbar, commandObj),
TK_CONFIG_OBJS|TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
DEF_SCROLLBAR_CURSOR, offsetof(TkScrollbar, cursor), TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth",
Expand All @@ -79,8 +79,8 @@ static const Tk_ConfigSpec configSpecs[] = {
{TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
DEF_SCROLLBAR_REPEAT_INTERVAL, offsetof(TkScrollbar, repeatInterval), 0, NULL},
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_SCROLLBAR_TAKE_FOCUS, offsetof(TkScrollbar, takeFocus),
TK_CONFIG_NULL_OK, NULL},
DEF_SCROLLBAR_TAKE_FOCUS, offsetof(TkScrollbar, takeFocusObj),
TK_CONFIG_NULL_OK|TK_CONFIG_OBJS, NULL},
{TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
DEF_SCROLLBAR_TROUGH_COLOR, offsetof(TkScrollbar, troughColorPtr),
TK_CONFIG_COLOR_ONLY, NULL},
Expand Down Expand Up @@ -159,7 +159,7 @@ Tk_ScrollbarObjCmd(
scrollPtr, ScrollbarCmdDeletedProc);
scrollPtr->vertical = 0;
scrollPtr->width = 0;
scrollPtr->command = NULL;
scrollPtr->commandObj = NULL;
scrollPtr->commandSize = 0;
scrollPtr->repeatDelay = 0;
scrollPtr->repeatInterval = 0;
Expand All @@ -179,6 +179,10 @@ Tk_ScrollbarObjCmd(
scrollPtr->activeField = 0;
scrollPtr->activeRelief = TK_RELIEF_RAISED;
#ifndef TK_NO_DEPRECATED
#define totalUnits dummy1
#define windowUnits dummy2
#define firstUnit dummy3
#define lastUnit dummy4
scrollPtr->totalUnits = 0;
scrollPtr->windowUnits = 0;
scrollPtr->firstUnit = 0;
Expand All @@ -187,7 +191,7 @@ Tk_ScrollbarObjCmd(
scrollPtr->firstFraction = 0.0;
scrollPtr->lastFraction = 0.0;
scrollPtr->cursor = NULL;
scrollPtr->takeFocus = NULL;
scrollPtr->takeFocusObj = NULL;
scrollPtr->flags = 0;

if (ConfigureScrollbar(interp, scrollPtr, objc-2, objv+2, 0) != TCL_OK) {
Expand Down Expand Up @@ -323,11 +327,11 @@ ScrollbarWidgetObjCmd(
if (scrollPtr->vertical) {
pixels = yDelta;
length = Tk_Height(scrollPtr->tkwin) - 1
- 2*(scrollPtr->arrowLength + scrollPtr->inset);
- 2 * (scrollPtr->arrowLength + scrollPtr->inset);
} else {
pixels = xDelta;
length = Tk_Width(scrollPtr->tkwin) - 1
- 2*(scrollPtr->arrowLength + scrollPtr->inset);
- 2 * (scrollPtr->arrowLength + scrollPtr->inset);
}
if (length == 0) {
fraction = 0.0;
Expand All @@ -352,11 +356,11 @@ ScrollbarWidgetObjCmd(
if (scrollPtr->vertical) {
pos = y - (scrollPtr->arrowLength + scrollPtr->inset);
length = Tk_Height(scrollPtr->tkwin) - 1
- 2*(scrollPtr->arrowLength + scrollPtr->inset);
- 2 * (scrollPtr->arrowLength + scrollPtr->inset);
} else {
pos = x - (scrollPtr->arrowLength + scrollPtr->inset);
length = Tk_Width(scrollPtr->tkwin) - 1
- 2*(scrollPtr->arrowLength + scrollPtr->inset);
- 2 * (scrollPtr->arrowLength + scrollPtr->inset);
}
if (length == 0) {
fraction = 0.0;
Expand All @@ -379,6 +383,7 @@ ScrollbarWidgetObjCmd(
goto error;
}
#ifndef TK_NO_DEPRECATED
# define OLD_STYLE_COMMANDS 2
if (scrollPtr->flags & OLD_STYLE_COMMANDS) {
resObjs[0] = Tcl_NewWideIntObj(scrollPtr->totalUnits);
resObjs[1] = Tcl_NewWideIntObj(scrollPtr->windowUnits);
Expand Down Expand Up @@ -540,8 +545,8 @@ ConfigureScrollbar(
* from a 3-D border.
*/

if (scrollPtr->command != NULL) {
scrollPtr->commandSize = (int) strlen(scrollPtr->command);
if (scrollPtr->commandObj != NULL) {
scrollPtr->commandSize = (int) strlen(Tcl_GetString(scrollPtr->commandObj));
} else {
scrollPtr->commandSize = 0;
}
Expand Down
74 changes: 33 additions & 41 deletions generic/tkScrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ typedef struct TkScrollbar {
Tcl_Command widgetCmd; /* Token for scrollbar's widget command. */
int vertical; /* Non-zero means vertical orientation
* requested, zero means horizontal. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *widthObj; /* Desired narrow dimension of scrollbar, in
* pixels. */
#else
int width; /* Desired narrow dimension of scrollbar, in
* pixels. */
char *command; /* Command prefix to use when invoking
#endif
Tcl_Obj *commandObj; /* Command prefix to use when invoking
* scrolling commands. NULL means don't invoke
* commands. Malloc'ed. */
* commands. */
int commandSize; /* Number of non-NULL bytes in command. */
int repeatDelay; /* How long to wait before auto-repeating on
* scrolling actions (in ms). */
Expand All @@ -48,17 +53,25 @@ typedef struct TkScrollbar {
* Information used when displaying widget:
*/

int borderWidth; /* Width of 3-D borders. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *borderWidthObj; /* Width of 3-D borders. */
#else
int borderWidth;
#endif
Tk_3DBorder bgBorder; /* Used for drawing background (all flat
* surfaces except for trough). */
Tk_3DBorder activeBorder; /* For drawing backgrounds when active (i.e.
* when mouse is positioned over element). */
XColor *troughColorPtr; /* Color for drawing trough. */
int relief; /* Indicates whether window as a whole is
* raised, sunken, or flat. */
int highlightWidth; /* Width in pixels of highlight to draw around
#if TK_MAJOR_VERSION > 8
Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around
* widget when it has the focus. <= 0 means
* don't draw a highlight. */
#else
int highlightWidth;
#endif
XColor *highlightBgColorPtr;
/* Color for drawing traversal highlight area
* when highlight is off. */
Expand All @@ -68,9 +81,13 @@ typedef struct TkScrollbar {
* Indicates how much interior stuff must be
* offset from outside edges to leave room for
* borders. */
int elementBorderWidth; /* Width of border to draw around elements
#if TK_MAJOR_VERSION > 8
Tcl_Obj *elementBorderWidthObj; /* Width of border to draw around elements
* inside scrollbar (arrows and slider). -1
* means use borderWidth. */
#else
int elementBorderWidth;
#endif
int arrowLength; /* Length of arrows along long dimension of
* scrollbar, including space for a small gap
* between the arrow and the slider.
Expand All @@ -87,46 +104,28 @@ typedef struct TkScrollbar {
* use for active element. */

/*
* Information describing the application related to the scrollbar. This
* information is provided by the application by invoking the "set" widget
* command. This information can now be provided in two ways: the "old"
* form (totalUnits, windowUnits, firstUnit, and lastUnit), or the "new"
* form (firstFraction and lastFraction). FirstFraction and lastFraction
* will always be valid, but the old-style information is only valid if
* the OLD_STYLE_COMMANDS flag is 1.
* Information describing the application related to the scrollbar, which
* is provided by the application by invoking the "set" widget command.
* It can be provided in two ways: the "new" form (firstFraction
* and lastFraction) or the "old" form. The "old" form is deprecated.
*/

#ifndef TK_NO_DEPRECATED
int totalUnits; /* Total dimension of application, in units.
* Valid only if the OLD_STYLE_COMMANDS flag
* is set. */
int windowUnits; /* Maximum number of units that can be
* displayed in the window at once. Valid only
* if the OLD_STYLE_COMMANDS flag is set. */
int firstUnit; /* Number of last unit visible in
* application's window. Valid only if the
* OLD_STYLE_COMMANDS flag is set. */
int lastUnit; /* Index of last unit visible in window.
* Valid only if the OLD_STYLE_COMMANDS flag
* isn't set. */
#else
int dummy1,dummy2,dummy3,dummy4; /* sizeof(TkScrollbar) should not depend on TK_NO_DEPRECATED */
#endif /* TK_NO_DEPRECATED */
#if TK_MAJOR_VERSION < 9
int dummy1, dummy2, dummy3, dummy4; /* deprecated, for "old" form. */
#endif
double firstFraction; /* Position of first visible thing in window,
* specified as a fraction between 0 and
* 1.0. */
* specified as a fraction between 0 and 1.0. */
double lastFraction; /* Position of last visible thing in window,
* specified as a fraction between 0 and
* 1.0. */
* specified as a fraction between 0 and 1.0. */

/*
* Miscellaneous information:
*/

Tk_Cursor cursor; /* Current cursor for window, or NULL. */
char *takeFocus; /* Value of -takefocus option; not used in the
Tcl_Obj *takeFocusObj; /* Value of -takefocus option; not used in the
* C code, but used by keyboard traversal
* scripts. Malloc'ed, but may be NULL. */
* scripts. May be NULL. */
int flags; /* Various flags; see below for
* definitions. */
} TkScrollbar;
Expand All @@ -148,18 +147,11 @@ typedef struct TkScrollbar {
*
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
* already been queued to redraw this window.
* OLD_STYLE_COMMANDS: Non-zero means the old style of commands
* should be used to communicate with the widget:
* ".t yview 40", instead of
* ".t yview scroll 2 lines", for example.
* GOT_FOCUS: Non-zero means this window has the input
* focus.
*/

#define REDRAW_PENDING 1
#ifndef TK_NO_DEPRECATED
# define OLD_STYLE_COMMANDS 2
#endif /* TK_NO_DEPRECATED */
#define GOT_FOCUS 4

/*
Expand Down
Loading

0 comments on commit 03959bc

Please sign in to comment.