1 /* Tabs Widget for XEmacs.
2 Copyright (C) 1999 Edward A. Falk
4 This file is part of XEmacs.
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
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
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. */
21 /* Synched up with: Tabs.c 1.23 */
24 * Tabs.c - Index Tabs composite widget
26 * Author: Edward A. Falk
27 * falk@falconer.vip.best.com
32 * Overall layout of this widget is as follows:
34 * ________ ,---------. _________
35 * | label || Label || Label | \ tabs
36 * |________|| ||_________| /
37 * |+----------------------------+| \
39 * || child widget window || > frame
40 * |+----------------------------+| |
41 * +------------------------------+ /
43 * The height of the tabs includes the shadow width, top and bottom
44 * margins, and the height of the text.
46 * The height of the frame includes the top and bottom shadow width and the
47 * size of the child widget window.
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
54 /* TODO: min child height = tab height
62 #include <X11/IntrinsicP.h>
63 #include <X11/StringDefs.h>
64 #include "../src/xmu.h"
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 */
77 /****************************************************************
81 ****************************************************************/
83 static char defaultTranslations[] = "\
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\
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\
125 static XtAccelerators defaultAccelerators ;
127 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
128 static XtResource resources[] = {
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},
161 /* constraint resources */
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},
179 #if !NeedFunctionPrototypes
181 /* FORWARD REFERENCES: */
183 /* member functions */
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() ;
200 static void TabsSelect() ;
201 static void TabsPage() ;
202 static void TabsHighlight() ;
203 static void TabsUnhighlight() ;
205 /* internal privates */
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 */
227 static void TabsAllocFgGC() ;
228 static void TabsAllocGreyGC() ;
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) ;
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 *) ;
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) ;
262 static void TabWidth( Widget w) ;
263 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
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) ;
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) ;
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)
289 static XtActionsRec actionsList[] =
291 {"select", TabsSelect},
293 {"highlight", TabsHighlight},
294 {"unhighlight", TabsUnhighlight},
298 /****************************************************************
300 * Full class record constant
302 ****************************************************************/
305 #define SuperClass (&constraintClassRec)
307 #define SuperClass (&xmManagerClassRec)
310 TabsClassRec tabsClassRec = {
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,
347 /* composite_class fields */
348 /* geometry_manager */ TabsGeometryManager,
349 /* change_managed */ TabsChangeManaged,
350 /* insert_child */ XtInheritInsertChild, /* TODO? */
351 /* delete_child */ XtInheritDeleteChild, /* TODO? */
355 /* constraint_class fields */
356 /* subresources */ tabsConstraintResources,
357 /* subresource_count */ XtNumber(tabsConstraintResources),
358 /* constraint_size */ sizeof(TabsConstraintsRec),
359 /* initialize */ TabsConstraintInitialize,
361 /* set_values */ TabsConstraintSetValues,
362 /* extension */ NULL,
365 /* Manager Class fields */
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,
377 /* Tabs class fields */
378 /* extension */ NULL,
382 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
389 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
392 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
401 /****************************************************************
405 ****************************************************************/
410 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
411 /* TODO: register converter for labels? */
416 /* Init a newly created tabs widget. Compute height of tabs
417 * and optionally compute size of widget. */
422 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
424 TabsWidget newTw = (TabsWidget)new;
426 newTw->tabs.numRows = 0 ;
427 newTw->tabs.displayChildren = 0;
429 GetPreferredSizes(newTw) ;
431 /* height is easy, it's the same for all tabs:
432 * TODO: font height + height of tallest bitmap.
434 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
436 if( newTw->tabs.font != NULL )
437 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
438 newTw->tabs.font->max_bounds.descent ;
440 /* GC allocation is deferred until XtRealize() */
442 /* if size not explicitly set, set it to our preferred size now. */
444 if( request->core.width == 0 || request->core.height == 0 )
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) ;
453 /* defer GC allocation, etc., until Realize() time. */
454 newTw->tabs.foregroundGC =
455 newTw->tabs.backgroundGC =
458 newTw->tabs.botGC = None ;
460 newTw->tabs.grey50 = None ;
462 newTw->tabs.needs_layout = False ;
464 newTw->tabs.hilight = NULL ;
467 newTw->manager.navigation_type = XmTAB_GROUP ;
468 newTw->manager.traversal_on = True ;
473 /* Init the constraint part of a new tab child. Compute the
478 TabsConstraintInitialize(Widget request, Widget new,
479 ArgList args, Cardinal *num_args)
481 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
482 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
483 tab->tabs.queried = False ; /* defer size query */
485 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
491 /* Called when tabs widget first realized. Create the window
492 * and allocate the GCs
496 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
498 TabsWidget tw = (TabsWidget) w;
500 attributes->bit_gravity = NorthWestGravity;
501 *valueMask |= CWBitGravity;
503 SuperClass->core_class.realize(w, valueMask, attributes);
511 TabsDestroy(Widget w)
513 TabsFreeGCs((TabsWidget)w) ;
517 /* Parent has resized us. This will require that the tabs be
524 TabsWidget tw = (TabsWidget) w;
526 int num_children = tw->composite.num_children ;
528 TabsConstraints tab ;
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.
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
542 if( num_children > 0 && tw->composite.children != NULL )
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;
548 /* assign a top widget, bring it to bottom row. */
549 TabsShuffleRows(tw) ;
551 /* now assign child positions & sizes. Positions are all the
552 * same: just inside the frame. Sizes are also all the same.
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 ;
560 for(i=0, childP=tw->composite.children;
563 if( XtIsManaged(*childP) )
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) ;
570 if( XtIsRealized(w) )
571 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
574 tw->tabs.needs_layout = False ;
579 /* Redraw entire Tabs widget */
583 TabsExpose(Widget w, XEvent *event, Region region)
585 TabsWidget tw = (TabsWidget) w;
587 if( tw->tabs.needs_layout )
588 XtClass(w)->core_class.resize(w) ;
594 /* Called when any Tabs widget resources are changed. */
598 TabsSetValues(Widget current, Widget request, Widget new,
599 ArgList args, Cardinal *num_args)
601 TabsWidget curtw = (TabsWidget) current ;
602 TabsWidget tw = (TabsWidget) new ;
603 Boolean needRedraw = False ;
608 if( tw->tabs.font != curtw->tabs.font ||
609 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
610 tw->tabs.internalHeight != curtw->tabs.internalHeight )
612 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
614 if( tw->tabs.font != NULL )
615 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
616 tw->tabs.font->max_bounds.descent ;
618 /* Tab size has changed. Resize all tabs and request a new size */
619 for(i=0, childP=tw->composite.children;
620 i < tw->composite.num_children;
622 if( XtIsManaged(*childP) )
624 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
626 tw->tabs.needs_layout = True ;
629 /* TODO: if any color changes, need to recompute GCs and redraw */
631 if( tw->core.background_pixel != curtw->core.background_pixel ||
632 tw->core.background_pixmap != curtw->core.background_pixmap )
633 if( XtIsRealized(new) )
640 if( tw->core.sensitive != curtw->core.sensitive )
643 /* If top widget changes, need to change stacking order, redraw tabs.
644 * Window system will handle the redraws.
647 if( tw->tabs.topWidget != curtw->tabs.topWidget ) {
648 if( XtIsRealized(tw->tabs.topWidget) )
650 Widget w = tw->tabs.topWidget ;
651 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
653 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
655 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
656 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
659 if( tab->tabs.row != tw->tabs.numRows-1 )
660 TabsShuffleRows(tw) ;
666 tw->tabs.needs_layout = True ;
672 /* Called when any child constraint resources change. */
676 TabsConstraintSetValues(Widget current, Widget request, Widget new,
677 ArgList args, Cardinal *num_args)
679 TabsWidget tw = (TabsWidget) XtParent(new) ;
680 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
681 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
684 /* if label changes, need to re-layout the entire widget */
685 /* if foreground changes, need to redraw tab label */
687 /* TODO: only need resize of new bitmap has different dimensions
691 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
692 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
695 tw->tabs.needs_layout = True ;
697 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
698 getBitmapInfo(tw, tab) ;
700 /* If there are no subclass ConstraintSetValues procedures remaining
701 * to be invoked, and if the preferred size has changed, ask
704 if( XtClass((Widget)tw) == tabsWidgetClass )
705 MakeSizeRequest(tw) ;
709 /* The child widget itself never needs a redisplay, but the parent
713 if( XtIsRealized(new) )
715 if( tw->tabs.needs_layout ) {
716 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
717 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
720 else if( tab->tabs.foreground != ctab->tabs.foreground )
721 DrawTab(tw, new, True) ;
730 * Return preferred size. Happily accept anything >= our preferred size.
731 * (TODO: is that the right thing to do? Should we always return "almost"
732 * if offerred more than we need?)
735 static XtGeometryResult
736 TabsQueryGeometry(Widget w,
737 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
739 register TabsWidget tw = (TabsWidget)w ;
740 XtGeometryMask mode = intended->request_mode ;
742 preferred->request_mode = CWWidth | CWHeight ;
743 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
745 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
746 (!(mode & CWHeight) || intended->height == w->core.height) )
747 return XtGeometryNo ;
750 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
751 (!(mode & CWHeight) || intended->height >= preferred->height) )
752 return XtGeometryYes;
755 return XtGeometryAlmost;
761 * Geometry Manager; called when a child wants to be resized.
764 static XtGeometryResult
765 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
767 TabsWidget tw = (TabsWidget) XtParent(w);
768 Dimension s = SHADWID ;
769 TabsConstraints tab = (TabsConstraints)w->core.constraints;
770 XtGeometryResult result ;
772 /* Position request always denied */
774 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
775 ((req->request_mode & CWY) && req->y != w->core.y) ||
776 !tab->tabs.resizable )
777 return XtGeometryNo ;
779 /* Make all three fields in the request valid */
780 if( !(req->request_mode & CWWidth) )
781 req->width = w->core.width;
782 if( !(req->request_mode & CWHeight) )
783 req->height = w->core.height;
784 if( !(req->request_mode & CWBorderWidth) )
785 req->border_width = w->core.border_width;
787 if( req->width == w->core.width &&
788 req->height == w->core.height &&
789 req->border_width == w->core.border_width )
790 return XtGeometryNo ;
792 /* updated cached preferred size of the child */
793 tab->tabs.bwid = req->border_width ;
794 tab->tabs.wid = req->width + req->border_width * 2 ;
795 tab->tabs.hgt = req->height + req->border_width * 2 ;
799 /* Size changes must see if the new size can be accommodated.
800 * The Tabs widget keeps all of its children the same
801 * size. A request to shrink will be accepted only if the
802 * new size is still big enough for all other children. A
803 * request to shrink that is not big enough for all children
804 * returns an "almost" response with the new proposed size.
805 * A request to grow will be accepted only if the Tabs parent can
806 * grow to accommodate.
809 * We could get fancy here and re-arrange the tabs if it is
810 * necessary to compromise with the parent, but we'll save that
814 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
816 Dimension rw,rh ; /* child's requested width, height */
817 Dimension cw,ch ; /* children's preferred size */
818 Dimension aw,ah ; /* available size we can give child */
819 Dimension th ; /* space used by tabs */
820 Dimension wid,hgt ; /* Tabs widget size */
822 rw = cw = tab->tabs.wid ;
823 rh = ch = tab->tabs.hgt ;
825 /* find out what the resulting preferred size would be */
828 MaxChild(tw, &cw, &ch) ;
830 PreferredSize2(tw, tw->tabs.max_cw,tw->tabs.max_ch, &wid, &hgt) ;
832 /* Ask to be resized to accommodate. */
834 if( wid != tw->core.width || hgt != tw->core.height )
836 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
837 XtWidgetGeometry myrequest, myreply ;
839 myrequest.width = wid ;
840 myrequest.height = hgt ;
841 myrequest.request_mode = CWWidth | CWHeight ;
843 /* If child is only querying, or if we're going to have to
844 * offer the child a compromise, then make this a query only.
847 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
848 myrequest.request_mode |= XtCWQueryOnly ;
850 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
852 /* !$@# Box widget changes the core size even if QueryOnly
853 * is set. I'm convinced this is a bug. At any rate, to work
854 * around the bug, we need to restore the core size after every
855 * query geometry request. This is only partly effective,
856 * as there may be other boxes further up the tree.
858 if( myrequest.request_mode & XtCWQueryOnly ) {
859 tw->core.width = oldWid ;
860 tw->core.height = oldHgt ;
863 /* based on the parent's response, determine what the
864 * resulting Tabs widget size would be.
873 wid = tw->core.width ;
874 hgt = tw->core.height ;
877 case XtGeometryAlmost:
878 wid = myreply.width ;
879 hgt = myreply.height ;
883 /* Within the constraints imposed by the parent, what is
884 * the max size we can give the child?
886 (void) TabLayout(tw, wid, hgt, &th, True) ;
888 ah = hgt - th - 2*s ;
890 /* OK, make our decision. If requested size is >= max sibling
891 * preferred size, AND requested size <= available size, then
892 * we accept. Otherwise, we offer a compromise.
895 if( rw == aw && rh == ah )
897 /* Acceptable. If this wasn't a query, change *all* children
900 if( req->request_mode & XtCWQueryOnly )
901 return XtGeometryYes ;
904 Widget *childP = tw->composite.children ;
906 w->core.border_width = req->border_width ;
907 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
908 if( XtIsManaged(*childP) )
910 bw = (*childP)->core.border_width ;
911 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
912 rw-2*bw, rh-2*bw, bw) ;
915 /* TODO: under what conditions will we need to redraw? */
916 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
917 XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
919 return XtGeometryDone ;
923 /* Cannot grant child's request. Describe what we *can* do
924 * and return counter-offer.
926 reply->width = aw - 2 * req->border_width ;
927 reply->height = ah - 2 * req->border_width ;
928 reply->border_width = req->border_width ;
929 reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
930 return XtGeometryAlmost ;
933 return XtGeometryYes ;
939 /* The number of children we manage has changed; recompute
944 TabsChangeManaged(Widget w)
946 TabsWidget tw = (TabsWidget)w ;
947 Widget *childP = tw->composite.children ;
950 if( tw->tabs.topWidget != NULL &&
951 ( !XtIsManaged(tw->tabs.topWidget) ||
952 tw->tabs.topWidget->core.being_destroyed ) )
953 tw->tabs.topWidget = NULL ;
955 GetPreferredSizes(tw) ;
956 MakeSizeRequest(tw) ;
958 XtClass(w)->core_class.resize(w) ;
959 if( XtIsRealized(w) )
961 Display *dpy = XtDisplay(w) ;
962 XClearWindow(dpy, XtWindow(w)) ;
963 XtClass(w)->core_class.expose(w,NULL,NULL) ;
965 /* make sure the top widget stays on top. This requires
966 * making sure that all new children are realized first.
968 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
970 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
971 if( !XtIsRealized(*childP) )
972 XtRealizeWidget(*childP) ;
974 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
979 /* Only top widget may receive input */
981 for(childP = tw->composite.children, i=tw->composite.num_children;
985 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
988 if( tw->tabs.topWidget != NULL )
989 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
999 /****************************************************************
1003 ****************************************************************/
1006 /* User clicks on a tab, figure out which one it was. */
1010 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
1012 TabsWidget tw = (TabsWidget) w ;
1015 Dimension h = tw->tabs.tab_height ;
1019 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
1022 /* TODO: is there an Xmu function or something to do this instead? */
1023 switch( event->type ) {
1026 x = event->xbutton.x ; y = event->xbutton.y ; break ;
1029 x = event->xkey.x ; y = event->xkey.y ; break ;
1034 /* TODO: determine which tab was clicked, if any. Set that
1035 * widget to be top of stacking order with XawTabsSetTop().
1037 for(i=0, childP=tw->composite.children;
1038 i < tw->tabs.displayChildren;
1040 if( XtIsManaged(*childP) )
1042 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
1043 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
1044 y > tab->tabs.y && y < tab->tabs.y + h )
1046 if( *childP != tw->tabs.topWidget &&
1047 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
1048 XawTabsSetTop(*childP, True) ;
1055 /* User hits a key */
1058 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
1060 TabsWidget tw = (TabsWidget) w ;
1061 Widget newtop = NULL;
1064 int nc = tw->composite.num_children ;
1069 if( *num_params < 1 ) {
1070 XtAppWarning(XtWidgetToApplicationContext(w),
1071 "Tabs: page() action called with no arguments") ;
1075 if( tw->tabs.topWidget == NULL )
1076 tw->tabs.topWidget = tw->composite.children[0] ;
1078 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1079 if( tw->tabs.topWidget == *childP )
1082 switch( params[0][0] ) {
1087 newtop = tw->composite.children[idx-1] ;
1090 case 'd': /* down */
1094 newtop = tw->composite.children[idx] ;
1099 newtop = tw->composite.children[0] ;
1104 newtop = tw->composite.children[nc-1] ;
1107 case 's': /* selected */
1109 if( (newtop = tw->tabs.hilight) == NULL )
1114 XawTabsSetTop(newtop, True) ;
1118 /* User hits up/down key */
1121 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1123 TabsWidget tw = (TabsWidget) w ;
1124 Widget newhl = NULL;
1127 int nc = tw->composite.num_children ;
1132 if( *num_params < 1 )
1134 if( tw->tabs.hilight != NULL )
1135 DrawHighlight(tw, tw->tabs.hilight, False) ;
1139 if( tw->tabs.hilight == NULL )
1140 newhl = tw->composite.children[0] ;
1144 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1145 if( tw->tabs.hilight == *childP )
1148 switch( params[0][0] ) {
1153 newhl = tw->composite.children[idx-1] ;
1156 case 'd': /* down */
1160 newhl = tw->composite.children[idx] ;
1165 newhl = tw->composite.children[0] ;
1170 newhl = tw->composite.children[nc-1] ;
1175 XawTabsSetHighlight(w, newhl) ;
1181 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1183 TabsWidget tw = (TabsWidget) w ;
1184 int nc = tw->composite.num_children ;
1189 if( tw->tabs.hilight != NULL )
1190 DrawHighlight(tw, tw->tabs.hilight, True) ;
1197 /****************************************************************
1201 ****************************************************************/
1204 /* Set the top tab, optionally call all callbacks. */
1206 XawTabsSetTop(Widget w, Bool callCallbacks)
1208 TabsWidget tw = (TabsWidget)w->core.parent ;
1209 TabsConstraints tab ;
1210 Widget oldtop = tw->tabs.topWidget ;
1212 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
1215 sprintf(line, "XawTabsSetTop: widget \"%s\" is not the child of a tabs widget.", XtName(w)) ;
1216 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
1221 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
1222 (XtPointer)tw->tabs.topWidget) ;
1224 if( !XtIsRealized(w) ) {
1225 tw->tabs.topWidget = w ;
1226 tw->tabs.needs_layout = True ;
1230 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
1232 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
1233 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
1236 tab = (TabsConstraints) w->core.constraints ;
1237 if( tab->tabs.row == 0 )
1239 /* Easy case; undraw current top, undraw new top, assign new
1240 * top, redraw all borders.
1241 * We *could* just erase and execute a full redraw, but I like to
1242 * reduce screen flicker.
1244 UndrawTab(tw, oldtop) ; /* undraw old */
1245 DrawBorder(tw, oldtop, True) ;
1246 UndrawTab(tw, w) ; /* undraw new */
1247 DrawBorder(tw, w, True) ;
1248 tw->tabs.topWidget = w ;
1249 DrawTab(tw, oldtop, True) ; /* redraw old */
1250 DrawTab(tw, w, True) ; /* redraw new */
1251 DrawTabs(tw, False) ;
1255 tw->tabs.topWidget = w ;
1256 TabsShuffleRows(tw) ;
1257 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
1258 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
1261 XawTabsSetHighlight((Widget)tw, w) ;
1264 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
1268 /* Set the top tab, optionally call all callbacks. */
1270 XawTabsSetHighlight(Widget t, Widget w)
1272 TabsWidget tw = (TabsWidget)t ;
1274 if( !XtIsSubclass(t, tabsWidgetClass) )
1277 if( XtIsRealized(t) && w != tw->tabs.hilight )
1279 if( tw->tabs.hilight != NULL )
1280 DrawHighlight(tw, tw->tabs.hilight, True) ;
1282 DrawHighlight(tw, w, False) ;
1285 tw->tabs.hilight = w ;
1291 /****************************************************************
1293 * Private Procedures
1295 ****************************************************************/
1299 TabsAllocGCs(TabsWidget tw)
1302 TabsAllocGreyGC(tw) ;
1303 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
1304 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
1305 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1306 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
1307 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1312 TabsFreeGCs(TabsWidget tw)
1314 Widget w = (Widget) tw;
1316 XtReleaseGC(w, tw->tabs.foregroundGC) ;
1317 XtReleaseGC(w, tw->tabs.greyGC) ;
1318 XtReleaseGC(w, tw->tabs.backgroundGC) ;
1319 XtReleaseGC(w, tw->tabs.topGC) ;
1320 XtReleaseGC(w, tw->tabs.botGC) ;
1322 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
1330 /* Redraw entire Tabs widget */
1333 DrawTabs(TabsWidget tw, Bool labels)
1337 Dimension s = SHADWID ;
1338 Dimension th = tw->tabs.tab_height ;
1340 TabsConstraints tab ;
1342 if( !XtIsRealized((Widget)tw))
1345 /* draw tabs and frames by row except for the top tab, which
1346 * is drawn last. (This is inefficiently written, but should not
1347 * be too slow as long as there are not a lot of rows.)
1350 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
1351 for(i=0; i<tw->tabs.numRows; ++i, y += th)
1353 for( j=tw->tabs.displayChildren, childP=tw->composite.children;
1354 --j >= 0; ++childP )
1355 if( XtIsManaged(*childP) )
1357 tab = (TabsConstraints)(*childP)->core.constraints;
1358 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
1359 DrawTab(tw, *childP, labels) ;
1361 if( i != tw->tabs.numRows -1 )
1362 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
1367 /* and now the top tab */
1368 if( tw->tabs.topWidget != NULL )
1369 DrawTab(tw, tw->tabs.topWidget, labels) ;
1374 /* Draw one tab. Corners are rounded very slightly. */
1377 DrawTab(TabsWidget tw, Widget child, Bool labels)
1382 if( !XtIsRealized((Widget)tw))
1385 DrawBorder(tw, child, False) ;
1389 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1390 Display *dpy = XtDisplay((Widget)tw) ;
1391 Window win = XtWindow((Widget)tw) ;
1392 String lbl = tab->tabs.label != NULL ?
1393 tab->tabs.label : XtName(child) ;
1395 if( XtIsSensitive(child) )
1397 gc = tw->tabs.foregroundGC ;
1398 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1402 /* grey pixel allocation deferred until now */
1403 if( !tab->tabs.greyAlloc )
1405 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
1406 tab->tabs.grey = tab->tabs.foreground ;
1408 tab->tabs.grey = AllocGreyPixel((Widget)tw,
1409 tab->tabs.foreground,
1410 tw->core.background_pixel,
1411 tw->tabs.insensitive_contrast ) ;
1412 tab->tabs.greyAlloc = True ;
1414 gc = tw->tabs.greyGC ;
1415 XSetForeground(dpy, gc, tab->tabs.grey) ;
1420 if( child == tw->tabs.topWidget )
1423 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
1425 if( tab->tabs.lbm_depth == 1 )
1426 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
1427 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1428 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
1430 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
1431 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1432 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
1435 if( lbl != NULL && tw->tabs.font != NULL )
1436 XDrawString(dpy,win,gc,
1437 x+tab->tabs.l_x, y+tab->tabs.l_y,
1438 lbl, (int)strlen(lbl)) ;
1441 if( child == tw->tabs.hilight )
1442 DrawHighlight(tw, child, False) ;
1446 /* draw frame all the way around the child windows. */
1449 DrawFrame(TabsWidget tw)
1451 GC topgc = tw->tabs.topGC ;
1452 GC botgc = tw->tabs.botGC ;
1453 Dimension s = SHADWID ;
1454 Dimension ch = tw->tabs.child_height ;
1455 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1456 tw->core.width, ch+2*s, s, topgc, botgc) ;
1460 /* draw trim around a tab or underneath a row of tabs */
1463 DrawTrim(TabsWidget tw, /* widget */
1464 int x, /* upper-left corner */
1466 int wid, /* total size */
1468 Bool bottom, /* draw bottom? */
1469 Bool undraw) /* undraw all */
1471 Display *dpy = XtDisplay((Widget)tw) ;
1472 Window win = XtWindow((Widget)tw) ;
1473 GC bggc = tw->tabs.backgroundGC ;
1474 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1475 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1477 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1478 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1479 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1480 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1481 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1482 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1486 /* Draw one tab border. */
1489 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1491 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1492 Position x = tab->tabs.x ;
1493 Position y = tab->tabs.y ;
1494 Dimension twid = tab->tabs.width ;
1495 Dimension thgt = tw->tabs.tab_height ;
1497 /* top tab requires a little special attention; it overlaps
1498 * neighboring tabs slightly, so the background must be cleared
1499 * in the region of the overlap to partially erase those neighbors.
1500 * TODO: is this worth doing with regions instead?
1502 if( child == tw->tabs.topWidget )
1504 Display *dpy = XtDisplay((Widget)tw) ;
1505 Window win = XtWindow((Widget)tw) ;
1506 GC bggc = tw->tabs.backgroundGC ;
1507 XRectangle rects[3] ;
1510 twid += TABDELTA*2 ;
1512 AddRect(0, x,y+1,twid,TABDELTA) ;
1513 AddRect(1, x+1,y,TABDELTA,thgt) ;
1514 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1515 XFillRectangles(dpy,win,bggc, rects, 3) ;
1518 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1522 /* Draw highlight around tab that has focus */
1525 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1527 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1528 Display *dpy = XtDisplay((Widget)tw) ;
1529 Window win = XtWindow((Widget)tw) ;
1531 Position x = tab->tabs.x ;
1532 Position y = tab->tabs.y ;
1533 Dimension wid = tab->tabs.width ;
1534 Dimension hgt = tw->tabs.tab_height ;
1537 /* top tab does not have a highlight */
1539 if( child == tw->tabs.topWidget )
1543 gc = tw->tabs.backgroundGC ;
1545 else if( XtIsSensitive(child) )
1547 gc = tw->tabs.foregroundGC ;
1548 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1552 gc = tw->tabs.greyGC ;
1553 XSetForeground(dpy, gc, tab->tabs.grey) ;
1556 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1557 points[1].x = x+1 ; points[1].y = y+2 ;
1558 points[2].x = x+2 ; points[2].y = y+1 ;
1559 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1560 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1561 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1563 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1567 /* Undraw one tab interior */
1570 UndrawTab(TabsWidget tw, Widget child)
1572 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1573 Position x = tab->tabs.x ;
1574 Position y = tab->tabs.y ;
1575 Dimension twid = tab->tabs.width ;
1576 Dimension thgt = tw->tabs.tab_height ;
1577 Display *dpy = XtDisplay((Widget)tw) ;
1578 Window win = XtWindow((Widget)tw) ;
1579 GC bggc = tw->tabs.backgroundGC ;
1581 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1588 /* GEOMETRY UTILITIES */
1591 /* Compute the size of one child's tab. Positions will be computed
1594 * height: font height + vertical_space*2 + shadowWid*2
1595 * width: string width + horizontal_space*2 + shadowWid*2
1597 * All tabs are the same height, so that is computed elsewhere.
1603 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1604 TabsWidget tw = (TabsWidget)XtParent(w) ;
1605 String lbl = tab->tabs.label != NULL ?
1606 tab->tabs.label : XtName(w) ;
1607 XFontStruct *font = tw->tabs.font ;
1608 int iw = tw->tabs.internalWidth ;
1610 tab->tabs.width = iw + SHADWID*2 ;
1611 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1613 if( tab->tabs.left_bitmap != None )
1615 tab->tabs.width += tab->tabs.lbm_width + iw ;
1616 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1617 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1620 if( lbl != NULL && font != NULL )
1622 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1623 tab->tabs.l_y = (tw->tabs.tab_height +
1624 tw->tabs.font->max_bounds.ascent -
1625 tw->tabs.font->max_bounds.descent)/2 ;
1631 /* Lay out tabs to fit in given width. Compute x,y position and
1632 * row number for each tab. Return number of rows and total height
1633 * required by all tabs. If there is only one row, add TABDELTA
1634 * height to the total. Rows are assigned bottom to top.
1636 * Tabs are indented from the edges by INDENT.
1638 * TODO: if they require more than two rows and the total height:width
1639 * ratio is more than 2:1, then try something else.
1643 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
1646 int num_children = tw->composite.num_children ;
1650 TabsConstraints tab ;
1653 tw->tabs.displayChildren = 0;
1655 /* Algorithm: loop through children, assign X positions. If a tab
1656 * would extend beyond the right edge, start a new row. After all
1657 * rows are assigned, make a second pass and assign Y positions.
1660 if( num_children > 0 )
1662 /* Loop through the tabs and see how much space they need. */
1668 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1669 if( XtIsManaged(*childP) )
1671 tab = (TabsConstraints) (*childP)->core.constraints ;
1672 w = tab->tabs.width ;
1673 if( x + w > wid ) { /* new row */
1674 if (y + tw->tabs.tab_height > hgt)
1678 y += tw->tabs.tab_height ;
1683 tab->tabs.row = row ;
1687 tw->tabs.displayChildren++;
1689 /* If there was only one row, increse the height by TABDELTA */
1694 for(i=num_children, childP=tw->composite.children;
1695 --i >= 0 ; ++childP)
1696 if( XtIsManaged(*childP) )
1698 tab = (TabsConstraints) (*childP)->core.constraints ;
1702 y += tw->tabs.tab_height ;
1708 tw->tabs.tab_total = y ;
1709 tw->tabs.numRows = row ;
1712 if( reply_height != NULL )
1720 /* Find max preferred child size. Returned sizes include child
1721 * border widths. We only ever ask a child its preferred
1722 * size once. After that, the preferred size is updated only
1723 * if the child makes a geometry request.
1727 GetPreferredSizes(TabsWidget tw)
1730 Widget *childP = tw->composite.children ;
1731 XtWidgetGeometry preferred ;
1732 TabsConstraints tab ;
1733 Dimension cw = 0, ch = 0 ;
1735 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
1736 if( XtIsManaged(*childP) )
1738 tab = (TabsConstraints) (*childP)->core.constraints ;
1739 if( !tab->tabs.queried ) {
1740 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1741 tab->tabs.bwid = preferred.border_width ;
1742 tab->tabs.wid = preferred.width + preferred.border_width * 2 ;
1743 tab->tabs.hgt = preferred.height + preferred.border_width * 2 ;
1744 tab->tabs.queried = True ;
1746 cw = Max(cw, tab->tabs.wid ) ;
1747 ch = Max(ch, tab->tabs.hgt ) ;
1749 tw->tabs.max_cw = cw ;
1750 tw->tabs.max_ch = ch ;
1755 /* Find max preferred child size. Returned sizes include child
1759 MaxChild(TabsWidget tw)
1761 Dimension cw,ch ; /* child width, height */
1763 Widget *childP = tw->composite.children ;
1764 TabsConstraints tab ;
1768 for(i=tw->composite.num_children; --i >=0; ++childP)
1769 if( XtIsManaged(*childP) )
1771 tab = (TabsConstraints) (*childP)->core.constraints ;
1772 cw = Max(cw, tab->tabs.wid ) ;
1773 ch = Max(ch, tab->tabs.hgt ) ;
1776 tw->tabs.max_cw = cw ;
1777 tw->tabs.max_ch = ch ;
1782 /* rotate row numbers to bring current widget to bottom row,
1783 * compute y positions for all tabs
1787 TabsShuffleRows(TabsWidget tw)
1789 TabsConstraints tab ;
1793 Dimension th = tw->tabs.tab_height ;
1797 /* There must be a top widget. If not, assign one. */
1798 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1799 for(i=tw->composite.num_children, childP=tw->composite.children;
1802 if( XtIsManaged(*childP) ) {
1803 tw->tabs.topWidget = *childP ;
1807 if( tw->tabs.topWidget != NULL )
1809 nrows = tw->tabs.numRows ;
1810 assert( nrows > 0 ) ;
1814 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1815 assert( tab != NULL ) ;
1817 /* how far to move top row */
1818 move = nrows - tab->tabs.row ;
1819 bottom = tw->tabs.tab_total - th ;
1821 for(i=tw->tabs.displayChildren, childP=tw->composite.children;
1824 if( XtIsManaged(*childP) )
1826 tab = (TabsConstraints) (*childP)->core.constraints ;
1827 tab->tabs.row = (tab->tabs.row + move) % nrows ;
1828 tab->tabs.y = bottom - tab->tabs.row * th ;
1835 /* find preferred size. Ask children, find size of largest,
1836 * add room for tabs & return. This can get a little involved,
1837 * as we don't want to have too many rows of tabs; we may widen
1838 * the widget to reduce # of rows.
1844 Dimension *reply_width, /* total widget size */
1845 Dimension *reply_height,
1846 Dimension *reply_cw, /* child widget size */
1847 Dimension *reply_ch)
1849 Dimension cw,ch ; /* child width, height */
1851 Dimension rwid,rhgt ;
1855 /* find max desired child height */
1857 MaxChild(tw, &cw, &ch) ;
1858 #endif /* COMMENT */
1860 wid = cw = tw->tabs.max_cw ;
1861 hgt = ch = tw->tabs.max_ch ;
1863 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1865 /* Check for absurd results (more than 2 rows, high aspect
1866 * ratio). Try wider size if needed.
1867 * TODO: make sure this terminates.
1870 if( nrow > 2 && rhgt > rwid )
1874 /* step 1: start doubling size until it's too big */
1877 wid = Max(wid*2, wid+20) ;
1878 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1879 } while( nrow > 2 && rhgt > rwid ) ;
1882 /* step 2: use Newton's method to find ideal size. Stop within
1885 while( w1 > w0 + 8 )
1888 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1889 if( nrow > 2 && rhgt > rwid )
1897 *reply_width = rwid ;
1898 *reply_height = rhgt ;
1899 if( reply_cw != NULL ) *reply_cw = cw ;
1900 if( reply_ch != NULL ) *reply_ch = ch ;
1905 /* Find preferred size, given size of children. */
1910 int cw, /* child width, height */
1912 Dimension *reply_width, /* total widget size */
1913 Dimension *reply_height)
1915 Dimension s = SHADWID ;
1917 /* make room for shadow frame */
1921 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1925 /* Find preferred size, given size of children+shadow. */
1930 int wid, /* child width, height */
1932 Dimension *reply_width, /* total widget size */
1933 Dimension *reply_height)
1935 Dimension th ; /* space used by tabs */
1938 if( tw->composite.num_children > 0 )
1939 nrows = TabLayout(tw, wid, hgt, &th, True) ;
1945 *reply_width = Max(wid, MIN_WID) ;
1946 *reply_height = Max(th+hgt, MIN_HGT) ;
1953 MakeSizeRequest(TabsWidget tw)
1955 Widget w = (Widget)tw ;
1956 XtWidgetGeometry request, reply ;
1957 XtGeometryResult result ;
1960 request.request_mode = CWWidth | CWHeight ;
1961 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
1963 if( request.width == tw->core.width &&
1964 request.height == tw->core.height )
1967 result = XtMakeGeometryRequest(w, &request, &reply) ;
1969 if( result == XtGeometryAlmost )
1971 /* Bugger. Didn't get what we want, but were offered a
1972 * compromise. If the width was too small, recompute
1973 * based on the too-small width and try again.
1974 * If the height was too small, make a wild-ass guess
1975 * at a wider width and try again.
1978 if( reply.width < request.width && reply.height >= request.height )
1980 Dimension s = SHADWID ;
1982 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
1983 result = XtMakeGeometryRequest(w, &request, &reply) ;
1984 if( result == XtGeometryAlmost )
1985 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
1989 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
1995 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2001 if( tab->tabs.left_bitmap == None ||
2002 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2003 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2004 &bw, &tab->tabs.lbm_depth) )
2005 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2011 /* Code copied & modified from Gcs.c. This version has dynamic
2016 TabsAllocFgGC(TabsWidget tw)
2018 Widget w = (Widget) tw;
2021 values.background = tw->core.background_pixel ;
2022 values.font = tw->tabs.font->fid ;
2023 values.line_style = LineOnOffDash ;
2024 values.line_style = LineSolid ;
2026 tw->tabs.foregroundGC =
2027 XtAllocateGC(w, w->core.depth,
2028 GCBackground|GCFont|GCLineStyle, &values,
2030 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2031 GCDashList|GCArcMode) ;
2035 TabsAllocGreyGC(TabsWidget tw)
2037 Widget w = (Widget) tw;
2040 values.background = tw->core.background_pixel ;
2041 values.font = tw->tabs.font->fid ;
2043 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2045 values.fill_style = FillStippled ;
2047 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2050 XtAllocateGC(w, w->core.depth,
2051 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2053 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2054 GCDashList|GCArcMode) ;
2060 XtAllocateGC(w, w->core.depth,
2063 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2064 GCDashList|GCArcMode) ;