summaryrefslogtreecommitdiffstats
path: root/generic/tkObj.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkObj.c')
-rw-r--r--generic/tkObj.c178
1 files changed, 101 insertions, 77 deletions
diff --git a/generic/tkObj.c b/generic/tkObj.c
index 7672240..8877d42 100644
--- a/generic/tkObj.c
+++ b/generic/tkObj.c
@@ -34,7 +34,7 @@ typedef struct PixelRep {
#define SET_COMPLEXPIXEL(objPtr, repPtr) \
(objPtr)->internalRep.twoPtrValue.ptr1 = 0; \
- (objPtr)->internalRep.twoPtrValue.ptr2 = (VOID *) repPtr
+ (objPtr)->internalRep.twoPtrValue.ptr2 = repPtr
#define GET_COMPLEXPIXEL(objPtr) \
((PixelRep *) (objPtr)->internalRep.twoPtrValue.ptr2)
@@ -82,8 +82,8 @@ typedef struct WindowRep {
*/
static void DupMMInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr);
-static void DupPixelInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr);
-static void DupWindowInternalRep(Tcl_Obj *srcPtr,Tcl_Obj *copyPtr);
+static void DupPixelInternalRep(Tcl_Obj *srcPtr, Tcl_Obj*copyPtr);
+static void DupWindowInternalRep(Tcl_Obj *srcPtr,Tcl_Obj*copyPtr);
static void FreeMMInternalRep(Tcl_Obj *objPtr);
static void FreePixelInternalRep(Tcl_Obj *objPtr);
static void FreeWindowInternalRep(Tcl_Obj *objPtr);
@@ -99,7 +99,7 @@ static int SetWindowFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
* initial display-independant settings.
*/
-static Tcl_ObjType pixelObjType = {
+static const Tcl_ObjType pixelObjType = {
"pixel", /* name */
FreePixelInternalRep, /* freeIntRepProc */
DupPixelInternalRep, /* dupIntRepProc */
@@ -113,7 +113,7 @@ static Tcl_ObjType pixelObjType = {
* initial display-independant settings.
*/
-static Tcl_ObjType mmObjType = {
+static const Tcl_ObjType mmObjType = {
"mm", /* name */
FreeMMInternalRep, /* freeIntRepProc */
DupMMInternalRep, /* dupIntRepProc */
@@ -126,7 +126,7 @@ static Tcl_ObjType mmObjType = {
* Tcl object.
*/
-static Tcl_ObjType windowObjType = {
+static const Tcl_ObjType windowObjType = {
"window", /* name */
FreeWindowInternalRep, /* freeIntRepProc */
DupWindowInternalRep, /* dupIntRepProc */
@@ -147,9 +147,9 @@ static Tcl_ObjType windowObjType = {
*/
static ThreadSpecificData *
-GetTypeCache()
+GetTypeCache(void)
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (tsdPtr->doubleTypePtr == NULL) {
@@ -189,10 +189,10 @@ GetPixelsFromObjEx(
int *intPtr,
double *dblPtr) /* Places to store resulting pixels. */
{
- int result,fresh;
+ int result, fresh;
double d;
PixelRep *pixelPtr;
- static double bias[] = {
+ static const double bias[] = {
1.0, 10.0, 25.4, 0.35278 /*25.4 / 72.0*/
};
@@ -204,16 +204,16 @@ GetPixelsFromObjEx(
*/
if (objPtr->typePtr != &pixelObjType) {
- ThreadSpecificData *tsdPtr = GetTypeCache();
+ ThreadSpecificData *typeCache = GetTypeCache();
- if (objPtr->typePtr == tsdPtr->doubleTypePtr) {
+ if (objPtr->typePtr == typeCache->doubleTypePtr) {
(void) Tcl_GetDoubleFromObj(interp, objPtr, &d);
if (dblPtr != NULL) {
*dblPtr = d;
}
*intPtr = (int) (d<0 ? d-0.5 : d+0.5);
return TCL_OK;
- } else if (objPtr->typePtr == tsdPtr->intTypePtr) {
+ } else if (objPtr->typePtr == typeCache->intTypePtr) {
(void) Tcl_GetIntFromObj(interp, objPtr, intPtr);
if (dblPtr) {
*dblPtr = (double) (*intPtr);
@@ -223,14 +223,12 @@ GetPixelsFromObjEx(
}
retry:
- if (objPtr->typePtr != &pixelObjType) {
+ fresh = (objPtr->typePtr != &pixelObjType);
+ if (fresh) {
result = SetPixelFromAny(interp, objPtr);
if (result != TCL_OK) {
return result;
}
- fresh = 1;
- } else {
- fresh = 0;
}
if (SIMPLE_PIXELREP(objPtr)) {
@@ -242,14 +240,14 @@ GetPixelsFromObjEx(
pixelPtr = GET_COMPLEXPIXEL(objPtr);
if ((!fresh) && (pixelPtr->tkwin != tkwin)) {
/*
- * In case of exo-screen conversions of non-pixels we force a
+ * In the case of exo-screen conversions of non-pixels, we force a
* recomputation from the string.
*/
FreePixelInternalRep(objPtr);
goto retry;
}
- if ((pixelPtr->tkwin != tkwin)||dblPtr) {
+ if ((pixelPtr->tkwin != tkwin) || dblPtr) {
d = pixelPtr->value;
if (pixelPtr->units >= 0) {
d *= bias[pixelPtr->units] * WidthOfScreen(Tk_Screen(tkwin));
@@ -294,7 +292,7 @@ Tk_GetPixelsFromObj(
Tcl_Obj *objPtr, /* The object from which to get pixels. */
int *intPtr) /* Place to store resulting pixels. */
{
- return GetPixelsFromObjEx(interp,tkwin,objPtr,intPtr,NULL);
+ return GetPixelsFromObjEx(interp, tkwin, objPtr, intPtr, NULL);
}
/*
@@ -326,7 +324,7 @@ Tk_GetDoublePixelsFromObj(
double *doublePtr) /* Place to store resulting pixels. */
{
double d;
- int result,val;
+ int result, val;
result = GetPixelsFromObjEx(interp, tkwin, objPtr, &val, &d);
if (result != TCL_OK) {
@@ -373,7 +371,7 @@ FreePixelInternalRep(
if (!SIMPLE_PIXELREP(objPtr)) {
PixelRep *pixelPtr = GET_COMPLEXPIXEL(objPtr);
- ckfree((char *) pixelPtr);
+ ckfree(pixelPtr);
}
SET_SIMPLEPIXEL(objPtr, 0);
objPtr->typePtr = NULL;
@@ -410,7 +408,7 @@ DupPixelInternalRep(
PixelRep *oldPtr, *newPtr;
oldPtr = GET_COMPLEXPIXEL(srcPtr);
- newPtr = (PixelRep *) ckalloc(sizeof(PixelRep));
+ newPtr = ckalloc(sizeof(PixelRep));
newPtr->value = oldPtr->value;
newPtr->units = oldPtr->units;
newPtr->tkwin = oldPtr->tkwin;
@@ -444,7 +442,8 @@ SetPixelFromAny(
Tcl_Obj *objPtr) /* The object to convert. */
{
const Tcl_ObjType *typePtr;
- char *string, *rest;
+ const char *string;
+ char *rest;
double d;
int i, units;
@@ -484,7 +483,7 @@ SetPixelFromAny(
typePtr = objPtr->typePtr;
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
- (*typePtr->freeIntRepProc)(objPtr);
+ typePtr->freeIntRepProc(objPtr);
}
objPtr->typePtr = &pixelObjType;
@@ -493,7 +492,7 @@ SetPixelFromAny(
if ((units < 0) && (i == d)) {
SET_SIMPLEPIXEL(objPtr, i);
} else {
- PixelRep *pixelPtr = (PixelRep *) ckalloc(sizeof(PixelRep));
+ PixelRep *pixelPtr = ckalloc(sizeof(PixelRep));
pixelPtr->value = d;
pixelPtr->units = units;
@@ -505,16 +504,8 @@ SetPixelFromAny(
error:
if (interp != NULL) {
- /*
- * Must copy string before resetting the result in case a caller is
- * trying to convert the interpreter's result to pixels.
- */
-
- char buf[100];
-
- sprintf(buf, "bad screen distance \"%.50s\"", string);
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad screen distance \"%.50s\"", string));
}
return TCL_ERROR;
}
@@ -550,7 +541,7 @@ Tk_GetMMFromObj(
int result;
double d;
MMRep *mmPtr;
- static double bias[] = {
+ static const double bias[] = {
10.0, 25.4, 1.0, 0.35278 /*25.4 / 72.0*/
};
@@ -561,7 +552,7 @@ Tk_GetMMFromObj(
}
}
- mmPtr = (MMRep *) objPtr->internalRep.otherValuePtr;
+ mmPtr = objPtr->internalRep.otherValuePtr;
if (mmPtr->tkwin != tkwin) {
d = mmPtr->value;
if (mmPtr->units == -1) {
@@ -600,7 +591,7 @@ static void
FreeMMInternalRep(
Tcl_Obj *objPtr) /* MM object with internal rep to free. */
{
- ckfree((char *) objPtr->internalRep.otherValuePtr);
+ ckfree(objPtr->internalRep.otherValuePtr);
objPtr->internalRep.otherValuePtr = NULL;
objPtr->typePtr = NULL;
}
@@ -631,13 +622,13 @@ DupMMInternalRep(
MMRep *oldPtr, *newPtr;
copyPtr->typePtr = srcPtr->typePtr;
- oldPtr = (MMRep *) srcPtr->internalRep.otherValuePtr;
- newPtr = (MMRep *) ckalloc(sizeof(MMRep));
+ oldPtr = srcPtr->internalRep.otherValuePtr;
+ newPtr = ckalloc(sizeof(MMRep));
newPtr->value = oldPtr->value;
newPtr->units = oldPtr->units;
newPtr->tkwin = oldPtr->tkwin;
newPtr->returnValue = oldPtr->returnValue;
- copyPtr->internalRep.otherValuePtr = (VOID *) newPtr;
+ copyPtr->internalRep.otherValuePtr = newPtr;
}
/*
@@ -667,7 +658,7 @@ UpdateStringOfMM(
char buffer[TCL_DOUBLE_SPACE];
register int len;
- mmPtr = (MMRep *) objPtr->internalRep.otherValuePtr;
+ mmPtr = objPtr->internalRep.otherValuePtr;
/* assert( mmPtr->units == -1 && objPtr->bytes == NULL ); */
if ((mmPtr->units != -1) || (objPtr->bytes != NULL)) {
Tcl_Panic("UpdateStringOfMM: false precondition");
@@ -676,7 +667,7 @@ UpdateStringOfMM(
Tcl_PrintDouble(NULL, mmPtr->value, buffer);
len = (int)strlen(buffer);
- objPtr->bytes = (char *) ckalloc((unsigned) len + 1);
+ objPtr->bytes = ckalloc(len + 1);
strcpy(objPtr->bytes, buffer);
objPtr->length = len;
}
@@ -705,17 +696,18 @@ SetMMFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
- ThreadSpecificData *tsdPtr = GetTypeCache();
+ ThreadSpecificData *typeCache = GetTypeCache();
const Tcl_ObjType *typePtr;
- char *string, *rest;
+ const char *string;
+ char *rest;
double d;
int units;
MMRep *mmPtr;
- if (objPtr->typePtr == tsdPtr->doubleTypePtr) {
+ if (objPtr->typePtr == typeCache->doubleTypePtr) {
Tcl_GetDoubleFromObj(interp, objPtr, &d);
units = -1;
- } else if (objPtr->typePtr == tsdPtr->intTypePtr) {
+ } else if (objPtr->typePtr == typeCache->intTypePtr) {
Tcl_GetIntFromObj(interp, objPtr, &units);
d = (double) units;
units = -1;
@@ -777,18 +769,18 @@ SetMMFromAny(
typePtr = objPtr->typePtr;
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
- (*typePtr->freeIntRepProc)(objPtr);
+ typePtr->freeIntRepProc(objPtr);
}
- objPtr->typePtr = &mmObjType;
+ objPtr->typePtr = &mmObjType;
- mmPtr = (MMRep *) ckalloc(sizeof(MMRep));
- mmPtr->value = d;
- mmPtr->units = units;
- mmPtr->tkwin = NULL;
+ mmPtr = ckalloc(sizeof(MMRep));
+ mmPtr->value = d;
+ mmPtr->units = units;
+ mmPtr->tkwin = NULL;
mmPtr->returnValue = d;
- objPtr->internalRep.otherValuePtr = (VOID *) mmPtr;
+ objPtr->internalRep.otherValuePtr = mmPtr;
return TCL_OK;
}
@@ -821,7 +813,7 @@ TkGetWindowFromObj(
Tcl_Obj *objPtr, /* The object from which to get window. */
Tk_Window *windowPtr) /* Place to store resulting window. */
{
- TkMainInfo *mainPtr = ((TkWindow *)tkwin)->mainPtr;
+ TkMainInfo *mainPtr = ((TkWindow *) tkwin)->mainPtr;
register WindowRep *winPtr;
int result;
@@ -830,28 +822,27 @@ TkGetWindowFromObj(
return result;
}
- winPtr = (WindowRep *) objPtr->internalRep.otherValuePtr;
- if ( winPtr->tkwin == NULL
- || winPtr->mainPtr == NULL
- || winPtr->mainPtr != mainPtr
- || winPtr->epoch != mainPtr->deletionEpoch)
- {
+ winPtr = objPtr->internalRep.otherValuePtr;
+ if (winPtr->tkwin == NULL
+ || winPtr->mainPtr == NULL
+ || winPtr->mainPtr != mainPtr
+ || winPtr->epoch != mainPtr->deletionEpoch) {
/*
* Cache is invalid.
*/
winPtr->tkwin = Tk_NameToWindow(interp,
Tcl_GetStringFromObj(objPtr, NULL), tkwin);
+ if (winPtr->tkwin == NULL) {
+ /* ASSERT: Tk_NameToWindow has left error message in interp */
+ return TCL_ERROR;
+ }
+
winPtr->mainPtr = mainPtr;
winPtr->epoch = mainPtr ? mainPtr->deletionEpoch : 0;
}
*windowPtr = winPtr->tkwin;
-
- if (winPtr->tkwin == NULL) {
- /* ASSERT: Tk_NameToWindow has left error message in interp */
- return TCL_ERROR;
- }
return TCL_OK;
}
@@ -890,15 +881,15 @@ SetWindowFromAny(
Tcl_GetStringFromObj(objPtr, NULL);
typePtr = objPtr->typePtr;
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
- (*typePtr->freeIntRepProc)(objPtr);
+ typePtr->freeIntRepProc(objPtr);
}
- winPtr = (WindowRep *) ckalloc(sizeof(WindowRep));
+ winPtr = ckalloc(sizeof(WindowRep));
winPtr->tkwin = NULL;
winPtr->mainPtr = NULL;
winPtr->epoch = 0;
- objPtr->internalRep.otherValuePtr = (VOID*)winPtr;
+ objPtr->internalRep.otherValuePtr = winPtr;
objPtr->typePtr = &windowObjType;
return TCL_OK;
@@ -930,11 +921,11 @@ DupWindowInternalRep(
register WindowRep *oldPtr, *newPtr;
oldPtr = srcPtr->internalRep.otherValuePtr;
- newPtr = (WindowRep *) ckalloc(sizeof(WindowRep));
+ newPtr = ckalloc(sizeof(WindowRep));
newPtr->tkwin = oldPtr->tkwin;
newPtr->mainPtr = oldPtr->mainPtr;
newPtr->epoch = oldPtr->epoch;
- copyPtr->internalRep.otherValuePtr = (VOID *)newPtr;
+ copyPtr->internalRep.otherValuePtr = newPtr;
copyPtr->typePtr = srcPtr->typePtr;
}
@@ -960,13 +951,47 @@ static void
FreeWindowInternalRep(
Tcl_Obj *objPtr) /* Window object with internal rep to free. */
{
- ckfree((char *) objPtr->internalRep.otherValuePtr);
+ ckfree(objPtr->internalRep.otherValuePtr);
objPtr->internalRep.otherValuePtr = NULL;
objPtr->typePtr = NULL;
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
+ *
+ * TkNewWindowObj --
+ *
+ * This function allocates a new Tcl_Obj that refers to a particular to a
+ * particular Tk window.
+ *
+ * Results:
+ * A standard Tcl object reference, with refcount 0.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Tcl_Obj *
+TkNewWindowObj(
+ Tk_Window tkwin)
+{
+ Tcl_Obj *objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
+ TkMainInfo *mainPtr = ((TkWindow *) tkwin)->mainPtr;
+ register WindowRep *winPtr;
+
+ SetWindowFromAny(NULL, objPtr);
+
+ winPtr = objPtr->internalRep.otherValuePtr;
+ winPtr->tkwin = tkwin;
+ winPtr->mainPtr = mainPtr;
+ winPtr->epoch = mainPtr->deletionEpoch;
+ return objPtr;
+}
+
+/*
+ *----------------------------------------------------------------------
*
* TkParsePadAmount --
*
@@ -984,7 +1009,7 @@ FreeWindowInternalRep(
* An error message is written to the interpreter if something is not
* right.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
int
@@ -1006,7 +1031,7 @@ TkParsePadAmount(
*/
if (specObj->typePtr == &pixelObjType) {
- if (Tk_GetPixelsFromObj(interp, tkwin, specObj, &firstInt) != TCL_OK) {
+ if (Tk_GetPixelsFromObj(interp, tkwin, specObj, &firstInt) != TCL_OK){
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "bad pad value \"",
Tcl_GetString(specObj),
@@ -1097,7 +1122,6 @@ TkRegisterObjTypes(void)
Tcl_RegisterObjType(&tkCursorObjType);
Tcl_RegisterObjType(&tkFontObjType);
Tcl_RegisterObjType(&mmObjType);
- Tcl_RegisterObjType(&tkOptionObjType);
Tcl_RegisterObjType(&pixelObjType);
Tcl_RegisterObjType(&tkStateKeyObjType);
Tcl_RegisterObjType(&windowObjType);