OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [generic/] [tixDiITxt.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixDiImgTxt.c --
3
 *
4
 *      This file implements one of the "Display Items" in the Tix library :
5
 *      Image-text display items.
6
 *
7
 * Copyright (c) 1996, Expert Interface Technologies
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
#include <tixPort.h>
15
#include <tk.h>
16
#include <tixInt.h>
17
#include <tixDef.h>
18
 
19
#define DEF_IMAGETEXTITEM_BITMAP        ""
20
#define DEF_IMAGETEXTITEM_IMAGE         ""
21
#define DEF_IMAGETEXTITEM_TYPE          "imagetext"
22
#define DEF_IMAGETEXTITEM_SHOWIMAGE     "1"
23
#define DEF_IMAGETEXTITEM_SHOWTEXT      "1"
24
#define DEF_IMAGETEXTITEM_STYLE         ""
25
#define DEF_IMAGETEXTITEM_TEXT          ""
26
#define DEF_IMAGETEXTITEM_UNDERLINE     "-1"
27
 
28
static Tk_ConfigSpec imageTextItemConfigSpecs[] = {
29
 
30
    {TK_CONFIG_BITMAP, "-bitmap", "bitmap", "Bitmap",
31
       DEF_IMAGETEXTITEM_BITMAP, Tk_Offset(TixImageTextItem, bitmap),
32
       TK_CONFIG_NULL_OK},
33
 
34
    {TK_CONFIG_STRING, "-image", "image", "Image",
35
       DEF_IMAGETEXTITEM_IMAGE, Tk_Offset(TixImageTextItem, imageString),
36
       TK_CONFIG_NULL_OK},
37
 
38
    {TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType",
39
       DEF_IMAGETEXTITEM_TYPE, Tk_Offset(TixImageTextItem, diTypePtr),
40
       0, &tixConfigItemType},
41
 
42
    {TK_CONFIG_INT, "-showimage", "showImage", "ShowImage",
43
        DEF_IMAGETEXTITEM_SHOWIMAGE, Tk_Offset(TixImageTextItem, showImage), 0},
44
 
45
    {TK_CONFIG_INT, "-showtext", "showText", "ShowText",
46
        DEF_IMAGETEXTITEM_SHOWTEXT, Tk_Offset(TixImageTextItem, showText), 0},
47
 
48
    {TK_CONFIG_CUSTOM, "-style", "imageTextStyle", "ImageTextStyle",
49
       DEF_IMAGETEXTITEM_STYLE, Tk_Offset(TixImageTextItem, stylePtr),
50
       TK_CONFIG_NULL_OK, &tixConfigItemStyle},
51
 
52
    {TK_CONFIG_STRING, "-text", "text", "Text",
53
       DEF_IMAGETEXTITEM_TEXT, Tk_Offset(TixImageTextItem, text),
54
       TK_CONFIG_NULL_OK},
55
 
56
    {TK_CONFIG_INT, "-underline", "underline", "Underline",
57
       DEF_IMAGETEXTITEM_UNDERLINE, Tk_Offset(TixImageTextItem, underline), 0},
58
 
59
    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
60
       (char *) NULL, 0, 0}
61
};
62
 
63
/*----------------------------------------------------------------------
64
 *
65
 *              Configuration options for Text Styles
66
 *
67
 *----------------------------------------------------------------------
68
 */
69
 
70
 
71
#define SELECTED_BG SELECT_BG 
72
#define DISABLED_BG DISABLED  
73
 
74
#define DEF_IMAGETEXTSTYLE_NORMAL_FG_COLOR      BLACK
75
#define DEF_IMAGETEXTSTYLE_NORMAL_FG_MONO       BLACK
76
#define DEF_IMAGETEXTSTYLE_NORMAL_BG_COLOR      NORMAL_BG
77
#define DEF_IMAGETEXTSTYLE_NORMAL_BG_MONO       WHITE
78
 
79
#define DEF_IMAGETEXTSTYLE_ACTIVE_FG_COLOR      BLACK
80
#define DEF_IMAGETEXTSTYLE_ACTIVE_FG_MONO       WHITE
81
#define DEF_IMAGETEXTSTYLE_ACTIVE_BG_COLOR      ACTIVE_BG
82
#define DEF_IMAGETEXTSTYLE_ACTIVE_BG_MONO       BLACK
83
 
