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