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
|
/*
Copyright 1988, 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/IntrinsicP.h>
#include <X11/extensions/shape.h>
#include "Converters.h"
#include "Drawing.h"
#include "Misc.h"
/*
* Prototypes
*/
static void ShapeEllipseOrRoundedRectangle(Widget, Bool, int, int);
static void ShapeError(Widget);
static void ShapeOval(Widget);
static void ShapeRectangle(Widget);
/*
* Implementation
*/
Boolean
XmuReshapeWidget(Widget w, int shape_style,
int corner_width, int corner_height)
{
switch (shape_style)
{
case XmuShapeRectangle:
ShapeRectangle(w);
break;
case XmuShapeOval:
ShapeOval(w);
break;
case XmuShapeEllipse:
case XmuShapeRoundedRectangle:
ShapeEllipseOrRoundedRectangle(w, shape_style == XmuShapeEllipse,
corner_width, corner_height);
break;
default:
ShapeError(w);
return (False);
}
return (True);
}
static void
ShapeError(Widget w)
{
String params[1];
Cardinal num_params = 1;
params[0] = XtName(w);
XtAppWarningMsg(XtWidgetToApplicationContext(w),
"shapeUnknown", "xmuReshapeWidget", "XmuLibrary",
"Unsupported shape style for Command widget \"%s\"",
params, &num_params);
}
static void
ShapeRectangle(Widget w)
{
XShapeCombineMask(XtDisplay(w), XtWindow(w),
ShapeBounding, 0, 0, None, ShapeSet);
XShapeCombineMask(XtDisplay(w), XtWindow(w),
ShapeClip, 0, 0, None, ShapeSet);
}
/*
* Function:
* ShapeOval
*
* Parameters:
* w - widget to be reshaped
*
* Description:
* Reshapes a widget to a oval format.
*
* Notes:
* X11R6.3 behaviour changed. Now if the height is larger than the
* width, this function inverts the sense of the oval, instead of
* fallbacking to ellipse.
*/
static void
ShapeOval(Widget w)
{
Display *dpy = XtDisplay(w);
int width = w->core.width;
int height = w->core.height;
Pixmap p;
XGCValues values;
GC gc;
int rad;
if (width < 3 || height < 3)
return;
width += w->core.border_width << 1;
height += w->core.border_width << 1;
p = XCreatePixmap(dpy, XtWindow(w), width, height, 1);
values.foreground = 0;
values.background = 1;
values.cap_style = CapRound;
values.line_width = Min(width, height);
gc = XCreateGC(dpy, p,
GCForeground | GCBackground | GCLineWidth | GCCapStyle,
&values);
XFillRectangle(dpy, p, gc, 0, 0, width, height);
XSetForeground(dpy, gc, 1);
if (width < height)
{
rad = width >> 1;
XDrawLine(dpy, p, gc, rad, rad, rad, height - rad - 1);
}
else
{
rad = height >> 1;
XDrawLine(dpy, p, gc, rad, rad, width - rad - 1, rad);
}
XShapeCombineMask(dpy, XtWindow(w), ShapeBounding,
-(int)w->core.border_width, -(int)w->core.border_width,
p, ShapeSet);
if (w->core.border_width)
{
XSetForeground(dpy, gc, 0);
XFillRectangle(dpy, p, gc, 0, 0, width, height);
values.line_width = Min(w->core.width, w->core.height);
values.foreground = 1;
XChangeGC(dpy, gc, GCLineWidth | GCForeground, &values);
if (w->core.width < w->core.height)
{
rad = w->core.width >> 1;
XDrawLine(dpy, p, gc, rad, rad, rad, w->core.height - rad - 1);
}
else
{
rad = w->core.height >> 1;
XDrawLine(dpy, p, gc, rad, rad, w->core.width - rad - 1, rad);
}
XShapeCombineMask(dpy, XtWindow(w), ShapeClip, 0, 0, p, ShapeSet);
}
else
XShapeCombineMask(XtDisplay(w), XtWindow(w),
ShapeClip, 0, 0, None, ShapeSet);
XFreePixmap(dpy, p);
XFreeGC(dpy, gc);
}
/*
* Function:
* ShapeEllipseOrRoundedRectangle
*
* Parameters:
* w - widget to be reshaped
* ellipse - True if shape to ellise, rounded rectangle otherwise
* ew - horizontal radius of rounded rectangle
* eh - vertical radius of rouded rectangle
*
* Description:
* Based on the ellipse parameter, gives the widget a elliptical
* shape, or rounded rectangle shape.
*
* Notes:
* The GC is created with a line width of 2, what seens to draw the
* widget border correctly, if the width - height is not proportional.
*/
static void
ShapeEllipseOrRoundedRectangle(Widget w, Bool ellipse, int ew, int eh)
{
Display *dpy = XtDisplay(w);
unsigned width = w->core.width;
unsigned height = w->core.height;
Pixmap p;
XGCValues values;
GC gc;
unsigned long mask;
if (width < 3 || width < 3)
return;
width += w->core.border_width << 1;
height += w->core.border_width << 1;
mask = GCForeground | GCLineWidth;
p = XCreatePixmap(dpy, XtWindow(w), width, height, 1);
values.foreground = 0;
values.line_width = 2;
gc = XCreateGC(dpy, p, mask, &values);
XFillRectangle(dpy, p, gc, 0, 0, width, height);
XSetForeground(dpy, gc, 1);
if (!ellipse)
XmuFillRoundedRectangle(dpy, p, gc, 1, 1, width - 2, height - 2, ew, eh);
else
{
XDrawArc(dpy, p, gc, 1, 1, width - 2, height - 2, 0, 360 * 64);
XFillArc(dpy, p, gc, 2, 2, width - 4, height - 4, 0, 360 * 64);
}
XShapeCombineMask(dpy, XtWindow(w), ShapeBounding,
-(int)w->core.border_width, -(int)w->core.border_width,
p, ShapeSet);
if (w->core.border_width)
{
XSetForeground(dpy, gc, 0);
XFillRectangle(dpy, p, gc, 0, 0, width, height);
XSetForeground(dpy, gc, 1);
if (!ellipse)
XmuFillRoundedRectangle(dpy, p, gc, 1, 1,
w->core.width - 2, w->core.height - 2,
ew, eh);
else
XFillArc(dpy, p, gc, 0, 0, w->core.width, w->core.height,
0, 360 * 64);
XShapeCombineMask(dpy, XtWindow(w), ShapeClip, 0, 0, p, ShapeSet);
}
else
XShapeCombineMask(XtDisplay(w), XtWindow(w),
ShapeClip, 0, 0, None, ShapeSet);
XFreePixmap(dpy, p);
XFreeGC(dpy, gc);
}
|