Debian Codegraph @

gdraw/ggadgets.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 "basics.h"
31 #include "ffglib.h"
32 #include "gdraw.h"
33 #include "ggadgetP.h"
34 #include "gkeysym.h"
35 #include "gresource.h"
36 #include "gwidget.h"
37 #include "ustring.h"
38 #include "utype.h"
39
40 GBox _ggadget_Default_Box = { bt_raised, bs_rect, 2, 2, 0, 0,
41 COLOR_CREATE(0xd8,0xd8,0xd8), /* border left */ /* brightest */
42 COLOR_CREATE(0xd0,0xd0,0xd0), /* border top */
43 COLOR_CREATE(0x80,0x80,0x80), /* border right */
44 COLOR_CREATE(0x66,0x66,0x66), /* border bottom */ /* darkest */
45 COLOR_DEFAULT, /* normal background */
46 COLOR_DEFAULT, /* normal foreground */
47 COLOR_CREATE(0xd8,0xd8,0xd8), /* disabled background */
48 COLOR_CREATE(0x66,0x66,0x66), /* disabled foreground */
49 COLOR_CREATE(0xff,0xff,0x00), /* active border */
50 COLOR_CREATE(0xa0,0xa0,0xa0), /* pressed background */
51 COLOR_CREATE(0x00,0x00,0x00), /* gradient bg end */
52 COLOR_CREATE(0x00,0x00,0x00), /* border inner */
53 COLOR_CREATE(0x00,0x00,0x00), /* border outer */
54 };
55 GBox _GListMark_Box = GBOX_EMPTY; /* Don't initialize here */
56 GResFont _ggadget_default_font = GRESFONT_INIT("400 10pt " SANS_UI_FAMILIES);
57 GResFont popup_font = GRESFONT_INIT("400 8pt " SANS_UI_FAMILIES);
58 int _GListMarkSize = 12;
59 GResImage _GListMark_Image = GRESIMAGE_INIT("downarrow.png");
60 GResImage _GListMark_DisImage = GRESIMAGE_INIT("downarrow_disabled.png");
61 static int _GGadget_FirstLine = 6;
62 static int _GGadget_LeftMargin = 6;
63 static int _GGadget_LineSkip = 3;
64 int _GGadget_Skip = 6;
65 int _GGadget_TextImageSkip = 4;
66 static Color popup_foreground=0, popup_background=COLOR_CREATE(0xff,0xff,0xc0);
67 static int popup_delay=1000, popup_lifetime=20000;
68 static char *_GGadget_ImagePathRes;
69
70 static int GGadgetRIInit(GResInfo *ri) {
71 if ( ri->is_initialized )
72 return false;
73
74 ri->overrides.main_background = GDrawGetDefaultBackground(NULL);
75 ri->overrides.main_foreground = GDrawGetDefaultForeground(NULL);
76 _GResEditInitialize(ri);
77 return true;
78 }
79
80 static void *_GGadgetImagePathResSet(char *res, void *def) {
81 GGadgetSetImagePath(res);
82 return res;
83 }
84
85 static struct resed ggadget_re[] = {
86 {N_("Skip"), "Skip", rt_int, &_GGadget_Skip, N_("Space (in points) to skip between gadget elements"), NULL, { 0 }, 0, 0 },
87 {N_("Line Skip"), "LineSkip", rt_int, &_GGadget_LineSkip, N_("Space (in points) to skip after a line"), NULL, { 0 }, 0, 0 },
88 {N_("First Line Skip"), "FirstLine", rt_int, &_GGadget_FirstLine, N_("Space (in points) before a line when it is the first element"), NULL, { 0 }, 0, 0 },
89 {N_("Left Margin"), "LeftMargin", rt_int, &_GGadget_LeftMargin, N_("The default left margin (in points)"), NULL, { 0 }, 0, 0 },
90 {N_("Text Image Skip"), "TextImageSkip", rt_int, &_GGadget_TextImageSkip, N_("Space (in points) left between images and text in any labels, buttons, menu items, etc. that have both"), NULL, { 0 }, 0, 0 },
91 {N_("Image Path"), "ImagePath", rt_stringlong, &_GGadget_ImagePathRes, N_("List of directories to search for images, separated by colons"), _GGadgetImagePathResSet, { 0 }, 0, 0 },
92 RESED_EMPTY
93 };
94 GResInfo ggadget2_ri = {
95 &listmark_ri, NULL,NULL, NULL,
96 NULL,
97 NULL,
98 NULL,
99 ggadget_re,
100 N_("GGadget 2"),
101 N_("More configuration parameters for the \"abstract\" gadget."),
102 "GGadget",
103 "Gdraw",
104 false,
105 false,
106 0,
107 GBOX_EMPTY,
108 GBOX_EMPTY,
109 NULL,
110 NULL,
111 NULL
112 };
113 GResInfo ggadget_ri = {
114 &ggadget2_ri, NULL,NULL, NULL,
115 &_ggadget_Default_Box,
116 &_ggadget_default_font,
117 NULL,
118 NULL,
119 N_("GGadget"),
120 N_("This is an \"abstract\" gadget. It will never appear on the screen\nbut it is the root of gadget tree from which all others inherit"),
121 "GGadget",
122 "Gdraw",
123 false,
124 false,
125 omf_main_foreground|omf_main_background,
126 GBOX_EMPTY,
127 GBOX_EMPTY,
128 NULL,
129 GGadgetRIInit,
130 NULL
131 };
132 static struct resed popup_re[] = {
133 {N_("Color|Foreground"), "Foreground", rt_color, &popup_foreground, N_("Text color for popup windows"), NULL, { 0 }, 0, 0 },
134 {N_("Color|Background"), "Background", rt_color, &popup_background, N_("Background color for popup windows"), NULL, { 0 }, 0, 0 },
135 {N_("Delay"), "Delay", rt_int, &popup_delay, N_("Delay (in milliseconds) before popup windows appear"), NULL, { 0 }, 0, 0 },
136 {N_("Life Time"), "LifeTime", rt_int, &popup_lifetime, N_("Time (in milliseconds) that popup windows remain visible"), NULL, { 0 }, 0, 0 },
137 RESED_EMPTY
138 };
139 static void popup_refresh(void);
140 extern GResInfo gprogress_ri;
141 GResInfo gpopup_ri = {
142 &gprogress_ri, NULL, NULL,NULL,
143 NULL, /* No box */
144 &popup_font,
145 NULL,
146 popup_re,
147 N_("Popup"),
148 N_("Popup windows"),
149 "GGadget.Popup",
150 "Gdraw",
151 false,
152 false,
153 omf_refresh,
154 GBOX_EMPTY,
155 GBOX_EMPTY,
156 popup_refresh,
157 NULL,
158 NULL
159 };
160 static struct resed listmark_re[] = {
161 { N_("Image"), "Image", rt_image, &_GListMark_Image, N_("Image used for enabled listmarks (overrides the box)"), NULL, { 0 }, 0, 0 },
162 { N_("Disabled Image"), "DisabledImage", rt_image, &_GListMark_DisImage, N_("Image used for disabled listmarks (overrides the box)"), NULL, { 0 }, 0, 0 },
163 { N_("Width"), "Width", rt_int, &_GListMarkSize, N_("Size of the list mark"), NULL, { 0 }, 0, 0 },
164 RESED_EMPTY
165 };
166 static GTextInfo list_choices[] = {
167 { (unichar_t *) "1", NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
168 { (unichar_t *) "2", NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
169 { (unichar_t *) "3", NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
170 GTEXTINFO_EMPTY
171 };
172 static GGadgetCreateData droplist_gcd[] = {
173 { GListFieldCreate, { {0, 0, 80, 0 }, NULL, 0, 0, 0, 0, 0, &list_choices[0], { list_choices }, gg_visible, NULL, NULL }, NULL, NULL },
174 { GListFieldCreate, { {0, 0, 80, 0 }, NULL, 0, 0, 0, 0, 0, &list_choices[1], { list_choices }, gg_visible|gg_enabled, NULL, NULL }, NULL, NULL }
175 };
176 static GGadgetCreateData *dlarray[] = { GCD_Glue, &droplist_gcd[0], GCD_Glue, &droplist_gcd[1], GCD_Glue, NULL, NULL };
177 static GGadgetCreateData droplistbox =
178 { GHVGroupCreate, { { 2, 2, 0, 0 }, NULL, 0, 0, 0, 0, 0, NULL, { (GTextInfo *) dlarray }, gg_visible|gg_enabled, NULL, NULL }, NULL, NULL };
179 extern GResInfo glabel_ri;
180 GResInfo listmark_ri = {
181 &glabel_ri, &ggadget_ri, NULL,NULL,
182 &_GListMark_Box, /* No box */
183 NULL,
184 &droplistbox,
185 listmark_re,
186 N_("List Mark"),
187 N_("This is the mark that differentiates ComboBoxes and ListButtons\n"
188 "from TextFields and normal Buttons." ),
189 "GListMark",
190 "Gdraw",
191 false,
192 false,
193 omf_border_width|omf_padding,
194 { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
195 GBOX_EMPTY,
196 NULL,
197 NULL,
198 NULL
199 };
200
201
202 static GWindow popup;
203 static GTimer *popup_timer, *popup_vanish_timer;
204 static int popup_visible = false;
205
206 void GGadgetInit(void) {
207 GResEditDoInit(&ggadget_ri);
208 GResEditDoInit(&ggadget2_ri);
209 GResEditDoInit(&gpopup_ri);
210 GResEditDoInit(&listmark_ri);
211 GTabSetInit();
212 }
213
214 void GListMarkDraw(GWindow pixmap,int x, int y, int height, enum gadget_state state ) {
215 GRect r, old;
216 GImage *mi, *mdi;
217 int gmsize = GDrawPointsToPixels(pixmap,_GListMarkSize);
218 if ( (mi=GResImageGetImage(&_GListMark_Image))!=NULL ) {
219 int size = GImageGetWidth(mi);
220 if ( size>gmsize )
221 gmsize = size;
222 }
223 int marklen = gmsize;
224
225 if ( state == gs_disabled && (mdi=GResImageGetImage(&_GListMark_DisImage))!=NULL) {
226 GDrawDrawScaledImage(pixmap,mdi,x,
227 y + (height-GImageGetScaledHeight(pixmap,mdi))/2);
228 } else if ( mi!=NULL ) {
229 GDrawDrawScaledImage(pixmap,mi,x,
230 y + (height-GImageGetScaledHeight(pixmap,mi))/2);
231 } else {
232 r.x = x; r.width = marklen;
233 r.height = 2*GDrawPointsToPixels(pixmap,_GListMark_Box.border_width) +
234 GDrawPointsToPixels(pixmap,3);
235 r.y = y + (height-r.height)/2;
236 GDrawPushClip(pixmap,&r,&old);
237
238 GBoxDrawBackground(pixmap,&r,&_GListMark_Box, state,false);
239 GBoxDrawBorder(pixmap,&r,&_GListMark_Box,state,false);
240 GDrawPopClip(pixmap,&old);
241 }
242 }
243
244 static struct popup_info {
245 const unichar_t *msg;
246 GImage *img;
247 const void *data;
248 GImage *(*get_image)(const void *data);
249 void (*free_image)(const void *data,GImage *img);
250 GWindow gw;
251 } popup_info;
252
253 void GGadgetEndPopup() {
254 if ( popup_visible ) {
255 GDrawSetVisible(popup,false);
256 popup_visible = false;
257 }
258 if ( popup_timer!=NULL ) {
259 GDrawCancelTimer(popup_timer);
260 popup_timer = NULL;
261 }
262 if ( popup_vanish_timer!=NULL ) {
263 GDrawCancelTimer(popup_vanish_timer);
264 popup_vanish_timer = NULL;
265 }
266 if ( popup_info.img!=NULL ) {
267 if ( popup_info.free_image!=NULL )
268 (popup_info.free_image)(popup_info.data,popup_info.img);
269 else
270 GImageDestroy(popup_info.img);
271 }
272
273 memset(&popup_info,0,sizeof(popup_info));
274 }
275
276 void GGadgetPopupExternalEvent(GEvent *e) {
277 /* Depress control key to keep popup alive */
278 if ( e->type == et_char &&
279 ( e->u.chr.keysym == GK_Control_L || e->u.chr.keysym == GK_Control_R )) {
280 if ( popup_vanish_timer!=NULL ) {
281 GDrawCancelTimer(popup_vanish_timer);
282 popup_vanish_timer = NULL;
283 }
284 return;
285 }
286 if ( e->type==et_char || e->type==et_charup || e->type==et_mousemove ||
287 e->type == et_mousedown || e->type==et_mouseup ||
288 e->type==et_destroy || (e->type==et_create && popup!=e->w))
289 GGadgetEndPopup();
290 }
291
292 static int GGadgetPopupTest(GEvent *e) {
293 unichar_t *msg;
294 int lines, temp, width;
295 GWindow root = GDrawGetRoot(GDrawGetDisplayOfWindow(popup));
296 GRect pos, size;
297 unichar_t *pt, *ept;
298 int as, ds, ld, img_height=0;
299 GEvent where;
300
301 if ( e->type!=et_timer || e->u.timer.timer!=popup_timer || popup==NULL )
302 return( false );
303 popup_timer = NULL;
304
305 /* Is the cursor still in the original window? */
306 if (!GDrawWindowIsAncestor(popup_info.gw, GDrawGetPointerWindow(popup_info.gw)))
307 return true;
308
309 lines = 0; width = 1;
310 if ( popup_info.img==NULL && popup_info.get_image!=NULL ) {
311 popup_info.img = (popup_info.get_image)(popup_info.data);
312 popup_info.get_image = NULL;
313 }
314 if ( popup_info.img!=NULL ) {
315 img_height = GImageGetHeight(popup_info.img);
316 width = GImageGetWidth(popup_info.img);
317 }
318 pt = msg = (unichar_t *) popup_info.msg;
319 if ( msg!=NULL ) {
320 GDrawSetFont(popup,popup_font.fi);
321 do {
322 temp = -1;
323 if (( ept = u_strchr(pt,'\n'))!=NULL )
324 temp = ept-pt;
325 temp = GDrawGetTextWidth(popup,pt,temp);
326 if ( temp>width ) width = temp;
327 ++lines;
328 pt = ept+1;
329 } while ( ept!=NULL && *pt!='\0' );
330 }
331 GDrawWindowFontMetrics(popup,popup_font.fi,&as, &ds, &ld);
332 pos.width = width+2*GDrawPointsToPixels(popup,2);
333 pos.height = lines*(as+ds) + img_height + 2*GDrawPointsToPixels(popup,2);
334
335 GDrawGetPointerPosition(root,&where);
336 pos.x = where.u.mouse.x+10; pos.y = where.u.mouse.y+10;
337 GDrawGetSize(root,&size);
338 if ( pos.x + pos.width > size.width )
339 pos.x = (pos.x - 20 - pos.width );
340 if ( pos.x<0 ) pos.x = 0;
341 if ( pos.y + pos.height > size.height )
342 pos.y = (pos.y - 20 - pos.height );
343 if ( pos.y<0 ) pos.y = 0;
344 GDrawMoveResize(popup,pos.x,pos.y,pos.width,pos.height);
345 GDrawSetVisible(popup,true);
346 GDrawRaise(popup);
347 GDrawSetUserData(popup,msg);
348 popup_vanish_timer = GDrawRequestTimer(popup,popup_lifetime,0,NULL);
349 return( true );
350 }
351
352 static int msgpopup_eh(GWindow popup,GEvent *event) {
353 if ( event->type == et_expose ) {
354 unichar_t *msg, *pt, *ept;
355 int x,y, fh, temp;
356 int as, ds, ld;
357
358 popup_visible = true;
359 pt = msg = (unichar_t *) popup_info.msg;
360 if ( (pt==NULL || *pt=='\0') && popup_info.img==NULL ) {
361 GGadgetEndPopup();
362 return( true );
363 }
364 y = x = GDrawPointsToPixels(popup,2);
365 if ( popup_info.img!=NULL ) {
366 GDrawDrawImage(popup,popup_info.img,NULL,x,y);
367 y += GImageGetHeight(popup_info.img);
368 }
369 if ( pt!=NULL ) {
370 GDrawWindowFontMetrics(popup,popup_font.fi,&as, &ds, &ld);
371 fh = as+ds;
372 y += as;
373 while ( *pt!='\0' ) {
374 /* Find end of this line, if multiline text */
375 if (( ept = u_strchr(pt,'\n'))!=NULL )
376 temp = ept-pt; /* display next segment of multiline text */
377 else
378 temp = -1; /* last line, so display remainder of text */
379 GDrawDrawText(popup,x,y,pt,temp,popup_foreground);
380 y += fh;
381 pt = ept+1;
382 if ( ept==NULL )
383 break;
384 }
385 }
386 } else if ( event->type == et_timer && event->u.timer.timer==popup_timer ) {
387 GGadgetPopupTest(event);
388 } else if ( event->type == et_mousemove || event->type == et_mouseup ||
389 event->type == et_mousedown || event->type == et_char ||
390 event->type == et_timer || event->type == et_crossing ) {
391 GGadgetEndPopup();
392 }
393 return( true );
394 }
395
396 void GGadgetPreparePopupImage(GWindow base,const unichar_t *msg, const void *data,
397 GImage *(*get_image)(const void *data),
398 void (*free_image)(const void *data,GImage *img)) {
399
400 GGadgetEndPopup();
401 if ( msg==NULL && get_image==NULL )
402 return;
403
404 memset(&popup_info,0,sizeof(popup_info));
405 popup_info.msg = msg;
406 popup_info.data = data;
407 popup_info.get_image = get_image;
408 popup_info.free_image = free_image;
409 popup_info.gw = base;
410
411 if ( popup==NULL ) {
412 GWindowAttrs pattrs;
413 GRect pos;
414
415 pattrs.mask = wam_events|wam_nodecor|wam_positioned|wam_cursor|wam_backcol/*|wam_transient*/;
416 pattrs.event_masks = -1;
417 pattrs.nodecoration = true;
418 pattrs.positioned = true;
419 pattrs.cursor = ct_pointer;
420 pattrs.background_color = popup_background;
421 /*pattrs.transient = GWidgetGetTopWidget(base);*/
422 pos.x = pos.y = 0; pos.width = pos.height = 1;
423 popup = GDrawCreateTopWindow(GDrawGetDisplayOfWindow(base),&pos,
424 msgpopup_eh,NULL,&pattrs);
425 GDrawSetFont(popup,popup_font.fi);
426 }
427 popup_timer = GDrawRequestTimer(popup,popup_delay,0,(void *) msg);
428 }
429
430 static void popup_refresh(void) {
431 if ( popup!=NULL ) {
432 GDrawSetWindowBackground(popup,popup_background);
433 }
434 }
435
436 void GGadgetPreparePopup(GWindow base,const unichar_t *msg) {
437 GGadgetPreparePopupImage(base,msg,NULL,NULL,NULL);
438 }
439
440 void GGadgetPreparePopup8(GWindow base, const char *msg) {
441 static unichar_t popup_msg[500];
442 utf82u_strncpy(popup_msg,msg,sizeof(popup_msg)/sizeof(popup_msg[0]));
443 popup_msg[sizeof(popup_msg)/sizeof(popup_msg[0])-1]=0;
444 GGadgetPreparePopupImage(base,popup_msg,NULL,NULL,NULL);
445 }
446
447 void _ggadget_redraw(GGadget *g) {
448 GDrawRequestExpose(g->base, &g->r, false);
449 }
450
451 int _ggadget_noop(GGadget *g, GEvent *event) {
452 return( false );
453 }
454
455 static void GBoxFigureRect(GWindow gw, GBox *design, GRect *r, int isdef) {
456 int scale = GDrawPointsToPixels(gw,1);
457 int bp = GDrawPointsToPixels(gw,design->border_width)+
458 GDrawPointsToPixels(gw,design->padding)+
459 ((design->flags & box_foreground_border_outer)?scale:0)+
460 ((design->flags &
461 (box_foreground_border_inner|box_active_border_inner))?scale:0)+
462 (isdef && (design->flags & box_draw_default)?scale+GDrawPointsToPixels(gw,2):0);
463 r->width += 2*bp;
464 r->height += 2*bp;
465 }
466
467 static void GBoxFigureDiamond(GWindow gw, GBox *design, GRect *r, int isdef) {
468 int scale = GDrawPointsToPixels(gw,1);
469 int p = GDrawPointsToPixels(gw,design->padding);
470 int b = GDrawPointsToPixels(gw,design->border_width)+
471 ((design->flags & box_foreground_border_outer)?scale:0)+
472 ((design->flags &
473 (box_foreground_border_inner|box_active_border_inner))?scale:0)+
474 (isdef && (design->flags & box_draw_default)?scale+GDrawPointsToPixels(gw,2):0);
475 int xoff = r->width/2, yoff = r->height/2;
476
477 if ( xoff<2*p ) xoff = 2*p;
478 if ( yoff<2*p ) yoff = 2*p;
479 r->width += 2*b+xoff;
480 r->height += 2*b+yoff;
481 }
482
483 void _ggadgetFigureSize(GWindow gw, GBox *design, GRect *r, int isdef) {
484 /* given that we want something with a client rectangle as big as r */
485 /* Then given the box shape, figure out how much of a rectangle we */
486 /* need around it */
487
488 if ( r->width<=0 ) r->width = 1;
489 if ( r->height<=0 ) r->height = 1;
490
491 switch ( design->border_shape ) {
492 case bs_rect:
493 GBoxFigureRect(gw,design,r,isdef);
494 break;
495 case bs_roundrect:
496 GBoxFigureRect(gw,design,r,isdef);
497 break;
498 case bs_elipse:
499 GBoxFigureDiamond(gw,design,r,isdef);
500 break;
501 case bs_diamond:
502 GBoxFigureDiamond(gw,design,r,isdef);
503 break;
504 }
505 }
506
507 void _ggadgetSetRects(GGadget *g, GRect *outer, GRect *inner, int xjust, int yjust) {
508 int bp = GBoxBorderWidth(g->base,g->box);
509
510
511 if ( g->r.width==0 )
512 g->r.width = outer->width;
513 if ( g->r.height==0 )
514 g->r.height = outer->height;
515
516 if ( g->inner.width==0 ) {
517 if ( inner->width<g->r.width ) {
518 g->inner.width = g->r.width - 2*bp;
519 if ( xjust==-1 )
520 g->inner.x = g->r.x + bp;
521 else if ( xjust==0 ) {
522 g->inner.x = g->r.x + (g->r.width-inner->width)/2;
523 g->inner.width = inner->width;
524 } else
525 g->inner.x = g->r.x + (g->r.width-bp-g->inner.width);
526 } else {
527 g->inner.x = g->r.x;
528 g->inner.width = g->r.width;
529 }
530 }
531 if ( g->inner.height==0 ) {
532 if ( inner->height<g->r.height ) {
533 if ( yjust==-1 )
534 g->inner.y = g->r.y + bp;
535 else if ( yjust==0 )
536 g->inner.y = g->r.y + (g->r.height-inner->height)/2;
537 else
538 g->inner.y = g->r.y + (g->r.height-bp-inner->height);
539 g->inner.height = inner->height;
540 } else {
541 g->inner.y = g->r.y;
542 g->inner.height = g->r.height;
543 }
544 }
545 }
546
547 static GGadget *GGadgetFindLastOpenGroup(GGadget *g) {
548 for ( g=g->prev; g!=NULL && !g->opengroup; g = g->prev );
549 return( g );
550 }
551
552 static int GGadgetLMargin(GGadget *sigh, GGadget *lastOpenGroup) {
553 if ( lastOpenGroup==NULL )
554 return( GDrawPointsToPixels(sigh->base,_GGadget_LeftMargin));
555 else
556 return( lastOpenGroup->r.x + GDrawPointsToPixels(lastOpenGroup->base,_GGadget_Skip));
557 }
558
559 int GGadgetScale(int xpos) {
560 return( xpos*GIntGetResource(_NUM_ScaleFactor)/100 );
561 }
562
563 GGadget *_GGadget_Create(GGadget *g, struct gwindow *base, GGadgetData *gd,void *data, GBox *def) {
564 GGadget *last, *lastopengroup;
565
566 g->desired_width = g->desired_height = -1;
567 _GWidget_AddGGadget(base,g);
568 g->r = gd->pos;
569 if ( !(gd->flags&gg_pos_in_pixels) ) {
570 g->r.x = GDrawPointsToPixels(base,g->r.x);
571 g->r.y = GDrawPointsToPixels(base,g->r.y);
572 if ( g->r.width!=-1 )
573 g->r.width = GDrawPointsToPixels(base,g->r.width);
574 if ( !(gd->flags&gg_pos_use0)) {
575 g->r.x = GGadgetScale(g->r.x);
576 if ( g->r.width!=-1 )
577 g->r.width = GGadgetScale(g->r.width);
578 }
579 g->r.height = GDrawPointsToPixels(base,g->r.height);
580 }
581 if ( gd->pos.width>0 ) g->desired_width = g->r.width;
582 if ( gd->pos.height>0 ) g->desired_height = g->r.height;
583 last = g->prev;
584 lastopengroup = GGadgetFindLastOpenGroup(g);
585 if ( g->r.y==0 && !(gd->flags & gg_pos_use0)) {
586 if ( last==NULL ) {
587 g->r.y = GDrawPointsToPixels(base,_GGadget_FirstLine);
588 if ( g->r.x==0 )
589 g->r.x = GGadgetLMargin(g,lastopengroup);
590 } else if ( gd->flags & gg_pos_newline ) {
591 int temp, y = last->r.y, nexty = last->r.y+last->r.height;
592 while ( last!=NULL && last->r.y==y ) {
593 temp = last->r.y+last->r.height;
594 if ( temp>nexty ) nexty = temp;
595 last = last->prev;
596 }
597 g->r.y = nexty + GDrawPointsToPixels(base,_GGadget_LineSkip);
598 if ( g->r.x==0 )
599 g->r.x = GGadgetLMargin(g,lastopengroup);
600 } else {
601 g->r.y = last->r.y;
602 }
603 }
604 if ( g->r.x == 0 && !(gd->flags & gg_pos_use0)) {
605 last = g->prev;
606 if ( last==NULL )
607 g->r.x = GGadgetLMargin(g,lastopengroup);
608 else if ( gd->flags & gg_pos_under ) {
609 int onthisline=0, onprev=0, i;
610 GGadget *prev, *prevline;
611 /* see if we can find a gadget on the previous line that has the */
612 /* same number of gadgets between it and the start of the line */
613 /* as this one has from the start of its line, then put at the */
614 /* same x offset */
615 for ( prev = last; prev!=NULL && prev->r.y==g->r.y; prev = prev->prev )
616 ++onthisline;
617 prevline = prev;
618 for ( ; prev!=NULL && prev->r.y==prevline->r.y ; prev = prev->prev )
619 onprev++;
620 for ( prev = prevline, i=0; prev!=NULL && i<onprev-onthisline; prev = prev->prev);
621 if ( prev!=NULL )
622 g->r.x = prev->r.x;
623 }
624 if ( g->r.x==0 )
625 g->r.x = last->r.x + last->r.width + GDrawPointsToPixels(base,_GGadget_Skip);
626 }
627
628 g->mnemonic = islower(gd->mnemonic)?toupper(gd->mnemonic):gd->mnemonic;
629 g->shortcut = islower(gd->shortcut)?toupper(gd->shortcut):gd->shortcut;
630 g->short_mask = gd->short_mask;
631 g->cid = gd->cid;
632 g->data = data;
633 g->popup_msg = utf82u_copy(gd->popup_msg);
634 g->handle_controlevent = gd->handle_controlevent;
635 if ( gd->box == NULL )
636 g->box = def;
637 else if ( gd->flags & gg_dontcopybox )
638 g->box = gd->box;
639 else {
640 g->free_box = true;
641 g->box = malloc(sizeof(GBox));
642 *g->box = *gd->box;
643 }
644 g->state = !(gd->flags&gg_visible) ? gs_invisible :
645 !(gd->flags&gg_enabled) ? gs_disabled :
646 gs_enabled;
647 if ( !(gd->flags&gg_enabled) ) g->was_disabled = true;
648 return( g );
649 }
650
651 void _GGadget_FinalPosition(GGadget *g, struct gwindow *base, GGadgetData *gd) {
652 if ( g->r.x<0 && !(gd->flags&gg_pos_use0)) {
653 GRect size;
654 GDrawGetSize(base,&size);
655 g->r.x += size.width-g->r.width;
656 g->inner.x += size.width-g->r.width;
657 }
658 }
659
660 void _ggadget_destroy(GGadget *g) {
661 if ( g==NULL )
662 return;
663 _GWidget_RemoveGadget(g);
664 GGadgetEndPopup();
665 if ( g->free_box )
666 free( g->box );
667 free(g->popup_msg);
668 free(g);
669 }
670
671 void _GGadgetCloseGroup(GGadget *g) {
672 GGadget *group = GGadgetFindLastOpenGroup(g);
673 GGadget *prev;
674 int maxx=0, maxy=0, temp;
675 int bp = GBoxBorderWidth(g->base,g->box);
676
677 if ( group==NULL )
678 return;
679 for ( prev=g ; prev!=group; prev = prev->prev ) {
680 temp = prev->r.x + prev->r.width;
681 if ( temp>maxx ) maxx = temp;
682 temp = prev->r.y + prev->r.height;
683 if ( temp>maxy ) maxy = temp;
684 }
685 if ( group->prevlabel ) {
686 prev = group->prev;
687 temp = prev->r.x + prev->r.width;
688 if ( temp>maxx ) maxx = temp;
689 temp = prev->r.y + prev->r.height/2 ;
690 if ( temp>maxy ) maxy = temp;
691 }
692 maxx += GDrawPointsToPixels(g->base,_GGadget_Skip);
693 maxy += GDrawPointsToPixels(g->base,_GGadget_LineSkip);
694
695 if ( group->r.width==0 ) {
696 group->r.width = maxx - group->r.x;
697 group->inner.width = group->r.width - 2*bp;
698 }
699 if ( group->r.height==0 ) {
700 group->r.height = maxy - group->r.y;
701 group->inner.height = group->r.y + group->r.height - bp -
702 group->inner.y;
703 }
704 group->opengroup = false;
705 }
706
707 int GGadgetWithin(GGadget *g, int x, int y) {
708 register GRect *r = &g->r;
709
710 if ( x<r->x || y<r->y || x>=r->x+r->width || y>=r->y+r->height )
711 return( false );
712
713 return( true );
714 }
715
716 int GGadgetInnerWithin(GGadget *g, int x, int y) {
717 register GRect *r = &g->inner;
718
719 if ( x<r->x || y<r->y || x>=r->x+r->width || y>=r->y+r->height )
720 return( false );
721
722 return( true );
723 }
724
725 void _ggadget_underlineMnemonic(GWindow gw,int32_t x,int32_t y,unichar_t *label,
726 unichar_t mnemonic, Color fg, int maxy) {
727 int point = GDrawPointsToPixels(gw,1);
728 int width;
729 /*GRect clip;*/
730
731 if ( mnemonic=='\0' )
732 return;
733 char *ctext = u2utf8_copy(label);
734 char *cpt = utf8_strchr(ctext,mnemonic);
735 GRect space;
736 if ( cpt==NULL && isupper(mnemonic))
737 cpt = utf8_strchr(ctext,tolower(mnemonic));
738 if ( cpt==NULL )
739 return;
740 GDrawLayoutInit(gw,ctext,-1,NULL);
741 GDrawLayoutIndexToPos(gw, cpt-ctext, &space);
742 free(ctext);
743 x += space.x;
744 width = space.width;
745 GDrawSetLineWidth(gw,point);
746 y += 2*point;
747 if ( y+point-1 >= maxy )
748 y = maxy-point;
749 GDrawDrawLine(gw,x,y,x+width,y,fg);
750 GDrawSetLineWidth(gw,0);
751 }
752
753 void _ggadget_move(GGadget *g, int32_t x, int32_t y ) {
754 g->inner.x = x+(g->inner.x-g->r.x);
755 g->inner.y = y+(g->inner.y-g->r.y);
756 g->r.x = x;
757 g->r.y = y;
758 }
759
760 void _ggadget_resize(GGadget *g, int32_t width, int32_t height ) {
761 g->inner.width = width-(g->r.width-g->inner.width);
762 g->inner.height = height-(g->r.height-g->inner.height);
763 g->r.width = width;
764 g->r.height = height;
765 }
766
767 void _ggadget_getDesiredSize(GGadget *g, GRect *outer, GRect *inner) {
768
769 if ( inner!=NULL ) {
770 inner->x = inner->y = 0;
771 inner->width = g->desired_width;
772 inner->height = g->desired_height;
773 }
774 if ( outer!=NULL ) {
775 outer->x = outer->y = 0;
776 outer->width = g->desired_width;
777 outer->height = g->desired_height;
778 }
779 }
780
781 void _ggadget_setDesiredSize(GGadget *g,GRect *outer, GRect *inner) {
782 int bp = GBoxBorderWidth(g->base,g->box);
783
784 if ( outer!=NULL ) {
785 g->desired_width = outer->width;
786 g->desired_height = outer->height;
787 } else if ( inner!=NULL ) {
788 g->desired_width = inner->width<=0 ? -1 : inner->width+2*bp;
789 g->desired_height = inner->height<=0 ? -1 : inner->height+2*bp;
790 }
791 }
792
793 GRect *_ggadget_getsize(GGadget *g,GRect *rct) {
794 *rct = g->r;
795 return( rct );
796 }
797
798 GRect *_ggadget_getinnersize(GGadget *g,GRect *rct) {
799 *rct = g->inner;
800 return( rct );
801 }
802
803 void _ggadget_setvisible(GGadget *g,int visible) {
804 g->state = !visible ? gs_invisible :
805 g->was_disabled ? gs_disabled :
806 gs_enabled;
807 /* Make sure it isn't the focused _ggadget in the container !!!! */
808 _ggadget_redraw(g);
809 }
810
811 void _ggadget_setenabled(GGadget *g,int enabled) {
812 g->was_disabled = !enabled;
813 if ( g->state!=gs_invisible ) {
814 g->state = enabled? gs_enabled : gs_disabled;
815 _ggadget_redraw(g);
816 }
817 /* Make sure it isn't the focused _ggadget in the container !!!! */
818 }
819
820 void GGadgetDestroy(GGadget *g) {
821 (g->funcs->destroy)(g);
822 }
823
824 void GGadgetRedraw(GGadget *g) {
825 (g->funcs->redraw)(g);
826 }
827
828 void GGadgetMove(GGadget *g,int32_t x, int32_t y ) {
829 (g->funcs->move)(g,x,y);
830 }
831
832 void GGadgetMoveAddToY(GGadget *g, int32_t yoffset )
833 {
834 GRect sz;
835 GGadgetGetSize( g, &sz );
836 GGadgetMove( g, sz.x, sz.y + yoffset );
837 }
838
839
840
841 int32_t GGadgetGetX(GGadget *g)
842 {
843 return g->r.x;
844 }
845
846 int32_t GGadgetGetY(GGadget *g)
847 {
848 return g->r.y;
849 }
850
851 void GGadgetSetY(GGadget *g, int32_t y )
852 {
853 int32_t x = GGadgetGetX(g);
854 GGadgetMove( g, x, y );
855 }
856
857
858
859 void GGadgetResize(GGadget *g,int32_t width, int32_t height ) {
860 (g->funcs->resize)(g,width,height);
861 }
862
863 GRect *GGadgetGetSize(GGadget *g,GRect *rct) {
864 return( (g->funcs->getsize)(g,rct) );
865 }
866
867 void GGadgetSetSize(GGadget *g,GRect *rct)
868 {
869 GGadgetResize(g,rct->width,rct->height);
870 }
871
872
873 int GGadgetContainsEventLocation(GGadget *g, GEvent* e )
874 {
875 switch( e->type )
876 {
877 case et_mousemove:
878 case et_mouseup: case et_mousedown:
879 return( GGadgetContains( g, e->u.mouse.x, e->u.mouse.y ));
880 default: break;
881 }
882
883 return 0;
884 }
885
886 int GGadgetContains(GGadget *g, int x, int y )
887 {
888 GRect r;
889 GGadgetGetSize( g, &r );
890 return r.x < x && r.x+r.width > x
891 && r.y < y && r.y+r.height > y;
892 }
893
894 GRect *GGadgetGetInnerSize(GGadget *g,GRect *rct) {
895 return( (g->funcs->getinnersize)(g,rct) );
896 }
897
898 void GGadgetSetVisible(GGadget *g,int visible) {
899 (g->funcs->setvisible)(g,visible);
900 }
901
902 int GGadgetIsVisible(GGadget *g) {
903 return( g->state!=gs_invisible );
904 }
905
906 void GGadgetSetEnabled(GGadget *g,int enabled) {
907 if(g)
908 (g->funcs->setenabled)(g,enabled);
909 }
910
911 int GGadgetIsEnabled(GGadget *g) {
912 if ( g->state==gs_invisible )
913 return( !g->was_disabled );
914 return( g->state==gs_enabled );
915 }
916
917 void GGadgetSetUserData(GGadget *g,void *data) {
918 g->data = data;
919 }
920
921 void GGadgetSetPopupMsg(GGadget *g,const unichar_t *msg) {
922 free(g->popup_msg);
923 g->popup_msg = u_copy(msg);
924 }
925
926 GWindow GGadgetGetWindow(GGadget *g) {
927 return( g->base );
928 }
929
930 int GGadgetGetCid(GGadget *g) {
931 return( g->cid );
932 }
933
934 void *GGadgetGetUserData(GGadget *g) {
935 return( g->data );
936 }
937
938 int GGadgetEditCmd(GGadget *g,enum editor_commands cmd) {
939 if ( g->funcs->handle_editcmd!=NULL )
940 return(g->funcs->handle_editcmd)(g,cmd);
941 return( false );
942 }
943
944 void GGadgetSetTitle(GGadget *g,const unichar_t *title) {
945 if ( g->funcs->set_title!=NULL )
946 (g->funcs->set_title)(g,title);
947 }
948
949 void GGadgetSetTitle8(GGadget *g,const char *title) {
950 if ( g->funcs->set_title!=NULL ) {
951 unichar_t *temp = utf82u_copy(title);
952 (g->funcs->set_title)(g,temp);
953 free(temp);
954 }
955 }
956
957 void GGadgetSetTitle8WithMn(GGadget *g,const char *title) {
958 char *pt = strchr(title,'_');
959 char *freeme=NULL;
960 int mnc;
961
962 if ( pt!=NULL ) {
963 char *pos = pt+1;
964 mnc = utf8_ildb((const char **) &pos);
965 g->mnemonic = mnc;
966 freeme = copy(title);
967 for ( pt = freeme + (pt-title); *pt; ++pt )
968 *pt = pt[1];
969 title = freeme;
970 } else
971 g->mnemonic = 0;
972 GGadgetSetTitle8(g,title);
973 free(freeme);
974 }
975
976 const unichar_t *_GGadgetGetTitle(GGadget *g) {
977 if ( g && g->funcs->_get_title!=NULL ) return( (g->funcs->_get_title)(g) );
978
979 return( NULL );
980 }
981
982 unichar_t *GGadgetGetTitle(GGadget *g) {
983 if ( g ) {
984 if ( g->funcs->get_title!=NULL )
985 return( (g->funcs->get_title)(g) );
986 else if ( g->funcs->_get_title!=NULL )
987 return( u_copy( (g->funcs->_get_title)(g) ));
988 }
989
990 return( NULL );
991 }
992
993 char *GGadgetGetTitle8(GGadget *g) {
994 if ( g->funcs->_get_title!=NULL )
995 return( u2utf8_copy( (g->funcs->_get_title)(g) ));
996 else if ( g->funcs->get_title!=NULL ) {
997 unichar_t *temp = (g->funcs->get_title)(g);
998 char *ret = u2utf8_copy(temp);
999 free(temp);
1000 return( ret );
1001 }
1002
1003 return( NULL );
1004 }
1005
1006 void GGadgetSetFont(GGadget *g,GFont *font) {
1007 if ( g->funcs->set_font!=NULL )
1008 (g->funcs->set_font)(g,font);
1009 }
1010
1011 GFont *GGadgetGetFont(GGadget *g) {
1012 if ( g==NULL )
1013 return( _ggadget_default_font.fi );
1014 if ( g->funcs->get_font!=NULL )
1015 return( (g->funcs->get_font)(g) );
1016
1017 return( NULL );
1018 }
1019
1020 void GGadgetSetHandler(GGadget *g, GGadgetHandler handler) {
1021 g->handle_controlevent = handler;
1022 }
1023
1024 GGadgetHandler GGadgetGetHandler(GGadget *g) {
1025 return( g->handle_controlevent );
1026 }
1027
1028 void GGadgetClearList(GGadget *g) {
1029 if ( g->funcs->clear_list!=NULL )
1030 (g->funcs->clear_list)(g);
1031 }
1032
1033 void GGadgetSetList(GGadget *g, GTextInfo **ti, int32_t copyit) {
1034 if ( g->funcs->set_list!=NULL )
1035 (g->funcs->set_list)(g,ti,copyit);
1036 }
1037
1038 GTextInfo **GGadgetGetList(GGadget *g,int32_t *len) {
1039 if ( g->funcs->get_list!=NULL )
1040 return((g->funcs->get_list)(g,len));
1041
1042 if ( len!=NULL ) *len = 0;
1043 return( NULL );
1044 }
1045
1046 GTextInfo *GGadgetGetListItem(GGadget *g,int32_t pos) {
1047 if ( g->funcs->get_list_item!=NULL )
1048 return((g->funcs->get_list_item)(g,pos));
1049
1050 return( NULL );
1051 }
1052
1053 GTextInfo *GGadgetGetListItemSelected(GGadget *g) {
1054 int pos = GGadgetGetFirstListSelectedItem(g);
1055
1056 if ( pos!=-1 && g->funcs->get_list_item!=NULL )
1057 return((g->funcs->get_list_item)(g,pos));
1058
1059 return( NULL );
1060 }
1061
1062 void GGadgetSelectListItem(GGadget *g,int32_t pos,int32_t sel) {
1063 if ( g->funcs->select_list_item!=NULL )
1064 (g->funcs->select_list_item)(g,pos,sel);
1065 }
1066
1067 void GGadgetSelectOneListItem(GGadget *g,int32_t pos) {
1068 if ( g->funcs->select_one_list_item!=NULL )
1069 (g->funcs->select_one_list_item)(g,pos);
1070 }
1071
1072 int32_t GGadgetIsListItemSelected(GGadget *g,int32_t pos) {
1073 if ( g->funcs->is_list_item_selected!=NULL )
1074 return((g->funcs->is_list_item_selected)(g,pos));
1075
1076 return( 0 );
1077 }
1078
1079 int32_t GGadgetGetFirstListSelectedItem(GGadget *g) {
1080 if ( g->funcs->get_first_selection!=NULL )
1081 return((g->funcs->get_first_selection)(g));
1082 return( -1 );
1083 }
1084
1085 void GGadgetScrollListToPos(GGadget *g,int32_t pos) {
1086 if ( g->funcs->scroll_list_to_pos!=NULL )
1087 (g->funcs->scroll_list_to_pos)(g,pos);
1088 }
1089
1090 void GGadgetScrollListToText(GGadget *g,const unichar_t *lab,int32_t sel) {
1091 if ( g->funcs->scroll_list_to_text!=NULL )
1092 (g->funcs->scroll_list_to_text)(g,lab,sel);
1093 }
1094
1095 void GGadgetSetListOrderer(GGadget *g,int (*orderer)(const void *, const void *)) {
1096 if ( g->funcs->set_list_orderer!=NULL )
1097 (g->funcs->set_list_orderer)(g,orderer);
1098 }
1099
1100 void GGadgetGetDesiredSize(GGadget *g,GRect *outer, GRect *inner) {
1101 if ( g->state==gs_invisible ) {
1102 if ( outer!=NULL )
1103 memset(outer,0,sizeof(*outer));
1104 if ( inner!=NULL )
1105 memset(inner,0,sizeof(*inner));
1106 } else if ( ((char *) &g->funcs->get_desired_size) - ((char *) g->funcs) < g->funcs->size &&
1107 g->funcs->get_desired_size!=NULL )
1108 (g->funcs->get_desired_size)(g,outer,inner);
1109 else {
1110 if ( outer!=NULL )
1111 *outer = g->r;
1112 if ( inner!=NULL )
1113 *inner = g->inner;
1114 }
1115 }
1116
1117 void GGadgetGetDesiredVisibleSize(GGadget *g,GRect *outer, GRect *inner) {
1118 if ( ((char *) &g->funcs->get_desired_size) - ((char *) g->funcs) < g->funcs->size &&
1119 g->funcs->get_desired_size!=NULL )
1120 (g->funcs->get_desired_size)(g,outer,inner);
1121 else {
1122 if ( outer!=NULL )
1123 *outer = g->r;
1124 if ( inner!=NULL )
1125 *inner = g->inner;
1126 }
1127 }
1128
1129 void GGadgetSetDesiredSize(GGadget *g,GRect *outer, GRect *inner) {
1130 if ( ((char *) &g->funcs->set_desired_size) - ((char *) g->funcs) < g->funcs->size &&
1131 g->funcs->set_desired_size!=NULL )
1132 (g->funcs->set_desired_size)(g,outer,inner);
1133 }
1134
1135 int GGadgetFillsWindow(GGadget *g) {
1136 if ( ((char *) &g->funcs->fills_window) - ((char *) g->funcs) < g->funcs->size &&
1137 g->funcs->fills_window!=NULL )
1138 return( (g->funcs->fills_window)(g) );
1139
1140 return( false );
1141 }
1142
1143 int GGadgetIsDefault(GGadget *g) {
1144 if ( ((char *) &g->funcs->is_default) - ((char *) g->funcs) < g->funcs->size &&
1145 g->funcs->is_default!=NULL )
1146 return( (g->funcs->is_default)(g) );
1147
1148 return( false );
1149 }
1150
1151 void GGadgetsCreate(GWindow base, GGadgetCreateData *gcd) {
1152 int i;
1153
1154 for ( i=0; gcd[i].creator!=NULL; ++i )
1155 gcd[i].ret = (gcd[i].creator)(base,&gcd[i].gd,gcd[i].data);
1156 }
1157
1158 int GGadgetDispatchEvent(GGadget *g, GEvent *event) {
1159
1160 if ( g==NULL || event==NULL )
1161 return( false );
1162 switch ( event->type ) {
1163 case et_expose:
1164 if ( g->funcs->handle_expose )
1165 return( (g->funcs->handle_expose)(g->base,g,event) );
1166 break;
1167 case et_mouseup: case et_mousedown: case et_mousemove: case et_crossing:
1168 if ( g->funcs->handle_mouse )
1169 return( (g->funcs->handle_mouse)(g,event) );
1170 break;
1171 case et_char: case et_charup:
1172 if ( g->funcs->handle_key ) {
1173 int ret;
1174 int old = g->takes_keyboard;
1175 g->takes_keyboard = true;
1176 ret =(g->funcs->handle_key)(g,event);
1177 g->takes_keyboard = old;
1178 return( ret );
1179 }
1180 break;
1181 case et_drag: case et_dragout: case et_drop: case et_selclear:
1182 if ( g->funcs->handle_sel )
1183 return( (g->funcs->handle_sel)(g,event) );
1184 break;
1185 case et_timer:
1186 if ( g->funcs->handle_timer )
1187 return( (g->funcs->handle_timer)(g,event) );
1188 break;
1189 case et_controlevent:
1190 if ( g->handle_controlevent!=NULL )
1191 return( (g->handle_controlevent)(g,event) );
1192 else
1193 GDrawPostEvent(event);
1194 return( true );
1195 default: break;
1196 }
1197 return( false );
1198 }
1199
1200 void GGadgetTakesKeyboard(GGadget *g, int takes_keyboard) {
1201 g->takes_keyboard = takes_keyboard;
1202 }
1203
1204 void GGadgetSetSkipHotkeyProcessing( GGadget *g, int v )
1205 {
1206 if( !g )
1207 return;
1208
1209 printf("GGadgetSetSkipHotkeyProcessing1 %d\n", g->state );
1210 g->gg_skip_hotkey_processing = v;
1211 printf("GGadgetSetSkipHotkeyProcessing2 %d\n", g->state );
1212 }
1213
1214 int GGadgetGetSkipHotkeyProcessing( GGadget *g )
1215 {
1216 if( !g )
1217 return 0;
1218
1219 return (g->gg_skip_hotkey_processing);
1220 }
1221
1222 void GGadgetSetSkipUnQualifiedHotkeyProcessing( GGadget *g, int v )
1223 {
1224 if( !g )
1225 return;
1226 g->gg_skip_unqualified_hotkey_processing = v;
1227 }
1228
1229 int GGadgetGetSkipUnQualifiedHotkeyProcessing( GGadget *g )
1230 {
1231 if( !g )
1232 return 0;
1233
1234 return (g->gg_skip_unqualified_hotkey_processing);
1235 }
1236