84
#define DEF_IMAGETEXTSTYLE_SELECTED_FG_COLOR    BLACK
85
#define DEF_IMAGETEXTSTYLE_SELECTED_FG_MONO     WHITE
86
#define DEF_IMAGETEXTSTYLE_SELECTED_BG_COLOR    SELECTED_BG
87
#define DEF_IMAGETEXTSTYLE_SELECTED_BG_MONO     BLACK
88
 
89
#define DEF_IMAGETEXTSTYLE_DISABLED_FG_COLOR    BLACK
90
#define DEF_IMAGETEXTSTYLE_DISABLED_FG_MONO     BLACK
91
#define DEF_IMAGETEXTSTYLE_DISABLED_BG_COLOR    DISABLED_BG
92
#define DEF_IMAGETEXTSTYLE_DISABLED_BG_MONO     WHITE
93
 
94
#define DEF_IMAGETEXTSTYLE_FONT  CTL_FONT
95
#define DEF_IMAGETEXTSTYLE_GAP          "4"
96
#define DEF_IMAGETEXTSTYLE_PADX         "2"
97
#define DEF_IMAGETEXTSTYLE_PADY         "2"
98
#define DEF_IMAGETEXTSTYLE_JUSTIFY      "left"
99
#define DEF_IMAGETEXTSTYLE_WLENGTH      "0"
100
#define DEF_IMAGETEXTSTYLE_ANCHOR       "w"
101
 
102
 
103
static Tk_ConfigSpec imageTextStyleConfigSpecs[] = {
104
    {TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
105
       DEF_IMAGETEXTSTYLE_ANCHOR, Tk_Offset(TixImageTextStyle, anchor), 0},
106
 
107
    {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
108
       (char *) NULL, 0, 0},
109
    {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
110
       (char *) NULL, 0, 0},
111
 
112
    {TK_CONFIG_FONT, "-font", "font", "Font",
113
       DEF_IMAGETEXTSTYLE_FONT, Tk_Offset(TixImageTextStyle, font), 0},
114
 
115
    {TK_CONFIG_PIXELS, "-gap", "gap", "Gap",
116
       DEF_IMAGETEXTSTYLE_GAP, Tk_Offset(TixImageTextStyle, gap), 0},
117
 
118
    {TK_CONFIG_JUSTIFY, "-justify", "justify", "Justyfy",
119
       DEF_IMAGETEXTSTYLE_JUSTIFY, Tk_Offset(TixImageTextStyle, justify),
120
       TK_CONFIG_NULL_OK},
121
 
122
    {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",
123
       DEF_IMAGETEXTSTYLE_PADX, Tk_Offset(TixImageTextStyle, pad[0]), 0},
124
 
125
    {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",
126
       DEF_IMAGETEXTSTYLE_PADY, Tk_Offset(TixImageTextStyle, pad[1]), 0},
127
 
128
    {TK_CONFIG_PIXELS, "-wraplength", "wrapLength", "WrapLength",
129
       DEF_IMAGETEXTSTYLE_WLENGTH, Tk_Offset(TixImageTextStyle, wrapLength),
130
       0},
131
 
132
/* The following is automatically generated */
133
        {TK_CONFIG_COLOR,"-background","background","Background",
134
        DEF_IMAGETEXTSTYLE_NORMAL_BG_COLOR,
135
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].bg),
136
        TK_CONFIG_COLOR_ONLY},
137
        {TK_CONFIG_COLOR,"-background","background","Background",
138
        DEF_IMAGETEXTSTYLE_NORMAL_BG_MONO,
139
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].bg),
140
        TK_CONFIG_MONO_ONLY},
141
        {TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
142
        DEF_IMAGETEXTSTYLE_NORMAL_FG_COLOR,
143
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].fg),
144
        TK_CONFIG_COLOR_ONLY},
145
        {TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
146
        DEF_IMAGETEXTSTYLE_NORMAL_FG_MONO,
147
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].fg),
148
        TK_CONFIG_MONO_ONLY},
