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.27.
23 #### This file contains essential XEmacs related fixes to the original
24 verison of the Tabs widget. Be VERY careful about syncing if you ever
25 update to a more recent version. In general this is probably now a
29 * Tabs.c - Index Tabs composite widget
31 * Author: Edward A. Falk
32 * falk@falconer.vip.best.com
37 * Overall layout of this widget is as follows:
39 * ________ ,---------. _________
40 * | label || Label || Label | \ tabs
41 * |________|| ||_________| /
42 * |+----------------------------+| \
44 * || child widget window || > frame
45 * |+----------------------------+| |
46 * +------------------------------+ /
48 * The height of the tabs includes the shadow width, top and bottom
49 * margins, and the height of the text.
51 * The height of the frame includes the top and bottom shadow width and the
52 * size of the child widget window.
54 * The tabs overlap the frame and each other vertically by the shadow
55 * width, so that when the topmost tab is drawn, it obliterates part of
60 * TODO: min child height = tab height
67 #include <X11/IntrinsicP.h>
68 #include <X11/StringDefs.h>
70 #include "lwlib-internal.h"
71 #include "../src/xmu.h"
77 #define INDENT 3 /* tabs indented from edge by this much */
78 #define SPACING 0 /* distance between tabs */
79 #define SHADWID 1 /* default shadow width */
80 #define TABDELTA 2 /* top tab grows this many pixels */
81 #define TABLDELTA 2 /* top tab label offset this many pixels */
84 /****************************************************************
88 ****************************************************************/
90 static char defaultTranslations[] = "\
92 <FocusIn>: highlight() \n\
93 <FocusOut>: unhighlight() \n\
94 <Key>Page_Up: page(up) \n\
95 <Key>KP_Page_Up: page(up) \n\
96 <Key>Prior: page(up) \n\
97 <Key>KP_Prior: page(up) \n\
98 <Key>Page_Down: page(down) \n\
99 <Key>KP_Page_Down: page(down) \n\
100 <Key>Next: page(down) \n\
101 <Key>KP_Next: page(down) \n\
102 <Key>Home: page(home) \n\
103 <Key>KP_Home: page(home) \n\
104 <Key>End: page(end) \n\
105 <Key>KP_End: page(end) \n\
106 <Key>Up: highlight(up) \n\
107 <Key>KP_Up: highlight(up) \n\
108 <Key>Down: highlight(down) \n\
109 <Key>KP_Down: highlight(down) \n\
110 <Key> : page(select) \n\
113 static char accelTable[] = " #augment\n\
114 <Key>Page_Up: page(up) \n\
115 <Key>KP_Page_Up: page(up) \n\
116 <Key>Prior: page(up) \n\
117 <Key>KP_Prior: page(up) \n\
118 <Key>Page_Down: page(down) \n\
119 <Key>KP_Page_Down: page(down) \n\
120 <Key>Next: page(down) \n\
121 <Key>KP_Next: page(down) \n\
122 <Key>Home: page(home) \n\
123 <Key>KP_Home: page(home) \n\
124 <Key>End: page(end) \n\
125 <Key>KP_End: page(end) \n\
126 <Key>Up: highlight(up) \n\
127 <Key>KP_Up: highlight(up) \n\
128 <Key>Down: highlight(down) \n\
129 <Key>KP_Down: highlight(down) \n\
130 <Key> : page(select) \n\
132 static XtAccelerators defaultAccelerators ; /* #### Never used */
134 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
135 static XtResource resources[] = {
137 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
138 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
139 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
140 offset(font), XtRString, (XtPointer) XtDefaultFont},
141 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
142 offset(internalWidth), XtRImmediate, (XtPointer)4 },
143 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
144 offset(internalHeight), XtRImmediate, (XtPointer)4 },
145 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
146 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
147 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
148 offset(topWidget), XtRImmediate, NULL},
149 {XtNhighlightWidget, XtCHighlightWidget, XtRWidget, sizeof(Widget),
150 offset(hilight), XtRImmediate, NULL},
151 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
152 offset(callbacks), XtRCallback, NULL},
153 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
154 offset(popdownCallbacks), XtRCallback, NULL},
155 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
156 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
157 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
158 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
159 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
160 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
161 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
162 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
163 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
164 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
170 /* constraint resources */
172 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
173 static XtResource tabsConstraintResources[] = {
174 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
175 offset(label), XtRString, NULL},
176 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
177 offset(left_bitmap), XtRImmediate, None},
178 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
179 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
180 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
181 offset(resizable), XtRImmediate, (XtPointer) True},
188 #if !NeedFunctionPrototypes
190 /* FORWARD REFERENCES: */
192 /* member functions */
194 static void TabsClassInit();
195 static void TabsInit();
196 static void TabsResize();
197 static void TabsExpose();
198 static void TabsDestroy();
199 static void TabsRealize();
200 static Boolean TabsSetValues();
201 static Boolean TabsAcceptFocus();
202 static XtGeometryResult TabsQueryGeometry();
203 static XtGeometryResult TabsGeometryManager();
204 static void TabsChangeManaged();
205 static void TabsConstraintInitialize() ;
206 static Boolean TabsConstraintSetValues() ;
210 static void TabsSelect() ;
211 static void TabsPage() ;
212 static void TabsHighlight() ;
213 static void TabsUnhighlight() ;
215 /* internal privates */
217 static void TabsAllocGCs() ; /* get rendering GCs */
218 static void TabsFreeGCs() ; /* return rendering GCs */
219 static void DrawTabs() ; /* draw all tabs */
220 static void DrawTab() ; /* draw one index tab */
221 static void DrawFrame() ; /* draw frame around contents */
222 static void DrawTrim() ; /* draw trim around a tab */
223 static void DrawBorder() ; /* draw border */
224 static void DrawHighlight() ; /* draw highlight */
225 static void UndrawTab() ; /* undraw interior of a tab */
226 static void TabWidth() ; /* recompute tab size */
227 static void GetPreferredSizes() ; /* query all children for their sizes */
228 static void MaxChild() ; /* find max preferred child size */
229 static int PreferredSize() ; /* compute preferred size */
230 static int PreferredSize2() ; /* compute preferred size */
231 static int PreferredSize3() ; /* compute preferred size */
232 static void MakeSizeRequest() ; /* try to change size */
233 static void getBitmapInfo() ;
234 static int TabLayout() ; /* lay out tabs */
235 static void TabsShuffleRows() ; /* bring current tab to bottom row */
237 static void TabsAllocFgGC() ;
238 static void TabsAllocGreyGC() ;
242 static void TabsClassInit(void) ;
243 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
244 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
245 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
246 static void TabsDestroy( Widget w) ;
247 static void TabsResize( Widget w) ;
248 static void TabsExpose( Widget w, XEvent *event, Region region) ;
249 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
250 static Boolean TabsAcceptFocus(Widget, Time *);
251 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
252 ArgList, Cardinal *) ;
253 static XtGeometryResult TabsQueryGeometry(Widget,
254 XtWidgetGeometry *, XtWidgetGeometry *) ;
255 static XtGeometryResult TabsGeometryManager(Widget,
256 XtWidgetGeometry *, XtWidgetGeometry *) ;
257 static void TabsChangeManaged( Widget w) ;
259 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
260 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
261 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
262 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
264 static void DrawTabs( TabsWidget tw, Bool labels) ;
265 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
266 static void DrawFrame( TabsWidget tw) ;
267 static void DrawTrim( TabsWidget, int x, int y,
268 int wid, int hgt, Bool bottom, Bool undraw) ;
269 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
270 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
271 static void UndrawTab( TabsWidget tw, Widget child) ;
273 static void TabWidth( Widget w) ;
274 static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt,
276 static void GetPreferredSizes(TabsWidget) ;
277 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
278 static void TabsShuffleRows( TabsWidget tw) ;
279 static int PreferredSize( TabsWidget,
280 Dimension *reply_width, Dimension *reply_height,
281 Dimension *reply_cw, Dimension *reply_ch) ;
282 static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch,
283 Dimension *rw, Dimension *rh) ;
284 static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt,
285 Dimension *rw, Dimension *rh) ;
286 static void MakeSizeRequest(TabsWidget) ;
288 static void TabsAllocGCs(TabsWidget) ;
289 static void TabsFreeGCs(TabsWidget) ;
290 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
291 static void TabsAllocFgGC( TabsWidget tw) ;
292 static void TabsAllocGreyGC( TabsWidget tw) ;
296 #define AddRect(i,xx,yy,w,h) \
297 do{rects[(i)].x=(xx); rects[i].y=(yy); \
298 rects[i].width=(w); rects[i].height=(h);}while(0)
300 static XtActionsRec actionsList[] =
302 {"select", TabsSelect},
304 {"highlight", TabsHighlight},
305 {"unhighlight", TabsUnhighlight},
309 /****************************************************************
311 * Full class record constant
313 ****************************************************************/
316 #define SuperClass (&constraintClassRec)
318 #define SuperClass (&xmManagerClassRec)
321 TabsClassRec tabsClassRec = {
323 /* core_class fields */
324 /* superclass */ (WidgetClass) SuperClass,
325 /* class_name */ "Tabs",
326 /* widget_size */ sizeof(TabsRec),
327 /* class_initialize */ TabsClassInit,
328 /* class_part_init */ NULL, /* TODO? */
329 /* class_inited */ FALSE,
330 /* initialize */ TabsInit,
331 /* initialize_hook */ NULL,
332 /* realize */ TabsRealize,
333 /* actions */ actionsList,
334 /* num_actions */ XtNumber(actionsList),
335 /* resources */ resources,
336 /* num_resources */ XtNumber(resources),
337 /* xrm_class */ NULLQUARK,
338 /* compress_motion */ TRUE,
339 #if XtSpecificationRelease < 6
340 /* compress_exposure */ XtExposeCompressMaximal,
342 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
344 /* compress_enterleave*/ TRUE,
345 /* visible_interest */ TRUE,
346 /* destroy */ TabsDestroy,
347 /* resize */ TabsResize,
348 /* expose */ TabsExpose,
349 /* set_values */ TabsSetValues,
350 /* set_values_hook */ NULL,
351 /* set_values_almost */ XtInheritSetValuesAlmost,
352 /* get_values_hook */ NULL,
353 /* accept_focus */ TabsAcceptFocus,
354 /* version */ XtVersion,
355 /* callback_private */ NULL,
356 /* tm_table */ defaultTranslations,
357 /* query_geometry */ TabsQueryGeometry,
358 /* display_accelerator*/ XtInheritDisplayAccelerator,
362 /* composite_class fields */
363 /* geometry_manager */ TabsGeometryManager,
364 /* change_managed */ TabsChangeManaged,
365 /* insert_child */ XtInheritInsertChild, /* TODO? */
366 /* delete_child */ XtInheritDeleteChild, /* TODO? */
370 /* constraint_class fields */
371 /* subresources */ tabsConstraintResources,
372 /* subresource_count */ XtNumber(tabsConstraintResources),
373 /* constraint_size */ sizeof(TabsConstraintsRec),
374 /* initialize */ TabsConstraintInitialize,
376 /* set_values */ TabsConstraintSetValues,
377 /* extension */ NULL,
380 /* Manager Class fields */
382 /* translations */ NULL,
383 /* syn_resources */ NULL,
384 /* num_syn_resources */ 0,
385 /* syn_constraint_resources */ NULL,
386 /* num_syn_constraint_resources */ 0,
387 /* parent_process */ XmInheritParentProcess,
392 /* Tabs class fields */
393 /* extension */ NULL,
397 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
399 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
400 #define TabVisible(tab) \
401 (XtIsManaged(tab) && \
402 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
405 /****************************************************************
409 ****************************************************************/
414 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
415 /* TODO: register converter for labels? */
420 /* Init a newly created tabs widget. Compute height of tabs
421 * and optionally compute size of widget. */
426 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
428 TabsWidget newTw = (TabsWidget)new;
430 newTw->tabs.numRows = 0 ;
431 newTw->tabs.realRows = 0;
433 GetPreferredSizes(newTw) ;
435 /* height is easy, it's the same for all tabs:
436 * TODO: font height + height of tallest bitmap.
438 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
440 if( newTw->tabs.font != NULL )
441 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
442 newTw->tabs.font->max_bounds.descent ;
444 /* GC allocation is deferred until XtRealize() */
446 /* if size not explicitly set, set it to our preferred size now. */
448 if( request->core.width == 0 || request->core.height == 0 )
451 PreferredSize(newTw, &w, &h, NULL,NULL) ;
452 if( request->core.width == 0 ) new->core.width = w ;
453 if( request->core.height == 0 ) new->core.height = h ;
454 XtClass(new)->core_class.resize(new) ;
457 /* defer GC allocation, etc., until Realize() time. */
458 newTw->tabs.foregroundGC =
459 newTw->tabs.backgroundGC =
462 newTw->tabs.botGC = None ;
464 newTw->tabs.grey50 = None ;
466 newTw->tabs.needs_layout = False ;
468 newTw->tabs.hilight = NULL ;
471 newTw->manager.navigation_type = XmTAB_GROUP ;
472 newTw->manager.traversal_on = True ;
477 /* Init the constraint part of a new tab child. Compute the
482 TabsConstraintInitialize(Widget request, Widget new,
483 ArgList args, Cardinal *num_args)
485 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
486 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
487 tab->tabs.visible = False ;
489 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
495 /* Called when tabs widget first realized. Create the window
496 * and allocate the GCs
500 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
502 TabsWidget tw = (TabsWidget) w;
504 attributes->bit_gravity = NorthWestGravity;
505 *valueMask |= CWBitGravity;
507 SuperClass->core_class.realize(w, valueMask, attributes);
515 TabsDestroy(Widget w)
517 TabsFreeGCs((TabsWidget)w) ;
521 /* Parent has resized us. This will require that the tabs be
528 TabsWidget tw = (TabsWidget) w;
530 int num_children = tw->composite.num_children ;
532 TabsConstraints tab ; /* #### unused */
535 /* Our size has now been dictated by the parent. Lay out the
536 * tabs, lay out the frame, lay out the children. Remember
537 * that the tabs overlap each other and the frame by shadowWidth.
538 * Also, the top tab is larger than the others, so if there's only
539 * one row, the widget must be made taller to accommodate this.
541 * Once the tabs are laid out, if there is more than one
542 * row, we may need to shuffle the rows to bring the top tab
546 tw->tabs.needs_layout = False ;
548 if( num_children > 0 && tw->composite.children != NULL )
550 /* Loop through the tabs and assign rows & x positions */
551 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
552 num_children = TabsNumChildren (tw);
554 /* assign a top widget, bring it to bottom row. */
555 TabsShuffleRows(tw) ;
557 /* now assign child positions & sizes. Positions are all the
558 * same: just inside the frame. Sizes are also all the same.
561 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
562 tw->tabs.child_height = ch =
563 tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 :
564 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
566 for(i=0, childP=tw->composite.children;
569 if( XtIsManaged(*childP) )
571 tab = (TabsConstraints) (*childP)->core.constraints ;
572 bw = (*childP)->core.border_width ;
573 /* Don't do anything if we can't see any of the child. */
574 if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0)
575 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
576 cw-bw*2,ch-bw*2, bw) ;
578 if( XtIsRealized(w) ) {
579 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
580 /* should not be necessary to explicitly repaint after a
581 * resize, but XEmacs folks tell me it is.
583 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
590 /* Redraw entire Tabs widget */
594 TabsExpose(Widget w, XEvent *event, Region region)
596 TabsWidget tw = (TabsWidget) w;
598 if( tw->tabs.needs_layout )
599 XtClass(w)->core_class.resize(w) ;
605 /* Called when any Tabs widget resources are changed. */
609 TabsSetValues(Widget current, Widget request, Widget new,
610 ArgList args, Cardinal *num_args)
612 TabsWidget curtw = (TabsWidget) current ;
613 TabsWidget tw = (TabsWidget) new ;
614 Boolean needRedraw = False ;
619 if( tw->tabs.font != curtw->tabs.font ||
620 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
621 tw->tabs.internalHeight != curtw->tabs.internalHeight )
623 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
625 if( tw->tabs.font != NULL )
626 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
627 tw->tabs.font->max_bounds.descent ;
629 /* Tab size has changed. Resize all tabs and request a new size */
630 for(i=0, childP=tw->composite.children;
631 i < tw->composite.num_children;
633 if( XtIsManaged(*childP) )
635 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
637 tw->tabs.needs_layout = True ;
640 /* TODO: if any color changes, need to recompute GCs and redraw */
642 if( tw->core.background_pixel != curtw->core.background_pixel ||
643 tw->core.background_pixmap != curtw->core.background_pixmap ||
644 tw->tabs.font != curtw->tabs.font )
645 if( XtIsRealized(new) )
652 if( tw->core.sensitive != curtw->core.sensitive )
655 /* Highlit widget changed */
656 if ( tw->tabs.hilight != curtw->tabs.hilight )
661 /* If top widget changes, need to change stacking order, redraw tabs.
662 * Window system will handle the redraws.
665 if( tw->tabs.topWidget != curtw->tabs.topWidget )
667 if( XtIsRealized(tw->tabs.topWidget) )
669 Widget w = tw->tabs.topWidget ;
670 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
672 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
674 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
675 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
678 if( tab->tabs.row != tw->tabs.numRows-1 )
679 TabsShuffleRows(tw) ;
685 tw->tabs.needs_layout = True ;
692 /* Called when any child constraint resources change. */
696 TabsConstraintSetValues(Widget current, Widget request, Widget new,
697 ArgList args, Cardinal *num_args)
699 TabsWidget tw = (TabsWidget) XtParent(new) ;
700 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
701 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
704 /* if label changes, need to re-layout the entire widget */
705 /* if foreground changes, need to redraw tab label */
707 /* TODO: only need resize of new bitmap has different dimensions
711 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
712 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
715 tw->tabs.needs_layout = True ;
717 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
718 getBitmapInfo(tw, tab) ;
720 /* If there are no subclass ConstraintSetValues procedures remaining
721 * to be invoked, and if the preferred size has changed, ask
724 if( XtClass((Widget)tw) == tabsWidgetClass )
725 MakeSizeRequest(tw) ;
729 /* The child widget itself never needs a redisplay, but the parent
733 if( XtIsRealized(new) )
735 if( tw->tabs.needs_layout ) {
736 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
737 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
740 else if( tab->tabs.foreground != ctab->tabs.foreground )
741 DrawTab(tw, new, True) ;
749 TabsAcceptFocus(Widget w, Time *t)
751 if( !w->core.being_destroyed && XtIsRealized(w) &&
752 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
755 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
756 XtSetKeyboardFocus(p,w) ;
766 * Return preferred size. Happily accept anything >= our preferred size.
767 * (TODO: is that the right thing to do? Should we always return "almost"
768 * if offered more than we need?)
771 static XtGeometryResult
772 TabsQueryGeometry(Widget w,
773 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
775 register TabsWidget tw = (TabsWidget)w ;
776 XtGeometryMask mode = intended->request_mode ;
778 preferred->request_mode = CWWidth | CWHeight ;
779 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
781 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
782 (!(mode & CWHeight) || intended->height == w->core.height) )
783 return XtGeometryNo ;
785 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
786 (!(mode & CWHeight) || intended->height >= preferred->height) )
787 return XtGeometryYes;
789 return XtGeometryAlmost;
795 * Geometry Manager; called when a child wants to be resized.
798 static XtGeometryResult
799 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
801 TabsWidget tw = (TabsWidget) XtParent(w);
802 Dimension s = SHADWID ;
803 TabsConstraints tab = (TabsConstraints)w->core.constraints;
804 XtGeometryResult result ;
807 /* Position request always denied */
809 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
810 ((req->request_mode & CWY) && req->y != w->core.y) ||
811 !tab->tabs.resizable )
812 return XtGeometryNo ;
814 /* Make all three fields in the request valid */
815 if( !(req->request_mode & CWWidth) )
816 req->width = w->core.width;
817 if( !(req->request_mode & CWHeight) )
818 req->height = w->core.height;
819 if( !(req->request_mode & CWBorderWidth) )
820 req->border_width = w->core.border_width;
822 if( req->width == w->core.width &&
823 req->height == w->core.height &&
824 req->border_width == w->core.border_width )
825 return XtGeometryNo ;
827 rw = req->width + 2 * req->border_width ;
828 rh = req->height + 2 * req->border_width ;
830 /* find out how big the children want to be now */
831 MaxChild(tw, w, rw, rh) ;
834 /* Size changes must see if the new size can be accommodated.
835 * The Tabs widget keeps all of its children the same
836 * size. A request to shrink will be accepted only if the
837 * new size is still big enough for all other children. A
838 * request to shrink that is not big enough for all children
839 * returns an "almost" response with the new proposed size
840 * or a "no" response if unable to shrink at all.
842 * A request to grow will be accepted only if the Tabs parent can
843 * grow to accommodate.
846 * We could get fancy here and re-arrange the tabs if it is
847 * necessary to compromise with the parent, but we'll save that
851 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
853 Dimension cw,ch ; /* children's preferred size */
854 Dimension aw,ah ; /* available size we can give child */
855 Dimension th ; /* space used by tabs */
856 Dimension wid,hgt ; /* Tabs widget size */
858 cw = tw->tabs.max_cw ;
859 ch = tw->tabs.max_ch ;
861 /* find out what *my* resulting preferred size would be */
863 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
865 /* Would my size change? If so, ask to be resized. */
867 if( wid != tw->core.width || hgt != tw->core.height )
869 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
870 XtWidgetGeometry myrequest, myreply ;
872 myrequest.width = wid ;
873 myrequest.height = hgt ;
874 myrequest.request_mode = CWWidth | CWHeight ;
876 assert (wid > 0 && hgt > 0);
877 /* If child is only querying, or if we're going to have to
878 * offer the child a compromise, then make this a query only.
881 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
882 myrequest.request_mode |= XtCWQueryOnly ;
884 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
886 /* !$@# Athena Box widget changes the core size even if QueryOnly
887 * is set. I'm convinced this is a bug. At any rate, to work
888 * around the bug, we need to restore the core size after every
889 * query geometry request. This is only partly effective,
890 * as there may be other boxes further up the tree.
892 if( myrequest.request_mode & XtCWQueryOnly ) {
893 tw->core.width = oldWid ;
894 tw->core.height = oldHgt ;
897 /* based on the parent's response, determine what the
898 * resulting Tabs widget size would be.
904 tw->tabs.needs_layout = True ;
908 wid = tw->core.width ;
909 hgt = tw->core.height ;
912 case XtGeometryAlmost:
913 wid = myreply.width ;
914 hgt = myreply.height ;
915 tw->tabs.needs_layout = True ;
920 /* Within the constraints imposed by the parent, what is
921 * the max size we can give the child?
923 (void) TabLayout(tw, wid, hgt, &th, True) ;
925 ah = hgt - th - 2*s ;
927 /* OK, make our decision. If requested size is >= max sibling
928 * preferred size, AND requested size <= available size, then
929 * we accept. Otherwise, we offer a compromise.
932 if( rw == aw && rh == ah )
934 /* Acceptable. If this wasn't a query, change *all* children
937 if( req->request_mode & XtCWQueryOnly )
938 return XtGeometryYes ;
941 Widget *childP = tw->composite.children ;
943 w->core.border_width = req->border_width ;
944 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
945 if( TabVisible(*childP) )
947 bw = (*childP)->core.border_width ;
948 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
949 rw-2*bw, rh-2*bw, bw) ;
952 /* TODO: under what conditions will we need to redraw? */
953 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
954 XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
956 return XtGeometryDone ;
960 /* Cannot grant child's request. Describe what we *can* do
961 * and return counter-offer.
963 reply->width = aw - 2 * req->border_width ;
964 reply->height = ah - 2 * req->border_width ;
965 reply->border_width = req->border_width ;
966 reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
967 return XtGeometryAlmost ;
970 return XtGeometryYes ;
976 /* The number of children we manage has changed; recompute
981 TabsChangeManaged(Widget w)
983 TabsWidget tw = (TabsWidget)w ;
984 Widget *childP = tw->composite.children ;
987 if( tw->tabs.topWidget != NULL &&
988 ( !XtIsManaged(tw->tabs.topWidget) ||
989 tw->tabs.topWidget->core.being_destroyed ) )
990 tw->tabs.topWidget = NULL ;
992 /* Check whether the highlight tab is still valid. */
993 if( tw->tabs.hilight != NULL &&
994 ( !XtIsManaged(tw->tabs.hilight) ||
995 tw->tabs.hilight->core.being_destroyed ) )
996 tw->tabs.hilight = NULL ;
998 GetPreferredSizes(tw) ;
999 MakeSizeRequest(tw) ;
1001 XtClass(w)->core_class.resize(w) ;
1002 if( XtIsRealized(w) )
1004 Display *dpy = XtDisplay(w) ;
1005 XClearWindow(dpy, XtWindow(w)) ;
1006 XtClass(w)->core_class.expose(w,NULL,NULL) ;
1008 /* make sure the top widget stays on top. This requires
1009 * making sure that all new children are realized first.
1011 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
1013 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
1014 if( !XtIsRealized(*childP) )
1015 XtRealizeWidget(*childP) ;
1017 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
1022 /* Only top widget may receive input */
1024 for(childP = tw->composite.children, i=tw->composite.num_children;
1028 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
1031 if( tw->tabs.topWidget != NULL )
1032 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
1039 /****************************************************************
1043 ****************************************************************/
1046 /* User clicks on a tab, figure out which one it was. */
1050 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
1052 TabsWidget tw = (TabsWidget) w ;
1055 Dimension h = tw->tabs.tab_height ;
1059 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
1062 /* TODO: is there an Xmu function or something to do this instead? */
1063 switch( event->type ) {
1066 x = event->xbutton.x ; y = event->xbutton.y ; break ;
1069 x = event->xkey.x ; y = event->xkey.y ; break ;
1074 /* TODO: determine which tab was clicked, if any. Set that
1075 * widget to be top of stacking order with XawTabsSetTop().
1077 for(i=0, childP=tw->composite.children;
1078 i < TabsNumChildren (tw);
1080 if( TabVisible(*childP) )
1082 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
1083 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
1084 y > tab->tabs.y && y < tab->tabs.y + h )
1086 if( *childP != tw->tabs.topWidget &&
1087 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
1088 XawTabsSetTop(*childP, True) ;
1095 /* User hits a key */
1098 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
1100 TabsWidget tw = (TabsWidget) w ;
1101 Widget newtop = NULL;
1104 int nc = TabsNumChildren (tw) ;
1109 if( *num_params < 1 ) {
1110 XtAppWarning(XtWidgetToApplicationContext(w),
1111 "Tabs: page() action called with no arguments") ;
1115 if( tw->tabs.topWidget == NULL )
1116 tw->tabs.topWidget = tw->composite.children[0] ;
1118 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1119 if( tw->tabs.topWidget == *childP )
1122 switch( params[0][0] ) {
1127 newtop = tw->composite.children[idx] ;
1130 case 'd': /* down */
1134 newtop = tw->composite.children[idx] ;
1140 newtop = tw->composite.children[0] ;
1145 newtop = tw->composite.children[nc-1] ;
1148 case 's': /* selected */
1150 if( (newtop = tw->tabs.hilight) == NULL )
1155 XawTabsSetTop(newtop, True) ;
1159 /* User hits up/down key */
1162 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1164 TabsWidget tw = (TabsWidget) w ;
1165 Widget newhl = NULL;
1168 int nc = TabsNumChildren (tw) ;
1173 if( *num_params < 1 )
1175 if( tw->tabs.hilight != NULL )
1176 DrawHighlight(tw, tw->tabs.hilight, False) ;
1180 if( tw->tabs.hilight == NULL )
1181 newhl = tw->composite.children[0] ;
1185 /* find index of currently highlit child */
1186 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1187 if( tw->tabs.hilight == *childP )
1190 switch( params[0][0] ) {
1195 newhl = tw->composite.children[idx] ;
1198 case 'd': /* down */
1202 newhl = tw->composite.children[idx] ;
1207 newhl = tw->composite.children[0] ;
1212 newhl = tw->composite.children[nc-1] ;
1216 newhl = tw->tabs.hilight ;
1221 XawTabsSetHighlight(w, newhl) ;
1227 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1229 TabsWidget tw = (TabsWidget) w ;
1230 int nc = tw->composite.num_children ;
1235 if( tw->tabs.hilight != NULL )
1236 DrawHighlight(tw, tw->tabs.hilight, True) ;
1243 /****************************************************************
1247 ****************************************************************/
1250 /* Set the top tab, optionally call all callbacks. */
1252 XawTabsSetTop(Widget w, Bool callCallbacks)
1254 TabsWidget tw = (TabsWidget)w->core.parent ;
1255 TabsConstraints tab ;
1256 Widget oldtop = tw->tabs.topWidget ;
1258 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
1261 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
1262 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
1267 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
1268 (XtPointer)tw->tabs.topWidget) ;
1270 if( !XtIsRealized(w) ) {
1271 tw->tabs.topWidget = w ;
1272 tw->tabs.needs_layout = True ;
1273 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
1277 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
1279 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
1280 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
1283 tab = (TabsConstraints) w->core.constraints ;
1285 /* Unhighlight before we start messing with the stacking order. */
1286 if( tw->tabs.hilight != NULL )
1288 DrawHighlight(tw, tw->tabs.hilight, True) ;
1289 tw->tabs.hilight = NULL;
1292 if( tab->tabs.row == 0 )
1294 /* Easy case; undraw current top, undraw new top, assign new
1295 * top, redraw all borders.
1296 * We *could* just erase and execute a full redraw, but I like to
1297 * reduce screen flicker.
1299 UndrawTab(tw, oldtop) ; /* undraw old */
1300 DrawBorder(tw, oldtop, True) ;
1301 UndrawTab(tw, w) ; /* undraw new */
1302 DrawBorder(tw, w, True) ;
1303 tw->tabs.topWidget = w ;
1304 DrawTab(tw, oldtop, True) ; /* redraw old */
1305 DrawTab(tw, w, True) ; /* redraw new */
1306 DrawTabs(tw, False) ;
1310 tw->tabs.topWidget = w ;
1311 TabsShuffleRows(tw) ;
1312 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
1313 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
1316 XawTabsSetHighlight((Widget)tw, w) ;
1319 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
1323 /* Set the top tab, optionally call all callbacks. */
1325 XawTabsSetHighlight(Widget t, Widget w)
1327 TabsWidget tw = (TabsWidget)t ;
1329 if( !XtIsSubclass(t, tabsWidgetClass) )
1332 if( XtIsRealized(t) && w != tw->tabs.hilight )
1335 DrawHighlight(tw, w, False) ;
1338 tw->tabs.hilight = w ;
1344 /****************************************************************
1346 * Private Procedures
1348 ****************************************************************/
1352 TabsAllocGCs(TabsWidget tw)
1355 TabsAllocGreyGC(tw) ;
1356 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
1357 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
1358 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1359 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
1360 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1365 TabsFreeGCs(TabsWidget tw)
1367 Widget w = (Widget) tw;
1369 XtReleaseGC(w, tw->tabs.foregroundGC) ;
1370 XtReleaseGC(w, tw->tabs.greyGC) ;
1371 XtReleaseGC(w, tw->tabs.backgroundGC) ;
1372 XtReleaseGC(w, tw->tabs.topGC) ;
1373 XtReleaseGC(w, tw->tabs.botGC) ;
1375 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
1383 /* Redraw entire Tabs widget */
1386 DrawTabs(TabsWidget tw, Bool labels)
1390 Dimension s = SHADWID ;
1391 Dimension th = tw->tabs.tab_height ;
1393 TabsConstraints tab ;
1395 if( !XtIsRealized((Widget)tw))
1398 /* draw tabs and frames by row except for the top tab, which
1399 * is drawn last. (This is inefficiently written, but should not
1400 * be too slow as long as there are not a lot of rows.)
1403 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
1404 for(i=0; i<tw->tabs.numRows; ++i, y += th)
1406 for( j=TabsNumChildren (tw), childP=tw->composite.children;
1407 --j >= 0; ++childP )
1408 if( TabVisible(*childP) )
1410 tab = (TabsConstraints)(*childP)->core.constraints;
1411 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
1412 DrawTab(tw, *childP, labels) ;
1414 if( i != tw->tabs.numRows -1 )
1415 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
1420 /* and now the top tab */
1421 if( tw->tabs.topWidget != NULL )
1422 DrawTab(tw, tw->tabs.topWidget, labels) ;
1427 /* Draw one tab. Corners are rounded very slightly. */
1430 DrawTab(TabsWidget tw, Widget child, Bool labels)
1435 if( !XtIsRealized((Widget)tw))
1438 DrawBorder(tw, child, False) ;
1442 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1443 Display *dpy = XtDisplay((Widget)tw) ;
1444 Window win = XtWindow((Widget)tw) ;
1445 String lbl = tab->tabs.label != NULL ?
1446 tab->tabs.label : XtName(child) ;
1448 if( XtIsSensitive(child) )
1450 gc = tw->tabs.foregroundGC ;
1451 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1455 /* grey pixel allocation deferred until now */
1456 if( !tab->tabs.greyAlloc )
1458 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
1459 tab->tabs.grey = tab->tabs.foreground ;
1461 tab->tabs.grey = AllocGreyPixel((Widget)tw,
1462 tab->tabs.foreground,
1463 tw->core.background_pixel,
1464 tw->tabs.insensitive_contrast ) ;
1465 tab->tabs.greyAlloc = True ;
1467 gc = tw->tabs.greyGC ;
1468 XSetForeground(dpy, gc, tab->tabs.grey) ;
1473 if( child == tw->tabs.topWidget )
1476 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
1478 if( tab->tabs.lbm_depth == 1 )
1479 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
1480 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1481 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
1483 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
1484 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1485 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
1488 if( lbl != NULL && tw->tabs.font != NULL )
1489 XDrawString(dpy,win,gc,
1490 x+tab->tabs.l_x, y+tab->tabs.l_y,
1491 lbl, (int)strlen(lbl)) ;
1494 if( child == tw->tabs.hilight )
1495 DrawHighlight(tw, child, False) ;
1499 /* draw frame all the way around the child windows. */
1502 DrawFrame(TabsWidget tw)
1504 GC topgc = tw->tabs.topGC ;
1505 GC botgc = tw->tabs.botGC ;
1506 Dimension s = SHADWID ;
1507 Dimension ch = tw->tabs.child_height ;
1509 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1510 tw->core.width, ch+2*s, s, topgc, botgc) ;
1513 Widget w = tw->tabs.topWidget ;
1516 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1517 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
1518 tab->tabs.x, 2*s, s, topgc, botgc);
1519 Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width,
1520 tw->core.height - 2*s,
1521 tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s,
1525 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
1526 tw->core.width, 2*s, s, topgc, botgc) ;
1531 /* draw trim around a tab or underneath a row of tabs */
1534 DrawTrim(TabsWidget tw, /* widget */
1535 int x, /* upper-left corner */
1537 int wid, /* total size */
1539 Bool bottom, /* draw bottom? */
1540 Bool undraw) /* undraw all */
1542 Display *dpy = XtDisplay((Widget)tw) ;
1543 Window win = XtWindow((Widget)tw) ;
1544 GC bggc = tw->tabs.backgroundGC ;
1545 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1546 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1548 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1549 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1550 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1551 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1552 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1553 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1557 /* Draw one tab border. */
1560 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1562 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1563 Position x = tab->tabs.x ;
1564 Position y = tab->tabs.y ;
1565 Dimension twid = tab->tabs.width ;
1566 Dimension thgt = tw->tabs.tab_height ;
1568 /* top tab requires a little special attention; it overlaps
1569 * neighboring tabs slightly, so the background must be cleared
1570 * in the region of the overlap to partially erase those neighbors.
1571 * TODO: is this worth doing with regions instead?
1573 if( child == tw->tabs.topWidget )
1575 Display *dpy = XtDisplay((Widget)tw) ;
1576 Window win = XtWindow((Widget)tw) ;
1577 GC bggc = tw->tabs.backgroundGC ;
1578 XRectangle rects[3] ;
1581 twid += TABDELTA*2 ;
1583 AddRect(0, x,y+1,twid,TABDELTA) ;
1584 AddRect(1, x+1,y,TABDELTA,thgt) ;
1585 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1586 XFillRectangles(dpy,win,bggc, rects, 3) ;
1589 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1593 /* Draw highlight around tab that has focus */
1596 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1598 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1599 Display *dpy = XtDisplay((Widget)tw) ;
1600 Window win = XtWindow((Widget)tw) ;
1602 Position x = tab->tabs.x ;
1603 Position y = tab->tabs.y ;
1604 Dimension wid = tab->tabs.width ;
1605 Dimension hgt = tw->tabs.tab_height ;
1608 /* top tab does not have a highlight */
1610 if( child == tw->tabs.topWidget )
1614 gc = tw->tabs.backgroundGC ;
1616 else if( XtIsSensitive(child) )
1618 gc = tw->tabs.foregroundGC ;
1619 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1623 gc = tw->tabs.greyGC ;
1624 XSetForeground(dpy, gc, tab->tabs.grey) ;
1627 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1628 points[1].x = x+1 ; points[1].y = y+2 ;
1629 points[2].x = x+2 ; points[2].y = y+1 ;
1630 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1631 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1632 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1634 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1638 /* Undraw one tab interior */
1641 UndrawTab(TabsWidget tw, Widget child)
1643 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1644 Position x = tab->tabs.x ;
1645 Position y = tab->tabs.y ;
1646 Dimension twid = tab->tabs.width ;
1647 Dimension thgt = tw->tabs.tab_height ;
1648 Display *dpy = XtDisplay((Widget)tw) ;
1649 Window win = XtWindow((Widget)tw) ;
1650 GC bggc = tw->tabs.backgroundGC ;
1652 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1659 /* GEOMETRY UTILITIES */
1663 * MaxChild(): ask all children (except possibly one) their
1664 * preferred sizes, set max_cw, max_ch accordingly.
1666 * GetPreferredSizes(): ask all children their preferred sizes,
1667 * set max_cw, max_ch accordingly.
1669 * PreferredSize(): given max_cw, max_ch, return tabs widget
1670 * preferred size. Iterate with other widths in order to get
1671 * a reasonable aspect ratio.
1673 * PreferredSize2(): Given child dimensions, return Tabs
1674 * widget dimensions.
1676 * PreferredSize3(): Same, except given child dimensions plus
1681 /* Compute the width of one child's tab. Positions will be computed
1684 * height: font height + vertical_space*2 + shadowWid*2
1685 * width: string width + horizontal_space*2 + shadowWid*2
1687 * All tabs are the same height, so that is computed elsewhere.
1693 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1694 TabsWidget tw = (TabsWidget)XtParent(w) ;
1695 String lbl = tab->tabs.label != NULL ?
1696 tab->tabs.label : XtName(w) ;
1697 XFontStruct *font = tw->tabs.font ;
1698 int iw = tw->tabs.internalWidth ;
1700 tab->tabs.width = iw + SHADWID*2 ;
1701 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1703 if( tab->tabs.left_bitmap != None )
1705 tab->tabs.width += tab->tabs.lbm_width + iw ;
1706 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1707 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1710 if( lbl != NULL && font != NULL )
1712 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1713 tab->tabs.l_y = (tw->tabs.tab_height +
1714 tw->tabs.font->max_bounds.ascent -
1715 tw->tabs.font->max_bounds.descent)/2 ;
1721 /* Lay out tabs to fit in given width. Compute x,y position and
1722 * row number for each tab. Return number of rows and total height
1723 * required by all tabs. If there is only one row, add TABDELTA
1724 * height to the total. Rows are assigned bottom to top.
1726 * Tabs are indented from the edges by INDENT.
1728 * TODO: if they require more than two rows and the total height:width
1729 * ratio is more than 2:1, then try something else.
1733 TabLayout(TabsWidget tw,
1736 Dimension *reply_height, Bool query_only)
1738 int i, row, done = 0, display_rows = 0 ;
1739 int num_children = tw->composite.num_children ;
1743 TabsConstraints tab ;
1745 /* Algorithm: loop through children, assign X positions. If a tab
1746 * would extend beyond the right edge, start a new row. After all
1747 * rows are assigned, make a second pass and assign Y positions.
1750 if( num_children > 0 )
1752 /* Loop through the tabs and see how much space they need. */
1758 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1759 if( XtIsManaged(*childP) )
1761 tab = (TabsConstraints) (*childP)->core.constraints ;
1762 w = tab->tabs.width ;
1764 if( x + w > wid ) { /* new row */
1765 if (y + tw->tabs.tab_height > hgt && !done)
1772 y += tw->tabs.tab_height ;
1777 tab->tabs.row = row ;
1780 if (!query_only && !done)
1781 tab->tabs.visible = 1;
1784 /* If there was only one row, increase the height by TABDELTA */
1785 if( ++display_rows == 1 )
1790 for(i=num_children, childP=tw->composite.children;
1791 --i >= 0 ; ++childP)
1792 if( XtIsManaged(*childP) )
1794 tab = (TabsConstraints) (*childP)->core.constraints ;
1798 y += tw->tabs.tab_height ;
1801 display_rows = row = y = 0 ;
1804 tw->tabs.tab_total = y ;
1805 tw->tabs.numRows = display_rows ;
1806 tw->tabs.realRows = row;
1809 if( reply_height != NULL )
1812 return display_rows ;
1817 /* Find max preferred child size. Returned sizes include child
1822 GetPreferredSizes(TabsWidget tw)
1824 MaxChild(tw, NULL, 0,0) ;
1829 /* Find max preferred child size. Returned sizes include child
1830 * border widths. If except is non-null, don't ask that one.
1834 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
1837 Widget *childP = tw->composite.children ;
1838 XtWidgetGeometry preferred ;
1840 for(i=tw->composite.num_children; --i >=0; ++childP)
1841 if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except )
1843 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1844 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
1845 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
1848 tw->tabs.max_cw = cw ;
1849 tw->tabs.max_ch = ch ;
1854 /* rotate row numbers to bring current widget to bottom row,
1855 * compute y positions for all tabs
1859 TabsShuffleRows(TabsWidget tw)
1861 TabsConstraints tab ;
1863 int real_rows, display_rows ;
1865 Dimension th = tw->tabs.tab_height ;
1869 /* There must be a top widget. If not, assign one. */
1870 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1871 for(i=TabsNumChildren (tw), childP=tw->composite.children;
1874 if( XtIsManaged(*childP) ) {
1875 tw->tabs.topWidget = *childP ;
1879 if( tw->tabs.topWidget != NULL )
1881 display_rows = tw->tabs.numRows ;
1882 real_rows = tw->tabs.realRows ;
1883 assert( display_rows <= real_rows ) ;
1887 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1888 assert( tab != NULL ) ;
1890 /* How far to move top row. The selected tab must be on
1891 the bottom row of the *visible* rows. */
1892 move = (real_rows + 1 - display_rows) - tab->tabs.row ;
1894 move = real_rows - move;
1895 bottom = tw->tabs.tab_total - th ;
1897 for(i=tw->composite.num_children, childP=tw->composite.children;
1900 if( XtIsManaged(*childP) )
1902 tab = (TabsConstraints) (*childP)->core.constraints ;
1903 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
1904 tab->tabs.y = bottom - tab->tabs.row * th ;
1905 tab->tabs.visible = (tab->tabs.row < display_rows);
1912 /* Find preferred size. Ask children, find size of largest,
1913 * add room for tabs & return. This can get a little involved,
1914 * as we don't want to have too many rows of tabs; we may widen
1915 * the widget to reduce # of rows.
1917 * This function requires that max_cw, max_ch already be set.
1922 Dimension *reply_width, /* total widget size */
1923 Dimension *reply_height,
1924 Dimension *reply_cw, /* child widget size */
1925 Dimension *reply_ch)
1927 Dimension cw,ch ; /* child width, height */
1929 Dimension rwid,rhgt ;
1932 wid = cw = tw->tabs.max_cw ;
1933 hgt = ch = tw->tabs.max_ch ;
1935 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1937 /* Check for absurd results (more than 2 rows, high aspect
1938 * ratio). Try wider size if needed.
1939 * TODO: make sure this terminates.
1942 if( nrow > 2 && rhgt > rwid )
1947 /* step 1: start doubling size until it's too big */
1950 wid = Max(wid*2, wid+20) ;
1951 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1952 } while( nrow > 2 && rhgt > rwid ) ;
1955 /* step 2: use Newton's method to find ideal size. Stop within
1958 while( --maxloop > 0 && w1 > w0 + 8 )
1961 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1962 if( nrow > 2 && rhgt > rwid )
1970 *reply_width = rwid ;
1971 *reply_height = rhgt ;
1972 if( reply_cw != NULL ) *reply_cw = cw ;
1973 if( reply_ch != NULL ) *reply_ch = ch ;
1978 /* Find preferred size, given size of children. */
1983 Dimension cw, /* child width, height */
1985 Dimension *reply_width, /* total widget size */
1986 Dimension *reply_height)
1988 Dimension s = SHADWID ;
1991 /* make room for shadow frame */
1995 ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1997 assert (*reply_width > 0 && *reply_height > 0);
2002 /* Find preferred size, given size of children+shadow. */
2007 Dimension wid, /* child width, height */
2009 Dimension *reply_width, /* total widget size */
2010 Dimension *reply_height)
2012 Dimension th ; /* space used by tabs */
2015 if( tw->composite.num_children > 0 )
2016 nrows = TabLayout(tw, wid, hgt, &th, True) ;
2022 *reply_width = Max(wid, MIN_WID) ;
2023 *reply_height = Max(th+hgt, MIN_HGT) ;
2030 MakeSizeRequest(TabsWidget tw)
2032 Widget w = (Widget)tw ;
2033 XtWidgetGeometry request, reply ;
2034 XtGeometryResult result ;
2037 request.request_mode = CWWidth | CWHeight ;
2038 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
2040 if( request.width == tw->core.width &&
2041 request.height == tw->core.height )
2044 result = XtMakeGeometryRequest(w, &request, &reply) ;
2046 if( result == XtGeometryAlmost )
2048 /* Bugger. Didn't get what we want, but were offered a
2049 * compromise. If the width was too small, recompute
2050 * based on the too-small width and try again.
2051 * If the height was too small, make a wild-ass guess
2052 * at a wider width and try again.
2055 if( reply.width < request.width && reply.height >= request.height )
2057 Dimension s = SHADWID ;
2059 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
2060 result = XtMakeGeometryRequest(w, &request, &reply) ;
2061 if( result == XtGeometryAlmost )
2062 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2066 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2072 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2078 if( tab->tabs.left_bitmap == None ||
2079 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2080 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2081 &bw, &tab->tabs.lbm_depth) )
2082 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2088 /* Code copied & modified from Gcs.c. This version has dynamic
2093 TabsAllocFgGC(TabsWidget tw)
2095 Widget w = (Widget) tw;
2098 values.background = tw->core.background_pixel ;
2099 values.font = tw->tabs.font->fid ;
2100 values.line_style = LineOnOffDash ;
2101 values.line_style = LineSolid ;
2103 tw->tabs.foregroundGC =
2104 XtAllocateGC(w, w->core.depth,
2105 GCBackground|GCFont|GCLineStyle, &values,
2107 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2108 GCDashList|GCArcMode) ;
2112 TabsAllocGreyGC(TabsWidget tw)
2114 Widget w = (Widget) tw;
2117 values.background = tw->core.background_pixel ;
2118 values.font = tw->tabs.font->fid ;
2120 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2122 values.fill_style = FillStippled ;
2124 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2127 XtAllocateGC(w, w->core.depth,
2128 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2130 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2131 GCDashList|GCArcMode) ;
2137 XtAllocateGC(w, w->core.depth,
2140 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2141 GCDashList|GCArcMode) ;