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 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
150 offset(callbacks), XtRCallback, NULL},
151 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
152 offset(popdownCallbacks), XtRCallback, NULL},
153 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
154 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
155 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
156 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
157 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
158 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
159 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
160 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
161 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
162 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
168 /* constraint resources */
170 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
171 static XtResource tabsConstraintResources[] = {
172 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
173 offset(label), XtRString, NULL},
174 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
175 offset(left_bitmap), XtRImmediate, None},
176 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
177 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
178 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
179 offset(resizable), XtRImmediate, (XtPointer) True},
186 #if !NeedFunctionPrototypes
188 /* FORWARD REFERENCES: */
190 /* member functions */
192 static void TabsClassInit();
193 static void TabsInit();
194 static void TabsResize();
195 static void TabsExpose();
196 static void TabsDestroy();
197 static void TabsRealize();
198 static Boolean TabsSetValues();
199 static Boolean TabsAcceptFocus();
200 static XtGeometryResult TabsQueryGeometry();
201 static XtGeometryResult TabsGeometryManager();
202 static void TabsChangeManaged();
203 static void TabsConstraintInitialize() ;
204 static Boolean TabsConstraintSetValues() ;
208 static void TabsSelect() ;
209 static void TabsPage() ;
210 static void TabsHighlight() ;
211 static void TabsUnhighlight() ;
213 /* internal privates */
215 static void TabsAllocGCs() ; /* get rendering GCs */
216 static void TabsFreeGCs() ; /* return rendering GCs */
217 static void DrawTabs() ; /* draw all tabs */
218 static void DrawTab() ; /* draw one index tab */
219 static void DrawFrame() ; /* draw frame around contents */
220 static void DrawTrim() ; /* draw trim around a tab */
221 static void DrawBorder() ; /* draw border */
222 static void DrawHighlight() ; /* draw highlight */
223 static void UndrawTab() ; /* undraw interior of a tab */
224 static void TabWidth() ; /* recompute tab size */
225 static void GetPreferredSizes() ; /* query all children for their sizes */
226 static void MaxChild() ; /* find max preferred child size */
227 static int PreferredSize() ; /* compute preferred size */
228 static int PreferredSize2() ; /* compute preferred size */
229 static int PreferredSize3() ; /* compute preferred size */
230 static void MakeSizeRequest() ; /* try to change size */
231 static void getBitmapInfo() ;
232 static int TabLayout() ; /* lay out tabs */
233 static void TabsShuffleRows() ; /* bring current tab to bottom row */
235 static void TabsAllocFgGC() ;
236 static void TabsAllocGreyGC() ;
240 static void TabsClassInit(void) ;
241 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
242 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
243 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
244 static void TabsDestroy( Widget w) ;
245 static void TabsResize( Widget w) ;
246 static void TabsExpose( Widget w, XEvent *event, Region region) ;
247 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
248 static Boolean TabsAcceptFocus(Widget, Time *);
249 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
250 ArgList, Cardinal *) ;
251 static XtGeometryResult TabsQueryGeometry(Widget,
252 XtWidgetGeometry *, XtWidgetGeometry *) ;
253 static XtGeometryResult TabsGeometryManager(Widget,
254 XtWidgetGeometry *, XtWidgetGeometry *) ;
255 static void TabsChangeManaged( Widget w) ;
257 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
258 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
259 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
260 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
262 static void DrawTabs( TabsWidget tw, Bool labels) ;
263 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
264 static void DrawFrame( TabsWidget tw) ;
265 static void DrawTrim( TabsWidget, int x, int y,
266 int wid, int hgt, Bool bottom, Bool undraw) ;
267 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
268 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
269 static void UndrawTab( TabsWidget tw, Widget child) ;
271 static void TabWidth( Widget w) ;
272 static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt,
274 static void GetPreferredSizes(TabsWidget) ;
275 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
276 static void TabsShuffleRows( TabsWidget tw) ;
277 static int PreferredSize( TabsWidget,
278 Dimension *reply_width, Dimension *reply_height,
279 Dimension *reply_cw, Dimension *reply_ch) ;
280 static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch,
281 Dimension *rw, Dimension *rh) ;
282 static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt,
283 Dimension *rw, Dimension *rh) ;
284 static void MakeSizeRequest(TabsWidget) ;
286 static void TabsAllocGCs(TabsWidget) ;
287 static void TabsFreeGCs(TabsWidget) ;
288 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
289 static void TabsAllocFgGC( TabsWidget tw) ;
290 static void TabsAllocGreyGC( TabsWidget tw) ;
294 #define AddRect(i,xx,yy,w,h) \
295 do{rects[(i)].x=(xx); rects[i].y=(yy); \
296 rects[i].width=(w); rects[i].height=(h);}while(0)
298 static XtActionsRec actionsList[] =
300 {"select", TabsSelect},
302 {"highlight", TabsHighlight},
303 {"unhighlight", TabsUnhighlight},
307 /****************************************************************
309 * Full class record constant
311 ****************************************************************/
314 #define SuperClass (&constraintClassRec)
316 #define SuperClass (&xmManagerClassRec)
319 TabsClassRec tabsClassRec = {
321 /* core_class fields */
322 /* superclass */ (WidgetClass) SuperClass,
323 /* class_name */ "Tabs",
324 /* widget_size */ sizeof(TabsRec),
325 /* class_initialize */ TabsClassInit,
326 /* class_part_init */ NULL, /* TODO? */
327 /* class_inited */ FALSE,
328 /* initialize */ TabsInit,
329 /* initialize_hook */ NULL,
330 /* realize */ TabsRealize,
331 /* actions */ actionsList,
332 /* num_actions */ XtNumber(actionsList),
333 /* resources */ resources,
334 /* num_resources */ XtNumber(resources),
335 /* xrm_class */ NULLQUARK,
336 /* compress_motion */ TRUE,
337 #if XtSpecificationRelease < 6
338 /* compress_exposure */ XtExposeCompressMaximal,
340 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
342 /* compress_enterleave*/ TRUE,
343 /* visible_interest */ TRUE,
344 /* destroy */ TabsDestroy,
345 /* resize */ TabsResize,
346 /* expose */ TabsExpose,
347 /* set_values */ TabsSetValues,
348 /* set_values_hook */ NULL,
349 /* set_values_almost */ XtInheritSetValuesAlmost,
350 /* get_values_hook */ NULL,
351 /* accept_focus */ TabsAcceptFocus,
352 /* version */ XtVersion,
353 /* callback_private */ NULL,
354 /* tm_table */ defaultTranslations,
355 /* query_geometry */ TabsQueryGeometry,
356 /* display_accelerator*/ XtInheritDisplayAccelerator,
360 /* composite_class fields */
361 /* geometry_manager */ TabsGeometryManager,
362 /* change_managed */ TabsChangeManaged,
363 /* insert_child */ XtInheritInsertChild, /* TODO? */
364 /* delete_child */ XtInheritDeleteChild, /* TODO? */
368 /* constraint_class fields */
369 /* subresources */ tabsConstraintResources,
370 /* subresource_count */ XtNumber(tabsConstraintResources),
371 /* constraint_size */ sizeof(TabsConstraintsRec),
372 /* initialize */ TabsConstraintInitialize,
374 /* set_values */ TabsConstraintSetValues,
375 /* extension */ NULL,
378 /* Manager Class fields */
380 /* translations */ NULL,
381 /* syn_resources */ NULL,
382 /* num_syn_resources */ 0,
383 /* syn_constraint_resources */ NULL,
384 /* num_syn_constraint_resources */ 0,
385 /* parent_process */ XmInheritParentProcess,
390 /* Tabs class fields */
391 /* extension */ NULL,
395 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
397 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
398 #define TabVisible(tab) \
399 (XtIsManaged(tab) && \
400 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
403 /****************************************************************
407 ****************************************************************/
412 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
413 /* TODO: register converter for labels? */
418 /* Init a newly created tabs widget. Compute height of tabs
419 * and optionally compute size of widget. */
424 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
426 TabsWidget newTw = (TabsWidget)new;
428 newTw->tabs.numRows = 0 ;
429 newTw->tabs.realRows = 0;
431 GetPreferredSizes(newTw) ;
433 /* height is easy, it's the same for all tabs:
434 * TODO: font height + height of tallest bitmap.
436 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
438 if( newTw->tabs.font != NULL )
439 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
440 newTw->tabs.font->max_bounds.descent ;
442 /* GC allocation is deferred until XtRealize() */
444 /* if size not explicitly set, set it to our preferred size now. */
446 if( request->core.width == 0 || request->core.height == 0 )
449 PreferredSize(newTw, &w, &h, NULL,NULL) ;
450 if( request->core.width == 0 ) new->core.width = w ;
451 if( request->core.height == 0 ) new->core.height = h ;
452 XtClass(new)->core_class.resize(new) ;
455 /* defer GC allocation, etc., until Realize() time. */
456 newTw->tabs.foregroundGC =
457 newTw->tabs.backgroundGC =
460 newTw->tabs.botGC = None ;
462 newTw->tabs.grey50 = None ;
464 newTw->tabs.needs_layout = False ;
466 newTw->tabs.hilight = NULL ;
469 newTw->manager.navigation_type = XmTAB_GROUP ;
470 newTw->manager.traversal_on = True ;
475 /* Init the constraint part of a new tab child. Compute the
480 TabsConstraintInitialize(Widget request, Widget new,
481 ArgList args, Cardinal *num_args)
483 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
484 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
485 tab->tabs.visible = False ;
487 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
493 /* Called when tabs widget first realized. Create the window
494 * and allocate the GCs
498 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
500 TabsWidget tw = (TabsWidget) w;
502 attributes->bit_gravity = NorthWestGravity;
503 *valueMask |= CWBitGravity;
505 SuperClass->core_class.realize(w, valueMask, attributes);
513 TabsDestroy(Widget w)
515 TabsFreeGCs((TabsWidget)w) ;
519 /* Parent has resized us. This will require that the tabs be
526 TabsWidget tw = (TabsWidget) w;
528 int num_children = tw->composite.num_children ;
530 TabsConstraints tab ; /* #### unused */
533 /* Our size has now been dictated by the parent. Lay out the
534 * tabs, lay out the frame, lay out the children. Remember
535 * that the tabs overlap each other and the frame by shadowWidth.
536 * Also, the top tab is larger than the others, so if there's only
537 * one row, the widget must be made taller to accommodate this.
539 * Once the tabs are laid out, if there is more than one
540 * row, we may need to shuffle the rows to bring the top tab
544 tw->tabs.needs_layout = False ;
546 if( num_children > 0 && tw->composite.children != NULL )
548 /* Loop through the tabs and assign rows & x positions */
549 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
550 num_children = TabsNumChildren (tw);
552 /* assign a top widget, bring it to bottom row. */
553 TabsShuffleRows(tw) ;
555 /* now assign child positions & sizes. Positions are all the
556 * same: just inside the frame. Sizes are also all the same.
559 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
560 tw->tabs.child_height = ch =
561 tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 :
562 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
564 for(i=0, childP=tw->composite.children;
567 if( XtIsManaged(*childP) )
569 tab = (TabsConstraints) (*childP)->core.constraints ;
570 bw = (*childP)->core.border_width ;
571 /* Don't do anything if we can't see any of the child. */
572 if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0)
573 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
574 cw-bw*2,ch-bw*2, bw) ;
576 if( XtIsRealized(w) ) {
577 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
578 /* should not be necessary to explicitly repaint after a
579 * resize, but XEmacs folks tell me it is.
581 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
588 /* Redraw entire Tabs widget */
592 TabsExpose(Widget w, XEvent *event, Region region)
594 TabsWidget tw = (TabsWidget) w;
596 if( tw->tabs.needs_layout )
597 XtClass(w)->core_class.resize(w) ;
603 /* Called when any Tabs widget resources are changed. */
607 TabsSetValues(Widget current, Widget request, Widget new,
608 ArgList args, Cardinal *num_args)
610 TabsWidget curtw = (TabsWidget) current ;
611 TabsWidget tw = (TabsWidget) new ;
612 Boolean needRedraw = False ;
617 if( tw->tabs.font != curtw->tabs.font ||
618 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
619 tw->tabs.internalHeight != curtw->tabs.internalHeight )
621 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
623 if( tw->tabs.font != NULL )
624 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
625 tw->tabs.font->max_bounds.descent ;
627 /* Tab size has changed. Resize all tabs and request a new size */
628 for(i=0, childP=tw->composite.children;
629 i < tw->composite.num_children;
631 if( XtIsManaged(*childP) )
633 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
635 tw->tabs.needs_layout = True ;
638 /* TODO: if any color changes, need to recompute GCs and redraw */
640 if( tw->core.background_pixel != curtw->core.background_pixel ||
641 tw->core.background_pixmap != curtw->core.background_pixmap ||
642 tw->tabs.font != curtw->tabs.font )
643 if( XtIsRealized(new) )
650 if( tw->core.sensitive != curtw->core.sensitive )
653 /* If top widget changes, need to change stacking order, redraw tabs.
654 * Window system will handle the redraws.
657 if( tw->tabs.topWidget != curtw->tabs.topWidget )
659 if( XtIsRealized(tw->tabs.topWidget) )
661 Widget w = tw->tabs.topWidget ;
662 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
664 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
666 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
667 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
670 if( tab->tabs.row != tw->tabs.numRows-1 )
671 TabsShuffleRows(tw) ;
676 tw->tabs.needs_layout = True ;
683 /* Called when any child constraint resources change. */
687 TabsConstraintSetValues(Widget current, Widget request, Widget new,
688 ArgList args, Cardinal *num_args)
690 TabsWidget tw = (TabsWidget) XtParent(new) ;
691 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
692 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
695 /* if label changes, need to re-layout the entire widget */
696 /* if foreground changes, need to redraw tab label */
698 /* TODO: only need resize of new bitmap has different dimensions
702 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
703 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
706 tw->tabs.needs_layout = True ;
708 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
709 getBitmapInfo(tw, tab) ;
711 /* If there are no subclass ConstraintSetValues procedures remaining
712 * to be invoked, and if the preferred size has changed, ask
715 if( XtClass((Widget)tw) == tabsWidgetClass )
716 MakeSizeRequest(tw) ;
720 /* The child widget itself never needs a redisplay, but the parent
724 if( XtIsRealized(new) )
726 if( tw->tabs.needs_layout ) {
727 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
728 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
731 else if( tab->tabs.foreground != ctab->tabs.foreground )
732 DrawTab(tw, new, True) ;
740 TabsAcceptFocus(Widget w, Time *t)
742 if( !w->core.being_destroyed && XtIsRealized(w) &&
743 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
746 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
747 XtSetKeyboardFocus(p,w) ;
757 * Return preferred size. Happily accept anything >= our preferred size.
758 * (TODO: is that the right thing to do? Should we always return "almost"
759 * if offered more than we need?)
762 static XtGeometryResult
763 TabsQueryGeometry(Widget w,
764 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
766 register TabsWidget tw = (TabsWidget)w ;
767 XtGeometryMask mode = intended->request_mode ;
769 preferred->request_mode = CWWidth | CWHeight ;
770 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
772 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
773 (!(mode & CWHeight) || intended->height == w->core.height) )
774 return XtGeometryNo ;
776 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
777 (!(mode & CWHeight) || intended->height >= preferred->height) )
778 return XtGeometryYes;
780 return XtGeometryAlmost;
786 * Geometry Manager; called when a child wants to be resized.
789 static XtGeometryResult
790 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
792 TabsWidget tw = (TabsWidget) XtParent(w);
793 Dimension s = SHADWID ;
794 TabsConstraints tab = (TabsConstraints)w->core.constraints;
795 XtGeometryResult result ;
798 /* Position request always denied */
800 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
801 ((req->request_mode & CWY) && req->y != w->core.y) ||
802 !tab->tabs.resizable )
803 return XtGeometryNo ;
805 /* Make all three fields in the request valid */
806 if( !(req->request_mode & CWWidth) )
807 req->width = w->core.width;
808 if( !(req->request_mode & CWHeight) )
809 req->height = w->core.height;
810 if( !(req->request_mode & CWBorderWidth) )
811 req->border_width = w->core.border_width;
813 if( req->width == w->core.width &&
814 req->height == w->core.height &&
815 req->border_width == w->core.border_width )
816 return XtGeometryNo ;
818 rw = req->width + 2 * req->border_width ;
819 rh = req->height + 2 * req->border_width ;
821 /* find out how big the children want to be now */
822 MaxChild(tw, w, rw, rh) ;
825 /* Size changes must see if the new size can be accommodated.
826 * The Tabs widget keeps all of its children the same
827 * size. A request to shrink will be accepted only if the
828 * new size is still big enough for all other children. A
829 * request to shrink that is not big enough for all children
830 * returns an "almost" response with the new proposed size
831 * or a "no" response if unable to shrink at all.
833 * A request to grow will be accepted only if the Tabs parent can
834 * grow to accommodate.
837 * We could get fancy here and re-arrange the tabs if it is
838 * necessary to compromise with the parent, but we'll save that
842 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
844 Dimension cw,ch ; /* children's preferred size */
845 Dimension aw,ah ; /* available size we can give child */
846 Dimension th ; /* space used by tabs */
847 Dimension wid,hgt ; /* Tabs widget size */
849 cw = tw->tabs.max_cw ;
850 ch = tw->tabs.max_ch ;
852 /* find out what *my* resulting preferred size would be */
854 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
856 /* Would my size change? If so, ask to be resized. */
858 if( wid != tw->core.width || hgt != tw->core.height )
860 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
861 XtWidgetGeometry myrequest, myreply ;
863 myrequest.width = wid ;
864 myrequest.height = hgt ;
865 myrequest.request_mode = CWWidth | CWHeight ;
867 assert (wid > 0 && hgt > 0);
868 /* If child is only querying, or if we're going to have to
869 * offer the child a compromise, then make this a query only.
872 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
873 myrequest.request_mode |= XtCWQueryOnly ;
875 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
877 /* !$@# Athena Box widget changes the core size even if QueryOnly
878 * is set. I'm convinced this is a bug. At any rate, to work
879 * around the bug, we need to restore the core size after every
880 * query geometry request. This is only partly effective,
881 * as there may be other boxes further up the tree.
883 if( myrequest.request_mode & XtCWQueryOnly ) {
884 tw->core.width = oldWid ;
885 tw->core.height = oldHgt ;
888 /* based on the parent's response, determine what the
889 * resulting Tabs widget size would be.
895 tw->tabs.needs_layout = True ;
899 wid = tw->core.width ;
900 hgt = tw->core.height ;
903 case XtGeometryAlmost:
904 wid = myreply.width ;
905 hgt = myreply.height ;
906 tw->tabs.needs_layout = True ;
911 /* Within the constraints imposed by the parent, what is
912 * the max size we can give the child?
914 (void) TabLayout(tw, wid, hgt, &th, True) ;
916 ah = hgt - th - 2*s ;
918 /* OK, make our decision. If requested size is >= max sibling
919 * preferred size, AND requested size <= available size, then
920 * we accept. Otherwise, we offer a compromise.
923 if( rw == aw && rh == ah )
925 /* Acceptable. If this wasn't a query, change *all* children
928 if( req->request_mode & XtCWQueryOnly )
929 return XtGeometryYes ;
932 Widget *childP = tw->composite.children ;
934 w->core.border_width = req->border_width ;
935 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
936 if( TabVisible(*childP) )
938 bw = (*childP)->core.border_width ;
939 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
940 rw-2*bw, rh-2*bw, bw) ;
943 /* TODO: under what conditions will we need to redraw? */
944 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
945 XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
947 return XtGeometryDone ;
951 /* Cannot grant child's request. Describe what we *can* do
952 * and return counter-offer.
954 reply->width = aw - 2 * req->border_width ;
955 reply->height = ah - 2 * req->border_width ;
956 reply->border_width = req->border_width ;
957 reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
958 return XtGeometryAlmost ;
961 return XtGeometryYes ;
967 /* The number of children we manage has changed; recompute
972 TabsChangeManaged(Widget w)
974 TabsWidget tw = (TabsWidget)w ;
975 Widget *childP = tw->composite.children ;
978 if( tw->tabs.topWidget != NULL &&
979 ( !XtIsManaged(tw->tabs.topWidget) ||
980 tw->tabs.topWidget->core.being_destroyed ) )
981 tw->tabs.topWidget = NULL ;
983 /* Check whether the highlight tab is still valid. */
984 if( tw->tabs.hilight != NULL &&
985 ( !XtIsManaged(tw->tabs.hilight) ||
986 tw->tabs.hilight->core.being_destroyed ) )
987 tw->tabs.hilight = NULL ;
989 GetPreferredSizes(tw) ;
990 MakeSizeRequest(tw) ;
992 XtClass(w)->core_class.resize(w) ;
993 if( XtIsRealized(w) )
995 Display *dpy = XtDisplay(w) ;
996 XClearWindow(dpy, XtWindow(w)) ;
997 XtClass(w)->core_class.expose(w,NULL,NULL) ;
999 /* make sure the top widget stays on top. This requires
1000 * making sure that all new children are realized first.
1002 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
1004 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
1005 if( !XtIsRealized(*childP) )
1006 XtRealizeWidget(*childP) ;
1008 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
1013 /* Only top widget may receive input */
1015 for(childP = tw->composite.children, i=tw->composite.num_children;
1019 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
1022 if( tw->tabs.topWidget != NULL )
1023 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
1030 /****************************************************************
1034 ****************************************************************/
1037 /* User clicks on a tab, figure out which one it was. */
1041 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
1043 TabsWidget tw = (TabsWidget) w ;
1046 Dimension h = tw->tabs.tab_height ;
1050 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
1053 /* TODO: is there an Xmu function or something to do this instead? */
1054 switch( event->type ) {
1057 x = event->xbutton.x ; y = event->xbutton.y ; break ;
1060 x = event->xkey.x ; y = event->xkey.y ; break ;
1065 /* TODO: determine which tab was clicked, if any. Set that
1066 * widget to be top of stacking order with XawTabsSetTop().
1068 for(i=0, childP=tw->composite.children;
1069 i < TabsNumChildren (tw);
1071 if( TabVisible(*childP) )
1073 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
1074 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
1075 y > tab->tabs.y && y < tab->tabs.y + h )
1077 if( *childP != tw->tabs.topWidget &&
1078 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
1079 XawTabsSetTop(*childP, True) ;
1086 /* User hits a key */
1089 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
1091 TabsWidget tw = (TabsWidget) w ;
1092 Widget newtop = NULL;
1095 int nc = TabsNumChildren (tw) ;
1100 if( *num_params < 1 ) {
1101 XtAppWarning(XtWidgetToApplicationContext(w),
1102 "Tabs: page() action called with no arguments") ;
1106 if( tw->tabs.topWidget == NULL )
1107 tw->tabs.topWidget = tw->composite.children[0] ;
1109 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1110 if( tw->tabs.topWidget == *childP )
1113 switch( params[0][0] ) {
1118 newtop = tw->composite.children[idx] ;
1121 case 'd': /* down */
1125 newtop = tw->composite.children[idx] ;
1131 newtop = tw->composite.children[0] ;
1136 newtop = tw->composite.children[nc-1] ;
1139 case 's': /* selected */
1141 if( (newtop = tw->tabs.hilight) == NULL )
1146 XawTabsSetTop(newtop, True) ;
1150 /* User hits up/down key */
1153 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1155 TabsWidget tw = (TabsWidget) w ;
1156 Widget newhl = NULL;
1159 int nc = TabsNumChildren (tw) ;
1164 if( *num_params < 1 )
1166 if( tw->tabs.hilight != NULL )
1167 DrawHighlight(tw, tw->tabs.hilight, False) ;
1171 if( tw->tabs.hilight == NULL )
1172 newhl = tw->composite.children[0] ;
1176 /* find index of currently highlit child */
1177 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
1178 if( tw->tabs.hilight == *childP )
1181 switch( params[0][0] ) {
1186 newhl = tw->composite.children[idx] ;
1189 case 'd': /* down */
1193 newhl = tw->composite.children[idx] ;
1198 newhl = tw->composite.children[0] ;
1203 newhl = tw->composite.children[nc-1] ;
1207 newhl = tw->tabs.hilight ;
1212 XawTabsSetHighlight(w, newhl) ;
1218 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
1220 TabsWidget tw = (TabsWidget) w ;
1221 int nc = tw->composite.num_children ;
1226 if( tw->tabs.hilight != NULL )
1227 DrawHighlight(tw, tw->tabs.hilight, True) ;
1234 /****************************************************************
1238 ****************************************************************/
1241 /* Set the top tab, optionally call all callbacks. */
1243 XawTabsSetTop(Widget w, Bool callCallbacks)
1245 TabsWidget tw = (TabsWidget)w->core.parent ;
1246 TabsConstraints tab ;
1247 Widget oldtop = tw->tabs.topWidget ;
1249 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
1252 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
1253 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
1258 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
1259 (XtPointer)tw->tabs.topWidget) ;
1261 if( !XtIsRealized(w) ) {
1262 tw->tabs.topWidget = w ;
1263 tw->tabs.needs_layout = True ;
1264 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
1268 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
1270 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
1271 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
1274 tab = (TabsConstraints) w->core.constraints ;
1276 /* Unhighlight before we start messing with the stacking order. */
1277 if( tw->tabs.hilight != NULL )
1279 DrawHighlight(tw, tw->tabs.hilight, True) ;
1280 tw->tabs.hilight = NULL;
1283 if( tab->tabs.row == 0 )
1285 /* Easy case; undraw current top, undraw new top, assign new
1286 * top, redraw all borders.
1287 * We *could* just erase and execute a full redraw, but I like to
1288 * reduce screen flicker.
1290 UndrawTab(tw, oldtop) ; /* undraw old */
1291 DrawBorder(tw, oldtop, True) ;
1292 UndrawTab(tw, w) ; /* undraw new */
1293 DrawBorder(tw, w, True) ;
1294 tw->tabs.topWidget = w ;
1295 DrawTab(tw, oldtop, True) ; /* redraw old */
1296 DrawTab(tw, w, True) ; /* redraw new */
1297 DrawTabs(tw, False) ;
1301 tw->tabs.topWidget = w ;
1302 TabsShuffleRows(tw) ;
1303 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
1304 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
1307 XawTabsSetHighlight((Widget)tw, w) ;
1310 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
1314 /* Set the top tab, optionally call all callbacks. */
1316 XawTabsSetHighlight(Widget t, Widget w)
1318 TabsWidget tw = (TabsWidget)t ;
1320 if( !XtIsSubclass(t, tabsWidgetClass) )
1323 if( XtIsRealized(t) && w != tw->tabs.hilight )
1326 DrawHighlight(tw, w, False) ;
1329 tw->tabs.hilight = w ;
1335 /****************************************************************
1337 * Private Procedures
1339 ****************************************************************/
1343 TabsAllocGCs(TabsWidget tw)
1346 TabsAllocGreyGC(tw) ;
1347 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
1348 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
1349 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1350 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
1351 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
1356 TabsFreeGCs(TabsWidget tw)
1358 Widget w = (Widget) tw;
1360 XtReleaseGC(w, tw->tabs.foregroundGC) ;
1361 XtReleaseGC(w, tw->tabs.greyGC) ;
1362 XtReleaseGC(w, tw->tabs.backgroundGC) ;
1363 XtReleaseGC(w, tw->tabs.topGC) ;
1364 XtReleaseGC(w, tw->tabs.botGC) ;
1366 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
1374 /* Redraw entire Tabs widget */
1377 DrawTabs(TabsWidget tw, Bool labels)
1381 Dimension s = SHADWID ;
1382 Dimension th = tw->tabs.tab_height ;
1384 TabsConstraints tab ;
1386 if( !XtIsRealized((Widget)tw))
1389 /* draw tabs and frames by row except for the top tab, which
1390 * is drawn last. (This is inefficiently written, but should not
1391 * be too slow as long as there are not a lot of rows.)
1394 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
1395 for(i=0; i<tw->tabs.numRows; ++i, y += th)
1397 for( j=TabsNumChildren (tw), childP=tw->composite.children;
1398 --j >= 0; ++childP )
1399 if( TabVisible(*childP) )
1401 tab = (TabsConstraints)(*childP)->core.constraints;
1402 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
1403 DrawTab(tw, *childP, labels) ;
1405 if( i != tw->tabs.numRows -1 )
1406 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
1411 /* and now the top tab */
1412 if( tw->tabs.topWidget != NULL )
1413 DrawTab(tw, tw->tabs.topWidget, labels) ;
1418 /* Draw one tab. Corners are rounded very slightly. */
1421 DrawTab(TabsWidget tw, Widget child, Bool labels)
1426 if( !XtIsRealized((Widget)tw))
1429 DrawBorder(tw, child, False) ;
1433 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1434 Display *dpy = XtDisplay((Widget)tw) ;
1435 Window win = XtWindow((Widget)tw) ;
1436 String lbl = tab->tabs.label != NULL ?
1437 tab->tabs.label : XtName(child) ;
1439 if( XtIsSensitive(child) )
1441 gc = tw->tabs.foregroundGC ;
1442 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1446 /* grey pixel allocation deferred until now */
1447 if( !tab->tabs.greyAlloc )
1449 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
1450 tab->tabs.grey = tab->tabs.foreground ;
1452 tab->tabs.grey = AllocGreyPixel((Widget)tw,
1453 tab->tabs.foreground,
1454 tw->core.background_pixel,
1455 tw->tabs.insensitive_contrast ) ;
1456 tab->tabs.greyAlloc = True ;
1458 gc = tw->tabs.greyGC ;
1459 XSetForeground(dpy, gc, tab->tabs.grey) ;
1464 if( child == tw->tabs.topWidget )
1467 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
1469 if( tab->tabs.lbm_depth == 1 )
1470 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
1471 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1472 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
1474 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
1475 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
1476 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
1479 if( lbl != NULL && tw->tabs.font != NULL )
1480 XDrawString(dpy,win,gc,
1481 x+tab->tabs.l_x, y+tab->tabs.l_y,
1482 lbl, (int)strlen(lbl)) ;
1485 if( child == tw->tabs.hilight )
1486 DrawHighlight(tw, child, False) ;
1490 /* draw frame all the way around the child windows. */
1493 DrawFrame(TabsWidget tw)
1495 GC topgc = tw->tabs.topGC ;
1496 GC botgc = tw->tabs.botGC ;
1497 Dimension s = SHADWID ;
1498 Dimension ch = tw->tabs.child_height ;
1500 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1501 tw->core.width, ch+2*s, s, topgc, botgc) ;
1504 Widget w = tw->tabs.topWidget ;
1507 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1508 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
1509 tab->tabs.x, 2*s, s, topgc, botgc);
1510 Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width,
1511 tw->core.height - 2*s,
1512 tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s,
1516 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
1517 tw->core.width, 2*s, s, topgc, botgc) ;
1522 /* draw trim around a tab or underneath a row of tabs */
1525 DrawTrim(TabsWidget tw, /* widget */
1526 int x, /* upper-left corner */
1528 int wid, /* total size */
1530 Bool bottom, /* draw bottom? */
1531 Bool undraw) /* undraw all */
1533 Display *dpy = XtDisplay((Widget)tw) ;
1534 Window win = XtWindow((Widget)tw) ;
1535 GC bggc = tw->tabs.backgroundGC ;
1536 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1537 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1539 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1540 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1541 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1542 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1543 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1544 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1548 /* Draw one tab border. */
1551 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1553 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1554 Position x = tab->tabs.x ;
1555 Position y = tab->tabs.y ;
1556 Dimension twid = tab->tabs.width ;
1557 Dimension thgt = tw->tabs.tab_height ;
1559 /* top tab requires a little special attention; it overlaps
1560 * neighboring tabs slightly, so the background must be cleared
1561 * in the region of the overlap to partially erase those neighbors.
1562 * TODO: is this worth doing with regions instead?
1564 if( child == tw->tabs.topWidget )
1566 Display *dpy = XtDisplay((Widget)tw) ;
1567 Window win = XtWindow((Widget)tw) ;
1568 GC bggc = tw->tabs.backgroundGC ;
1569 XRectangle rects[3] ;
1572 twid += TABDELTA*2 ;
1574 AddRect(0, x,y+1,twid,TABDELTA) ;
1575 AddRect(1, x+1,y,TABDELTA,thgt) ;
1576 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1577 XFillRectangles(dpy,win,bggc, rects, 3) ;
1580 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1584 /* Draw highlight around tab that has focus */
1587 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1589 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1590 Display *dpy = XtDisplay((Widget)tw) ;
1591 Window win = XtWindow((Widget)tw) ;
1593 Position x = tab->tabs.x ;
1594 Position y = tab->tabs.y ;
1595 Dimension wid = tab->tabs.width ;
1596 Dimension hgt = tw->tabs.tab_height ;
1599 /* top tab does not have a highlight */
1601 if( child == tw->tabs.topWidget )
1605 gc = tw->tabs.backgroundGC ;
1607 else if( XtIsSensitive(child) )
1609 gc = tw->tabs.foregroundGC ;
1610 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1614 gc = tw->tabs.greyGC ;
1615 XSetForeground(dpy, gc, tab->tabs.grey) ;
1618 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1619 points[1].x = x+1 ; points[1].y = y+2 ;
1620 points[2].x = x+2 ; points[2].y = y+1 ;
1621 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1622 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1623 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1625 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1629 /* Undraw one tab interior */
1632 UndrawTab(TabsWidget tw, Widget child)
1634 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1635 Position x = tab->tabs.x ;
1636 Position y = tab->tabs.y ;
1637 Dimension twid = tab->tabs.width ;
1638 Dimension thgt = tw->tabs.tab_height ;
1639 Display *dpy = XtDisplay((Widget)tw) ;
1640 Window win = XtWindow((Widget)tw) ;
1641 GC bggc = tw->tabs.backgroundGC ;
1643 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1650 /* GEOMETRY UTILITIES */
1654 * MaxChild(): ask all children (except possibly one) their
1655 * preferred sizes, set max_cw, max_ch accordingly.
1657 * GetPreferredSizes(): ask all children their preferred sizes,
1658 * set max_cw, max_ch accordingly.
1660 * PreferredSize(): given max_cw, max_ch, return tabs widget
1661 * preferred size. Iterate with other widths in order to get
1662 * a reasonable aspect ratio.
1664 * PreferredSize2(): Given child dimensions, return Tabs
1665 * widget dimensions.
1667 * PreferredSize3(): Same, except given child dimensions plus
1672 /* Compute the width of one child's tab. Positions will be computed
1675 * height: font height + vertical_space*2 + shadowWid*2
1676 * width: string width + horizontal_space*2 + shadowWid*2
1678 * All tabs are the same height, so that is computed elsewhere.
1684 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1685 TabsWidget tw = (TabsWidget)XtParent(w) ;
1686 String lbl = tab->tabs.label != NULL ?
1687 tab->tabs.label : XtName(w) ;
1688 XFontStruct *font = tw->tabs.font ;
1689 int iw = tw->tabs.internalWidth ;
1691 tab->tabs.width = iw + SHADWID*2 ;
1692 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1694 if( tab->tabs.left_bitmap != None )
1696 tab->tabs.width += tab->tabs.lbm_width + iw ;
1697 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1698 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1701 if( lbl != NULL && font != NULL )
1703 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1704 tab->tabs.l_y = (tw->tabs.tab_height +
1705 tw->tabs.font->max_bounds.ascent -
1706 tw->tabs.font->max_bounds.descent)/2 ;
1712 /* Lay out tabs to fit in given width. Compute x,y position and
1713 * row number for each tab. Return number of rows and total height
1714 * required by all tabs. If there is only one row, add TABDELTA
1715 * height to the total. Rows are assigned bottom to top.
1717 * Tabs are indented from the edges by INDENT.
1719 * TODO: if they require more than two rows and the total height:width
1720 * ratio is more than 2:1, then try something else.
1724 TabLayout(TabsWidget tw,
1727 Dimension *reply_height, Bool query_only)
1729 int i, row, done = 0, display_rows = 0 ;
1730 int num_children = tw->composite.num_children ;
1734 TabsConstraints tab ;
1736 /* Algorithm: loop through children, assign X positions. If a tab
1737 * would extend beyond the right edge, start a new row. After all
1738 * rows are assigned, make a second pass and assign Y positions.
1741 if( num_children > 0 )
1743 /* Loop through the tabs and see how much space they need. */
1749 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1750 if( XtIsManaged(*childP) )
1752 tab = (TabsConstraints) (*childP)->core.constraints ;
1753 w = tab->tabs.width ;
1755 if( x + w > wid ) { /* new row */
1756 if (y + tw->tabs.tab_height > hgt && !done)
1763 y += tw->tabs.tab_height ;
1768 tab->tabs.row = row ;
1771 if (!query_only && !done)
1772 tab->tabs.visible = 1;
1775 /* If there was only one row, increase the height by TABDELTA */
1776 if( ++display_rows == 1 )
1781 for(i=num_children, childP=tw->composite.children;
1782 --i >= 0 ; ++childP)
1783 if( XtIsManaged(*childP) )
1785 tab = (TabsConstraints) (*childP)->core.constraints ;
1789 y += tw->tabs.tab_height ;
1792 display_rows = row = y = 0 ;
1795 tw->tabs.tab_total = y ;
1796 tw->tabs.numRows = display_rows ;
1797 tw->tabs.realRows = row;
1800 if( reply_height != NULL )
1803 return display_rows ;
1808 /* Find max preferred child size. Returned sizes include child
1813 GetPreferredSizes(TabsWidget tw)
1815 MaxChild(tw, NULL, 0,0) ;
1820 /* Find max preferred child size. Returned sizes include child
1821 * border widths. If except is non-null, don't ask that one.
1825 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
1828 Widget *childP = tw->composite.children ;
1829 XtWidgetGeometry preferred ;
1831 for(i=tw->composite.num_children; --i >=0; ++childP)
1832 if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except )
1834 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1835 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
1836 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
1839 tw->tabs.max_cw = cw ;
1840 tw->tabs.max_ch = ch ;
1845 /* rotate row numbers to bring current widget to bottom row,
1846 * compute y positions for all tabs
1850 TabsShuffleRows(TabsWidget tw)
1852 TabsConstraints tab ;
1854 int real_rows, display_rows ;
1856 Dimension th = tw->tabs.tab_height ;
1860 /* There must be a top widget. If not, assign one. */
1861 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1862 for(i=TabsNumChildren (tw), childP=tw->composite.children;
1865 if( XtIsManaged(*childP) ) {
1866 tw->tabs.topWidget = *childP ;
1870 if( tw->tabs.topWidget != NULL )
1872 display_rows = tw->tabs.numRows ;
1873 real_rows = tw->tabs.realRows ;
1874 assert( display_rows <= real_rows ) ;
1878 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1879 assert( tab != NULL ) ;
1881 /* How far to move top row. The selected tab must be on
1882 the bottom row of the *visible* rows. */
1883 move = (real_rows + 1 - display_rows) - tab->tabs.row ;
1885 move = real_rows - move;
1886 bottom = tw->tabs.tab_total - th ;
1888 for(i=tw->composite.num_children, childP=tw->composite.children;
1891 if( XtIsManaged(*childP) )
1893 tab = (TabsConstraints) (*childP)->core.constraints ;
1894 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
1895 tab->tabs.y = bottom - tab->tabs.row * th ;
1896 tab->tabs.visible = (tab->tabs.row < display_rows);
1903 /* Find preferred size. Ask children, find size of largest,
1904 * add room for tabs & return. This can get a little involved,
1905 * as we don't want to have too many rows of tabs; we may widen
1906 * the widget to reduce # of rows.
1908 * This function requires that max_cw, max_ch already be set.
1913 Dimension *reply_width, /* total widget size */
1914 Dimension *reply_height,
1915 Dimension *reply_cw, /* child widget size */
1916 Dimension *reply_ch)
1918 Dimension cw,ch ; /* child width, height */
1920 Dimension rwid,rhgt ;
1923 wid = cw = tw->tabs.max_cw ;
1924 hgt = ch = tw->tabs.max_ch ;
1926 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1928 /* Check for absurd results (more than 2 rows, high aspect
1929 * ratio). Try wider size if needed.
1930 * TODO: make sure this terminates.
1933 if( nrow > 2 && rhgt > rwid )
1938 /* step 1: start doubling size until it's too big */
1941 wid = Max(wid*2, wid+20) ;
1942 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1943 } while( nrow > 2 && rhgt > rwid ) ;
1946 /* step 2: use Newton's method to find ideal size. Stop within
1949 while( --maxloop > 0 && w1 > w0 + 8 )
1952 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1953 if( nrow > 2 && rhgt > rwid )
1961 *reply_width = rwid ;
1962 *reply_height = rhgt ;
1963 if( reply_cw != NULL ) *reply_cw = cw ;
1964 if( reply_ch != NULL ) *reply_ch = ch ;
1969 /* Find preferred size, given size of children. */
1974 Dimension cw, /* child width, height */
1976 Dimension *reply_width, /* total widget size */
1977 Dimension *reply_height)
1979 Dimension s = SHADWID ;
1982 /* make room for shadow frame */
1986 ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1988 assert (*reply_width > 0 && *reply_height > 0);
1993 /* Find preferred size, given size of children+shadow. */
1998 Dimension wid, /* child width, height */
2000 Dimension *reply_width, /* total widget size */
2001 Dimension *reply_height)
2003 Dimension th ; /* space used by tabs */
2006 if( tw->composite.num_children > 0 )
2007 nrows = TabLayout(tw, wid, hgt, &th, True) ;
2013 *reply_width = Max(wid, MIN_WID) ;
2014 *reply_height = Max(th+hgt, MIN_HGT) ;
2021 MakeSizeRequest(TabsWidget tw)
2023 Widget w = (Widget)tw ;
2024 XtWidgetGeometry request, reply ;
2025 XtGeometryResult result ;
2028 request.request_mode = CWWidth | CWHeight ;
2029 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
2031 if( request.width == tw->core.width &&
2032 request.height == tw->core.height )
2035 result = XtMakeGeometryRequest(w, &request, &reply) ;
2037 if( result == XtGeometryAlmost )
2039 /* Bugger. Didn't get what we want, but were offered a
2040 * compromise. If the width was too small, recompute
2041 * based on the too-small width and try again.
2042 * If the height was too small, make a wild-ass guess
2043 * at a wider width and try again.
2046 if( reply.width < request.width && reply.height >= request.height )
2048 Dimension s = SHADWID ;
2050 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
2051 result = XtMakeGeometryRequest(w, &request, &reply) ;
2052 if( result == XtGeometryAlmost )
2053 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2057 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2063 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2069 if( tab->tabs.left_bitmap == None ||
2070 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2071 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2072 &bw, &tab->tabs.lbm_depth) )
2073 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2079 /* Code copied & modified from Gcs.c. This version has dynamic
2084 TabsAllocFgGC(TabsWidget tw)
2086 Widget w = (Widget) tw;
2089 values.background = tw->core.background_pixel ;
2090 values.font = tw->tabs.font->fid ;
2091 values.line_style = LineOnOffDash ;
2092 values.line_style = LineSolid ;
2094 tw->tabs.foregroundGC =
2095 XtAllocateGC(w, w->core.depth,
2096 GCBackground|GCFont|GCLineStyle, &values,
2098 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2099 GCDashList|GCArcMode) ;
2103 TabsAllocGreyGC(TabsWidget tw)
2105 Widget w = (Widget) tw;
2108 values.background = tw->core.background_pixel ;
2109 values.font = tw->tabs.font->fid ;
2111 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2113 values.fill_style = FillStippled ;
2115 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2118 XtAllocateGC(w, w->core.depth,
2119 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2121 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2122 GCDashList|GCArcMode) ;
2128 XtAllocateGC(w, w->core.depth,
2131 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2132 GCDashList|GCArcMode) ;