| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <tclInt.h> |
| 17 |
#include "tixInt.h" |
| 18 |
#include "tixItcl.h" |
| 19 |
|
| 20 |
static int ParseOptions _ANSI_ARGS_(( |
| 21 |
Tcl_Interp * interp,TixClassRecord * cPtr, |
| 22 |
char *widRec, int argc, char** argv)); |
| 23 |
|
| 24 |
TIX_DECLARE_CMD(Tix_InstanceCmd); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
TIX_DEFINE_CMD(Tix_CreateWidgetCmd) |
| 36 |
{ |
| 37 |
TixClassRecord * cPtr =(TixClassRecord *)clientData; |
| 38 |
TixConfigSpec * spec; |
| 39 |
char * widRec = NULL; |
| 40 |
char * rootCmd = NULL; |
| 41 |
char * value; |
| 42 |
int i; |
| 43 |
int code = TCL_OK; |
| 44 |
Tk_Window mainWin = Tk_MainWindow(interp); |
| 45 |
Tcl_DString ds; |
| 46 |
|
| 47 |
DECLARE_ITCL_NAMESP(nameSp, interp); |
| 48 |
|
| 49 |
if (argc <= 1) { |
| 50 |
return Tix_ArgcError(interp, argc, argv, 1, "pathname ?arg? ..."); |
| 51 |
} else { |
| 52 |
widRec = argv[1]; |
| 53 |
} |
| 54 |
|
| 55 |
if (Tk_NameToWindow(interp, widRec, mainWin) != NULL) { |
| 56 |
Tcl_ResetResult(interp); |
| 57 |
Tcl_AppendResult(interp, "window name \"", widRec, |
| 58 |
"\" already exists", NULL); |
| 59 |
return TCL_ERROR; |
| 60 |
} else { |
| 61 |
Tcl_ResetResult(interp); |
| 62 |
} |
| 63 |
|
| 64 |
if (!TixItclSetGlobalNameSp(&nameSp, interp)) { |
| 65 |
code = TCL_ERROR; |
| 66 |
goto done; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
Tcl_SetVar2(interp, "errorInfo", NULL, "", TCL_GLOBAL_ONLY); |
| 74 |
Tcl_SetVar2(interp, "errorCode", NULL, "", TCL_GLOBAL_ONLY); |
| 75 |
Tcl_ResetResult(interp); |
| 76 |
|
| 77 |
|
| 78 |
rootCmd = ckalloc(strlen(widRec)+10); |
| 79 |
sprintf(rootCmd, "%s:root", widRec); |
| 80 |
Tcl_SetVar2(interp, widRec, "className", cPtr->className, TCL_GLOBAL_ONLY); |
| 81 |
Tcl_SetVar2(interp, widRec, "ClassName", cPtr->ClassName, TCL_GLOBAL_ONLY); |
| 82 |
Tcl_SetVar2(interp, widRec, "context", cPtr->className, TCL_GLOBAL_ONLY); |
| 83 |
Tcl_SetVar2(interp, widRec, "w:root", widRec, TCL_GLOBAL_ONLY); |
| 84 |
Tcl_SetVar2(interp, widRec, "rootCmd", rootCmd, TCL_GLOBAL_ONLY); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
if (Tix_CallMethod(interp, cPtr->className, widRec, "CreateRootWidget", |
| 90 |
argc-2, argv+2) != TCL_OK) { |
| 91 |
code = TCL_ERROR; |
| 92 |
goto done; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
Tcl_ResetResult(interp); |
| 99 |
if (ParseOptions(interp, cPtr, widRec, argc-2, argv+2) != TCL_OK) { |
| 100 |
code = TCL_ERROR; |
| 101 |
goto done; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
Tcl_DStringInit(&ds); |
| 109 |
Tcl_DStringAppendElement(&ds, "rename"); |
| 110 |
Tcl_DStringAppendElement(&ds, widRec); |
| 111 |
Tcl_DStringAppendElement(&ds, rootCmd); |
| 112 |
|
| 113 |
if (Tcl_Eval(interp, ds.string) != TCL_OK) { |
| 114 |
Tcl_DStringFree(&ds); |
| 115 |
code = TCL_ERROR; |
| 116 |
goto done; |
| 117 |
} else { |
| 118 |
Tcl_DStringFree(&ds); |
| 119 |
} |
| 120 |
|
| 121 |
Tcl_CreateCommand(interp, widRec, Tix_InstanceCmd, |
| 122 |
(ClientData)cPtr, NULL); |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
if (Tix_CallMethod(interp, cPtr->className, widRec, "InitWidgetRec", |
| 127 |
0, 0) != TCL_OK) { |
| 128 |
code = TCL_ERROR; |
| 129 |
goto done; |
| 130 |
} |
| 131 |
|
| 132 |
if (Tix_CallMethod(interp, cPtr->className, widRec, "ConstructWidget", |
| 133 |
0, 0) != TCL_OK) { |
| 134 |
code = TCL_ERROR; |
| 135 |
goto done; |
| 136 |
} |
| 137 |
|
| 138 |
if (Tix_CallMethod(interp, cPtr->className, widRec, "SetBindings", |
| 139 |
0, 0) != TCL_OK) { |
| 140 |
code = TCL_ERROR; |
| 141 |
goto done; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
for (i=0; i<cPtr->nSpecs; i++) { |
| 148 |
spec = cPtr->specs[i]; |
| 149 |
if (spec->forceCall) { |
| 150 |
value = Tcl_GetVar2(interp, widRec, spec->argvName, |
| 151 |
TCL_GLOBAL_ONLY); |
| 152 |
if (Tix_CallConfigMethod(interp, cPtr, widRec, spec, |
| 153 |
value)!=TCL_OK){ |
| 154 |
code = TCL_ERROR; |
| 155 |
goto done; |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
Tcl_SetResult(interp, widRec, TCL_VOLATILE); |
| 161 |
|
| 162 |
done: |
| 163 |
|
| 164 |
if (code != TCL_OK) { |
| 165 |
|
| 166 |
Interp *iPtr = (Interp *) interp; |
| 167 |
char * oldResult, * oldErrorInfo, * oldErrorCode; |
| 168 |
Tk_Window topLevel, tkwin; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
if (interp->result) { |
| 175 |
oldResult = tixStrDup(interp->result); |
| 176 |
#if 0 |
| 177 |
printf("%s -->\n%s\n", widRec, oldResult); |
| 178 |
#endif |
| 179 |
} else { |
| 180 |
oldResult = NULL; |
| 181 |
} |
| 182 |
oldErrorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY); |
| 183 |
oldErrorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY); |
| 184 |
|
| 185 |
Tcl_ResetResult(interp); |
| 186 |
|
| 187 |
|
| 188 |
topLevel = cPtr->mainWindow; |
| 189 |
|
| 190 |
if (widRec != NULL) { |
| 191 |
Display *display = NULL; |
| 192 |
|
| 193 |
tkwin = Tk_NameToWindow(interp, widRec, topLevel); |
| 194 |
if (tkwin != NULL) { |
| 195 |
display = Tk_Display(tkwin); |
| 196 |
Tk_DestroyWindow(tkwin); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
Tcl_DeleteCommand(interp, widRec); |
| 201 |
Tcl_DeleteCommand(interp, rootCmd); |
| 202 |
|
| 203 |
|
| 204 |
Tcl_UnsetVar(interp, widRec, TCL_GLOBAL_ONLY); |
| 205 |
|
| 206 |
if (display) { |
| 207 |
#ifndef _WINDOWS |
| 208 |
XSync(display, False); |
| 209 |
#endif |
| 210 |
while (1) { |
| 211 |
if (Tk_DoOneEvent(TK_X_EVENTS|TK_DONT_WAIT) == 0) { |
| 212 |
break; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
if (oldResult) { |
| 218 |
Tcl_SetResult(interp, oldResult, TCL_DYNAMIC); |
| 219 |
} |
| 220 |
if (oldErrorInfo && *oldErrorInfo) { |
| 221 |
Tcl_SetVar2(interp, "errorInfo", NULL, oldErrorInfo, |
| 222 |
TCL_GLOBAL_ONLY); |
| 223 |
} else { |
| 224 |
Tcl_SetVar2(interp, "errorInfo", NULL, oldResult, |
| 225 |
TCL_GLOBAL_ONLY); |
| 226 |
} |
| 227 |
if (oldErrorCode) { |
| 228 |
Tcl_SetVar2(interp, "errorCode", NULL, oldErrorCode, |
| 229 |
TCL_GLOBAL_ONLY); |
| 230 |
} |
| 231 |
iPtr->flags |= ERR_IN_PROGRESS; |
| 232 |
} |
| 233 |
if (rootCmd) { |
| 234 |
ckfree(rootCmd); |
| 235 |
} |
| 236 |
|
| 237 |
TixItclRestoreGlobalNameSp(&nameSp, interp); |
| 238 |
|
| 239 |
return code; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
static int ParseOptions(interp, cPtr, widRec, argc, argv) |
| 249 |
Tcl_Interp * interp; |
| 250 |
TixClassRecord * cPtr; |
| 251 |
char *widRec; |
| 252 |
int argc; |
| 253 |
char** argv; |
| 254 |
{ |
| 255 |
int i; |
| 256 |
TixConfigSpec *spec; |
| 257 |
Tk_Window tkwin; |
| 258 |
char * value; |
| 259 |
|
| 260 |
if ((argc %2) != 0) { |
| 261 |
Tcl_AppendResult(interp, "missing argument for \"", argv[argc-1], |
| 262 |
"\"", NULL); |
| 263 |
return TCL_ERROR; |
| 264 |
} |
| 265 |
|
| 266 |
if ((tkwin = Tk_NameToWindow(interp, widRec, cPtr->mainWindow)) == NULL) { |
| 267 |
return TCL_ERROR; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
for (i=0; i<cPtr->nSpecs; i++) { |
| 272 |
spec = cPtr->specs[i]; |
| 273 |
|
| 274 |
if (!spec->isAlias) { |
| 275 |
if ((value=Tk_GetOption(tkwin,spec->dbName,spec->dbClass))==NULL) { |
| 276 |
value = spec->defValue; |
| 277 |
} |
| 278 |
if (Tix_ChangeOneOption(interp, cPtr, widRec, spec, |
| 279 |
value, 1, 0)!=TCL_OK) { |
| 280 |
return TCL_ERROR; |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
for (i=0; i<argc; i+=2) { |
| 287 |
spec = Tix_FindConfigSpecByName(interp, cPtr, argv[i]); |
| 288 |
|
| 289 |
if (spec == NULL) { |
| 290 |
return TCL_ERROR; |
| 291 |
} |
| 292 |
|
| 293 |
if (Tix_ChangeOneOption(interp, cPtr, widRec, spec, |
| 294 |
argv[i+1], 0, 1)!=TCL_OK) { |
| 295 |
return TCL_ERROR; |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
return TCL_OK; |
| 300 |
} |