comparison lwlib/xlwtabs.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents
children
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
1 /* Tabs Widget for XEmacs.
2 Copyright (C) 1999 Edward A. Falk
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* Synched up with: Tabs.c 1.27 */
22
23 /*
24 * Tabs.c - Index Tabs composite widget
25 *
26 * Author: Edward A. Falk
27 * falk@falconer.vip.best.com
28 *
29 * Date: July 29, 1997
30 *
31 *
32 * Overall layout of this widget is as follows:
33 *
34 * ________ ,---------. _________
35 * | label || Label || Label | \ tabs
36 * |________|| ||_________| /
37 * |+----------------------------+| \
38 * || || |
39 * || child widget window || > frame
40 * |+----------------------------+| |
41 * +------------------------------+ /
42 *
43 * The height of the tabs includes the shadow width, top and bottom
44 * margins, and the height of the text.
45 *
46 * The height of the frame includes the top and bottom shadow width and the
47 * size of the child widget window.
48 *
49 * The tabs overlap the frame and each other vertically by the shadow
50 * width, so that when the topmost tab is drawn, it obliterates part of
51 * the frame.
52 */
53
54 /*
55 * TODO: min child height = tab height
56 */
57
58 #include <config.h>
59 #include <stdio.h>
60
61 #include <X11/Xlib.h>
62 #include <X11/IntrinsicP.h>
63 #include <X11/StringDefs.h>
64 #include "../src/xmu.h"
65 #include "xlwtabsP.h"
66 #include "xlwgcs.h"
67
68 #define MIN_WID 10
69 #define MIN_HGT 10
70 #define INDENT 3 /* tabs indented from edge by this much */
71 #define SPACING 0 /* distance between tabs */
72 #define SHADWID 1 /* default shadow width */
73 #define TABDELTA 2 /* top tab grows this many pixels */
74 #define TABLDELTA 2 /* top tab label offset this many pixels */
75
76
77 /****************************************************************
78 *
79 * IndexTabs Resources
80 *
81 ****************************************************************/
82
83 static char defaultTranslations[] = "\
84 <BtnUp>: select() \n\
85 <FocusIn>: highlight() \n\
86 <FocusOut>: unhighlight() \n\
87 <Key>Page_Up: page(up) \n\
88 <Key>KP_Page_Up: page(up) \n\
89 <Key>Prior: page(up) \n\
90 <Key>KP_Prior: page(up) \n\
91 <Key>Page_Down: page(down) \n\
92 <Key>KP_Page_Down: page(down) \n\
93 <Key>Next: page(down) \n\
94 <Key>KP_Next: page(down) \n\
95 <Key>Home: page(home) \n\
96 <Key>KP_Home: page(home) \n\
97 <Key>End: page(end) \n\
98 <Key>KP_End: page(end) \n\
99 <Key>Up: highlight(up) \n\
100 <Key>KP_Up: highlight(up) \n\
101 <Key>Down: highlight(down) \n\
102 <Key>KP_Down: highlight(down) \n\
103 <Key> : page(select) \n\
104 " ;
105
106 static char accelTable[] = " #augment\n\
107 <Key>Page_Up: page(up) \n\
108 <Key>KP_Page_Up: page(up) \n\
109 <Key>Prior: page(up) \n\
110 <Key>KP_Prior: page(up) \n\
111 <Key>Page_Down: page(down) \n\
112 <Key>KP_Page_Down: page(down) \n\
113 <Key>Next: page(down) \n\
114 <Key>KP_Next: page(down) \n\
115 <Key>Home: page(home) \n\
116 <Key>KP_Home: page(home) \n\
117 <Key>End: page(end) \n\
118 <Key>KP_End: page(end) \n\
119 <Key>Up: highlight(up) \n\
120 <Key>KP_Up: highlight(up) \n\
121 <Key>Down: highlight(down) \n\
122 <Key>KP_Down: highlight(down) \n\
123 <Key> : page(select) \n\
124 " ;
125 static XtAccelerators defaultAccelerators ;
126
127 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
128 static XtResource resources[] = {
129
130 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
131 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
132 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
133 offset(font), XtRString, (XtPointer) XtDefaultFont},
134 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
135 offset(internalWidth), XtRImmediate, (XtPointer)4 },
136 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
137 offset(internalHeight), XtRImmediate, (XtPointer)4 },
138 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
139 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
140 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
141 offset(topWidget), XtRImmediate, NULL},
142 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
143 offset(callbacks), XtRCallback, NULL},
144 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
145 offset(popdownCallbacks), XtRCallback, NULL},
146 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
147 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
148 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
149 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
150 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
151 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
152 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
153 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
154 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
155 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
156 };
157 #undef offset
158
159
160
161 /* constraint resources */
162
163 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
164 static XtResource tabsConstraintResources[] = {
165 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
166 offset(label), XtRString, NULL},
167 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
168 offset(left_bitmap), XtRImmediate, None},
169 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
170 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
171 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
172 offset(resizable), XtRImmediate, (XtPointer) True},
173 } ;
174 #undef offset
175
176
177
178
179 #if !NeedFunctionPrototypes
180
181 /* FORWARD REFERENCES: */
182
183 /* member functions */
184
185 static void TabsClassInit();
186 static void TabsInit();
187 static void TabsResize();
188 static void TabsExpose();
189 static void TabsDestroy();
190 static void TabsRealize();
191 static Boolean TabsSetValues();
192 static Boolean TabsAcceptFocus();
193 static XtGeometryResult TabsQueryGeometry();
194 static XtGeometryResult TabsGeometryManager();
195 static void TabsChangeManaged();
196 static void TabsConstraintInitialize() ;
197 static Boolean TabsConstraintSetValues() ;
198
199 /* action procs */
200
201 static void TabsSelect() ;
202 static void TabsPage() ;
203 static void TabsHighlight() ;
204 static void TabsUnhighlight() ;
205
206 /* internal privates */
207
208 static void TabsAllocGCs() ; /* get rendering GCs */
209 static void TabsFreeGCs() ; /* return rendering GCs */
210 static void DrawTabs() ; /* draw all tabs */
211 static void DrawTab() ; /* draw one index tab */
212 static void DrawFrame() ; /* draw frame around contents */
213 static void DrawTrim() ; /* draw trim around a tab */
214 static void DrawBorder() ; /* draw border */
215 static void DrawHighlight() ; /* draw highlight */
216 static void UndrawTab() ; /* undraw interior of a tab */
217 static void TabWidth() ; /* recompute tab size */
218 static void GetPreferredSizes() ; /* query all children for their sizes */
219 static void MaxChild() ; /* find max preferred child size */
220 static int PreferredSize() ; /* compute preferred size */
221 static int PreferredSize2() ; /* compute preferred size */
222 static int PreferredSize3() ; /* compute preferred size */
223 static void MakeSizeRequest() ; /* try to change size */
224 static void getBitmapInfo() ;
225 static int TabLayout() ; /* lay out tabs */
226 static void TabsShuffleRows() ; /* bring current tab to bottom row */
227
228 static void TabsAllocFgGC() ;
229 static void TabsAllocGreyGC() ;
230
231 #else
232
233 static void TabsClassInit(void) ;
234 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
235 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
236 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
237 static void TabsDestroy( Widget w) ;
238 static void TabsResize( Widget w) ;
239 static void TabsExpose( Widget w, XEvent *event, Region region) ;
240 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
241 static Boolean TabsAcceptFocus(Widget, Time *);
242 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
243 ArgList, Cardinal *) ;
244 static XtGeometryResult TabsQueryGeometry(Widget,
245 XtWidgetGeometry *, XtWidgetGeometry *) ;
246 static XtGeometryResult TabsGeometryManager(Widget,
247 XtWidgetGeometry *, XtWidgetGeometry *) ;
248 static void TabsChangeManaged( Widget w) ;
249
250 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
251 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
252 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
253 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
254
255 static void DrawTabs( TabsWidget tw, Bool labels) ;
256 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
257 static void DrawFrame( TabsWidget tw) ;
258 static void DrawTrim( TabsWidget, int x, int y,
259 int wid, int hgt, Bool bottom, Bool undraw) ;
260 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
261 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
262 static void UndrawTab( TabsWidget tw, Widget child) ;
263
264 static void TabWidth( Widget w) ;
265 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
266 Bool query_only) ;
267 static void GetPreferredSizes(TabsWidget) ;
268 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
269 static void TabsShuffleRows( TabsWidget tw) ;
270 static int PreferredSize( TabsWidget,
271 Dimension *reply_width, Dimension *reply_height,
272 Dimension *reply_cw, Dimension *reply_ch) ;
273 static int PreferredSize2( TabsWidget, int cw, int ch,
274 Dimension *rw, Dimension *rh) ;
275 static int PreferredSize3( TabsWidget, int wid, int hgt,
276 Dimension *rw, Dimension *rh) ;
277 static void MakeSizeRequest(TabsWidget) ;
278
279 static void TabsAllocGCs(TabsWidget) ;
280 static void TabsFreeGCs(TabsWidget) ;
281 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
282 static void TabsAllocFgGC( TabsWidget tw) ;
283 static void TabsAllocGreyGC( TabsWidget tw) ;
284
285 #endif
286
287 #define AddRect(i,xx,yy,w,h) \
288 do{rects[(i)].x=(xx); rects[i].y=(yy); \
289 rects[i].width=(w); rects[i].height=(h);}while(0)
290
291 static XtActionsRec actionsList[] =
292 {
293 {"select", TabsSelect},
294 {"page", TabsPage},
295 {"highlight", TabsHighlight},
296 {"unhighlight", TabsUnhighlight},
297 } ;
298
299
300 /****************************************************************
301 *
302 * Full class record constant
303 *
304 ****************************************************************/
305
306 #ifndef NEED_MOTIF
307 #define SuperClass (&constraintClassRec)
308 #else
309 #define SuperClass (&xmManagerClassRec)
310 #endif
311
312 TabsClassRec tabsClassRec = {
313 {
314 /* core_class fields */
315 /* superclass */ (WidgetClass) SuperClass,
316 /* class_name */ "Tabs",
317 /* widget_size */ sizeof(TabsRec),
318 /* class_initialize */ TabsClassInit,
319 /* class_part_init */ NULL, /* TODO? */
320 /* class_inited */ FALSE,
321 /* initialize */ TabsInit,
322 /* initialize_hook */ NULL,
323 /* realize */ TabsRealize,
324 /* actions */ actionsList,
325 /* num_actions */ XtNumber(actionsList),
326 /* resources */ resources,
327 /* num_resources */ XtNumber(resources),
328 /* xrm_class */ NULLQUARK,
329 /* compress_motion */ TRUE,
330 #if XtSpecificationRelease < 6
331 /* compress_exposure */ XtExposeCompressMaximal,
332 #else
333 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
334 #endif
335 /* compress_enterleave*/ TRUE,
336 /* visible_interest */ TRUE,
337 /* destroy */ TabsDestroy,
338 /* resize */ TabsResize,
339 /* expose */ TabsExpose,
340 /* set_values */ TabsSetValues,
341 /* set_values_hook */ NULL,
342 /* set_values_almost */ XtInheritSetValuesAlmost,
343 /* get_values_hook */ NULL,
344 /* accept_focus */ TabsAcceptFocus,
345 /* version */ XtVersion,
346 /* callback_private */ NULL,
347 /* tm_table */ defaultTranslations,
348 /* query_geometry */ TabsQueryGeometry,
349 /* display_accelerator*/ XtInheritDisplayAccelerator,
350 /* extension */ NULL
351 },
352 {
353 /* composite_class fields */
354 /* geometry_manager */ TabsGeometryManager,
355 /* change_managed */ TabsChangeManaged,
356 /* insert_child */ XtInheritInsertChild, /* TODO? */
357 /* delete_child */ XtInheritDeleteChild, /* TODO? */
358 /* extension */ NULL
359 },
360 {
361 /* constraint_class fields */
362 /* subresources */ tabsConstraintResources,
363 /* subresource_count */ XtNumber(tabsConstraintResources),
364 /* constraint_size */ sizeof(TabsConstraintsRec),
365 /* initialize */ TabsConstraintInitialize,
366 /* destroy */ NULL,
367 /* set_values */ TabsConstraintSetValues,
368 /* extension */ NULL,
369 },
370 #ifdef NEED_MOTIF
371 /* Manager Class fields */
372 {
373 /* translations */ NULL,
374 /* syn_resources */ NULL,
375 /* num_syn_resources */ 0,
376 /* syn_constraint_resources */ NULL,
377 /* num_syn_constraint_resources */ 0,
378 /* parent_process */ XmInheritParentProcess,
379 /* extension */ NULL
380 },
381 #endif
382 {
383 /* Tabs class fields */
384 /* extension */ NULL,
385 }
386 };
387
388 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
389
390
391
392 #ifdef DEBUG
393 #ifdef __STDC__
394 #define assert(e) \
395 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
396 #else
397 #define assert(e) \
398 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
399 #endif
400 #else
401 #define assert(e)
402 #endif
403
404
405
406
407 /****************************************************************
408 *
409 * Member Procedures
410 *
411 ****************************************************************/
412
413 static void
414 TabsClassInit(void)
415 {
416 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
417 /* TODO: register converter for labels? */
418 }
419
420
421
422 /* Init a newly created tabs widget. Compute height of tabs
423 * and optionally compute size of widget. */
424
425 /* ARGSUSED */
426
427 static void
428 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
429 {
430 TabsWidget newTw = (TabsWidget)new;
431
432 newTw->tabs.numRows = 0 ;
433 newTw->tabs.displayChildren = 0;
434
435 GetPreferredSizes(newTw) ;
436
437 /* height is easy, it's the same for all tabs:
438 * TODO: font height + height of tallest bitmap.
439 */
440 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
441
442 if( newTw->tabs.font != NULL )
443 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
444 newTw->tabs.font->max_bounds.descent ;
445
446 /* GC allocation is deferred until XtRealize() */
447
448 /* if size not explicitly set, set it to our preferred size now. */
449
450 if( request->core.width == 0 || request->core.height == 0 )
451 {
452 Dimension w,h ;
453 PreferredSize(newTw, &w, &h, NULL,NULL) ;
454 if( request->core.width == 0 ) new->core.width = w ;
455 if( request->core.height == 0 ) new->core.height = h ;
456 XtClass(new)->core_class.resize(new) ;
457 }
458
459 /* defer GC allocation, etc., until Realize() time. */
460 newTw->tabs.foregroundGC =
461 newTw->tabs.backgroundGC =
462 newTw->tabs.greyGC =
463 newTw->tabs.topGC =
464 newTw->tabs.botGC = None ;
465
466 newTw->tabs.grey50 = None ;
467
468 newTw->tabs.needs_layout = False ;
469
470 newTw->tabs.hilight = NULL ;
471
472 #ifdef NEED_MOTIF
473 newTw->manager.navigation_type = XmTAB_GROUP ;
474 newTw->manager.traversal_on = True ;
475 #endif
476 }
477
478
479 /* Init the constraint part of a new tab child. Compute the
480 * size of the tab.
481 */
482 /* ARGSUSED */
483 static void
484 TabsConstraintInitialize(Widget request, Widget new,
485 ArgList args, Cardinal *num_args)
486 {
487 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
488 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
489
490 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
491 TabWidth(new) ;
492 }
493
494
495
496 /* Called when tabs widget first realized. Create the window
497 * and allocate the GCs
498 */
499
500 static void
501 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
502 {
503 TabsWidget tw = (TabsWidget) w;
504
505 attributes->bit_gravity = NorthWestGravity;
506 *valueMask |= CWBitGravity;
507
508 SuperClass->core_class.realize(w, valueMask, attributes);
509
510 TabsAllocGCs(tw) ;
511 }
512
513
514
515 static void
516 TabsDestroy(Widget w)
517 {
518 TabsFreeGCs((TabsWidget)w) ;
519 }
520
521
522 /* Parent has resized us. This will require that the tabs be
523 * laid out again.
524 */
525
526 static void
527 TabsResize(Widget w)
528 {
529 TabsWidget tw = (TabsWidget) w;
530 int i ;
531 int num_children = tw->composite.num_children ;
532 Widget *childP ;
533 TabsConstraints tab ;
534 Dimension cw,ch,bw ;
535
536 /* Our size has now been dictated by the parent. Lay out the
537 * tabs, lay out the frame, lay out the children. Remember
538 * that the tabs overlap each other and the frame by shadowWidth.
539 * Also, the top tab is larger than the others, so if there's only
540 * one row, the widget must be made taller to accommodate this.
541 *
542 * Once the tabs are laid out, if there is more than one
543 * row, we may need to shuffle the rows to bring the top tab
544 * to the bottom row.
545 */
546
547 tw->tabs.needs_layout = False ;
548
549 if( num_children > 0 && tw->composite.children != NULL )
550 {
551 /* Loop through the tabs and assign rows & x positions */
552 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
553 num_children = tw->tabs.displayChildren;
554
555 /* assign a top widget, bring it to bottom row. */
556 TabsShuffleRows(tw) ;
557
558 /* now assign child positions & sizes. Positions are all the
559 * same: just inside the frame. Sizes are also all the same.
560 */
561
562 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
563 tw->tabs.child_height = ch =
564 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
565
566
567 for(i=0, childP=tw->composite.children;
568 i < num_children;
569 ++i, ++childP)
570 if( XtIsManaged(*childP) )
571 {
572 tab = (TabsConstraints) (*childP)->core.constraints ;
573 bw = (*childP)->core.border_width ;
574 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
575 cw-bw*2,ch-bw*2, bw) ;
576 }
577 if( XtIsRealized(w) ) {
578 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
579 /* should not be necessary to explicitly repaint after a
580 * resize, but XEmacs folks tell me it is.
581 */
582 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
583 }
584 }
585 } /* Resize */
586
587
588
589 /* Redraw entire Tabs widget */
590
591 /* ARGSUSED */
592 static void
593 TabsExpose(Widget w, XEvent *event, Region region)
594 {
595 TabsWidget tw = (TabsWidget) w;
596
597 if( tw->tabs.needs_layout )
598 XtClass(w)->core_class.resize(w) ;
599
600 DrawTabs(tw, True) ;
601 }
602
603
604 /* Called when any Tabs widget resources are changed. */
605
606 /* ARGSUSED */
607 static Boolean
608 TabsSetValues(Widget current, Widget request, Widget new,
609 ArgList args, Cardinal *num_args)
610 {
611 TabsWidget curtw = (TabsWidget) current ;
612 TabsWidget tw = (TabsWidget) new ;
613 Boolean needRedraw = False ;
614 Widget *childP ;
615 int i ;
616
617
618 if( tw->tabs.font != curtw->tabs.font ||
619 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
620 tw->tabs.internalHeight != curtw->tabs.internalHeight )
621 {
622 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
623
624 if( tw->tabs.font != NULL )
625 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
626 tw->tabs.font->max_bounds.descent ;
627
628 /* Tab size has changed. Resize all tabs and request a new size */
629 for(i=0, childP=tw->composite.children;
630 i < tw->composite.num_children;
631 ++i, ++childP)
632 if( XtIsManaged(*childP) )
633 TabWidth(*childP) ;
634 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
635 needRedraw = True ;
636 tw->tabs.needs_layout = True ;
637 }
638
639 /* TODO: if any color changes, need to recompute GCs and redraw */
640
641 if( tw->core.background_pixel != curtw->core.background_pixel ||
642 tw->core.background_pixmap != curtw->core.background_pixmap ||
643 tw->tabs.font != curtw->tabs.font )
644 if( XtIsRealized(new) )
645 {
646 TabsFreeGCs(tw) ;
647 TabsAllocGCs(tw) ;
648 needRedraw = True ;
649 }
650
651 if( tw->core.sensitive != curtw->core.sensitive )
652 needRedraw = True ;
653
654 /* If top widget changes, need to change stacking order, redraw tabs.
655 * Window system will handle the redraws.
656 */
657
658 if( tw->tabs.topWidget != curtw->tabs.topWidget )
659 {
660 if( XtIsRealized(tw->tabs.topWidget) )
661 {
662 Widget w = tw->tabs.topWidget ;
663 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
664
665 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
666 #ifdef NEED_MOTIF
667 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
668 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
669 #endif
670
671 if( tab->tabs.row != tw->tabs.numRows-1 )
672 TabsShuffleRows(tw) ;
673
674 needRedraw = True ;
675 }
676 else
677 tw->tabs.needs_layout = True ;
678 }
679
680 return needRedraw ;
681 }
682
683
684 /* Called when any child constraint resources change. */
685
686 /* ARGSUSED */
687 static Boolean
688 TabsConstraintSetValues(Widget current, Widget request, Widget new,
689 ArgList args, Cardinal *num_args)
690 {
691 TabsWidget tw = (TabsWidget) XtParent(new) ;
692 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
693 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
694
695
696 /* if label changes, need to re-layout the entire widget */
697 /* if foreground changes, need to redraw tab label */
698
699 /* TODO: only need resize of new bitmap has different dimensions
700 * from old bitmap.
701 */
702
703 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
704 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
705 {
706 TabWidth(new) ;
707 tw->tabs.needs_layout = True ;
708
709 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
710 getBitmapInfo(tw, tab) ;
711
712 /* If there are no subclass ConstraintSetValues procedures remaining
713 * to be invoked, and if the preferred size has changed, ask
714 * for a resize.
715 */
716 if( XtClass((Widget)tw) == tabsWidgetClass )
717 MakeSizeRequest(tw) ;
718 }
719
720
721 /* The child widget itself never needs a redisplay, but the parent
722 * Tabs widget might.
723 */
724
725 if( XtIsRealized(new) )
726 {
727 if( tw->tabs.needs_layout ) {
728 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
729 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
730 }
731
732 else if( tab->tabs.foreground != ctab->tabs.foreground )
733 DrawTab(tw, new, True) ;
734 }
735
736 return False ;
737 }
738
739
740 static Boolean
741 TabsAcceptFocus(Widget w, Time *t)
742 {
743 if( !w->core.being_destroyed && XtIsRealized(w) &&
744 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
745 {
746 Widget p ;
747 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
748 XtSetKeyboardFocus(p,w) ;
749 return True ;
750 }
751 else
752 return False ;
753 }
754
755
756
757 /*
758 * Return preferred size. Happily accept anything >= our preferred size.
759 * (TODO: is that the right thing to do? Should we always return "almost"
760 * if offerred more than we need?)
761 */
762
763 static XtGeometryResult
764 TabsQueryGeometry(Widget w,
765 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
766 {
767 register TabsWidget tw = (TabsWidget)w ;
768 XtGeometryMask mode = intended->request_mode ;
769
770 preferred->request_mode = CWWidth | CWHeight ;
771 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
772
773 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
774 (!(mode & CWHeight) || intended->height == w->core.height) )
775 return XtGeometryNo ;
776
777 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
778 (!(mode & CWHeight) || intended->height >= preferred->height) )
779 return XtGeometryYes;
780
781 return XtGeometryAlmost;
782 }
783
784
785
786 /*
787 * Geometry Manager; called when a child wants to be resized.
788 */
789
790 static XtGeometryResult
791 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
792 {
793 TabsWidget tw = (TabsWidget) XtParent(w);
794 Dimension s = SHADWID ;
795 TabsConstraints tab = (TabsConstraints)w->core.constraints;
796 XtGeometryResult result ;
797 Dimension rw, rh ;
798
799 /* Position request always denied */
800
801 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
802 ((req->request_mode & CWY) && req->y != w->core.y) ||
803 !tab->tabs.resizable )
804 return XtGeometryNo ;
805
806 /* Make all three fields in the request valid */
807 if( !(req->request_mode & CWWidth) )
808 req->width = w->core.width;
809 if( !(req->request_mode & CWHeight) )
810 req->height = w->core.height;
811 if( !(req->request_mode & CWBorderWidth) )
812 req->border_width = w->core.border_width;
813
814 if( req->width == w->core.width &&
815 req->height == w->core.height &&
816 req->border_width == w->core.border_width )
817 return XtGeometryNo ;
818
819 rw = req->width + 2 * req->border_width ;
820 rh = req->height + 2 * req->border_width ;
821
822 /* find out how big the children want to be now */
823 MaxChild(tw, w, rw, rh) ;
824
825
826 /* Size changes must see if the new size can be accommodated.
827 * The Tabs widget keeps all of its children the same
828 * size. A request to shrink will be accepted only if the
829 * new size is still big enough for all other children. A
830 * request to shrink that is not big enough for all children
831 * returns an "almost" response with the new proposed size
832 * or a "no" response if unable to shrink at all.
833 *
834 * A request to grow will be accepted only if the Tabs parent can
835 * grow to accommodate.
836 *
837 * TODO:
838 * We could get fancy here and re-arrange the tabs if it is
839 * necessary to compromise with the parent, but we'll save that
840 * for another day.
841 */
842
843 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
844 {
845 Dimension cw,ch ; /* children's preferred size */
846 Dimension aw,ah ; /* available size we can give child */
847 Dimension th ; /* space used by tabs */
848 Dimension wid,hgt ; /* Tabs widget size */
849
850 cw = tw->tabs.max_cw ;
851 ch = tw->tabs.max_ch ;
852
853 /* find out what *my* resulting preferred size would be */
854
855 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
856
857 /* Would my size change? If so, ask to be resized. */
858
859 if( wid != tw->core.width || hgt != tw->core.height )
860 {
861 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
862 XtWidgetGeometry myrequest, myreply ;
863
864 myrequest.width = wid ;
865 myrequest.height = hgt ;
866 myrequest.request_mode = CWWidth | CWHeight ;
867
868 /* If child is only querying, or if we're going to have to
869 * offer the child a compromise, then make this a query only.
870 */
871
872 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
873 myrequest.request_mode |= XtCWQueryOnly ;
874
875 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
876
877 /* !$@# Athena Box widget changes the core size even if QueryOnly
878 * is set. I'm convinced this is a bug. At any rate, to work
879 * around the bug, we need to restore the core size after every
880 * query geometry request. This is only partly effective,
881 * as there may be other boxes further up the tree.
882 */
883 if( myrequest.request_mode & XtCWQueryOnly ) {
884 tw->core.width = oldWid ;
885 tw->core.height = oldHgt ;
886 }
887
888 /* based on the parent's response, determine what the
889 * resulting Tabs widget size would be.
890 */
891
892 switch( result ) {
893 case XtGeometryYes:
894 case XtGeometryDone:
895 tw->tabs.needs_layout = True ;
896 break ;
897
898 case XtGeometryNo:
899 wid = tw->core.width ;
900 hgt = tw->core.height ;
901 break ;
902
903 case XtGeometryAlmost:
904 wid = myreply.width ;
905 hgt = myreply.height ;
906 tw->tabs.needs_layout = True ;
907 break ;
908 }
909 }
910
911 /* Within the constraints imposed by the parent, what is
912 * the max size we can give the child?
913 */
914 (void) TabLayout(tw, wid, hgt, &th, True) ;
915 aw = wid - 2*s ;
916 ah = hgt - th - 2*s ;
917
918 /* OK, make our decision. If requested size is >= max sibling
919 * preferred size, AND requested size <= available size, then
920 * we accept. Otherwise, we offer a compromise.
921 */
922
923 if( rw == aw && rh == ah )
924 {
925 /* Acceptable. If this wasn't a query, change *all* children
926 * to this size.
927 */
928 if( req->request_mode & XtCWQueryOnly )
929 return XtGeometryYes ;
930 else
931 {
932 Widget *childP = tw->composite.children ;
933 int i,bw ;
934 w->core.border_width = req->border_width ;
935 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
936 if( XtIsManaged(*childP) )
937 {
938 bw = (*childP)->core.border_width ;
939 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
940 rw-2*bw, rh-2*bw, bw) ;
941 }
942 #ifdef COMMENT
943 /* TODO: under what conditions will we need to redraw? */
944 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
945 XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
946 #endif /* COMMENT */
947 return XtGeometryDone ;
948 }
949 }
950
951 /* Cannot grant child's request. Describe what we *can* do
952 * and return counter-offer.
953 */
954 reply->width = aw - 2 * req->border_width ;
955 reply->height = ah - 2 * req->border_width ;
956 reply->border_width = req->border_width ;
957 reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
958 return XtGeometryAlmost ;
959 }
960
961 return XtGeometryYes ;
962 }
963
964
965
966
967 /* The number of children we manage has changed; recompute
968 * size from scratch.
969 */
970
971 static void
972 TabsChangeManaged(Widget w)
973 {
974 TabsWidget tw = (TabsWidget)w ;
975 Widget *childP = tw->composite.children ;
976 int i ;
977
978 if( tw->tabs.topWidget != NULL &&
979 ( !XtIsManaged(tw->tabs.topWidget) ||
980 tw->tabs.topWidget->core.being_destroyed ) )
981 tw->tabs.topWidget = NULL ;
982
983 /* Check whether the highlight tab is still valid. */
984 if( tw->tabs.hilight != NULL &&
985 ( !XtIsManaged(tw->tabs.hilight) ||
986 tw->tabs.hilight->core.being_destroyed ) )
987 tw->tabs.hilight = NULL ;
988
989 GetPreferredSizes(tw) ;
990 MakeSizeRequest(tw) ;
991
992 XtClass(w)->core_class.resize(w) ;
993 if( XtIsRealized(w) )
994 {
995 Display *dpy = XtDisplay(w) ;
996 XClearWindow(dpy, XtWindow(w)) ;
997 XtClass(w)->core_class.expose(w,NULL,NULL) ;
998
999 /* make sure the top widget stays on top. This requires
1000 * making sure that all new children are realized first.
1001 */
1002 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
1003 {
1004 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
1005 if( !XtIsRealized(*childP) )
1006 XtRealizeWidget(*childP) ;
1007
1008 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
1009 }
1010 }
1011
1012 #ifdef NEED_MOTIF
1013 /* Only top widget may receive input */
1014
1015 for(childP = tw->composite.children, i=tw->composite.num_children;
1016 --i >= 0;
1017 ++childP)
1018 {
1019 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
1020 }
1021
1022 if( tw->tabs.topWidget != NULL )
1023 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
1024 #endif
1025 }
1026
1027
1028
1029
1030 /****************************************************************
1031 *
1032 * Action Procedures
1033 *
1034 ****************************************************************/
1035
1036
1037 /* User clicks on a tab, figure out which one it was. */
1038
1039 /* ARGSUSED */
1040 static void
1041 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
1042 {
1043 TabsWidget tw = (TabsWidget) w ;
1044 Widget *childP ;
1045 Position x,y ;
1046 Dimension h = tw->tabs.tab_height ;
1047 int i ;
1048
1049 #ifdef NEED_MOTIF
1050 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
1051 #endif
1052
1053 /* TODO: is there an Xmu function or something to do this instead? */
1054 switch( event->type ) {
1055 case ButtonPress:
1056 case ButtonRelease:
1057 x = event->xbutton.x ; y = event->xbutton.y ; break ;
1058 case KeyPress:
1059 case KeyRelease:
1060 x = event->xkey.x ; y = event->xkey.y ; break ;
1061 default:
1062 return ;
1063 }
1064
1065 /* TODO: determine which tab was clicked, if any. Set that
1066 * widget to be top of stacking order with XawTabsSetTop().
1067 */
1068 for(i=0, childP=tw->composite.children;
1069 i < tw->tabs.displayChildren;
1070 ++i, ++childP)
1071 if( XtIsManaged(*childP) )
1072 {
1073 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
1074 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
1075 y > tab->tabs.y && y < tab->tabs.y + h )
1076 {
1077 if( *childP != tw->tabs.topWidget &&
1078 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
1079 XawTabsSetTop(*childP, True) ;
1080 break ;
1081 }
1082 }
1083 }
1084
1085
1086 /* User hits a key */
1087
1088 static void
1089 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
1090 {
1091 TabsWidget tw = (TabsWidget) w ;
1092 Widget newtop = NULL;
1093 Widget *childP ;
1094 int idx ;
1095 int nc = tw->tabs.displayChildren ;
1096
1097 if( nc <= 0 )
1098 return ;
1099
1100 if( *num_params < 1 ) {
1101 XtAppWarning(XtWidgetToApplicationContext(w),
1102 "Tabs: page() action called with no arguments") ;
1103 return ;
1104 }
1105
1106 if( tw->tabs.topWidget == NULL )
1107 tw->tabs.topWidget = tw->composite.children[0] ;
1108
1109 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1110 if( tw->tabs.topWidget == *childP )
1111 break ;
1112
1113 switch( params[0][0] ) {
1114 case 'u': /* up */
1115 case 'U':
1116 if( --idx < 0 )
1117 idx = nc-1 ;
1118 newtop = tw->composite.children[idx] ;
1119 break ;
1120
1121 case 'd': /* down */
1122 case 'D':
1123 if( ++idx >= nc )
1124 idx = 0 ;
1125 newtop = tw->composite.children[idx] ;
1126 break ;
1127
1128 case 'h':
1129 case 'H':
1130 default:
1131 newtop = tw->composite.children[0] ;
1132 break ;
1133
1134 case 'e':
1135 case 'E':
1136 newtop = tw->composite.children[nc-1] ;
1137 break ;
1138
1139 case 's': /* selected */
1140 case 'S':
1141 if( (newtop = tw->tabs.hilight) == NULL )
1142 return ;
1143 break ;
1144 }
1145
1146 XawTabsSetTop(newtop, True) ;
1147 }
1148
1149
1150 /* User hits up/down key */
1151
1152 static void
1153 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1154 {
1155 TabsWidget tw = (TabsWidget) w ;
1156 Widget newhl = NULL;
1157 Widget *childP ;
1158 int idx ;
1159 int nc = tw->tabs.displayChildren ;
1160
1161 if( nc <= 0 )
1162 return ;
1163
1164 if( *num_params < 1 )
1165 {
1166 if( tw->tabs.hilight != NULL )
1167 DrawHighlight(tw, tw->tabs.hilight, False) ;
1168 return ;
1169 }
1170
1171 if( tw->tabs.hilight == NULL )
1172 newhl = tw->composite.children[0] ;
1173
1174 else
1175 {
1176 /* find index of currently highlit child */
1177 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1178 if( tw->tabs.hilight == *childP )
1179 break ;
1180
1181 switch( params[0][0] ) {
1182 case 'u': /* up */
1183 case 'U':
1184 if( --idx < 0 )
1185 idx = nc-1 ;
1186 newhl = tw->composite.children[idx] ;
1187 break ;
1188
1189 case 'd': /* down */
1190 case 'D':
1191 if( ++idx >= nc )
1192 idx = 0 ;
1193 newhl = tw->composite.children[idx] ;
1194 break ;
1195
1196 case 'h':
1197 case 'H':
1198 newhl = tw->composite.children[0] ;
1199 break ;
1200
1201 case 'e':
1202 case 'E':
1203 newhl = tw->composite.children[nc-1] ;
1204 break ;
1205
1206 default:
1207 newhl = tw->tabs.hilight ;
1208 break ;
1209 }
1210 }
1211
1212 XawTabsSetHighlight(w, newhl) ;
1213 }
1214
1215
1216
1217 static void
1218 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1219 {
1220 TabsWidget tw = (TabsWidget) w ;
1221 int nc = tw->composite.num_children ;
1222
1223 if( nc <= 0 )
1224 return ;
1225
1226 if( tw->tabs.hilight != NULL )
1227 DrawHighlight(tw, tw->tabs.hilight, True) ;
1228 }
1229
1230
1231
1232
1233
1234 /****************************************************************
1235 *
1236 * Public Procedures
1237 *
1238 ****************************************************************/
1239
1240
1241 /* Set the top tab, optionally call all callbacks. */
1242 void
1243 XawTabsSetTop(Widget w, Bool callCallbacks)
1244 {
1245 TabsWidget tw = (TabsWidget)w->core.parent ;
1246 TabsConstraints tab ;
1247 Widget oldtop = tw->tabs.topWidget ;
1248
1249 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
1250 {
1251 char line[256] ;
1252 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
1253 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
1254 return ;
1255 }
1256
1257 if( callCallbacks )
1258 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
1259 (XtPointer)tw->tabs.topWidget) ;
1260
1261 if( !XtIsRealized(w) ) {
1262 tw->tabs.topWidget = w ;
1263 tw->tabs.needs_layout = True ;
1264 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
1265 return ;
1266 }
1267
1268 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
1269 #ifdef NEED_MOTIF
1270 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
1271 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
1272 #endif
1273
1274 tab = (TabsConstraints) w->core.constraints ;
1275
1276 /* Unhighlight before we start messing with the stacking order. */
1277 if( tw->tabs.hilight != NULL )
1278 {
1279 DrawHighlight(tw, tw->tabs.hilight, True) ;
1280 tw->tabs.hilight = NULL;
1281 }
1282
1283 if( tab->tabs.row == 0 )
1284 {
1285 /* Easy case; undraw current top, undraw new top, assign new
1286 * top, redraw all borders.
1287 * We *could* just erase and execute a full redraw, but I like to
1288 * reduce screen flicker.
1289 */
1290 UndrawTab(tw, oldtop) ; /* undraw old */
1291 DrawBorder(tw, oldtop, True) ;
1292 UndrawTab(tw, w) ; /* undraw new */
1293 DrawBorder(tw, w, True) ;
1294 tw->tabs.topWidget = w ;
1295 DrawTab(tw, oldtop, True) ; /* redraw old */
1296 DrawTab(tw, w, True) ; /* redraw new */
1297 DrawTabs(tw, False) ;
1298 }
1299 else
1300 {
1301 tw->tabs.topWidget = w ;
1302 TabsShuffleRows(tw) ;
1303 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
1304 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
1305 }
1306
1307 XawTabsSetHighlight((Widget)tw, w) ;
1308
1309 if( callCallbacks )
1310 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
1311 }
1312
1313
1314 /* Set the top tab, optionally call all callbacks. */
1315 void
1316 XawTabsSetHighlight(Widget t, Widget w)
1317 {
1318 TabsWidget tw = (TabsWidget)t ;
1319
1320 if( !XtIsSubclass(t, tabsWidgetClass) )
1321 return ;
1322
1323 if( XtIsRealized(t) && w != tw->tabs.hilight )
1324 {
1325 if( w != NULL )
1326 DrawHighlight(tw, w, False) ;
1327 }
1328
1329 tw->tabs.hilight = w ;
1330 }
1331
1332
1333
1334
1335 /****************************************************************
1336 *
1337 * Private Procedures
1338 *
1339 ****************************************************************/
1340
1341
1342 static void
1343 TabsAllocGCs(TabsWidget tw)
1344 {
1345 TabsAllocFgGC(tw) ;
1346 TabsAllocGreyGC(tw) ;
1347 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
1348 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
1349 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1350 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
1351 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1352 }
1353
1354
1355 static void
1356 TabsFreeGCs(TabsWidget tw)
1357 {
1358 Widget w = (Widget) tw;
1359
1360 XtReleaseGC(w, tw->tabs.foregroundGC) ;
1361 XtReleaseGC(w, tw->tabs.greyGC) ;
1362 XtReleaseGC(w, tw->tabs.backgroundGC) ;
1363 XtReleaseGC(w, tw->tabs.topGC) ;
1364 XtReleaseGC(w, tw->tabs.botGC) ;
1365 #ifdef HAVE_XMU
1366 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
1367 #endif
1368 }
1369
1370
1371
1372
1373
1374 /* Redraw entire Tabs widget */
1375
1376 static void
1377 DrawTabs(TabsWidget tw, Bool labels)
1378 {
1379 Widget *childP ;
1380 int i,j ;
1381 Dimension s = SHADWID ;
1382 Dimension th = tw->tabs.tab_height ;
1383 Position y ;
1384 TabsConstraints tab ;
1385
1386 if( !XtIsRealized((Widget)tw))
1387 return ;
1388
1389 /* draw tabs and frames by row except for the top tab, which
1390 * is drawn last. (This is inefficiently written, but should not
1391 * be too slow as long as there are not a lot of rows.)
1392 */
1393
1394 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
1395 for(i=0; i<tw->tabs.numRows; ++i, y += th)
1396 {
1397 for( j=tw->tabs.displayChildren, childP=tw->composite.children;
1398 --j >= 0; ++childP )
1399 if( XtIsManaged(*childP) )
1400 {
1401 tab = (TabsConstraints)(*childP)->core.constraints;
1402 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
1403 DrawTab(tw, *childP, labels) ;
1404 }
1405 if( i != tw->tabs.numRows -1 )
1406 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
1407 }
1408
1409 DrawFrame(tw) ;
1410
1411 /* and now the top tab */
1412 if( tw->tabs.topWidget != NULL )
1413 DrawTab(tw, tw->tabs.topWidget, labels) ;
1414 }
1415
1416
1417
1418 /* Draw one tab. Corners are rounded very slightly. */
1419
1420 static void
1421 DrawTab(TabsWidget tw, Widget child, Bool labels)
1422 {
1423 GC gc ;
1424 int x,y ;
1425
1426 if( !XtIsRealized((Widget)tw))
1427 return ;
1428
1429 DrawBorder(tw, child, False) ;
1430
1431 if( labels )
1432 {
1433 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1434 Display *dpy = XtDisplay((Widget)tw) ;
1435 Window win = XtWindow((Widget)tw) ;
1436 String lbl = tab->tabs.label != NULL ?
1437 tab->tabs.label : XtName(child) ;
1438
1439 if( XtIsSensitive(child) )
1440 {
1441 gc = tw->tabs.foregroundGC ;
1442 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1443 }
1444 else
1445 {
1446 /* grey pixel allocation deferred until now */
1447 if( !tab->tabs.greyAlloc )
1448 {
1449 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
1450 tab->tabs.grey = tab->tabs.foreground ;
1451 else
1452 tab->tabs.grey = AllocGreyPixel((Widget)tw,
1453 tab->tabs.foreground,
1454 tw->core.background_pixel,
1455 tw->tabs.insensitive_contrast ) ;
1456 tab->tabs.greyAlloc = True ;
1457 }
1458 gc = tw->tabs.greyGC ;
1459 XSetForeground(dpy, gc, tab->tabs.grey) ;
1460 }
1461
1462 x = tab->tabs.x ;
1463 y = tab->tabs.y ;
1464 if( child == tw->tabs.topWidget )
1465 y -= TABLDELTA ;
1466
1467 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
1468 {
1469 if( tab->tabs.lbm_depth == 1 )
1470 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
1471 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1472 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
1473 else
1474 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
1475 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1476 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
1477 }
1478
1479 if( lbl != NULL && tw->tabs.font != NULL )
1480 XDrawString(dpy,win,gc,
1481 x+tab->tabs.l_x, y+tab->tabs.l_y,
1482 lbl, (int)strlen(lbl)) ;
1483 }
1484
1485 if( child == tw->tabs.hilight )
1486 DrawHighlight(tw, child, False) ;
1487 }
1488
1489
1490 /* draw frame all the way around the child windows. */
1491
1492 static void
1493 DrawFrame(TabsWidget tw)
1494 {
1495 GC topgc = tw->tabs.topGC ;
1496 GC botgc = tw->tabs.botGC ;
1497 Dimension s = SHADWID ;
1498 Dimension ch = tw->tabs.child_height ;
1499 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1500 tw->core.width, ch+2*s, s, topgc, botgc) ;
1501 }
1502
1503
1504 /* draw trim around a tab or underneath a row of tabs */
1505
1506 static void
1507 DrawTrim(TabsWidget tw, /* widget */
1508 int x, /* upper-left corner */
1509 int y,
1510 int wid, /* total size */
1511 int hgt,
1512 Bool bottom, /* draw bottom? */
1513 Bool undraw) /* undraw all */
1514 {
1515 Display *dpy = XtDisplay((Widget)tw) ;
1516 Window win = XtWindow((Widget)tw) ;
1517 GC bggc = tw->tabs.backgroundGC ;
1518 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1519 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1520 if( bottom )
1521 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1522 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1523 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1524 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1525 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1526 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1527 }
1528
1529
1530 /* Draw one tab border. */
1531
1532 static void
1533 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1534 {
1535 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1536 Position x = tab->tabs.x ;
1537 Position y = tab->tabs.y ;
1538 Dimension twid = tab->tabs.width ;
1539 Dimension thgt = tw->tabs.tab_height ;
1540
1541 /* top tab requires a little special attention; it overlaps
1542 * neighboring tabs slightly, so the background must be cleared
1543 * in the region of the overlap to partially erase those neighbors.
1544 * TODO: is this worth doing with regions instead?
1545 */
1546 if( child == tw->tabs.topWidget )
1547 {
1548 Display *dpy = XtDisplay((Widget)tw) ;
1549 Window win = XtWindow((Widget)tw) ;
1550 GC bggc = tw->tabs.backgroundGC ;
1551 XRectangle rects[3] ;
1552 x -= TABDELTA ;
1553 y -= TABDELTA ;
1554 twid += TABDELTA*2 ;
1555 thgt += TABDELTA ;
1556 AddRect(0, x,y+1,twid,TABDELTA) ;
1557 AddRect(1, x+1,y,TABDELTA,thgt) ;
1558 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1559 XFillRectangles(dpy,win,bggc, rects, 3) ;
1560 }
1561
1562 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1563 }
1564
1565
1566 /* Draw highlight around tab that has focus */
1567
1568 static void
1569 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1570 {
1571 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1572 Display *dpy = XtDisplay((Widget)tw) ;
1573 Window win = XtWindow((Widget)tw) ;
1574 GC gc ;
1575 Position x = tab->tabs.x ;
1576 Position y = tab->tabs.y ;
1577 Dimension wid = tab->tabs.width ;
1578 Dimension hgt = tw->tabs.tab_height ;
1579 XPoint points[6] ;
1580
1581 /* top tab does not have a highlight */
1582
1583 if( child == tw->tabs.topWidget )
1584 return ;
1585
1586 if( undraw )
1587 gc = tw->tabs.backgroundGC ;
1588
1589 else if( XtIsSensitive(child) )
1590 {
1591 gc = tw->tabs.foregroundGC ;
1592 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1593 }
1594 else
1595 {
1596 gc = tw->tabs.greyGC ;
1597 XSetForeground(dpy, gc, tab->tabs.grey) ;
1598 }
1599
1600 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1601 points[1].x = x+1 ; points[1].y = y+2 ;
1602 points[2].x = x+2 ; points[2].y = y+1 ;
1603 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1604 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1605 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1606
1607 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1608 }
1609
1610
1611 /* Undraw one tab interior */
1612
1613 static void
1614 UndrawTab(TabsWidget tw, Widget child)
1615 {
1616 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1617 Position x = tab->tabs.x ;
1618 Position y = tab->tabs.y ;
1619 Dimension twid = tab->tabs.width ;
1620 Dimension thgt = tw->tabs.tab_height ;
1621 Display *dpy = XtDisplay((Widget)tw) ;
1622 Window win = XtWindow((Widget)tw) ;
1623 GC bggc = tw->tabs.backgroundGC ;
1624
1625 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1626 }
1627
1628
1629
1630
1631
1632 /* GEOMETRY UTILITIES */
1633
1634 /* Overview:
1635 *
1636 * MaxChild(): ask all children (except possibly one) their
1637 * preferred sizes, set max_cw, max_ch accordingly.
1638 *
1639 * GetPreferredSizes(): ask all children their preferred sizes,
1640 * set max_cw, max_ch accordingly.
1641 *
1642 * PreferredSize(): given max_cw, max_ch, return tabs widget
1643 * preferred size. Iterate with other widths in order to get
1644 * a reasonable aspect ratio.
1645 *
1646 * PreferredSize2(): Given child dimensions, return Tabs
1647 * widget dimensions.
1648 *
1649 * PreferredSize3(): Same, except given child dimensions plus
1650 * shadow.
1651 */
1652
1653
1654 /* Compute the width of one child's tab. Positions will be computed
1655 * elsewhere.
1656 *
1657 * height: font height + vertical_space*2 + shadowWid*2
1658 * width: string width + horizontal_space*2 + shadowWid*2
1659 *
1660 * All tabs are the same height, so that is computed elsewhere.
1661 */
1662
1663 static void
1664 TabWidth(Widget w)
1665 {
1666 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1667 TabsWidget tw = (TabsWidget)XtParent(w) ;
1668 String lbl = tab->tabs.label != NULL ?
1669 tab->tabs.label : XtName(w) ;
1670 XFontStruct *font = tw->tabs.font ;
1671 int iw = tw->tabs.internalWidth ;
1672
1673 tab->tabs.width = iw + SHADWID*2 ;
1674 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1675
1676 if( tab->tabs.left_bitmap != None )
1677 {
1678 tab->tabs.width += tab->tabs.lbm_width + iw ;
1679 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1680 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1681 }
1682
1683 if( lbl != NULL && font != NULL )
1684 {
1685 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1686 tab->tabs.l_y = (tw->tabs.tab_height +
1687 tw->tabs.font->max_bounds.ascent -
1688 tw->tabs.font->max_bounds.descent)/2 ;
1689 }
1690 }
1691
1692
1693
1694 /* Lay out tabs to fit in given width. Compute x,y position and
1695 * row number for each tab. Return number of rows and total height
1696 * required by all tabs. If there is only one row, add TABDELTA
1697 * height to the total. Rows are assigned bottom to top.
1698 *
1699 * Tabs are indented from the edges by INDENT.
1700 *
1701 * TODO: if they require more than two rows and the total height:width
1702 * ratio is more than 2:1, then try something else.
1703 */
1704
1705 static int
1706 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
1707 {
1708 int i, row ;
1709 int num_children = tw->composite.num_children ;
1710 Widget *childP ;
1711 Dimension w ;
1712 Position x,y ;
1713 TabsConstraints tab ;
1714
1715 if (!query_only)
1716 tw->tabs.displayChildren = 0;
1717
1718 /* Algorithm: loop through children, assign X positions. If a tab
1719 * would extend beyond the right edge, start a new row. After all
1720 * rows are assigned, make a second pass and assign Y positions.
1721 */
1722
1723 if( num_children > 0 )
1724 {
1725 /* Loop through the tabs and see how much space they need. */
1726
1727 row = 0 ;
1728 x = INDENT ;
1729 y = 0 ;
1730 wid -= INDENT ;
1731 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1732 if( XtIsManaged(*childP) )
1733 {
1734 tab = (TabsConstraints) (*childP)->core.constraints ;
1735 w = tab->tabs.width ;
1736 if( x + w > wid ) { /* new row */
1737 if (y + tw->tabs.tab_height > hgt)
1738 break;
1739 ++row ;
1740 x = INDENT ;
1741 y += tw->tabs.tab_height ;
1742 }
1743 if( !query_only ) {
1744 tab->tabs.x = x ;
1745 tab->tabs.y = y ;
1746 tab->tabs.row = row ;
1747 }
1748 x += w + SPACING ;
1749 if (!query_only)
1750 tw->tabs.displayChildren++;
1751 }
1752 /* If there was only one row, increse the height by TABDELTA */
1753 if( ++row == 1 )
1754 {
1755 y = TABDELTA ;
1756 if( !query_only )
1757 for(i=num_children, childP=tw->composite.children;
1758 --i >= 0 ; ++childP)
1759 if( XtIsManaged(*childP) )
1760 {
1761 tab = (TabsConstraints) (*childP)->core.constraints ;
1762 tab->tabs.y = y ;
1763 }
1764 }
1765 y += tw->tabs.tab_height ;
1766 }
1767 else
1768 row = y = 0 ;
1769
1770 if( !query_only ) {
1771 tw->tabs.tab_total = y ;
1772 tw->tabs.numRows = row ;
1773 }
1774
1775 if( reply_height != NULL )
1776 *reply_height = y ;
1777
1778 return row ;
1779 }
1780
1781
1782
1783 /* Find max preferred child size. Returned sizes include child
1784 * border widths.
1785 */
1786
1787 static void
1788 GetPreferredSizes(TabsWidget tw)
1789 {
1790 MaxChild(tw, NULL, 0,0) ;
1791 }
1792
1793
1794
1795 /* Find max preferred child size. Returned sizes include child
1796 * border widths. If except is non-null, don't ask that one.
1797 */
1798
1799 static void
1800 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
1801 {
1802 int i ;
1803 Widget *childP = tw->composite.children ;
1804 XtWidgetGeometry preferred ;
1805
1806 for(i=tw->composite.num_children; --i >=0; ++childP)
1807 if( XtIsManaged(*childP) && *childP != except )
1808 {
1809 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1810 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
1811 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
1812 }
1813
1814 tw->tabs.max_cw = cw ;
1815 tw->tabs.max_ch = ch ;
1816 }
1817
1818
1819
1820 /* rotate row numbers to bring current widget to bottom row,
1821 * compute y positions for all tabs
1822 */
1823
1824 static void
1825 TabsShuffleRows(TabsWidget tw)
1826 {
1827 TabsConstraints tab ;
1828 int move ;
1829 int nrows ;
1830 Widget *childP ;
1831 Dimension th = tw->tabs.tab_height ;
1832 Position bottom ;
1833 int i ;
1834
1835 /* There must be a top widget. If not, assign one. */
1836 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1837 for(i=tw->composite.num_children, childP=tw->composite.children;
1838 --i >= 0;
1839 ++childP)
1840 if( XtIsManaged(*childP) ) {
1841 tw->tabs.topWidget = *childP ;
1842 break ;
1843 }
1844
1845 if( tw->tabs.topWidget != NULL )
1846 {
1847 nrows = tw->tabs.numRows ;
1848 assert( nrows > 0 ) ;
1849
1850 if( nrows > 1 )
1851 {
1852 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1853 assert( tab != NULL ) ;
1854
1855 /* how far to move top row */
1856 move = nrows - tab->tabs.row ;
1857 bottom = tw->tabs.tab_total - th ;
1858
1859 for(i=tw->tabs.displayChildren, childP=tw->composite.children;
1860 --i >= 0;
1861 ++childP)
1862 if( XtIsManaged(*childP) )
1863 {
1864 tab = (TabsConstraints) (*childP)->core.constraints ;
1865 tab->tabs.row = (tab->tabs.row + move) % nrows ;
1866 tab->tabs.y = bottom - tab->tabs.row * th ;
1867 }
1868 }
1869 }
1870 }
1871
1872
1873 /* Find preferred size. Ask children, find size of largest,
1874 * add room for tabs & return. This can get a little involved,
1875 * as we don't want to have too many rows of tabs; we may widen
1876 * the widget to reduce # of rows.
1877 *
1878 * This function requires that max_cw, max_ch already be set.
1879 */
1880
1881 static int
1882 PreferredSize(
1883 TabsWidget tw,
1884 Dimension *reply_width, /* total widget size */
1885 Dimension *reply_height,
1886 Dimension *reply_cw, /* child widget size */
1887 Dimension *reply_ch)
1888 {
1889 Dimension cw,ch ; /* child width, height */
1890 Dimension wid,hgt ;
1891 Dimension rwid,rhgt ;
1892 int nrow ;
1893
1894 wid = cw = tw->tabs.max_cw ;
1895 hgt = ch = tw->tabs.max_ch ;
1896
1897 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1898
1899 /* Check for absurd results (more than 2 rows, high aspect
1900 * ratio). Try wider size if needed.
1901 * TODO: make sure this terminates.
1902 */
1903
1904 if( nrow > 2 && rhgt > rwid )
1905 {
1906 Dimension w0, w1 ;
1907 int maxloop = 20 ;
1908
1909 /* step 1: start doubling size until it's too big */
1910 do {
1911 w0 = wid ;
1912 wid = Max(wid*2, wid+20) ;
1913 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1914 } while( nrow > 2 && rhgt > rwid ) ;
1915 w1 = wid ;
1916
1917 /* step 2: use Newton's method to find ideal size. Stop within
1918 * 8 pixels.
1919 */
1920 while( --maxloop > 0 && w1 > w0 + 8 )
1921 {
1922 wid = (w0+w1)/2 ;
1923 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1924 if( nrow > 2 && rhgt > rwid )
1925 w0 = wid ;
1926 else
1927 w1 = wid ;
1928 }
1929 wid = w1 ;
1930 }
1931
1932 *reply_width = rwid ;
1933 *reply_height = rhgt ;
1934 if( reply_cw != NULL ) *reply_cw = cw ;
1935 if( reply_ch != NULL ) *reply_ch = ch ;
1936 return nrow ;
1937 }
1938
1939
1940 /* Find preferred size, given size of children. */
1941
1942 static int
1943 PreferredSize2(
1944 TabsWidget tw,
1945 int cw, /* child width, height */
1946 int ch,
1947 Dimension *reply_width, /* total widget size */
1948 Dimension *reply_height)
1949 {
1950 Dimension s = SHADWID ;
1951
1952 /* make room for shadow frame */
1953 cw += s*2 ;
1954 ch += s*2 ;
1955
1956 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1957 }
1958
1959
1960 /* Find preferred size, given size of children+shadow. */
1961
1962 static int
1963 PreferredSize3(
1964 TabsWidget tw,
1965 int wid, /* child width, height */
1966 int hgt,
1967 Dimension *reply_width, /* total widget size */
1968 Dimension *reply_height)
1969 {
1970 Dimension th ; /* space used by tabs */
1971 int nrows ;
1972
1973 if( tw->composite.num_children > 0 )
1974 nrows = TabLayout(tw, wid, hgt, &th, True) ;
1975 else {
1976 th = 0 ;
1977 nrows = 0 ;
1978 }
1979
1980 *reply_width = Max(wid, MIN_WID) ;
1981 *reply_height = Max(th+hgt, MIN_HGT) ;
1982
1983 return nrows ;
1984 }
1985
1986
1987 static void
1988 MakeSizeRequest(TabsWidget tw)
1989 {
1990 Widget w = (Widget)tw ;
1991 XtWidgetGeometry request, reply ;
1992 XtGeometryResult result ;
1993 Dimension cw,ch ;
1994
1995 request.request_mode = CWWidth | CWHeight ;
1996 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
1997
1998 if( request.width == tw->core.width &&
1999 request.height == tw->core.height )
2000 return ;
2001
2002 result = XtMakeGeometryRequest(w, &request, &reply) ;
2003
2004 if( result == XtGeometryAlmost )
2005 {
2006 /* Bugger. Didn't get what we want, but were offered a
2007 * compromise. If the width was too small, recompute
2008 * based on the too-small width and try again.
2009 * If the height was too small, make a wild-ass guess
2010 * at a wider width and try again.
2011 */
2012
2013 if( reply.width < request.width && reply.height >= request.height )
2014 {
2015 Dimension s = SHADWID ;
2016 ch += s*2 ;
2017 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
2018 result = XtMakeGeometryRequest(w, &request, &reply) ;
2019 if( result == XtGeometryAlmost )
2020 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2021 }
2022
2023 else
2024 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2025 }
2026 }
2027
2028
2029 static void
2030 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2031 {
2032 Window root ;
2033 int x,y ;
2034 unsigned int bw ;
2035
2036 if( tab->tabs.left_bitmap == None ||
2037 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2038 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2039 &bw, &tab->tabs.lbm_depth) )
2040 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2041 }
2042
2043
2044
2045
2046 /* Code copied & modified from Gcs.c. This version has dynamic
2047 * foreground.
2048 */
2049
2050 static void
2051 TabsAllocFgGC(TabsWidget tw)
2052 {
2053 Widget w = (Widget) tw;
2054 XGCValues values ;
2055
2056 values.background = tw->core.background_pixel ;
2057 values.font = tw->tabs.font->fid ;
2058 values.line_style = LineOnOffDash ;
2059 values.line_style = LineSolid ;
2060
2061 tw->tabs.foregroundGC =
2062 XtAllocateGC(w, w->core.depth,
2063 GCBackground|GCFont|GCLineStyle, &values,
2064 GCForeground,
2065 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2066 GCDashList|GCArcMode) ;
2067 }
2068
2069 static void
2070 TabsAllocGreyGC(TabsWidget tw)
2071 {
2072 Widget w = (Widget) tw;
2073 XGCValues values ;
2074
2075 values.background = tw->core.background_pixel ;
2076 values.font = tw->tabs.font->fid ;
2077 #ifdef HAVE_XMU
2078 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2079 {
2080 values.fill_style = FillStippled ;
2081 tw->tabs.grey50 =
2082 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2083
2084 tw->tabs.greyGC =
2085 XtAllocateGC(w, w->core.depth,
2086 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2087 GCForeground,
2088 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2089 GCDashList|GCArcMode) ;
2090 }
2091 else
2092 #endif
2093 {
2094 tw->tabs.greyGC =
2095 XtAllocateGC(w, w->core.depth,
2096 GCFont, &values,
2097 GCForeground,
2098 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2099 GCDashList|GCArcMode) ;
2100 }
2101 }