Debian Codegraph @

gdraw/ggroupbox.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "gdraw.h"
31 #include "ggadgetP.h"
32
33 GBox _GGroup_LineBox = GBOX_EMPTY; /* Don't initialize here */
34 static GBox group_box = GBOX_EMPTY; /* Don't initialize here */
35
36 static GGadgetCreateData gline_gcd[] = {
37 { GLineCreate, { { 0, 0, 100, 0 }, NULL, 0, 0, 0, 0, 0, NULL, { NULL }, gg_visible|gg_enabled, NULL, NULL }, NULL, NULL }
38 };
39 static GGadgetCreateData *larray[] = { GCD_Glue, &gline_gcd[0], GCD_Glue, NULL, NULL };
40 static GGadgetCreateData linebox =
41 { GHVGroupCreate, { { 2, 2, 0, 0 }, NULL, 0, 0, 0, 0, 0, NULL, { (GTextInfo *) larray }, gg_visible|gg_enabled, NULL, NULL }, NULL, NULL };
42 extern GResInfo ghvbox_ri;
43 static GResInfo gline_ri = {
44 &ghvbox_ri, &ggadget_ri, NULL, NULL,
45 &_GGroup_LineBox,
46 NULL,
47 &linebox,
48 NULL,
49 N_("Line"),
50 N_("A separator line drawn across a dialog or in a menu"),
51 "GLine",
52 "Gdraw",
53 false,
54 false,
55 omf_border_type|omf_border_shape|omf_padding,
56 { bt_engraved, bs_rect, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 },
57 GBOX_EMPTY,
58 NULL,
59 NULL,
60 NULL
61 };
62 GResInfo ggroup_ri = {
63 &gline_ri, &ggadget_ri, NULL, NULL,
64 &group_box,
65 NULL,
66 NULL,
67 NULL,
68 N_("Group"),
69 N_("A grouping of elements"),
70 "GGroup",
71 "Gdraw",
72 false,
73 false,
74 omf_border_type|omf_border_shape|omf_padding|omf_main_background|omf_disabled_background,
75 { bt_engraved, bs_rect, 0, 0, 0, 0, 0, 0, 0, 0, COLOR_TRANSPARENT, 0, COLOR_TRANSPARENT, 0, 0 ,0 ,0 ,0 ,0 },
76 GBOX_EMPTY,
77 NULL,
78 NULL,
79 NULL
80 };
81
82 void _GGroup_Init(void) {
83 GResEditDoInit(&ggroup_ri);
84 GResEditDoInit(&gline_ri);
85 }
86
87 static int ggroup_expose(GWindow pixmap, GGadget *g, GEvent *event) {
88 GRect old1, border;
89
90 if ( g->state == gs_invisible )
91 return( false );
92
93 GDrawPushClip(pixmap,&g->r,&old1);
94 /* Background should be transpearant */
95 /*GBoxDrawBackground(pixmap,&g->r,g->box, g->state,false);*/
96 border = g->r;
97 if ( g->prevlabel ) {
98 int off = (g->prev->r.height-GBoxBorderWidth(g->base,g->box))/2;
99 border.y += off; border.height -= off;
100 }
101 GBoxDrawBorder(pixmap,&border,g->box,g->state,false);
102
103 GDrawPopClip(pixmap,&old1);
104 return( true );
105 }
106
107 static int gline_expose(GWindow pixmap, GGadget *g, GEvent *event) {
108 GRect old1;
109
110 if ( g->state == gs_invisible )
111 return( false );
112
113 GDrawPushClip(pixmap,&g->r,&old1);
114 if ( g->vert )
115 GBoxDrawVLine(pixmap,&g->r,g->box);
116 else
117 GBoxDrawHLine(pixmap,&g->r,g->box);
118 GDrawPopClip(pixmap,&old1);
119 return( true );
120 }
121
122 static void GGroupGetDesiredSize(GGadget *g, GRect *outer, GRect *inner) {
123 if ( outer!=NULL ) {
124 int bp = GBoxBorderWidth(g->base,g->box);
125 outer->x = outer->y = 0;
126 outer->width = outer->height = 2*bp+2;
127 if ( g->desired_width>0 ) outer->width = g->desired_width;
128 if ( g->desired_height>0 ) outer->height = g->desired_height;
129 }
130 if ( inner!=NULL ) {
131 inner->x = inner->y = 0;
132 inner->width = inner->height = 1;
133 }
134 }
135
136 struct gfuncs gline_funcs = {
137 0,
138 sizeof(struct gfuncs),
139
140 gline_expose,
141 _ggadget_noop,
142 _ggadget_noop,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
147
148 _ggadget_redraw,
149 _ggadget_move,
150 _ggadget_resize,
151 _ggadget_setvisible,
152 _ggadget_setenabled,
153 _ggadget_getsize,
154 _ggadget_getinnersize,
155
156 _ggadget_destroy,
157
158 NULL,
159 NULL,
160 NULL,
161 NULL,
162 NULL,
163
164 NULL,
165 NULL,
166
167 NULL,
168 NULL,
169 NULL,
170 NULL,
171 NULL,
172 NULL,
173 NULL,
174 NULL,
175 NULL,
176 NULL,
177 NULL,
178
179 GGroupGetDesiredSize,
180 _ggadget_setDesiredSize,
181 NULL,
182 NULL
183 };
184
185 struct gfuncs ggroup_funcs = {
186 0,
187 sizeof(struct gfuncs),
188
189 ggroup_expose,
190 _ggadget_noop,
191 _ggadget_noop,
192 NULL,
193 NULL,
194 NULL,
195 NULL,
196
197 _ggadget_redraw,
198 _ggadget_move,
199 _ggadget_resize,
200 _ggadget_setvisible,
201 _ggadget_setenabled,
202 _ggadget_getsize,
203 _ggadget_getinnersize,
204
205 _ggadget_destroy,
206
207 NULL,
208 NULL,
209 NULL,
210 NULL,
211 NULL,
212
213 NULL,
214 NULL,
215
216 NULL,
217 NULL,
218 NULL,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 NULL,
224 NULL,
225 NULL,
226 NULL,
227
228 GGroupGetDesiredSize,
229 _ggadget_setDesiredSize,
230 NULL,
231 NULL
232 };
233
234 static void GLineFit(GGadget *g) {
235 int bp = GBoxBorderWidth(g->base,g->box);
236
237 if ( g->r.width==0 && !g->vert ) {
238 GRect size;
239 GDrawGetSize(g->base,&size);
240 g->r.width = size.width - g->r.x - GDrawPointsToPixels(g->base,_GGadget_Skip);
241 }
242 if ( g->r.height==0 && !g->vert )
243 g->r.height = bp;
244 if ( g->r.width==0 && g->vert )
245 g->r.width = bp;
246 g->inner = g->r;
247 g->inner.width = g->inner.height = 0;
248 }
249
250 static void GGroupFit(GGadget *g) {
251 int bp = GBoxBorderWidth(g->base,g->box);
252
253 if ( g->r.width==0 || g->r.height==0 )
254 g->opengroup = true;
255 g->inner = g->r;
256 g->inner.x += bp;
257 if ( g->prevlabel )
258 g->inner.y += (g->prev->r.height-bp)/2 + bp;
259 else
260 g->inner.y += bp;
261 if ( g->r.width != 0 )
262 g->inner.width = g->r.width - 2*bp;
263 if ( g->r.height != 0 )
264 g->inner.height = g->r.y + g->r.height - bp - g->inner.y;
265 }
266
267 GGadget *GLineCreate(struct gwindow *base, GGadgetData *gd,void *data) {
268 GGadget *g = calloc(1,sizeof(GLine));
269
270 _GGroup_Init();
271 g->funcs = &gline_funcs;
272 _GGadget_Create(g,base,gd,data,&_GGroup_LineBox);
273 if ( gd->flags & gg_line_vert )
274 g->vert = true;
275
276 GLineFit(g);
277 _GGadget_FinalPosition(g,base,gd);
278 return( g );
279 }
280
281 GGadget *GGroupCreate(struct gwindow *base, GGadgetData *gd,void *data) {
282 GGadget *g = calloc(1,sizeof(GGroup));
283
284 _GGroup_Init();
285 g->funcs = &ggroup_funcs;
286 _GGadget_Create(g,base,gd,data,&group_box);
287
288 if ( (gd->flags&gg_group_prevlabel) && g->prev!=NULL )
289 g->prevlabel = true;
290 if ( g->prevlabel && gd->pos.x==0 )
291 g->r.x = g->prev->r.x - GDrawPointsToPixels(base,_GGadget_Skip);
292 GGroupFit(g);
293 _GGadget_FinalPosition(g,base,gd);
294 return( g );
295 }