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