149
        {TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
150
        DEF_IMAGETEXTSTYLE_ACTIVE_BG_COLOR,
151
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].bg),
152
        TK_CONFIG_COLOR_ONLY},
153
        {TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
154
        DEF_IMAGETEXTSTYLE_ACTIVE_BG_MONO,
155
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].bg),
156
        TK_CONFIG_MONO_ONLY},
157
        {TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
158
        DEF_IMAGETEXTSTYLE_ACTIVE_FG_COLOR,
159
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].fg),
160
        TK_CONFIG_COLOR_ONLY},
161
        {TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
162
        DEF_IMAGETEXTSTYLE_ACTIVE_FG_MONO,
163
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].fg),
164
        TK_CONFIG_MONO_ONLY},
165
        {TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
166
        DEF_IMAGETEXTSTYLE_SELECTED_BG_COLOR,
167
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].bg),
168
        TK_CONFIG_COLOR_ONLY},
169
        {TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
170
        DEF_IMAGETEXTSTYLE_SELECTED_BG_MONO,
171
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].bg),
172
        TK_CONFIG_MONO_ONLY},
173
        {TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
174
        DEF_IMAGETEXTSTYLE_SELECTED_FG_COLOR,
175
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].fg),
176
        TK_CONFIG_COLOR_ONLY},
177
        {TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
178
        DEF_IMAGETEXTSTYLE_SELECTED_FG_MONO,
179
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].fg),
180
        TK_CONFIG_MONO_ONLY},
181
        {TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
182
        DEF_IMAGETEXTSTYLE_DISABLED_BG_COLOR,
183
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].bg),
184
        TK_CONFIG_COLOR_ONLY},
185
        {TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
186
        DEF_IMAGETEXTSTYLE_DISABLED_BG_MONO,
187
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].bg),
188
        TK_CONFIG_MONO_ONLY},
189
        {TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
190
        DEF_IMAGETEXTSTYLE_DISABLED_FG_COLOR,
191
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].fg),
192
        TK_CONFIG_COLOR_ONLY},
193
        {TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
194
        DEF_IMAGETEXTSTYLE_DISABLED_FG_MONO,
195
        Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].fg),
196
        TK_CONFIG_MONO_ONLY},
197
 
198
    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
199
       (char *) NULL, 0, 0}
200
};
201
 
202
/*----------------------------------------------------------------------
203
 * Forward declarations for procedures defined later in this file:
204
 *----------------------------------------------------------------------
205
 */
206
static void             ImageProc _ANSI_ARGS_((ClientData clientData,
207
                            int x, int y, int width, int height,
208
                            int imgWidth, int imgHeight));
209
static void             Tix_ImageTextItemCalculateSize  _ANSI_ARGS_((
210
                            Tix_DItem * iPtr));
211
static char *           Tix_ImageTextItemComponent  _ANSI_ARGS_((
212
                            Tix_DItem * iPtr, int x, int y));
213
static int              Tix_ImageTextItemConfigure _ANSI_ARGS_((
214
                            Tix_DItem * iPtr, int argc, char ** argv,
215
                            int flags));
216
static Tix_DItem *      Tix_ImageTextItemCreate _ANSI_ARGS_((
217
                            Tix_DispData * ddPtr, Tix_DItemInfo * diTypePtr));
218
static void             Tix_ImageTextItemDisplay  _ANSI_ARGS_((
219
                            Pixmap pixmap, GC gc, Tix_DItem * iPtr,
220
                            int x, int y, int width, int height, int flag));
221
static void             Tix_ImageTextItemFree  _ANSI_ARGS_((
222
                            Tix_DItem * iPtr));
223
static void             Tix_ImageTextItemLostStyle  _ANSI_ARGS_((
224
                            Tix_DItem * iPtr));
225
static void             Tix_ImageTextItemStyleChanged  _ANSI_ARGS_((
226
                            Tix_DItem * iPtr));
227
static int              Tix_ImageTextStyleConfigure _ANSI_ARGS_((
228
                            Tix_DItemStyle* style, int argc, char ** argv,
229
                            int flags));
