| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkInt.h" |
| 18 |
#include "tixPort.h" |
| 19 |
#include "tixInt.h" |
| 20 |
#include "tkVMacro.h" |
| 21 |
#include "tixDef.h" |
| 22 |
|
| 23 |
#define NUM_TAB_POINTS 6 |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
typedef struct NoteBookFrameStruct { |
| 31 |
Tk_Window tkwin; |
| 32 |
|
| 33 |
|
| 34 |
Display *display; |
| 35 |
Tcl_Interp *interp; |
| 36 |
Tcl_Command widgetCmd; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
int desiredWidth; |
| 42 |
|
| 43 |
int width; |
| 44 |
int height; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
int borderWidth; |
| 53 |
Tk_3DBorder bgBorder; |
| 54 |
Tk_3DBorder focusBorder; |
| 55 |
Tk_3DBorder inActiveBorder; |
| 56 |
XColor * backPageColorPtr; |
| 57 |
GC backPageGC; |
| 58 |
int relief; |
| 59 |
|
| 60 |
int tabPadx; |
| 61 |
int tabPady; |
| 62 |
|
| 63 |
int isSlave; |
| 64 |
|
| 65 |
|
| 66 |
TixFont font; |
| 67 |
XColor *textColorPtr; |
| 68 |
XColor *disabledFg; |
| 69 |
|
| 70 |
|
| 71 |
GC textGC; |
| 72 |
GC focusGC; |
| 73 |
Pixmap gray; |
| 74 |
|
| 75 |
GC disabledGC; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
Cursor cursor; |
| 83 |
|
| 84 |
struct _Tab * tabHead; |
| 85 |
struct _Tab * tabTail; |
| 86 |
struct _Tab * active; |
| 87 |
struct _Tab * focus; |
| 88 |
|
| 89 |
int tabsWidth; |
| 90 |
int tabsHeight; |
| 91 |
|
| 92 |
char *takeFocus; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
unsigned int redrawing : 1; |
| 97 |
unsigned int gotFocus : 1; |
| 98 |
|
| 99 |
} NoteBookFrame; |
| 100 |
|
| 101 |
typedef struct _Tab { |
| 102 |
struct _Tab * next; |
| 103 |
|
| 104 |
NoteBookFrame * wPtr; |
| 105 |
char * name; |
| 106 |
|
| 107 |
Tk_Uid state; |
| 108 |
|
| 109 |
Tk_Anchor anchor; |
| 110 |
|
| 111 |
char * text; |
| 112 |
int width, height; |
| 113 |
int numChars; |
| 114 |
Tk_Justify justify; |
| 115 |
int wrapLength; |
| 116 |
int underline; |
| 117 |
|
| 118 |
|
| 119 |
Tk_Image image; |
| 120 |
char * imageString; |
| 121 |
|
| 122 |
Pixmap bitmap; |
| 123 |
} Tab; |
| 124 |
|
| 125 |
typedef NoteBookFrame WidgetRecord; |
| 126 |
typedef NoteBookFrame * WidgetPtr; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
static Tk_ConfigSpec configSpecs[] = { |
| 132 |
|
| 133 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 134 |
DEF_NOTEBOOKFRAME_BG_COLOR, Tk_Offset(WidgetRecord, bgBorder), |
| 135 |
TK_CONFIG_COLOR_ONLY}, |
| 136 |
|
| 137 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 138 |
DEF_NOTEBOOKFRAME_BG_MONO, Tk_Offset(WidgetRecord, bgBorder), |
| 139 |
TK_CONFIG_MONO_ONLY}, |
| 140 |
|
| 141 |
{TK_CONFIG_COLOR, "-backpagecolor", "backPageColor", "BackPageColor", |
| 142 |
DEF_NOTEBOOKFRAME_BACKPAGE_COLOR, |
| 143 |
Tk_Offset(WidgetRecord, backPageColorPtr), |
| 144 |
TK_CONFIG_COLOR_ONLY}, |
| 145 |
|
| 146 |
{TK_CONFIG_COLOR, "-backpagecolor", "backPageColor", "BackPageColor", |
| 147 |
DEF_NOTEBOOKFRAME_BACKPAGE_MONO, |
| 148 |
Tk_Offset(WidgetRecord, backPageColorPtr), |
| 149 |
TK_CONFIG_MONO_ONLY}, |
| 150 |
|
| 151 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL, |
| 152 |
(char *) NULL, 0, 0}, |
| 153 |
|
| 154 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL, |
| 155 |
(char *) NULL, 0, 0}, |
| 156 |
|
| 157 |
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", |
| 158 |
DEF_NOTEBOOKFRAME_BORDER_WIDTH, Tk_Offset(WidgetRecord, borderWidth), |
| 159 |
0}, |
| 160 |
|
| 161 |
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", |
| 162 |
DEF_NOTEBOOKFRAME_CURSOR, Tk_Offset(WidgetRecord, cursor), |
| 163 |
TK_CONFIG_NULL_OK}, |
| 164 |
|
| 165 |
{TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground", |
| 166 |
"DisabledForeground", DEF_NOTEBOOKFRAME_DISABLED_FG_COLOR, |
| 167 |
Tk_Offset(WidgetRecord, disabledFg), |
| 168 |
TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK}, |
| 169 |
|
| 170 |
{TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground", |
| 171 |
"DisabledForeground", DEF_NOTEBOOKFRAME_DISABLED_FG_MONO, |
| 172 |
Tk_Offset(WidgetRecord, disabledFg), |
| 173 |
TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK}, |
| 174 |
|
| 175 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL, |
| 176 |
(char *) NULL, 0, 0}, |
| 177 |
|
| 178 |
{TK_CONFIG_BORDER, "-focuscolor", "focusColor", "FocusColor", |
| 179 |
DEF_NOTEBOOKFRAME_FOCUS_COLOR, Tk_Offset(WidgetRecord, focusBorder), |
| 180 |
TK_CONFIG_COLOR_ONLY}, |
| 181 |
|
| 182 |
{TK_CONFIG_BORDER, "-focuscolor", "focusColor", "FocusColor", |
| 183 |
DEF_NOTEBOOKFRAME_FOCUS_MONO, Tk_Offset(WidgetRecord, focusBorder), |
| 184 |
TK_CONFIG_MONO_ONLY}, |
| 185 |
|
| 186 |
{TK_CONFIG_FONT, "-font", "font", "Font", |
| 187 |
DEF_NOTEBOOKFRAME_FONT, Tk_Offset(WidgetRecord, font), 0}, |
| 188 |
|
| 189 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 190 |
DEF_NOTEBOOKFRAME_FG_COLOR, Tk_Offset(WidgetRecord, textColorPtr), |
| 191 |
TK_CONFIG_COLOR_ONLY}, |
| 192 |
|
| 193 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 194 |
DEF_NOTEBOOKFRAME_FG_MONO, Tk_Offset(WidgetRecord, textColorPtr), |
| 195 |
TK_CONFIG_MONO_ONLY}, |
| 196 |
|
| 197 |
{TK_CONFIG_BORDER, "-inactivebackground", "inactiveBackground", |
| 198 |
"Background", |
| 199 |
DEF_NOTEBOOKFRAME_INACTIVE_BG_COLOR, |
| 200 |
Tk_Offset(WidgetRecord, inActiveBorder), |
| 201 |
TK_CONFIG_COLOR_ONLY}, |
| 202 |
|
| 203 |
{TK_CONFIG_BORDER, "-inactivebackground", "inactiveBackground", |
| 204 |
"Background", |
| 205 |
DEF_NOTEBOOKFRAME_INACTIVE_BG_MONO, |
| 206 |
Tk_Offset(WidgetRecord, inActiveBorder), |
| 207 |
TK_CONFIG_MONO_ONLY}, |
| 208 |
|
| 209 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 210 |
DEF_NOTEBOOKFRAME_RELIEF, Tk_Offset(WidgetRecord, relief), 0}, |
| 211 |
|
| 212 |
{TK_CONFIG_BOOLEAN, "-slave", "slave", "Slave", |
| 213 |
DEF_NOTEBOOKFRAME_SLAVE, Tk_Offset(WidgetRecord, isSlave), 0}, |
| 214 |
|
| 215 |
{TK_CONFIG_PIXELS, "-tabpadx", "tabPadX", "Pad", |
| 216 |
DEF_NOTEBOOKFRAME_TABPADX, Tk_Offset(WidgetRecord, tabPadx), 0}, |
| 217 |
|
| 218 |
{TK_CONFIG_PIXELS, "-tabpady", "tabPadY", "Pad", |
| 219 |
DEF_NOTEBOOKFRAME_TABPADY, Tk_Offset(WidgetRecord, tabPady), 0}, |
| 220 |
|
| 221 |
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 222 |
DEF_NOTEBOOKFRAME_TAKE_FOCUS, Tk_Offset(WidgetRecord, takeFocus), |
| 223 |
TK_CONFIG_NULL_OK}, |
| 224 |
|
| 225 |
{TK_CONFIG_PIXELS, "-width", "width", "Width", |
| 226 |
DEF_NOTEBOOKFRAME_WIDTH, Tk_Offset(WidgetRecord, desiredWidth), 0}, |
| 227 |
|
| 228 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 229 |
(char *) NULL, 0, 0} |
| 230 |
}; |
| 231 |
|
| 232 |
#define DEF_NBF_TAB_ANCHOR "c" |
| 233 |
#define DEF_NBF_TAB_BITMAP "" |
| 234 |
#define DEF_NBF_TAB_IMAGE "" |
| 235 |
#define DEF_NBF_TAB_JUSTIFY "center" |
| 236 |
#define DEF_NBF_TAB_TEXT "" |
| 237 |
#define DEF_NBF_TAB_STATE "normal" |
| 238 |
#define DEF_NBF_TAB_UNDERLINE "-1" |
| 239 |
#define DEF_NBF_TAB_WRAPLENGTH "0" |
| 240 |
|
| 241 |
static Tk_ConfigSpec tabConfigSpecs[] = { |
| 242 |
{TK_CONFIG_ANCHOR, "-anchor", (char*)NULL, (char*)NULL, |
| 243 |
DEF_NBF_TAB_ANCHOR, Tk_Offset(Tab, anchor), 0}, |
| 244 |
|
| 245 |
{TK_CONFIG_BITMAP, "-bitmap", (char*)NULL, (char*)NULL, |
| 246 |
DEF_NBF_TAB_BITMAP, Tk_Offset(Tab, bitmap), TK_CONFIG_NULL_OK}, |
| 247 |
|
| 248 |
{TK_CONFIG_STRING, "-image", (char*)NULL, (char*)NULL, |
| 249 |
DEF_NBF_TAB_IMAGE, Tk_Offset(Tab, imageString), |
| 250 |
TK_CONFIG_NULL_OK}, |
| 251 |
|
| 252 |
{TK_CONFIG_JUSTIFY, "-justify", (char*)NULL, (char*)NULL, |
| 253 |
DEF_NBF_TAB_JUSTIFY, Tk_Offset(Tab, justify), 0}, |
| 254 |
|
| 255 |
{TK_CONFIG_STRING, "-label", (char*)NULL, (char*)NULL, |
| 256 |
DEF_NBF_TAB_TEXT, Tk_Offset(Tab, text), TK_CONFIG_NULL_OK}, |
| 257 |
|
| 258 |
{TK_CONFIG_UID, "-state", (char*)NULL, (char*)NULL, |
| 259 |
DEF_NBF_TAB_STATE, Tk_Offset(Tab, state), 0}, |
| 260 |
|
| 261 |
{TK_CONFIG_INT, "-underline", (char*)NULL, (char*)NULL, |
| 262 |
DEF_NBF_TAB_UNDERLINE, Tk_Offset(Tab, underline), 0}, |
| 263 |
|
| 264 |
{TK_CONFIG_PIXELS, "-wraplength", (char*)NULL, (char*)NULL, |
| 265 |
DEF_NBF_TAB_WRAPLENGTH, Tk_Offset(Tab, wrapLength), 0}, |
| 266 |
|
| 267 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 268 |
(char *) NULL, 0, 0} |
| 269 |
}; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
static void WidgetCmdDeletedProc _ANSI_ARGS_(( |
| 279 |
ClientData clientData)); |
| 280 |
static int WidgetConfigure _ANSI_ARGS_((Tcl_Interp *interp, |
| 281 |
WidgetPtr wPtr, int argc, char **argv, |
| 282 |
int flags)); |
| 283 |
static int WidgetCommand _ANSI_ARGS_((ClientData clientData, |
| 284 |
Tcl_Interp *, int argc, char **argv)); |
| 285 |
static void WidgetComputeGeometry _ANSI_ARGS_((WidgetPtr wPtr)); |
| 286 |
static void WidgetDestroy _ANSI_ARGS_((char *clientData)); |
| 287 |
static void WidgetDisplay _ANSI_ARGS_((ClientData clientData)); |
| 288 |
static void WidgetEventProc _ANSI_ARGS_((ClientData clientData, |
| 289 |
XEvent *eventPtr)); |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
static int AddTab _ANSI_ARGS_((WidgetPtr wPtr, char * name, |
| 294 |
char ** argv, int argc)); |
| 295 |
static void DeleteTab _ANSI_ARGS_((Tab * tPtr)); |
| 296 |
static void CancelRedrawWhenIdle _ANSI_ARGS_((WidgetPtr wPtr)); |
| 297 |
static void ComputeGeometry _ANSI_ARGS_((WidgetPtr wPtr)); |
| 298 |
static void DrawTab _ANSI_ARGS_((WidgetPtr wPtr, |
| 299 |
Tab * tPtr, int x, int isActive, |
| 300 |
Drawable drawable)); |
| 301 |
static Tab * FindTab _ANSI_ARGS_((Tcl_Interp *interp, |
| 302 |
WidgetPtr wPtr, char * name)); |
| 303 |
static void FocusTab _ANSI_ARGS_((WidgetPtr wPtr, |
| 304 |
Tab * tPtr, int x, Drawable drawable)); |
| 305 |
static void GetTabPoints _ANSI_ARGS_(( |
| 306 |
WidgetPtr wPtr, Tab * tPtr, |
| 307 |
int x, XPoint *points)); |
| 308 |
static void ImageProc _ANSI_ARGS_((ClientData clientData, |
| 309 |
int x, int y, int width, int height, |
| 310 |
int imgWidth, int imgHeight)); |
| 311 |
static void RedrawWhenIdle _ANSI_ARGS_((WidgetPtr wPtr)); |
| 312 |
static int TabConfigure _ANSI_ARGS_((WidgetPtr wPtr, |
| 313 |
Tab *tPtr, char ** argv, int argc)); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
int |
| 333 |
Tix_NoteBookFrameCmd(clientData, interp, argc, argv) |
| 334 |
ClientData clientData; |
| 335 |
|
| 336 |
Tcl_Interp *interp; |
| 337 |
int argc; |
| 338 |
char **argv; |
| 339 |
{ |
| 340 |
Tk_Window mainw = (Tk_Window) clientData; |
| 341 |
WidgetPtr wPtr; |
| 342 |
Tk_Window tkwin; |
| 343 |
|
| 344 |
if (argc < 2) { |
| 345 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 346 |
argv[0], " pathName ?options?\"", (char *) NULL); |
| 347 |
return TCL_ERROR; |
| 348 |
} |
| 349 |
|
| 350 |
tkwin = Tk_CreateWindowFromPath(interp, mainw, argv[1], (char *) NULL); |
| 351 |
if (tkwin == NULL) { |
| 352 |
return TCL_ERROR; |
| 353 |
} |
| 354 |
|
| 355 |
Tk_SetClass(tkwin, "TixNoteBookFrame"); |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
wPtr = (WidgetPtr) ckalloc(sizeof(WidgetRecord)); |
| 361 |
wPtr->tkwin = tkwin; |
| 362 |
wPtr->display = Tk_Display(tkwin); |
| 363 |
wPtr->interp = interp; |
| 364 |
wPtr->isSlave = 1; |
| 365 |
wPtr->desiredWidth = 0; |
| 366 |
wPtr->interp = interp; |
| 367 |
wPtr->width = 0; |
| 368 |
wPtr->borderWidth = 0; |
| 369 |
wPtr->bgBorder = NULL; |
| 370 |
wPtr->backPageGC = None; |
| 371 |
wPtr->backPageColorPtr = NULL; |
| 372 |
wPtr->disabledFg = NULL; |
| 373 |
wPtr->gray = None; |
| 374 |
wPtr->disabledGC = None; |
| 375 |
wPtr->inActiveBorder = NULL; |
| 376 |
wPtr->focusBorder = NULL; |
| 377 |
wPtr->font = NULL; |
| 378 |
wPtr->textColorPtr = NULL; |
| 379 |
wPtr->textGC = None; |
| 380 |
wPtr->focusGC = None; |
| 381 |
wPtr->relief = TK_RELIEF_FLAT; |
| 382 |
wPtr->cursor = None; |
| 383 |
|
| 384 |
wPtr->tabHead = 0; |
| 385 |
wPtr->tabTail = 0; |
| 386 |
wPtr->tabPadx = 0; |
| 387 |
wPtr->tabPady = 0; |
| 388 |
wPtr->active = 0; |
| 389 |
wPtr->focus = 0; |
| 390 |
wPtr->takeFocus = 0; |
| 391 |
wPtr->redrawing = 0; |
| 392 |
wPtr->gotFocus = 0; |
| 393 |
|
| 394 |
Tk_CreateEventHandler(wPtr->tkwin, |
| 395 |
ExposureMask|StructureNotifyMask|FocusChangeMask, |
| 396 |
WidgetEventProc, (ClientData) wPtr); |
| 397 |
wPtr->widgetCmd = Tcl_CreateCommand(interp, Tk_PathName(wPtr->tkwin), |
| 398 |
WidgetCommand, (ClientData) wPtr, WidgetCmdDeletedProc); |
| 399 |
if (WidgetConfigure(interp, wPtr, argc-2, argv+2, 0) != TCL_OK) { |
| 400 |
Tk_DestroyWindow(wPtr->tkwin); |
| 401 |
return TCL_ERROR; |
| 402 |
} |
| 403 |
|
| 404 |
interp->result = Tk_PathName(wPtr->tkwin); |
| 405 |
return TCL_OK; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
static int |
| 427 |
WidgetCommand(clientData, interp, argc, argv) |
| 428 |
ClientData clientData; |
| 429 |
Tcl_Interp *interp; |
| 430 |
int argc; |
| 431 |
char **argv; |
| 432 |
{ |
| 433 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 434 |
int result = TCL_OK; |
| 435 |
int length; |
| 436 |
char c; |
| 437 |
|
| 438 |
if (argc < 2) { |
| 439 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 440 |
argv[0], " option ?arg arg ...?\"", (char *) NULL); |
| 441 |
return TCL_ERROR; |
| 442 |
} |
| 443 |
Tcl_Preserve((ClientData) wPtr); |
| 444 |
c = argv[1][0]; |
| 445 |
length = strlen(argv[1]); |
| 446 |
|
| 447 |
if (((c == 'a') && (strncmp(argv[1], "activate", length) == 0))|| |
| 448 |
((c == 'f') && (strncmp(argv[1], "focus", length) == 0))){ |
| 449 |
if (argc != 3) { |
| 450 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 451 |
argv[0], " ", argv[1], " name\"", (char *) NULL); |
| 452 |
goto error; |
| 453 |
} |
| 454 |
else { |
| 455 |
if (strcmp(argv[2], "")==0) { |
| 456 |
if (c == 'a') { |
| 457 |
wPtr->active = 0; |
| 458 |
wPtr->focus = 0; |
| 459 |
} |
| 460 |
else { |
| 461 |
wPtr->focus = 0; |
| 462 |
} |
| 463 |
RedrawWhenIdle(wPtr); |
| 464 |
} |
| 465 |
else { |
| 466 |
Tab * tPtr; |
| 467 |
|
| 468 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 469 |
if (strcmp(argv[2], tPtr->name) == 0) { |
| 470 |
if (c == 'a') { |
| 471 |
wPtr->active = tPtr; |
| 472 |
wPtr->focus = tPtr; |
| 473 |
} |
| 474 |
else { |
| 475 |
wPtr->focus = tPtr; |
| 476 |
} |
| 477 |
RedrawWhenIdle(wPtr); |
| 478 |
goto done; |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
Tcl_AppendResult(interp, "unknown tab \"", |
| 483 |
argv[0], "\"", (char *) NULL); |
| 484 |
goto error; |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
else if ((c == 'a') && (strncmp(argv[1], "add", length) == 0)) { |
| 489 |
if (argc < 3) { |
| 490 |
Tcl_AppendResult(interp, "wrong # args: should be ", |
| 491 |
argv[0], " add name ?options?", (char *) NULL); |
| 492 |
goto error; |
| 493 |
} |
| 494 |
else { |
| 495 |
if (AddTab(wPtr, argv[2], argv+3, argc-3)!= TCL_OK) { |
| 496 |
goto error; |
| 497 |
} else { |
| 498 |
WidgetComputeGeometry(wPtr); |
| 499 |
RedrawWhenIdle(wPtr); |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)) { |
| 504 |
if (argc == 3) { |
| 505 |
result = Tk_ConfigureValue(interp, wPtr->tkwin, configSpecs, |
| 506 |
(char *)wPtr, argv[2], 0); |
| 507 |
} else { |
| 508 |
result = Tix_ArgcError(interp, argc, argv, 2, "option"); |
| 509 |
} |
| 510 |
} |
| 511 |
else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)) { |
| 512 |
if (argc == 2) { |
| 513 |
result = Tk_ConfigureInfo(interp, wPtr->tkwin, configSpecs, |
| 514 |
(char *) wPtr, (char *) NULL, 0); |
| 515 |
} else if (argc == 3) { |
| 516 |
result = Tk_ConfigureInfo(interp, wPtr->tkwin, configSpecs, |
| 517 |
(char *) wPtr, argv[2], 0); |
| 518 |
} else { |
| 519 |
result = WidgetConfigure(interp, wPtr, argc-2, argv+2, |
| 520 |
TK_CONFIG_ARGV_ONLY); |
| 521 |
} |
| 522 |
} |
| 523 |
else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) { |
| 524 |
Tab * tPtr, * prev ; |
| 525 |
|
| 526 |
if (argc != 3) { |
| 527 |
Tix_ArgcError(interp, argc, argv, 2, "page"); |
| 528 |
goto error; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
for (prev=tPtr=wPtr->tabHead; tPtr; prev=tPtr,tPtr=tPtr->next) { |
| 533 |
if (strcmp(tPtr->name, argv[2])==0) { |
| 534 |
break; |
| 535 |
} |
| 536 |
} |
| 537 |
if (tPtr == NULL) { |
| 538 |
Tcl_AppendResult(wPtr->interp, |
| 539 |
"Unknown tab \"", argv[2], "\"", (char*) NULL); |
| 540 |
goto error; |
| 541 |
} |
| 542 |
if (tPtr == prev) { |
| 543 |
if (wPtr->tabHead == wPtr->tabTail) { |
| 544 |
wPtr->tabHead = wPtr->tabTail = NULL; |
| 545 |
} else { |
| 546 |
wPtr->tabHead = tPtr->next; |
| 547 |
} |
| 548 |
} else { |
| 549 |
if (tPtr == wPtr->tabTail) { |
| 550 |
wPtr->tabTail = prev; |
| 551 |
} |
| 552 |
prev->next = tPtr->next; |
| 553 |
} |
| 554 |
|
| 555 |
DeleteTab(tPtr); |
| 556 |
ComputeGeometry(wPtr); |
| 557 |
RedrawWhenIdle(wPtr); |
| 558 |
} |
| 559 |
else if ((c == 'g') && (strncmp(argv[1], "geometryinfo", length) == 0)) { |
| 560 |
ComputeGeometry(wPtr); |
| 561 |
Tcl_IntResults(interp, 2, 0, wPtr->width, wPtr->height); |
| 562 |
} |
| 563 |
else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) { |
| 564 |
if (argc != 4) { |
| 565 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 566 |
argv[0], " identify x y\"", (char *) NULL); |
| 567 |
goto error; |
| 568 |
} |
| 569 |
else { |
| 570 |
int x, y, left, right; |
| 571 |
Tab * tPtr; |
| 572 |
|
| 573 |
if (Tcl_GetIntFromObj(interp, argv[2], &x) != TCL_OK) { |
| 574 |
goto error; |
| 575 |
} |
| 576 |
if (Tcl_GetIntFromObj(interp, argv[3], &y) != TCL_OK) { |
| 577 |
goto error; |
| 578 |
} |
| 579 |
|
| 580 |
if (y < wPtr->tabsHeight) { |
| 581 |
left = 0; |
| 582 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 583 |
right = left + (wPtr->borderWidth + wPtr->tabPadx) * 2 |
| 584 |
+ tPtr->width; |
| 585 |
|
| 586 |
if (x >= left && x <= right && tPtr->state ==tixNormalUid){ |
| 587 |
Tcl_AppendResult(interp, tPtr->name, NULL); |
| 588 |
goto done; |
| 589 |
} |
| 590 |
left = right; |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
Tcl_ResetResult(interp); |
| 598 |
} |
| 599 |
} |
| 600 |
else if ((c == 'i') && (strncmp(argv[1], "info", length) == 0)) { |
| 601 |
Tcl_ResetResult(interp); |
| 602 |
|
| 603 |
if (argc == 3 && strcmp(argv[2], "pages")==0 ) { |
| 604 |
Tab * tPtr; |
| 605 |
|
| 606 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 607 |
Tcl_AppendElement(interp, tPtr->name); |
| 608 |
} |
| 609 |
} |
| 610 |
else if (argc == 3 && strcmp(argv[2], "active")==0 ) { |
| 611 |
if (wPtr->active) { |
| 612 |
Tcl_AppendResult(interp, wPtr->active->name, NULL); |
| 613 |
} |
| 614 |
} |
| 615 |
else if (argc == 3 && strcmp(argv[2], "focus")==0 ) { |
| 616 |
if (wPtr->focus) { |
| 617 |
Tcl_AppendResult(interp, wPtr->focus->name, NULL); |
| 618 |
} |
| 619 |
} |
| 620 |
else if (argc == 3 && strcmp(argv[2], "focusnext")==0 ) { |
| 621 |
Tab * next; |
| 622 |
if (wPtr->focus) { |
| 623 |
if (wPtr->focus->next) { |
| 624 |
next = wPtr->focus->next; |
| 625 |
} else { |
| 626 |
next = wPtr->tabHead; |
| 627 |
} |
| 628 |
Tcl_AppendResult(interp, next->name, NULL); |
| 629 |
} |
| 630 |
} |
| 631 |
else if (argc == 3 && strcmp(argv[2], "focusprev")==0 ) { |
| 632 |
Tab * prev, *tPtr; |
| 633 |
|
| 634 |
if (wPtr->focus==wPtr->tabHead) { |
| 635 |
prev = wPtr->tabTail; |
| 636 |
} |
| 637 |
else { |
| 638 |
for (prev=tPtr=wPtr->tabHead;tPtr; prev=tPtr,tPtr=tPtr->next) { |
| 639 |
if (tPtr == wPtr->focus) { |
| 640 |
break; |
| 641 |
} |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
if (prev) { |
| 646 |
Tcl_AppendResult(interp, prev->name, NULL); |
| 647 |
} |
| 648 |
} |
| 649 |
else { |
| 650 |
Tcl_AppendResult(interp, "wrong number of arguments or ", |
| 651 |
"unknown option", NULL); |
| 652 |
goto error; |
| 653 |
} |
| 654 |
} |
| 655 |
else if ((c == 'm') && (strncmp(argv[1], "move", length) == 0)) { |
| 656 |
|
| 657 |
} |
| 658 |
else if ((c == 'p') && (strncmp(argv[1], "pagecget", length) == 0)) { |
| 659 |
Tab * tPtr; |
| 660 |
|
| 661 |
if (argc != 4) { |
| 662 |
Tix_ArgcError(interp, argc, argv, 2, "option"); |
| 663 |
goto error; |
| 664 |
} |
| 665 |
if ((tPtr=FindTab(interp, wPtr, argv[2])) == NULL) { |
| 666 |
goto error; |
| 667 |
} |
| 668 |
result = Tk_ConfigureValue(interp, wPtr->tkwin, tabConfigSpecs, |
| 669 |
(char *)tPtr, argv[3], 0); |
| 670 |
} |
| 671 |
else if ((c == 'p') && (strncmp(argv[1], "pageconfigure", length) == 0)) { |
| 672 |
Tab * tPtr; |
| 673 |
|
| 674 |
if (argc < 3) { |
| 675 |
Tix_ArgcError(interp, argc, argv, 2, |
| 676 |
"page ?option value ...?"); |
| 677 |
goto error; |
| 678 |
} |
| 679 |
if ((tPtr=FindTab(interp, wPtr, argv[2])) == NULL) { |
| 680 |
goto error; |
| 681 |
} |
| 682 |
if (argc == 3) { |
| 683 |
result = Tk_ConfigureInfo(interp, wPtr->tkwin, tabConfigSpecs, |
| 684 |
(char *)tPtr, (char *) NULL, 0); |
| 685 |
} else if (argc == 4) { |
| 686 |
result = Tk_ConfigureInfo(interp, wPtr->tkwin, tabConfigSpecs, |
| 687 |
(char *)tPtr, argv[3], 0); |
| 688 |
} else { |
| 689 |
result = TabConfigure(wPtr, tPtr, argv+3, argc-3); |
| 690 |
} |
| 691 |
} |
| 692 |
else { |
| 693 |
Tcl_AppendResult(interp, "bad option \"", argv[1], |
| 694 |
"\": must be activate, add, configure, delete, ", |
| 695 |
"geometryinfo, identify, move, pagecget or ", |
| 696 |
"pageconfigure", (char *) NULL); |
| 697 |
goto error; |
| 698 |
} |
| 699 |
|
| 700 |
done: |
| 701 |
Tcl_Release((ClientData) wPtr); |
| 702 |
return result; |
| 703 |
|
| 704 |
error: |
| 705 |
Tcl_Release((ClientData) wPtr); |
| 706 |
return TCL_ERROR; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
static int |
| 730 |
WidgetConfigure(interp, wPtr, argc, argv, flags) |
| 731 |
Tcl_Interp *interp; |
| 732 |
WidgetPtr wPtr; |
| 733 |
int argc; |
| 734 |
char **argv; |
| 735 |
int flags; |
| 736 |
|
| 737 |
{ |
| 738 |
XGCValues gcValues; |
| 739 |
GC newGC; |
| 740 |
int mask; |
| 741 |
|
| 742 |
if (Tk_ConfigureWidget(interp, wPtr->tkwin, configSpecs, |
| 743 |
argc, argv, (char *) wPtr, flags) != TCL_OK) { |
| 744 |
return TCL_ERROR; |
| 745 |
} |
| 746 |
|
| 747 |
if (wPtr->tabPadx < 3) { |
| 748 |
wPtr->tabPadx = 3; |
| 749 |
} |
| 750 |
if (wPtr->tabPady < 2) { |
| 751 |
wPtr->tabPady = 2; |
| 752 |
} |
| 753 |
|
| 754 |
Tk_SetBackgroundFromBorder(wPtr->tkwin, wPtr->bgBorder); |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
gcValues.foreground = wPtr->backPageColorPtr->pixel; |
| 760 |
gcValues.graphics_exposures = False; |
| 761 |
newGC = Tk_GetGC(wPtr->tkwin, GCForeground|GCGraphicsExposures, |
| 762 |
&gcValues); |
| 763 |
if (wPtr->backPageGC != None) { |
| 764 |
Tk_FreeGC(wPtr->display, wPtr->backPageGC); |
| 765 |
} |
| 766 |
wPtr->backPageGC = newGC; |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
gcValues.foreground = wPtr->textColorPtr->pixel; |
| 772 |
gcValues.background = Tk_3DBorderColor(wPtr->bgBorder)->pixel; |
| 773 |
gcValues.font = TixFontId(wPtr->font); |
| 774 |
gcValues.graphics_exposures = False; |
| 775 |
newGC = Tk_GetGC(wPtr->tkwin, |
| 776 |
GCBackground|GCForeground|GCFont|GCGraphicsExposures, |
| 777 |
&gcValues); |
| 778 |
if (wPtr->textGC != None) { |
| 779 |
Tk_FreeGC(wPtr->display, wPtr->textGC); |
| 780 |
} |
| 781 |
wPtr->textGC = newGC; |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
if (wPtr->disabledFg != NULL) { |
| 787 |
gcValues.foreground = wPtr->disabledFg->pixel; |
| 788 |
gcValues.background = Tk_3DBorderColor(wPtr->bgBorder)->pixel; |
| 789 |
mask = GCForeground|GCBackground|GCFont; |
| 790 |
} else { |
| 791 |
gcValues.foreground = Tk_3DBorderColor(wPtr->bgBorder)->pixel; |
| 792 |
if (wPtr->gray == None) { |
| 793 |
wPtr->gray = Tk_GetBitmap(interp, wPtr->tkwin, |
| 794 |
Tk_GetUid("gray50")); |
| 795 |
if (wPtr->gray == None) { |
| 796 |
return TCL_ERROR; |
| 797 |
} |
| 798 |
} |
| 799 |
gcValues.fill_style = FillStippled; |
| 800 |
gcValues.stipple = wPtr->gray; |
| 801 |
mask = GCForeground|GCFillStyle|GCFont|GCStipple; |
| 802 |
} |
| 803 |
gcValues.font = TixFontId(wPtr->font); |
| 804 |
newGC = Tk_GetGC(wPtr->tkwin, mask, &gcValues); |
| 805 |
if (wPtr->disabledGC != None) { |
| 806 |
Tk_FreeGC(wPtr->display, wPtr->disabledGC); |
| 807 |
} |
| 808 |
wPtr->disabledGC = newGC; |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
gcValues.foreground = wPtr->textColorPtr->pixel; |
| 814 |
gcValues.background = Tk_3DBorderColor(wPtr->bgBorder)->pixel; |
| 815 |
gcValues.graphics_exposures = False; |
| 816 |
gcValues.line_style = LineDoubleDash; |
| 817 |
gcValues.dashes = 2; |
| 818 |
newGC = Tk_GetGC(wPtr->tkwin, |
| 819 |
GCForeground|GCBackground|GCGraphicsExposures|GCLineStyle|GCDashList, |
| 820 |
&gcValues); |
| 821 |
if (wPtr->focusGC != None) { |
| 822 |
Tk_FreeGC(wPtr->display, wPtr->focusGC); |
| 823 |
} |
| 824 |
wPtr->focusGC = newGC; |
| 825 |
|
| 826 |
WidgetComputeGeometry(wPtr); |
| 827 |
RedrawWhenIdle(wPtr); |
| 828 |
|
| 829 |
return TCL_OK; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
static void |
| 851 |
WidgetEventProc(clientData, eventPtr) |
| 852 |
ClientData clientData; |
| 853 |
XEvent *eventPtr; |
| 854 |
{ |
| 855 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 856 |
|
| 857 |
switch (eventPtr->type ) { |
| 858 |
case DestroyNotify: |
| 859 |
if (wPtr->tkwin != NULL) { |
| 860 |
wPtr->tkwin = NULL; |
| 861 |
Tcl_DeleteCommand(wPtr->interp, |
| 862 |
Tcl_GetCommandName(wPtr->interp, wPtr->widgetCmd)); |
| 863 |
} |
| 864 |
CancelRedrawWhenIdle(wPtr); |
| 865 |
Tcl_EventuallyFree((ClientData) wPtr, WidgetDestroy); |
| 866 |
break; |
| 867 |
|
| 868 |
case Expose: |
| 869 |
case ConfigureNotify: |
| 870 |
RedrawWhenIdle(wPtr); |
| 871 |
break; |
| 872 |
|
| 873 |
case FocusIn: |
| 874 |
if (eventPtr->xfocus.detail != NotifyVirtual) { |
| 875 |
wPtr->gotFocus = 1; |
| 876 |
if (wPtr->focus == NULL) { |
| 877 |
wPtr->focus = wPtr->active; |
| 878 |
} |
| 879 |
RedrawWhenIdle(wPtr); |
| 880 |
} |
| 881 |
break; |
| 882 |
|
| 883 |
case FocusOut: |
| 884 |
if (eventPtr->xfocus.detail != NotifyVirtual) { |
| 885 |
wPtr->gotFocus = 0; |
| 886 |
RedrawWhenIdle(wPtr); |
| 887 |
} |
| 888 |
break; |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
static void |
| 911 |
WidgetDestroy(clientData) |
| 912 |
char *clientData; |
| 913 |
{ |
| 914 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 915 |
Tab * tPtr; |
| 916 |
|
| 917 |
for (tPtr=wPtr->tabHead; tPtr;) { |
| 918 |
Tab * toDelete; |
| 919 |
|
| 920 |
toDelete = tPtr; |
| 921 |
tPtr=tPtr->next; |
| 922 |
|
| 923 |
DeleteTab(toDelete); |
| 924 |
} |
| 925 |
|
| 926 |
if (wPtr->backPageGC != None) { |
| 927 |
Tk_FreeGC(wPtr->display, wPtr->backPageGC); |
| 928 |
} |
| 929 |
if (wPtr->textGC != None) { |
| 930 |
Tk_FreeGC(wPtr->display, wPtr->textGC); |
| 931 |
} |
| 932 |
if (wPtr->focusGC != None) { |
| 933 |
Tk_FreeGC(wPtr->display, wPtr->focusGC); |
| 934 |
} |
| 935 |
if (wPtr->gray != None) { |
| 936 |
Tk_FreeBitmap(wPtr->display, wPtr->gray); |
| 937 |
} |
| 938 |
if (wPtr->disabledGC != None) { |
| 939 |
Tk_FreeGC(wPtr->display, wPtr->disabledGC); |
| 940 |
} |
| 941 |
Tk_FreeOptions(configSpecs, (char *) wPtr, wPtr->display, 0); |
| 942 |
ckfree((char *) wPtr); |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
static void |
| 963 |
WidgetCmdDeletedProc(clientData) |
| 964 |
ClientData clientData; |
| 965 |
{ |
| 966 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
if (wPtr->tkwin != NULL) { |
| 975 |
Tk_Window tkwin = wPtr->tkwin; |
| 976 |
wPtr->tkwin = NULL; |
| 977 |
Tk_DestroyWindow(tkwin); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
static Tab * FindTab(interp, wPtr, name) |
| 990 |
Tcl_Interp * interp; |
| 991 |
WidgetPtr wPtr; |
| 992 |
char * name; |
| 993 |
{ |
| 994 |
Tab *tPtr; |
| 995 |
|
| 996 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 997 |
if (strcmp(tPtr->name, name) == 0) { |
| 998 |
return tPtr; |
| 999 |
} |
| 1000 |
} |
| 1001 |
|
| 1002 |
Tcl_AppendResult(interp, "Unknown tab \"", name, "\"", (char*) NULL); |
| 1003 |
return NULL; |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
static int TabConfigure(wPtr, tPtr, argv, argc) |
| 1008 |
WidgetPtr wPtr; |
| 1009 |
Tab *tPtr; |
| 1010 |
char ** argv; |
| 1011 |
int argc; |
| 1012 |
{ |
| 1013 |
if (Tk_ConfigureWidget(wPtr->interp, wPtr->tkwin, tabConfigSpecs, |
| 1014 |
argc, argv, (char *)tPtr, TK_CONFIG_ARGV_ONLY) != TCL_OK) { |
| 1015 |
return TCL_ERROR; |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
if (tPtr->image != NULL) { |
| 1022 |
Tk_FreeImage(tPtr->image); |
| 1023 |
tPtr->image = NULL; |
| 1024 |
} |
| 1025 |
|
| 1026 |
if (tPtr->imageString != NULL) { |
| 1027 |
tPtr->image = Tk_GetImage(wPtr->interp, wPtr->tkwin, |
| 1028 |
tPtr->imageString, ImageProc, (ClientData) tPtr); |
| 1029 |
if (tPtr->image == NULL) { |
| 1030 |
return TCL_ERROR; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (tPtr->text != NULL) { |
| 1035 |
tPtr->numChars = -1; |
| 1036 |
TixComputeTextGeometry(wPtr->font, tPtr->text, tPtr->numChars, |
| 1037 |
tPtr->wrapLength, &tPtr->width, &tPtr->height); |
| 1038 |
} |
| 1039 |
else if (tPtr->image != NULL) { |
| 1040 |
Tk_SizeOfImage(tPtr->image, &tPtr->width, &tPtr->height); |
| 1041 |
} |
| 1042 |
else if (tPtr->bitmap != None) { |
| 1043 |
Tk_SizeOfBitmap(wPtr->display, tPtr->bitmap, &tPtr->width, |
| 1044 |
&tPtr->height); |
| 1045 |
} |
| 1046 |
else { |
| 1047 |
tPtr->width = 0; |
| 1048 |
tPtr->height = 0; |
| 1049 |
} |
| 1050 |
|
| 1051 |
WidgetComputeGeometry(wPtr); |
| 1052 |
RedrawWhenIdle(wPtr); |
| 1053 |
|
| 1054 |
return TCL_OK; |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
static int |
| 1076 |
AddTab(wPtr, name, argv, argc) |
| 1077 |
WidgetPtr wPtr; |
| 1078 |
char * name; |
| 1079 |
char ** argv; |
| 1080 |
int argc; |
| 1081 |
{ |
| 1082 |
Tab * tPtr; |
| 1083 |
|
| 1084 |
tPtr = (Tab*)ckalloc(sizeof(Tab)); |
| 1085 |
|
| 1086 |
tPtr->next = NULL; |
| 1087 |
tPtr->wPtr = wPtr; |
| 1088 |
tPtr->name = tixStrDup(name); |
| 1089 |
tPtr->state = tixNormalUid; |
| 1090 |
tPtr->text = NULL; |
| 1091 |
tPtr->width = 0; |
| 1092 |
tPtr->height = 0; |
| 1093 |
tPtr->numChars = 0; |
| 1094 |
tPtr->justify = TK_JUSTIFY_CENTER; |
| 1095 |
tPtr->wrapLength = 0; |
| 1096 |
tPtr->underline = -1; |
| 1097 |
tPtr->image = NULL; |
| 1098 |
tPtr->imageString = NULL; |
| 1099 |
tPtr->bitmap = None; |
| 1100 |
tPtr->anchor = TK_ANCHOR_CENTER; |
| 1101 |
|
| 1102 |
if (TabConfigure(wPtr, tPtr, argv, argc) != TCL_OK) { |
| 1103 |
return TCL_ERROR; |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
if (wPtr->tabHead == 0) { |
| 1109 |
wPtr->tabHead = wPtr->tabTail = tPtr; |
| 1110 |
} |
| 1111 |
else { |
| 1112 |
|
| 1113 |
wPtr->tabTail->next = tPtr; |
| 1114 |
wPtr->tabTail = tPtr; |
| 1115 |
} |
| 1116 |
|
| 1117 |
return TCL_OK; |
| 1118 |
} |
| 1119 |
|
| 1120 |
static void DeleteTab(tPtr) |
| 1121 |
Tab * tPtr; |
| 1122 |
{ |
| 1123 |
if (tPtr->wPtr->focus == tPtr) { |
| 1124 |
tPtr->wPtr->focus = 0; |
| 1125 |
} |
| 1126 |
if (tPtr->wPtr->active == tPtr) { |
| 1127 |
tPtr->wPtr->active = 0; |
| 1128 |
} |
| 1129 |
if (tPtr->name) { |
| 1130 |
ckfree(tPtr->name); |
| 1131 |
} |
| 1132 |
if (tPtr->image) { |
| 1133 |
Tk_FreeImage(tPtr->image); |
| 1134 |
} |
| 1135 |
|
| 1136 |
if (tPtr->wPtr->tkwin) { |
| 1137 |
Tk_FreeOptions(tabConfigSpecs, (char *)tPtr, |
| 1138 |
Tk_Display(tPtr->wPtr->tkwin), 0); |
| 1139 |
} |
| 1140 |
ckfree((char*)tPtr); |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
static void |
| 1157 |
RedrawWhenIdle(wPtr) |
| 1158 |
WidgetPtr wPtr; |
| 1159 |
{ |
| 1160 |
if (! wPtr->redrawing && Tk_IsMapped(wPtr->tkwin)) { |
| 1161 |
wPtr->redrawing = 1; |
| 1162 |
Tcl_DoWhenIdle(WidgetDisplay, (ClientData)wPtr); |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
static void |
| 1180 |
CancelRedrawWhenIdle(wPtr) |
| 1181 |
WidgetPtr wPtr; |
| 1182 |
{ |
| 1183 |
if (wPtr->redrawing) { |
| 1184 |
wPtr->redrawing = 0; |
| 1185 |
Tcl_CancelIdleCall(WidgetDisplay, (ClientData)wPtr); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
|
| 1189 |
static void GetTabPoints(wPtr, tPtr, x, points) |
| 1190 |
WidgetPtr wPtr; |
| 1191 |
Tab * tPtr; |
| 1192 |
int x; |
| 1193 |
XPoint *points; |
| 1194 |
{ |
| 1195 |
points[0].x = x + wPtr->borderWidth; |
| 1196 |
points[0].y = wPtr->tabsHeight; |
| 1197 |
points[1].x = points[0].x; |
| 1198 |
points[1].y = wPtr->borderWidth * 2; |
| 1199 |
points[2].x = x + wPtr->borderWidth * 2; |
| 1200 |
points[2].y = wPtr->borderWidth; |
| 1201 |
|
| 1202 |
points[3].x = x + tPtr->width + wPtr->tabPadx*2; |
| 1203 |
points[3].y = points[2].y; |
| 1204 |
points[4].x = points[3].x + wPtr->borderWidth; |
| 1205 |
points[4].y = points[1].y; |
| 1206 |
points[5].x = points[4].x; |
| 1207 |
points[5].y = points[0].y; |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
static void DrawTab(wPtr, tPtr, x, isActive, drawable) |
| 1224 |
WidgetPtr wPtr; |
| 1225 |
Tab * tPtr; |
| 1226 |
int x; |
| 1227 |
int isActive; |
| 1228 |
Drawable drawable; |
| 1229 |
{ |
| 1230 |
Tk_3DBorder border; |
| 1231 |
XPoint points[NUM_TAB_POINTS]; |
| 1232 |
int drawX, drawY, extraH; |
| 1233 |
|
| 1234 |
if (isActive) { |
| 1235 |
border = wPtr->bgBorder; |
| 1236 |
} else { |
| 1237 |
border = wPtr->inActiveBorder; |
| 1238 |
} |
| 1239 |
|
| 1240 |
GetTabPoints(wPtr, tPtr, x, points); |
| 1241 |
drawX = x + wPtr->borderWidth + wPtr->tabPadx; |
| 1242 |
drawY = wPtr->borderWidth + wPtr->tabPady; |
| 1243 |
extraH = wPtr->tabsHeight - tPtr->height - |
| 1244 |
wPtr->borderWidth - wPtr->tabPady *2; |
| 1245 |
|
| 1246 |
if (extraH > 0) { |
| 1247 |
switch (tPtr->anchor) { |
| 1248 |
case TK_ANCHOR_SW: case TK_ANCHOR_S: case TK_ANCHOR_SE: |
| 1249 |
drawY += extraH; |
| 1250 |
break; |
| 1251 |
case TK_ANCHOR_W: case TK_ANCHOR_CENTER: case TK_ANCHOR_E: |
| 1252 |
drawY += extraH/2; |
| 1253 |
break; |
| 1254 |
case TK_ANCHOR_N: case TK_ANCHOR_NE: case TK_ANCHOR_NW: |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
break; |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
Tk_Fill3DPolygon(wPtr->tkwin, drawable, |
| 1263 |
border, points, NUM_TAB_POINTS, |
| 1264 |
wPtr->borderWidth, TK_RELIEF_SUNKEN); |
| 1265 |
|
| 1266 |
if (tPtr->text != NULL) { |
| 1267 |
if (tPtr->state == tixNormalUid) { |
| 1268 |
TixDisplayText(wPtr->display, drawable, wPtr->font, |
| 1269 |
tPtr->text, tPtr->numChars, |
| 1270 |
drawX, drawY, |
| 1271 |
tPtr->width, |
| 1272 |
tPtr->justify, |
| 1273 |
tPtr->underline, |
| 1274 |
wPtr->textGC); |
| 1275 |
} else { |
| 1276 |
TixDisplayText(wPtr->display, drawable, wPtr->font, |
| 1277 |
tPtr->text, tPtr->numChars, |
| 1278 |
drawX, drawY, |
| 1279 |
tPtr->width, |
| 1280 |
tPtr->justify, |
| 1281 |
tPtr->underline, |
| 1282 |
wPtr->disabledGC); |
| 1283 |
} |
| 1284 |
} |
| 1285 |
else if (tPtr->image != NULL) { |
| 1286 |
Tk_RedrawImage(tPtr->image, 0, 0, tPtr->width, tPtr->height, |
| 1287 |
drawable, drawX, drawY); |
| 1288 |
} |
| 1289 |
else if (tPtr->bitmap != None) { |
| 1290 |
GC gc; |
| 1291 |
|
| 1292 |
if (tPtr->state == tixNormalUid) { |
| 1293 |
gc = wPtr->textGC; |
| 1294 |
} else { |
| 1295 |
gc = wPtr->disabledGC; |
| 1296 |
} |
| 1297 |
XSetClipOrigin(wPtr->display, gc, drawX, drawY); |
| 1298 |
XCopyPlane(wPtr->display, tPtr->bitmap, drawable, |
| 1299 |
gc, 0, 0, tPtr->width, tPtr->height, |
| 1300 |
drawX, drawY, 1); |
| 1301 |
XSetClipOrigin(wPtr->display, gc, 0, 0); |
| 1302 |
} |
| 1303 |
|
| 1304 |
#if 0 |
| 1305 |
if (wPtr->gotFocus && tPtr == wPtr->focus) { |
| 1306 |
XDrawLine(Tk_Display(wPtr->tkwin), drawable, wPtr->focusGC, |
| 1307 |
drawX, |
| 1308 |
drawY + tPtr->height + 1, |
| 1309 |
drawX + tPtr->width, |
| 1310 |
drawY + tPtr->height + 1); |
| 1311 |
} |
| 1312 |
#endif |
| 1313 |
} |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
static void FocusTab(wPtr, tPtr, x, drawable) |
| 1328 |
WidgetPtr wPtr; |
| 1329 |
Tab * tPtr; |
| 1330 |
int x; |
| 1331 |
Drawable drawable; |
| 1332 |
{ |
| 1333 |
Tk_3DBorder border; |
| 1334 |
|
| 1335 |
XPoint points[NUM_TAB_POINTS]; |
| 1336 |
|
| 1337 |
if (wPtr->active == tPtr) { |
| 1338 |
border = wPtr->bgBorder; |
| 1339 |
} else { |
| 1340 |
border = wPtr->inActiveBorder; |
| 1341 |
} |
| 1342 |
|
| 1343 |
GetTabPoints(wPtr, tPtr, x, points); |
| 1344 |
Tk_Draw3DPolygon(wPtr->tkwin, drawable, |
| 1345 |
wPtr->focusBorder, points, NUM_TAB_POINTS, |
| 1346 |
wPtr->borderWidth, TK_RELIEF_SUNKEN); |
| 1347 |
|
| 1348 |
if (wPtr->active == tPtr) { |
| 1349 |
Tk_Draw3DPolygon(wPtr->tkwin, drawable, |
| 1350 |
border, points, NUM_TAB_POINTS, |
| 1351 |
wPtr->borderWidth/2, TK_RELIEF_SUNKEN); |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
static void |
| 1369 |
WidgetDisplay(clientData) |
| 1370 |
ClientData clientData; |
| 1371 |
{ |
| 1372 |
WidgetPtr wPtr = (WidgetPtr) clientData; |
| 1373 |
Tab * tPtr; |
| 1374 |
int width, height; |
| 1375 |
Drawable buffer; |
| 1376 |
|
| 1377 |
|
| 1378 |
if (wPtr->tabHead == NULL) { |
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
if ((wPtr->bgBorder != NULL) && (wPtr->relief != TK_RELIEF_FLAT)) { |
| 1383 |
Tk_Fill3DRectangle(wPtr->tkwin, Tk_WindowId(wPtr->tkwin), |
| 1384 |
wPtr->bgBorder, 0, 0, |
| 1385 |
Tk_Width(wPtr->tkwin), Tk_Height(wPtr->tkwin), |
| 1386 |
wPtr->borderWidth, wPtr->relief); |
| 1387 |
} |
| 1388 |
} |
| 1389 |
else { |
| 1390 |
int x, y, activex = 0; |
| 1391 |
|
| 1392 |
buffer = Tix_GetRenderBuffer(wPtr->display, Tk_WindowId(wPtr->tkwin), |
| 1393 |
Tk_Width(wPtr->tkwin), Tk_Height(wPtr->tkwin), |
| 1394 |
Tk_Depth(wPtr->tkwin)); |
| 1395 |
XFillRectangle(Tk_Display(wPtr->tkwin), buffer, wPtr->backPageGC, |
| 1396 |
0, 0, Tk_Width(wPtr->tkwin), Tk_Height(wPtr->tkwin)); |
| 1397 |
|
| 1398 |
Tk_Fill3DRectangle(wPtr->tkwin, buffer, |
| 1399 |
wPtr->bgBorder, 0, wPtr->tabsHeight, |
| 1400 |
Tk_Width(wPtr->tkwin), |
| 1401 |
Tk_Height(wPtr->tkwin) - wPtr->tabsHeight, |
| 1402 |
wPtr->borderWidth, wPtr->relief); |
| 1403 |
|
| 1404 |
|
| 1405 |
x = 0; |
| 1406 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 1407 |
if (tPtr == wPtr->active) { |
| 1408 |
activex = x; |
| 1409 |
DrawTab(wPtr, tPtr, x, 1, buffer); |
| 1410 |
} |
| 1411 |
else { |
| 1412 |
DrawTab(wPtr, tPtr, x, 0, buffer); |
| 1413 |
} |
| 1414 |
if (tPtr == wPtr->focus && wPtr->gotFocus) { |
| 1415 |
FocusTab(wPtr, tPtr, x, buffer); |
| 1416 |
} |
| 1417 |
|
| 1418 |
x += (wPtr->borderWidth + wPtr->tabPadx) * 2; |
| 1419 |
x += tPtr->width; |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
Tk_Draw3DRectangle(wPtr->tkwin, buffer, |
| 1424 |
wPtr->bgBorder, 0, wPtr->tabsHeight, |
| 1425 |
Tk_Width(wPtr->tkwin), |
| 1426 |
Tk_Height(wPtr->tkwin) - wPtr->tabsHeight, |
| 1427 |
wPtr->borderWidth, wPtr->relief); |
| 1428 |
|
| 1429 |
if (wPtr->active != NULL) { |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
x = activex + wPtr->borderWidth; |
| 1434 |
y = wPtr->tabsHeight; |
| 1435 |
height = wPtr->borderWidth; |
| 1436 |
width = wPtr->active->width + wPtr->tabPadx*2; |
| 1437 |
|
| 1438 |
XFillRectangle(wPtr->display, buffer, |
| 1439 |
Tk_3DBorderGC(wPtr->tkwin, wPtr->bgBorder, TK_3D_FLAT_GC), |
| 1440 |
x, y, width, height); |
| 1441 |
} |
| 1442 |
|
| 1443 |
if (buffer != Tk_WindowId(wPtr->tkwin)) { |
| 1444 |
XCopyArea(wPtr->display, buffer, Tk_WindowId(wPtr->tkwin), |
| 1445 |
wPtr->textGC, 0, 0, Tk_Width(wPtr->tkwin), |
| 1446 |
Tk_Height(wPtr->tkwin), 0, 0); |
| 1447 |
Tk_FreePixmap(wPtr->display, buffer); |
| 1448 |
} |
| 1449 |
} |
| 1450 |
|
| 1451 |
wPtr->redrawing = 0; |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
static void |
| 1469 |
ComputeGeometry(wPtr) |
| 1470 |
WidgetPtr wPtr; |
| 1471 |
{ |
| 1472 |
Tab * tPtr; |
| 1473 |
|
| 1474 |
|
| 1475 |
if (wPtr->tabHead == NULL) { |
| 1476 |
wPtr->width = wPtr->borderWidth * 2; |
| 1477 |
wPtr->height = wPtr->borderWidth * 2; |
| 1478 |
|
| 1479 |
wPtr->tabsWidth = 0; |
| 1480 |
wPtr->tabsHeight = 0; |
| 1481 |
} else { |
| 1482 |
wPtr->tabsWidth = 0; |
| 1483 |
wPtr->tabsHeight = 0; |
| 1484 |
for (tPtr=wPtr->tabHead; tPtr; tPtr=tPtr->next) { |
| 1485 |
|
| 1486 |
if (tPtr->text != NULL) { |
| 1487 |
tPtr->numChars = -1; |
| 1488 |
TixComputeTextGeometry(wPtr->font, tPtr->text, |
| 1489 |
tPtr->numChars, tPtr->wrapLength, |
| 1490 |
&tPtr->width, &tPtr->height); |
| 1491 |
} |
| 1492 |
else if (tPtr->image != NULL) { |
| 1493 |
Tk_SizeOfImage(tPtr->image, &tPtr->width, &tPtr->height); |
| 1494 |
} |
| 1495 |
else if (tPtr->bitmap != None) { |
| 1496 |
Tk_SizeOfBitmap(wPtr->display, tPtr->bitmap, &tPtr->width, |
| 1497 |
&tPtr->height); |
| 1498 |
} |
| 1499 |
else { |
| 1500 |
tPtr->width = 0; |
| 1501 |
tPtr->height = 0; |
| 1502 |
} |
| 1503 |
|
| 1504 |
wPtr->tabsWidth += (wPtr->borderWidth + wPtr->tabPadx) * 2; |
| 1505 |
wPtr->tabsWidth += tPtr->width; |
| 1506 |
|
| 1507 |
if (tPtr->height > wPtr->tabsHeight) { |
| 1508 |
wPtr->tabsHeight = tPtr->height; |
| 1509 |
} |
| 1510 |
} |
| 1511 |
wPtr->tabsHeight += wPtr->tabPady*2 + wPtr->borderWidth; |
| 1512 |
|
| 1513 |
wPtr->width = wPtr->tabsWidth; |
| 1514 |
wPtr->height = wPtr->tabsHeight + wPtr->borderWidth*2; |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
static void |
| 1536 |
WidgetComputeGeometry(wPtr) |
| 1537 |
WidgetPtr wPtr; |
| 1538 |
{ |
| 1539 |
int width; |
| 1540 |
|
| 1541 |
ComputeGeometry(wPtr); |
| 1542 |
|
| 1543 |
if (!wPtr->isSlave) { |
| 1544 |
if (wPtr->desiredWidth > 0) { |
| 1545 |
width = wPtr->desiredWidth; |
| 1546 |
} else { |
| 1547 |
width = wPtr->width; |
| 1548 |
} |
| 1549 |
Tk_GeometryRequest(wPtr->tkwin, width, wPtr->height); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
static void |
| 1571 |
ImageProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 1572 |
ClientData clientData; |
| 1573 |
int x, y; |
| 1574 |
|
| 1575 |
int width, height; |
| 1576 |
|
| 1577 |
int imgWidth, imgHeight; |
| 1578 |
{ |
| 1579 |
Tab * tPtr; |
| 1580 |
|
| 1581 |
tPtr = (Tab *)clientData; |
| 1582 |
|
| 1583 |
WidgetComputeGeometry(tPtr->wPtr); |
| 1584 |
RedrawWhenIdle(tPtr->wPtr); |
| 1585 |
} |