| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tixPort.h" |
| 18 |
#include "tixInt.h" |
| 19 |
#include "tixDef.h" |
| 20 |
|
| 21 |
#define DEF_IMAGEITEM_BITMAP "" |
| 22 |
#define DEF_IMAGEITEM_IMAGE "" |
| 23 |
#define DEF_IMAGEITEM_TYPE "image" |
| 24 |
#define DEF_IMAGEITEM_SHOWIMAGE "1" |
| 25 |
#define DEF_IMAGEITEM_SHOWTEXT "1" |
| 26 |
#define DEF_IMAGEITEM_STYLE "" |
| 27 |
#define DEF_IMAGEITEM_TEXT "" |
| 28 |
#define DEF_IMAGEITEM_UNDERLINE "-1" |
| 29 |
|
| 30 |
static Tk_ConfigSpec imageItemConfigSpecs[] = { |
| 31 |
|
| 32 |
{TK_CONFIG_STRING, "-image", "image", "Image", |
| 33 |
DEF_IMAGEITEM_IMAGE, Tk_Offset(TixImageItem, imageString), |
| 34 |
TK_CONFIG_NULL_OK}, |
| 35 |
|
| 36 |
{TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType", |
| 37 |
DEF_IMAGEITEM_TYPE, Tk_Offset(TixImageItem, diTypePtr), |
| 38 |
0, &tixConfigItemType}, |
| 39 |
|
| 40 |
{TK_CONFIG_CUSTOM, "-style", "imageStyle", "ImageStyle", |
| 41 |
DEF_IMAGEITEM_STYLE, Tk_Offset(TixImageItem, stylePtr), |
| 42 |
TK_CONFIG_NULL_OK, &tixConfigItemStyle}, |
| 43 |
|
| 44 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 45 |
(char *) NULL, 0, 0} |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#define SELECTED_BG SELECT_BG |
| 57 |
#define DISABLED_BG DISABLED |
| 58 |
|
| 59 |
#define DEF_IMAGESTYLE_NORMAL_FG_COLOR BLACK |
| 60 |
#define DEF_IMAGESTYLE_NORMAL_FG_MONO BLACK |
| 61 |
#define DEF_IMAGESTYLE_NORMAL_BG_COLOR NORMAL_BG |
| 62 |
#define DEF_IMAGESTYLE_NORMAL_BG_MONO WHITE |
| 63 |
|
| 64 |
#define DEF_IMAGESTYLE_ACTIVE_FG_COLOR BLACK |
| 65 |
#define DEF_IMAGESTYLE_ACTIVE_FG_MONO WHITE |
| 66 |
#define DEF_IMAGESTYLE_ACTIVE_BG_COLOR ACTIVE_BG |
| 67 |
#define DEF_IMAGESTYLE_ACTIVE_BG_MONO BLACK |
| 68 |
|
| 69 |
#define DEF_IMAGESTYLE_SELECTED_FG_COLOR BLACK |
| 70 |
#define DEF_IMAGESTYLE_SELECTED_FG_MONO WHITE |
| 71 |
#define DEF_IMAGESTYLE_SELECTED_BG_COLOR SELECTED_BG |
| 72 |
#define DEF_IMAGESTYLE_SELECTED_BG_MONO BLACK |
| 73 |
|
| 74 |
#define DEF_IMAGESTYLE_DISABLED_FG_COLOR BLACK |
| 75 |
#define DEF_IMAGESTYLE_DISABLED_FG_MONO BLACK |
| 76 |
#define DEF_IMAGESTYLE_DISABLED_BG_COLOR DISABLED_BG |
| 77 |
#define DEF_IMAGESTYLE_DISABLED_BG_MONO WHITE |
| 78 |
|
| 79 |
#define DEF_IMAGESTYLE_PADX "0" |
| 80 |
#define DEF_IMAGESTYLE_PADY "0" |
| 81 |
#define DEF_IMAGESTYLE_ANCHOR "w" |
| 82 |
|
| 83 |
|
| 84 |
static Tk_ConfigSpec imageStyleConfigSpecs[] = { |
| 85 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 86 |
DEF_IMAGESTYLE_ANCHOR, Tk_Offset(TixImageStyle, anchor), 0}, |
| 87 |
|
| 88 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL, |
| 89 |
(char *) NULL, 0, 0}, |
| 90 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL, |
| 91 |
(char *) NULL, 0, 0}, |
| 92 |
|
| 93 |
{TK_CONFIG_PIXELS, "-padx", "padX", "Pad", |
| 94 |
DEF_IMAGESTYLE_PADX, Tk_Offset(TixImageStyle, pad[0]), 0}, |
| 95 |
|
| 96 |
{TK_CONFIG_PIXELS, "-pady", "padY", "Pad", |
| 97 |
DEF_IMAGESTYLE_PADY, Tk_Offset(TixImageStyle, pad[1]), 0}, |
| 98 |
|
| 99 |
|
| 100 |
{TK_CONFIG_COLOR,"-background","background","Background", |
| 101 |
DEF_IMAGESTYLE_NORMAL_BG_COLOR, |
| 102 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_NORMAL].bg), |
| 103 |
TK_CONFIG_COLOR_ONLY}, |
| 104 |
{TK_CONFIG_COLOR,"-background","background","Background", |
| 105 |
DEF_IMAGESTYLE_NORMAL_BG_MONO, |
| 106 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_NORMAL].bg), |
| 107 |
TK_CONFIG_MONO_ONLY}, |
| 108 |
{TK_CONFIG_COLOR,"-foreground","foreground","Foreground", |
| 109 |
DEF_IMAGESTYLE_NORMAL_FG_COLOR, |
| 110 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_NORMAL].fg), |
| 111 |
TK_CONFIG_COLOR_ONLY}, |
| 112 |
{TK_CONFIG_COLOR,"-foreground","foreground","Foreground", |
| 113 |
DEF_IMAGESTYLE_NORMAL_FG_MONO, |
| 114 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_NORMAL].fg), |
| 115 |
TK_CONFIG_MONO_ONLY}, |
| 116 |
{TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground", |
| 117 |
DEF_IMAGESTYLE_ACTIVE_BG_COLOR, |
| 118 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_ACTIVE].bg), |
| 119 |
TK_CONFIG_COLOR_ONLY}, |
| 120 |
{TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground", |
| 121 |
DEF_IMAGESTYLE_ACTIVE_BG_MONO, |
| 122 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_ACTIVE].bg), |
| 123 |
TK_CONFIG_MONO_ONLY}, |
| 124 |
{TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground", |
| 125 |
DEF_IMAGESTYLE_ACTIVE_FG_COLOR, |
| 126 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_ACTIVE].fg), |
| 127 |
TK_CONFIG_COLOR_ONLY}, |
| 128 |
{TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground", |
| 129 |
DEF_IMAGESTYLE_ACTIVE_FG_MONO, |
| 130 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_ACTIVE].fg), |
| 131 |
TK_CONFIG_MONO_ONLY}, |
| 132 |
{TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground", |
| 133 |
DEF_IMAGESTYLE_SELECTED_BG_COLOR, |
| 134 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_SELECTED].bg), |
| 135 |
TK_CONFIG_COLOR_ONLY}, |
| 136 |
{TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground", |
| 137 |
DEF_IMAGESTYLE_SELECTED_BG_MONO, |
| 138 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_SELECTED].bg), |
| 139 |
TK_CONFIG_MONO_ONLY}, |
| 140 |
{TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground", |
| 141 |
DEF_IMAGESTYLE_SELECTED_FG_COLOR, |
| 142 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_SELECTED].fg), |
| 143 |
TK_CONFIG_COLOR_ONLY}, |
| 144 |
{TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground", |
| 145 |
DEF_IMAGESTYLE_SELECTED_FG_MONO, |
| 146 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_SELECTED].fg), |
| 147 |
TK_CONFIG_MONO_ONLY}, |
| 148 |
{TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground", |
| 149 |
DEF_IMAGESTYLE_DISABLED_BG_COLOR, |
| 150 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_DISABLED].bg), |
| 151 |
TK_CONFIG_COLOR_ONLY}, |
| 152 |
{TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground", |
| 153 |
DEF_IMAGESTYLE_DISABLED_BG_MONO, |
| 154 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_DISABLED].bg), |
| 155 |
TK_CONFIG_MONO_ONLY}, |
| 156 |
{TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground", |
| 157 |
DEF_IMAGESTYLE_DISABLED_FG_COLOR, |
| 158 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_DISABLED].fg), |
| 159 |
TK_CONFIG_COLOR_ONLY}, |
| 160 |
{TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground", |
| 161 |
DEF_IMAGESTYLE_DISABLED_FG_MONO, |
| 162 |
Tk_Offset(TixImageStyle,colors[TIX_DITEM_DISABLED].fg), |
| 163 |
TK_CONFIG_MONO_ONLY}, |
| 164 |
|
| 165 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 166 |
(char *) NULL, 0, 0} |
| 167 |
}; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
static void ImageProc _ANSI_ARGS_((ClientData clientData, |
| 174 |
int x, int y, int width, int height, |
| 175 |
int imgWidth, int imgHeight)); |
| 176 |
static void Tix_ImageItemCalculateSize _ANSI_ARGS_(( |
| 177 |
Tix_DItem * iPtr)); |
| 178 |
static char * Tix_ImageItemComponent _ANSI_ARGS_(( |
| 179 |
Tix_DItem * iPtr, int x, int y)); |
| 180 |
static int Tix_ImageItemConfigure _ANSI_ARGS_(( |
| 181 |
Tix_DItem * iPtr, int argc, char ** argv, |
| 182 |
int flags)); |
| 183 |
static Tix_DItem * Tix_ImageItemCreate _ANSI_ARGS_(( |
| 184 |
Tix_DispData * ddPtr, Tix_DItemInfo * diTypePtr)); |
| 185 |
static void Tix_ImageItemDisplay _ANSI_ARGS_(( |
| 186 |
Pixmap pixmap, GC gc, Tix_DItem * iPtr, |
| 187 |
int x, int y, int width, int height, int flag)); |
| 188 |
static void Tix_ImageItemFree _ANSI_ARGS_(( |
| 189 |
Tix_DItem * iPtr)); |
| 190 |
static void Tix_ImageItemLostStyle _ANSI_ARGS_(( |
| 191 |
Tix_DItem * iPtr)); |
| 192 |
static void Tix_ImageItemStyleChanged _ANSI_ARGS_(( |
| 193 |
Tix_DItem * iPtr)); |
| 194 |
static int Tix_ImageStyleConfigure _ANSI_ARGS_(( |
| 195 |
Tix_DItemStyle* style, int argc, char ** argv, |
| 196 |
int flags)); |
| 197 |
static Tix_DItemStyle * Tix_ImageStyleCreate _ANSI_ARGS_(( |
| 198 |
Tcl_Interp *interp, Tk_Window tkwin, |
| 199 |
Tix_DItemInfo * diTypePtr, char * name)); |
| 200 |
static void Tix_ImageStyleFree _ANSI_ARGS_(( |
| 201 |
Tix_DItemStyle* style)); |
| 202 |
static void Tix_ImageStyleSetTemplate _ANSI_ARGS_(( |
| 203 |
Tix_DItemStyle* style, |
| 204 |
Tix_StyleTemplate * tmplPtr)); |
| 205 |
|
| 206 |
Tix_DItemInfo tix_ImageItemType = { |
| 207 |
"image", |
| 208 |
TIX_DITEM_IMAGE, |
| 209 |
Tix_ImageItemCreate, |
| 210 |
Tix_ImageItemConfigure, |
| 211 |
Tix_ImageItemCalculateSize, |
| 212 |
Tix_ImageItemComponent, |
| 213 |
Tix_ImageItemDisplay, |
| 214 |
Tix_ImageItemFree, |
| 215 |
Tix_ImageItemStyleChanged, |
| 216 |
Tix_ImageItemLostStyle, |
| 217 |
|
| 218 |
Tix_ImageStyleCreate, |
| 219 |
Tix_ImageStyleConfigure, |
| 220 |
Tix_ImageStyleFree, |
| 221 |
Tix_ImageStyleSetTemplate, |
| 222 |
|
| 223 |
imageItemConfigSpecs, |
| 224 |
imageStyleConfigSpecs, |
| 225 |
NULL, |
| 226 |
}; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
static Tix_DItem * Tix_ImageItemCreate(ddPtr, diTypePtr) |
| 236 |
Tix_DispData * ddPtr; |
| 237 |
Tix_DItemInfo * diTypePtr; |
| 238 |
{ |
| 239 |
TixImageItem * itPtr; |
| 240 |
|
| 241 |
itPtr = (TixImageItem*) ckalloc(sizeof(TixImageItem)); |
| 242 |
|
| 243 |
itPtr->diTypePtr = diTypePtr; |
| 244 |
itPtr->ddPtr = ddPtr; |
| 245 |
itPtr->stylePtr = NULL; |
| 246 |
itPtr->clientData = 0; |
| 247 |
itPtr->size[0] = 0; |
| 248 |
itPtr->size[1] = 0; |
| 249 |
|
| 250 |
itPtr->imageString = NULL; |
| 251 |
itPtr->image = NULL; |
| 252 |
itPtr->imageW = 0; |
| 253 |
itPtr->imageH = 0; |
| 254 |
|
| 255 |
return (Tix_DItem *)itPtr; |
| 256 |
} |
| 257 |
|
| 258 |
static void Tix_ImageItemFree(iPtr) |
| 259 |
Tix_DItem * iPtr; |
| 260 |
{ |
| 261 |
TixImageItem * itPtr = (TixImageItem *) iPtr; |
| 262 |
|
| 263 |
if (itPtr->image) { |
| 264 |
Tk_FreeImage(itPtr->image); |
| 265 |
} |
| 266 |
if (itPtr->stylePtr) { |
| 267 |
TixDItemStyleFree(iPtr, (Tix_DItemStyle*)itPtr->stylePtr); |
| 268 |
} |
| 269 |
|
| 270 |
Tk_FreeOptions(imageItemConfigSpecs, (char *)itPtr, |
| 271 |
itPtr->ddPtr->display, 0); |
| 272 |
ckfree((char*)itPtr); |
| 273 |
} |
| 274 |
|
| 275 |
static int Tix_ImageItemConfigure(iPtr, argc, argv, flags) |
| 276 |
Tix_DItem * iPtr; |
| 277 |
int argc; |
| 278 |
char ** argv; |
| 279 |
int flags; |
| 280 |
{ |
| 281 |
TixImageItem * itPtr = (TixImageItem *) iPtr; |
| 282 |
TixImageStyle * oldStyle = itPtr->stylePtr; |
| 283 |
|
| 284 |
if (Tk_ConfigureWidget(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin, |
| 285 |
imageItemConfigSpecs, |
| 286 |
argc, argv, (char *)itPtr, flags) != TCL_OK) { |
| 287 |
return TCL_ERROR; |
| 288 |
} |
| 289 |
if (itPtr->stylePtr == NULL) { |
| 290 |
itPtr->stylePtr = (TixImageStyle*)TixGetDefaultDItemStyle( |
| 291 |
itPtr->ddPtr, &tix_ImageItemType, iPtr, NULL); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if (itPtr->image != NULL) { |
| 298 |
Tk_FreeImage(itPtr->image); |
| 299 |
itPtr->image = NULL; |
| 300 |
} |
| 301 |
|
| 302 |
if (itPtr->imageString != NULL) { |
| 303 |
itPtr->image = Tk_GetImage(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin, |
| 304 |
itPtr->imageString, ImageProc, (ClientData) itPtr); |
| 305 |
if (itPtr->image == NULL) { |
| 306 |
return TCL_ERROR; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
if (oldStyle != NULL && itPtr->stylePtr != oldStyle) { |
| 311 |
Tix_ImageItemStyleChanged(iPtr); |
| 312 |
} |
| 313 |
else { |
| 314 |
Tix_ImageItemCalculateSize((Tix_DItem*)itPtr); |
| 315 |
} |
| 316 |
|
| 317 |
return TCL_OK; |
| 318 |
} |
| 319 |
|
| 320 |
static void Tix_ImageItemDisplay(pixmap, gc, iPtr, x, y, width, height, flags) |
| 321 |
Pixmap pixmap; |
| 322 |
GC gc; |
| 323 |
Tix_DItem * iPtr; |
| 324 |
int x; |
| 325 |
int y; |
| 326 |
int width; |
| 327 |
int height; |
| 328 |
int flags; |
| 329 |
{ |
| 330 |
TixImageItem *itPtr = (TixImageItem *)iPtr; |
| 331 |
GC foreGC, backGC; |
| 332 |
TixpSubRegion subReg; |
| 333 |
|
| 334 |
if ((width <= 0) || (height <= 0)) { |
| 335 |
return; |
| 336 |
} |
| 337 |
|
| 338 |
TixGetColorDItemGC(iPtr, &backGC, &foreGC, flags); |
| 339 |
TixpStartSubRegionDraw(itPtr->ddPtr, pixmap, foreGC, |
| 340 |
&subReg, 0, 0, x, y, width, height, |
| 341 |
itPtr->size[0], itPtr->size[1]); |
| 342 |
TixDItemGetAnchor(itPtr->stylePtr->anchor, x, y, width, height, |
| 343 |
itPtr->size[0], itPtr->size[1], &x, &y); |
| 344 |
|
| 345 |
if (backGC != None) { |
| 346 |
TixpSubRegFillRectangle(itPtr->ddPtr->display, pixmap, |
| 347 |
backGC, &subReg, x, y, width, height); |
| 348 |
} |
| 349 |
|
| 350 |
if (itPtr->image != NULL) { |
| 351 |
int bitY; |
| 352 |
|
| 353 |
bitY = itPtr->size[1] - itPtr->imageH - 2*itPtr->stylePtr->pad[1]; |
| 354 |
|
| 355 |
if (bitY > 0) { |
| 356 |
bitY = bitY / 2; |
| 357 |
} else { |
| 358 |
bitY = 0; |
| 359 |
} |
| 360 |
TixpSubRegDrawImage(&subReg, itPtr->image, 0, 0, itPtr->imageW, |
| 361 |
itPtr->imageH, pixmap, |
| 362 |
x + itPtr->stylePtr->pad[0], |
| 363 |
y + itPtr->stylePtr->pad[1] + bitY); |
| 364 |
} |
| 365 |
|
| 366 |
TixpEndSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC, |
| 367 |
&subReg); |
| 368 |
} |
| 369 |
|
| 370 |
static void Tix_ImageItemCalculateSize(iPtr) |
| 371 |
Tix_DItem * iPtr; |
| 372 |
{ |
| 373 |
TixImageItem *itPtr = (TixImageItem *)iPtr; |
| 374 |
|
| 375 |
itPtr->size[0] = 0; |
| 376 |
itPtr->size[1] = 0; |
| 377 |
|
| 378 |
if (itPtr->image != NULL) { |
| 379 |
Tk_SizeOfImage(itPtr->image, &itPtr->imageW, &itPtr->imageH); |
| 380 |
|
| 381 |
itPtr->size[0] = itPtr->imageW; |
| 382 |
itPtr->size[1] = itPtr->imageH; |
| 383 |
} |
| 384 |
|
| 385 |
itPtr->size[0] += 2*itPtr->stylePtr->pad[0]; |
| 386 |
itPtr->size[1] += 2*itPtr->stylePtr->pad[1]; |
| 387 |
} |
| 388 |
|
| 389 |
static char * Tix_ImageItemComponent(iPtr, x, y) |
| 390 |
Tix_DItem * iPtr; |
| 391 |
int x; |
| 392 |
int y; |
| 393 |
{ |
| 394 |
#if 0 |
| 395 |
TixImageItem *itPtr = (TixImageItem *)iPtr; |
| 396 |
#endif |
| 397 |
static char * body = "body"; |
| 398 |
|
| 399 |
return body; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
static void Tix_ImageItemStyleChanged(iPtr) |
| 404 |
Tix_DItem * iPtr; |
| 405 |
{ |
| 406 |
TixImageItem *itPtr = (TixImageItem *)iPtr; |
| 407 |
|
| 408 |
if (itPtr->stylePtr == NULL) { |
| 409 |
|
| 410 |
return; |
| 411 |
} |
| 412 |
Tix_ImageItemCalculateSize(iPtr); |
| 413 |
if (itPtr->ddPtr->sizeChangedProc != NULL) { |
| 414 |
itPtr->ddPtr->sizeChangedProc(iPtr); |
| 415 |
} |
| 416 |
} |
| 417 |
static void Tix_ImageItemLostStyle(iPtr) |
| 418 |
Tix_DItem * iPtr; |
| 419 |
{ |
| 420 |
TixImageItem *itPtr = (TixImageItem *)iPtr; |
| 421 |
|
| 422 |
itPtr->stylePtr = (TixImageStyle*)TixGetDefaultDItemStyle( |
| 423 |
itPtr->ddPtr, &tix_ImageItemType, iPtr, NULL); |
| 424 |
|
| 425 |
Tix_ImageItemStyleChanged(iPtr); |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
static void |
| 446 |
ImageProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 447 |
ClientData clientData; |
| 448 |
int x, y; |
| 449 |
|
| 450 |
int width, height; |
| 451 |
|
| 452 |
int imgWidth, imgHeight; |
| 453 |
{ |
| 454 |
TixImageItem *itPtr = (TixImageItem *)clientData; |
| 455 |
|
| 456 |
Tix_ImageItemCalculateSize((Tix_DItem *)itPtr); |
| 457 |
if (itPtr->ddPtr->sizeChangedProc != NULL) { |
| 458 |
itPtr->ddPtr->sizeChangedProc((Tix_DItem *)itPtr); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
static Tix_DItemStyle * |
| 471 |
Tix_ImageStyleCreate(interp, tkwin, diTypePtr, name) |
| 472 |
Tcl_Interp * interp; |
| 473 |
Tk_Window tkwin; |
| 474 |
char * name; |
| 475 |
Tix_DItemInfo * diTypePtr; |
| 476 |
{ |
| 477 |
int i; |
| 478 |
TixImageStyle * stylePtr = |
| 479 |
(TixImageStyle *)ckalloc(sizeof(TixImageStyle)); |
| 480 |
|
| 481 |
stylePtr->pad[0] = 0; |
| 482 |
stylePtr->pad[1] = 0; |
| 483 |
stylePtr->anchor = TK_ANCHOR_CENTER; |
| 484 |
|
| 485 |
for (i=0; i<4; i++) { |
| 486 |
stylePtr->colors[i].bg = NULL; |
| 487 |
stylePtr->colors[i].fg = NULL; |
| 488 |
stylePtr->colors[i].backGC = None; |
| 489 |
stylePtr->colors[i].foreGC = NULL; |
| 490 |
} |
| 491 |
|
| 492 |
return (Tix_DItemStyle *)stylePtr; |
| 493 |
} |
| 494 |
|
| 495 |
static int |
| 496 |
Tix_ImageStyleConfigure(style, argc, argv, flags) |
| 497 |
Tix_DItemStyle *style; |
| 498 |
int argc; |
| 499 |
char ** argv; |
| 500 |
int flags; |
| 501 |
{ |
| 502 |
TixImageStyle * stylePtr = (TixImageStyle *)style; |
| 503 |
XGCValues gcValues; |
| 504 |
GC newGC; |
| 505 |
int i; |
| 506 |
|
| 507 |
if (!(flags &TIX_DONT_CALL_CONFIG)) { |
| 508 |
if (Tk_ConfigureWidget(stylePtr->interp, stylePtr->tkwin, |
| 509 |
imageStyleConfigSpecs, |
| 510 |
argc, argv, (char *)stylePtr, flags) != TCL_OK) { |
| 511 |
return TCL_ERROR; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
gcValues.graphics_exposures = False; |
| 516 |
for (i=0; i<4; i++) { |
| 517 |
|
| 518 |
gcValues.background = stylePtr->colors[i].bg->pixel; |
| 519 |
gcValues.foreground = stylePtr->colors[i].fg->pixel; |
| 520 |
newGC = Tk_GetGC(stylePtr->tkwin, |
| 521 |
GCForeground|GCBackground|GCGraphicsExposures, &gcValues); |
| 522 |
|
| 523 |
if (stylePtr->colors[i].foreGC != None) { |
| 524 |
Tk_FreeGC(Tk_Display(stylePtr->tkwin), |
| 525 |
stylePtr->colors[i].foreGC); |
| 526 |
} |
| 527 |
stylePtr->colors[i].foreGC = newGC; |
| 528 |
|
| 529 |
|
| 530 |
gcValues.foreground = stylePtr->colors[i].bg->pixel; |
| 531 |
newGC = Tk_GetGC(stylePtr->tkwin, |
| 532 |
GCForeground|GCGraphicsExposures, &gcValues); |
| 533 |
|
| 534 |
if (stylePtr->colors[i].backGC != None) { |
| 535 |
Tk_FreeGC(Tk_Display(stylePtr->tkwin), |
| 536 |
stylePtr->colors[i].backGC); |
| 537 |
} |
| 538 |
stylePtr->colors[i].backGC = newGC; |
| 539 |
} |
| 540 |
|
| 541 |
return TCL_OK; |
| 542 |
} |
| 543 |
|
| 544 |
static void Tix_ImageStyleFree(style) |
| 545 |
Tix_DItemStyle *style; |
| 546 |
{ |
| 547 |
TixImageStyle * stylePtr = (TixImageStyle *)style; |
| 548 |
int i; |
| 549 |
|
| 550 |
for (i=0; i<4; i++) { |
| 551 |
if (stylePtr->colors[i].backGC != None) { |
| 552 |
Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].backGC); |
| 553 |
} |
| 554 |
if (stylePtr->colors[i].foreGC != None) { |
| 555 |
Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].foreGC); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
Tk_FreeOptions(imageStyleConfigSpecs, (char *)stylePtr, |
| 560 |
Tk_Display(stylePtr->tkwin), 0); |
| 561 |
ckfree((char *)stylePtr); |
| 562 |
} |
| 563 |
|
| 564 |
static int bg_flags [4] = { |
| 565 |
TIX_DITEM_NORMAL_BG, |
| 566 |
TIX_DITEM_ACTIVE_BG, |
| 567 |
TIX_DITEM_SELECTED_BG, |
| 568 |
TIX_DITEM_DISABLED_BG |
| 569 |
}; |
| 570 |
static int fg_flags [4] = { |
| 571 |
TIX_DITEM_NORMAL_FG, |
| 572 |
TIX_DITEM_ACTIVE_FG, |
| 573 |
TIX_DITEM_SELECTED_FG, |
| 574 |
TIX_DITEM_DISABLED_FG |
| 575 |
}; |
| 576 |
|
| 577 |
static void |
| 578 |
Tix_ImageStyleSetTemplate(style, tmplPtr) |
| 579 |
Tix_DItemStyle* style; |
| 580 |
Tix_StyleTemplate * tmplPtr; |
| 581 |
{ |
| 582 |
TixImageStyle * stylePtr = (TixImageStyle *)style; |
| 583 |
int i; |
| 584 |
|
| 585 |
if (tmplPtr->flags & TIX_DITEM_PADX) { |
| 586 |
stylePtr->pad[0] = tmplPtr->pad[0]; |
| 587 |
} |
| 588 |
if (tmplPtr->flags & TIX_DITEM_PADY) { |
| 589 |
stylePtr->pad[1] = tmplPtr->pad[1]; |
| 590 |
} |
| 591 |
|
| 592 |
for (i=0; i<4; i++) { |
| 593 |
if (tmplPtr->flags & bg_flags[i]) { |
| 594 |
if (stylePtr->colors[i].bg != NULL) { |
| 595 |
Tk_FreeColor(stylePtr->colors[i].bg); |
| 596 |
} |
| 597 |
stylePtr->colors[i].bg = Tk_GetColor( |
| 598 |
stylePtr->interp, stylePtr->tkwin, |
| 599 |
Tk_NameOfColor(tmplPtr->colors[i].bg)); |
| 600 |
} |
| 601 |
} |
| 602 |
for (i=0; i<4; i++) { |
| 603 |
if (tmplPtr->flags & fg_flags[i]) { |
| 604 |
if (stylePtr->colors[i].fg != NULL) { |
| 605 |
Tk_FreeColor(stylePtr->colors[i].fg); |
| 606 |
} |
| 607 |
stylePtr->colors[i].fg = Tk_GetColor( |
| 608 |
stylePtr->interp, stylePtr->tkwin, |
| 609 |
Tk_NameOfColor(tmplPtr->colors[i].fg)); |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
Tix_ImageStyleConfigure(style, 0, 0, TIX_DONT_CALL_CONFIG); |
| 614 |
} |