230
static Tix_DItemStyle * Tix_ImageTextStyleCreate _ANSI_ARGS_((
231
                            Tcl_Interp *interp, Tk_Window tkwin,
232
                            Tix_DItemInfo * diTypePtr, char * name));
233
static void             Tix_ImageTextStyleFree _ANSI_ARGS_((
234
                            Tix_DItemStyle* style));
235
static void             Tix_ImageTextStyleSetTemplate _ANSI_ARGS_((
236
                            Tix_DItemStyle* style,
237
                            Tix_StyleTemplate * tmplPtr));
238
 
239
Tix_DItemInfo tix_ImageTextItemType = {
240
    "imagetext",                        /* type */
241
    TIX_DITEM_IMAGETEXT,
242
    Tix_ImageTextItemCreate,            /* createProc */
243
    Tix_ImageTextItemConfigure,
244
    Tix_ImageTextItemCalculateSize,
245
    Tix_ImageTextItemComponent,
246
    Tix_ImageTextItemDisplay,
247
    Tix_ImageTextItemFree,
248
    Tix_ImageTextItemStyleChanged,
249
    Tix_ImageTextItemLostStyle,
250
 
251
    Tix_ImageTextStyleCreate,
252
    Tix_ImageTextStyleConfigure,
253
    Tix_ImageTextStyleFree,
254
    Tix_ImageTextStyleSetTemplate,
255
 
256
    imageTextItemConfigSpecs,
257
    imageTextStyleConfigSpecs,
258
    NULL,                               /*next */
259
};
260
 
261
 
262
/*----------------------------------------------------------------------
263
 * Tix_ImageText --
264
 *
265
 *
266
 *----------------------------------------------------------------------
267
 */
268
static Tix_DItem * Tix_ImageTextItemCreate(ddPtr, diTypePtr)
269
    Tix_DispData * ddPtr;
270
    Tix_DItemInfo * diTypePtr;
271
{
272
    TixImageTextItem * itPtr;
273
 
274
    itPtr = (TixImageTextItem*) ckalloc(sizeof(TixImageTextItem));
275
 
276
    itPtr->diTypePtr    = diTypePtr;
277
    itPtr->ddPtr        = ddPtr;
278
    itPtr->stylePtr     = NULL;
279
    itPtr->clientData   = 0;
280
    itPtr->size[0]       = 0;
281
    itPtr->size[1]      = 0;
282
 
283
    itPtr->bitmap       = None;
284
    itPtr->bitmapW      = 0;
285
    itPtr->bitmapH      = 0;
286
 
287
    itPtr->imageString  = NULL;
288
    itPtr->image        = NULL;
289
    itPtr->imageW       = 0;
290
    itPtr->imageH       = 0;
291
 
292
    itPtr->numChars     = 0;
293
    itPtr->text         = NULL;
294
    itPtr->textW        = 0;
295
    itPtr->textH        = 0;
296
    itPtr->underline    = -1;
297
 
298
    itPtr->showImage    = 1;
299
    itPtr->showText     = 1;
300
 
301
    return (Tix_DItem *)itPtr;
302
}
303
 
304
static void Tix_ImageTextItemFree(iPtr)
305
    Tix_DItem * iPtr;
306
{
307
    TixImageTextItem * itPtr = (TixImageTextItem *) iPtr;
308
 
309
    if (itPtr->image) {
310
        Tk_FreeImage(itPtr->image);
311
    }
312
    if (itPtr->stylePtr) {
313
        TixDItemStyleFree(iPtr, (Tix_DItemStyle*)itPtr->stylePtr);
314
    }
315
 
316
    Tk_FreeOptions(imageTextItemConfigSpecs, (char *)itPtr,
317
        itPtr->ddPtr->display, 0);
318
    ckfree((char*)itPtr);
319
}
320
 
321
static int Tix_ImageTextItemConfigure(iPtr, argc, argv, flags)
322
    Tix_DItem * iPtr;
323
    int argc;
324
    char ** argv;
325
    int flags;
