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 */
24 * Tabs.c - Index Tabs composite widget
26 * Author: Edward A. Falk
27 * falk@falconer.vip.best.com
32 * Overall layout of this widget is as follows:
34 * ________ ,---------. _________
35 * | label || Label || Label | \ tabs
36 * |________|| ||_________| /
37 * |+----------------------------+| \
39 * || child widget window || > frame
40 * |+----------------------------+| |
41 * +------------------------------+ /
43 * The height of the tabs includes the shadow width, top and bottom
44 * margins, and the height of the text.
46 * The height of the frame includes the top and bottom shadow width and the
47 * size of the child widget window.
49 * The tabs overlap the frame and each other vertically by the shadow
50 * width, so that when the topmost tab is drawn, it obliterates part of
55 * TODO: min child height = tab height
62 #include <X11/IntrinsicP.h>
63 #include <X11/StringDefs.h>
64 #include "../src/xmu.h"
70 #define INDENT 3 /* tabs indented from edge by this much */
71 #define SPACING 0 /* distance between tabs */
72 #define SHADWID 1 /* default shadow width */
73 #define TABDELTA 2 /* top tab grows this many pixels */
74 #define TABLDELTA 2 /* top tab label offset this many pixels */
77 /****************************************************************
81 ****************************************************************/
83 static char defaultTranslations[] = "\
85 <FocusIn>: highlight() \n\
86 <FocusOut>: unhighlight() \n\
87 <Key>Page_Up: page(up) \n\
88 <Key>KP_Page_Up: page(up) \n\
89 <Key>Prior: page(up) \n\
90 <Key>KP_Prior: page(up) \n\
91 <Key>Page_Down: page(down) \n\
92 <Key>KP_Page_Down: page(down) \n\
93 <Key>Next: page(down) \n\
94 <Key>KP_Next: page(down) \n\
95 <Key>Home: page(home) \n\
96 <Key>KP_Home: page(home) \n\
97 <Key>End: page(end) \n\
98 <Key>KP_End: page(end) \n\
99 <Key>Up: highlight(up) \n\
100 <Key>KP_Up: highlight(up) \n\
101 <Key>Down: highlight(down) \n\
102 <Key>KP_Down: highlight(down) \n\
103 <Key> : page(select) \n\
106 static char accelTable[] = " #augment\n\
107 <Key>Page_Up: page(up) \n\
108 <Key>KP_Page_Up: page(up) \n\
109 <Key>Prior: page(up) \n\
110 <Key>KP_Prior: page(up) \n\
111 <Key>Page_Down: page(down) \n\
112 <Key>KP_Page_Down: page(down) \n\
113 <Key>Next: page(down) \n\
114 <Key>KP_Next: page(down) \n\
115 <Key>Home: page(home) \n\
116 <Key>KP_Home: page(home) \n\
117 <Key>End: page(end) \n\
118 <Key>KP_End: page(end) \n\
119 <Key>Up: highlight(up) \n\
120 <Key>KP_Up: highlight(up) \n\
121 <Key>Down: highlight(down) \n\
122 <Key>KP_Down: highlight(down) \n\
123 <Key> : page(select) \n\
125 static XtAccelerators defaultAccelerators ;
127 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
128 static XtResource resources[] = {
130 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
131 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
132 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
133 offset(font), XtRString, (XtPointer) XtDefaultFont},
134 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
135 offset(internalWidth), XtRImmediate, (XtPointer)4 },
136 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
137 offset(internalHeight), XtRImmediate, (XtPointer)4 },
138 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
139 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
140 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
141 offset(topWidget), XtRImmediate, NULL},
142 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
143 offset(callbacks), XtRCallback, NULL},
144 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
145 offset(popdownCallbacks), XtRCallback, NULL},
146 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
147 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
148 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
149 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
150 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
151 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
152 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
153 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
154 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
155 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
161 /* constraint resources */
163 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
164 static XtResource tabsConstraintResources[] = {
165 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
166 offset(label), XtRString, NULL},
167 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
168 offset(left_bitmap), XtRImmediate, None},
169 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
170 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
171 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
172 offset(resizable), XtRImmediate, (XtPointer) True},
179 #if !NeedFunctionPrototypes
181 /* FORWARD REFERENCES: */
183 /* member functions */
185 static void TabsClassInit();
186 static void TabsInit();
187 static void TabsResize();
188 static void TabsExpose();
189 static void TabsDestroy();
190 static void TabsRealize();
191 static Boolean TabsSetValues();
192 static Boolean TabsAcceptFocus();
193 static XtGeometryResult TabsQueryGeometry();
194 static XtGeometryResult TabsGeometryManager();
195 static void TabsChangeManaged();
196 static void TabsConstraintInitialize() ;
197 static Boolean TabsConstraintSetValues() ;
201 static void TabsSelect() ;
202 static void TabsPage() ;
203 static void TabsHighlight() ;
204 static void TabsUnhighlight() ;
206 /* internal privates */
208 static void TabsAllocGCs() ; /* get rendering GCs */
209 static void TabsFreeGCs() ; /* return rendering GCs */
210 static void DrawTabs() ; /* draw all tabs */
211 static void DrawTab() ; /* draw one index tab */
212 static void DrawFrame() ; /* draw frame around contents */
213 static void DrawTrim() ; /* draw trim around a tab */
214 static void DrawBorder() ; /* draw border */
215 static void DrawHighlight() ; /* draw highlight */
216 static void UndrawTab() ; /* undraw interior of a tab */
217 static void TabWidth() ; /* recompute tab size */
218 static void GetPreferredSizes() ; /* query all children for their sizes */
219 static void MaxChild() ; /* find max preferred child size */
220 static int PreferredSize() ; /* compute preferred size */
221 static int PreferredSize2() ; /* compute preferred size */
222 static int PreferredSize3() ; /* compute preferred size */
223 static void MakeSizeRequest() ; /* try to change size */
224 static void getBitmapInfo() ;
225 static int TabLayout() ; /* lay out tabs */
226 static void TabsShuffleRows() ; /* bring current tab to bottom row */
228 static void TabsAllocFgGC() ;
229 static void TabsAllocGreyGC() ;
233 static void TabsClassInit(void) ;
234 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
235 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
236 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
237 static void TabsDestroy( Widget w) ;
238 static void TabsResize( Widget w) ;
239 static void TabsExpose( Widget w, XEvent *event, Region region) ;
240 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
241 static Boolean TabsAcceptFocus(Widget, Time *);
242 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
243 ArgList, Cardinal *) ;
244 static XtGeometryResult TabsQueryGeometry(Widget,
245 XtWidgetGeometry *, XtWidgetGeometry *) ;
246 static XtGeometryResult TabsGeometryManager(Widget,
247 XtWidgetGeometry *, XtWidgetGeometry *) ;
248 static void TabsChangeManaged( Widget w) ;
250 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
251 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
252 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
253 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
255 static void DrawTabs( TabsWidget tw, Bool labels) ;
256 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
257 static void DrawFrame( TabsWidget tw) ;
258 static void DrawTrim( TabsWidget, int x, int y,
259 int wid, int hgt, Bool bottom, Bool undraw) ;
260 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
261 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
262 static void UndrawTab( TabsWidget tw, Widget child) ;
264 static void TabWidth( Widget w) ;
265 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
267 static void GetPreferredSizes(TabsWidget) ;
268 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
269 static void TabsShuffleRows( TabsWidget tw) ;
270 static int PreferredSize( TabsWidget,
271 Dimension *reply_width, Dimension *reply_height,
272 Dimension *reply_cw, Dimension *reply_ch) ;
273 static int PreferredSize2( TabsWidget, int cw, int ch,
274 Dimension *rw, Dimension *rh) ;
275 static int PreferredSize3( TabsWidget, int wid, int hgt,
276 Dimension *rw, Dimension *rh) ;
277 static void MakeSizeRequest(TabsWidget) ;
279 static void TabsAllocGCs(TabsWidget) ;
280 static void TabsFreeGCs(TabsWidget) ;
281 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
282 static void TabsAllocFgGC( TabsWidget tw) ;
283 static void TabsAllocGreyGC( TabsWidget tw) ;
287 #define AddRect(i,xx,yy,w,h) \
288 do{rects[(i)].x=(xx); rects[i].y=(yy); \
289 rects[i].width=(w); rects[i].height=(h);}while(0)
291 static XtActionsRec actionsList[] =
293 {"select", TabsSelect},
295 {"highlight", TabsHighlight},
296 {"unhighlight", TabsUnhighlight},
300 /****************************************************************
302 * Full class record constant
304 ****************************************************************/
307 #define SuperClass (&constraintClassRec)
309 #define SuperClass (&xmManagerClassRec)
312 TabsClassRec tabsClassRec = {
314 /* core_class fields */
315 /* superclass */ (WidgetClass) SuperClass,
316 /* class_name */ "Tabs",
317 /* widget_size */ sizeof(TabsRec),
318 /* class_initialize */ TabsClassInit,
319 /* class_part_init */ NULL, /* TODO? */
320 /* class_inited */ FALSE,
321 /* initialize */ TabsInit,
322 /* initialize_hook */ NULL,
323 /* realize */ TabsRealize,
324 /* actions */ actionsList,
325 /* num_actions */ XtNumber(actionsList),
326 /* resources */ resources,
327 /* num_resources */ XtNumber(resources),
328 /* xrm_class */ NULLQUARK,
329 /* compress_motion */ TRUE,
330 #if XtSpecificationRelease < 6
331 /* compress_exposure */ XtExposeCompressMaximal,
333 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
335 /* compress_enterleave*/ TRUE,
336 /* visible_interest */ TRUE,
337 /* destroy */ TabsDestroy,
338 /* resize */ TabsResize,
339 /* expose */ TabsExpose,
340 /* set_values */ TabsSetValues,
341 /* set_values_hook */ NULL,
342 /* set_values_almost */ XtInheritSetValuesAlmost,
343 /* get_values_hook */ NULL,
344 /* accept_focus */ TabsAcceptFocus,
345 /* version */ XtVersion,
346 /* callback_private */ NULL,
347 /* tm_table */ defaultTranslations,
348 /* query_geometry */ TabsQueryGeometry,
349 /* display_accelerator*/ XtInheritDisplayAccelerator,
353 /* composite_class fields */
354 /* geometry_manager */ TabsGeometryManager,
355 /* change_managed */ TabsChangeManaged,
356 /* insert_child */ XtInheritInsertChild, /* TODO? */
357 /* delete_child */ XtInheritDeleteChild, /* TODO? */
361 /* constraint_class fields */
362 /* subresources */ tabsConstraintResources,
363 /* subresource_count */ XtNumber(tabsConstraintResources),
364 /* constraint_size */ sizeof(TabsConstraintsRec),
365 /* initialize */ TabsConstraintInitialize,
367 /* set_values */ TabsConstraintSetValues,
368 /* extension */ NULL,
371 /* Manager Class fields */
373 /* translations */ NULL,
374 /* syn_resources */ NULL,
375 /* num_syn_resources */ 0,
376 /* syn_constraint_resources */ NULL,
377 /* num_syn_constraint_resources */ 0,
378 /* parent_process */ XmInheritParentProcess,
383 /* Tabs class fields */
384 /* extension */ NULL,
388 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
395 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
398 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
407 /****************************************************************
411 ****************************************************************/
416 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
417 /* TODO: register converter for labels? */
422 /* Init a newly created tabs widget. Compute height of tabs
423 * and optionally compute size of widget. */
428 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
430 TabsWidget newTw = (TabsWidget)new;
432 newTw->tabs.numRows = 0 ;
433 newTw->tabs.displayChildren = 0;
435 GetPreferredSizes(newTw) ;
437 /* height is easy, it's the same for all tabs:
438 * TODO: font height + height of tallest bitmap.
440 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
442 if( newTw->tabs.font != NULL )
443 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
444 newTw->tabs.font->max_bounds.descent ;
446 /* GC allocation is deferred until XtRealize() */
448 /* if size not explicitly set, set it to our preferred size now. */
450 if( request->core.width == 0 || request->core.height == 0 )
453 PreferredSize(newTw, &w, &h, NULL,NULL) ;
454 if( request->core.width == 0 ) new->core.width = w ;
455 if( request->core.height == 0 ) new->core.height = h ;
456 XtClass(new)->core_class.resize(new) ;
459 /* defer GC allocation, etc., until Realize() time. */
460 newTw->tabs.foregroundGC =
461 newTw->tabs.backgroundGC =
464 newTw->tabs.botGC = None ;
466 newTw->tabs.grey50 = None ;
468 newTw->tabs.needs_layout = False ;
470 newTw->tabs.hilight = NULL ;
473 newTw->manager.navigation_type = XmTAB_GROUP ;
474 newTw->manager.traversal_on = True ;
479 /* Init the constraint part of a new tab child. Compute the
484 TabsConstraintInitialize(Widget request, Widget new,
485 ArgList args, Cardinal *num_args)
487 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
488 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
490 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
496 /* Called when tabs widget first realized. Create the window
497 * and allocate the GCs
501 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
503 TabsWidget tw = (TabsWidget) w;
505 attributes->bit_gravity = NorthWestGravity;
506 *valueMask |= CWBitGravity;
508 SuperClass->core_class.realize(w, valueMask, attributes);
516 TabsDestroy(Widget w)
518 TabsFreeGCs((TabsWidget)w) ;
522 /* Parent has resized us. This will require that the tabs be
529 TabsWidget tw = (TabsWidget) w;
531 int num_children = tw->composite.num_children ;
533 TabsConstraints tab ;
536 /* Our size has now been dictated by the parent. Lay out the
537 * tabs, lay out the frame, lay out the children. Remember
538 * that the tabs overlap each other and the frame by shadowWidth.
539 * Also, the top tab is larger than the others, so if there's only
540 * one row, the widget must be made taller to accommodate this.
542 * Once the tabs are laid out, if there is more than one
543 * row, we may need to shuffle the rows to bring the top tab
547 tw->tabs.needs_layout = False ;
549 if( num_children > 0 && tw->composite.children != NULL )
551 /* Loop through the tabs and assign rows & x positions */
552 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
553 num_children = tw->tabs.displayChildren;
555 /* assign a top widget, bring it to bottom row. */
556 TabsShuffleRows(tw) ;
558 /* now assign child positions & sizes. Positions are all the
559 * same: just inside the frame. Sizes are also all the same.
562 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
563 tw->tabs.child_height = ch =
564 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
567 for(i=0, childP=tw->composite.children;
570 if( XtIsManaged(*childP) )
572 tab = (TabsConstraints) (*childP)->core.constraints ;
573 bw = (*childP)->core.border_width ;
574 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
575 cw-bw*2,ch-bw*2, bw) ;
577 if( XtIsRealized(w) ) {
578 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
579 /* should not be necessary to explicitly repaint after a
580 * resize, but XEmacs folks tell me it is.
582 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
589 /* Redraw entire Tabs widget */
593 TabsExpose(Widget w, XEvent *event, Region region)
595 TabsWidget tw = (TabsWidget) w;
597 if( tw->tabs.needs_layout )
598 XtClass(w)->core_class.resize(w) ;
604 /* Called when any Tabs widget resources are changed. */
608 TabsSetValues(Widget current, Widget request, Widget new,
609 ArgList args, Cardinal *num_args)
611 TabsWidget curtw = (TabsWidget) current ;
612 TabsWidget tw = (TabsWidget) new ;
613 Boolean needRedraw = False ;
618 if( tw->tabs.font != curtw->tabs.font ||
619 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
620 tw->tabs.internalHeight != curtw->tabs.internalHeight )
622 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
624 if( tw->tabs.font != NULL )
625 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
626 tw->tabs.font->max_bounds.descent ;
628 /* Tab size has changed. Resize all tabs and request a new size */
629 for(i=0, childP=tw->composite.children;
630 i < tw->composite.num_children;
632 if( XtIsManaged(*childP) )
634 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
636 tw->tabs.needs_layout = True ;
639 /* TODO: if any color changes, need to recompute GCs and redraw */
641 if( tw->core.background_pixel != curtw->core.background_pixel ||
642 tw->core.background_pixmap != curtw->core.background_pixmap ||
643 tw->tabs.font != curtw->tabs.font )
644 if( XtIsRealized(new) )
651 if( tw->core.sensitive != curtw->core.sensitive )
654 /* If top widget changes, need to change stacking order, redraw tabs.
655 * Window system will handle the redraws.
658 if( tw->tabs.topWidget != curtw->tabs.topWidget )
660 if( XtIsRealized(tw->tabs.topWidget) )
662 Widget w = tw->tabs.topWidget ;
663 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
665 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
667 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
668 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
671 if( tab->tabs.row != tw->tabs.numRows-1 )
672 TabsShuffleRows(tw) ;
677 tw->tabs.needs_layout = True ;
684 /* Called when any child constraint resources change. */
688 TabsConstraintSetValues(Widget current, Widget request, Widget new,
689 ArgList args, Cardinal *num_args)
691 TabsWidget tw = (TabsWidget) XtParent(new) ;
692 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
693 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
696 /* if label changes, need to re-layout the entire widget */
697 /* if foreground changes, need to redraw tab label */
699 /* TODO: only need resize of new bitmap has different dimensions
703 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
704 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
707 tw->tabs.needs_layout = True ;
709 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
710 getBitmapInfo(tw, tab) ;
712 /* If there are no subclass ConstraintSetValues procedures remaining
713 * to be invoked, and if the preferred size has changed, ask
716 if( XtClass((Widget)tw) == tabsWidgetClass )
717 MakeSizeRequest(tw) ;
721 /* The child widget itself never needs a redisplay, but the parent
725 if( XtIsRealized(new) )
727 if( tw->tabs.needs_layout ) {
728 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
729 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
732 else if( tab->tabs.foreground != ctab->tabs.foreground )
733 DrawTab(tw, new, True) ;
741 TabsAcceptFocus(Widget w, Time *t)
743 if( !w->core.being_destroyed && XtIsRealized(w) &&
744 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
747 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
748 XtSetKeyboardFocus(p,w) ;
758 * Return preferred size. Happily accept anything >= our preferred size.
759 * (TODO: is that the right thing to do? Should we always return "almost"
760 * if offered more than we need?)
763 static XtGeometryResult
764 TabsQueryGeometry(Widget w,
765 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
767 register TabsWidget tw = (TabsWidget)w ;
768 XtGeometryMask mode = intended->request_mode ;
770 preferred->request_mode = CWWidth | CWHeight ;
771 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
773 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
774 (!(mode & CWHeight) || intended->height == w->core.height) )
775 return XtGeometryNo ;
777 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
778 (!(mode & CWHeight) || intended->height >= preferred->height) )
779 return XtGeometryYes;
781 return XtGeometryAlmost;
787 * Geometry Manager; called when a child wants to be resized.
790 static XtGeometryResult
791 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
793 TabsWidget tw = (TabsWidget) XtParent(w);
794 Dimension s = SHADWID ;
795 TabsConstraints tab = (TabsConstraints)w->core.constraints;
796 XtGeometryResult result ;
799 /* Position request always denied */
801 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
802 ((req->request_mode & CWY) && req->y != w->core.y) ||
803 !tab->tabs.resizable )
804 return XtGeometryNo ;
806 /* Make all three fields in the request valid */
807 if( !(req->request_mode & CWWidth) )
808 req->width = w->core.width;
809 if( !(req->request_mode & CWHeight) )
810 req->height = w->core.height;
811 if( !(req->request_mode & CWBorderWidth) )
812 req->border_width = w->core.border_width;
814 if( req->width == w->core.width &&
815 req->height == w->core.height &&
816 req->border_width == w->core.border_width )
817 return XtGeometryNo ;
819 rw = req->width + 2 * req->border_width ;
820 rh = req->height + 2 * req->border_width ;
822 /* find out how big the children want to be now */
823 MaxChild(tw, w, rw, rh) ;
826 /* Size changes must see if the new size can be accommodated.
827 * The Tabs widget keeps all of its children the same
828 * size. A request to shrink will be accepted only if the
829 * new size is still big enough for all other children. A
830 * request to shrink that is not big enough for all children
831 * returns an "almost" response with the new proposed size
832 * or a "no" response if unable to shrink at all.
834 * A request to grow will be accepted only if the Tabs parent can
835 * grow to accommodate.
838 * We could get fancy here and re-arrange the tabs if it is
839 * necessary to compromise with the parent, but we'll save that
843 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
845 Dimension cw,ch ; /* children's preferred size */
846 Dimension aw,ah ; /* available size we can give child */
847 Dimension th ; /* space used by tabs */
848 Dimension wid,hgt ; /* Tabs widget size */
850 cw = tw->tabs.max_cw ;
851 ch = tw->tabs.max_ch ;
853 /* find out what *my* resulting preferred size would be */
855 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
857 /* Would my size change? If so, ask to be resized. */
859 if( wid != tw->core.width || hgt != tw->core.height )
861 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
862 XtWidgetGeometry myrequest, myreply ;
864 myrequest.width = wid ;
865 myrequest.height = hgt ;
866 myrequest.request_mode = CWWidth | CWHeight ;
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=tw->tabs.displayChildren; --i >= 0; ++childP)
936 if( XtIsManaged(*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=tw->tabs.displayChildren; --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 < tw->tabs.displayChildren;
1071 if( XtIsManaged(*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 = tw->tabs.displayChildren ;
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 = tw->tabs.displayChildren ;
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=tw->tabs.displayChildren, childP=tw->composite.children;
1398 --j >= 0; ++childP )
1399 if( XtIsManaged(*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 ;
1499 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
1500 tw->core.width, ch+2*s, s, topgc, botgc) ;
1504 /* draw trim around a tab or underneath a row of tabs */
1507 DrawTrim(TabsWidget tw, /* widget */
1508 int x, /* upper-left corner */
1510 int wid, /* total size */
1512 Bool bottom, /* draw bottom? */
1513 Bool undraw) /* undraw all */
1515 Display *dpy = XtDisplay((Widget)tw) ;
1516 Window win = XtWindow((Widget)tw) ;
1517 GC bggc = tw->tabs.backgroundGC ;
1518 GC topgc = undraw ? bggc : tw->tabs.topGC ;
1519 GC botgc = undraw ? bggc : tw->tabs.botGC ;
1521 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
1522 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
1523 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
1524 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
1525 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
1526 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
1530 /* Draw one tab border. */
1533 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
1535 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1536 Position x = tab->tabs.x ;
1537 Position y = tab->tabs.y ;
1538 Dimension twid = tab->tabs.width ;
1539 Dimension thgt = tw->tabs.tab_height ;
1541 /* top tab requires a little special attention; it overlaps
1542 * neighboring tabs slightly, so the background must be cleared
1543 * in the region of the overlap to partially erase those neighbors.
1544 * TODO: is this worth doing with regions instead?
1546 if( child == tw->tabs.topWidget )
1548 Display *dpy = XtDisplay((Widget)tw) ;
1549 Window win = XtWindow((Widget)tw) ;
1550 GC bggc = tw->tabs.backgroundGC ;
1551 XRectangle rects[3] ;
1554 twid += TABDELTA*2 ;
1556 AddRect(0, x,y+1,twid,TABDELTA) ;
1557 AddRect(1, x+1,y,TABDELTA,thgt) ;
1558 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
1559 XFillRectangles(dpy,win,bggc, rects, 3) ;
1562 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
1566 /* Draw highlight around tab that has focus */
1569 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
1571 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1572 Display *dpy = XtDisplay((Widget)tw) ;
1573 Window win = XtWindow((Widget)tw) ;
1575 Position x = tab->tabs.x ;
1576 Position y = tab->tabs.y ;
1577 Dimension wid = tab->tabs.width ;
1578 Dimension hgt = tw->tabs.tab_height ;
1581 /* top tab does not have a highlight */
1583 if( child == tw->tabs.topWidget )
1587 gc = tw->tabs.backgroundGC ;
1589 else if( XtIsSensitive(child) )
1591 gc = tw->tabs.foregroundGC ;
1592 XSetForeground(dpy, gc, tab->tabs.foreground) ;
1596 gc = tw->tabs.greyGC ;
1597 XSetForeground(dpy, gc, tab->tabs.grey) ;
1600 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
1601 points[1].x = x+1 ; points[1].y = y+2 ;
1602 points[2].x = x+2 ; points[2].y = y+1 ;
1603 points[3].x = x+wid-4 ; points[3].y = y+1 ;
1604 points[4].x = x+wid-3 ; points[4].y = y+2 ;
1605 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
1607 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
1611 /* Undraw one tab interior */
1614 UndrawTab(TabsWidget tw, Widget child)
1616 TabsConstraints tab = (TabsConstraints)child->core.constraints;
1617 Position x = tab->tabs.x ;
1618 Position y = tab->tabs.y ;
1619 Dimension twid = tab->tabs.width ;
1620 Dimension thgt = tw->tabs.tab_height ;
1621 Display *dpy = XtDisplay((Widget)tw) ;
1622 Window win = XtWindow((Widget)tw) ;
1623 GC bggc = tw->tabs.backgroundGC ;
1625 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
1632 /* GEOMETRY UTILITIES */
1636 * MaxChild(): ask all children (except possibly one) their
1637 * preferred sizes, set max_cw, max_ch accordingly.
1639 * GetPreferredSizes(): ask all children their preferred sizes,
1640 * set max_cw, max_ch accordingly.
1642 * PreferredSize(): given max_cw, max_ch, return tabs widget
1643 * preferred size. Iterate with other widths in order to get
1644 * a reasonable aspect ratio.
1646 * PreferredSize2(): Given child dimensions, return Tabs
1647 * widget dimensions.
1649 * PreferredSize3(): Same, except given child dimensions plus
1654 /* Compute the width of one child's tab. Positions will be computed
1657 * height: font height + vertical_space*2 + shadowWid*2
1658 * width: string width + horizontal_space*2 + shadowWid*2
1660 * All tabs are the same height, so that is computed elsewhere.
1666 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
1667 TabsWidget tw = (TabsWidget)XtParent(w) ;
1668 String lbl = tab->tabs.label != NULL ?
1669 tab->tabs.label : XtName(w) ;
1670 XFontStruct *font = tw->tabs.font ;
1671 int iw = tw->tabs.internalWidth ;
1673 tab->tabs.width = iw + SHADWID*2 ;
1674 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
1676 if( tab->tabs.left_bitmap != None )
1678 tab->tabs.width += tab->tabs.lbm_width + iw ;
1679 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
1680 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
1683 if( lbl != NULL && font != NULL )
1685 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
1686 tab->tabs.l_y = (tw->tabs.tab_height +
1687 tw->tabs.font->max_bounds.ascent -
1688 tw->tabs.font->max_bounds.descent)/2 ;
1694 /* Lay out tabs to fit in given width. Compute x,y position and
1695 * row number for each tab. Return number of rows and total height
1696 * required by all tabs. If there is only one row, add TABDELTA
1697 * height to the total. Rows are assigned bottom to top.
1699 * Tabs are indented from the edges by INDENT.
1701 * TODO: if they require more than two rows and the total height:width
1702 * ratio is more than 2:1, then try something else.
1706 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
1709 int num_children = tw->composite.num_children ;
1713 TabsConstraints tab ;
1716 tw->tabs.displayChildren = 0;
1718 /* Algorithm: loop through children, assign X positions. If a tab
1719 * would extend beyond the right edge, start a new row. After all
1720 * rows are assigned, make a second pass and assign Y positions.
1723 if( num_children > 0 )
1725 /* Loop through the tabs and see how much space they need. */
1731 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
1732 if( XtIsManaged(*childP) )
1734 tab = (TabsConstraints) (*childP)->core.constraints ;
1735 w = tab->tabs.width ;
1736 if( x + w > wid ) { /* new row */
1737 if (y + tw->tabs.tab_height > hgt)
1741 y += tw->tabs.tab_height ;
1746 tab->tabs.row = row ;
1750 tw->tabs.displayChildren++;
1752 /* If there was only one row, increase the height by TABDELTA */
1757 for(i=num_children, childP=tw->composite.children;
1758 --i >= 0 ; ++childP)
1759 if( XtIsManaged(*childP) )
1761 tab = (TabsConstraints) (*childP)->core.constraints ;
1765 y += tw->tabs.tab_height ;
1771 tw->tabs.tab_total = y ;
1772 tw->tabs.numRows = row ;
1775 if( reply_height != NULL )
1783 /* Find max preferred child size. Returned sizes include child
1788 GetPreferredSizes(TabsWidget tw)
1790 MaxChild(tw, NULL, 0,0) ;
1795 /* Find max preferred child size. Returned sizes include child
1796 * border widths. If except is non-null, don't ask that one.
1800 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
1803 Widget *childP = tw->composite.children ;
1804 XtWidgetGeometry preferred ;
1806 for(i=tw->composite.num_children; --i >=0; ++childP)
1807 if( XtIsManaged(*childP) && *childP != except )
1809 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
1810 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
1811 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
1814 tw->tabs.max_cw = cw ;
1815 tw->tabs.max_ch = ch ;
1820 /* rotate row numbers to bring current widget to bottom row,
1821 * compute y positions for all tabs
1825 TabsShuffleRows(TabsWidget tw)
1827 TabsConstraints tab ;
1831 Dimension th = tw->tabs.tab_height ;
1835 /* There must be a top widget. If not, assign one. */
1836 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
1837 for(i=tw->composite.num_children, childP=tw->composite.children;
1840 if( XtIsManaged(*childP) ) {
1841 tw->tabs.topWidget = *childP ;
1845 if( tw->tabs.topWidget != NULL )
1847 nrows = tw->tabs.numRows ;
1848 assert( nrows > 0 ) ;
1852 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
1853 assert( tab != NULL ) ;
1855 /* how far to move top row */
1856 move = nrows - tab->tabs.row ;
1857 bottom = tw->tabs.tab_total - th ;
1859 for(i=tw->tabs.displayChildren, childP=tw->composite.children;
1862 if( XtIsManaged(*childP) )
1864 tab = (TabsConstraints) (*childP)->core.constraints ;
1865 tab->tabs.row = (tab->tabs.row + move) % nrows ;
1866 tab->tabs.y = bottom - tab->tabs.row * th ;
1873 /* Find preferred size. Ask children, find size of largest,
1874 * add room for tabs & return. This can get a little involved,
1875 * as we don't want to have too many rows of tabs; we may widen
1876 * the widget to reduce # of rows.
1878 * This function requires that max_cw, max_ch already be set.
1884 Dimension *reply_width, /* total widget size */
1885 Dimension *reply_height,
1886 Dimension *reply_cw, /* child widget size */
1887 Dimension *reply_ch)
1889 Dimension cw,ch ; /* child width, height */
1891 Dimension rwid,rhgt ;
1894 wid = cw = tw->tabs.max_cw ;
1895 hgt = ch = tw->tabs.max_ch ;
1897 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
1899 /* Check for absurd results (more than 2 rows, high aspect
1900 * ratio). Try wider size if needed.
1901 * TODO: make sure this terminates.
1904 if( nrow > 2 && rhgt > rwid )
1909 /* step 1: start doubling size until it's too big */
1912 wid = Max(wid*2, wid+20) ;
1913 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1914 } while( nrow > 2 && rhgt > rwid ) ;
1917 /* step 2: use Newton's method to find ideal size. Stop within
1920 while( --maxloop > 0 && w1 > w0 + 8 )
1923 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
1924 if( nrow > 2 && rhgt > rwid )
1932 *reply_width = rwid ;
1933 *reply_height = rhgt ;
1934 if( reply_cw != NULL ) *reply_cw = cw ;
1935 if( reply_ch != NULL ) *reply_ch = ch ;
1940 /* Find preferred size, given size of children. */
1945 int cw, /* child width, height */
1947 Dimension *reply_width, /* total widget size */
1948 Dimension *reply_height)
1950 Dimension s = SHADWID ;
1952 /* make room for shadow frame */
1956 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
1960 /* Find preferred size, given size of children+shadow. */
1965 int wid, /* child width, height */
1967 Dimension *reply_width, /* total widget size */
1968 Dimension *reply_height)
1970 Dimension th ; /* space used by tabs */
1973 if( tw->composite.num_children > 0 )
1974 nrows = TabLayout(tw, wid, hgt, &th, True) ;
1980 *reply_width = Max(wid, MIN_WID) ;
1981 *reply_height = Max(th+hgt, MIN_HGT) ;
1988 MakeSizeRequest(TabsWidget tw)
1990 Widget w = (Widget)tw ;
1991 XtWidgetGeometry request, reply ;
1992 XtGeometryResult result ;
1995 request.request_mode = CWWidth | CWHeight ;
1996 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
1998 if( request.width == tw->core.width &&
1999 request.height == tw->core.height )
2002 result = XtMakeGeometryRequest(w, &request, &reply) ;
2004 if( result == XtGeometryAlmost )
2006 /* Bugger. Didn't get what we want, but were offered a
2007 * compromise. If the width was too small, recompute
2008 * based on the too-small width and try again.
2009 * If the height was too small, make a wild-ass guess
2010 * at a wider width and try again.
2013 if( reply.width < request.width && reply.height >= request.height )
2015 Dimension s = SHADWID ;
2017 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
2018 result = XtMakeGeometryRequest(w, &request, &reply) ;
2019 if( result == XtGeometryAlmost )
2020 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2024 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
2030 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
2036 if( tab->tabs.left_bitmap == None ||
2037 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
2038 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
2039 &bw, &tab->tabs.lbm_depth) )
2040 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
2046 /* Code copied & modified from Gcs.c. This version has dynamic
2051 TabsAllocFgGC(TabsWidget tw)
2053 Widget w = (Widget) tw;
2056 values.background = tw->core.background_pixel ;
2057 values.font = tw->tabs.font->fid ;
2058 values.line_style = LineOnOffDash ;
2059 values.line_style = LineSolid ;
2061 tw->tabs.foregroundGC =
2062 XtAllocateGC(w, w->core.depth,
2063 GCBackground|GCFont|GCLineStyle, &values,
2065 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2066 GCDashList|GCArcMode) ;
2070 TabsAllocGreyGC(TabsWidget tw)
2072 Widget w = (Widget) tw;
2075 values.background = tw->core.background_pixel ;
2076 values.font = tw->tabs.font->fid ;
2078 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
2080 values.fill_style = FillStippled ;
2082 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
2085 XtAllocateGC(w, w->core.depth,
2086 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
2088 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2089 GCDashList|GCArcMode) ;
2095 XtAllocateGC(w, w->core.depth,
2098 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
2099 GCDashList|GCArcMode) ;