1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
/* $XdotOrg: xc/programs/xlogo/Logo.c,v 1.2 2004/04/23 19:54:57 eich Exp $ */
/* $Xorg: Logo.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
/*
Copyright 1988, 1994, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
/* $XFree86: xc/programs/xlogo/Logo.c,v 1.6 2002/05/23 23:53:59 keithp Exp $ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <X11/Xmu/Drawing.h>
#include "LogoP.h"
#include <X11/extensions/shape.h>
#include <X11/Xos.h>
#ifdef XRENDER
#include "RenderLogo.h"
#endif
static XtResource resources[] = {
{XtNshapeWindow, XtCShapeWindow, XtRBoolean, sizeof (Boolean),
XtOffsetOf(LogoRec,logo.shape_window), XtRImmediate,
(XtPointer) FALSE},
#ifdef XRENDER
{XtNrender, XtCBoolean, XtRBoolean, sizeof(Boolean),
XtOffsetOf(LogoRec,logo.render), XtRImmediate,
(XtPointer) FALSE },
{XtNsharp, XtCBoolean, XtRBoolean, sizeof(Boolean),
XtOffsetOf(LogoRec,logo.sharp), XtRImmediate,
(XtPointer) FALSE },
{XtNforeground, XtCForeground, XtRXftColor, sizeof(XftColor),
XtOffsetOf(LogoRec, logo.fg), XtRString,
(XtPointer) XtDefaultForeground},
{XtNbackground, XtCForeground, XtRXftColor, sizeof(XftColor),
XtOffsetOf(LogoRec, logo.bg), XtRString,
(XtPointer) XtDefaultBackground},
#else
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
XtOffsetOf(LogoRec,logo.fgpixel), XtRString,
(XtPointer) XtDefaultForeground},
#endif
};
static void ClassInitialize ( void );
static void Initialize ( Widget request, Widget new, ArgList args,
Cardinal *num_args );
static void Destroy ( Widget gw );
static void Realize ( Widget gw, XtValueMask *valuemaskp,
XSetWindowAttributes *attr );
static void Resize ( Widget gw );
static void Redisplay ( Widget gw, XEvent *event, Region region );
static Boolean SetValues ( Widget gcurrent, Widget grequest, Widget gnew,
ArgList args, Cardinal *num_args );
LogoClassRec logoClassRec = {
{ /* core fields */
/* superclass */ (WidgetClass) &simpleClassRec,
/* class_name */ "Logo",
/* widget_size */ sizeof(LogoRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* resource_count */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{ /* simple fields */
/* change_sensitive */ XtInheritChangeSensitive
},
{ /* logo fields */
/* ignore */ 0
}
};
WidgetClass logoWidgetClass = (WidgetClass) &logoClassRec;
/*****************************************************************************
* *
* private utility routines *
* *
*****************************************************************************/
static void
create_gcs(LogoWidget w)
{
XGCValues v;
#ifdef XRENDER
w->logo.fgpixel = w->logo.fg.pixel;
#endif
v.foreground = w->logo.fgpixel;
w->logo.foreGC = XtGetGC ((Widget) w, GCForeground, &v);
v.foreground = w->core.background_pixel;
w->logo.backGC = XtGetGC ((Widget) w, GCForeground, &v);
}
static void
check_shape(LogoWidget w)
{
if (w->logo.shape_window) {
int event_base, error_base;
if (!XShapeQueryExtension (XtDisplay (w), &event_base, &error_base))
w->logo.shape_window = FALSE;
}
}
/* ARGSUSED */
static void
unset_shape(LogoWidget w)
{
XSetWindowAttributes attr;
unsigned long mask;
Display *dpy = XtDisplay ((Widget) w);
Window win = XtWindow ((Widget) w);
if (w->core.background_pixmap != None &&
w->core.background_pixmap != XtUnspecifiedPixmap) {
attr.background_pixmap = w->core.background_pixmap;
mask = CWBackPixmap;
} else {
attr.background_pixel = w->core.background_pixel;
mask = CWBackPixel;
}
XChangeWindowAttributes (dpy, win, mask, &attr);
XShapeCombineMask (dpy, win, ShapeBounding, 0, 0, None, ShapeSet);
if (!w->logo.foreGC) create_gcs (w);
w->logo.need_shaping = w->logo.shape_window;
}
static void
set_shape(LogoWidget w)
{
GC ones, zeros;
Display *dpy = XtDisplay ((Widget) w);
Window win = XtWindow ((Widget) w);
unsigned int width = (unsigned int) w->core.width;
unsigned int height = (unsigned int) w->core.height;
Pixmap pm = XCreatePixmap (dpy, win, width, height, (unsigned int) 1);
XGCValues v;
v.foreground = (Pixel) 1;
v.background = (Pixel) 0;
ones = XCreateGC (dpy, pm, (GCForeground | GCBackground), &v);
v.foreground = (Pixel) 0;
v.background = (Pixel) 1;
zeros = XCreateGC (dpy, pm, (GCForeground | GCBackground), &v);
if (pm && ones && zeros) {
int x = 0, y = 0;
Widget parent;
XmuDrawLogo (dpy, pm, ones, zeros, 0, 0, width, height);
for (parent = (Widget) w; XtParent(parent);
parent = XtParent(parent)) {
x += parent->core.x + parent->core.border_width;
y += parent->core.y + parent->core.border_width;
}
XShapeCombineMask (dpy, XtWindow (parent), ShapeBounding,
x, y, pm, ShapeSet);
w->logo.need_shaping = FALSE;
} else {
unset_shape (w);
}
if (ones) XFreeGC (dpy, ones);
if (zeros) XFreeGC (dpy, zeros);
if (pm) XFreePixmap (dpy, pm);
}
/*****************************************************************************
* *
* class methods *
* *
*****************************************************************************/
#ifdef XRENDER
static void
RenderPrepare (LogoWidget w)
{
if (!w->logo.draw)
{
w->logo.draw = XftDrawCreate (XtDisplay (w), XtWindow (w),
DefaultVisual (XtDisplay (w),
DefaultScreen(XtDisplay (w))),
w->core.colormap);
}
}
static XtConvertArgRec xftColorConvertArgs[] = {
{XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
sizeof(Screen *)},
{XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
sizeof(Colormap)}
};
#define donestr(type, value, tstr) \
{ \
if (toVal->addr != NULL) { \
if (toVal->size < sizeof(type)) { \
toVal->size = sizeof(type); \
XtDisplayStringConversionWarning(dpy, \
(char*) fromVal->addr, tstr); \
return False; \
} \
*(type*)(toVal->addr) = (value); \
} \
else { \
static type static_val; \
static_val = (value); \
toVal->addr = (XPointer)&static_val; \
} \
toVal->size = sizeof(type); \
return True; \
}
static void
XmuFreeXftColor (XtAppContext app, XrmValuePtr toVal, XtPointer closure,
XrmValuePtr args, Cardinal *num_args)
{
Screen *screen;
Colormap colormap;
XftColor *color;
if (*num_args != 2)
{
XtAppErrorMsg (app,
"freeXftColor", "wrongParameters",
"XtToolkitError",
"Freeing an XftColor requires screen and colormap arguments",
(String *) NULL, (Cardinal *)NULL);
return;
}
screen = *((Screen **) args[0].addr);
colormap = *((Colormap *) args[1].addr);
color = (XftColor *) toVal->addr;
XftColorFree (DisplayOfScreen (screen),
DefaultVisual (DisplayOfScreen (screen),
XScreenNumberOfScreen (screen)),
colormap, color);
}
static Boolean
XmuCvtStringToXftColor(Display *dpy,
XrmValue *args, Cardinal *num_args,
XrmValue *fromVal, XrmValue *toVal,
XtPointer *converter_data)
{
char *spec;
XRenderColor renderColor;
XftColor xftColor;
Screen *screen;
Colormap colormap;
if (*num_args != 2)
{
XtAppErrorMsg (XtDisplayToApplicationContext (dpy),
"cvtStringToXftColor", "wrongParameters",
"XtToolkitError",
"String to render color conversion needs screen and colormap arguments",
(String *) NULL, (Cardinal *)NULL);
return False;
}
screen = *((Screen **) args[0].addr);
colormap = *((Colormap *) args[1].addr);
spec = (char *) fromVal->addr;
if (strcasecmp (spec, XtDefaultForeground) == 0)
{
renderColor.red = 0;
renderColor.green = 0;
renderColor.blue = 0;
renderColor.alpha = 0xffff;
}
else if (strcasecmp (spec, XtDefaultBackground) == 0)
{
renderColor.red = 0xffff;
renderColor.green = 0xffff;
renderColor.blue = 0xffff;
renderColor.alpha = 0xffff;
}
else if (!XRenderParseColor (dpy, spec, &renderColor))
return False;
if (!XftColorAllocValue (dpy,
DefaultVisual (dpy,
XScreenNumberOfScreen (screen)),
colormap,
&renderColor,
&xftColor))
return False;
donestr (XftColor, xftColor, XtRXftColor);
}
#endif
static void
ClassInitialize(void)
{
#ifdef XRENDER
XtSetTypeConverter (XtRString, XtRXftColor,
XmuCvtStringToXftColor,
xftColorConvertArgs, XtNumber(xftColorConvertArgs),
XtCacheByDisplay, XmuFreeXftColor);
#endif
}
/* ARGSUSED */
static void
Initialize(Widget request, Widget new, ArgList args, Cardinal *num_args)
{
LogoWidget w = (LogoWidget)new;
#ifdef XRENDER
w->logo.draw = NULL;
w->logo.fgpixel = w->logo.fg.pixel;
#endif
if (w->core.width < 1) w->core.width = 100;
if (w->core.height < 1) w->core.height = 100;
w->logo.foreGC = (GC) NULL;
w->logo.backGC = (GC) NULL;
check_shape (w);
w->logo.need_shaping = w->logo.shape_window;
}
static void
Destroy(Widget gw)
{
LogoWidget w = (LogoWidget) gw;
if (w->logo.foreGC) {
XtReleaseGC (gw, w->logo.foreGC);
w->logo.foreGC = (GC) NULL;
}
if (w->logo.backGC) {
XtReleaseGC (gw, w->logo.backGC);
w->logo.backGC = (GC) NULL;
}
}
static void
Realize(Widget gw, XtValueMask *valuemaskp, XSetWindowAttributes *attr)
{
LogoWidget w = (LogoWidget) gw;
if (w->logo.shape_window) {
attr->background_pixel = w->logo.fgpixel; /* going to shape */
*valuemaskp |= CWBackPixel;
} else
create_gcs (w);
(*logoWidgetClass->core_class.superclass->core_class.realize)
(gw, valuemaskp, attr);
}
static void
Resize(Widget gw)
{
LogoWidget w = (LogoWidget) gw;
if (w->logo.shape_window && XtIsRealized(gw)) set_shape (w);
}
/* ARGSUSED */
static void
Redisplay(Widget gw, XEvent *event, Region region)
{
LogoWidget w = (LogoWidget) gw;
if (w->logo.shape_window) {
if (w->logo.need_shaping) set_shape (w); /* may change shape flag */
}
if (!w->logo.shape_window) {
#ifdef XRENDER
if (w->logo.render)
{
RenderPrepare (w);
XClearWindow (XtDisplay(w), XtWindow(w));
RenderLogo (XtDisplay(w), PictOpOver,
XftDrawSrcPicture (w->logo.draw, &w->logo.fg),
XftDrawPicture (w->logo.draw),
XRenderFindStandardFormat (XtDisplay (w),
w->logo.sharp ?
PictStandardA1:
PictStandardA8),
0, 0, (unsigned int) w->core.width,
(unsigned int) w->core.height);
}
else
#endif
{
XmuDrawLogo (XtDisplay(w), XtWindow(w), w->logo.foreGC, w->logo.backGC,
0, 0, (unsigned int) w->core.width,
(unsigned int) w->core.height);
}
}
}
/* ARGSUSED */
static Boolean
SetValues (Widget gcurrent, Widget grequest, Widget gnew,
ArgList args, Cardinal *num_args)
{
LogoWidget current = (LogoWidget) gcurrent;
LogoWidget new = (LogoWidget) gnew;
Boolean redisplay = FALSE;
if (new->logo.shape_window &&
new->logo.shape_window != current->logo.shape_window)
check_shape (new); /* validate shape_window */
if ((new->logo.fgpixel != current->logo.fgpixel) ||
(new->core.background_pixel != current->core.background_pixel)) {
Destroy (gnew);
if (!new->logo.shape_window) create_gcs (new);
redisplay = TRUE;
}
if (new->logo.shape_window != current->logo.shape_window) {
if (new->logo.shape_window) {
Destroy (gnew);
if (XtIsRealized(gnew))
set_shape (new);
else
new->logo.need_shaping = True;
redisplay = FALSE;
} else {
if (XtIsRealized(gnew))
unset_shape (new); /* creates new GCs */
redisplay = TRUE;
}
}
return (redisplay);
}
|