326
{
327
    TixImageTextItem * itPtr = (TixImageTextItem *) iPtr;
328
    TixImageTextStyle * oldStyle = itPtr->stylePtr;
329
 
330
    if (Tk_ConfigureWidget(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin,
331
        imageTextItemConfigSpecs,
332
        argc, argv, (char *)itPtr, flags) != TCL_OK) {
333
        return TCL_ERROR;
334
    }
335
    if (itPtr->stylePtr == NULL) {
336
        itPtr->stylePtr = (TixImageTextStyle*)TixGetDefaultDItemStyle(
337
            itPtr->ddPtr, &tix_ImageTextItemType, iPtr, NULL);
338
    }
339
 
340
    /*
341
     * Free the old images for the widget, if there were any.
342
     */
343
    if (itPtr->image != NULL) {
344
        Tk_FreeImage(itPtr->image);
345
        itPtr->image = NULL;
346
    }
347
 
348
    if (itPtr->imageString != NULL) {
349
        itPtr->image = Tk_GetImage(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin,
350
            itPtr->imageString, ImageProc, (ClientData) itPtr);
351
        if (itPtr->image == NULL) {
352
            return TCL_ERROR;
353
        }
354
    }
355
 
356
    if (oldStyle != NULL && itPtr->stylePtr != oldStyle) {
357
        Tix_ImageTextItemStyleChanged(iPtr);
358
    }
359
    else {
360
        Tix_ImageTextItemCalculateSize((Tix_DItem*)itPtr);
361
    }
362
 
363
    return TCL_OK;
364
}
365
 
366
static void Tix_ImageTextItemDisplay(pixmap, gc, iPtr, x, y,
367
        width, height, flags)
368
    Pixmap pixmap;
369
    GC gc;
370
    Tix_DItem * iPtr;
371
    int x;
372
    int y;
373
    int width;
374
    int height;
375
    int flags;
376
{
377
    TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
378
    GC foreGC, backGC;
379
    TixpSubRegion subReg;
380
 
381
    if ((width <= 0) || (height <= 0)) {
382
        return;
383
    }
384
 
385
    TixGetColorDItemGC(iPtr, &backGC, &foreGC, flags);
386
    TixpStartSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC,
387
            &subReg, 0, 0, x, y, width, height,
388
            itPtr->size[0], itPtr->size[1]);
389
    TixDItemGetAnchor(itPtr->stylePtr->anchor, x, y, width, height,
390
        itPtr->size[0], itPtr->size[1], &x, &y);
391
 
392
    if (backGC != None) {
393
        TixpSubRegFillRectangle(itPtr->ddPtr->display, pixmap,
394
                backGC, &subReg, x, y, width, height);
395
    }
396
 
397
    if (itPtr->image != NULL) {
398
        int bitY;
399
 
400
        bitY = itPtr->size[1] - itPtr->imageH - 2*itPtr->stylePtr->pad[1];
401
 
402
        if (bitY > 0) {
403
            bitY = bitY / 2 + (bitY %2);
404
        } else {
405
            bitY = 0;
406
        }
407
        if (itPtr->showImage) {
408
            TixpSubRegDrawImage(&subReg, itPtr->image, 0, 0,
409
                    itPtr->imageW, itPtr->imageH, pixmap,
410
                    x + itPtr->stylePtr->pad[0],
411
                    y + itPtr->stylePtr->pad[1] + bitY);
412
        }
413
        x += itPtr->imageW + itPtr->stylePtr->gap;
414
    }
415
    else if (itPtr->bitmap != None && foreGC != None) {
416
        int bitY;
417
 
418
        bitY = itPtr->size[1] - itPtr->bitmapH - 2*itPtr->stylePtr->pad[1];
419
        if (bitY > 0) {
420
            bitY = bitY / 2 + (bitY %2);
421
        } else {
422
            bitY = 0;
423
        }
424
 
425
        if (itPtr->showImage) {
426
            TixpSubRegDrawBitmap(itPtr->ddPtr->display, pixmap, foreGC,
427
                    &subReg, itPtr->bitmap, 0, 0,
428
                    itPtr->bitmapW, itPtr->bitmapH,
429
                    x + itPtr->stylePtr->pad[0],
430
                    y + itPtr->stylePtr->pad[1] + bitY,
431
                    1);
432
        }
433
        x += itPtr->bitmapW + itPtr->stylePtr->gap;
434
    }
435
 
