Skip to content

Commit 87d8e77

Browse files
author
jan.nijtmans
committed
Finish for "text". Alphabetise button and frame range checks
1 parent 2ce9513 commit 87d8e77

File tree

3 files changed

+73
-53
lines changed

3 files changed

+73
-53
lines changed

generic/tkButton.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ ConfigureButton(
10281028
int error, haveImage;
10291029
Tk_Image image;
10301030
int wrapLength, borderWidth, highlightWidth, padX, padY;
1031-
int butPtrWidth, butPtrHeight;
1031+
int width, height;
10321032

10331033
/*
10341034
* Eliminate any existing trace on variables monitored by the button.
@@ -1092,13 +1092,6 @@ ConfigureButton(
10921092
} else {
10931093
Tk_SetBackgroundFromBorder(butPtr->tkwin, butPtr->normalBorder);
10941094
}
1095-
Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->wrapLengthObj, &wrapLength);
1096-
if (wrapLength < 0) {
1097-
wrapLength = 0;
1098-
Tcl_DecrRefCount(butPtr->wrapLengthObj);
1099-
butPtr->wrapLengthObj = Tcl_NewIntObj(0);
1100-
Tcl_IncrRefCount(butPtr->wrapLengthObj);
1101-
}
11021095
Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthObj, &borderWidth);
11031096
if (borderWidth < 0) {
11041097
borderWidth = 0;
@@ -1127,6 +1120,13 @@ ConfigureButton(
11271120
butPtr->padYObj = Tcl_NewIntObj(0);
11281121
Tcl_IncrRefCount(butPtr->padYObj);
11291122
}
1123+
Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->wrapLengthObj, &wrapLength);
1124+
if (wrapLength < 0) {
1125+
wrapLength = 0;
1126+
Tcl_DecrRefCount(butPtr->wrapLengthObj);
1127+
butPtr->wrapLengthObj = Tcl_NewIntObj(0);
1128+
Tcl_IncrRefCount(butPtr->wrapLengthObj);
1129+
}
11301130

11311131
if (butPtr->type >= TYPE_CHECK_BUTTON) {
11321132
Tcl_Obj *valuePtr, *namePtr;
@@ -1274,13 +1274,13 @@ ConfigureButton(
12741274
*/
12751275

12761276
if (Tk_GetPixelsFromObj(interp, butPtr->tkwin, butPtr->widthObj,
1277-
&butPtrWidth) != TCL_OK) {
1277+
&width) != TCL_OK) {
12781278
widthError:
12791279
Tcl_AddErrorInfo(interp, "\n (processing \"-width\" option)");
12801280
continue;
12811281
}
12821282
if (Tk_GetPixelsFromObj(interp, butPtr->tkwin, butPtr->heightObj,
1283-
&butPtrHeight) != TCL_OK) {
1283+
&height) != TCL_OK) {
12841284
heightError:
12851285
Tcl_AddErrorInfo(interp, "\n (processing \"-height\" option)");
12861286
continue;
@@ -1290,21 +1290,21 @@ ConfigureButton(
12901290
* The button displays an ordinary text string.
12911291
*/
12921292

1293-
if (Tcl_GetIntFromObj(interp, butPtr->widthObj, &butPtrWidth)
1293+
if (Tcl_GetIntFromObj(interp, butPtr->widthObj, &width)
12941294
!= TCL_OK) {
12951295
goto widthError;
12961296
}
1297-
if (Tcl_GetIntFromObj(interp, butPtr->heightObj, &butPtrHeight)
1297+
if (Tcl_GetIntFromObj(interp, butPtr->heightObj, &height)
12981298
!= TCL_OK) {
12991299
goto heightError;
13001300
}
13011301
}
1302-
if (butPtrWidth < 0) {
1302+
if (width < 0) {
13031303
Tcl_DecrRefCount(butPtr->widthObj);
13041304
butPtr->widthObj = Tcl_NewIntObj(0);
13051305
Tcl_IncrRefCount(butPtr->widthObj);
13061306
}
1307-
if (butPtrHeight < 0) {
1307+
if (height < 0) {
13081308
Tcl_DecrRefCount(butPtr->heightObj);
13091309
butPtr->heightObj = Tcl_NewIntObj(0);
13101310
Tcl_IncrRefCount(butPtr->heightObj);

generic/tkFrame.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -986,24 +986,18 @@ ConfigureFrame(
986986
Tk_SetWindowBackgroundPixmap(framePtr->tkwin, None);
987987
}
988988

989-
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->widthObj, &width);
990-
if (width < 0) {
991-
Tcl_DecrRefCount(framePtr->widthObj);
992-
framePtr->widthObj = Tcl_NewIntObj(0);
993-
Tcl_IncrRefCount(framePtr->widthObj);
989+
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->borderWidthObj, &borderWidth);
990+
if (borderWidth < 0) {
991+
Tcl_DecrRefCount(framePtr->borderWidthObj);
992+
framePtr->borderWidthObj = Tcl_NewIntObj(0);
993+
Tcl_IncrRefCount(framePtr->borderWidthObj);
994994
}
995995
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->heightObj, &height);
996996
if (height < 0) {
997997
Tcl_DecrRefCount(framePtr->heightObj);
998998
framePtr->heightObj = Tcl_NewIntObj(0);
999999
Tcl_IncrRefCount(framePtr->heightObj);
10001000
}
1001-
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->borderWidthObj, &borderWidth);
1002-
if (borderWidth < 0) {
1003-
Tcl_DecrRefCount(framePtr->borderWidthObj);
1004-
framePtr->borderWidthObj = Tcl_NewIntObj(0);
1005-
Tcl_IncrRefCount(framePtr->borderWidthObj);
1006-
}
10071001
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->highlightWidthObj, &highlightWidth);
10081002
if (highlightWidth < 0) {
10091003
Tcl_DecrRefCount(framePtr->highlightWidthObj);
@@ -1022,6 +1016,12 @@ ConfigureFrame(
10221016
framePtr->padYObj = Tcl_NewIntObj(0);
10231017
Tcl_IncrRefCount(framePtr->padYObj);
10241018
}
1019+
Tk_GetPixelsFromObj(NULL, framePtr->tkwin, framePtr->widthObj, &width);
1020+
if (width < 0) {
1021+
Tcl_DecrRefCount(framePtr->widthObj);
1022+
framePtr->widthObj = Tcl_NewIntObj(0);
1023+
Tcl_IncrRefCount(framePtr->widthObj);
1024+
}
10251025

10261026
/*
10271027
* If a -labelwidget is specified, check that it is valid and set up

generic/tkText.c

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,8 +2062,8 @@ ConfigureText(
20622062
{
20632063
Tk_SavedOptions savedOptions;
20642064
int oldExport = (textPtr->exportSelection) && (!Tcl_IsSafe(textPtr->interp));
2065-
int mask = 0;
2066-
int selBorderWidth = INT_MIN, spacing1, spacing2, spacing3;
2065+
int mask = 0, selBorderWidth = 0, height, highlightWidth;
2066+
int borderWidth, spacing1, spacing2, spacing3;
20672067
int insertBorderWidth, insertWidth, padX, padY;
20682068

20692069
if (Tk_SetOptions(interp, (char *) textPtr, textPtr->optionTable,
@@ -2204,6 +2204,41 @@ ConfigureText(
22042204
* Don't allow negative spacings.
22052205
*/
22062206

2207+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->borderWidthObj, &borderWidth);
2208+
if (borderWidth < 0) {
2209+
borderWidth = 0;
2210+
Tcl_DecrRefCount(textPtr->borderWidthObj);
2211+
textPtr->borderWidthObj = Tcl_NewIntObj(0);
2212+
Tcl_IncrRefCount(textPtr->borderWidthObj);
2213+
}
2214+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->heightObj, &height);
2215+
if (height < 0) {
2216+
height = 0;
2217+
Tcl_DecrRefCount(textPtr->heightObj);
2218+
textPtr->heightObj = Tcl_NewIntObj(0);
2219+
Tcl_IncrRefCount(textPtr->heightObj);
2220+
}
2221+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->highlightWidthObj, &highlightWidth);
2222+
if (highlightWidth < 0) {
2223+
highlightWidth = 0;
2224+
Tcl_DecrRefCount(textPtr->highlightWidthObj);
2225+
textPtr->highlightWidthObj = Tcl_NewIntObj(0);
2226+
Tcl_IncrRefCount(textPtr->highlightWidthObj);
2227+
}
2228+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->insertBorderWidthObj, &insertBorderWidth);
2229+
if (insertBorderWidth < 0) {
2230+
insertBorderWidth = 0;
2231+
Tcl_DecrRefCount(textPtr->insertBorderWidthObj);
2232+
textPtr->insertBorderWidthObj = Tcl_NewIntObj(0);
2233+
Tcl_IncrRefCount(textPtr->insertBorderWidthObj);
2234+
}
2235+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->insertWidthObj, &insertWidth);
2236+
if (insertWidth < 0) {
2237+
insertWidth = 0;
2238+
Tcl_DecrRefCount(textPtr->insertWidthObj);
2239+
textPtr->insertWidthObj = Tcl_NewIntObj(0);
2240+
Tcl_IncrRefCount(textPtr->insertWidthObj);
2241+
}
22072242
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padXObj, &padX);
22082243
if (padX < 0) {
22092244
Tcl_DecrRefCount(textPtr->padXObj);
@@ -2216,6 +2251,17 @@ ConfigureText(
22162251
textPtr->padYObj = Tcl_NewIntObj(0);
22172252
Tcl_IncrRefCount(textPtr->padYObj);
22182253
}
2254+
if (textPtr->selBorderWidthObj) {
2255+
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->selBorderWidthObj, &selBorderWidth);
2256+
}
2257+
if (selBorderWidth < 0) {
2258+
selBorderWidth = 0;
2259+
if (textPtr->selBorderWidthObj) {
2260+
Tcl_DecrRefCount(textPtr->selBorderWidthObj);
2261+
}
2262+
textPtr->selBorderWidthObj = Tcl_NewIntObj(0);
2263+
Tcl_IncrRefCount(textPtr->selBorderWidthObj);
2264+
}
22192265
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->spacing1Obj, &spacing1);
22202266
if (spacing1 < 0) {
22212267
spacing1 = 0;
@@ -2237,32 +2283,6 @@ ConfigureText(
22372283
textPtr->spacing3Obj = Tcl_NewIntObj(0);
22382284
Tcl_IncrRefCount(textPtr->spacing3Obj);
22392285
}
2240-
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->insertBorderWidthObj, &insertBorderWidth);
2241-
if (insertBorderWidth < 0) {
2242-
insertBorderWidth = 0;
2243-
Tcl_DecrRefCount(textPtr->insertBorderWidthObj);
2244-
textPtr->insertBorderWidthObj = Tcl_NewIntObj(0);
2245-
Tcl_IncrRefCount(textPtr->insertBorderWidthObj);
2246-
}
2247-
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->insertWidthObj, &insertWidth);
2248-
if (insertWidth < 0) {
2249-
insertWidth = 0;
2250-
Tcl_DecrRefCount(textPtr->insertWidthObj);
2251-
textPtr->insertWidthObj = Tcl_NewIntObj(0);
2252-
Tcl_IncrRefCount(textPtr->insertWidthObj);
2253-
}
2254-
if (textPtr->selBorderWidthObj) {
2255-
Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->selBorderWidthObj, &selBorderWidth);
2256-
}
2257-
if (selBorderWidth < 0) {
2258-
selBorderWidth = 0;
2259-
if (textPtr->selBorderWidthObj) {
2260-
Tcl_DecrRefCount(textPtr->selBorderWidthObj);
2261-
}
2262-
textPtr->selBorderWidthObj = Tcl_NewIntObj(0);
2263-
Tcl_IncrRefCount(textPtr->selBorderWidthObj);
2264-
}
2265-
22662286

22672287
/*
22682288
* Parse tab stops.

0 commit comments

Comments
 (0)