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
|
428
|
21 /*
|
|
22 * Tabs.c - Index Tabs composite widget
|
|
23 *
|
|
24 * Author: Edward A. Falk
|
|
25 * falk@falconer.vip.best.com
|
|
26 *
|
|
27 * Date: July 29, 1997
|
|
28 *
|
|
29 *
|
|
30 * Overall layout of this widget is as follows:
|
|
31 *
|
|
32 * ________ ,---------. _________
|
|
33 * | label || Label || Label | \ tabs
|
|
34 * |________|| ||_________| /
|
|
35 * |+----------------------------+| \
|
|
36 * || || |
|
|
37 * || child widget window || > frame
|
|
38 * |+----------------------------+| |
|
|
39 * +------------------------------+ /
|
|
40 *
|
|
41 * The height of the tabs includes the shadow width, top and bottom
|
|
42 * margins, and the height of the text.
|
|
43 *
|
|
44 * The height of the frame includes the top and bottom shadow width and the
|
|
45 * size of the child widget window.
|
|
46 *
|
|
47 * The tabs overlap the frame and each other vertically by the shadow
|
|
48 * width, so that when the topmost tab is drawn, it obliterates part of
|
|
49 * the frame.
|
|
50 */
|
|
51
|
3094
|
52 /* Synched up with: Tabs.c 1.27.
|
|
53
|
|
54 This file contains essential XEmacs-related fixes to the original
|
|
55 version of the Tabs widget. Be VERY careful about syncing if you ever
|
|
56 update to a more recent version. In general this is probably now a
|
|
57 bad idea.
|
|
58
|
|
59 #### We need to check that various windows (the whole widget, or a single
|
|
60 tab) are of "reasonable" size, ie, we need to try for more sanity in the
|
|
61 geometry management routines.
|
|
62 */
|
|
63
|
434
|
64 /*
|
|
65 * TODO: min child height = tab height
|
428
|
66 */
|
|
67
|
|
68 #include <config.h>
|
|
69 #include <stdio.h>
|
|
70
|
|
71 #include <X11/Xlib.h>
|
|
72 #include <X11/IntrinsicP.h>
|
|
73 #include <X11/StringDefs.h>
|
448
|
74
|
3094
|
75 /* #### This may be risky, lwlib-internal.h redefines abort() */
|
|
76 #include "lwlib-fonts.h"
|
|
77 #include "lwlib-colors.h"
|
448
|
78 #include "lwlib-internal.h"
|
428
|
79 #include "../src/xmu.h"
|
|
80 #include "xlwtabsP.h"
|
|
81 #include "xlwgcs.h"
|
|
82
|
3094
|
83 #define XFT_USE_HEIGHT_NOT_ASCENT_DESCENT 0
|
|
84
|
|
85 /* #### These should probably be resources. */
|
428
|
86 #define MIN_WID 10
|
|
87 #define MIN_HGT 10
|
|
88 #define INDENT 3 /* tabs indented from edge by this much */
|
|
89 #define SPACING 0 /* distance between tabs */
|
|
90 #define SHADWID 1 /* default shadow width */
|
|
91 #define TABDELTA 2 /* top tab grows this many pixels */
|
|
92 #define TABLDELTA 2 /* top tab label offset this many pixels */
|
|
93
|
|
94
|
|
95 /****************************************************************
|
|
96 *
|
|
97 * IndexTabs Resources
|
|
98 *
|
|
99 ****************************************************************/
|
|
100
|
|
101 static char defaultTranslations[] = "\
|
|
102 <BtnUp>: select() \n\
|
|
103 <FocusIn>: highlight() \n\
|
|
104 <FocusOut>: unhighlight() \n\
|
|
105 <Key>Page_Up: page(up) \n\
|
|
106 <Key>KP_Page_Up: page(up) \n\
|
|
107 <Key>Prior: page(up) \n\
|
|
108 <Key>KP_Prior: page(up) \n\
|
|
109 <Key>Page_Down: page(down) \n\
|
|
110 <Key>KP_Page_Down: page(down) \n\
|
|
111 <Key>Next: page(down) \n\
|
|
112 <Key>KP_Next: page(down) \n\
|
|
113 <Key>Home: page(home) \n\
|
|
114 <Key>KP_Home: page(home) \n\
|
|
115 <Key>End: page(end) \n\
|
|
116 <Key>KP_End: page(end) \n\
|
|
117 <Key>Up: highlight(up) \n\
|
|
118 <Key>KP_Up: highlight(up) \n\
|
|
119 <Key>Down: highlight(down) \n\
|
|
120 <Key>KP_Down: highlight(down) \n\
|
|
121 <Key> : page(select) \n\
|
|
122 " ;
|
|
123
|
|
124 static char accelTable[] = " #augment\n\
|
|
125 <Key>Page_Up: page(up) \n\
|
|
126 <Key>KP_Page_Up: page(up) \n\
|
|
127 <Key>Prior: page(up) \n\
|
|
128 <Key>KP_Prior: page(up) \n\
|
|
129 <Key>Page_Down: page(down) \n\
|
|
130 <Key>KP_Page_Down: page(down) \n\
|
|
131 <Key>Next: page(down) \n\
|
|
132 <Key>KP_Next: page(down) \n\
|
|
133 <Key>Home: page(home) \n\
|
|
134 <Key>KP_Home: page(home) \n\
|
|
135 <Key>End: page(end) \n\
|
|
136 <Key>KP_End: page(end) \n\
|
|
137 <Key>Up: highlight(up) \n\
|
|
138 <Key>KP_Up: highlight(up) \n\
|
|
139 <Key>Down: highlight(down) \n\
|
|
140 <Key>KP_Down: highlight(down) \n\
|
|
141 <Key> : page(select) \n\
|
|
142 " ;
|
446
|
143 static XtAccelerators defaultAccelerators ; /* #### Never used */
|
428
|
144
|
|
145 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
|
|
146 static XtResource resources[] = {
|
|
147
|
|
148 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
|
|
149 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
|
|
150 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
|
|
151 offset(font), XtRString, (XtPointer) XtDefaultFont},
|
3094
|
152 #ifdef USE_XFT_TABS
|
3397
|
153 /* #### Maybe use "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1" here?
|
|
154 or XtDefaultFont? */
|
|
155 {XtNfcFontName, XtCFcFontName, XtRString, sizeof(String),
|
3685
|
156 offset(fcFontName), XtRString, (XtPointer) NULL },
|
3397
|
157 /* #### This needs to be fixed to give a proper type and converter for
|
|
158 XftFonts. See also xlwmenu.c. */
|
3685
|
159 {XtNxftFont, XtCXftFont, XtRString, sizeof(String),
|
|
160 offset(xftFontName), XtRString, (XtPointer) "Helvetica-12" },
|
3094
|
161 #endif
|
428
|
162 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
|
|
163 offset(internalWidth), XtRImmediate, (XtPointer)4 },
|
|
164 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
|
|
165 offset(internalHeight), XtRImmediate, (XtPointer)4 },
|
|
166 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
|
|
167 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
|
|
168 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
|
|
169 offset(topWidget), XtRImmediate, NULL},
|
|
170 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
171 offset(callbacks), XtRCallback, NULL},
|
|
172 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
173 offset(popdownCallbacks), XtRCallback, NULL},
|
|
174 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
|
|
175 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
|
|
176 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
|
|
177 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
|
|
178 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
|
|
179 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
|
|
180 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
|
|
181 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
|
|
182 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
|
|
183 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
|
|
184 };
|
|
185 #undef offset
|
|
186
|
|
187
|
|
188
|
|
189 /* constraint resources */
|
|
190
|
|
191 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
|
|
192 static XtResource tabsConstraintResources[] = {
|
|
193 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
|
|
194 offset(label), XtRString, NULL},
|
|
195 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
|
|
196 offset(left_bitmap), XtRImmediate, None},
|
|
197 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
|
|
198 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
|
|
199 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
|
|
200 offset(resizable), XtRImmediate, (XtPointer) True},
|
|
201 } ;
|
|
202 #undef offset
|
|
203
|
|
204
|
|
205
|
|
206
|
|
207 #if !NeedFunctionPrototypes
|
|
208
|
|
209 /* FORWARD REFERENCES: */
|
|
210
|
|
211 /* member functions */
|
|
212
|
|
213 static void TabsClassInit();
|
|
214 static void TabsInit();
|
|
215 static void TabsResize();
|
|
216 static void TabsExpose();
|
|
217 static void TabsDestroy();
|
|
218 static void TabsRealize();
|
|
219 static Boolean TabsSetValues();
|
434
|
220 static Boolean TabsAcceptFocus();
|
428
|
221 static XtGeometryResult TabsQueryGeometry();
|
|
222 static XtGeometryResult TabsGeometryManager();
|
|
223 static void TabsChangeManaged();
|
|
224 static void TabsConstraintInitialize() ;
|
|
225 static Boolean TabsConstraintSetValues() ;
|
|
226
|
|
227 /* action procs */
|
|
228
|
|
229 static void TabsSelect() ;
|
|
230 static void TabsPage() ;
|
|
231 static void TabsHighlight() ;
|
|
232 static void TabsUnhighlight() ;
|
|
233
|
|
234 /* internal privates */
|
|
235
|
|
236 static void TabsAllocGCs() ; /* get rendering GCs */
|
|
237 static void TabsFreeGCs() ; /* return rendering GCs */
|
|
238 static void DrawTabs() ; /* draw all tabs */
|
|
239 static void DrawTab() ; /* draw one index tab */
|
|
240 static void DrawFrame() ; /* draw frame around contents */
|
|
241 static void DrawTrim() ; /* draw trim around a tab */
|
|
242 static void DrawBorder() ; /* draw border */
|
|
243 static void DrawHighlight() ; /* draw highlight */
|
|
244 static void UndrawTab() ; /* undraw interior of a tab */
|
|
245 static void TabWidth() ; /* recompute tab size */
|
|
246 static void GetPreferredSizes() ; /* query all children for their sizes */
|
|
247 static void MaxChild() ; /* find max preferred child size */
|
|
248 static int PreferredSize() ; /* compute preferred size */
|
|
249 static int PreferredSize2() ; /* compute preferred size */
|
|
250 static int PreferredSize3() ; /* compute preferred size */
|
|
251 static void MakeSizeRequest() ; /* try to change size */
|
|
252 static void getBitmapInfo() ;
|
|
253 static int TabLayout() ; /* lay out tabs */
|
|
254 static void TabsShuffleRows() ; /* bring current tab to bottom row */
|
|
255
|
|
256 static void TabsAllocFgGC() ;
|
|
257 static void TabsAllocGreyGC() ;
|
|
258
|
|
259 #else
|
|
260
|
|
261 static void TabsClassInit(void) ;
|
3025
|
262 static void TabsInit( Widget req, Widget new_, ArgList, Cardinal *nargs) ;
|
428
|
263 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
|
|
264 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
|
|
265 static void TabsDestroy( Widget w) ;
|
|
266 static void TabsResize( Widget w) ;
|
|
267 static void TabsExpose( Widget w, XEvent *event, Region region) ;
|
|
268 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
|
434
|
269 static Boolean TabsAcceptFocus(Widget, Time *);
|
428
|
270 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
|
|
271 ArgList, Cardinal *) ;
|
|
272 static XtGeometryResult TabsQueryGeometry(Widget,
|
|
273 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
274 static XtGeometryResult TabsGeometryManager(Widget,
|
|
275 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
276 static void TabsChangeManaged( Widget w) ;
|
|
277
|
|
278 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
|
|
279 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
|
|
280 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
281 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
282
|
|
283 static void DrawTabs( TabsWidget tw, Bool labels) ;
|
|
284 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
|
|
285 static void DrawFrame( TabsWidget tw) ;
|
|
286 static void DrawTrim( TabsWidget, int x, int y,
|
|
287 int wid, int hgt, Bool bottom, Bool undraw) ;
|
|
288 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
|
|
289 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
|
|
290 static void UndrawTab( TabsWidget tw, Widget child) ;
|
|
291
|
|
292 static void TabWidth( Widget w) ;
|
448
|
293 static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt,
|
428
|
294 Bool query_only) ;
|
|
295 static void GetPreferredSizes(TabsWidget) ;
|
434
|
296 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
|
428
|
297 static void TabsShuffleRows( TabsWidget tw) ;
|
|
298 static int PreferredSize( TabsWidget,
|
|
299 Dimension *reply_width, Dimension *reply_height,
|
|
300 Dimension *reply_cw, Dimension *reply_ch) ;
|
448
|
301 static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch,
|
428
|
302 Dimension *rw, Dimension *rh) ;
|
448
|
303 static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt,
|
428
|
304 Dimension *rw, Dimension *rh) ;
|
|
305 static void MakeSizeRequest(TabsWidget) ;
|
|
306
|
|
307 static void TabsAllocGCs(TabsWidget) ;
|
|
308 static void TabsFreeGCs(TabsWidget) ;
|
|
309 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
|
|
310 static void TabsAllocFgGC( TabsWidget tw) ;
|
|
311 static void TabsAllocGreyGC( TabsWidget tw) ;
|
|
312
|
|
313 #endif
|
|
314
|
|
315 #define AddRect(i,xx,yy,w,h) \
|
|
316 do{rects[(i)].x=(xx); rects[i].y=(yy); \
|
|
317 rects[i].width=(w); rects[i].height=(h);}while(0)
|
|
318
|
|
319 static XtActionsRec actionsList[] =
|
|
320 {
|
|
321 {"select", TabsSelect},
|
|
322 {"page", TabsPage},
|
|
323 {"highlight", TabsHighlight},
|
|
324 {"unhighlight", TabsUnhighlight},
|
|
325 } ;
|
|
326
|
|
327
|
|
328 /****************************************************************
|
|
329 *
|
|
330 * Full class record constant
|
|
331 *
|
|
332 ****************************************************************/
|
|
333
|
|
334 #ifndef NEED_MOTIF
|
|
335 #define SuperClass (&constraintClassRec)
|
|
336 #else
|
|
337 #define SuperClass (&xmManagerClassRec)
|
|
338 #endif
|
|
339
|
|
340 TabsClassRec tabsClassRec = {
|
|
341 {
|
|
342 /* core_class fields */
|
|
343 /* superclass */ (WidgetClass) SuperClass,
|
|
344 /* class_name */ "Tabs",
|
|
345 /* widget_size */ sizeof(TabsRec),
|
|
346 /* class_initialize */ TabsClassInit,
|
|
347 /* class_part_init */ NULL, /* TODO? */
|
|
348 /* class_inited */ FALSE,
|
|
349 /* initialize */ TabsInit,
|
|
350 /* initialize_hook */ NULL,
|
|
351 /* realize */ TabsRealize,
|
|
352 /* actions */ actionsList,
|
|
353 /* num_actions */ XtNumber(actionsList),
|
|
354 /* resources */ resources,
|
|
355 /* num_resources */ XtNumber(resources),
|
|
356 /* xrm_class */ NULLQUARK,
|
|
357 /* compress_motion */ TRUE,
|
434
|
358 #if XtSpecificationRelease < 6
|
|
359 /* compress_exposure */ XtExposeCompressMaximal,
|
|
360 #else
|
|
361 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
|
|
362 #endif
|
428
|
363 /* compress_enterleave*/ TRUE,
|
434
|
364 /* visible_interest */ TRUE,
|
428
|
365 /* destroy */ TabsDestroy,
|
|
366 /* resize */ TabsResize,
|
|
367 /* expose */ TabsExpose,
|
|
368 /* set_values */ TabsSetValues,
|
|
369 /* set_values_hook */ NULL,
|
|
370 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
371 /* get_values_hook */ NULL,
|
434
|
372 /* accept_focus */ TabsAcceptFocus,
|
428
|
373 /* version */ XtVersion,
|
|
374 /* callback_private */ NULL,
|
|
375 /* tm_table */ defaultTranslations,
|
|
376 /* query_geometry */ TabsQueryGeometry,
|
|
377 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
378 /* extension */ NULL
|
|
379 },
|
|
380 {
|
|
381 /* composite_class fields */
|
|
382 /* geometry_manager */ TabsGeometryManager,
|
|
383 /* change_managed */ TabsChangeManaged,
|
|
384 /* insert_child */ XtInheritInsertChild, /* TODO? */
|
|
385 /* delete_child */ XtInheritDeleteChild, /* TODO? */
|
|
386 /* extension */ NULL
|
|
387 },
|
|
388 {
|
|
389 /* constraint_class fields */
|
|
390 /* subresources */ tabsConstraintResources,
|
|
391 /* subresource_count */ XtNumber(tabsConstraintResources),
|
|
392 /* constraint_size */ sizeof(TabsConstraintsRec),
|
|
393 /* initialize */ TabsConstraintInitialize,
|
|
394 /* destroy */ NULL,
|
|
395 /* set_values */ TabsConstraintSetValues,
|
|
396 /* extension */ NULL,
|
|
397 },
|
|
398 #ifdef NEED_MOTIF
|
|
399 /* Manager Class fields */
|
|
400 {
|
|
401 /* translations */ NULL,
|
|
402 /* syn_resources */ NULL,
|
|
403 /* num_syn_resources */ 0,
|
|
404 /* syn_constraint_resources */ NULL,
|
|
405 /* num_syn_constraint_resources */ 0,
|
|
406 /* parent_process */ XmInheritParentProcess,
|
|
407 /* extension */ NULL
|
|
408 },
|
|
409 #endif
|
|
410 {
|
|
411 /* Tabs class fields */
|
|
412 /* extension */ NULL,
|
|
413 }
|
|
414 };
|
|
415
|
|
416 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
|
|
417
|
446
|
418 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
|
|
419 #define TabVisible(tab) \
|
|
420 (XtIsManaged(tab) && \
|
|
421 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
|
428
|
422
|
|
423
|
3094
|
424
|
|
425 static int debug_tabs = 0; /* increase for more verbosity */
|
|
426
|
|
427 #ifdef USE_XFT_TABS
|
|
428 /* #### duplicated from xlwmenu.c -- CLEAN THIS SHIT UP!
|
|
429 Undeclared so define at top. */
|
|
430 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
431 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
432
|
|
433 static int
|
|
434 x_xft_text_width (Display *dpy, XftFont *xft_font, FcChar8 *run, int len)
|
|
435 {
|
|
436 static XGlyphInfo glyphinfo; /* #### static? */
|
|
437
|
|
438 XftTextExtents8 (dpy,
|
|
439 xft_font,
|
|
440 run, len, &glyphinfo);
|
|
441 return glyphinfo.xOff;
|
|
442 }
|
|
443 #endif
|
|
444
|
428
|
445 /****************************************************************
|
|
446 *
|
|
447 * Member Procedures
|
|
448 *
|
|
449 ****************************************************************/
|
|
450
|
|
451 static void
|
|
452 TabsClassInit(void)
|
|
453 {
|
|
454 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
|
|
455 /* TODO: register converter for labels? */
|
|
456 }
|
|
457
|
|
458
|
|
459
|
|
460 /* Init a newly created tabs widget. Compute height of tabs
|
|
461 * and optionally compute size of widget. */
|
|
462
|
|
463 /* ARGSUSED */
|
|
464
|
|
465 static void
|
3025
|
466 TabsInit(Widget request, Widget new_, ArgList UNUSED (args),
|
2286
|
467 Cardinal *UNUSED (num_args))
|
428
|
468 {
|
3025
|
469 TabsWidget newTw = (TabsWidget)new_;
|
428
|
470
|
|
471 newTw->tabs.numRows = 0 ;
|
446
|
472 newTw->tabs.realRows = 0;
|
428
|
473
|
|
474 GetPreferredSizes(newTw) ;
|
|
475
|
|
476 /* height is easy, it's the same for all tabs:
|
|
477 * TODO: font height + height of tallest bitmap.
|
|
478 */
|
|
479 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
|
|
480
|
3094
|
481 #ifdef USE_XFT_TABS
|
3685
|
482 /* #### kludge for name change */
|
|
483 if (!newTw->tabs.fcFontName)
|
|
484 newTw->tabs.fcFontName = newTw->tabs.xftFontName;
|
3094
|
485 /* must get font here
|
3685
|
486 #### to do this right, we should add a new Xt Resource type +
|
|
487 conversion function */
|
3094
|
488 newTw->tabs.renderFont =
|
|
489 xft_open_font_by_name (XtDisplay ((Widget) newTw),
|
3397
|
490 newTw->tabs.fcFontName);
|
3094
|
491 if (newTw->tabs.renderFont != NULL)
|
|
492 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT
|
|
493 newTw->tabs.tab_height += newTw->tabs.renderFont->height;
|
|
494 #else
|
|
495 newTw->tabs.tab_height += newTw->tabs.renderFont->ascent +
|
|
496 newTw->tabs.renderFont->descent;
|
|
497 #endif /* XFT_USE_HEIGHT_NOT_ASCENT_DESCENT */
|
|
498 #else /* ! USE_XFT_TABS */
|
|
499 if (newTw->tabs.font != NULL)
|
428
|
500 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
|
3094
|
501 newTw->tabs.font->max_bounds.descent;
|
|
502 #endif /* ! USE_XFT_TABS */
|
428
|
503
|
|
504 /* if size not explicitly set, set it to our preferred size now. */
|
|
505
|
|
506 if( request->core.width == 0 || request->core.height == 0 )
|
|
507 {
|
|
508 Dimension w,h ;
|
|
509 PreferredSize(newTw, &w, &h, NULL,NULL) ;
|
3025
|
510 if( request->core.width == 0 ) new_->core.width = w ;
|
|
511 if( request->core.height == 0 ) new_->core.height = h ;
|
|
512 XtClass(new_)->core_class.resize(new_) ;
|
428
|
513 }
|
|
514
|
|
515 /* defer GC allocation, etc., until Realize() time. */
|
|
516 newTw->tabs.foregroundGC =
|
|
517 newTw->tabs.backgroundGC =
|
|
518 newTw->tabs.greyGC =
|
|
519 newTw->tabs.topGC =
|
|
520 newTw->tabs.botGC = None ;
|
|
521
|
|
522 newTw->tabs.grey50 = None ;
|
|
523
|
|
524 newTw->tabs.needs_layout = False ;
|
434
|
525
|
428
|
526 newTw->tabs.hilight = NULL ;
|
|
527
|
|
528 #ifdef NEED_MOTIF
|
|
529 newTw->manager.navigation_type = XmTAB_GROUP ;
|
|
530 newTw->manager.traversal_on = True ;
|
|
531 #endif
|
|
532 }
|
|
533
|
|
534
|
|
535 /* Init the constraint part of a new tab child. Compute the
|
|
536 * size of the tab.
|
|
537 */
|
|
538 /* ARGSUSED */
|
|
539 static void
|
3025
|
540 TabsConstraintInitialize(Widget UNUSED (request), Widget new_,
|
2286
|
541 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
542 {
|
3025
|
543 TabsConstraints tab = (TabsConstraints) new_->core.constraints ;
|
428
|
544 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
|
446
|
545 tab->tabs.visible = False ;
|
428
|
546
|
3025
|
547 getBitmapInfo((TabsWidget)XtParent(new_), tab) ;
|
|
548 TabWidth(new_) ;
|
428
|
549 }
|
|
550
|
|
551
|
|
552
|
|
553 /* Called when tabs widget first realized. Create the window
|
|
554 * and allocate the GCs
|
|
555 */
|
|
556
|
|
557 static void
|
|
558 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
559 {
|
|
560 TabsWidget tw = (TabsWidget) w;
|
|
561
|
|
562 attributes->bit_gravity = NorthWestGravity;
|
|
563 *valueMask |= CWBitGravity;
|
|
564
|
|
565 SuperClass->core_class.realize(w, valueMask, attributes);
|
|
566
|
|
567 TabsAllocGCs(tw) ;
|
|
568 }
|
|
569
|
|
570
|
|
571
|
|
572 static void
|
|
573 TabsDestroy(Widget w)
|
|
574 {
|
4173
|
575 TabsWidget tw = (TabsWidget) w;
|
|
576 #ifdef USE_XFT_TABS
|
|
577 XftFontClose (XtDisplay (w), tw->tabs.renderFont);
|
|
578 #endif /* ! USE_XFT_TABS */
|
|
579 TabsFreeGCs (tw) ;
|
428
|
580 }
|
|
581
|
|
582
|
|
583 /* Parent has resized us. This will require that the tabs be
|
|
584 * laid out again.
|
|
585 */
|
|
586
|
|
587 static void
|
|
588 TabsResize(Widget w)
|
|
589 {
|
|
590 TabsWidget tw = (TabsWidget) w;
|
|
591 int i ;
|
|
592 int num_children = tw->composite.num_children ;
|
|
593 Widget *childP ;
|
2286
|
594 /* TabsConstraints tab ; */ /* #### unused */
|
428
|
595 Dimension cw,ch,bw ;
|
|
596
|
|
597 /* Our size has now been dictated by the parent. Lay out the
|
|
598 * tabs, lay out the frame, lay out the children. Remember
|
|
599 * that the tabs overlap each other and the frame by shadowWidth.
|
|
600 * Also, the top tab is larger than the others, so if there's only
|
|
601 * one row, the widget must be made taller to accommodate this.
|
|
602 *
|
|
603 * Once the tabs are laid out, if there is more than one
|
|
604 * row, we may need to shuffle the rows to bring the top tab
|
|
605 * to the bottom row.
|
|
606 */
|
|
607
|
434
|
608 tw->tabs.needs_layout = False ;
|
|
609
|
428
|
610 if( num_children > 0 && tw->composite.children != NULL )
|
|
611 {
|
|
612 /* Loop through the tabs and assign rows & x positions */
|
|
613 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
|
446
|
614 num_children = TabsNumChildren (tw);
|
428
|
615
|
|
616 /* assign a top widget, bring it to bottom row. */
|
|
617 TabsShuffleRows(tw) ;
|
|
618
|
|
619 /* now assign child positions & sizes. Positions are all the
|
|
620 * same: just inside the frame. Sizes are also all the same.
|
|
621 */
|
|
622
|
|
623 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
|
|
624 tw->tabs.child_height = ch =
|
448
|
625 tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 :
|
|
626 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
|
428
|
627
|
|
628 for(i=0, childP=tw->composite.children;
|
434
|
629 i < num_children;
|
428
|
630 ++i, ++childP)
|
448
|
631 if( XtIsManaged(*childP) )
|
428
|
632 {
|
2286
|
633 /* tab = (TabsConstraints) (*childP)->core.constraints ; */
|
434
|
634 bw = (*childP)->core.border_width ;
|
448
|
635 /* Don't do anything if we can't see any of the child. */
|
|
636 if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0)
|
|
637 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
|
|
638 cw-bw*2,ch-bw*2, bw) ;
|
428
|
639 }
|
434
|
640 if( XtIsRealized(w) ) {
|
|
641 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
642 /* should not be necessary to explicitly repaint after a
|
|
643 * resize, but XEmacs folks tell me it is.
|
|
644 */
|
|
645 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
646 }
|
428
|
647 }
|
|
648 } /* Resize */
|
|
649
|
|
650
|
|
651
|
|
652 /* Redraw entire Tabs widget */
|
|
653
|
|
654 /* ARGSUSED */
|
|
655 static void
|
2286
|
656 TabsExpose(Widget w, XEvent *UNUSED (event), Region UNUSED (region))
|
428
|
657 {
|
|
658 TabsWidget tw = (TabsWidget) w;
|
|
659
|
|
660 if( tw->tabs.needs_layout )
|
|
661 XtClass(w)->core_class.resize(w) ;
|
|
662
|
|
663 DrawTabs(tw, True) ;
|
|
664 }
|
|
665
|
|
666
|
|
667 /* Called when any Tabs widget resources are changed. */
|
|
668
|
|
669 /* ARGSUSED */
|
|
670 static Boolean
|
3025
|
671 TabsSetValues(Widget current, Widget UNUSED (request), Widget new_,
|
2286
|
672 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
673 {
|
430
|
674 TabsWidget curtw = (TabsWidget) current ;
|
3025
|
675 TabsWidget tw = (TabsWidget) new_ ;
|
430
|
676 Boolean needRedraw = False ;
|
|
677 Widget *childP ;
|
|
678 int i ;
|
428
|
679
|
3094
|
680 if(
|
|
681 #ifdef USE_XFT_TABS
|
|
682 tw->tabs.renderFont != curtw->tabs.renderFont ||
|
|
683 #else
|
|
684 tw->tabs.font != curtw->tabs.font ||
|
|
685 #endif
|
|
686 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
|
|
687 tw->tabs.internalHeight != curtw->tabs.internalHeight)
|
430
|
688 {
|
3094
|
689 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID;
|
428
|
690
|
3094
|
691 #ifdef USE_XFT_TABS
|
|
692 if (tw->tabs.renderFont != NULL)
|
|
693 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT
|
|
694 tw->tabs.tab_height += tw->tabs.renderFont->height;
|
|
695 #else
|
|
696 tw->tabs.tab_height += tw->tabs.renderFont->ascent +
|
|
697 tw->tabs.renderFont->descent;
|
|
698 #endif /* XFT_USE_HEIGHT_NOT_ASCENT_DESCENT */
|
|
699 #else /* ! USE_XFT_TABS */
|
|
700 if (tw->tabs.font != NULL)
|
430
|
701 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
|
3094
|
702 tw->tabs.font->max_bounds.descent;
|
|
703 #endif /* ! USE_XFT_TABS */
|
428
|
704
|
430
|
705 /* Tab size has changed. Resize all tabs and request a new size */
|
|
706 for(i=0, childP=tw->composite.children;
|
647
|
707 i < (int) tw->composite.num_children;
|
430
|
708 ++i, ++childP)
|
|
709 if( XtIsManaged(*childP) )
|
|
710 TabWidth(*childP) ;
|
|
711 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
|
|
712 needRedraw = True ;
|
|
713 tw->tabs.needs_layout = True ;
|
|
714 }
|
428
|
715
|
430
|
716 /* TODO: if any color changes, need to recompute GCs and redraw */
|
428
|
717
|
430
|
718 if( tw->core.background_pixel != curtw->core.background_pixel ||
|
432
|
719 tw->core.background_pixmap != curtw->core.background_pixmap ||
|
3094
|
720 #ifdef USE_XFT_TABS
|
|
721 tw->tabs.renderFont != curtw->tabs.renderFont
|
|
722 #else
|
|
723 tw->tabs.font != curtw->tabs.font
|
|
724 #endif
|
|
725 )
|
3025
|
726 if( XtIsRealized(new_) )
|
430
|
727 {
|
|
728 TabsFreeGCs(tw) ;
|
|
729 TabsAllocGCs(tw) ;
|
|
730 needRedraw = True ;
|
|
731 }
|
428
|
732
|
430
|
733 if( tw->core.sensitive != curtw->core.sensitive )
|
|
734 needRedraw = True ;
|
428
|
735
|
430
|
736 /* If top widget changes, need to change stacking order, redraw tabs.
|
|
737 * Window system will handle the redraws.
|
|
738 */
|
428
|
739
|
442
|
740 if( tw->tabs.topWidget != curtw->tabs.topWidget )
|
432
|
741 {
|
430
|
742 if( XtIsRealized(tw->tabs.topWidget) )
|
|
743 {
|
|
744 Widget w = tw->tabs.topWidget ;
|
|
745 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
428
|
746
|
430
|
747 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
428
|
748 #ifdef NEED_MOTIF
|
430
|
749 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
|
|
750 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
428
|
751 #endif
|
|
752
|
647
|
753 if( tab->tabs.row != (int) tw->tabs.numRows-1 )
|
430
|
754 TabsShuffleRows(tw) ;
|
428
|
755
|
430
|
756 needRedraw = True ;
|
|
757 }
|
|
758 else
|
|
759 tw->tabs.needs_layout = True ;
|
432
|
760 }
|
428
|
761
|
430
|
762 return needRedraw ;
|
428
|
763 }
|
|
764
|
|
765
|
|
766 /* Called when any child constraint resources change. */
|
|
767
|
|
768 /* ARGSUSED */
|
|
769 static Boolean
|
3025
|
770 TabsConstraintSetValues(Widget current, Widget UNUSED (request), Widget new_,
|
2286
|
771 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
772 {
|
3025
|
773 TabsWidget tw = (TabsWidget) XtParent(new_) ;
|
428
|
774 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
|
3025
|
775 TabsConstraints tab = (TabsConstraints) new_->core.constraints ;
|
428
|
776
|
|
777
|
|
778 /* if label changes, need to re-layout the entire widget */
|
|
779 /* if foreground changes, need to redraw tab label */
|
|
780
|
|
781 /* TODO: only need resize of new bitmap has different dimensions
|
|
782 * from old bitmap.
|
|
783 */
|
|
784
|
|
785 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
|
|
786 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
787 {
|
3025
|
788 TabWidth(new_) ;
|
428
|
789 tw->tabs.needs_layout = True ;
|
|
790
|
|
791 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
792 getBitmapInfo(tw, tab) ;
|
|
793
|
|
794 /* If there are no subclass ConstraintSetValues procedures remaining
|
|
795 * to be invoked, and if the preferred size has changed, ask
|
|
796 * for a resize.
|
|
797 */
|
|
798 if( XtClass((Widget)tw) == tabsWidgetClass )
|
|
799 MakeSizeRequest(tw) ;
|
|
800 }
|
|
801
|
|
802
|
|
803 /* The child widget itself never needs a redisplay, but the parent
|
|
804 * Tabs widget might.
|
|
805 */
|
|
806
|
3025
|
807 if( XtIsRealized(new_) )
|
428
|
808 {
|
|
809 if( tw->tabs.needs_layout ) {
|
|
810 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
811 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
812 }
|
|
813
|
|
814 else if( tab->tabs.foreground != ctab->tabs.foreground )
|
3025
|
815 DrawTab(tw, new_, True) ;
|
428
|
816 }
|
|
817
|
|
818 return False ;
|
|
819 }
|
|
820
|
|
821
|
434
|
822 static Boolean
|
2286
|
823 TabsAcceptFocus(Widget w, Time *UNUSED (t))
|
434
|
824 {
|
|
825 if( !w->core.being_destroyed && XtIsRealized(w) &&
|
|
826 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
|
|
827 {
|
|
828 Widget p ;
|
|
829 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
|
|
830 XtSetKeyboardFocus(p,w) ;
|
|
831 return True ;
|
|
832 }
|
|
833 else
|
|
834 return False ;
|
|
835 }
|
|
836
|
|
837
|
428
|
838
|
|
839 /*
|
3094
|
840 * Return status, with preferred size in PREFERRED.
|
|
841 *
|
|
842 * According to the X Toolkit Intrinsics manual
|
|
843 * XtGeometryYes = accept INTENDED without change
|
|
844 * XtGeometryNo = request to stay _exactly_ the same
|
|
845 * XtGeometryAlmost = suggest PREFERRED as a compromise
|
|
846 * and the PREFERRED argument must be filled in completely (ie, any fields
|
|
847 * whose bits are set in the request_mode mask must correspond to the
|
|
848 * preferred geometry, which must be consistent with the return value).
|
|
849 *
|
|
850 * Assuming horizontal orientation, in XEmacs, we should always accept if
|
|
851 * the width is more than we need. There's no problem if there are only a
|
|
852 * couple of tabs packed to the left. OTOH there's probably something wrong
|
|
853 * if we're offered a height more than 1.5x or 2x the preferred height.
|
|
854 * (#### Do tab controls do vertical?)
|
428
|
855 */
|
|
856
|
3094
|
857 /* compute the height above which we complain */
|
|
858 #define TAB_HEIGHT_TOLERANCE(x) (2*x)
|
|
859
|
428
|
860 static XtGeometryResult
|
3094
|
861 TabsQueryGeometry (Widget w,
|
|
862 XtWidgetGeometry *intended,
|
|
863 XtWidgetGeometry *preferred) /* RETURN */
|
428
|
864 {
|
3094
|
865 TabsWidget tw = (TabsWidget) w;
|
|
866 XtGeometryMask mode = intended->request_mode;
|
|
867
|
|
868 preferred->request_mode = CWWidth | CWHeight;
|
|
869 PreferredSize (tw, &preferred->width, &preferred->height, NULL, NULL);
|
428
|
870
|
3094
|
871 /* If width is big enough, accept it. */
|
|
872 if ((mode & CWWidth) && intended->width >= preferred->width)
|
|
873 preferred->width = intended->width;
|
428
|
874
|
3094
|
875 /* If height is within range, accept it.
|
|
876 #### If too tall, we could offer a compromise at TAB_HEIGHT_TOLERANCE.
|
|
877 Should we? */
|
|
878 if ((mode & CWHeight) && intended->height >= preferred->height
|
|
879 && intended->height <= TAB_HEIGHT_TOLERANCE (preferred->height))
|
|
880 preferred->height = intended->height;
|
428
|
881
|
3094
|
882 /* Compute return value. */
|
|
883 if (preferred->width == ((mode & CWWidth) ? intended->width
|
|
884 : w->core.width)
|
|
885 && preferred->height == ((mode & CWHeight) ? intended->height
|
|
886 : w->core.height))
|
428
|
887 return XtGeometryYes;
|
3094
|
888 else if (preferred->width == w->core.width
|
|
889 && preferred->height == w->core.height)
|
|
890 return XtGeometryNo;
|
|
891 else
|
|
892 return XtGeometryAlmost;
|
428
|
893 }
|
|
894
|
|
895
|
|
896
|
|
897 /*
|
3094
|
898 * Geometry Manager; called when TAB (a child) wants to be resized.
|
|
899 *
|
|
900 * According to the X Toolkit Intrinsics manual
|
|
901 * XtGeometryDone = accept REQUEST and do it (#### check this)
|
|
902 * XtGeometryYes = accept REQUEST without change
|
|
903 * XtGeometryNo = refuse REQUEST (ie, stay _exactly_ the same)
|
|
904 * XtGeometryAlmost = suggest REPLY as a compromise
|
428
|
905 */
|
|
906
|
|
907 static XtGeometryResult
|
3094
|
908 TabsGeometryManager (Widget tab,
|
|
909 XtWidgetGeometry *request,
|
|
910 XtWidgetGeometry *reply) /* RETURN */
|
428
|
911 {
|
3094
|
912 TabsWidget control = (TabsWidget) XtParent(tab);
|
|
913 Dimension s = SHADWID;
|
|
914 TabsConstraints constraint = (TabsConstraints) tab->core.constraints;
|
|
915 XtGeometryResult result, best_offer = XtGeometryYes;
|
|
916 Dimension rw, rh;
|
|
917
|
|
918 static int debug_count = 0;
|
|
919 static int debug_mask = 1;
|
|
920
|
|
921 /* Position request cannot be satisfied, so if tabs are not resizable,
|
|
922 no nontrivial request can be satisfied: return XGeometryNo. */
|
|
923 if (!constraint->tabs.resizable)
|
|
924 return XtGeometryNo;
|
|
925
|
|
926 fprintf (stderr, "Urk! label is resizable!\n");
|
428
|
927
|
3094
|
928 /* Assume we will refuse these; toggle iff we accept them.
|
|
929 Reply won't specify any fields not in the request. */
|
|
930 reply->request_mode = request->request_mode;
|
|
931 reply->x = tab->core.x;
|
|
932 reply->y = tab->core.y;
|
428
|
933
|
3094
|
934 /* If a position request would result in a change, best offer is
|
|
935 XtGeometryAlmost. Otherwise toggle reply->request_mode. */
|
|
936 if ((request->request_mode & CWX) && request->x != tab->core.x)
|
|
937 best_offer = XtGeometryAlmost;
|
|
938 else
|
|
939 reply->request_mode &= ~CWX;
|
|
940 if ((request->request_mode & CWY) && request->y != tab->core.y)
|
|
941 best_offer = XtGeometryAlmost;
|
|
942 else
|
|
943 reply->request_mode &= ~CWY;
|
428
|
944
|
3094
|
945 /* Make all three fields in the reply valid */
|
|
946 reply->width = (request->request_mode & CWWidth)
|
|
947 ? request->width : tab->core.width;
|
|
948 reply->height = (request->request_mode & CWHeight)
|
|
949 ? request->height : tab->core.height;
|
|
950 reply->border_width = (request->request_mode & CWBorderWidth)
|
|
951 ? request->border_width : tab->core.border_width;
|
|
952
|
|
953 /* check if we can already offer a compromise */
|
|
954 if (best_offer == XtGeometryAlmost &&
|
|
955 reply->width == tab->core.width &&
|
|
956 reply->height == tab->core.height &&
|
|
957 reply->border_width == tab->core.border_width)
|
|
958 {
|
|
959 reply->request_mode &= ~(CWWidth | CWHeight | CWBorderWidth);
|
|
960 return best_offer;
|
|
961 }
|
428
|
962
|
3094
|
963 #ifndef DONT_DEBUG_REQUESTS
|
|
964 #define DBG_REQUEST_PRINT(name,field,size) \
|
|
965 do { \
|
|
966 if (reply->field > size) \
|
|
967 { \
|
|
968 if (++debug_count == debug_mask) \
|
|
969 { \
|
|
970 debug_mask <<= 1; \
|
|
971 fprintf (stderr, "ridiculous %s request #%d: %d > %d\n", \
|
|
972 name, debug_count, reply->field, size); \
|
|
973 } \
|
|
974 reply->field = tab->core.field; \
|
|
975 } \
|
|
976 } while (0)
|
428
|
977
|
3094
|
978 DBG_REQUEST_PRINT ("width",width,1024);
|
|
979 DBG_REQUEST_PRINT ("height",height,768);
|
|
980 DBG_REQUEST_PRINT ("border_width",border_width,30);
|
|
981 #undef DBG_REQUEST_PRINT
|
|
982 #endif
|
|
983
|
|
984 rw = reply->width + 2 * reply->border_width;
|
|
985 rh = reply->height + 2 * reply->border_width;
|
434
|
986
|
|
987 /* find out how big the children want to be now */
|
3094
|
988 MaxChild (control, tab, rw, rh);
|
428
|
989
|
|
990
|
|
991 /* Size changes must see if the new size can be accommodated.
|
3094
|
992 * The Tabs widget keeps all of its children the same height, but
|
|
993 * widths may vary.
|
|
994 * A request to shrink will be accepted only if the
|
428
|
995 * new size is still big enough for all other children. A
|
|
996 * request to shrink that is not big enough for all children
|
434
|
997 * returns an "almost" response with the new proposed size
|
|
998 * or a "no" response if unable to shrink at all.
|
|
999 *
|
3094
|
1000 * A request to grow will be accepted only if the Tabs control can
|
428
|
1001 * grow to accommodate.
|
|
1002 *
|
|
1003 * TODO:
|
|
1004 * We could get fancy here and re-arrange the tabs if it is
|
|
1005 * necessary to compromise with the parent, but we'll save that
|
|
1006 * for another day.
|
|
1007 */
|
|
1008
|
3094
|
1009 if (request->request_mode & (CWWidth | CWHeight | CWBorderWidth))
|
428
|
1010 {
|
|
1011 Dimension cw,ch ; /* children's preferred size */
|
|
1012 Dimension aw,ah ; /* available size we can give child */
|
|
1013 Dimension th ; /* space used by tabs */
|
|
1014 Dimension wid,hgt ; /* Tabs widget size */
|
3094
|
1015 int check_nrows;
|
428
|
1016
|
3094
|
1017 cw = control->tabs.max_cw ;
|
|
1018 ch = control->tabs.max_ch ;
|
428
|
1019
|
434
|
1020 /* find out what *my* resulting preferred size would be */
|
3094
|
1021 /* #### this whole API is wrong; what should happen is
|
|
1022 1. app should hint as to #rows and/or aspect ratio
|
|
1023 2. tab control should attempt to layout in current space
|
|
1024 3. if not all tabs fit, should request resize to achieve
|
|
1025 layout hints
|
|
1026 Probably can and should cache preferred size in widget, with
|
|
1027 cache cleared when labels or core size changes. */
|
|
1028 PreferredSize2(control, cw, ch, &wid, &hgt) ;
|
434
|
1029
|
|
1030 /* Would my size change? If so, ask to be resized. */
|
428
|
1031
|
3094
|
1032 if (wid != control->core.width || hgt != control->core.height)
|
428
|
1033 {
|
3094
|
1034 Dimension oldWid = control->core.width,
|
|
1035 oldHgt = control->core.height;
|
428
|
1036 XtWidgetGeometry myrequest, myreply ;
|
|
1037
|
|
1038 myrequest.width = wid ;
|
|
1039 myrequest.height = hgt ;
|
|
1040 myrequest.request_mode = CWWidth | CWHeight ;
|
448
|
1041
|
|
1042 assert (wid > 0 && hgt > 0);
|
428
|
1043 /* If child is only querying, or if we're going to have to
|
|
1044 * offer the child a compromise, then make this a query only.
|
|
1045 */
|
|
1046
|
3094
|
1047 if ((request->request_mode & XtCWQueryOnly) || rw < cw || rh < ch)
|
|
1048 myrequest.request_mode |= XtCWQueryOnly;
|
428
|
1049
|
3094
|
1050 result = XtMakeGeometryRequest ((Widget) control,
|
|
1051 &myrequest, &myreply);
|
428
|
1052
|
434
|
1053 /* !$@# Athena Box widget changes the core size even if QueryOnly
|
428
|
1054 * is set. I'm convinced this is a bug. At any rate, to work
|
|
1055 * around the bug, we need to restore the core size after every
|
|
1056 * query geometry request. This is only partly effective,
|
|
1057 * as there may be other boxes further up the tree.
|
|
1058 */
|
3094
|
1059 if (myrequest.request_mode & XtCWQueryOnly) {
|
|
1060 control->core.width = oldWid;
|
|
1061 control->core.height = oldHgt;
|
428
|
1062 }
|
|
1063
|
|
1064 /* based on the parent's response, determine what the
|
|
1065 * resulting Tabs widget size would be.
|
|
1066 */
|
|
1067
|
3094
|
1068 switch (result) {
|
428
|
1069 case XtGeometryYes:
|
|
1070 case XtGeometryDone:
|
3094
|
1071 control->tabs.needs_layout = True;
|
|
1072 break;
|
428
|
1073
|
|
1074 case XtGeometryNo:
|
3094
|
1075 wid = control->core.width;
|
|
1076 hgt = control->core.height;
|
|
1077 break;
|
428
|
1078
|
|
1079 case XtGeometryAlmost:
|
3094
|
1080 wid = myreply.width;
|
|
1081 hgt = myreply.height;
|
|
1082 control->tabs.needs_layout = True;
|
|
1083 break;
|
428
|
1084 }
|
|
1085 }
|
|
1086
|
|
1087 /* Within the constraints imposed by the parent, what is
|
|
1088 * the max size we can give the child?
|
|
1089 */
|
3094
|
1090 check_nrows = TabLayout (control, wid, hgt, &th, True);
|
|
1091 aw = wid - 2*s;
|
|
1092 if (check_nrows == 1)
|
|
1093 {
|
|
1094 ah = hgt - th - 2*s;
|
|
1095 }
|
|
1096 else
|
|
1097 {
|
|
1098 /* this rarely gets triggered, but when it does it seems to
|
|
1099 get triggered forever after */
|
|
1100 int n = control->composite.num_children;
|
|
1101 ah = control->tabs.tab_height;
|
3397
|
1102 if (debug_tabs > 1)
|
3094
|
1103 fprintf (stderr, "Kludging around %d != 1 rows,"
|
|
1104 " #children = %d, total height %d, using %d.\n",
|
|
1105 check_nrows, n, th, ah);
|
|
1106 }
|
428
|
1107
|
|
1108 /* OK, make our decision. If requested size is >= max sibling
|
|
1109 * preferred size, AND requested size <= available size, then
|
|
1110 * we accept. Otherwise, we offer a compromise.
|
|
1111 */
|
|
1112
|
3094
|
1113 if (rw == aw && rh == ah)
|
428
|
1114 {
|
|
1115 /* Acceptable. If this wasn't a query, change *all* children
|
|
1116 * to this size.
|
|
1117 */
|
3094
|
1118 if (request->request_mode & XtCWQueryOnly)
|
|
1119 {
|
|
1120 control->tabs.needs_layout = False;
|
|
1121 return XtGeometryYes ;
|
|
1122 }
|
428
|
1123 else
|
|
1124 {
|
3094
|
1125 Widget *childP = control->composite.children;
|
|
1126 int i, bw;
|
|
1127 tab->core.border_width = request->border_width;
|
|
1128 for (i = TabsNumChildren (control); --i >= 0; ++childP)
|
|
1129 if (TabVisible (*childP))
|
428
|
1130 {
|
3094
|
1131 bw = (*childP)->core.border_width;
|
|
1132 XtConfigureWidget (*childP, s, control->tabs.tab_total+s,
|
|
1133 rw-2*bw, rh-2*bw, bw);
|
428
|
1134 }
|
|
1135 #ifdef COMMENT
|
|
1136 /* TODO: under what conditions will we need to redraw? */
|
3094
|
1137 XClearWindow (XtDisplay ((Widget) control),
|
|
1138 XtWindow ((Widget) control));
|
|
1139 XtClass (control)->core_class.expose ((Widget)control,
|
|
1140 NULL, NULL);
|
428
|
1141 #endif /* COMMENT */
|
3094
|
1142 return XtGeometryDone;
|
428
|
1143 }
|
|
1144 }
|
|
1145
|
|
1146 /* Cannot grant child's request. Describe what we *can* do
|
|
1147 * and return counter-offer.
|
|
1148 */
|
3094
|
1149 control->tabs.needs_layout = False;
|
|
1150 reply->width = aw - 2 * request->border_width ;
|
|
1151 reply->height = ah - 2 * request->border_width ;
|
|
1152 reply->request_mode &=
|
|
1153 ~((reply->border_width == tab->core.border_width
|
|
1154 ? CWBorderWidth : 0)
|
|
1155 |(reply->width == tab->core.width ? CWWidth : 0)
|
|
1156 |(reply->height == tab->core.height ? CWHeight : 0));
|
428
|
1157 return XtGeometryAlmost ;
|
|
1158 }
|
|
1159
|
|
1160 return XtGeometryYes ;
|
|
1161 }
|
|
1162
|
|
1163
|
|
1164
|
|
1165
|
|
1166 /* The number of children we manage has changed; recompute
|
|
1167 * size from scratch.
|
|
1168 */
|
|
1169
|
|
1170 static void
|
|
1171 TabsChangeManaged(Widget w)
|
|
1172 {
|
|
1173 TabsWidget tw = (TabsWidget)w ;
|
|
1174 Widget *childP = tw->composite.children ;
|
|
1175 int i ;
|
|
1176
|
|
1177 if( tw->tabs.topWidget != NULL &&
|
|
1178 ( !XtIsManaged(tw->tabs.topWidget) ||
|
|
1179 tw->tabs.topWidget->core.being_destroyed ) )
|
|
1180 tw->tabs.topWidget = NULL ;
|
|
1181
|
440
|
1182 /* Check whether the highlight tab is still valid. */
|
|
1183 if( tw->tabs.hilight != NULL &&
|
|
1184 ( !XtIsManaged(tw->tabs.hilight) ||
|
|
1185 tw->tabs.hilight->core.being_destroyed ) )
|
|
1186 tw->tabs.hilight = NULL ;
|
|
1187
|
428
|
1188 GetPreferredSizes(tw) ;
|
|
1189 MakeSizeRequest(tw) ;
|
|
1190
|
|
1191 XtClass(w)->core_class.resize(w) ;
|
|
1192 if( XtIsRealized(w) )
|
|
1193 {
|
|
1194 Display *dpy = XtDisplay(w) ;
|
|
1195 XClearWindow(dpy, XtWindow(w)) ;
|
|
1196 XtClass(w)->core_class.expose(w,NULL,NULL) ;
|
|
1197
|
|
1198 /* make sure the top widget stays on top. This requires
|
|
1199 * making sure that all new children are realized first.
|
|
1200 */
|
|
1201 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
|
|
1202 {
|
446
|
1203 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
|
428
|
1204 if( !XtIsRealized(*childP) )
|
|
1205 XtRealizeWidget(*childP) ;
|
|
1206
|
|
1207 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
|
|
1208 }
|
|
1209 }
|
|
1210
|
|
1211 #ifdef NEED_MOTIF
|
|
1212 /* Only top widget may receive input */
|
|
1213
|
|
1214 for(childP = tw->composite.children, i=tw->composite.num_children;
|
|
1215 --i >= 0;
|
|
1216 ++childP)
|
|
1217 {
|
|
1218 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
|
|
1219 }
|
|
1220
|
|
1221 if( tw->tabs.topWidget != NULL )
|
|
1222 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
|
|
1223 #endif
|
|
1224 }
|
|
1225
|
|
1226
|
|
1227
|
|
1228
|
|
1229 /****************************************************************
|
|
1230 *
|
|
1231 * Action Procedures
|
|
1232 *
|
|
1233 ****************************************************************/
|
|
1234
|
|
1235
|
|
1236 /* User clicks on a tab, figure out which one it was. */
|
|
1237
|
|
1238 /* ARGSUSED */
|
|
1239 static void
|
2286
|
1240 TabsSelect(Widget w, XEvent *event, String *UNUSED (params),
|
|
1241 Cardinal *UNUSED (num_params))
|
428
|
1242 {
|
|
1243 TabsWidget tw = (TabsWidget) w ;
|
|
1244 Widget *childP ;
|
|
1245 Position x,y ;
|
|
1246 Dimension h = tw->tabs.tab_height ;
|
|
1247 int i ;
|
|
1248
|
|
1249 #ifdef NEED_MOTIF
|
|
1250 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
|
|
1251 #endif
|
|
1252
|
|
1253 /* TODO: is there an Xmu function or something to do this instead? */
|
|
1254 switch( event->type ) {
|
|
1255 case ButtonPress:
|
|
1256 case ButtonRelease:
|
|
1257 x = event->xbutton.x ; y = event->xbutton.y ; break ;
|
|
1258 case KeyPress:
|
|
1259 case KeyRelease:
|
|
1260 x = event->xkey.x ; y = event->xkey.y ; break ;
|
|
1261 default:
|
|
1262 return ;
|
|
1263 }
|
|
1264
|
|
1265 /* TODO: determine which tab was clicked, if any. Set that
|
|
1266 * widget to be top of stacking order with XawTabsSetTop().
|
|
1267 */
|
|
1268 for(i=0, childP=tw->composite.children;
|
647
|
1269 i < (int) TabsNumChildren (tw);
|
428
|
1270 ++i, ++childP)
|
446
|
1271 if( TabVisible(*childP) )
|
428
|
1272 {
|
|
1273 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1274 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
|
|
1275 y > tab->tabs.y && y < tab->tabs.y + h )
|
|
1276 {
|
|
1277 if( *childP != tw->tabs.topWidget &&
|
|
1278 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
|
|
1279 XawTabsSetTop(*childP, True) ;
|
|
1280 break ;
|
|
1281 }
|
|
1282 }
|
|
1283 }
|
|
1284
|
|
1285
|
|
1286 /* User hits a key */
|
|
1287
|
|
1288 static void
|
2286
|
1289 TabsPage(Widget w, XEvent *UNUSED (event), String *params,
|
|
1290 Cardinal *num_params)
|
428
|
1291 {
|
|
1292 TabsWidget tw = (TabsWidget) w ;
|
430
|
1293 Widget newtop = NULL;
|
428
|
1294 Widget *childP ;
|
|
1295 int idx ;
|
446
|
1296 int nc = TabsNumChildren (tw) ;
|
428
|
1297
|
|
1298 if( nc <= 0 )
|
|
1299 return ;
|
|
1300
|
|
1301 if( *num_params < 1 ) {
|
|
1302 XtAppWarning(XtWidgetToApplicationContext(w),
|
|
1303 "Tabs: page() action called with no arguments") ;
|
|
1304 return ;
|
|
1305 }
|
|
1306
|
|
1307 if( tw->tabs.topWidget == NULL )
|
|
1308 tw->tabs.topWidget = tw->composite.children[0] ;
|
|
1309
|
|
1310 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1311 if( tw->tabs.topWidget == *childP )
|
|
1312 break ;
|
|
1313
|
|
1314 switch( params[0][0] ) {
|
|
1315 case 'u': /* up */
|
|
1316 case 'U':
|
432
|
1317 if( --idx < 0 )
|
|
1318 idx = nc-1 ;
|
|
1319 newtop = tw->composite.children[idx] ;
|
428
|
1320 break ;
|
|
1321
|
|
1322 case 'd': /* down */
|
|
1323 case 'D':
|
|
1324 if( ++idx >= nc )
|
|
1325 idx = 0 ;
|
|
1326 newtop = tw->composite.children[idx] ;
|
|
1327 break ;
|
|
1328
|
|
1329 case 'h':
|
|
1330 case 'H':
|
432
|
1331 default:
|
428
|
1332 newtop = tw->composite.children[0] ;
|
|
1333 break ;
|
|
1334
|
|
1335 case 'e':
|
|
1336 case 'E':
|
|
1337 newtop = tw->composite.children[nc-1] ;
|
|
1338 break ;
|
|
1339
|
|
1340 case 's': /* selected */
|
|
1341 case 'S':
|
|
1342 if( (newtop = tw->tabs.hilight) == NULL )
|
|
1343 return ;
|
|
1344 break ;
|
|
1345 }
|
|
1346
|
|
1347 XawTabsSetTop(newtop, True) ;
|
|
1348 }
|
|
1349
|
|
1350
|
|
1351 /* User hits up/down key */
|
|
1352
|
|
1353 static void
|
2286
|
1354 TabsHighlight(Widget w, XEvent *UNUSED (event), String *params,
|
|
1355 Cardinal *num_params)
|
428
|
1356 {
|
|
1357 TabsWidget tw = (TabsWidget) w ;
|
430
|
1358 Widget newhl = NULL;
|
428
|
1359 Widget *childP ;
|
|
1360 int idx ;
|
446
|
1361 int nc = TabsNumChildren (tw) ;
|
428
|
1362
|
|
1363 if( nc <= 0 )
|
|
1364 return ;
|
|
1365
|
|
1366 if( *num_params < 1 )
|
|
1367 {
|
|
1368 if( tw->tabs.hilight != NULL )
|
|
1369 DrawHighlight(tw, tw->tabs.hilight, False) ;
|
|
1370 return ;
|
|
1371 }
|
|
1372
|
|
1373 if( tw->tabs.hilight == NULL )
|
|
1374 newhl = tw->composite.children[0] ;
|
|
1375
|
|
1376 else
|
|
1377 {
|
432
|
1378 /* find index of currently highlit child */
|
428
|
1379 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1380 if( tw->tabs.hilight == *childP )
|
|
1381 break ;
|
|
1382
|
|
1383 switch( params[0][0] ) {
|
|
1384 case 'u': /* up */
|
|
1385 case 'U':
|
432
|
1386 if( --idx < 0 )
|
|
1387 idx = nc-1 ;
|
|
1388 newhl = tw->composite.children[idx] ;
|
428
|
1389 break ;
|
|
1390
|
|
1391 case 'd': /* down */
|
|
1392 case 'D':
|
|
1393 if( ++idx >= nc )
|
|
1394 idx = 0 ;
|
|
1395 newhl = tw->composite.children[idx] ;
|
|
1396 break ;
|
|
1397
|
|
1398 case 'h':
|
|
1399 case 'H':
|
|
1400 newhl = tw->composite.children[0] ;
|
|
1401 break ;
|
|
1402
|
|
1403 case 'e':
|
|
1404 case 'E':
|
|
1405 newhl = tw->composite.children[nc-1] ;
|
|
1406 break ;
|
432
|
1407
|
|
1408 default:
|
|
1409 newhl = tw->tabs.hilight ;
|
|
1410 break ;
|
428
|
1411 }
|
|
1412 }
|
|
1413
|
|
1414 XawTabsSetHighlight(w, newhl) ;
|
|
1415 }
|
|
1416
|
|
1417
|
|
1418
|
|
1419 static void
|
2286
|
1420 TabsUnhighlight(Widget w, XEvent *UNUSED (event), String *UNUSED (params),
|
|
1421 Cardinal *UNUSED (num_params))
|
428
|
1422 {
|
|
1423 TabsWidget tw = (TabsWidget) w ;
|
|
1424 int nc = tw->composite.num_children ;
|
|
1425
|
|
1426 if( nc <= 0 )
|
|
1427 return ;
|
|
1428
|
|
1429 if( tw->tabs.hilight != NULL )
|
|
1430 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1431 }
|
|
1432
|
|
1433
|
|
1434
|
|
1435
|
|
1436
|
|
1437 /****************************************************************
|
|
1438 *
|
|
1439 * Public Procedures
|
|
1440 *
|
|
1441 ****************************************************************/
|
|
1442
|
|
1443
|
|
1444 /* Set the top tab, optionally call all callbacks. */
|
|
1445 void
|
|
1446 XawTabsSetTop(Widget w, Bool callCallbacks)
|
|
1447 {
|
|
1448 TabsWidget tw = (TabsWidget)w->core.parent ;
|
|
1449 TabsConstraints tab ;
|
|
1450 Widget oldtop = tw->tabs.topWidget ;
|
|
1451
|
|
1452 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
|
|
1453 {
|
434
|
1454 char line[256] ;
|
|
1455 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
|
428
|
1456 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
|
|
1457 return ;
|
|
1458 }
|
|
1459
|
|
1460 if( callCallbacks )
|
|
1461 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
|
434
|
1462 (XtPointer)tw->tabs.topWidget) ;
|
428
|
1463
|
|
1464 if( !XtIsRealized(w) ) {
|
|
1465 tw->tabs.topWidget = w ;
|
|
1466 tw->tabs.needs_layout = True ;
|
440
|
1467 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
|
428
|
1468 return ;
|
|
1469 }
|
|
1470
|
|
1471 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
|
1472 #ifdef NEED_MOTIF
|
|
1473 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
|
|
1474 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
|
1475 #endif
|
|
1476
|
|
1477 tab = (TabsConstraints) w->core.constraints ;
|
440
|
1478
|
|
1479 /* Unhighlight before we start messing with the stacking order. */
|
|
1480 if( tw->tabs.hilight != NULL )
|
|
1481 {
|
|
1482 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1483 tw->tabs.hilight = NULL;
|
|
1484 }
|
|
1485
|
428
|
1486 if( tab->tabs.row == 0 )
|
|
1487 {
|
|
1488 /* Easy case; undraw current top, undraw new top, assign new
|
|
1489 * top, redraw all borders.
|
|
1490 * We *could* just erase and execute a full redraw, but I like to
|
|
1491 * reduce screen flicker.
|
|
1492 */
|
|
1493 UndrawTab(tw, oldtop) ; /* undraw old */
|
|
1494 DrawBorder(tw, oldtop, True) ;
|
|
1495 UndrawTab(tw, w) ; /* undraw new */
|
|
1496 DrawBorder(tw, w, True) ;
|
|
1497 tw->tabs.topWidget = w ;
|
|
1498 DrawTab(tw, oldtop, True) ; /* redraw old */
|
|
1499 DrawTab(tw, w, True) ; /* redraw new */
|
|
1500 DrawTabs(tw, False) ;
|
|
1501 }
|
|
1502 else
|
|
1503 {
|
|
1504 tw->tabs.topWidget = w ;
|
|
1505 TabsShuffleRows(tw) ;
|
|
1506 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
1507 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
1508 }
|
|
1509
|
|
1510 XawTabsSetHighlight((Widget)tw, w) ;
|
|
1511
|
|
1512 if( callCallbacks )
|
|
1513 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
|
|
1514 }
|
|
1515
|
|
1516
|
|
1517 /* Set the top tab, optionally call all callbacks. */
|
|
1518 void
|
|
1519 XawTabsSetHighlight(Widget t, Widget w)
|
|
1520 {
|
|
1521 TabsWidget tw = (TabsWidget)t ;
|
|
1522
|
|
1523 if( !XtIsSubclass(t, tabsWidgetClass) )
|
|
1524 return ;
|
|
1525
|
|
1526 if( XtIsRealized(t) && w != tw->tabs.hilight )
|
|
1527 {
|
|
1528 if( w != NULL )
|
|
1529 DrawHighlight(tw, w, False) ;
|
|
1530 }
|
|
1531
|
|
1532 tw->tabs.hilight = w ;
|
|
1533 }
|
|
1534
|
|
1535
|
|
1536
|
|
1537
|
|
1538 /****************************************************************
|
|
1539 *
|
|
1540 * Private Procedures
|
|
1541 *
|
|
1542 ****************************************************************/
|
|
1543
|
|
1544
|
|
1545 static void
|
|
1546 TabsAllocGCs(TabsWidget tw)
|
|
1547 {
|
|
1548 TabsAllocFgGC(tw) ;
|
|
1549 TabsAllocGreyGC(tw) ;
|
|
1550 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
|
|
1551 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
|
|
1552 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1553 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
|
|
1554 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1555 }
|
|
1556
|
|
1557
|
|
1558 static void
|
|
1559 TabsFreeGCs(TabsWidget tw)
|
|
1560 {
|
|
1561 Widget w = (Widget) tw;
|
|
1562
|
|
1563 XtReleaseGC(w, tw->tabs.foregroundGC) ;
|
|
1564 XtReleaseGC(w, tw->tabs.greyGC) ;
|
|
1565 XtReleaseGC(w, tw->tabs.backgroundGC) ;
|
|
1566 XtReleaseGC(w, tw->tabs.topGC) ;
|
|
1567 XtReleaseGC(w, tw->tabs.botGC) ;
|
|
1568 #ifdef HAVE_XMU
|
|
1569 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
|
|
1570 #endif
|
|
1571 }
|
|
1572
|
|
1573
|
|
1574
|
|
1575
|
|
1576
|
|
1577 /* Redraw entire Tabs widget */
|
|
1578
|
|
1579 static void
|
|
1580 DrawTabs(TabsWidget tw, Bool labels)
|
|
1581 {
|
|
1582 Widget *childP ;
|
|
1583 int i,j ;
|
|
1584 Dimension s = SHADWID ;
|
|
1585 Dimension th = tw->tabs.tab_height ;
|
|
1586 Position y ;
|
|
1587 TabsConstraints tab ;
|
|
1588
|
|
1589 if( !XtIsRealized((Widget)tw))
|
|
1590 return ;
|
442
|
1591
|
428
|
1592 /* draw tabs and frames by row except for the top tab, which
|
|
1593 * is drawn last. (This is inefficiently written, but should not
|
|
1594 * be too slow as long as there are not a lot of rows.)
|
|
1595 */
|
|
1596
|
|
1597 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
|
647
|
1598 for(i=0; i < (int) tw->tabs.numRows; ++i, y += th)
|
428
|
1599 {
|
446
|
1600 for( j=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
1601 --j >= 0; ++childP )
|
446
|
1602 if( TabVisible(*childP) )
|
428
|
1603 {
|
|
1604 tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1605 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
|
|
1606 DrawTab(tw, *childP, labels) ;
|
|
1607 }
|
647
|
1608 if( i != (int) tw->tabs.numRows -1 )
|
428
|
1609 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
|
|
1610 }
|
|
1611
|
|
1612 DrawFrame(tw) ;
|
|
1613
|
|
1614 /* and now the top tab */
|
|
1615 if( tw->tabs.topWidget != NULL )
|
|
1616 DrawTab(tw, tw->tabs.topWidget, labels) ;
|
|
1617 }
|
|
1618
|
|
1619
|
|
1620
|
|
1621 /* Draw one tab. Corners are rounded very slightly. */
|
|
1622
|
|
1623 static void
|
|
1624 DrawTab(TabsWidget tw, Widget child, Bool labels)
|
|
1625 {
|
|
1626 GC gc ;
|
|
1627 int x,y ;
|
|
1628
|
3397
|
1629 if (debug_tabs > 2) fprintf (stderr, "DrawTab called.\n");
|
3094
|
1630
|
428
|
1631 if( !XtIsRealized((Widget)tw))
|
|
1632 return ;
|
|
1633
|
|
1634 DrawBorder(tw, child, False) ;
|
|
1635
|
|
1636 if( labels )
|
|
1637 {
|
|
1638 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1639 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1640 Window win = XtWindow((Widget)tw) ;
|
|
1641 String lbl = tab->tabs.label != NULL ?
|
|
1642 tab->tabs.label : XtName(child) ;
|
3094
|
1643 #ifdef USE_XFT_TABS
|
|
1644 XftColor color;
|
|
1645 XftColor colorBG;
|
|
1646 Colormap cmap = tw->core.colormap;
|
|
1647 Visual *visual;
|
|
1648 int ignored;
|
428
|
1649
|
3094
|
1650 visual_info_from_widget ((Widget) tw, &visual, &ignored);
|
|
1651 colorBG = xft_convert_color (dpy, cmap, visual,
|
|
1652 tw->core.background_pixel, 0);
|
|
1653 #endif
|
|
1654
|
|
1655 if (debug_tabs > 2)
|
|
1656 fprintf (stderr, "(Re)drawing labels.\n");
|
|
1657
|
|
1658 if (XtIsSensitive(child))
|
428
|
1659 {
|
3094
|
1660 gc = tw->tabs.foregroundGC;
|
|
1661 #ifdef USE_XFT_TABS
|
|
1662 color = xft_convert_color (dpy, cmap, visual,
|
|
1663 tab->tabs.foreground, 0);
|
|
1664 #else
|
|
1665 XSetForeground(dpy, gc, tab->tabs.foreground);
|
|
1666 #endif
|
428
|
1667 }
|
|
1668 else
|
|
1669 {
|
|
1670 /* grey pixel allocation deferred until now */
|
3094
|
1671 if (!tab->tabs.greyAlloc)
|
428
|
1672 {
|
3094
|
1673 if (tw->tabs.be_nice_to_cmap || tw->core.depth == 1)
|
|
1674 tab->tabs.grey = tab->tabs.foreground;
|
428
|
1675 else
|
3094
|
1676 tab->tabs.grey = AllocGreyPixel ((Widget) tw,
|
428
|
1677 tab->tabs.foreground,
|
|
1678 tw->core.background_pixel,
|
3094
|
1679 tw->tabs.insensitive_contrast);
|
|
1680 tab->tabs.greyAlloc = True;
|
428
|
1681 }
|
3094
|
1682 gc = tw->tabs.greyGC;
|
|
1683 #ifdef USE_XFT_TABS
|
|
1684 color = xft_convert_color (dpy, cmap, visual, tab->tabs.grey, 0);
|
|
1685 #else
|
|
1686 XSetForeground(dpy, gc, tab->tabs.grey);
|
|
1687 #endif
|
428
|
1688 }
|
|
1689
|
3094
|
1690 x = tab->tabs.x;
|
|
1691 y = tab->tabs.y;
|
|
1692 if (child == tw->tabs.topWidget)
|
|
1693 y -= TABLDELTA;
|
428
|
1694
|
3094
|
1695 if (tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0)
|
428
|
1696 {
|
3094
|
1697 if (tab->tabs.lbm_depth == 1)
|
428
|
1698 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1699 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
3094
|
1700 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L);
|
428
|
1701 else
|
|
1702 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1703 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
3094
|
1704 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y);
|
428
|
1705 }
|
|
1706
|
3094
|
1707 if (lbl != NULL &&
|
|
1708 #ifdef USE_XFT_TABS
|
|
1709 tw->tabs.renderFont != NULL
|
|
1710 #else
|
|
1711 tw->tabs.font != NULL
|
|
1712 #endif
|
|
1713 )
|
|
1714 {
|
|
1715 #ifdef USE_XFT_TABS
|
|
1716 XftDraw *xftDraw = XftDrawCreate (dpy, win, visual, cmap);
|
|
1717 XftFont *renderFont = tw->tabs.renderFont;
|
|
1718 XGlyphInfo glyphinfo;
|
|
1719 XftColor colorDBG;
|
|
1720 XftColorAllocName (dpy, visual, cmap, "wheat", &colorDBG);
|
3374
|
1721 XftTextExtents8 (dpy, renderFont, (FcChar8 *) lbl,
|
|
1722 (int) strlen (lbl), &glyphinfo);
|
3094
|
1723 /* #### unnecessary? for the moment, give visual extent */
|
|
1724 /* draw background rect */
|
|
1725 if (debug_tabs > 2)
|
|
1726 {
|
|
1727 fprintf (stderr, "background color: pixel=%08lx, r=%04x,"
|
|
1728 " g=%04x, b=%04x, alpha=%04x.\n",
|
|
1729 colorDBG.pixel, colorDBG.color.red,
|
|
1730 colorDBG.color.green, colorDBG.color.blue,
|
|
1731 colorDBG.color.alpha);
|
|
1732 fprintf (stderr, "label geometry: x=%d, y=%d, xOff=%d,"
|
|
1733 " yOff=%d, width=%d, height=%d\n",
|
|
1734 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
|
|
1735 glyphinfo.yOff, glyphinfo.width, glyphinfo.height);
|
|
1736 }
|
3397
|
1737 if (debug_tabs > 2)
|
|
1738 XftDrawRect (xftDraw, &colorDBG,
|
|
1739 /* left, top, width, height */
|
|
1740 x+tab->tabs.l_x-glyphinfo.x,
|
|
1741 y+tab->tabs.l_y-glyphinfo.y,
|
|
1742 glyphinfo.width, glyphinfo.height);
|
|
1743
|
3094
|
1744 /* draw text */
|
3397
|
1745 if (debug_tabs > 1)
|
3094
|
1746 {
|
|
1747 fprintf (stderr, "label: %s.\n", lbl);
|
|
1748 fprintf (stderr, "foreground color: pixel=%08lx, r=%04x,"
|
|
1749 " g=%04x, b=%04x, alpha=%04x.\n",
|
|
1750 color.pixel, color.color.red, color.color.green,
|
|
1751 color.color.blue, color.color.alpha);
|
|
1752 fprintf (stderr, "extent: x=%d, y=%d, xOffset=%d,"
|
|
1753 " yOffset=%d, height=%d, width=%d.\n",
|
|
1754 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
|
|
1755 glyphinfo.yOff, glyphinfo.height, glyphinfo.width);
|
3397
|
1756 }
|
|
1757 if (debug_tabs > 0)
|
|
1758 {
|
|
1759 FcValue name;
|
|
1760 FcValue size;
|
|
1761 FcPatternGet (renderFont->pattern, FC_FAMILY, 0, &name);
|
|
1762 FcPatternGet (renderFont->pattern, FC_SIZE, 0, &size);
|
3094
|
1763 fprintf (stderr, "font: name=%s-%.1f,"
|
|
1764 " height=%d, ascent=%d, descent=%d.\n",
|
|
1765 name.u.s, size.u.d, renderFont->height,
|
|
1766 renderFont->ascent, renderFont->descent);
|
|
1767 }
|
|
1768 XftDrawString8 (xftDraw, &color, renderFont,
|
|
1769 x+tab->tabs.l_x, y+tab->tabs.l_y,
|
3374
|
1770 (FcChar8 *) lbl, (int) strlen (lbl));
|
3094
|
1771 XftDrawDestroy (xftDraw);
|
|
1772 #else
|
|
1773 XDrawString(dpy,win,gc,
|
|
1774 x+tab->tabs.l_x, y+tab->tabs.l_y,
|
|
1775 lbl, (int)strlen(lbl));
|
|
1776 #endif
|
|
1777 }
|
428
|
1778 }
|
|
1779
|
3094
|
1780 if (child == tw->tabs.hilight)
|
|
1781 DrawHighlight(tw, child, False);
|
428
|
1782 }
|
|
1783
|
|
1784
|
|
1785 /* draw frame all the way around the child windows. */
|
|
1786
|
|
1787 static void
|
|
1788 DrawFrame(TabsWidget tw)
|
|
1789 {
|
|
1790 GC topgc = tw->tabs.topGC ;
|
|
1791 GC botgc = tw->tabs.botGC ;
|
|
1792 Dimension s = SHADWID ;
|
|
1793 Dimension ch = tw->tabs.child_height ;
|
448
|
1794 if (ch > 0)
|
|
1795 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
|
|
1796 tw->core.width, ch+2*s, s, topgc, botgc) ;
|
|
1797 else
|
|
1798 {
|
|
1799 Widget w = tw->tabs.topWidget ;
|
|
1800 if (w != NULL)
|
|
1801 {
|
|
1802 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
1803 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
|
|
1804 tab->tabs.x, 2*s, s, topgc, botgc);
|
|
1805 Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width,
|
|
1806 tw->core.height - 2*s,
|
|
1807 tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s,
|
|
1808 topgc, botgc);
|
|
1809 }
|
|
1810 else
|
|
1811 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
|
|
1812 tw->core.width, 2*s, s, topgc, botgc) ;
|
|
1813 }
|
428
|
1814 }
|
|
1815
|
|
1816
|
|
1817 /* draw trim around a tab or underneath a row of tabs */
|
|
1818
|
|
1819 static void
|
|
1820 DrawTrim(TabsWidget tw, /* widget */
|
|
1821 int x, /* upper-left corner */
|
|
1822 int y,
|
|
1823 int wid, /* total size */
|
|
1824 int hgt,
|
|
1825 Bool bottom, /* draw bottom? */
|
|
1826 Bool undraw) /* undraw all */
|
|
1827 {
|
|
1828 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1829 Window win = XtWindow((Widget)tw) ;
|
|
1830 GC bggc = tw->tabs.backgroundGC ;
|
|
1831 GC topgc = undraw ? bggc : tw->tabs.topGC ;
|
|
1832 GC botgc = undraw ? bggc : tw->tabs.botGC ;
|
|
1833 if( bottom )
|
|
1834 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
|
|
1835 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
|
|
1836 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
|
|
1837 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
|
|
1838 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
|
|
1839 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
|
|
1840 }
|
|
1841
|
|
1842
|
|
1843 /* Draw one tab border. */
|
|
1844
|
|
1845 static void
|
|
1846 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
|
|
1847 {
|
|
1848 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1849 Position x = tab->tabs.x ;
|
|
1850 Position y = tab->tabs.y ;
|
|
1851 Dimension twid = tab->tabs.width ;
|
|
1852 Dimension thgt = tw->tabs.tab_height ;
|
|
1853
|
|
1854 /* top tab requires a little special attention; it overlaps
|
|
1855 * neighboring tabs slightly, so the background must be cleared
|
|
1856 * in the region of the overlap to partially erase those neighbors.
|
|
1857 * TODO: is this worth doing with regions instead?
|
|
1858 */
|
|
1859 if( child == tw->tabs.topWidget )
|
|
1860 {
|
|
1861 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1862 Window win = XtWindow((Widget)tw) ;
|
|
1863 GC bggc = tw->tabs.backgroundGC ;
|
|
1864 XRectangle rects[3] ;
|
|
1865 x -= TABDELTA ;
|
|
1866 y -= TABDELTA ;
|
|
1867 twid += TABDELTA*2 ;
|
|
1868 thgt += TABDELTA ;
|
|
1869 AddRect(0, x,y+1,twid,TABDELTA) ;
|
|
1870 AddRect(1, x+1,y,TABDELTA,thgt) ;
|
|
1871 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
|
|
1872 XFillRectangles(dpy,win,bggc, rects, 3) ;
|
|
1873 }
|
|
1874
|
|
1875 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
|
|
1876 }
|
|
1877
|
|
1878
|
|
1879 /* Draw highlight around tab that has focus */
|
|
1880
|
|
1881 static void
|
|
1882 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
|
|
1883 {
|
|
1884 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1885 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1886 Window win = XtWindow((Widget)tw) ;
|
|
1887 GC gc ;
|
|
1888 Position x = tab->tabs.x ;
|
|
1889 Position y = tab->tabs.y ;
|
|
1890 Dimension wid = tab->tabs.width ;
|
|
1891 Dimension hgt = tw->tabs.tab_height ;
|
|
1892 XPoint points[6] ;
|
|
1893
|
|
1894 /* top tab does not have a highlight */
|
|
1895
|
|
1896 if( child == tw->tabs.topWidget )
|
|
1897 return ;
|
|
1898
|
|
1899 if( undraw )
|
|
1900 gc = tw->tabs.backgroundGC ;
|
|
1901
|
|
1902 else if( XtIsSensitive(child) )
|
|
1903 {
|
|
1904 gc = tw->tabs.foregroundGC ;
|
|
1905 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1906 }
|
|
1907 else
|
|
1908 {
|
|
1909 gc = tw->tabs.greyGC ;
|
|
1910 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1911 }
|
|
1912
|
|
1913 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
|
|
1914 points[1].x = x+1 ; points[1].y = y+2 ;
|
|
1915 points[2].x = x+2 ; points[2].y = y+1 ;
|
|
1916 points[3].x = x+wid-4 ; points[3].y = y+1 ;
|
|
1917 points[4].x = x+wid-3 ; points[4].y = y+2 ;
|
|
1918 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
|
|
1919
|
|
1920 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
|
|
1921 }
|
|
1922
|
|
1923
|
|
1924 /* Undraw one tab interior */
|
|
1925
|
|
1926 static void
|
|
1927 UndrawTab(TabsWidget tw, Widget child)
|
|
1928 {
|
|
1929 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1930 Position x = tab->tabs.x ;
|
|
1931 Position y = tab->tabs.y ;
|
|
1932 Dimension twid = tab->tabs.width ;
|
|
1933 Dimension thgt = tw->tabs.tab_height ;
|
|
1934 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1935 Window win = XtWindow((Widget)tw) ;
|
|
1936 GC bggc = tw->tabs.backgroundGC ;
|
|
1937
|
|
1938 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
|
|
1939 }
|
|
1940
|
|
1941
|
|
1942
|
|
1943
|
|
1944
|
|
1945 /* GEOMETRY UTILITIES */
|
|
1946
|
434
|
1947 /* Overview:
|
|
1948 *
|
|
1949 * MaxChild(): ask all children (except possibly one) their
|
|
1950 * preferred sizes, set max_cw, max_ch accordingly.
|
|
1951 *
|
|
1952 * GetPreferredSizes(): ask all children their preferred sizes,
|
|
1953 * set max_cw, max_ch accordingly.
|
|
1954 *
|
|
1955 * PreferredSize(): given max_cw, max_ch, return tabs widget
|
|
1956 * preferred size. Iterate with other widths in order to get
|
|
1957 * a reasonable aspect ratio.
|
|
1958 *
|
|
1959 * PreferredSize2(): Given child dimensions, return Tabs
|
|
1960 * widget dimensions.
|
|
1961 *
|
|
1962 * PreferredSize3(): Same, except given child dimensions plus
|
|
1963 * shadow.
|
|
1964 */
|
428
|
1965
|
434
|
1966
|
|
1967 /* Compute the width of one child's tab. Positions will be computed
|
428
|
1968 * elsewhere.
|
|
1969 *
|
|
1970 * height: font height + vertical_space*2 + shadowWid*2
|
|
1971 * width: string width + horizontal_space*2 + shadowWid*2
|
|
1972 *
|
|
1973 * All tabs are the same height, so that is computed elsewhere.
|
|
1974 */
|
|
1975
|
|
1976 static void
|
|
1977 TabWidth(Widget w)
|
|
1978 {
|
|
1979 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
1980 TabsWidget tw = (TabsWidget)XtParent(w) ;
|
|
1981 String lbl = tab->tabs.label != NULL ?
|
3094
|
1982 tab->tabs.label : XtName(w);
|
|
1983 #ifdef USE_XFT_TABS
|
|
1984 XftFont *font = tw->tabs.renderFont;
|
|
1985 #else
|
|
1986 XFontStruct *font = tw->tabs.font;
|
|
1987 #endif
|
|
1988 int iw = tw->tabs.internalWidth;
|
428
|
1989
|
|
1990 tab->tabs.width = iw + SHADWID*2 ;
|
|
1991 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
|
|
1992
|
|
1993 if( tab->tabs.left_bitmap != None )
|
|
1994 {
|
|
1995 tab->tabs.width += tab->tabs.lbm_width + iw ;
|
|
1996 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
|
|
1997 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
|
|
1998 }
|
|
1999
|
|
2000 if( lbl != NULL && font != NULL )
|
|
2001 {
|
3094
|
2002 #ifdef USE_XFT_TABS
|
|
2003 tab->tabs.width += x_xft_text_width (XtDisplay(tw), font,
|
3374
|
2004 (FcChar8 *) lbl,
|
|
2005 (int)strlen(lbl)) + iw;
|
3094
|
2006 tab->tabs.l_y = (tw->tabs.tab_height
|
|
2007 + tw->tabs.renderFont->ascent
|
|
2008 /* #### how can this subtraction be correct? */
|
|
2009 - tw->tabs.renderFont->descent)/2;
|
|
2010 if (debug_tabs > 2)
|
|
2011 fprintf (stderr, "tab: height=%d, width=%d, baseline=%d.\n",
|
|
2012 tw->tabs.tab_height, tab->tabs.width, tab->tabs.l_y);
|
|
2013 if (debug_tabs > 1)
|
|
2014 fprintf (stderr, "font: height=%d, ascent=%d, descent=%d.\n",
|
|
2015 tw->tabs.renderFont->height,
|
|
2016 tw->tabs.renderFont->ascent,
|
|
2017 tw->tabs.renderFont->descent);
|
|
2018 #else
|
|
2019 tab->tabs.width += XTextWidth (font, lbl, (int)strlen(lbl)) + iw;
|
428
|
2020 tab->tabs.l_y = (tw->tabs.tab_height +
|
434
|
2021 tw->tabs.font->max_bounds.ascent -
|
3094
|
2022 tw->tabs.font->max_bounds.descent)/2;
|
|
2023 #endif
|
428
|
2024 }
|
|
2025 }
|
|
2026
|
|
2027
|
|
2028
|
|
2029 /* Lay out tabs to fit in given width. Compute x,y position and
|
|
2030 * row number for each tab. Return number of rows and total height
|
|
2031 * required by all tabs. If there is only one row, add TABDELTA
|
|
2032 * height to the total. Rows are assigned bottom to top.
|
|
2033 *
|
|
2034 * Tabs are indented from the edges by INDENT.
|
|
2035 *
|
|
2036 * TODO: if they require more than two rows and the total height:width
|
|
2037 * ratio is more than 2:1, then try something else.
|
3094
|
2038 * Gaak! This is actually already done in PreferredSize()!
|
|
2039 *
|
|
2040 * TODO SOONER: for reasons unclear, some applications (specifically
|
|
2041 * XEmacs) give a nominal geometry (in the core record) which doesn't
|
|
2042 * make much sense (eg, may be smaller than some of the tab children).
|
|
2043 * This results in bizarre values for DISPLAY_ROWS and REPLY_HEIGHT.
|
|
2044 * Specify a way to say "tell me what you really want" (eg, with WID
|
|
2045 * and/or HGT == 0 or == Dimension_MAX), and use it where appropriate.
|
|
2046 * LATE-BREAKING LOSE: This happens in PreferredSize(), not XEmacs!
|
|
2047 *
|
|
2048 * TODO EVEN SOONER: some applications lay out the tab control by
|
|
2049 * repeatedly querying until a fixed width and height has been filled
|
|
2050 * by the tabs (XEmacs). There should be an API to cache this?
|
428
|
2051 */
|
|
2052
|
|
2053 static int
|
448
|
2054 TabLayout(TabsWidget tw,
|
3094
|
2055 Dimension wid, /* if 0, use core.width as guess */
|
|
2056 Dimension hgt, /* if 0, use core.height as guess */
|
448
|
2057 Dimension *reply_height, Bool query_only)
|
428
|
2058 {
|
446
|
2059 int i, row, done = 0, display_rows = 0 ;
|
428
|
2060 int num_children = tw->composite.num_children ;
|
|
2061 Widget *childP ;
|
|
2062 Dimension w ;
|
3094
|
2063 Position x,y ; /* #### gaak, these are dimensions! */
|
428
|
2064 TabsConstraints tab ;
|
|
2065
|
|
2066 /* Algorithm: loop through children, assign X positions. If a tab
|
|
2067 * would extend beyond the right edge, start a new row. After all
|
|
2068 * rows are assigned, make a second pass and assign Y positions.
|
|
2069 */
|
|
2070
|
|
2071 if( num_children > 0 )
|
|
2072 {
|
|
2073 /* Loop through the tabs and see how much space they need. */
|
|
2074
|
|
2075 row = 0 ;
|
|
2076 x = INDENT ;
|
|
2077 y = 0 ;
|
3094
|
2078 /* If wid or hgt is 0, we want to guess our own dimensions.
|
|
2079 Currently the guessing functions are broken....
|
|
2080 #### When PreferredSize*() get fixed, fix this too. */
|
3397
|
2081 if (debug_tabs > 1)
|
3094
|
2082 fprintf (stderr, "arg=%d,", wid);
|
|
2083 wid = (wid ? wid : tw->core.width) - INDENT ;
|
|
2084 hgt = hgt ? hgt : tw->core.height;
|
3397
|
2085 if (debug_tabs > 1)
|
3094
|
2086 fprintf (stderr, "wid=%d: x,w,y=", wid);
|
428
|
2087 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
|
|
2088 if( XtIsManaged(*childP) )
|
|
2089 {
|
|
2090 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
2091 w = tab->tabs.width ;
|
446
|
2092
|
3397
|
2093 if (debug_tabs > 1)
|
3094
|
2094 fprintf (stderr, "%d,%d,%d;", x, w, y);
|
428
|
2095 if( x + w > wid ) { /* new row */
|
3094
|
2096 /* #### algorithm is not robust to wid < child's width */
|
|
2097 ++row;
|
|
2098 x = INDENT ;
|
|
2099 y += tw->tabs.tab_height ;
|
|
2100 if (y > hgt && !done)
|
446
|
2101 {
|
|
2102 display_rows = row;
|
|
2103 done = 1;
|
|
2104 }
|
428
|
2105 }
|
|
2106 if( !query_only ) {
|
|
2107 tab->tabs.x = x ;
|
|
2108 tab->tabs.y = y ;
|
|
2109 tab->tabs.row = row ;
|
|
2110 }
|
|
2111 x += w + SPACING ;
|
446
|
2112 if (!query_only && !done)
|
|
2113 tab->tabs.visible = 1;
|
|
2114
|
428
|
2115 }
|
3397
|
2116 if (debug_tabs > 1)
|
3094
|
2117 fprintf (stderr, "\n");
|
442
|
2118 /* If there was only one row, increase the height by TABDELTA */
|
446
|
2119 if( ++display_rows == 1 )
|
428
|
2120 {
|
|
2121 y = TABDELTA ;
|
|
2122 if( !query_only )
|
|
2123 for(i=num_children, childP=tw->composite.children;
|
|
2124 --i >= 0 ; ++childP)
|
|
2125 if( XtIsManaged(*childP) )
|
|
2126 {
|
|
2127 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
2128 tab->tabs.y = y ;
|
|
2129 }
|
|
2130 }
|
3094
|
2131 row++;
|
428
|
2132 y += tw->tabs.tab_height ;
|
|
2133 }
|
|
2134 else
|
446
|
2135 display_rows = row = y = 0 ;
|
428
|
2136
|
|
2137 if( !query_only ) {
|
|
2138 tw->tabs.tab_total = y ;
|
446
|
2139 tw->tabs.numRows = display_rows ;
|
|
2140 tw->tabs.realRows = row;
|
428
|
2141 }
|
|
2142
|
3397
|
2143 if (debug_tabs > 1 && (row > 1 || display_rows > 1))
|
3094
|
2144 fprintf (stderr, "tab: %d display rows, #children = %d,"
|
|
2145 " total height %d, total rows %d%s.\n",
|
|
2146 display_rows, num_children, y, row,
|
|
2147 query_only ? " (query)" : "");
|
|
2148
|
428
|
2149 if( reply_height != NULL )
|
|
2150 *reply_height = y ;
|
|
2151
|
446
|
2152 return display_rows ;
|
428
|
2153 }
|
|
2154
|
|
2155
|
|
2156
|
|
2157 /* Find max preferred child size. Returned sizes include child
|
434
|
2158 * border widths.
|
428
|
2159 */
|
|
2160
|
|
2161 static void
|
|
2162 GetPreferredSizes(TabsWidget tw)
|
|
2163 {
|
434
|
2164 MaxChild(tw, NULL, 0,0) ;
|
428
|
2165 }
|
|
2166
|
|
2167
|
|
2168
|
3094
|
2169 /* Find max preferred child size and store in control widget.
|
|
2170 * If except is non-null, don't ask that one.
|
434
|
2171 */
|
428
|
2172
|
|
2173 static void
|
434
|
2174 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
|
428
|
2175 {
|
434
|
2176 int i ;
|
|
2177 Widget *childP = tw->composite.children ;
|
|
2178 XtWidgetGeometry preferred ;
|
428
|
2179
|
|
2180 for(i=tw->composite.num_children; --i >=0; ++childP)
|
448
|
2181 if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except )
|
428
|
2182 {
|
434
|
2183 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
|
|
2184 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
|
|
2185 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
|
428
|
2186 }
|
|
2187
|
|
2188 tw->tabs.max_cw = cw ;
|
|
2189 tw->tabs.max_ch = ch ;
|
|
2190 }
|
|
2191
|
|
2192
|
|
2193
|
|
2194 /* rotate row numbers to bring current widget to bottom row,
|
|
2195 * compute y positions for all tabs
|
|
2196 */
|
|
2197
|
|
2198 static void
|
|
2199 TabsShuffleRows(TabsWidget tw)
|
|
2200 {
|
|
2201 TabsConstraints tab ;
|
|
2202 int move ;
|
446
|
2203 int real_rows, display_rows ;
|
428
|
2204 Widget *childP ;
|
|
2205 Dimension th = tw->tabs.tab_height ;
|
|
2206 Position bottom ;
|
|
2207 int i ;
|
|
2208
|
|
2209 /* There must be a top widget. If not, assign one. */
|
|
2210 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
|
446
|
2211 for(i=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
2212 --i >= 0;
|
|
2213 ++childP)
|
|
2214 if( XtIsManaged(*childP) ) {
|
|
2215 tw->tabs.topWidget = *childP ;
|
|
2216 break ;
|
|
2217 }
|
|
2218
|
|
2219 if( tw->tabs.topWidget != NULL )
|
|
2220 {
|
446
|
2221 display_rows = tw->tabs.numRows ;
|
|
2222 real_rows = tw->tabs.realRows ;
|
448
|
2223 assert( display_rows <= real_rows ) ;
|
428
|
2224
|
446
|
2225 if( real_rows > 1 )
|
428
|
2226 {
|
|
2227 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
|
|
2228 assert( tab != NULL ) ;
|
|
2229
|
446
|
2230 /* How far to move top row. The selected tab must be on
|
|
2231 the bottom row of the *visible* rows. */
|
|
2232 move = (real_rows + 1 - display_rows) - tab->tabs.row ;
|
|
2233 if (move < 0)
|
|
2234 move = real_rows - move;
|
428
|
2235 bottom = tw->tabs.tab_total - th ;
|
|
2236
|
446
|
2237 for(i=tw->composite.num_children, childP=tw->composite.children;
|
428
|
2238 --i >= 0;
|
|
2239 ++childP)
|
|
2240 if( XtIsManaged(*childP) )
|
|
2241 {
|
|
2242 tab = (TabsConstraints) (*childP)->core.constraints ;
|
446
|
2243 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
|
428
|
2244 tab->tabs.y = bottom - tab->tabs.row * th ;
|
446
|
2245 tab->tabs.visible = (tab->tabs.row < display_rows);
|
428
|
2246 }
|
|
2247 }
|
|
2248 }
|
|
2249 }
|
|
2250
|
|
2251
|
434
|
2252 /* Find preferred size. Ask children, find size of largest,
|
428
|
2253 * add room for tabs & return. This can get a little involved,
|
|
2254 * as we don't want to have too many rows of tabs; we may widen
|
|
2255 * the widget to reduce # of rows.
|
434
|
2256 *
|
|
2257 * This function requires that max_cw, max_ch already be set.
|
428
|
2258 */
|
|
2259 static int
|
|
2260 PreferredSize(
|
|
2261 TabsWidget tw,
|
|
2262 Dimension *reply_width, /* total widget size */
|
|
2263 Dimension *reply_height,
|
|
2264 Dimension *reply_cw, /* child widget size */
|
|
2265 Dimension *reply_ch)
|
|
2266 {
|
|
2267 Dimension cw,ch ; /* child width, height */
|
|
2268 Dimension wid,hgt ;
|
|
2269 Dimension rwid,rhgt ;
|
|
2270 int nrow ;
|
|
2271
|
|
2272 wid = cw = tw->tabs.max_cw ;
|
|
2273 hgt = ch = tw->tabs.max_ch ;
|
|
2274
|
|
2275 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
|
|
2276
|
|
2277 /* Check for absurd results (more than 2 rows, high aspect
|
|
2278 * ratio). Try wider size if needed.
|
|
2279 * TODO: make sure this terminates.
|
|
2280 */
|
|
2281
|
|
2282 if( nrow > 2 && rhgt > rwid )
|
|
2283 {
|
|
2284 Dimension w0, w1 ;
|
434
|
2285 int maxloop = 20 ;
|
428
|
2286
|
|
2287 /* step 1: start doubling size until it's too big */
|
|
2288 do {
|
|
2289 w0 = wid ;
|
|
2290 wid = Max(wid*2, wid+20) ;
|
|
2291 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
2292 } while( nrow > 2 && rhgt > rwid ) ;
|
|
2293 w1 = wid ;
|
|
2294
|
|
2295 /* step 2: use Newton's method to find ideal size. Stop within
|
|
2296 * 8 pixels.
|
|
2297 */
|
434
|
2298 while( --maxloop > 0 && w1 > w0 + 8 )
|
428
|
2299 {
|
|
2300 wid = (w0+w1)/2 ;
|
|
2301 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
2302 if( nrow > 2 && rhgt > rwid )
|
|
2303 w0 = wid ;
|
|
2304 else
|
|
2305 w1 = wid ;
|
|
2306 }
|
|
2307 wid = w1 ;
|
|
2308 }
|
|
2309
|
|
2310 *reply_width = rwid ;
|
|
2311 *reply_height = rhgt ;
|
|
2312 if( reply_cw != NULL ) *reply_cw = cw ;
|
|
2313 if( reply_ch != NULL ) *reply_ch = ch ;
|
|
2314 return nrow ;
|
|
2315 }
|
|
2316
|
|
2317
|
|
2318 /* Find preferred size, given size of children. */
|
|
2319
|
|
2320 static int
|
|
2321 PreferredSize2(
|
|
2322 TabsWidget tw,
|
448
|
2323 Dimension cw, /* child width, height */
|
|
2324 Dimension ch,
|
428
|
2325 Dimension *reply_width, /* total widget size */
|
|
2326 Dimension *reply_height)
|
|
2327 {
|
|
2328 Dimension s = SHADWID ;
|
448
|
2329 int ret;
|
428
|
2330
|
|
2331 /* make room for shadow frame */
|
|
2332 cw += s*2 ;
|
|
2333 ch += s*2 ;
|
|
2334
|
448
|
2335 ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
|
|
2336
|
|
2337 assert (*reply_width > 0 && *reply_height > 0);
|
|
2338 return ret;
|
428
|
2339 }
|
|
2340
|
|
2341
|
|
2342 /* Find preferred size, given size of children+shadow. */
|
|
2343
|
|
2344 static int
|
|
2345 PreferredSize3(
|
|
2346 TabsWidget tw,
|
448
|
2347 Dimension wid, /* child width, height */
|
|
2348 Dimension hgt,
|
428
|
2349 Dimension *reply_width, /* total widget size */
|
|
2350 Dimension *reply_height)
|
|
2351 {
|
|
2352 Dimension th ; /* space used by tabs */
|
|
2353 int nrows ;
|
|
2354
|
|
2355 if( tw->composite.num_children > 0 )
|
3094
|
2356 /* used to be wid, hgt not 0, 0 but that's obviously wrong
|
|
2357 since TabLayout wants dimensions of control parent but
|
|
2358 wid, hgt are dimensions of some child */
|
|
2359 nrows = TabLayout(tw, 0, 0, &th, True) ;
|
428
|
2360 else {
|
|
2361 th = 0 ;
|
|
2362 nrows = 0 ;
|
|
2363 }
|
|
2364
|
|
2365 *reply_width = Max(wid, MIN_WID) ;
|
|
2366 *reply_height = Max(th+hgt, MIN_HGT) ;
|
|
2367
|
|
2368 return nrows ;
|
|
2369 }
|
|
2370
|
|
2371
|
|
2372 static void
|
|
2373 MakeSizeRequest(TabsWidget tw)
|
|
2374 {
|
|
2375 Widget w = (Widget)tw ;
|
|
2376 XtWidgetGeometry request, reply ;
|
|
2377 XtGeometryResult result ;
|
|
2378 Dimension cw,ch ;
|
|
2379
|
|
2380 request.request_mode = CWWidth | CWHeight ;
|
|
2381 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
|
|
2382
|
|
2383 if( request.width == tw->core.width &&
|
|
2384 request.height == tw->core.height )
|
|
2385 return ;
|
|
2386
|
|
2387 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
2388
|
|
2389 if( result == XtGeometryAlmost )
|
|
2390 {
|
|
2391 /* Bugger. Didn't get what we want, but were offered a
|
|
2392 * compromise. If the width was too small, recompute
|
|
2393 * based on the too-small width and try again.
|
|
2394 * If the height was too small, make a wild-ass guess
|
|
2395 * at a wider width and try again.
|
|
2396 */
|
|
2397
|
|
2398 if( reply.width < request.width && reply.height >= request.height )
|
|
2399 {
|
|
2400 Dimension s = SHADWID ;
|
|
2401 ch += s*2 ;
|
|
2402 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
|
|
2403 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
2404 if( result == XtGeometryAlmost )
|
|
2405 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
2406 }
|
|
2407
|
|
2408 else
|
|
2409 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
2410 }
|
|
2411 }
|
|
2412
|
|
2413
|
|
2414 static void
|
|
2415 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
|
|
2416 {
|
|
2417 Window root ;
|
|
2418 int x,y ;
|
|
2419 unsigned int bw ;
|
|
2420
|
|
2421 if( tab->tabs.left_bitmap == None ||
|
|
2422 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
|
434
|
2423 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
|
428
|
2424 &bw, &tab->tabs.lbm_depth) )
|
|
2425 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
|
|
2426 }
|
|
2427
|
|
2428
|
|
2429
|
|
2430
|
|
2431 /* Code copied & modified from Gcs.c. This version has dynamic
|
|
2432 * foreground.
|
|
2433 */
|
|
2434
|
|
2435 static void
|
|
2436 TabsAllocFgGC(TabsWidget tw)
|
|
2437 {
|
|
2438 Widget w = (Widget) tw;
|
|
2439 XGCValues values ;
|
|
2440
|
3094
|
2441 values.background = tw->core.background_pixel;
|
|
2442 values.font =
|
|
2443 #ifdef USE_XFT_TABS
|
|
2444 None;
|
|
2445 #else
|
|
2446 tw->tabs.font->fid;
|
|
2447 #endif
|
|
2448 values.line_style = LineOnOffDash;
|
|
2449 values.line_style = LineSolid;
|
428
|
2450
|
|
2451 tw->tabs.foregroundGC =
|
|
2452 XtAllocateGC(w, w->core.depth,
|
3094
|
2453 #ifndef USE_XFT_TABS
|
|
2454 GCFont|
|
|
2455 #endif
|
|
2456 GCBackground|GCLineStyle,
|
|
2457 &values,
|
|
2458 GCForeground,
|
|
2459 #ifdef USE_XFT_TABS
|
|
2460 GCFont|
|
|
2461 #endif
|
|
2462 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2463 GCDashList|GCArcMode);
|
428
|
2464 }
|
|
2465
|
|
2466 static void
|
|
2467 TabsAllocGreyGC(TabsWidget tw)
|
|
2468 {
|
|
2469 Widget w = (Widget) tw;
|
|
2470 XGCValues values ;
|
|
2471
|
3094
|
2472 values.background = tw->core.background_pixel;
|
|
2473 values.font =
|
|
2474 #ifdef USE_XFT_TABS
|
|
2475 None;
|
|
2476 #else
|
|
2477 tw->tabs.font->fid;
|
|
2478 #endif
|
428
|
2479 #ifdef HAVE_XMU
|
3094
|
2480 if (tw->tabs.be_nice_to_cmap || w->core.depth == 1)
|
428
|
2481 {
|
3094
|
2482 values.fill_style = FillStippled;
|
428
|
2483 tw->tabs.grey50 =
|
3094
|
2484 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1);
|
428
|
2485
|
|
2486 tw->tabs.greyGC =
|
|
2487 XtAllocateGC(w, w->core.depth,
|
3094
|
2488 #ifndef USE_XFT_TABS
|
|
2489 GCFont|
|
|
2490 #endif
|
|
2491 GCBackground|GCStipple|GCFillStyle, &values,
|
428
|
2492 GCForeground,
|
3094
|
2493 #ifdef USE_XFT_TABS
|
|
2494 GCFont|
|
|
2495 #endif
|
428
|
2496 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
3094
|
2497 GCDashList|GCArcMode);
|
428
|
2498 }
|
|
2499 else
|
|
2500 #endif
|
|
2501 {
|
|
2502 tw->tabs.greyGC =
|
|
2503 XtAllocateGC(w, w->core.depth,
|
3094
|
2504 #ifdef USE_XFT_TABS
|
|
2505 0L,
|
|
2506 #else
|
|
2507 GCFont,
|
|
2508 #endif
|
|
2509 &values,
|
428
|
2510 GCForeground,
|
3094
|
2511 #ifdef USE_XFT_TABS
|
|
2512 GCFont|
|
|
2513 #endif
|
428
|
2514 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
3094
|
2515 GCDashList|GCArcMode);
|
428
|
2516 }
|
|
2517 }
|