436
    if (itPtr->text && itPtr->showText && foreGC != None) {
437
        int textY;
438
 
439
        textY = itPtr->size[1] - itPtr->textH - 2*itPtr->stylePtr->pad[1];
440
        if (textY > 0) {
441
            textY = textY / 2 + (textY %2);
442
        } else {
443
            textY = 0;
444
        }
445
 
446
        TixpSubRegDisplayText(itPtr->ddPtr->display, pixmap,  foreGC, &subReg,
447
                itPtr->stylePtr->font, itPtr->text, itPtr->numChars,
448
                x + itPtr->stylePtr->pad[0],
449
                y + itPtr->stylePtr->pad[1] + textY,
450
                itPtr->textW,
451
                itPtr->stylePtr->justify,
452
                itPtr->underline);
453
    }
454
 
455
    TixpEndSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC,
456
            &subReg);
457
}
458
 
459
static void Tix_ImageTextItemCalculateSize(iPtr)
460
    Tix_DItem * iPtr;
461
{
462
    TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
463
 
464
    itPtr->size[0] = 0;
465
    itPtr->size[1] = 0;
466
 
467
    /* Note: the size of the image or the text are used even when
468
     * the showImage or showText options are off. These two options are
469
     * used to "blank" the respective components temporarily without
470
     * affecting the geometry of the ditem. The main is to indicate
471
     * transfer during drag+drop.
472
     *
473
     * If you want the image or text to completely disappear, config them
474
     * to NULL
475
     */
476
    if (itPtr->image != NULL) {
477
        Tk_SizeOfImage(itPtr->image, &itPtr->imageW, &itPtr->imageH);
478
 
479
        itPtr->size[0] = itPtr->imageW + itPtr->stylePtr->gap;
480
        itPtr->size[1] = itPtr->imageH;
481
    }
482
    else if (itPtr->bitmap != None) {
483
        Tk_SizeOfBitmap(itPtr->ddPtr->display, itPtr->bitmap, &itPtr->bitmapW,
484
                &itPtr->bitmapH);
485
 
486
        itPtr->size[0] = itPtr->bitmapW + itPtr->stylePtr->gap;
487
        itPtr->size[1] = itPtr->bitmapH;
488
    }
489
 
490
    if (itPtr->text) {
491
        itPtr->numChars = strlen(itPtr->text);
492
        TixComputeTextGeometry(itPtr->stylePtr->font, itPtr->text,
493
                itPtr->numChars, itPtr->stylePtr->wrapLength,
494
                &itPtr->textW, &itPtr->textH);
495
 
496
        itPtr->size[0] += itPtr->textW;
497
 
498
        if (itPtr->textH > itPtr->size[1]) {
499
            itPtr->size[1] = itPtr->textH;
500
        }
501
    }
502
 
503
    itPtr->size[0] += 2*itPtr->stylePtr->pad[0];
504
    itPtr->size[1] += 2*itPtr->stylePtr->pad[1];
505
}
506
 
507
static char * Tix_ImageTextItemComponent(iPtr, x, y)
508
    Tix_DItem * iPtr;
509
    int x;
510
    int y;
511
{
512
    /* Unimplemented */
513
#if 0
514
    TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
515
#endif
516
 
517
    static char * body = "body";
518
 
519
    return body;
520
}
521
 
522
 
523
static void Tix_ImageTextItemStyleChanged(iPtr)
524
    Tix_DItem * iPtr;
525
{
526
    TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
527
 
528
    if (itPtr->stylePtr == NULL) {
529
        /* Maybe we haven't set the style to default style yet */
530
        return;
531
    }
532
    Tix_ImageTextItemCalculateSize(iPtr);
533
    if (itPtr->ddPtr->sizeChangedProc != NULL) {
534
        itPtr->ddPtr->sizeChangedProc(iPtr);
535
    }
536
}
537
static void Tix_ImageTextItemLostStyle(iPtr)
538
    Tix_DItem * iPtr;
539
{
540
    TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
541
 
542
    itPtr->stylePtr = (TixImageTextStyle*)TixGetDefaultDItemStyle(
543
        itPtr->ddPtr, &tix_ImageTextItemType, iPtr, NULL);
544
 
545
    Tix_ImageTextItemStyleChanged(iPtr);
546
}
547
 
