| 1 |
578 |
markom |
/*
|
| 2 |
|
|
* tkTest.c --
|
| 3 |
|
|
*
|
| 4 |
|
|
* This file contains C command procedures for a bunch of additional
|
| 5 |
|
|
* Tcl commands that are used for testing out Tcl's C interfaces.
|
| 6 |
|
|
* These commands are not normally included in Tcl applications;
|
| 7 |
|
|
* they're only used for testing.
|
| 8 |
|
|
*
|
| 9 |
|
|
* Copyright (c) 1993-1994 The Regents of the University of California.
|
| 10 |
|
|
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
|
| 11 |
|
|
*
|
| 12 |
|
|
* See the file "license.terms" for information on usage and redistribution
|
| 13 |
|
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
| 14 |
|
|
*
|
| 15 |
|
|
* RCS: @(#) $Id: tkTest.c,v 1.1.1.1 2002-01-16 10:25:52 markom Exp $
|
| 16 |
|
|
*/
|
| 17 |
|
|
|
| 18 |
|
|
#include "tkInt.h"
|
| 19 |
|
|
#include "tkPort.h"
|
| 20 |
|
|
|
| 21 |
|
|
#ifdef __WIN32__
|
| 22 |
|
|
#include "tkWinInt.h"
|
| 23 |
|
|
#endif
|
| 24 |
|
|
|
| 25 |
|
|
#ifdef MAC_TCL
|
| 26 |
|
|
#include "tkScrollbar.h"
|
| 27 |
|
|
#endif
|
| 28 |
|
|
|
| 29 |
|
|
#ifdef __UNIX__
|
| 30 |
|
|
#include "tkUnixInt.h"
|
| 31 |
|
|
#endif
|
| 32 |
|
|
|
| 33 |
|
|
/*
|
| 34 |
|
|
* The following data structure represents the master for a test
|
| 35 |
|
|
* image:
|
| 36 |
|
|
*/
|
| 37 |
|
|
|
| 38 |
|
|
typedef struct TImageMaster {
|
| 39 |
|
|
Tk_ImageMaster master; /* Tk's token for image master. */
|
| 40 |
|
|
Tcl_Interp *interp; /* Interpreter for application. */
|
| 41 |
|
|
int width, height; /* Dimensions of image. */
|
| 42 |
|
|
char *imageName; /* Name of image (malloc-ed). */
|
| 43 |
|
|
char *varName; /* Name of variable in which to log
|
| 44 |
|
|
* events for image (malloc-ed). */
|
| 45 |
|
|
} TImageMaster;
|
| 46 |
|
|
|
| 47 |
|
|
/*
|
| 48 |
|
|
* The following data structure represents a particular use of a
|
| 49 |
|
|
* particular test image.
|
| 50 |
|
|
*/
|
| 51 |
|
|
|
| 52 |
|
|
typedef struct TImageInstance {
|
| 53 |
|
|
TImageMaster *masterPtr; /* Pointer to master for image. */
|
| 54 |
|
|
XColor *fg; /* Foreground color for drawing in image. */
|
| 55 |
|
|
GC gc; /* Graphics context for drawing in image. */
|
| 56 |
|
|
} TImageInstance;
|
| 57 |
|
|
|
| 58 |
|
|
/*
|
| 59 |
|
|
* The type record for test images:
|
| 60 |
|
|
*/
|
| 61 |
|
|
|
| 62 |
|
|
static int ImageCreate _ANSI_ARGS_((Tcl_Interp *interp,
|
| 63 |
|
|
char *name, int argc, Tcl_Obj *CONST objv[],
|
| 64 |
|
|
Tk_ImageType *typePtr, Tk_ImageMaster master,
|
| 65 |
|
|
ClientData *clientDataPtr));
|
| 66 |
|
|
static ClientData ImageGet _ANSI_ARGS_((Tk_Window tkwin,
|
| 67 |
|
|
ClientData clientData));
|
| 68 |
|
|
static void ImageDisplay _ANSI_ARGS_((ClientData clientData,
|
| 69 |
|
|
Display *display, Drawable drawable,
|
| 70 |
|
|
int imageX, int imageY, int width,
|
| 71 |
|
|
int height, int drawableX,
|
| 72 |
|
|
int drawableY));
|
| 73 |
|
|
static void ImageFree _ANSI_ARGS_((ClientData clientData,
|
| 74 |
|
|
Display *display));
|
| 75 |
|
|
static void ImageDelete _ANSI_ARGS_((ClientData clientData));
|
| 76 |
|
|
|
| 77 |
|
|
static Tk_ImageType imageType = {
|
| 78 |
|
|
"test", /* name */
|
| 79 |
|
|
ImageCreate, /* createProc */
|
| 80 |
|
|
ImageGet, /* getProc */
|
| 81 |
|
|
ImageDisplay, /* displayProc */
|
| 82 |
|
|
ImageFree, /* freeProc */
|
| 83 |
|
|
ImageDelete, /* deleteProc */
|
| 84 |
|
|
(Tk_ImageType *) NULL /* nextPtr */
|
| 85 |
|
|
};
|
| 86 |
|
|
|
| 87 |
|
|
/*
|
| 88 |
|
|
* One of the following structures describes each of the interpreters
|
| 89 |
|
|
* created by the "testnewapp" command. This information is used by
|
| 90 |
|
|
* the "testdeleteinterps" command to destroy all of those interpreters.
|
| 91 |
|
|
*/
|
| 92 |
|
|
|
| 93 |
|
|
typedef struct NewApp {
|
| 94 |
|
|
Tcl_Interp *interp; /* Token for interpreter. */
|
| 95 |
|
|
struct NewApp *nextPtr; /* Next in list of new interpreters. */
|
| 96 |
|
|
} NewApp;
|
| 97 |
|
|
|
| 98 |
|
|
static NewApp *newAppPtr = NULL;
|
| 99 |
|
|
/* First in list of all new interpreters. */
|
| 100 |
|
|
|
| 101 |
|
|
/*
|
| 102 |
|
|
* Declaration for the square widget's class command procedure:
|
| 103 |
|
|
*/
|
| 104 |
|
|
|
| 105 |
|
|
extern int SquareCmd _ANSI_ARGS_((ClientData clientData,
|
| 106 |
|
|
Tcl_Interp *interp, int argc, char *argv[]));
|
| 107 |
|
|
|
| 108 |
|
|
typedef struct CBinding {
|
| 109 |
|
|
Tcl_Interp *interp;
|
| 110 |
|
|
char *command;
|
| 111 |
|
|
char *delete;
|
| 112 |
|
|
} CBinding;
|
| 113 |
|
|
|
| 114 |
|
|
/*
|
| 115 |
|
|
* Forward declarations for procedures defined later in this file:
|
| 116 |
|
|
*/
|
| 117 |
|
|
|
| 118 |
|
|
static int CBindingEvalProc _ANSI_ARGS_((ClientData clientData,
|
| 119 |
|
|
Tcl_Interp *interp, XEvent *eventPtr,
|
| 120 |
|
|
Tk_Window tkwin, KeySym keySym));
|
| 121 |
|
|
static void CBindingFreeProc _ANSI_ARGS_((ClientData clientData));
|
| 122 |
|
|
int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
|
| 123 |
|
|
static int ImageCmd _ANSI_ARGS_((ClientData dummy,
|
| 124 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 125 |
|
|
static int TestcbindCmd _ANSI_ARGS_((ClientData dummy,
|
| 126 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 127 |
|
|
#ifdef __WIN32__
|
| 128 |
|
|
static int TestclipboardCmd _ANSI_ARGS_((ClientData dummy,
|
| 129 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 130 |
|
|
#endif
|
| 131 |
|
|
static int TestdeleteappsCmd _ANSI_ARGS_((ClientData dummy,
|
| 132 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 133 |
|
|
static int TestmakeexistCmd _ANSI_ARGS_((ClientData dummy,
|
| 134 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 135 |
|
|
static int TestmenubarCmd _ANSI_ARGS_((ClientData dummy,
|
| 136 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 137 |
|
|
#if defined(__WIN32__) || defined(MAC_TCL)
|
| 138 |
|
|
static int TestmetricsCmd _ANSI_ARGS_((ClientData dummy,
|
| 139 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 140 |
|
|
#endif
|
| 141 |
|
|
static int TestsendCmd _ANSI_ARGS_((ClientData dummy,
|
| 142 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 143 |
|
|
static int TestpropCmd _ANSI_ARGS_((ClientData dummy,
|
| 144 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 145 |
|
|
#if !(defined(__WIN32__) || defined(MAC_TCL))
|
| 146 |
|
|
static int TestwrapperCmd _ANSI_ARGS_((ClientData dummy,
|
| 147 |
|
|
Tcl_Interp *interp, int argc, char **argv));
|
| 148 |
|
|
#endif
|
| 149 |
|
|
|
| 150 |
|
|
/*
|
| 151 |
|
|
* External (platform specific) initialization routine:
|
| 152 |
|
|
*/
|
| 153 |
|
|
|
| 154 |
|
|
EXTERN int TkplatformtestInit _ANSI_ARGS_((
|
| 155 |
|
|
Tcl_Interp *interp));
|
| 156 |
|
|
#ifndef MAC_TCL
|
| 157 |
|
|
#define TkplatformtestInit(x) TCL_OK
|
| 158 |
|
|
#endif
|
| 159 |
|
|
|
| 160 |
|
|
/*
|
| 161 |
|
|
*----------------------------------------------------------------------
|
| 162 |
|
|
*
|
| 163 |
|
|
* Tktest_Init --
|
| 164 |
|
|
*
|
| 165 |
|
|
* This procedure performs intialization for the Tk test
|
| 166 |
|
|
* suite exensions.
|
| 167 |
|
|
*
|
| 168 |
|
|
* Results:
|
| 169 |
|
|
* Returns a standard Tcl completion code, and leaves an error
|
| 170 |
|
|
* message in interp->result if an error occurs.
|
| 171 |
|
|
*
|
| 172 |
|
|
* Side effects:
|
| 173 |
|
|
* Creates several test commands.
|
| 174 |
|
|
*
|
| 175 |
|
|
*----------------------------------------------------------------------
|
| 176 |
|
|
*/
|
| 177 |
|
|
|
| 178 |
|
|
int
|
| 179 |
|
|
Tktest_Init(interp)
|
| 180 |
|
|
Tcl_Interp *interp; /* Interpreter for application. */
|
| 181 |
|
|
{
|
| 182 |
|
|
static int initialized = 0;
|
| 183 |
|
|
|
| 184 |
|
|
/*
|
| 185 |
|
|
* Create additional commands for testing Tk.
|
| 186 |
|
|
*/
|
| 187 |
|
|
|
| 188 |
|
|
if (Tcl_PkgProvide(interp, "Tktest", TK_VERSION) == TCL_ERROR) {
|
| 189 |
|
|
return TCL_ERROR;
|
| 190 |
|
|
}
|
| 191 |
|
|
|
| 192 |
|
|
Tcl_CreateCommand(interp, "square", SquareCmd,
|
| 193 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 194 |
|
|
#ifdef __WIN32__
|
| 195 |
|
|
Tcl_CreateCommand(interp, "testclipboard", TestclipboardCmd,
|
| 196 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 197 |
|
|
#endif
|
| 198 |
|
|
Tcl_CreateCommand(interp, "testcbind", TestcbindCmd,
|
| 199 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 200 |
|
|
Tcl_CreateCommand(interp, "testdeleteapps", TestdeleteappsCmd,
|
| 201 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 202 |
|
|
Tcl_CreateCommand(interp, "testembed", TkpTestembedCmd,
|
| 203 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 204 |
|
|
Tcl_CreateCommand(interp, "testmakeexist", TestmakeexistCmd,
|
| 205 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 206 |
|
|
Tcl_CreateCommand(interp, "testmenubar", TestmenubarCmd,
|
| 207 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 208 |
|
|
#if defined(__WIN32__) || defined(MAC_TCL)
|
| 209 |
|
|
Tcl_CreateCommand(interp, "testmetrics", TestmetricsCmd,
|
| 210 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 211 |
|
|
#endif
|
| 212 |
|
|
Tcl_CreateCommand(interp, "testprop", TestpropCmd,
|
| 213 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 214 |
|
|
Tcl_CreateCommand(interp, "testsend", TestsendCmd,
|
| 215 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 216 |
|
|
#if !(defined(__WIN32__) || defined(MAC_TCL))
|
| 217 |
|
|
Tcl_CreateCommand(interp, "testwrapper", TestwrapperCmd,
|
| 218 |
|
|
(ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
|
| 219 |
|
|
#endif
|
| 220 |
|
|
|
| 221 |
|
|
/*
|
| 222 |
|
|
* Create test image type.
|
| 223 |
|
|
*/
|
| 224 |
|
|
|
| 225 |
|
|
if (!initialized) {
|
| 226 |
|
|
initialized = 1;
|
| 227 |
|
|
Tk_CreateImageType(&imageType);
|
| 228 |
|
|
}
|
| 229 |
|
|
|
| 230 |
|
|
/*
|
| 231 |
|
|
* And finally add any platform specific test commands.
|
| 232 |
|
|
*/
|
| 233 |
|
|
|
| 234 |
|
|
return TkplatformtestInit(interp);
|
| 235 |
|
|
}
|
| 236 |
|
|
|
| 237 |
|
|
/*
|
| 238 |
|
|
*----------------------------------------------------------------------
|
| 239 |
|
|
*
|
| 240 |
|
|
* TestclipboardCmd --
|
| 241 |
|
|
*
|
| 242 |
|
|
* This procedure implements the testclipboard command. It provides
|
| 243 |
|
|
* a way to determine the actual contents of the Windows clipboard.
|
| 244 |
|
|
*
|
| 245 |
|
|
* Results:
|
| 246 |
|
|
* A standard Tcl result.
|
| 247 |
|
|
*
|
| 248 |
|
|
* Side effects:
|
| 249 |
|
|
* None.
|
| 250 |
|
|
*
|
| 251 |
|
|
*----------------------------------------------------------------------
|
| 252 |
|
|
*/
|
| 253 |
|
|
|
| 254 |
|
|
#ifdef __WIN32__
|
| 255 |
|
|
static int
|
| 256 |
|
|
TestclipboardCmd(clientData, interp, argc, argv)
|
| 257 |
|
|
ClientData clientData; /* Main window for application. */
|
| 258 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 259 |
|
|
int argc; /* Number of arguments. */
|
| 260 |
|
|
char **argv; /* Argument strings. */
|
| 261 |
|
|
{
|
| 262 |
|
|
TkWindow *winPtr = (TkWindow *) clientData;
|
| 263 |
|
|
HGLOBAL handle;
|
| 264 |
|
|
char *data;
|
| 265 |
|
|
|
| 266 |
|
|
if (OpenClipboard(NULL)) {
|
| 267 |
|
|
handle = GetClipboardData(CF_TEXT);
|
| 268 |
|
|
if (handle != NULL) {
|
| 269 |
|
|
data = GlobalLock(handle);
|
| 270 |
|
|
Tcl_AppendResult(interp, data, (char *) NULL);
|
| 271 |
|
|
GlobalUnlock(handle);
|
| 272 |
|
|
}
|
| 273 |
|
|
CloseClipboard();
|
| 274 |
|
|
}
|
| 275 |
|
|
return TCL_OK;
|
| 276 |
|
|
}
|
| 277 |
|
|
#endif
|
| 278 |
|
|
|
| 279 |
|
|
/*
|
| 280 |
|
|
*----------------------------------------------------------------------
|
| 281 |
|
|
*
|
| 282 |
|
|
* TestcbindCmd --
|
| 283 |
|
|
*
|
| 284 |
|
|
* This procedure implements the "testcbinding" command. It provides
|
| 285 |
|
|
* a set of functions for testing C bindings in tkBind.c.
|
| 286 |
|
|
*
|
| 287 |
|
|
* Results:
|
| 288 |
|
|
* A standard Tcl result.
|
| 289 |
|
|
*
|
| 290 |
|
|
* Side effects:
|
| 291 |
|
|
* Depends on option; see below.
|
| 292 |
|
|
*
|
| 293 |
|
|
*----------------------------------------------------------------------
|
| 294 |
|
|
*/
|
| 295 |
|
|
|
| 296 |
|
|
static int
|
| 297 |
|
|
TestcbindCmd(clientData, interp, argc, argv)
|
| 298 |
|
|
ClientData clientData; /* Main window for application. */
|
| 299 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 300 |
|
|
int argc; /* Number of arguments. */
|
| 301 |
|
|
char **argv; /* Argument strings. */
|
| 302 |
|
|
{
|
| 303 |
|
|
TkWindow *winPtr;
|
| 304 |
|
|
Tk_Window tkwin;
|
| 305 |
|
|
ClientData object;
|
| 306 |
|
|
CBinding *cbindPtr;
|
| 307 |
|
|
|
| 308 |
|
|
|
| 309 |
|
|
if (argc < 4 || argc > 5) {
|
| 310 |
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
| 311 |
|
|
" bindtag pattern command ?deletecommand?", (char *) NULL);
|
| 312 |
|
|
return TCL_ERROR;
|
| 313 |
|
|
}
|
| 314 |
|
|
|
| 315 |
|
|
tkwin = (Tk_Window) clientData;
|
| 316 |
|
|
|
| 317 |
|
|
if (argv[1][0] == '.') {
|
| 318 |
|
|
winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[1], tkwin);
|
| 319 |
|
|
if (winPtr == NULL) {
|
| 320 |
|
|
return TCL_ERROR;
|
| 321 |
|
|
}
|
| 322 |
|
|
object = (ClientData) winPtr->pathName;
|
| 323 |
|
|
} else {
|
| 324 |
|
|
winPtr = (TkWindow *) clientData;
|
| 325 |
|
|
object = (ClientData) Tk_GetUid(argv[1]);
|
| 326 |
|
|
}
|
| 327 |
|
|
|
| 328 |
|
|
if (argv[3][0] == '\0') {
|
| 329 |
|
|
return Tk_DeleteBinding(interp, winPtr->mainPtr->bindingTable,
|
| 330 |
|
|
object, argv[2]);
|
| 331 |
|
|
}
|
| 332 |
|
|
|
| 333 |
|
|
cbindPtr = (CBinding *) ckalloc(sizeof(CBinding));
|
| 334 |
|
|
cbindPtr->interp = interp;
|
| 335 |
|
|
cbindPtr->command =
|
| 336 |
|
|
strcpy((char *) ckalloc(strlen(argv[3]) + 1), argv[3]);
|
| 337 |
|
|
if (argc == 4) {
|
| 338 |
|
|
cbindPtr->delete = NULL;
|
| 339 |
|
|
} else {
|
| 340 |
|
|
cbindPtr->delete =
|
| 341 |
|
|
strcpy((char *) ckalloc(strlen(argv[4]) + 1), argv[4]);
|
| 342 |
|
|
}
|
| 343 |
|
|
|
| 344 |
|
|
if (TkCreateBindingProcedure(interp, winPtr->mainPtr->bindingTable,
|
| 345 |
|
|
object, argv[2], CBindingEvalProc, CBindingFreeProc,
|
| 346 |
|
|
(ClientData) cbindPtr) == 0) {
|
| 347 |
|
|
ckfree((char *) cbindPtr->command);
|
| 348 |
|
|
if (cbindPtr->delete != NULL) {
|
| 349 |
|
|
ckfree((char *) cbindPtr->delete);
|
| 350 |
|
|
}
|
| 351 |
|
|
ckfree((char *) cbindPtr);
|
| 352 |
|
|
return TCL_ERROR;
|
| 353 |
|
|
}
|
| 354 |
|
|
return TCL_OK;
|
| 355 |
|
|
}
|
| 356 |
|
|
|
| 357 |
|
|
static int
|
| 358 |
|
|
CBindingEvalProc(clientData, interp, eventPtr, tkwin, keySym)
|
| 359 |
|
|
ClientData clientData;
|
| 360 |
|
|
Tcl_Interp *interp;
|
| 361 |
|
|
XEvent *eventPtr;
|
| 362 |
|
|
Tk_Window tkwin;
|
| 363 |
|
|
KeySym keySym;
|
| 364 |
|
|
{
|
| 365 |
|
|
CBinding *cbindPtr;
|
| 366 |
|
|
|
| 367 |
|
|
cbindPtr = (CBinding *) clientData;
|
| 368 |
|
|
|
| 369 |
|
|
return Tcl_GlobalEval(interp, cbindPtr->command);
|
| 370 |
|
|
}
|
| 371 |
|
|
|
| 372 |
|
|
static void
|
| 373 |
|
|
CBindingFreeProc(clientData)
|
| 374 |
|
|
ClientData clientData;
|
| 375 |
|
|
{
|
| 376 |
|
|
CBinding *cbindPtr = (CBinding *) clientData;
|
| 377 |
|
|
|
| 378 |
|
|
if (cbindPtr->delete != NULL) {
|
| 379 |
|
|
Tcl_GlobalEval(cbindPtr->interp, cbindPtr->delete);
|
| 380 |
|
|
ckfree((char *) cbindPtr->delete);
|
| 381 |
|
|
}
|
| 382 |
|
|
ckfree((char *) cbindPtr->command);
|
| 383 |
|
|
ckfree((char *) cbindPtr);
|
| 384 |
|
|
}
|
| 385 |
|
|
|
| 386 |
|
|
/*
|
| 387 |
|
|
*----------------------------------------------------------------------
|
| 388 |
|
|
*
|
| 389 |
|
|
* TestdeleteappsCmd --
|
| 390 |
|
|
*
|
| 391 |
|
|
* This procedure implements the "testdeleteapps" command. It cleans
|
| 392 |
|
|
* up all the interpreters left behind by the "testnewapp" command.
|
| 393 |
|
|
*
|
| 394 |
|
|
* Results:
|
| 395 |
|
|
* A standard Tcl result.
|
| 396 |
|
|
*
|
| 397 |
|
|
* Side effects:
|
| 398 |
|
|
* All the intepreters created by previous calls to "testnewapp"
|
| 399 |
|
|
* get deleted.
|
| 400 |
|
|
*
|
| 401 |
|
|
*----------------------------------------------------------------------
|
| 402 |
|
|
*/
|
| 403 |
|
|
|
| 404 |
|
|
/* ARGSUSED */
|
| 405 |
|
|
static int
|
| 406 |
|
|
TestdeleteappsCmd(clientData, interp, argc, argv)
|
| 407 |
|
|
ClientData clientData; /* Main window for application. */
|
| 408 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 409 |
|
|
int argc; /* Number of arguments. */
|
| 410 |
|
|
char **argv; /* Argument strings. */
|
| 411 |
|
|
{
|
| 412 |
|
|
NewApp *nextPtr;
|
| 413 |
|
|
|
| 414 |
|
|
while (newAppPtr != NULL) {
|
| 415 |
|
|
nextPtr = newAppPtr->nextPtr;
|
| 416 |
|
|
Tcl_DeleteInterp(newAppPtr->interp);
|
| 417 |
|
|
ckfree((char *) newAppPtr);
|
| 418 |
|
|
newAppPtr = nextPtr;
|
| 419 |
|
|
}
|
| 420 |
|
|
|
| 421 |
|
|
return TCL_OK;
|
| 422 |
|
|
}
|
| 423 |
|
|
|
| 424 |
|
|
/*
|
| 425 |
|
|
*----------------------------------------------------------------------
|
| 426 |
|
|
*
|
| 427 |
|
|
* ImageCreate --
|
| 428 |
|
|
*
|
| 429 |
|
|
* This procedure is called by the Tk image code to create "test"
|
| 430 |
|
|
* images.
|
| 431 |
|
|
*
|
| 432 |
|
|
* Results:
|
| 433 |
|
|
* A standard Tcl result.
|
| 434 |
|
|
*
|
| 435 |
|
|
* Side effects:
|
| 436 |
|
|
* The data structure for a new image is allocated.
|
| 437 |
|
|
*
|
| 438 |
|
|
*----------------------------------------------------------------------
|
| 439 |
|
|
*/
|
| 440 |
|
|
|
| 441 |
|
|
/* ARGSUSED */
|
| 442 |
|
|
static int
|
| 443 |
|
|
ImageCreate(interp, name, argc, objv, typePtr, master, clientDataPtr)
|
| 444 |
|
|
Tcl_Interp *interp; /* Interpreter for application containing
|
| 445 |
|
|
* image. */
|
| 446 |
|
|
char *name; /* Name to use for image. */
|
| 447 |
|
|
int argc; /* Number of arguments. */
|
| 448 |
|
|
Tcl_Obj *CONST objv[]; /* Argument strings for options (doesn't
|
| 449 |
|
|
* include image name or type). */
|
| 450 |
|
|
Tk_ImageType *typePtr; /* Pointer to our type record (not used). */
|
| 451 |
|
|
Tk_ImageMaster master; /* Token for image, to be used by us in
|
| 452 |
|
|
* later callbacks. */
|
| 453 |
|
|
ClientData *clientDataPtr; /* Store manager's token for image here;
|
| 454 |
|
|
* it will be returned in later callbacks. */
|
| 455 |
|
|
{
|
| 456 |
|
|
TImageMaster *timPtr;
|
| 457 |
|
|
char *varName;
|
| 458 |
|
|
int i;
|
| 459 |
|
|
|
| 460 |
|
|
varName = "log";
|
| 461 |
|
|
for (i = 0; i < argc; i += 2) {
|
| 462 |
|
|
char *arg = Tcl_GetStringFromObj(objv[i], NULL);
|
| 463 |
|
|
if (strcmp(arg, "-variable") != 0) {
|
| 464 |
|
|
Tcl_AppendResult(interp, "bad option name \"", arg,
|
| 465 |
|
|
"\"", (char *) NULL);
|
| 466 |
|
|
return TCL_ERROR;
|
| 467 |
|
|
}
|
| 468 |
|
|
if ((i+1) == argc) {
|
| 469 |
|
|
Tcl_AppendResult(interp, "no value given for \"", arg,
|
| 470 |
|
|
"\" option", (char *) NULL);
|
| 471 |
|
|
return TCL_ERROR;
|
| 472 |
|
|
}
|
| 473 |
|
|
varName = Tcl_GetStringFromObj(objv[i+1], NULL);
|
| 474 |
|
|
}
|
| 475 |
|
|
timPtr = (TImageMaster *) ckalloc(sizeof(TImageMaster));
|
| 476 |
|
|
timPtr->master = master;
|
| 477 |
|
|
timPtr->interp = interp;
|
| 478 |
|
|
timPtr->width = 30;
|
| 479 |
|
|
timPtr->height = 15;
|
| 480 |
|
|
timPtr->imageName = (char *) ckalloc((unsigned) (strlen(name) + 1));
|
| 481 |
|
|
strcpy(timPtr->imageName, name);
|
| 482 |
|
|
timPtr->varName = (char *) ckalloc((unsigned) (strlen(varName) + 1));
|
| 483 |
|
|
strcpy(timPtr->varName, varName);
|
| 484 |
|
|
Tcl_CreateCommand(interp, name, ImageCmd, (ClientData) timPtr,
|
| 485 |
|
|
(Tcl_CmdDeleteProc *) NULL);
|
| 486 |
|
|
*clientDataPtr = (ClientData) timPtr;
|
| 487 |
|
|
Tk_ImageChanged(master, 0, 0, 30, 15, 30, 15);
|
| 488 |
|
|
return TCL_OK;
|
| 489 |
|
|
}
|
| 490 |
|
|
|
| 491 |
|
|
/*
|
| 492 |
|
|
*----------------------------------------------------------------------
|
| 493 |
|
|
*
|
| 494 |
|
|
* ImageCmd --
|
| 495 |
|
|
*
|
| 496 |
|
|
* This procedure implements the commands corresponding to individual
|
| 497 |
|
|
* images.
|
| 498 |
|
|
*
|
| 499 |
|
|
* Results:
|
| 500 |
|
|
* A standard Tcl result.
|
| 501 |
|
|
*
|
| 502 |
|
|
* Side effects:
|
| 503 |
|
|
* Forces windows to be created.
|
| 504 |
|
|
*
|
| 505 |
|
|
*----------------------------------------------------------------------
|
| 506 |
|
|
*/
|
| 507 |
|
|
|
| 508 |
|
|
/* ARGSUSED */
|
| 509 |
|
|
static int
|
| 510 |
|
|
ImageCmd(clientData, interp, argc, argv)
|
| 511 |
|
|
ClientData clientData; /* Main window for application. */
|
| 512 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 513 |
|
|
int argc; /* Number of arguments. */
|
| 514 |
|
|
char **argv; /* Argument strings. */
|
| 515 |
|
|
{
|
| 516 |
|
|
TImageMaster *timPtr = (TImageMaster *) clientData;
|
| 517 |
|
|
int x, y, width, height;
|
| 518 |
|
|
|
| 519 |
|
|
if (argc < 2) {
|
| 520 |
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
| 521 |
|
|
argv[0], "option ?arg arg ...?", (char *) NULL);
|
| 522 |
|
|
return TCL_ERROR;
|
| 523 |
|
|
}
|
| 524 |
|
|
if (strcmp(argv[1], "changed") == 0) {
|
| 525 |
|
|
if (argc != 8) {
|
| 526 |
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
| 527 |
|
|
argv[0], " changed x y width height imageWidth imageHeight",
|
| 528 |
|
|
(char *) NULL);
|
| 529 |
|
|
return TCL_ERROR;
|
| 530 |
|
|
}
|
| 531 |
|
|
if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)
|
| 532 |
|
|
|| (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)
|
| 533 |
|
|
|| (Tcl_GetInt(interp, argv[4], &width) != TCL_OK)
|
| 534 |
|
|
|| (Tcl_GetInt(interp, argv[5], &height) != TCL_OK)
|
| 535 |
|
|
|| (Tcl_GetInt(interp, argv[6], &timPtr->width) != TCL_OK)
|
| 536 |
|
|
|| (Tcl_GetInt(interp, argv[7], &timPtr->height) != TCL_OK)) {
|
| 537 |
|
|
return TCL_ERROR;
|
| 538 |
|
|
}
|
| 539 |
|
|
Tk_ImageChanged(timPtr->master, x, y, width, height, timPtr->width,
|
| 540 |
|
|
timPtr->height);
|
| 541 |
|
|
} else {
|
| 542 |
|
|
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
| 543 |
|
|
"\": must be changed", (char *) NULL);
|
| 544 |
|
|
return TCL_ERROR;
|
| 545 |
|
|
}
|
| 546 |
|
|
return TCL_OK;
|
| 547 |
|
|
}
|
| 548 |
|
|
|
| 549 |
|
|
/*
|
| 550 |
|
|
*----------------------------------------------------------------------
|
| 551 |
|
|
*
|
| 552 |
|
|
* ImageGet --
|
| 553 |
|
|
*
|
| 554 |
|
|
* This procedure is called by Tk to set things up for using a
|
| 555 |
|
|
* test image in a particular widget.
|
| 556 |
|
|
*
|
| 557 |
|
|
* Results:
|
| 558 |
|
|
* The return value is a token for the image instance, which is
|
| 559 |
|
|
* used in future callbacks to ImageDisplay and ImageFree.
|
| 560 |
|
|
*
|
| 561 |
|
|
* Side effects:
|
| 562 |
|
|
* None.
|
| 563 |
|
|
*
|
| 564 |
|
|
*----------------------------------------------------------------------
|
| 565 |
|
|
*/
|
| 566 |
|
|
|
| 567 |
|
|
static ClientData
|
| 568 |
|
|
ImageGet(tkwin, clientData)
|
| 569 |
|
|
Tk_Window tkwin; /* Token for window in which image will
|
| 570 |
|
|
* be used. */
|
| 571 |
|
|
ClientData clientData; /* Pointer to TImageMaster for image. */
|
| 572 |
|
|
{
|
| 573 |
|
|
TImageMaster *timPtr = (TImageMaster *) clientData;
|
| 574 |
|
|
TImageInstance *instPtr;
|
| 575 |
|
|
char buffer[100];
|
| 576 |
|
|
XGCValues gcValues;
|
| 577 |
|
|
|
| 578 |
|
|
sprintf(buffer, "%s get", timPtr->imageName);
|
| 579 |
|
|
Tcl_SetVar(timPtr->interp, timPtr->varName, buffer,
|
| 580 |
|
|
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
|
| 581 |
|
|
|
| 582 |
|
|
instPtr = (TImageInstance *) ckalloc(sizeof(TImageInstance));
|
| 583 |
|
|
instPtr->masterPtr = timPtr;
|
| 584 |
|
|
instPtr->fg = Tk_GetColor(timPtr->interp, tkwin, "#ff0000");
|
| 585 |
|
|
gcValues.foreground = instPtr->fg->pixel;
|
| 586 |
|
|
instPtr->gc = Tk_GetGC(tkwin, GCForeground, &gcValues);
|
| 587 |
|
|
return (ClientData) instPtr;
|
| 588 |
|
|
}
|
| 589 |
|
|
|
| 590 |
|
|
/*
|
| 591 |
|
|
*----------------------------------------------------------------------
|
| 592 |
|
|
*
|
| 593 |
|
|
* ImageDisplay --
|
| 594 |
|
|
*
|
| 595 |
|
|
* This procedure is invoked to redisplay part or all of an
|
| 596 |
|
|
* image in a given drawable.
|
| 597 |
|
|
*
|
| 598 |
|
|
* Results:
|
| 599 |
|
|
* None.
|
| 600 |
|
|
*
|
| 601 |
|
|
* Side effects:
|
| 602 |
|
|
* The image gets partially redrawn, as an "X" that shows the
|
| 603 |
|
|
* exact redraw area.
|
| 604 |
|
|
*
|
| 605 |
|
|
*----------------------------------------------------------------------
|
| 606 |
|
|
*/
|
| 607 |
|
|
|
| 608 |
|
|
static void
|
| 609 |
|
|
ImageDisplay(clientData, display, drawable, imageX, imageY, width, height,
|
| 610 |
|
|
drawableX, drawableY)
|
| 611 |
|
|
ClientData clientData; /* Pointer to TImageInstance for image. */
|
| 612 |
|
|
Display *display; /* Display to use for drawing. */
|
| 613 |
|
|
Drawable drawable; /* Where to redraw image. */
|
| 614 |
|
|
int imageX, imageY; /* Origin of area to redraw, relative to
|
| 615 |
|
|
* origin of image. */
|
| 616 |
|
|
int width, height; /* Dimensions of area to redraw. */
|
| 617 |
|
|
int drawableX, drawableY; /* Coordinates in drawable corresponding to
|
| 618 |
|
|
* imageX and imageY. */
|
| 619 |
|
|
{
|
| 620 |
|
|
TImageInstance *instPtr = (TImageInstance *) clientData;
|
| 621 |
|
|
char buffer[200];
|
| 622 |
|
|
|
| 623 |
|
|
sprintf(buffer, "%s display %d %d %d %d %d %d",
|
| 624 |
|
|
instPtr->masterPtr->imageName, imageX, imageY, width, height,
|
| 625 |
|
|
drawableX, drawableY);
|
| 626 |
|
|
Tcl_SetVar(instPtr->masterPtr->interp, instPtr->masterPtr->varName, buffer,
|
| 627 |
|
|
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
|
| 628 |
|
|
if (width > (instPtr->masterPtr->width - imageX)) {
|
| 629 |
|
|
width = instPtr->masterPtr->width - imageX;
|
| 630 |
|
|
}
|
| 631 |
|
|
if (height > (instPtr->masterPtr->height - imageY)) {
|
| 632 |
|
|
height = instPtr->masterPtr->height - imageY;
|
| 633 |
|
|
}
|
| 634 |
|
|
XDrawRectangle(display, drawable, instPtr->gc, drawableX, drawableY,
|
| 635 |
|
|
(unsigned) (width-1), (unsigned) (height-1));
|
| 636 |
|
|
XDrawLine(display, drawable, instPtr->gc, drawableX, drawableY,
|
| 637 |
|
|
(int) (drawableX + width - 1), (int) (drawableY + height - 1));
|
| 638 |
|
|
XDrawLine(display, drawable, instPtr->gc, drawableX,
|
| 639 |
|
|
(int) (drawableY + height - 1),
|
| 640 |
|
|
(int) (drawableX + width - 1), drawableY);
|
| 641 |
|
|
}
|
| 642 |
|
|
|
| 643 |
|
|
/*
|
| 644 |
|
|
*----------------------------------------------------------------------
|
| 645 |
|
|
*
|
| 646 |
|
|
* ImageFree --
|
| 647 |
|
|
*
|
| 648 |
|
|
* This procedure is called when an instance of an image is
|
| 649 |
|
|
* no longer used.
|
| 650 |
|
|
*
|
| 651 |
|
|
* Results:
|
| 652 |
|
|
* None.
|
| 653 |
|
|
*
|
| 654 |
|
|
* Side effects:
|
| 655 |
|
|
* Information related to the instance is freed.
|
| 656 |
|
|
*
|
| 657 |
|
|
*----------------------------------------------------------------------
|
| 658 |
|
|
*/
|
| 659 |
|
|
|
| 660 |
|
|
static void
|
| 661 |
|
|
ImageFree(clientData, display)
|
| 662 |
|
|
ClientData clientData; /* Pointer to TImageInstance for instance. */
|
| 663 |
|
|
Display *display; /* Display where image was to be drawn. */
|
| 664 |
|
|
{
|
| 665 |
|
|
TImageInstance *instPtr = (TImageInstance *) clientData;
|
| 666 |
|
|
char buffer[200];
|
| 667 |
|
|
|
| 668 |
|
|
sprintf(buffer, "%s free", instPtr->masterPtr->imageName);
|
| 669 |
|
|
Tcl_SetVar(instPtr->masterPtr->interp, instPtr->masterPtr->varName, buffer,
|
| 670 |
|
|
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
|
| 671 |
|
|
Tk_FreeColor(instPtr->fg);
|
| 672 |
|
|
Tk_FreeGC(display, instPtr->gc);
|
| 673 |
|
|
ckfree((char *) instPtr);
|
| 674 |
|
|
}
|
| 675 |
|
|
|
| 676 |
|
|
/*
|
| 677 |
|
|
*----------------------------------------------------------------------
|
| 678 |
|
|
*
|
| 679 |
|
|
* ImageDelete --
|
| 680 |
|
|
*
|
| 681 |
|
|
* This procedure is called to clean up a test image when
|
| 682 |
|
|
* an application goes away.
|
| 683 |
|
|
*
|
| 684 |
|
|
* Results:
|
| 685 |
|
|
* None.
|
| 686 |
|
|
*
|
| 687 |
|
|
* Side effects:
|
| 688 |
|
|
* Information about the image is deleted.
|
| 689 |
|
|
*
|
| 690 |
|
|
*----------------------------------------------------------------------
|
| 691 |
|
|
*/
|
| 692 |
|
|
|
| 693 |
|
|
static void
|
| 694 |
|
|
ImageDelete(clientData)
|
| 695 |
|
|
ClientData clientData; /* Pointer to TImageMaster for image. When
|
| 696 |
|
|
* this procedure is called, no more
|
| 697 |
|
|
* instances exist. */
|
| 698 |
|
|
{
|
| 699 |
|
|
TImageMaster *timPtr = (TImageMaster *) clientData;
|
| 700 |
|
|
char buffer[100];
|
| 701 |
|
|
|
| 702 |
|
|
sprintf(buffer, "%s delete", timPtr->imageName);
|
| 703 |
|
|
Tcl_SetVar(timPtr->interp, timPtr->varName, buffer,
|
| 704 |
|
|
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
|
| 705 |
|
|
|
| 706 |
|
|
Tcl_DeleteCommand(timPtr->interp, timPtr->imageName);
|
| 707 |
|
|
ckfree(timPtr->imageName);
|
| 708 |
|
|
ckfree(timPtr->varName);
|
| 709 |
|
|
ckfree((char *) timPtr);
|
| 710 |
|
|
}
|
| 711 |
|
|
|
| 712 |
|
|
/*
|
| 713 |
|
|
*----------------------------------------------------------------------
|
| 714 |
|
|
*
|
| 715 |
|
|
* TestmakeexistCmd --
|
| 716 |
|
|
*
|
| 717 |
|
|
* This procedure implements the "testmakeexist" command. It calls
|
| 718 |
|
|
* Tk_MakeWindowExist on each of its arguments to force the windows
|
| 719 |
|
|
* to be created.
|
| 720 |
|
|
*
|
| 721 |
|
|
* Results:
|
| 722 |
|
|
* A standard Tcl result.
|
| 723 |
|
|
*
|
| 724 |
|
|
* Side effects:
|
| 725 |
|
|
* Forces windows to be created.
|
| 726 |
|
|
*
|
| 727 |
|
|
*----------------------------------------------------------------------
|
| 728 |
|
|
*/
|
| 729 |
|
|
|
| 730 |
|
|
/* ARGSUSED */
|
| 731 |
|
|
static int
|
| 732 |
|
|
TestmakeexistCmd(clientData, interp, argc, argv)
|
| 733 |
|
|
ClientData clientData; /* Main window for application. */
|
| 734 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 735 |
|
|
int argc; /* Number of arguments. */
|
| 736 |
|
|
char **argv; /* Argument strings. */
|
| 737 |
|
|
{
|
| 738 |
|
|
Tk_Window mainwin = (Tk_Window) clientData;
|
| 739 |
|
|
int i;
|
| 740 |
|
|
Tk_Window tkwin;
|
| 741 |
|
|
|
| 742 |
|
|
for (i = 1; i < argc; i++) {
|
| 743 |
|
|
tkwin = Tk_NameToWindow(interp, argv[i], mainwin);
|
| 744 |
|
|
if (tkwin == NULL) {
|
| 745 |
|
|
return TCL_ERROR;
|
| 746 |
|
|
}
|
| 747 |
|
|
Tk_MakeWindowExist(tkwin);
|
| 748 |
|
|
}
|
| 749 |
|
|
|
| 750 |
|
|
return TCL_OK;
|
| 751 |
|
|
}
|
| 752 |
|
|
|
| 753 |
|
|
/*
|
| 754 |
|
|
*----------------------------------------------------------------------
|
| 755 |
|
|
*
|
| 756 |
|
|
* TestmenubarCmd --
|
| 757 |
|
|
*
|
| 758 |
|
|
* This procedure implements the "testmenubar" command. It is used
|
| 759 |
|
|
* to test the Unix facilities for creating space above a toplevel
|
| 760 |
|
|
* window for a menubar.
|
| 761 |
|
|
*
|
| 762 |
|
|
* Results:
|
| 763 |
|
|
* A standard Tcl result.
|
| 764 |
|
|
*
|
| 765 |
|
|
* Side effects:
|
| 766 |
|
|
* Changes menubar related stuff.
|
| 767 |
|
|
*
|
| 768 |
|
|
*----------------------------------------------------------------------
|
| 769 |
|
|
*/
|
| 770 |
|
|
|
| 771 |
|
|
/* ARGSUSED */
|
| 772 |
|
|
static int
|
| 773 |
|
|
TestmenubarCmd(clientData, interp, argc, argv)
|
| 774 |
|
|
ClientData clientData; /* Main window for application. */
|
| 775 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 776 |
|
|
int argc; /* Number of arguments. */
|
| 777 |
|
|
char **argv; /* Argument strings. */
|
| 778 |
|
|
{
|
| 779 |
|
|
#ifdef __UNIX__
|
| 780 |
|
|
Tk_Window mainwin = (Tk_Window) clientData;
|
| 781 |
|
|
Tk_Window tkwin, menubar;
|
| 782 |
|
|
|
| 783 |
|
|
if (argc < 2) {
|
| 784 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 785 |
|
|
" option ?arg ...?\"", (char *) NULL);
|
| 786 |
|
|
return TCL_ERROR;
|
| 787 |
|
|
}
|
| 788 |
|
|
|
| 789 |
|
|
if (strcmp(argv[1], "window") == 0) {
|
| 790 |
|
|
if (argc != 4) {
|
| 791 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 792 |
|
|
"window toplevel menubar\"", (char *) NULL);
|
| 793 |
|
|
return TCL_ERROR;
|
| 794 |
|
|
}
|
| 795 |
|
|
tkwin = Tk_NameToWindow(interp, argv[2], mainwin);
|
| 796 |
|
|
if (tkwin == NULL) {
|
| 797 |
|
|
return TCL_ERROR;
|
| 798 |
|
|
}
|
| 799 |
|
|
if (argv[3][0] == 0) {
|
| 800 |
|
|
TkUnixSetMenubar(tkwin, NULL);
|
| 801 |
|
|
} else {
|
| 802 |
|
|
menubar = Tk_NameToWindow(interp, argv[3], mainwin);
|
| 803 |
|
|
if (menubar == NULL) {
|
| 804 |
|
|
return TCL_ERROR;
|
| 805 |
|
|
}
|
| 806 |
|
|
TkUnixSetMenubar(tkwin, menubar);
|
| 807 |
|
|
}
|
| 808 |
|
|
} else {
|
| 809 |
|
|
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
| 810 |
|
|
"\": must be window", (char *) NULL);
|
| 811 |
|
|
return TCL_ERROR;
|
| 812 |
|
|
}
|
| 813 |
|
|
|
| 814 |
|
|
return TCL_OK;
|
| 815 |
|
|
#else
|
| 816 |
|
|
interp->result = "testmenubar is supported only under Unix";
|
| 817 |
|
|
return TCL_ERROR;
|
| 818 |
|
|
#endif
|
| 819 |
|
|
}
|
| 820 |
|
|
|
| 821 |
|
|
/*
|
| 822 |
|
|
*----------------------------------------------------------------------
|
| 823 |
|
|
*
|
| 824 |
|
|
* TestmetricsCmd --
|
| 825 |
|
|
*
|
| 826 |
|
|
* This procedure implements the testmetrics command. It provides
|
| 827 |
|
|
* a way to determine the size of various widget components.
|
| 828 |
|
|
*
|
| 829 |
|
|
* Results:
|
| 830 |
|
|
* A standard Tcl result.
|
| 831 |
|
|
*
|
| 832 |
|
|
* Side effects:
|
| 833 |
|
|
* None.
|
| 834 |
|
|
*
|
| 835 |
|
|
*----------------------------------------------------------------------
|
| 836 |
|
|
*/
|
| 837 |
|
|
|
| 838 |
|
|
#ifdef __WIN32__
|
| 839 |
|
|
static int
|
| 840 |
|
|
TestmetricsCmd(clientData, interp, argc, argv)
|
| 841 |
|
|
ClientData clientData; /* Main window for application. */
|
| 842 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 843 |
|
|
int argc; /* Number of arguments. */
|
| 844 |
|
|
char **argv; /* Argument strings. */
|
| 845 |
|
|
{
|
| 846 |
|
|
char buf[200];
|
| 847 |
|
|
|
| 848 |
|
|
if (argc < 2) {
|
| 849 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 850 |
|
|
" option ?arg ...?\"", (char *) NULL);
|
| 851 |
|
|
return TCL_ERROR;
|
| 852 |
|
|
}
|
| 853 |
|
|
|
| 854 |
|
|
if (strcmp(argv[1], "cyvscroll") == 0) {
|
| 855 |
|
|
sprintf(buf, "%d", GetSystemMetrics(SM_CYVSCROLL));
|
| 856 |
|
|
Tcl_AppendResult(interp, buf, (char *) NULL);
|
| 857 |
|
|
} else if (strcmp(argv[1], "cxhscroll") == 0) {
|
| 858 |
|
|
sprintf(buf, "%d", GetSystemMetrics(SM_CXHSCROLL));
|
| 859 |
|
|
Tcl_AppendResult(interp, buf, (char *) NULL);
|
| 860 |
|
|
} else {
|
| 861 |
|
|
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
| 862 |
|
|
"\": must be cxhscroll or cyvscroll", (char *) NULL);
|
| 863 |
|
|
return TCL_ERROR;
|
| 864 |
|
|
}
|
| 865 |
|
|
return TCL_OK;
|
| 866 |
|
|
}
|
| 867 |
|
|
#endif
|
| 868 |
|
|
#ifdef MAC_TCL
|
| 869 |
|
|
static int
|
| 870 |
|
|
TestmetricsCmd(clientData, interp, argc, argv)
|
| 871 |
|
|
ClientData clientData; /* Main window for application. */
|
| 872 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 873 |
|
|
int argc; /* Number of arguments. */
|
| 874 |
|
|
char **argv; /* Argument strings. */
|
| 875 |
|
|
{
|
| 876 |
|
|
Tk_Window tkwin = (Tk_Window) clientData;
|
| 877 |
|
|
TkWindow *winPtr;
|
| 878 |
|
|
char buf[200];
|
| 879 |
|
|
|
| 880 |
|
|
if (argc != 3) {
|
| 881 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 882 |
|
|
" option window\"", (char *) NULL);
|
| 883 |
|
|
return TCL_ERROR;
|
| 884 |
|
|
}
|
| 885 |
|
|
|
| 886 |
|
|
winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[2], tkwin);
|
| 887 |
|
|
if (winPtr == NULL) {
|
| 888 |
|
|
return TCL_ERROR;
|
| 889 |
|
|
}
|
| 890 |
|
|
|
| 891 |
|
|
if (strcmp(argv[1], "cyvscroll") == 0) {
|
| 892 |
|
|
sprintf(buf, "%d", ((TkScrollbar *) winPtr->instanceData)->width);
|
| 893 |
|
|
Tcl_AppendResult(interp, buf, (char *) NULL);
|
| 894 |
|
|
} else if (strcmp(argv[1], "cxhscroll") == 0) {
|
| 895 |
|
|
sprintf(buf, "%d", ((TkScrollbar *) winPtr->instanceData)->width);
|
| 896 |
|
|
Tcl_AppendResult(interp, buf, (char *) NULL);
|
| 897 |
|
|
} else {
|
| 898 |
|
|
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
| 899 |
|
|
"\": must be cxhscroll or cyvscroll", (char *) NULL);
|
| 900 |
|
|
return TCL_ERROR;
|
| 901 |
|
|
}
|
| 902 |
|
|
return TCL_OK;
|
| 903 |
|
|
}
|
| 904 |
|
|
#endif
|
| 905 |
|
|
|
| 906 |
|
|
/*
|
| 907 |
|
|
*----------------------------------------------------------------------
|
| 908 |
|
|
*
|
| 909 |
|
|
* TestpropCmd --
|
| 910 |
|
|
*
|
| 911 |
|
|
* This procedure implements the "testprop" command. It fetches
|
| 912 |
|
|
* and prints the value of a property on a window.
|
| 913 |
|
|
*
|
| 914 |
|
|
* Results:
|
| 915 |
|
|
* A standard Tcl result.
|
| 916 |
|
|
*
|
| 917 |
|
|
* Side effects:
|
| 918 |
|
|
* None.
|
| 919 |
|
|
*
|
| 920 |
|
|
*----------------------------------------------------------------------
|
| 921 |
|
|
*/
|
| 922 |
|
|
|
| 923 |
|
|
/* ARGSUSED */
|
| 924 |
|
|
static int
|
| 925 |
|
|
TestpropCmd(clientData, interp, argc, argv)
|
| 926 |
|
|
ClientData clientData; /* Main window for application. */
|
| 927 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 928 |
|
|
int argc; /* Number of arguments. */
|
| 929 |
|
|
char **argv; /* Argument strings. */
|
| 930 |
|
|
{
|
| 931 |
|
|
Tk_Window mainwin = (Tk_Window) clientData;
|
| 932 |
|
|
int result, actualFormat;
|
| 933 |
|
|
unsigned long bytesAfter, length, value;
|
| 934 |
|
|
Atom actualType, propName;
|
| 935 |
|
|
char *property, *p, *end;
|
| 936 |
|
|
Window w;
|
| 937 |
|
|
char buffer[30];
|
| 938 |
|
|
|
| 939 |
|
|
if (argc != 3) {
|
| 940 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 941 |
|
|
" window property\"", (char *) NULL);
|
| 942 |
|
|
return TCL_ERROR;
|
| 943 |
|
|
}
|
| 944 |
|
|
|
| 945 |
|
|
w = strtoul(argv[1], &end, 0);
|
| 946 |
|
|
propName = Tk_InternAtom(mainwin, argv[2]);
|
| 947 |
|
|
property = NULL;
|
| 948 |
|
|
result = XGetWindowProperty(Tk_Display(mainwin),
|
| 949 |
|
|
w, propName, 0, 100000, False, AnyPropertyType,
|
| 950 |
|
|
&actualType, &actualFormat, &length,
|
| 951 |
|
|
&bytesAfter, (unsigned char **) &property);
|
| 952 |
|
|
if ((result == Success) && (actualType != None)) {
|
| 953 |
|
|
if ((actualFormat == 8) && (actualType == XA_STRING)) {
|
| 954 |
|
|
for (p = property; ((unsigned long)(p-property)) < length; p++) {
|
| 955 |
|
|
if (*p == 0) {
|
| 956 |
|
|
*p = '\n';
|
| 957 |
|
|
}
|
| 958 |
|
|
}
|
| 959 |
|
|
Tcl_SetResult(interp, property, TCL_VOLATILE);
|
| 960 |
|
|
} else {
|
| 961 |
|
|
for (p = property; length > 0; length--) {
|
| 962 |
|
|
if (actualFormat == 32) {
|
| 963 |
|
|
value = *((long *) p);
|
| 964 |
|
|
p += sizeof(long);
|
| 965 |
|
|
} else if (actualFormat == 16) {
|
| 966 |
|
|
value = 0xffff & (*((short *) p));
|
| 967 |
|
|
p += sizeof(short);
|
| 968 |
|
|
} else {
|
| 969 |
|
|
value = 0xff & *p;
|
| 970 |
|
|
p += 1;
|
| 971 |
|
|
}
|
| 972 |
|
|
sprintf(buffer, "0x%lx", value);
|
| 973 |
|
|
Tcl_AppendElement(interp, buffer);
|
| 974 |
|
|
}
|
| 975 |
|
|
}
|
| 976 |
|
|
}
|
| 977 |
|
|
if (property != NULL) {
|
| 978 |
|
|
XFree(property);
|
| 979 |
|
|
}
|
| 980 |
|
|
return TCL_OK;
|
| 981 |
|
|
}
|
| 982 |
|
|
|
| 983 |
|
|
/*
|
| 984 |
|
|
*----------------------------------------------------------------------
|
| 985 |
|
|
*
|
| 986 |
|
|
* TestsendCmd --
|
| 987 |
|
|
*
|
| 988 |
|
|
* This procedure implements the "testsend" command. It provides
|
| 989 |
|
|
* a set of functions for testing the "send" command and support
|
| 990 |
|
|
* procedure in tkSend.c.
|
| 991 |
|
|
*
|
| 992 |
|
|
* Results:
|
| 993 |
|
|
* A standard Tcl result.
|
| 994 |
|
|
*
|
| 995 |
|
|
* Side effects:
|
| 996 |
|
|
* Depends on option; see below.
|
| 997 |
|
|
*
|
| 998 |
|
|
*----------------------------------------------------------------------
|
| 999 |
|
|
*/
|
| 1000 |
|
|
|
| 1001 |
|
|
/* ARGSUSED */
|
| 1002 |
|
|
static int
|
| 1003 |
|
|
TestsendCmd(clientData, interp, argc, argv)
|
| 1004 |
|
|
ClientData clientData; /* Main window for application. */
|
| 1005 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 1006 |
|
|
int argc; /* Number of arguments. */
|
| 1007 |
|
|
char **argv; /* Argument strings. */
|
| 1008 |
|
|
{
|
| 1009 |
|
|
TkWindow *winPtr = (TkWindow *) clientData;
|
| 1010 |
|
|
|
| 1011 |
|
|
if (argc < 2) {
|
| 1012 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 1013 |
|
|
" option ?arg ...?\"", (char *) NULL);
|
| 1014 |
|
|
return TCL_ERROR;
|
| 1015 |
|
|
}
|
| 1016 |
|
|
|
| 1017 |
|
|
#if !(defined(__WIN32__) || defined(MAC_TCL))
|
| 1018 |
|
|
if (strcmp(argv[1], "bogus") == 0) {
|
| 1019 |
|
|
XChangeProperty(winPtr->dispPtr->display,
|
| 1020 |
|
|
RootWindow(winPtr->dispPtr->display, 0),
|
| 1021 |
|
|
winPtr->dispPtr->registryProperty, XA_INTEGER, 32,
|
| 1022 |
|
|
PropModeReplace,
|
| 1023 |
|
|
(unsigned char *) "This is bogus information", 6);
|
| 1024 |
|
|
} else if (strcmp(argv[1], "prop") == 0) {
|
| 1025 |
|
|
int result, actualFormat;
|
| 1026 |
|
|
unsigned long length, bytesAfter;
|
| 1027 |
|
|
Atom actualType, propName;
|
| 1028 |
|
|
char *property, *p, *end;
|
| 1029 |
|
|
Window w;
|
| 1030 |
|
|
|
| 1031 |
|
|
if ((argc != 4) && (argc != 5)) {
|
| 1032 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 1033 |
|
|
" prop window name ?value ?\"", (char *) NULL);
|
| 1034 |
|
|
return TCL_ERROR;
|
| 1035 |
|
|
}
|
| 1036 |
|
|
if (strcmp(argv[2], "root") == 0) {
|
| 1037 |
|
|
w = RootWindow(winPtr->dispPtr->display, 0);
|
| 1038 |
|
|
} else if (strcmp(argv[2], "comm") == 0) {
|
| 1039 |
|
|
w = Tk_WindowId(winPtr->dispPtr->commTkwin);
|
| 1040 |
|
|
} else {
|
| 1041 |
|
|
w = strtoul(argv[2], &end, 0);
|
| 1042 |
|
|
}
|
| 1043 |
|
|
propName = Tk_InternAtom((Tk_Window) winPtr, argv[3]);
|
| 1044 |
|
|
if (argc == 4) {
|
| 1045 |
|
|
property = NULL;
|
| 1046 |
|
|
result = XGetWindowProperty(winPtr->dispPtr->display,
|
| 1047 |
|
|
w, propName, 0, 100000, False, XA_STRING,
|
| 1048 |
|
|
&actualType, &actualFormat, &length,
|
| 1049 |
|
|
&bytesAfter, (unsigned char **) &property);
|
| 1050 |
|
|
if ((result == Success) && (actualType != None)
|
| 1051 |
|
|
&& (actualFormat == 8) && (actualType == XA_STRING)) {
|
| 1052 |
|
|
for (p = property; (p-property) < length; p++) {
|
| 1053 |
|
|
if (*p == 0) {
|
| 1054 |
|
|
*p = '\n';
|
| 1055 |
|
|
}
|
| 1056 |
|
|
}
|
| 1057 |
|
|
Tcl_SetResult(interp, property, TCL_VOLATILE);
|
| 1058 |
|
|
}
|
| 1059 |
|
|
if (property != NULL) {
|
| 1060 |
|
|
XFree(property);
|
| 1061 |
|
|
}
|
| 1062 |
|
|
} else {
|
| 1063 |
|
|
if (argv[4][0] == 0) {
|
| 1064 |
|
|
XDeleteProperty(winPtr->dispPtr->display, w, propName);
|
| 1065 |
|
|
} else {
|
| 1066 |
|
|
for (p = argv[4]; *p != 0; p++) {
|
| 1067 |
|
|
if (*p == '\n') {
|
| 1068 |
|
|
*p = 0;
|
| 1069 |
|
|
}
|
| 1070 |
|
|
}
|
| 1071 |
|
|
XChangeProperty(winPtr->dispPtr->display,
|
| 1072 |
|
|
w, propName, XA_STRING, 8, PropModeReplace,
|
| 1073 |
|
|
(unsigned char *) argv[4], p-argv[4]);
|
| 1074 |
|
|
}
|
| 1075 |
|
|
}
|
| 1076 |
|
|
} else if (strcmp(argv[1], "serial") == 0) {
|
| 1077 |
|
|
sprintf(interp->result, "%d", tkSendSerial+1);
|
| 1078 |
|
|
} else {
|
| 1079 |
|
|
Tcl_AppendResult(interp, "bad option \"", argv[1],
|
| 1080 |
|
|
"\": must be bogus, prop, or serial", (char *) NULL);
|
| 1081 |
|
|
return TCL_ERROR;
|
| 1082 |
|
|
}
|
| 1083 |
|
|
#endif
|
| 1084 |
|
|
return TCL_OK;
|
| 1085 |
|
|
}
|
| 1086 |
|
|
|
| 1087 |
|
|
#if !(defined(__WIN32__) || defined(MAC_TCL))
|
| 1088 |
|
|
/*
|
| 1089 |
|
|
*----------------------------------------------------------------------
|
| 1090 |
|
|
*
|
| 1091 |
|
|
* TestwrapperCmd --
|
| 1092 |
|
|
*
|
| 1093 |
|
|
* This procedure implements the "testwrapper" command. It
|
| 1094 |
|
|
* provides a way from Tcl to determine the extra window Tk adds
|
| 1095 |
|
|
* in between the toplevel window and the window decorations.
|
| 1096 |
|
|
*
|
| 1097 |
|
|
* Results:
|
| 1098 |
|
|
* A standard Tcl result.
|
| 1099 |
|
|
*
|
| 1100 |
|
|
* Side effects:
|
| 1101 |
|
|
* None.
|
| 1102 |
|
|
*
|
| 1103 |
|
|
*----------------------------------------------------------------------
|
| 1104 |
|
|
*/
|
| 1105 |
|
|
|
| 1106 |
|
|
/* ARGSUSED */
|
| 1107 |
|
|
static int
|
| 1108 |
|
|
TestwrapperCmd(clientData, interp, argc, argv)
|
| 1109 |
|
|
ClientData clientData; /* Main window for application. */
|
| 1110 |
|
|
Tcl_Interp *interp; /* Current interpreter. */
|
| 1111 |
|
|
int argc; /* Number of arguments. */
|
| 1112 |
|
|
char **argv; /* Argument strings. */
|
| 1113 |
|
|
{
|
| 1114 |
|
|
TkWindow *winPtr, *wrapperPtr;
|
| 1115 |
|
|
Tk_Window tkwin;
|
| 1116 |
|
|
|
| 1117 |
|
|
if (argc != 2) {
|
| 1118 |
|
|
Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0],
|
| 1119 |
|
|
" window\"", (char *) NULL);
|
| 1120 |
|
|
return TCL_ERROR;
|
| 1121 |
|
|
}
|
| 1122 |
|
|
|
| 1123 |
|
|
tkwin = (Tk_Window) clientData;
|
| 1124 |
|
|
winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[1], tkwin);
|
| 1125 |
|
|
if (winPtr == NULL) {
|
| 1126 |
|
|
return TCL_ERROR;
|
| 1127 |
|
|
}
|
| 1128 |
|
|
|
| 1129 |
|
|
wrapperPtr = TkpGetWrapperWindow(winPtr);
|
| 1130 |
|
|
if (wrapperPtr != NULL) {
|
| 1131 |
|
|
TkpPrintWindowId(interp->result, Tk_WindowId(wrapperPtr));
|
| 1132 |
|
|
}
|
| 1133 |
|
|
return TCL_OK;
|
| 1134 |
|
|
}
|
| 1135 |
|
|
#endif
|