428
|
1 /* Tabs Widget for XEmacs.
|
|
2 Copyright (C) 1999 Edward A. Falk
|
442
|
3
|
428
|
4 This file is part of XEmacs.
|
442
|
5
|
428
|
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
|
|
9 later version.
|
442
|
10
|
428
|
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
|
|
14 for more details.
|
442
|
15
|
428
|
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. */
|
442
|
20
|
446
|
21 /* Synched up with: Tabs.c 1.27.
|
|
22
|
|
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
|
|
26 bad idea. */
|
442
|
27
|
428
|
28 /*
|
|
29 * Tabs.c - Index Tabs composite widget
|
|
30 *
|
|
31 * Author: Edward A. Falk
|
|
32 * falk@falconer.vip.best.com
|
|
33 *
|
|
34 * Date: July 29, 1997
|
|
35 *
|
|
36 *
|
|
37 * Overall layout of this widget is as follows:
|
|
38 *
|
|
39 * ________ ,---------. _________
|
|
40 * | label || Label || Label | \ tabs
|
|
41 * |________|| ||_________| /
|
|
42 * |+----------------------------+| \
|
|
43 * || || |
|
|
44 * || child widget window || > frame
|
|
45 * |+----------------------------+| |
|
|
46 * +------------------------------+ /
|
|
47 *
|
|
48 * The height of the tabs includes the shadow width, top and bottom
|
|
49 * margins, and the height of the text.
|
|
50 *
|
|
51 * The height of the frame includes the top and bottom shadow width and the
|
|
52 * size of the child widget window.
|
|
53 *
|
|
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
|
|
56 * the frame.
|
|
57 */
|
|
58
|
434
|
59 /*
|
|
60 * TODO: min child height = tab height
|
428
|
61 */
|
|
62
|
|
63 #include <config.h>
|
|
64 #include <stdio.h>
|
|
65
|
|
66 #include <X11/Xlib.h>
|
|
67 #include <X11/IntrinsicP.h>
|
|
68 #include <X11/StringDefs.h>
|
|
69 #include "../src/xmu.h"
|
|
70 #include "xlwtabsP.h"
|
|
71 #include "xlwgcs.h"
|
|
72
|
|
73 #define MIN_WID 10
|
|
74 #define MIN_HGT 10
|
|
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 */
|
|
80
|
|
81
|
|
82 /****************************************************************
|
|
83 *
|
|
84 * IndexTabs Resources
|
|
85 *
|
|
86 ****************************************************************/
|
|
87
|
|
88 static char defaultTranslations[] = "\
|
|
89 <BtnUp>: select() \n\
|
|
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\
|
|
109 " ;
|
|
110
|
|
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\
|
|
129 " ;
|
446
|
130 static XtAccelerators defaultAccelerators ; /* #### Never used */
|
428
|
131
|
|
132 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
|
|
133 static XtResource resources[] = {
|
|
134
|
|
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},
|
|
161 };
|
|
162 #undef offset
|
|
163
|
|
164
|
|
165
|
|
166 /* constraint resources */
|
|
167
|
|
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},
|
|
178 } ;
|
|
179 #undef offset
|
|
180
|
|
181
|
|
182
|
|
183
|
|
184 #if !NeedFunctionPrototypes
|
|
185
|
|
186 /* FORWARD REFERENCES: */
|
|
187
|
|
188 /* member functions */
|
|
189
|
|
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();
|
434
|
197 static Boolean TabsAcceptFocus();
|
428
|
198 static XtGeometryResult TabsQueryGeometry();
|
|
199 static XtGeometryResult TabsGeometryManager();
|
|
200 static void TabsChangeManaged();
|
|
201 static void TabsConstraintInitialize() ;
|
|
202 static Boolean TabsConstraintSetValues() ;
|
|
203
|
|
204 /* action procs */
|
|
205
|
|
206 static void TabsSelect() ;
|
|
207 static void TabsPage() ;
|
|
208 static void TabsHighlight() ;
|
|
209 static void TabsUnhighlight() ;
|
|
210
|
|
211 /* internal privates */
|
|
212
|
|
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 */
|
|
232
|
|
233 static void TabsAllocFgGC() ;
|
|
234 static void TabsAllocGreyGC() ;
|
|
235
|
|
236 #else
|
|
237
|
|
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 *) ;
|
434
|
246 static Boolean TabsAcceptFocus(Widget, Time *);
|
428
|
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) ;
|
|
254
|
|
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 *) ;
|
|
259
|
|
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) ;
|
|
268
|
|
269 static void TabWidth( Widget w) ;
|
|
270 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
|
|
271 Bool query_only) ;
|
|
272 static void GetPreferredSizes(TabsWidget) ;
|
434
|
273 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
|
428
|
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) ;
|
|
283
|
|
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) ;
|
|
289
|
|
290 #endif
|
|
291
|
|
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)
|
|
295
|
|
296 static XtActionsRec actionsList[] =
|
|
297 {
|
|
298 {"select", TabsSelect},
|
|
299 {"page", TabsPage},
|
|
300 {"highlight", TabsHighlight},
|
|
301 {"unhighlight", TabsUnhighlight},
|
|
302 } ;
|
|
303
|
|
304
|
|
305 /****************************************************************
|
|
306 *
|
|
307 * Full class record constant
|
|
308 *
|
|
309 ****************************************************************/
|
|
310
|
|
311 #ifndef NEED_MOTIF
|
|
312 #define SuperClass (&constraintClassRec)
|
|
313 #else
|
|
314 #define SuperClass (&xmManagerClassRec)
|
|
315 #endif
|
|
316
|
|
317 TabsClassRec tabsClassRec = {
|
|
318 {
|
|
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,
|
434
|
335 #if XtSpecificationRelease < 6
|
|
336 /* compress_exposure */ XtExposeCompressMaximal,
|
|
337 #else
|
|
338 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
|
|
339 #endif
|
428
|
340 /* compress_enterleave*/ TRUE,
|
434
|
341 /* visible_interest */ TRUE,
|
428
|
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,
|
434
|
349 /* accept_focus */ TabsAcceptFocus,
|
428
|
350 /* version */ XtVersion,
|
|
351 /* callback_private */ NULL,
|
|
352 /* tm_table */ defaultTranslations,
|
|
353 /* query_geometry */ TabsQueryGeometry,
|
|
354 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
355 /* extension */ NULL
|
|
356 },
|
|
357 {
|
|
358 /* composite_class fields */
|
|
359 /* geometry_manager */ TabsGeometryManager,
|
|
360 /* change_managed */ TabsChangeManaged,
|
|
361 /* insert_child */ XtInheritInsertChild, /* TODO? */
|
|
362 /* delete_child */ XtInheritDeleteChild, /* TODO? */
|
|
363 /* extension */ NULL
|
|
364 },
|
|
365 {
|
|
366 /* constraint_class fields */
|
|
367 /* subresources */ tabsConstraintResources,
|
|
368 /* subresource_count */ XtNumber(tabsConstraintResources),
|
|
369 /* constraint_size */ sizeof(TabsConstraintsRec),
|
|
370 /* initialize */ TabsConstraintInitialize,
|
|
371 /* destroy */ NULL,
|
|
372 /* set_values */ TabsConstraintSetValues,
|
|
373 /* extension */ NULL,
|
|
374 },
|
|
375 #ifdef NEED_MOTIF
|
|
376 /* Manager Class fields */
|
|
377 {
|
|
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,
|
|
384 /* extension */ NULL
|
|
385 },
|
|
386 #endif
|
|
387 {
|
|
388 /* Tabs class fields */
|
|
389 /* extension */ NULL,
|
|
390 }
|
|
391 };
|
|
392
|
|
393 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
|
|
394
|
|
395
|
|
396
|
|
397 #ifdef DEBUG
|
|
398 #ifdef __STDC__
|
|
399 #define assert(e) \
|
|
400 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
|
|
401 #else
|
|
402 #define assert(e) \
|
|
403 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
|
|
404 #endif
|
|
405 #else
|
|
406 #define assert(e)
|
|
407 #endif
|
|
408
|
446
|
409 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
|
|
410 #define TabVisible(tab) \
|
|
411 (XtIsManaged(tab) && \
|
|
412 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
|
428
|
413
|
|
414
|
|
415 /****************************************************************
|
|
416 *
|
|
417 * Member Procedures
|
|
418 *
|
|
419 ****************************************************************/
|
|
420
|
|
421 static void
|
|
422 TabsClassInit(void)
|
|
423 {
|
|
424 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
|
|
425 /* TODO: register converter for labels? */
|
|
426 }
|
|
427
|
|
428
|
|
429
|
|
430 /* Init a newly created tabs widget. Compute height of tabs
|
|
431 * and optionally compute size of widget. */
|
|
432
|
|
433 /* ARGSUSED */
|
|
434
|
|
435 static void
|
|
436 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
|
|
437 {
|
|
438 TabsWidget newTw = (TabsWidget)new;
|
|
439
|
|
440 newTw->tabs.numRows = 0 ;
|
446
|
441 newTw->tabs.realRows = 0;
|
428
|
442
|
|
443 GetPreferredSizes(newTw) ;
|
|
444
|
|
445 /* height is easy, it's the same for all tabs:
|
|
446 * TODO: font height + height of tallest bitmap.
|
|
447 */
|
|
448 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
|
|
449
|
|
450 if( newTw->tabs.font != NULL )
|
|
451 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
|
|
452 newTw->tabs.font->max_bounds.descent ;
|
|
453
|
|
454 /* GC allocation is deferred until XtRealize() */
|
|
455
|
|
456 /* if size not explicitly set, set it to our preferred size now. */
|
|
457
|
|
458 if( request->core.width == 0 || request->core.height == 0 )
|
|
459 {
|
|
460 Dimension w,h ;
|
|
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) ;
|
|
465 }
|
|
466
|
|
467 /* defer GC allocation, etc., until Realize() time. */
|
|
468 newTw->tabs.foregroundGC =
|
|
469 newTw->tabs.backgroundGC =
|
|
470 newTw->tabs.greyGC =
|
|
471 newTw->tabs.topGC =
|
|
472 newTw->tabs.botGC = None ;
|
|
473
|
|
474 newTw->tabs.grey50 = None ;
|
|
475
|
|
476 newTw->tabs.needs_layout = False ;
|
434
|
477
|
428
|
478 newTw->tabs.hilight = NULL ;
|
|
479
|
|
480 #ifdef NEED_MOTIF
|
|
481 newTw->manager.navigation_type = XmTAB_GROUP ;
|
|
482 newTw->manager.traversal_on = True ;
|
|
483 #endif
|
|
484 }
|
|
485
|
|
486
|
|
487 /* Init the constraint part of a new tab child. Compute the
|
|
488 * size of the tab.
|
|
489 */
|
|
490 /* ARGSUSED */
|
|
491 static void
|
|
492 TabsConstraintInitialize(Widget request, Widget new,
|
|
493 ArgList args, Cardinal *num_args)
|
|
494 {
|
|
495 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
|
|
496 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
|
446
|
497 tab->tabs.visible = False ;
|
428
|
498
|
|
499 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
|
|
500 TabWidth(new) ;
|
|
501 }
|
|
502
|
|
503
|
|
504
|
|
505 /* Called when tabs widget first realized. Create the window
|
|
506 * and allocate the GCs
|
|
507 */
|
|
508
|
|
509 static void
|
|
510 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
511 {
|
|
512 TabsWidget tw = (TabsWidget) w;
|
|
513
|
|
514 attributes->bit_gravity = NorthWestGravity;
|
|
515 *valueMask |= CWBitGravity;
|
|
516
|
|
517 SuperClass->core_class.realize(w, valueMask, attributes);
|
|
518
|
|
519 TabsAllocGCs(tw) ;
|
|
520 }
|
|
521
|
|
522
|
|
523
|
|
524 static void
|
|
525 TabsDestroy(Widget w)
|
|
526 {
|
|
527 TabsFreeGCs((TabsWidget)w) ;
|
|
528 }
|
|
529
|
|
530
|
|
531 /* Parent has resized us. This will require that the tabs be
|
|
532 * laid out again.
|
|
533 */
|
|
534
|
|
535 static void
|
|
536 TabsResize(Widget w)
|
|
537 {
|
|
538 TabsWidget tw = (TabsWidget) w;
|
|
539 int i ;
|
|
540 int num_children = tw->composite.num_children ;
|
|
541 Widget *childP ;
|
446
|
542 TabsConstraints tab ; /* #### unused */
|
428
|
543 Dimension cw,ch,bw ;
|
|
544
|
|
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.
|
|
550 *
|
|
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
|
|
553 * to the bottom row.
|
|
554 */
|
|
555
|
434
|
556 tw->tabs.needs_layout = False ;
|
|
557
|
428
|
558 if( num_children > 0 && tw->composite.children != NULL )
|
|
559 {
|
|
560 /* Loop through the tabs and assign rows & x positions */
|
|
561 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
|
446
|
562 num_children = TabsNumChildren (tw);
|
428
|
563
|
|
564 /* assign a top widget, bring it to bottom row. */
|
|
565 TabsShuffleRows(tw) ;
|
|
566
|
|
567 /* now assign child positions & sizes. Positions are all the
|
|
568 * same: just inside the frame. Sizes are also all the same.
|
|
569 */
|
|
570
|
|
571 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
|
|
572 tw->tabs.child_height = ch =
|
434
|
573 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
|
428
|
574
|
|
575
|
|
576 for(i=0, childP=tw->composite.children;
|
434
|
577 i < num_children;
|
428
|
578 ++i, ++childP)
|
446
|
579 if( TabVisible(*childP) )
|
428
|
580 {
|
|
581 tab = (TabsConstraints) (*childP)->core.constraints ;
|
434
|
582 bw = (*childP)->core.border_width ;
|
428
|
583 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
|
|
584 cw-bw*2,ch-bw*2, bw) ;
|
|
585 }
|
434
|
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.
|
|
590 */
|
|
591 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
592 }
|
428
|
593 }
|
|
594 } /* Resize */
|
|
595
|
|
596
|
|
597
|
|
598 /* Redraw entire Tabs widget */
|
|
599
|
|
600 /* ARGSUSED */
|
|
601 static void
|
|
602 TabsExpose(Widget w, XEvent *event, Region region)
|
|
603 {
|
|
604 TabsWidget tw = (TabsWidget) w;
|
|
605
|
|
606 if( tw->tabs.needs_layout )
|
|
607 XtClass(w)->core_class.resize(w) ;
|
|
608
|
|
609 DrawTabs(tw, True) ;
|
|
610 }
|
|
611
|
|
612
|
|
613 /* Called when any Tabs widget resources are changed. */
|
|
614
|
|
615 /* ARGSUSED */
|
|
616 static Boolean
|
|
617 TabsSetValues(Widget current, Widget request, Widget new,
|
|
618 ArgList args, Cardinal *num_args)
|
|
619 {
|
430
|
620 TabsWidget curtw = (TabsWidget) current ;
|
|
621 TabsWidget tw = (TabsWidget) new ;
|
|
622 Boolean needRedraw = False ;
|
|
623 Widget *childP ;
|
|
624 int i ;
|
428
|
625
|
|
626
|
430
|
627 if( tw->tabs.font != curtw->tabs.font ||
|
|
628 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
|
|
629 tw->tabs.internalHeight != curtw->tabs.internalHeight )
|
|
630 {
|
|
631 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
|
428
|
632
|
430
|
633 if( tw->tabs.font != NULL )
|
|
634 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
|
|
635 tw->tabs.font->max_bounds.descent ;
|
428
|
636
|
430
|
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;
|
|
640 ++i, ++childP)
|
|
641 if( XtIsManaged(*childP) )
|
|
642 TabWidth(*childP) ;
|
|
643 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
|
|
644 needRedraw = True ;
|
|
645 tw->tabs.needs_layout = True ;
|
|
646 }
|
428
|
647
|
430
|
648 /* TODO: if any color changes, need to recompute GCs and redraw */
|
428
|
649
|
430
|
650 if( tw->core.background_pixel != curtw->core.background_pixel ||
|
432
|
651 tw->core.background_pixmap != curtw->core.background_pixmap ||
|
|
652 tw->tabs.font != curtw->tabs.font )
|
430
|
653 if( XtIsRealized(new) )
|
|
654 {
|
|
655 TabsFreeGCs(tw) ;
|
|
656 TabsAllocGCs(tw) ;
|
|
657 needRedraw = True ;
|
|
658 }
|
428
|
659
|
430
|
660 if( tw->core.sensitive != curtw->core.sensitive )
|
|
661 needRedraw = True ;
|
428
|
662
|
430
|
663 /* If top widget changes, need to change stacking order, redraw tabs.
|
|
664 * Window system will handle the redraws.
|
|
665 */
|
428
|
666
|
442
|
667 if( tw->tabs.topWidget != curtw->tabs.topWidget )
|
432
|
668 {
|
430
|
669 if( XtIsRealized(tw->tabs.topWidget) )
|
|
670 {
|
|
671 Widget w = tw->tabs.topWidget ;
|
|
672 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
428
|
673
|
430
|
674 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
428
|
675 #ifdef NEED_MOTIF
|
430
|
676 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
|
|
677 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
428
|
678 #endif
|
|
679
|
430
|
680 if( tab->tabs.row != tw->tabs.numRows-1 )
|
|
681 TabsShuffleRows(tw) ;
|
428
|
682
|
430
|
683 needRedraw = True ;
|
|
684 }
|
|
685 else
|
|
686 tw->tabs.needs_layout = True ;
|
432
|
687 }
|
428
|
688
|
430
|
689 return needRedraw ;
|
428
|
690 }
|
|
691
|
|
692
|
|
693 /* Called when any child constraint resources change. */
|
|
694
|
|
695 /* ARGSUSED */
|
|
696 static Boolean
|
|
697 TabsConstraintSetValues(Widget current, Widget request, Widget new,
|
|
698 ArgList args, Cardinal *num_args)
|
|
699 {
|
|
700 TabsWidget tw = (TabsWidget) XtParent(new) ;
|
|
701 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
|
|
702 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
|
|
703
|
|
704
|
|
705 /* if label changes, need to re-layout the entire widget */
|
|
706 /* if foreground changes, need to redraw tab label */
|
|
707
|
|
708 /* TODO: only need resize of new bitmap has different dimensions
|
|
709 * from old bitmap.
|
|
710 */
|
|
711
|
|
712 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
|
|
713 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
714 {
|
|
715 TabWidth(new) ;
|
|
716 tw->tabs.needs_layout = True ;
|
|
717
|
|
718 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
719 getBitmapInfo(tw, tab) ;
|
|
720
|
|
721 /* If there are no subclass ConstraintSetValues procedures remaining
|
|
722 * to be invoked, and if the preferred size has changed, ask
|
|
723 * for a resize.
|
|
724 */
|
|
725 if( XtClass((Widget)tw) == tabsWidgetClass )
|
|
726 MakeSizeRequest(tw) ;
|
|
727 }
|
|
728
|
|
729
|
|
730 /* The child widget itself never needs a redisplay, but the parent
|
|
731 * Tabs widget might.
|
|
732 */
|
|
733
|
|
734 if( XtIsRealized(new) )
|
|
735 {
|
|
736 if( tw->tabs.needs_layout ) {
|
|
737 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
738 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
739 }
|
|
740
|
|
741 else if( tab->tabs.foreground != ctab->tabs.foreground )
|
|
742 DrawTab(tw, new, True) ;
|
|
743 }
|
|
744
|
|
745 return False ;
|
|
746 }
|
|
747
|
|
748
|
434
|
749 static Boolean
|
|
750 TabsAcceptFocus(Widget w, Time *t)
|
|
751 {
|
|
752 if( !w->core.being_destroyed && XtIsRealized(w) &&
|
|
753 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
|
|
754 {
|
|
755 Widget p ;
|
|
756 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
|
|
757 XtSetKeyboardFocus(p,w) ;
|
|
758 return True ;
|
|
759 }
|
|
760 else
|
|
761 return False ;
|
|
762 }
|
|
763
|
|
764
|
428
|
765
|
|
766 /*
|
|
767 * Return preferred size. Happily accept anything >= our preferred size.
|
|
768 * (TODO: is that the right thing to do? Should we always return "almost"
|
442
|
769 * if offered more than we need?)
|
428
|
770 */
|
|
771
|
|
772 static XtGeometryResult
|
|
773 TabsQueryGeometry(Widget w,
|
|
774 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
|
|
775 {
|
|
776 register TabsWidget tw = (TabsWidget)w ;
|
|
777 XtGeometryMask mode = intended->request_mode ;
|
|
778
|
|
779 preferred->request_mode = CWWidth | CWHeight ;
|
|
780 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
|
|
781
|
|
782 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
|
|
783 (!(mode & CWHeight) || intended->height == w->core.height) )
|
|
784 return XtGeometryNo ;
|
|
785
|
|
786 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
|
|
787 (!(mode & CWHeight) || intended->height >= preferred->height) )
|
|
788 return XtGeometryYes;
|
|
789
|
|
790 return XtGeometryAlmost;
|
|
791 }
|
|
792
|
|
793
|
|
794
|
|
795 /*
|
|
796 * Geometry Manager; called when a child wants to be resized.
|
|
797 */
|
|
798
|
|
799 static XtGeometryResult
|
|
800 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
|
|
801 {
|
|
802 TabsWidget tw = (TabsWidget) XtParent(w);
|
|
803 Dimension s = SHADWID ;
|
|
804 TabsConstraints tab = (TabsConstraints)w->core.constraints;
|
|
805 XtGeometryResult result ;
|
434
|
806 Dimension rw, rh ;
|
428
|
807
|
|
808 /* Position request always denied */
|
|
809
|
|
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 ;
|
|
814
|
|
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;
|
|
822
|
|
823 if( req->width == w->core.width &&
|
|
824 req->height == w->core.height &&
|
|
825 req->border_width == w->core.border_width )
|
|
826 return XtGeometryNo ;
|
|
827
|
434
|
828 rw = req->width + 2 * req->border_width ;
|
|
829 rh = req->height + 2 * req->border_width ;
|
|
830
|
|
831 /* find out how big the children want to be now */
|
|
832 MaxChild(tw, w, rw, rh) ;
|
428
|
833
|
|
834
|
|
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
|
434
|
840 * returns an "almost" response with the new proposed size
|
|
841 * or a "no" response if unable to shrink at all.
|
|
842 *
|
428
|
843 * A request to grow will be accepted only if the Tabs parent can
|
|
844 * grow to accommodate.
|
|
845 *
|
|
846 * TODO:
|
|
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
|
|
849 * for another day.
|
|
850 */
|
|
851
|
|
852 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
|
|
853 {
|
|
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 */
|
|
858
|
434
|
859 cw = tw->tabs.max_cw ;
|
|
860 ch = tw->tabs.max_ch ;
|
428
|
861
|
434
|
862 /* find out what *my* resulting preferred size would be */
|
428
|
863
|
434
|
864 PreferredSize2(tw, cw, ch, &wid, &hgt) ;
|
|
865
|
|
866 /* Would my size change? If so, ask to be resized. */
|
428
|
867
|
|
868 if( wid != tw->core.width || hgt != tw->core.height )
|
|
869 {
|
|
870 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
|
|
871 XtWidgetGeometry myrequest, myreply ;
|
|
872
|
|
873 myrequest.width = wid ;
|
|
874 myrequest.height = hgt ;
|
|
875 myrequest.request_mode = CWWidth | CWHeight ;
|
|
876
|
|
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.
|
|
879 */
|
|
880
|
|
881 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
|
|
882 myrequest.request_mode |= XtCWQueryOnly ;
|
|
883
|
|
884 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
|
|
885
|
434
|
886 /* !$@# Athena Box widget changes the core size even if QueryOnly
|
428
|
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.
|
|
891 */
|
|
892 if( myrequest.request_mode & XtCWQueryOnly ) {
|
|
893 tw->core.width = oldWid ;
|
|
894 tw->core.height = oldHgt ;
|
|
895 }
|
|
896
|
|
897 /* based on the parent's response, determine what the
|
|
898 * resulting Tabs widget size would be.
|
|
899 */
|
|
900
|
|
901 switch( result ) {
|
|
902 case XtGeometryYes:
|
|
903 case XtGeometryDone:
|
434
|
904 tw->tabs.needs_layout = True ;
|
428
|
905 break ;
|
|
906
|
|
907 case XtGeometryNo:
|
|
908 wid = tw->core.width ;
|
|
909 hgt = tw->core.height ;
|
|
910 break ;
|
|
911
|
|
912 case XtGeometryAlmost:
|
|
913 wid = myreply.width ;
|
|
914 hgt = myreply.height ;
|
434
|
915 tw->tabs.needs_layout = True ;
|
|
916 break ;
|
428
|
917 }
|
|
918 }
|
|
919
|
|
920 /* Within the constraints imposed by the parent, what is
|
|
921 * the max size we can give the child?
|
|
922 */
|
|
923 (void) TabLayout(tw, wid, hgt, &th, True) ;
|
|
924 aw = wid - 2*s ;
|
|
925 ah = hgt - th - 2*s ;
|
|
926
|
|
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.
|
|
930 */
|
|
931
|
|
932 if( rw == aw && rh == ah )
|
|
933 {
|
|
934 /* Acceptable. If this wasn't a query, change *all* children
|
|
935 * to this size.
|
|
936 */
|
|
937 if( req->request_mode & XtCWQueryOnly )
|
|
938 return XtGeometryYes ;
|
|
939 else
|
|
940 {
|
|
941 Widget *childP = tw->composite.children ;
|
|
942 int i,bw ;
|
|
943 w->core.border_width = req->border_width ;
|
446
|
944 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
|
|
945 if( TabVisible(*childP) )
|
428
|
946 {
|
|
947 bw = (*childP)->core.border_width ;
|
|
948 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
|
|
949 rw-2*bw, rh-2*bw, bw) ;
|
|
950 }
|
|
951 #ifdef COMMENT
|
|
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) ;
|
|
955 #endif /* COMMENT */
|
|
956 return XtGeometryDone ;
|
|
957 }
|
|
958 }
|
|
959
|
|
960 /* Cannot grant child's request. Describe what we *can* do
|
|
961 * and return counter-offer.
|
|
962 */
|
|
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 ;
|
|
968 }
|
|
969
|
|
970 return XtGeometryYes ;
|
|
971 }
|
|
972
|
|
973
|
|
974
|
|
975
|
|
976 /* The number of children we manage has changed; recompute
|
|
977 * size from scratch.
|
|
978 */
|
|
979
|
|
980 static void
|
|
981 TabsChangeManaged(Widget w)
|
|
982 {
|
|
983 TabsWidget tw = (TabsWidget)w ;
|
|
984 Widget *childP = tw->composite.children ;
|
|
985 int i ;
|
|
986
|
|
987 if( tw->tabs.topWidget != NULL &&
|
|
988 ( !XtIsManaged(tw->tabs.topWidget) ||
|
|
989 tw->tabs.topWidget->core.being_destroyed ) )
|
|
990 tw->tabs.topWidget = NULL ;
|
|
991
|
440
|
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 ;
|
|
997
|
428
|
998 GetPreferredSizes(tw) ;
|
|
999 MakeSizeRequest(tw) ;
|
|
1000
|
|
1001 XtClass(w)->core_class.resize(w) ;
|
|
1002 if( XtIsRealized(w) )
|
|
1003 {
|
|
1004 Display *dpy = XtDisplay(w) ;
|
|
1005 XClearWindow(dpy, XtWindow(w)) ;
|
|
1006 XtClass(w)->core_class.expose(w,NULL,NULL) ;
|
|
1007
|
|
1008 /* make sure the top widget stays on top. This requires
|
|
1009 * making sure that all new children are realized first.
|
|
1010 */
|
|
1011 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
|
|
1012 {
|
446
|
1013 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
|
428
|
1014 if( !XtIsRealized(*childP) )
|
|
1015 XtRealizeWidget(*childP) ;
|
|
1016
|
|
1017 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
|
|
1018 }
|
|
1019 }
|
|
1020
|
|
1021 #ifdef NEED_MOTIF
|
|
1022 /* Only top widget may receive input */
|
|
1023
|
|
1024 for(childP = tw->composite.children, i=tw->composite.num_children;
|
|
1025 --i >= 0;
|
|
1026 ++childP)
|
|
1027 {
|
|
1028 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
|
|
1029 }
|
|
1030
|
|
1031 if( tw->tabs.topWidget != NULL )
|
|
1032 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
|
|
1033 #endif
|
|
1034 }
|
|
1035
|
|
1036
|
|
1037
|
|
1038
|
|
1039 /****************************************************************
|
|
1040 *
|
|
1041 * Action Procedures
|
|
1042 *
|
|
1043 ****************************************************************/
|
|
1044
|
|
1045
|
|
1046 /* User clicks on a tab, figure out which one it was. */
|
|
1047
|
|
1048 /* ARGSUSED */
|
|
1049 static void
|
|
1050 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1051 {
|
|
1052 TabsWidget tw = (TabsWidget) w ;
|
|
1053 Widget *childP ;
|
|
1054 Position x,y ;
|
|
1055 Dimension h = tw->tabs.tab_height ;
|
|
1056 int i ;
|
|
1057
|
|
1058 #ifdef NEED_MOTIF
|
|
1059 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
|
|
1060 #endif
|
|
1061
|
|
1062 /* TODO: is there an Xmu function or something to do this instead? */
|
|
1063 switch( event->type ) {
|
|
1064 case ButtonPress:
|
|
1065 case ButtonRelease:
|
|
1066 x = event->xbutton.x ; y = event->xbutton.y ; break ;
|
|
1067 case KeyPress:
|
|
1068 case KeyRelease:
|
|
1069 x = event->xkey.x ; y = event->xkey.y ; break ;
|
|
1070 default:
|
|
1071 return ;
|
|
1072 }
|
|
1073
|
|
1074 /* TODO: determine which tab was clicked, if any. Set that
|
|
1075 * widget to be top of stacking order with XawTabsSetTop().
|
|
1076 */
|
|
1077 for(i=0, childP=tw->composite.children;
|
446
|
1078 i < TabsNumChildren (tw);
|
428
|
1079 ++i, ++childP)
|
446
|
1080 if( TabVisible(*childP) )
|
428
|
1081 {
|
|
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 )
|
|
1085 {
|
|
1086 if( *childP != tw->tabs.topWidget &&
|
|
1087 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
|
|
1088 XawTabsSetTop(*childP, True) ;
|
|
1089 break ;
|
|
1090 }
|
|
1091 }
|
|
1092 }
|
|
1093
|
|
1094
|
|
1095 /* User hits a key */
|
|
1096
|
|
1097 static void
|
|
1098 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1099 {
|
|
1100 TabsWidget tw = (TabsWidget) w ;
|
430
|
1101 Widget newtop = NULL;
|
428
|
1102 Widget *childP ;
|
|
1103 int idx ;
|
446
|
1104 int nc = TabsNumChildren (tw) ;
|
428
|
1105
|
|
1106 if( nc <= 0 )
|
|
1107 return ;
|
|
1108
|
|
1109 if( *num_params < 1 ) {
|
|
1110 XtAppWarning(XtWidgetToApplicationContext(w),
|
|
1111 "Tabs: page() action called with no arguments") ;
|
|
1112 return ;
|
|
1113 }
|
|
1114
|
|
1115 if( tw->tabs.topWidget == NULL )
|
|
1116 tw->tabs.topWidget = tw->composite.children[0] ;
|
|
1117
|
|
1118 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1119 if( tw->tabs.topWidget == *childP )
|
|
1120 break ;
|
|
1121
|
|
1122 switch( params[0][0] ) {
|
|
1123 case 'u': /* up */
|
|
1124 case 'U':
|
432
|
1125 if( --idx < 0 )
|
|
1126 idx = nc-1 ;
|
|
1127 newtop = tw->composite.children[idx] ;
|
428
|
1128 break ;
|
|
1129
|
|
1130 case 'd': /* down */
|
|
1131 case 'D':
|
|
1132 if( ++idx >= nc )
|
|
1133 idx = 0 ;
|
|
1134 newtop = tw->composite.children[idx] ;
|
|
1135 break ;
|
|
1136
|
|
1137 case 'h':
|
|
1138 case 'H':
|
432
|
1139 default:
|
428
|
1140 newtop = tw->composite.children[0] ;
|
|
1141 break ;
|
|
1142
|
|
1143 case 'e':
|
|
1144 case 'E':
|
|
1145 newtop = tw->composite.children[nc-1] ;
|
|
1146 break ;
|
|
1147
|
|
1148 case 's': /* selected */
|
|
1149 case 'S':
|
|
1150 if( (newtop = tw->tabs.hilight) == NULL )
|
|
1151 return ;
|
|
1152 break ;
|
|
1153 }
|
|
1154
|
|
1155 XawTabsSetTop(newtop, True) ;
|
|
1156 }
|
|
1157
|
|
1158
|
|
1159 /* User hits up/down key */
|
|
1160
|
|
1161 static void
|
|
1162 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1163 {
|
|
1164 TabsWidget tw = (TabsWidget) w ;
|
430
|
1165 Widget newhl = NULL;
|
428
|
1166 Widget *childP ;
|
|
1167 int idx ;
|
446
|
1168 int nc = TabsNumChildren (tw) ;
|
428
|
1169
|
|
1170 if( nc <= 0 )
|
|
1171 return ;
|
|
1172
|
|
1173 if( *num_params < 1 )
|
|
1174 {
|
|
1175 if( tw->tabs.hilight != NULL )
|
|
1176 DrawHighlight(tw, tw->tabs.hilight, False) ;
|
|
1177 return ;
|
|
1178 }
|
|
1179
|
|
1180 if( tw->tabs.hilight == NULL )
|
|
1181 newhl = tw->composite.children[0] ;
|
|
1182
|
|
1183 else
|
|
1184 {
|
432
|
1185 /* find index of currently highlit child */
|
428
|
1186 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1187 if( tw->tabs.hilight == *childP )
|
|
1188 break ;
|
|
1189
|
|
1190 switch( params[0][0] ) {
|
|
1191 case 'u': /* up */
|
|
1192 case 'U':
|
432
|
1193 if( --idx < 0 )
|
|
1194 idx = nc-1 ;
|
|
1195 newhl = tw->composite.children[idx] ;
|
428
|
1196 break ;
|
|
1197
|
|
1198 case 'd': /* down */
|
|
1199 case 'D':
|
|
1200 if( ++idx >= nc )
|
|
1201 idx = 0 ;
|
|
1202 newhl = tw->composite.children[idx] ;
|
|
1203 break ;
|
|
1204
|
|
1205 case 'h':
|
|
1206 case 'H':
|
|
1207 newhl = tw->composite.children[0] ;
|
|
1208 break ;
|
|
1209
|
|
1210 case 'e':
|
|
1211 case 'E':
|
|
1212 newhl = tw->composite.children[nc-1] ;
|
|
1213 break ;
|
432
|
1214
|
|
1215 default:
|
|
1216 newhl = tw->tabs.hilight ;
|
|
1217 break ;
|
428
|
1218 }
|
|
1219 }
|
|
1220
|
|
1221 XawTabsSetHighlight(w, newhl) ;
|
|
1222 }
|
|
1223
|
|
1224
|
|
1225
|
|
1226 static void
|
|
1227 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1228 {
|
|
1229 TabsWidget tw = (TabsWidget) w ;
|
|
1230 int nc = tw->composite.num_children ;
|
|
1231
|
|
1232 if( nc <= 0 )
|
|
1233 return ;
|
|
1234
|
|
1235 if( tw->tabs.hilight != NULL )
|
|
1236 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1237 }
|
|
1238
|
|
1239
|
|
1240
|
|
1241
|
|
1242
|
|
1243 /****************************************************************
|
|
1244 *
|
|
1245 * Public Procedures
|
|
1246 *
|
|
1247 ****************************************************************/
|
|
1248
|
|
1249
|
|
1250 /* Set the top tab, optionally call all callbacks. */
|
|
1251 void
|
|
1252 XawTabsSetTop(Widget w, Bool callCallbacks)
|
|
1253 {
|
|
1254 TabsWidget tw = (TabsWidget)w->core.parent ;
|
|
1255 TabsConstraints tab ;
|
|
1256 Widget oldtop = tw->tabs.topWidget ;
|
|
1257
|
|
1258 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
|
|
1259 {
|
434
|
1260 char line[256] ;
|
|
1261 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
|
428
|
1262 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
|
|
1263 return ;
|
|
1264 }
|
|
1265
|
|
1266 if( callCallbacks )
|
|
1267 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
|
434
|
1268 (XtPointer)tw->tabs.topWidget) ;
|
428
|
1269
|
|
1270 if( !XtIsRealized(w) ) {
|
|
1271 tw->tabs.topWidget = w ;
|
|
1272 tw->tabs.needs_layout = True ;
|
440
|
1273 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
|
428
|
1274 return ;
|
|
1275 }
|
|
1276
|
|
1277 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
|
1278 #ifdef NEED_MOTIF
|
|
1279 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
|
|
1280 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
|
1281 #endif
|
|
1282
|
|
1283 tab = (TabsConstraints) w->core.constraints ;
|
440
|
1284
|
|
1285 /* Unhighlight before we start messing with the stacking order. */
|
|
1286 if( tw->tabs.hilight != NULL )
|
|
1287 {
|
|
1288 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1289 tw->tabs.hilight = NULL;
|
|
1290 }
|
|
1291
|
428
|
1292 if( tab->tabs.row == 0 )
|
|
1293 {
|
|
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.
|
|
1298 */
|
|
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) ;
|
|
1307 }
|
|
1308 else
|
|
1309 {
|
|
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) ;
|
|
1314 }
|
|
1315
|
|
1316 XawTabsSetHighlight((Widget)tw, w) ;
|
|
1317
|
|
1318 if( callCallbacks )
|
|
1319 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
|
|
1320 }
|
|
1321
|
|
1322
|
|
1323 /* Set the top tab, optionally call all callbacks. */
|
|
1324 void
|
|
1325 XawTabsSetHighlight(Widget t, Widget w)
|
|
1326 {
|
|
1327 TabsWidget tw = (TabsWidget)t ;
|
|
1328
|
|
1329 if( !XtIsSubclass(t, tabsWidgetClass) )
|
|
1330 return ;
|
|
1331
|
|
1332 if( XtIsRealized(t) && w != tw->tabs.hilight )
|
|
1333 {
|
|
1334 if( w != NULL )
|
|
1335 DrawHighlight(tw, w, False) ;
|
|
1336 }
|
|
1337
|
|
1338 tw->tabs.hilight = w ;
|
|
1339 }
|
|
1340
|
|
1341
|
|
1342
|
|
1343
|
|
1344 /****************************************************************
|
|
1345 *
|
|
1346 * Private Procedures
|
|
1347 *
|
|
1348 ****************************************************************/
|
|
1349
|
|
1350
|
|
1351 static void
|
|
1352 TabsAllocGCs(TabsWidget tw)
|
|
1353 {
|
|
1354 TabsAllocFgGC(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) ;
|
|
1361 }
|
|
1362
|
|
1363
|
|
1364 static void
|
|
1365 TabsFreeGCs(TabsWidget tw)
|
|
1366 {
|
|
1367 Widget w = (Widget) tw;
|
|
1368
|
|
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) ;
|
|
1374 #ifdef HAVE_XMU
|
|
1375 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
|
|
1376 #endif
|
|
1377 }
|
|
1378
|
|
1379
|
|
1380
|
|
1381
|
|
1382
|
|
1383 /* Redraw entire Tabs widget */
|
|
1384
|
|
1385 static void
|
|
1386 DrawTabs(TabsWidget tw, Bool labels)
|
|
1387 {
|
|
1388 Widget *childP ;
|
|
1389 int i,j ;
|
|
1390 Dimension s = SHADWID ;
|
|
1391 Dimension th = tw->tabs.tab_height ;
|
|
1392 Position y ;
|
|
1393 TabsConstraints tab ;
|
|
1394
|
|
1395 if( !XtIsRealized((Widget)tw))
|
|
1396 return ;
|
442
|
1397
|
428
|
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.)
|
|
1401 */
|
|
1402
|
|
1403 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
|
|
1404 for(i=0; i<tw->tabs.numRows; ++i, y += th)
|
|
1405 {
|
446
|
1406 for( j=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
1407 --j >= 0; ++childP )
|
446
|
1408 if( TabVisible(*childP) )
|
428
|
1409 {
|
|
1410 tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1411 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
|
|
1412 DrawTab(tw, *childP, labels) ;
|
|
1413 }
|
|
1414 if( i != tw->tabs.numRows -1 )
|
|
1415 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
|
|
1416 }
|
|
1417
|
|
1418 DrawFrame(tw) ;
|
|
1419
|
|
1420 /* and now the top tab */
|
|
1421 if( tw->tabs.topWidget != NULL )
|
|
1422 DrawTab(tw, tw->tabs.topWidget, labels) ;
|
|
1423 }
|
|
1424
|
|
1425
|
|
1426
|
|
1427 /* Draw one tab. Corners are rounded very slightly. */
|
|
1428
|
|
1429 static void
|
|
1430 DrawTab(TabsWidget tw, Widget child, Bool labels)
|
|
1431 {
|
|
1432 GC gc ;
|
|
1433 int x,y ;
|
|
1434
|
|
1435 if( !XtIsRealized((Widget)tw))
|
|
1436 return ;
|
|
1437
|
|
1438 DrawBorder(tw, child, False) ;
|
|
1439
|
|
1440 if( labels )
|
|
1441 {
|
|
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) ;
|
|
1447
|
|
1448 if( XtIsSensitive(child) )
|
|
1449 {
|
|
1450 gc = tw->tabs.foregroundGC ;
|
|
1451 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1452 }
|
|
1453 else
|
|
1454 {
|
|
1455 /* grey pixel allocation deferred until now */
|
|
1456 if( !tab->tabs.greyAlloc )
|
|
1457 {
|
|
1458 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
|
|
1459 tab->tabs.grey = tab->tabs.foreground ;
|
|
1460 else
|
|
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 ;
|
|
1466 }
|
|
1467 gc = tw->tabs.greyGC ;
|
|
1468 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1469 }
|
|
1470
|
|
1471 x = tab->tabs.x ;
|
|
1472 y = tab->tabs.y ;
|
|
1473 if( child == tw->tabs.topWidget )
|
|
1474 y -= TABLDELTA ;
|
|
1475
|
|
1476 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
|
|
1477 {
|
|
1478 if( tab->tabs.lbm_depth == 1 )
|
|
1479 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1480 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
428
|
1481 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
|
|
1482 else
|
|
1483 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1484 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
428
|
1485 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
|
|
1486 }
|
|
1487
|
|
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)) ;
|
|
1492 }
|
|
1493
|
|
1494 if( child == tw->tabs.hilight )
|
|
1495 DrawHighlight(tw, child, False) ;
|
|
1496 }
|
|
1497
|
|
1498
|
|
1499 /* draw frame all the way around the child windows. */
|
|
1500
|
|
1501 static void
|
|
1502 DrawFrame(TabsWidget tw)
|
|
1503 {
|
|
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) ;
|
|
1510 }
|
|
1511
|
|
1512
|
|
1513 /* draw trim around a tab or underneath a row of tabs */
|
|
1514
|
|
1515 static void
|
|
1516 DrawTrim(TabsWidget tw, /* widget */
|
|
1517 int x, /* upper-left corner */
|
|
1518 int y,
|
|
1519 int wid, /* total size */
|
|
1520 int hgt,
|
|
1521 Bool bottom, /* draw bottom? */
|
|
1522 Bool undraw) /* undraw all */
|
|
1523 {
|
|
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 ;
|
|
1529 if( bottom )
|
|
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 */
|
|
1536 }
|
|
1537
|
|
1538
|
|
1539 /* Draw one tab border. */
|
|
1540
|
|
1541 static void
|
|
1542 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
|
|
1543 {
|
|
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 ;
|
|
1549
|
|
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?
|
|
1554 */
|
|
1555 if( child == tw->tabs.topWidget )
|
|
1556 {
|
|
1557 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1558 Window win = XtWindow((Widget)tw) ;
|
|
1559 GC bggc = tw->tabs.backgroundGC ;
|
|
1560 XRectangle rects[3] ;
|
|
1561 x -= TABDELTA ;
|
|
1562 y -= TABDELTA ;
|
|
1563 twid += TABDELTA*2 ;
|
|
1564 thgt += TABDELTA ;
|
|
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) ;
|
|
1569 }
|
|
1570
|
|
1571 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
|
|
1572 }
|
|
1573
|
|
1574
|
|
1575 /* Draw highlight around tab that has focus */
|
|
1576
|
|
1577 static void
|
|
1578 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
|
|
1579 {
|
|
1580 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1581 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1582 Window win = XtWindow((Widget)tw) ;
|
|
1583 GC gc ;
|
|
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 ;
|
|
1588 XPoint points[6] ;
|
|
1589
|
|
1590 /* top tab does not have a highlight */
|
|
1591
|
|
1592 if( child == tw->tabs.topWidget )
|
|
1593 return ;
|
|
1594
|
|
1595 if( undraw )
|
|
1596 gc = tw->tabs.backgroundGC ;
|
|
1597
|
|
1598 else if( XtIsSensitive(child) )
|
|
1599 {
|
|
1600 gc = tw->tabs.foregroundGC ;
|
|
1601 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1602 }
|
|
1603 else
|
|
1604 {
|
|
1605 gc = tw->tabs.greyGC ;
|
|
1606 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1607 }
|
|
1608
|
|
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 ;
|
|
1615
|
|
1616 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
|
|
1617 }
|
|
1618
|
|
1619
|
|
1620 /* Undraw one tab interior */
|
|
1621
|
|
1622 static void
|
|
1623 UndrawTab(TabsWidget tw, Widget child)
|
|
1624 {
|
|
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 ;
|
|
1633
|
|
1634 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
|
|
1635 }
|
|
1636
|
|
1637
|
|
1638
|
|
1639
|
|
1640
|
|
1641 /* GEOMETRY UTILITIES */
|
|
1642
|
434
|
1643 /* Overview:
|
|
1644 *
|
|
1645 * MaxChild(): ask all children (except possibly one) their
|
|
1646 * preferred sizes, set max_cw, max_ch accordingly.
|
|
1647 *
|
|
1648 * GetPreferredSizes(): ask all children their preferred sizes,
|
|
1649 * set max_cw, max_ch accordingly.
|
|
1650 *
|
|
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.
|
|
1654 *
|
|
1655 * PreferredSize2(): Given child dimensions, return Tabs
|
|
1656 * widget dimensions.
|
|
1657 *
|
|
1658 * PreferredSize3(): Same, except given child dimensions plus
|
|
1659 * shadow.
|
|
1660 */
|
428
|
1661
|
434
|
1662
|
|
1663 /* Compute the width of one child's tab. Positions will be computed
|
428
|
1664 * elsewhere.
|
|
1665 *
|
|
1666 * height: font height + vertical_space*2 + shadowWid*2
|
|
1667 * width: string width + horizontal_space*2 + shadowWid*2
|
|
1668 *
|
|
1669 * All tabs are the same height, so that is computed elsewhere.
|
|
1670 */
|
|
1671
|
|
1672 static void
|
|
1673 TabWidth(Widget w)
|
|
1674 {
|
|
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 ;
|
|
1681
|
|
1682 tab->tabs.width = iw + SHADWID*2 ;
|
|
1683 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
|
|
1684
|
|
1685 if( tab->tabs.left_bitmap != None )
|
|
1686 {
|
|
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 ;
|
|
1690 }
|
|
1691
|
|
1692 if( lbl != NULL && font != NULL )
|
|
1693 {
|
|
1694 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
|
|
1695 tab->tabs.l_y = (tw->tabs.tab_height +
|
434
|
1696 tw->tabs.font->max_bounds.ascent -
|
428
|
1697 tw->tabs.font->max_bounds.descent)/2 ;
|
|
1698 }
|
|
1699 }
|
|
1700
|
|
1701
|
|
1702
|
|
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.
|
|
1707 *
|
|
1708 * Tabs are indented from the edges by INDENT.
|
|
1709 *
|
|
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.
|
|
1712 */
|
|
1713
|
|
1714 static int
|
|
1715 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
|
|
1716 {
|
446
|
1717 int i, row, done = 0, display_rows = 0 ;
|
428
|
1718 int num_children = tw->composite.num_children ;
|
|
1719 Widget *childP ;
|
|
1720 Dimension w ;
|
|
1721 Position x,y ;
|
|
1722 TabsConstraints tab ;
|
|
1723
|
|
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.
|
|
1727 */
|
|
1728
|
|
1729 if( num_children > 0 )
|
|
1730 {
|
|
1731 /* Loop through the tabs and see how much space they need. */
|
|
1732
|
|
1733 row = 0 ;
|
|
1734 x = INDENT ;
|
|
1735 y = 0 ;
|
|
1736 wid -= INDENT ;
|
|
1737 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
|
|
1738 if( XtIsManaged(*childP) )
|
|
1739 {
|
|
1740 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1741 w = tab->tabs.width ;
|
446
|
1742
|
428
|
1743 if( x + w > wid ) { /* new row */
|
446
|
1744 if (y + tw->tabs.tab_height > hgt && !done)
|
|
1745 {
|
|
1746 display_rows = row;
|
|
1747 done = 1;
|
|
1748 }
|
|
1749 ++row;
|
428
|
1750 x = INDENT ;
|
|
1751 y += tw->tabs.tab_height ;
|
|
1752 }
|
|
1753 if( !query_only ) {
|
|
1754 tab->tabs.x = x ;
|
|
1755 tab->tabs.y = y ;
|
|
1756 tab->tabs.row = row ;
|
|
1757 }
|
|
1758 x += w + SPACING ;
|
446
|
1759 if (!query_only && !done)
|
|
1760 tab->tabs.visible = 1;
|
|
1761
|
428
|
1762 }
|
442
|
1763 /* If there was only one row, increase the height by TABDELTA */
|
446
|
1764 if( ++display_rows == 1 )
|
428
|
1765 {
|
446
|
1766 row++;
|
428
|
1767 y = TABDELTA ;
|
|
1768 if( !query_only )
|
|
1769 for(i=num_children, childP=tw->composite.children;
|
|
1770 --i >= 0 ; ++childP)
|
|
1771 if( XtIsManaged(*childP) )
|
|
1772 {
|
|
1773 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1774 tab->tabs.y = y ;
|
|
1775 }
|
|
1776 }
|
|
1777 y += tw->tabs.tab_height ;
|
|
1778 }
|
|
1779 else
|
446
|
1780 display_rows = row = y = 0 ;
|
428
|
1781
|
|
1782 if( !query_only ) {
|
|
1783 tw->tabs.tab_total = y ;
|
446
|
1784 tw->tabs.numRows = display_rows ;
|
|
1785 tw->tabs.realRows = row;
|
428
|
1786 }
|
|
1787
|
|
1788 if( reply_height != NULL )
|
|
1789 *reply_height = y ;
|
|
1790
|
446
|
1791 return display_rows ;
|
428
|
1792 }
|
|
1793
|
|
1794
|
|
1795
|
|
1796 /* Find max preferred child size. Returned sizes include child
|
434
|
1797 * border widths.
|
428
|
1798 */
|
|
1799
|
|
1800 static void
|
|
1801 GetPreferredSizes(TabsWidget tw)
|
|
1802 {
|
434
|
1803 MaxChild(tw, NULL, 0,0) ;
|
428
|
1804 }
|
|
1805
|
|
1806
|
|
1807
|
|
1808 /* Find max preferred child size. Returned sizes include child
|
434
|
1809 * border widths. If except is non-null, don't ask that one.
|
|
1810 */
|
428
|
1811
|
|
1812 static void
|
434
|
1813 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
|
428
|
1814 {
|
434
|
1815 int i ;
|
|
1816 Widget *childP = tw->composite.children ;
|
|
1817 XtWidgetGeometry preferred ;
|
428
|
1818
|
|
1819 for(i=tw->composite.num_children; --i >=0; ++childP)
|
434
|
1820 if( XtIsManaged(*childP) && *childP != except )
|
428
|
1821 {
|
434
|
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 ) ;
|
428
|
1825 }
|
|
1826
|
|
1827 tw->tabs.max_cw = cw ;
|
|
1828 tw->tabs.max_ch = ch ;
|
|
1829 }
|
|
1830
|
|
1831
|
|
1832
|
|
1833 /* rotate row numbers to bring current widget to bottom row,
|
|
1834 * compute y positions for all tabs
|
|
1835 */
|
|
1836
|
|
1837 static void
|
|
1838 TabsShuffleRows(TabsWidget tw)
|
|
1839 {
|
|
1840 TabsConstraints tab ;
|
|
1841 int move ;
|
446
|
1842 int real_rows, display_rows ;
|
428
|
1843 Widget *childP ;
|
|
1844 Dimension th = tw->tabs.tab_height ;
|
|
1845 Position bottom ;
|
|
1846 int i ;
|
|
1847
|
|
1848 /* There must be a top widget. If not, assign one. */
|
|
1849 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
|
446
|
1850 for(i=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
1851 --i >= 0;
|
|
1852 ++childP)
|
|
1853 if( XtIsManaged(*childP) ) {
|
|
1854 tw->tabs.topWidget = *childP ;
|
|
1855 break ;
|
|
1856 }
|
|
1857
|
|
1858 if( tw->tabs.topWidget != NULL )
|
|
1859 {
|
446
|
1860 display_rows = tw->tabs.numRows ;
|
|
1861 real_rows = tw->tabs.realRows ;
|
|
1862 assert( display_rows >= real_rows ) ;
|
428
|
1863
|
446
|
1864 if( real_rows > 1 )
|
428
|
1865 {
|
|
1866 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
|
|
1867 assert( tab != NULL ) ;
|
|
1868
|
446
|
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 ;
|
|
1872 if (move < 0)
|
|
1873 move = real_rows - move;
|
428
|
1874 bottom = tw->tabs.tab_total - th ;
|
|
1875
|
446
|
1876 for(i=tw->composite.num_children, childP=tw->composite.children;
|
428
|
1877 --i >= 0;
|
|
1878 ++childP)
|
|
1879 if( XtIsManaged(*childP) )
|
|
1880 {
|
|
1881 tab = (TabsConstraints) (*childP)->core.constraints ;
|
446
|
1882 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
|
428
|
1883 tab->tabs.y = bottom - tab->tabs.row * th ;
|
446
|
1884 tab->tabs.visible = (tab->tabs.row < display_rows);
|
428
|
1885 }
|
|
1886 }
|
|
1887 }
|
|
1888 }
|
|
1889
|
|
1890
|
434
|
1891 /* Find preferred size. Ask children, find size of largest,
|
428
|
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.
|
434
|
1895 *
|
|
1896 * This function requires that max_cw, max_ch already be set.
|
428
|
1897 */
|
|
1898 static int
|
|
1899 PreferredSize(
|
|
1900 TabsWidget tw,
|
|
1901 Dimension *reply_width, /* total widget size */
|
|
1902 Dimension *reply_height,
|
|
1903 Dimension *reply_cw, /* child widget size */
|
|
1904 Dimension *reply_ch)
|
|
1905 {
|
|
1906 Dimension cw,ch ; /* child width, height */
|
|
1907 Dimension wid,hgt ;
|
|
1908 Dimension rwid,rhgt ;
|
|
1909 int nrow ;
|
|
1910
|
|
1911 wid = cw = tw->tabs.max_cw ;
|
|
1912 hgt = ch = tw->tabs.max_ch ;
|
|
1913
|
|
1914 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
|
|
1915
|
|
1916 /* Check for absurd results (more than 2 rows, high aspect
|
|
1917 * ratio). Try wider size if needed.
|
|
1918 * TODO: make sure this terminates.
|
|
1919 */
|
|
1920
|
|
1921 if( nrow > 2 && rhgt > rwid )
|
|
1922 {
|
|
1923 Dimension w0, w1 ;
|
434
|
1924 int maxloop = 20 ;
|
428
|
1925
|
|
1926 /* step 1: start doubling size until it's too big */
|
|
1927 do {
|
|
1928 w0 = wid ;
|
|
1929 wid = Max(wid*2, wid+20) ;
|
|
1930 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
1931 } while( nrow > 2 && rhgt > rwid ) ;
|
|
1932 w1 = wid ;
|
|
1933
|
|
1934 /* step 2: use Newton's method to find ideal size. Stop within
|
|
1935 * 8 pixels.
|
|
1936 */
|
434
|
1937 while( --maxloop > 0 && w1 > w0 + 8 )
|
428
|
1938 {
|
|
1939 wid = (w0+w1)/2 ;
|
|
1940 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
1941 if( nrow > 2 && rhgt > rwid )
|
|
1942 w0 = wid ;
|
|
1943 else
|
|
1944 w1 = wid ;
|
|
1945 }
|
|
1946 wid = w1 ;
|
|
1947 }
|
|
1948
|
|
1949 *reply_width = rwid ;
|
|
1950 *reply_height = rhgt ;
|
|
1951 if( reply_cw != NULL ) *reply_cw = cw ;
|
|
1952 if( reply_ch != NULL ) *reply_ch = ch ;
|
|
1953 return nrow ;
|
|
1954 }
|
|
1955
|
|
1956
|
|
1957 /* Find preferred size, given size of children. */
|
|
1958
|
|
1959 static int
|
|
1960 PreferredSize2(
|
|
1961 TabsWidget tw,
|
|
1962 int cw, /* child width, height */
|
|
1963 int ch,
|
|
1964 Dimension *reply_width, /* total widget size */
|
|
1965 Dimension *reply_height)
|
|
1966 {
|
|
1967 Dimension s = SHADWID ;
|
|
1968
|
|
1969 /* make room for shadow frame */
|
|
1970 cw += s*2 ;
|
|
1971 ch += s*2 ;
|
|
1972
|
|
1973 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
|
|
1974 }
|
|
1975
|
|
1976
|
|
1977 /* Find preferred size, given size of children+shadow. */
|
|
1978
|
|
1979 static int
|
|
1980 PreferredSize3(
|
|
1981 TabsWidget tw,
|
|
1982 int wid, /* child width, height */
|
|
1983 int hgt,
|
|
1984 Dimension *reply_width, /* total widget size */
|
|
1985 Dimension *reply_height)
|
|
1986 {
|
|
1987 Dimension th ; /* space used by tabs */
|
|
1988 int nrows ;
|
|
1989
|
|
1990 if( tw->composite.num_children > 0 )
|
|
1991 nrows = TabLayout(tw, wid, hgt, &th, True) ;
|
|
1992 else {
|
|
1993 th = 0 ;
|
|
1994 nrows = 0 ;
|
|
1995 }
|
|
1996
|
|
1997 *reply_width = Max(wid, MIN_WID) ;
|
|
1998 *reply_height = Max(th+hgt, MIN_HGT) ;
|
|
1999
|
|
2000 return nrows ;
|
|
2001 }
|
|
2002
|
|
2003
|
|
2004 static void
|
|
2005 MakeSizeRequest(TabsWidget tw)
|
|
2006 {
|
|
2007 Widget w = (Widget)tw ;
|
|
2008 XtWidgetGeometry request, reply ;
|
|
2009 XtGeometryResult result ;
|
|
2010 Dimension cw,ch ;
|
|
2011
|
|
2012 request.request_mode = CWWidth | CWHeight ;
|
|
2013 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
|
|
2014
|
|
2015 if( request.width == tw->core.width &&
|
|
2016 request.height == tw->core.height )
|
|
2017 return ;
|
|
2018
|
|
2019 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
2020
|
|
2021 if( result == XtGeometryAlmost )
|
|
2022 {
|
|
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.
|
|
2028 */
|
|
2029
|
|
2030 if( reply.width < request.width && reply.height >= request.height )
|
|
2031 {
|
|
2032 Dimension s = SHADWID ;
|
|
2033 ch += s*2 ;
|
|
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) ;
|
|
2038 }
|
|
2039
|
|
2040 else
|
|
2041 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
2042 }
|
|
2043 }
|
|
2044
|
|
2045
|
|
2046 static void
|
|
2047 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
|
|
2048 {
|
|
2049 Window root ;
|
|
2050 int x,y ;
|
|
2051 unsigned int bw ;
|
|
2052
|
|
2053 if( tab->tabs.left_bitmap == None ||
|
|
2054 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
|
434
|
2055 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
|
428
|
2056 &bw, &tab->tabs.lbm_depth) )
|
|
2057 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
|
|
2058 }
|
|
2059
|
|
2060
|
|
2061
|
|
2062
|
|
2063 /* Code copied & modified from Gcs.c. This version has dynamic
|
|
2064 * foreground.
|
|
2065 */
|
|
2066
|
|
2067 static void
|
|
2068 TabsAllocFgGC(TabsWidget tw)
|
|
2069 {
|
|
2070 Widget w = (Widget) tw;
|
|
2071 XGCValues values ;
|
|
2072
|
|
2073 values.background = tw->core.background_pixel ;
|
|
2074 values.font = tw->tabs.font->fid ;
|
|
2075 values.line_style = LineOnOffDash ;
|
|
2076 values.line_style = LineSolid ;
|
|
2077
|
|
2078 tw->tabs.foregroundGC =
|
|
2079 XtAllocateGC(w, w->core.depth,
|
|
2080 GCBackground|GCFont|GCLineStyle, &values,
|
|
2081 GCForeground,
|
|
2082 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2083 GCDashList|GCArcMode) ;
|
|
2084 }
|
|
2085
|
|
2086 static void
|
|
2087 TabsAllocGreyGC(TabsWidget tw)
|
|
2088 {
|
|
2089 Widget w = (Widget) tw;
|
|
2090 XGCValues values ;
|
|
2091
|
|
2092 values.background = tw->core.background_pixel ;
|
|
2093 values.font = tw->tabs.font->fid ;
|
|
2094 #ifdef HAVE_XMU
|
|
2095 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
|
|
2096 {
|
|
2097 values.fill_style = FillStippled ;
|
|
2098 tw->tabs.grey50 =
|
|
2099 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
|
|
2100
|
|
2101 tw->tabs.greyGC =
|
|
2102 XtAllocateGC(w, w->core.depth,
|
|
2103 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
|
|
2104 GCForeground,
|
|
2105 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2106 GCDashList|GCArcMode) ;
|
|
2107 }
|
|
2108 else
|
|
2109 #endif
|
|
2110 {
|
|
2111 tw->tabs.greyGC =
|
|
2112 XtAllocateGC(w, w->core.depth,
|
|
2113 GCFont, &values,
|
|
2114 GCForeground,
|
|
2115 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2116 GCDashList|GCArcMode) ;
|
|
2117 }
|
|
2118 }
|