548
/*
549
 *----------------------------------------------------------------------
550
 *
551
 * ImageProc --
552
 *
553
 *      This procedure is invoked by the image code whenever the manager
554
 *      for an image does something that affects the size of contents
555
 *      of an image displayed in this widget.
556
 *
557
 * Results:
558
 *      None.
559
 *
560
 * Side effects:
561
 *      Arranges for the HList to get redisplayed.
562
 *
563
 *----------------------------------------------------------------------
564
 */
565
static void
566
ImageProc(clientData, x, y, width, height, imgWidth, imgHeight)
567
    ClientData clientData;              /* Pointer to widget record. */
568
    int x, y;                           /* Upper left pixel (within image)
569
                                         * that must be redisplayed. */
570
    int width, height;                  /* Dimensions of area to redisplay
571
                                         * (may be <= 0). */
572
    int imgWidth, imgHeight;            /* New dimensions of image. */
573
{
574
    TixImageTextItem *itPtr = (TixImageTextItem *)clientData;
575
 
576
    Tix_ImageTextItemCalculateSize((Tix_DItem *)itPtr);
577
    if (itPtr->ddPtr->sizeChangedProc != NULL) {
578
        itPtr->ddPtr->sizeChangedProc((Tix_DItem *)itPtr);
579
    }
580
}
581
 
582
/*----------------------------------------------------------------------
583
 *
584
 *
585
 *                      Display styles
586
 *
587
 *
588
 *----------------------------------------------------------------------
589
 */
590
static Tix_DItemStyle *
591
Tix_ImageTextStyleCreate(interp, tkwin, diTypePtr, name)
592
    Tcl_Interp * interp;
593
    Tk_Window tkwin;
594
    char * name;
595
    Tix_DItemInfo * diTypePtr;
596
{
597
    int i;
598
    TixImageTextStyle * stylePtr =
599
      (TixImageTextStyle *)ckalloc(sizeof(TixImageTextStyle));
600
 
601
    stylePtr->font       = NULL;
602
    stylePtr->gap        = 0;
603
    stylePtr->justify    = TK_JUSTIFY_LEFT;
604
    stylePtr->wrapLength = 0;
605
    stylePtr->pad[0]      = 0;
606
    stylePtr->pad[1]     = 0;
607
    stylePtr->anchor     = TK_ANCHOR_CENTER;
608
 
609
    for (i=0; i<4; i++) {
610
        stylePtr->colors[i].bg = NULL;
611
        stylePtr->colors[i].fg = NULL;
612
        stylePtr->colors[i].backGC = None;
613
        stylePtr->colors[i].foreGC = NULL;
614
    }
615
 
616
    return (Tix_DItemStyle *)stylePtr;
617
}
618
 
619
static int
620
Tix_ImageTextStyleConfigure(style, argc, argv, flags)
621
    Tix_DItemStyle *style;
622
    int argc;
623
    char ** argv;
624
    int flags;
