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>
69 #include "../src/xmu.h"
75 #define INDENT 3 /* tabs indented from edge by this much */
76 #define SPACING 0 /* distance between tabs */
77 #define SHADWID 1 /* default shadow width */
78 #define TABDELTA 2 /* top tab grows this many pixels */
79 #define TABLDELTA 2 /* top tab label offset this many pixels */
82 /****************************************************************
86 ****************************************************************/
88 static char defaultTranslations[] = "\
90 <FocusIn>: highlight() \n\
91 <FocusOut>: unhighlight() \n\
92 <Key>Page_Up: page(up) \n\
93 <Key>KP_Page_Up: page(up) \n\
94 <Key>Prior: page(up) \n\
95 <Key>KP_Prior: page(up) \n\
96 <Key>Page_Down: page(down) \n\
97 <Key>KP_Page_Down: page(down) \n\
98 <Key>Next: page(down) \n\
99 <Key>KP_Next: page(down) \n\
100 <Key>Home: page(home) \n\
101 <Key>KP_Home: page(home) \n\
102 <Key>End: page(end) \n\
103 <Key>KP_End: page(end) \n\
104 <Key>Up: highlight(up) \n\
105 <Key>KP_Up: highlight(up) \n\
106 <Key>Down: highlight(down) \n\
107 <Key>KP_Down: highlight(down) \n\
108 <Key> : page(select) \n\
111 static char accelTable[] = " #augment\n\
112 <Key>Page_Up: page(up) \n\
113 <Key>KP_Page_Up: page(up) \n\
114 <Key>Prior: page(up) \n\
115 <Key>KP_Prior: page(up) \n\
116 <Key>Page_Down: page(down) \n\
117 <Key>KP_Page_Down: page(down) \n\
118 <Key>Next: page(down) \n\
119 <Key>KP_Next: page(down) \n\
120 <Key>Home: page(home) \n\
121 <Key>KP_Home: page(home) \n\
122 <Key>End: page(end) \n\
123 <Key>KP_End: page(end) \n\
124 <Key>Up: highlight(up) \n\
125 <Key>KP_Up: highlight(up) \n\
126 <Key>Down: highlight(down) \n\
127 <Key>KP_Down: highlight(down) \n\
128 <Key> : page(select) \n\
130 static XtAccelerators defaultAccelerators ; /* #### Never used */
132 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
133 static XtResource resources[] = {
135 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
136 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
137 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
138 offset(font), XtRString, (XtPointer) XtDefaultFont},
139 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
140 offset(internalWidth), XtRImmediate, (XtPointer)4 },
141 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
142 offset(internalHeight), XtRImmediate, (XtPointer)4 },
143 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
144 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
145 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
146 offset(topWidget), XtRImmediate, NULL},
147 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
148 offset(callbacks), XtRCallback, NULL},
149 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
150 offset(popdownCallbacks), XtRCallback, NULL},
151 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
152 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
153 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
154 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
155 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
156 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
157 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
158 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
159 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
160 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
166 /* constraint resources */
168 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
169 static XtResource tabsConstraintResources[] = {
170 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
171 offset(label), XtRString, NULL},
172 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
173 offset(left_bitmap), XtRImmediate, None},
174 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
175 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
176 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
177 offset(resizable), XtRImmediate, (XtPointer) True},
184 #if !NeedFunctionPrototypes
186 /* FORWARD REFERENCES: */
188 /* member functions */
190 static void TabsClassInit();
191 static void TabsInit();
192 static void TabsResize();
193 static void TabsExpose();
194 static void TabsDestroy();
195 static void TabsRealize();
196 static Boolean TabsSetValues();
197 static Boolean TabsAcceptFocus();
198 static XtGeometryResult TabsQueryGeometry();
199 static XtGeometryResult TabsGeometryManager();
200 static void TabsChangeManaged();
201 static void TabsConstraintInitialize() ;
202 static Boolean TabsConstraintSetValues() ;
206 static void TabsSelect() ;
207 static void TabsPage() ;
208 static void TabsHighlight() ;
209 static void TabsUnhighlight() ;
211 /* internal privates */
213 static void TabsAllocGCs() ; /* get rendering GCs */
214 static void TabsFreeGCs() ; /* return rendering GCs */
215 static void DrawTabs() ; /* draw all tabs */
216 static void DrawTab() ; /* draw one index tab */
217 static void DrawFrame() ; /* draw frame around contents */
218 static void DrawTrim() ; /* draw trim around a tab */
219 static void DrawBorder() ; /* draw border */
220 static void DrawHighlight() ; /* draw highlight */
221 static void UndrawTab() ; /* undraw interior of a tab */
222 static void TabWidth() ; /* recompute tab size */
223 static void GetPreferredSizes() ; /* query all children for their sizes */
224 static void MaxChild() ; /* find max preferred child size */
225 static int PreferredSize() ; /* compute preferred size */
226 static int PreferredSize2() ; /* compute preferred size */
227 static int PreferredSize3() ; /* compute preferred size */
228 static void MakeSizeRequest() ; /* try to change size */
229 static void getBitmapInfo() ;
230 static int TabLayout() ; /* lay out tabs */
231 static void TabsShuffleRows() ; /* bring current tab to bottom row */
233 static void TabsAllocFgGC() ;
234 static void TabsAllocGreyGC() ;
238 static void TabsClassInit(void) ;
239 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
240 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
241 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
242 static void TabsDestroy( Widget w) ;
243 static void TabsResize( Widget w) ;
244 static void TabsExpose( Widget w, XEvent *event, Region region) ;
245 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
246 static Boolean TabsAcceptFocus(Widget, Time *);
247 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
248 ArgList, Cardinal *) ;
249 static XtGeometryResult TabsQueryGeometry(Widget,
250 XtWidgetGeometry *, XtWidgetGeometry *) ;
251 static XtGeometryResult TabsGeometryManager(Widget,
252 XtWidgetGeometry *, XtWidgetGeometry *) ;
253 static void TabsChangeManaged( Widget w) ;
255 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
256 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
257 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
258 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
260 static void DrawTabs( TabsWidget tw, Bool labels) ;
261 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
262 static void DrawFrame( TabsWidget tw) ;
263 static void DrawTrim( TabsWidget, int x, int y,
264 int wid, int hgt, Bool bottom, Bool undraw) ;
265 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
266 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
267 static void UndrawTab( TabsWidget tw, Widget child) ;
269 static void TabWidth( Widget w) ;
270 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
272 static void GetPreferredSizes(TabsWidget) ;
273 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
274 static void TabsShuffleRows( TabsWidget tw) ;
275 static int PreferredSize( TabsWidget,
276 Dimension *reply_width, Dimension *reply_height,
277 Dimension *reply_cw, Dimension *reply_ch) ;
278 static int PreferredSize2( TabsWidget, int cw, int ch,
279 Dimension *rw, Dimension *rh) ;
280 static int PreferredSize3( TabsWidget, int wid, int hgt,
281 Dimension *rw, Dimension *rh) ;
282 static void MakeSizeRequest(TabsWidget) ;
284 static void TabsAllocGCs(TabsWidget) ;
285 static void TabsFreeGCs(TabsWidget) ;
286 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
287 static void TabsAllocFgGC( TabsWidget tw) ;
288 static void TabsAllocGreyGC( TabsWidget tw) ;
292 #define AddRect(i,xx,yy,w,h) \
293 do{rects[(i)].x=(xx); rects[i].y=(yy); \
294 rects[i].width=(w); rects[i].height=(h);}while(0)
296 static XtActionsRec actionsList[] =
298 {"select", TabsSelect},
300 {"highlight", TabsHighlight},
301 {"unhighlight", TabsUnhighlight},
305 /****************************************************************
307 * Full class record constant
309 ****************************************************************/
312 #define SuperClass (&constraintClassRec)
314 #define SuperClass (&xmManagerClassRec)
317 TabsClassRec tabsClassRec = {
319 /* core_class fields */
320 /* superclass */ (WidgetClass) SuperClass,
321 /* class_name */ "Tabs",
322 /* widget_size */ sizeof(TabsRec),
323 /* class_initialize */ TabsClassInit,
324 /* class_part_init */ NULL, /* TODO? */
325 /* class_inited */ FALSE,
326 /* initialize */ TabsInit,
327 /* initialize_hook */ NULL,
328 /* realize */ TabsRealize,
329 /* actions */ actionsList,
330 /* num_actions */ XtNumber(actionsList),
331 /* resources */ resources,
332 /* num_resources */ XtNumber(resources),
333 /* xrm_class */ NULLQUARK,
334 /* compress_motion */ TRUE,
335 #if XtSpecificationRelease < 6
336 /* compress_exposure */ XtExposeCompressMaximal,
338 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
340 /* compress_enterleave*/ TRUE,
341 /* visible_interest */ TRUE,
342 /* destroy */ TabsDestroy,
343 /* resize */ TabsResize,
344 /* expose */ TabsExpose,
345 /* set_values */ TabsSetValues,
346 /* set_values_hook */ NULL,
347 /* set_values_almost */ XtInheritSetValuesAlmost,
348 /* get_values_hook */ NULL,
349 /* accept_focus */ TabsAcceptFocus,
350 /* version */ XtVersion,
351 /* callback_private */ NULL,
352 /* tm_table */ defaultTranslations,
353 /* query_geometry */ TabsQueryGeometry,
354 /* display_accelerator*/ XtInheritDisplayAccelerator,
358 /* composite_class fields */
359 /* geometry_manager */ TabsGeometryManager,
360 /* change_managed */ TabsChangeManaged,
361 /* insert_child */ XtInheritInsertChild, /* TODO? */
362 /* delete_child */ XtInheritDeleteChild, /* TODO? */
366 /* constraint_class fields */
367 /* subresources */ tabsConstraintResources,
368 /* subresource_count */ XtNumber(tabsConstraintResources),
369 /* constraint_size */ sizeof(TabsConstraintsRec),
370 /* initialize */ TabsConstraintInitialize,
372 /* set_values */ TabsConstraintSetValues,
373 /* extension */ NULL,
376 /* Manager Class fields */
378 /* translations */ NULL,
379 /* syn_resources */ NULL,
380 /* num_syn_resources */ 0,
381 /* syn_constraint_resources */ NULL,
382 /* num_syn_constraint_resources */ 0,
383 /* parent_process */ XmInheritParentProcess,
388 /* Tabs class fields */
389 /* extension */ NULL,
393 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
400 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
403 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
409 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
410 #define TabVisible(tab) \
411 (XtIsManaged(tab) && \
412 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
415 /****************************************************************
419 ****************************************************************/
424 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
425 /* TODO: register converter for labels? */
430 /* Init a newly created tabs widget. Compute height of tabs
431 * and optionally compute size of widget. */
436 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
438 TabsWidget newTw = (TabsWidget)new;
440 newTw->tabs.numRows = 0 ;
441 newTw->tabs.realRows = 0;
443 GetPreferredSizes(newTw) ;
445 /* height is easy, it's the same for all tabs:
446 * TODO: font height + height of tallest bitmap.
448 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
450 if( newTw->tabs.font != NULL )
451 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
452 newTw->tabs.font->max_bounds.descent ;
454 /* GC allocation is deferred until XtRealize() */
456 /* if size not explicitly set, set it to our preferred size now. */
458 if( request->core.width == 0 || request->core.height == 0 )
461 PreferredSize(newTw, &w, &h, NULL,NULL) ;
462 if( request->core.width == 0 ) new->core.width = w ;
463 if( request->core.height == 0 ) new->core.height = h ;
464 XtClass(new)->core_class.resize(new) ;
467 /* defer GC allocation, etc., until Realize() time. */
468 newTw->tabs.foregroundGC =
469 newTw->tabs.backgroundGC =
472 newTw->tabs.botGC = None ;
474 newTw->tabs.grey50 = None ;
476 newTw->tabs.needs_layout = False ;
478 newTw->tabs.hilight = NULL ;
481 newTw->manager.navigation_type = XmTAB_GROUP ;
482 newTw->manager.traversal_on = True ;
487 /* Init the constraint part of a new tab child. Compute the
492 TabsConstraintInitialize(Widget request, Widget new,
493 ArgList args, Cardinal *num_args)
495 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
496 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
497 tab->tabs.visible = False ;
499 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
505 /* Called when tabs widget first realized. Create the window
506 * and allocate the GCs
510 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
512 TabsWidget tw = (TabsWidget) w;
514 attributes->bit_gravity = NorthWestGravity;
515 *valueMask |= CWBitGravity;
517 SuperClass->core_class.realize(w, valueMask, attributes);
525 TabsDestroy(Widget w)
527 TabsFreeGCs((TabsWidget)w) ;
531 /* Parent has resized us. This will require that the tabs be
538 TabsWidget tw = (TabsWidget) w;
540 int num_children = tw->composite.num_children ;
542 TabsConstraints tab ; /* #### unused */
545 /* Our size has now been dictated by the parent. Lay out the
546 * tabs, lay out the frame, lay out the children. Remember
547 * that the tabs overlap each other and the frame by shadowWidth.
548 * Also, the top tab is larger than the others, so if there's only
549 * one row, the widget must be made taller to accommodate this.
551 * Once the tabs are laid out, if there is more than one
552 * row, we may need to shuffle the rows to bring the top tab
556 tw->tabs.needs_layout = False ;
558 if( num_children > 0 && tw->composite.children != NULL )
560 /* Loop through the tabs and assign rows & x positions */
561 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
562 num_children = TabsNumChildren (tw);
564 /* assign a top widget, bring it to bottom row. */
565 TabsShuffleRows(tw) ;
567 /* now assign child positions & sizes. Positions are all the
568 * same: just inside the frame. Sizes are also all the same.
571 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
572 tw->tabs.child_height = ch =
573 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
576 for(i=0, childP=tw->composite.children;
579 if( TabVisible(*childP) )
581 tab = (TabsConstraints) (*childP)->core.constraints ;
582 bw = (*childP)->core.border_width ;
583 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
584 cw-bw*2,ch-bw*2, bw) ;
586 if( XtIsRealized(w) ) {
587 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
588 /* should not be necessary to explicitly repaint after a
589 * resize, but XEmacs folks tell me it is.
591 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
598 /* Redraw entire Tabs widget */
602 TabsExpose(Widget w, XEvent *event, Region region)
604 TabsWidget tw = (TabsWidget) w;
606 if( tw->tabs.needs_layout )
607 XtClass(w)->core_class.resize(w) ;
613 /* Called when any Tabs widget resources are changed. */
617 TabsSetValues(Widget current, Widget request, Widget new,
618 ArgList args, Cardinal *num_args)
620 TabsWidget curtw = (TabsWidget) current ;
621 TabsWidget tw = (TabsWidget) new ;
622 Boolean needRedraw = False ;
627 if( tw->tabs.font != curtw->tabs.font ||
628 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
629 tw->tabs.internalHeight != curtw->tabs.internalHeight )
631 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
633 if( tw->tabs.font != NULL )
634 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
635 tw->tabs.font->max_bounds.descent ;
637 /* Tab size has changed. Resize all tabs and request a new size */
638 for(i=0, childP=tw->composite.children;
639 i < tw->composite.num_children;
641 if( XtIsManaged(*childP) )
643 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
645 tw->tabs.needs_layout = True ;
648 /* TODO: if any color changes, need to recompute GCs and redraw */
650 if( tw->core.background_pixel != curtw->core.background_pixel ||
651 tw->core.background_pixmap != curtw->core.background_pixmap ||
652 tw->tabs.font != curtw->tabs.font )
653 if( XtIsRealized(new) )
660 if( tw->core.sensitive != curtw->core.sensitive )
663 /* If top widget changes, need to change stacking order, redraw tabs.
664 * Window system will handle the redraws.
667 if( tw->tabs.topWidget != curtw->tabs.topWidget )
669 if( XtIsRealized(tw->tabs.topWidget) )
671 Widget w = tw->tabs.topWidget ;
672 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
674 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
676 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
677 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
680 if( tab->tabs.row != tw->tabs.numRows-1 )
681 TabsShuffleRows(tw) ;
686 tw->tabs.needs_layout = True ;
693 /* Called when any child constraint resources change. */
697 TabsConstraintSetValues(Widget current, Widget request, Widget new,
698 ArgList args, Cardinal *num_args)
700 TabsWidget tw = (TabsWidget) XtParent(new) ;
701 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
702 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
705 /* if label changes, need to re-layout the entire widget */
706 /* if foreground changes, need to redraw tab label */
708 /* TODO: only need resize of new bitmap has different dimensions
712 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
713 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
716 tw->tabs.needs_layout = True ;
718 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
719 getBitmapInfo(tw, tab) ;
721 /* If there are no subclass ConstraintSetValues procedures remaining
722 * to be invoked, and if the preferred size has changed, ask
725 if( XtClass((Widget)tw) == tabsWidgetClass )
726 MakeSizeRequest(tw) ;
730 /* The child widget itself never needs a redisplay, but the parent
734 if( XtIsRealized(new) )
736 if( tw->tabs.needs_layout ) {
737 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
738 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
741 else if( tab->tabs.foreground != ctab->tabs.foreground )
742 DrawTab(tw, new, True) ;
750 TabsAcceptFocus(Widget w, Time *t)
752 if( !w->core.being_destroyed && XtIsRealized(w) &&
753 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
756 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
757 XtSetKeyboardFocus(p,w) ;
767 * Return preferred size. Happily accept anything >= our preferred size.
768 * (TODO: is that the right thing to do? Should we always return "almost"
769 * if offered more than we need?)
772 static XtGeometryResult
773 TabsQueryGeometry(Widget w,
774 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
776 register TabsWidget tw = (TabsWidget)w ;
777 XtGeometryMask mode = intended->request_mode ;
779 preferred->request_mode = CWWidth | CWHeight ;
780 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
782 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
783 (!(mode & CWHeight) || intended->height == w->core.height) )
784 return XtGeometryNo ;
786 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
787 (!(mode & CWHeight) || intended->height >= preferred->height) )
788 return XtGeometryYes;
790 return XtGeometryAlmost;
796 * Geometry Manager; called when a child wants to be resized.
799 static XtGeometryResult
800 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
802 TabsWidget tw = (TabsWidget) XtParent(w);
803 Dimension s = SHADWID ;
804 TabsConstraints tab = (TabsConstraints)w->core.constraints;
805 XtGeometryResult result ;
808 /* Position request always denied */
810 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
811 ((req->request_mode & CWY) && req->y != w->core.y) ||
812 !tab->tabs.resizable )
813 return XtGeometryNo ;
815 /* Make all three fields in the request valid */
816 if( !(req->request_mode & CWWidth) )
817 req->width = w->core.width;
818 if( !(req->request_mode & CWHeight) )
819 req->height = w->core.height;
820 if( !(req->request_mode & CWBorderWidth) )
821 req->border_width = w->core.border_width;
823 if( req->width == w->core.width &&
824 req->height == w->core.height &&
825 req->border_width == w->core.border_width )
826 return XtGeometryNo ;
828 rw = req->width + 2 * req->border_width ;
829 rh = req->height + 2 * req->border_width ;
831 /* find out how big the children want to be now */
832 MaxChild(tw, w, rw, rh) ;
835 /* Size changes must see if the new size can be accommodated.
836 * The Tabs widget keeps all of its children the same
837 * size. A request to shrink will be accepted only if the
838 * new size is still big enough for all other children. A
839 * request to shrink that is not big enough for all children
840 * returns an "almost" response with the new proposed size
841 * or a "no" response if unable to shrink at all.
843 * A request to grow will be accepted only if the Tabs parent can
844 * grow to accommodate.
847 * We could get fancy here and re-arrange the tabs if it is
848 * necessary to compromise with the parent, but we'll save that
852 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
854 Dimension cw,ch ; /* children's preferred size */
855 Dimension aw,ah ; /* available size we can give child */
856 Dimension th ; /* space used by tabs */
857 Dimension wid,hgt ; /* Tabs widget size */
859 cw = tw->tabs.max_cw ;
860 ch = tw->tabs.max_ch ;
862 /* find out what *my* resulting preferred size would be */
864 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
866 /* Would my size change? If so, ask to be resized. */
868 if( wid != tw->core.width || hgt != tw->core.height )
870 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
871 XtWidgetGeometry myrequest, myreply ;
873 myrequest.width = wid ;
874 myrequest.height = hgt ;
875 myrequest.request_mode = CWWidth | CWHeight ;
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 ;
1508 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1509 tw->core.width, ch+2*s, s, topgc, botgc) ;
1513 /* draw trim around a tab or underneath a row of tabs */
1516 DrawTrim(TabsWidget tw, /* widget */
1517 int x, /* upper-left corner */
1519 int wid, /* total size */
1521 Bool bottom, /* draw bottom? */
1522 Bool undraw) /* undraw all */
1524 Display *dpy = XtDisplay((Widget)tw) ;
1525 Window win = XtWindow((Widget)tw) ;
1526 GC bggc = tw->tabs.backgroundGC ;
1527 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1528 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1530 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1531 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1532 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1533 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1534 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1535 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1539 /* Draw one tab border. */
1542 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1544 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1545 Position x = tab->tabs.x ;
1546 Position y = tab->tabs.y ;
1547 Dimension twid = tab->tabs.width ;
1548 Dimension thgt = tw->tabs.tab_height ;
1550 /* top tab requires a little special attention; it overlaps
1551 * neighboring tabs slightly, so the background must be cleared
1552 * in the region of the overlap to partially erase those neighbors.
1553 * TODO: is this worth doing with regions instead?
1555 if( child == tw->tabs.topWidget )
1557 Display *dpy = XtDisplay((Widget)tw) ;
1558 Window win = XtWindow((Widget)tw) ;
1559 GC bggc = tw->tabs.backgroundGC ;
1560 XRectangle rects[3] ;
1563 twid += TABDELTA*2 ;
1565 AddRect(0, x,y+1,twid,TABDELTA) ;
1566 AddRect(1, x+1,y,TABDELTA,thgt) ;
1567 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1568 XFillRectangles(dpy,win,bggc, rects, 3) ;
1571 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1575 /* Draw highlight around tab that has focus */
1578 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1580 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1581 Display *dpy = XtDisplay((Widget)tw) ;
1582 Window win = XtWindow((Widget)tw) ;
1584 Position x = tab->tabs.x ;
1585 Position y = tab->tabs.y ;
1586 Dimension wid = tab->tabs.width ;
1587 Dimension hgt = tw->tabs.tab_height ;
1590 /* top tab does not have a highlight */
1592 if( child == tw->tabs.topWidget )
1596 gc = tw->tabs.backgroundGC ;
1598 else if( XtIsSensitive(child) )
1600 gc = tw->tabs.foregroundGC ;
1601 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1605 gc = tw->tabs.greyGC ;
1606 XSetForeground(dpy, gc, tab->tabs.grey) ;
1609 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1610 points[1].x = x+1 ; points[1].y = y+2 ;
1611 points[2].x = x+2 ; points[2].y = y+1 ;
1612 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1613 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1614 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1616 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1620 /* Undraw one tab interior */
1623 UndrawTab(TabsWidget tw, Widget child)
1625 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1626 Position x = tab->tabs.x ;
1627 Position y = tab->tabs.y ;
1628 Dimension twid = tab->tabs.width ;
1629 Dimension thgt = tw->tabs.tab_height ;
1630 Display *dpy = XtDisplay((Widget)tw) ;
1631 Window win = XtWindow((Widget)tw) ;
1632 GC bggc = tw->tabs.backgroundGC ;
1634 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1641 /* GEOMETRY UTILITIES */
1645 * MaxChild(): ask all children (except possibly one) their
1646 * preferred sizes, set max_cw, max_ch accordingly.
1648 * GetPreferredSizes(): ask all children their preferred sizes,
1649 * set max_cw, max_ch accordingly.
1651 * PreferredSize(): given max_cw, max_ch, return tabs widget
1652 * preferred size. Iterate with other widths in order to get
1653 * a reasonable aspect ratio.
1655 * PreferredSize2(): Given child dimensions, return Tabs
1656 * widget dimensions.
1658 * PreferredSize3(): Same, except given child dimensions plus
1663 /* Compute the width of one child's tab. Positions will be computed
1666 * height: font height + vertical_space*2 + shadowWid*2
1667 * width: string width + horizontal_space*2 + shadowWid*2
1669 * All tabs are the same height, so that is computed elsewhere.
1675 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1676 TabsWidget tw = (TabsWidget)XtParent(w) ;
1677 String lbl = tab->tabs.label != NULL ?
1678 tab->tabs.label : XtName(w) ;
1679 XFontStruct *font = tw->tabs.font ;
1680 int iw = tw->tabs.internalWidth ;
1682 tab->tabs.width = iw + SHADWID*2 ;
1683 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1685 if( tab->tabs.left_bitmap != None )
1687 tab->tabs.width += tab->tabs.lbm_width + iw ;
1688 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1689 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1692 if( lbl != NULL && font != NULL )
1694 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1695 tab->tabs.l_y = (tw->tabs.tab_height +
1696 tw->tabs.font->max_bounds.ascent -
1697 tw->tabs.font->max_bounds.descent)/2 ;
1703 /* Lay out tabs to fit in given width. Compute x,y position and
1704 * row number for each tab. Return number of rows and total height
1705 * required by all tabs. If there is only one row, add TABDELTA
1706 * height to the total. Rows are assigned bottom to top.
1708 * Tabs are indented from the edges by INDENT.
1710 * TODO: if they require more than two rows and the total height:width
1711 * ratio is more than 2:1, then try something else.
1715 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
1717 int i, row, done = 0, display_rows = 0 ;
1718 int num_children = tw->composite.num_children ;
1722 TabsConstraints tab ;
1724 /* Algorithm: loop through children, assign X positions. If a tab
1725 * would extend beyond the right edge, start a new row. After all
1726 * rows are assigned, make a second pass and assign Y positions.
1729 if( num_children > 0 )
1731 /* Loop through the tabs and see how much space they need. */
1737 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1738 if( XtIsManaged(*childP) )
1740 tab = (TabsConstraints) (*childP)->core.constraints ;
1741 w = tab->tabs.width ;
1743 if( x + w > wid ) { /* new row */
1744 if (y + tw->tabs.tab_height > hgt && !done)
1751 y += tw->tabs.tab_height ;
1756 tab->tabs.row = row ;
1759 if (!query_only && !done)
1760 tab->tabs.visible = 1;
1763 /* If there was only one row, increase the height by TABDELTA */
1764 if( ++display_rows == 1 )
1769 for(i=num_children, childP=tw->composite.children;
1770 --i >= 0 ; ++childP)
1771 if( XtIsManaged(*childP) )
1773 tab = (TabsConstraints) (*childP)->core.constraints ;
1777 y += tw->tabs.tab_height ;
1780 display_rows = row = y = 0 ;
1783 tw->tabs.tab_total = y ;
1784 tw->tabs.numRows = display_rows ;
1785 tw->tabs.realRows = row;
1788 if( reply_height != NULL )
1791 return display_rows ;
1796 /* Find max preferred child size. Returned sizes include child
1801 GetPreferredSizes(TabsWidget tw)
1803 MaxChild(tw, NULL, 0,0) ;
1808 /* Find max preferred child size. Returned sizes include child
1809 * border widths. If except is non-null, don't ask that one.
1813 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
1816 Widget *childP = tw->composite.children ;
1817 XtWidgetGeometry preferred ;
1819 for(i=tw->composite.num_children; --i >=0; ++childP)
1820 if( XtIsManaged(*childP) && *childP != except )
1822 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1823 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
1824 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
1827 tw->tabs.max_cw = cw ;
1828 tw->tabs.max_ch = ch ;
1833 /* rotate row numbers to bring current widget to bottom row,
1834 * compute y positions for all tabs
1838 TabsShuffleRows(TabsWidget tw)
1840 TabsConstraints tab ;
1842 int real_rows, display_rows ;
1844 Dimension th = tw->tabs.tab_height ;
1848 /* There must be a top widget. If not, assign one. */
1849 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1850 for(i=TabsNumChildren (tw), childP=tw->composite.children;
1853 if( XtIsManaged(*childP) ) {
1854 tw->tabs.topWidget = *childP ;
1858 if( tw->tabs.topWidget != NULL )
1860 display_rows = tw->tabs.numRows ;
1861 real_rows = tw->tabs.realRows ;
1862 assert( display_rows >= real_rows ) ;
1866 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1867 assert( tab != NULL ) ;
1869 /* How far to move top row. The selected tab must be on
1870 the bottom row of the *visible* rows. */
1871 move = (real_rows + 1 - display_rows) - tab->tabs.row ;
1873 move = real_rows - move;
1874 bottom = tw->tabs.tab_total - th ;
1876 for(i=tw->composite.num_children, childP=tw->composite.children;
1879 if( XtIsManaged(*childP) )
1881 tab = (TabsConstraints) (*childP)->core.constraints ;
1882 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
1883 tab->tabs.y = bottom - tab->tabs.row * th ;
1884 tab->tabs.visible = (tab->tabs.row < display_rows);
1891 /* Find preferred size. Ask children, find size of largest,
1892 * add room for tabs & return. This can get a little involved,
1893 * as we don't want to have too many rows of tabs; we may widen
1894 * the widget to reduce # of rows.
1896 * This function requires that max_cw, max_ch already be set.
1901 Dimension *reply_width, /* total widget size */
1902 Dimension *reply_height,
1903 Dimension *reply_cw, /* child widget size */
1904 Dimension *reply_ch)
1906 Dimension cw,ch ; /* child width, height */
1908 Dimension rwid,rhgt ;
1911 wid = cw = tw->tabs.max_cw ;
1912 hgt = ch = tw->tabs.max_ch ;
1914 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1916 /* Check for absurd results (more than 2 rows, high aspect
1917 * ratio). Try wider size if needed.
1918 * TODO: make sure this terminates.
1921 if( nrow > 2 && rhgt > rwid )
1926 /* step 1: start doubling size until it's too big */
1929 wid = Max(wid*2, wid+20) ;
1930 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1931 } while( nrow > 2 && rhgt > rwid ) ;
1934 /* step 2: use Newton's method to find ideal size. Stop within
1937 while( --maxloop > 0 && w1 > w0 + 8 )
1940 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1941 if( nrow > 2 && rhgt > rwid )
1949 *reply_width = rwid ;
1950 *reply_height = rhgt ;
1951 if( reply_cw != NULL ) *reply_cw = cw ;
1952 if( reply_ch != NULL ) *reply_ch = ch ;
1957 /* Find preferred size, given size of children. */
1962 int cw, /* child width, height */
1964 Dimension *reply_width, /* total widget size */
1965 Dimension *reply_height)
1967 Dimension s = SHADWID ;
1969 /* make room for shadow frame */
1973 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1977 /* Find preferred size, given size of children+shadow. */
1982 int wid, /* child width, height */
1984 Dimension *reply_width, /* total widget size */
1985 Dimension *reply_height)
1987 Dimension th ; /* space used by tabs */
1990 if( tw->composite.num_children > 0 )
1991 nrows = TabLayout(tw, wid, hgt, &th, True) ;
1997 *reply_width = Max(wid, MIN_WID) ;
1998 *reply_height = Max(th+hgt, MIN_HGT) ;
2005 MakeSizeRequest(TabsWidget tw)
2007 Widget w = (Widget)tw ;
2008 XtWidgetGeometry request, reply ;
2009 XtGeometryResult result ;
2012 request.request_mode = CWWidth | CWHeight ;
2013 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
2015 if( request.width == tw->core.width &&
2016 request.height == tw->core.height )
2019 result = XtMakeGeometryRequest(w, &request, &reply) ;
2021 if( result == XtGeometryAlmost )
2023 /* Bugger. Didn't get what we want, but were offered a
2024 * compromise. If the width was too small, recompute
2025 * based on the too-small width and try again.
2026 * If the height was too small, make a wild-ass guess
2027 * at a wider width and try again.
2030 if( reply.width < request.width && reply.height >= request.height )
2032 Dimension s = SHADWID ;
2034 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
2035 result = XtMakeGeometryRequest(w, &request, &reply) ;
2036 if( result == XtGeometryAlmost )
2037 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2041 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2047 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2053 if( tab->tabs.left_bitmap == None ||
2054 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2055 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2056 &bw, &tab->tabs.lbm_depth) )
2057 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2063 /* Code copied & modified from Gcs.c. This version has dynamic
2068 TabsAllocFgGC(TabsWidget tw)
2070 Widget w = (Widget) tw;
2073 values.background = tw->core.background_pixel ;
2074 values.font = tw->tabs.font->fid ;
2075 values.line_style = LineOnOffDash ;
2076 values.line_style = LineSolid ;
2078 tw->tabs.foregroundGC =
2079 XtAllocateGC(w, w->core.depth,
2080 GCBackground|GCFont|GCLineStyle, &values,
2082 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2083 GCDashList|GCArcMode) ;
2087 TabsAllocGreyGC(TabsWidget tw)
2089 Widget w = (Widget) tw;
2092 values.background = tw->core.background_pixel ;
2093 values.font = tw->tabs.font->fid ;
2095 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2097 values.fill_style = FillStippled ;
2099 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2102 XtAllocateGC(w, w->core.depth,
2103 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2105 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2106 GCDashList|GCArcMode) ;
2112 XtAllocateGC(w, w->core.depth,
2115 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2116 GCDashList|GCArcMode) ;