625
{
626
    TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
627
    XGCValues gcValues;
628
    GC newGC;
629
    int i, isNew;
630
 
631
    if (stylePtr->font == NULL) {
632
        isNew = 1;
633
    } else {
634
        isNew = 0;
635
    }
636
 
637
    if (!(flags &TIX_DONT_CALL_CONFIG)) {
638
        if (Tk_ConfigureWidget(stylePtr->interp, stylePtr->tkwin,
639
            imageTextStyleConfigSpecs,
640
            argc, argv, (char *)stylePtr, flags) != TCL_OK) {
641
            return TCL_ERROR;
642
        }
643
    }
644
 
645
    gcValues.font = TixFontId(stylePtr->font);
646
    gcValues.graphics_exposures = False;
647
 
648
    for (i=0; i<4; i++) {
649
        /* Foreground */
650
        gcValues.background = stylePtr->colors[i].bg->pixel;
651
        gcValues.foreground = stylePtr->colors[i].fg->pixel;
652
        newGC = Tk_GetGC(stylePtr->tkwin,
653
            GCFont|GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
654
 
655
        if (stylePtr->colors[i].foreGC != None) {
656
            Tk_FreeGC(Tk_Display(stylePtr->tkwin),
657
                stylePtr->colors[i].foreGC);
658
        }
659
        stylePtr->colors[i].foreGC = newGC;
660
 
661
        /* Background */
662
        gcValues.foreground = stylePtr->colors[i].bg->pixel;
663
        newGC = Tk_GetGC(stylePtr->tkwin,
664
            GCFont|GCForeground|GCGraphicsExposures, &gcValues);
665
 
666
        if (stylePtr->colors[i].backGC != None) {
667
            Tk_FreeGC(Tk_Display(stylePtr->tkwin),
668
                stylePtr->colors[i].backGC);
669
        }
670
        stylePtr->colors[i].backGC = newGC;
671
    }
672
 
673
    if (!isNew) {
674
        TixDItemStyleChanged(stylePtr->diTypePtr, (Tix_DItemStyle *)stylePtr);
675
    }
676
 
677
    return TCL_OK;
678
}
679
 
680
static void Tix_ImageTextStyleFree(style)
681
    Tix_DItemStyle *style;
682
{
683
    TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
684
    int i;
685
 
686
    for (i=0; i<4; i++) {
687
        if (stylePtr->colors[i].backGC != None) {
688
            Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].backGC);
689
        }
690
        if (stylePtr->colors[i].foreGC != None) {
691
            Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].foreGC);
692
        }
693
    }
694
 
695
    Tk_FreeOptions(imageTextStyleConfigSpecs, (char *)stylePtr,
696
        Tk_Display(stylePtr->tkwin), 0);
697
    ckfree((char *)stylePtr);
698
}
699
 
700
static int bg_flags [4] = {
701
    TIX_DITEM_NORMAL_BG,
702
    TIX_DITEM_ACTIVE_BG,
703
    TIX_DITEM_SELECTED_BG,
704
    TIX_DITEM_DISABLED_BG
705
};
706
static int fg_flags [4] = {
707
    TIX_DITEM_NORMAL_FG,
708
    TIX_DITEM_ACTIVE_FG,
709
    TIX_DITEM_SELECTED_FG,
710
    TIX_DITEM_DISABLED_FG
711
};
712
 
713
static void
714
Tix_ImageTextStyleSetTemplate(style, tmplPtr)
715
    Tix_DItemStyle* style;
716
    Tix_StyleTemplate * tmplPtr;
717
{
718
    TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
719
    int i;
720
 
721
    if (tmplPtr->flags & TIX_DITEM_FONT) {
722
        if (stylePtr->font != NULL) {
723
            TixFreeFont(stylePtr->font);
724
        }
725
        stylePtr->font = TixGetFont(
726
            stylePtr->interp, stylePtr->tkwin,
727
            TixNameOfFont(tmplPtr->font));
728
    }
729
    if (tmplPtr->flags & TIX_DITEM_PADX) {
730
        stylePtr->pad[0] = tmplPtr->pad[0];
731
    }
732
    if (tmplPtr->flags & TIX_DITEM_PADY) {
733
        stylePtr->pad[1] = tmplPtr->pad[1];
734
    }
735
 
736
    for (i=0; i<4; i++) {
737
        if (tmplPtr->flags & bg_flags[i]) {
738
            if (stylePtr->colors[i].bg != NULL) {
739
                Tk_FreeColor(stylePtr->colors[i].bg);
740
            }
741
            stylePtr->colors[i].bg = Tk_GetColor(
742
                stylePtr->interp, stylePtr->tkwin,
743
                Tk_NameOfColor(tmplPtr->colors[i].bg));
744
        }
745
    }
746
    for (i=0; i<4; i++) {
747
        if (tmplPtr->flags & fg_flags[i]) {
748
            if (stylePtr->colors[i].fg != NULL) {
749
                Tk_FreeColor(stylePtr->colors[i].fg);
750
            }
751
            stylePtr->colors[i].fg = Tk_GetColor(
752
                stylePtr->interp, stylePtr->tkwin,
753
                Tk_NameOfColor(tmplPtr->colors[i].fg));
754
        }
755
    }
756
 
757
    Tix_ImageTextStyleConfigure(style, 0, 0, TIX_DONT_CALL_CONFIG);
758
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.