annotate lwlib/xlwgauge.c @ 458:c33ae14dd6d0 r21-2-44

Import from CVS: tag r21-2-44
author cvs
date Mon, 13 Aug 2007 11:42:25 +0200
parents abe6d1db359e
children b39c14581166
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1 /* Gauge Widget for XEmacs.
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
2 Copyright (C) 1999 Edward A. Falk
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
3
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
4 This file is part of XEmacs.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
5
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
9 later version.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
10
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
14 for more details.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
15
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
20
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
21 /* Synched up with: Gauge.c 1.2 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
22
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
23 /*
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
24 * Gauge.c - Gauge widget
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
25 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
26 * Author: Edward A. Falk
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
27 * falk@falconer.vip.best.com
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
28 *
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
29 * Date: July 9, 1997
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
30 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
31 * Note: for fun and demonstration purposes, I have added selection
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
32 * capabilities to this widget. If you select the widget, you create
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
33 * a primary selection containing the current value of the widget in
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
34 * both integer and string form. If you copy into the widget, the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
35 * primary selection is converted to an integer value and the gauge is
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
36 * set to that value.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
37 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
38
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
39 /* TODO: display time instead of value
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
40 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
41
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
42 #define DEF_LEN 50 /* default width (or height for vertical gauge) */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
43 #define MIN_LEN 10 /* minimum reasonable width (height) */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
44 #define TIC_LEN 6 /* length of tic marks */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
45 #define GA_WID 3 /* width of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
46 #define MS_PER_SEC 1000
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
47
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
48 #include <config.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
49 #include <stdlib.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
50 #include <stdio.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
51 #include <ctype.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
52 #include <X11/IntrinsicP.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
53 #include <X11/Xatom.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
54 #include <X11/StringDefs.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
55 #include ATHENA_XawInit_h_
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
56 #include "xlwgaugeP.h"
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
57 #include "../src/xmu.h"
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
58 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
59 #include <X11/Xmu/Atoms.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
60 #include <X11/Xmu/Drawing.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
61 #include <X11/Xmu/StdSel.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
62 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
63
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
64
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
65 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
66 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
67 * Gauge resources
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
68 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
69 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
70
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
71
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
72 static char defaultTranslations[] =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
73 "<Btn1Up>: select()\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
74 <Key>F1: select(CLIPBOARD)\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
75 <Btn2Up>: paste()\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
76 <Key>F2: paste(CLIPBOARD)" ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
77
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
78
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
79
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
80 #define offset(field) XtOffsetOf(GaugeRec, field)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
81 static XtResource resources[] = {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
82 {XtNvalue, XtCValue, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
83 offset(gauge.value), XtRImmediate, (XtPointer)0},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
84 {XtNminValue, XtCMinValue, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
85 offset(gauge.v0), XtRImmediate, (XtPointer)0},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
86 {XtNmaxValue, XtCMaxValue, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
87 offset(gauge.v1), XtRImmediate, (XtPointer)100},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
88 {XtNntics, XtCNTics, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
89 offset(gauge.ntics), XtRImmediate, (XtPointer) 0},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
90 {XtNnlabels, XtCNLabels, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
91 offset(gauge.nlabels), XtRImmediate, (XtPointer) 0},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
92 {XtNlabels, XtCLabels, XtRStringArray, sizeof(String *),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
93 offset(gauge.labels), XtRStringArray, NULL},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
94 {XtNautoScaleUp, XtCAutoScaleUp, XtRBoolean, sizeof(Boolean),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
95 offset(gauge.autoScaleUp), XtRImmediate, FALSE},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
96 {XtNautoScaleDown, XtCAutoScaleDown, XtRBoolean, sizeof(Boolean),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
97 offset(gauge.autoScaleDown), XtRImmediate, FALSE},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
98 {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
99 offset(gauge.orientation), XtRImmediate, (XtPointer)XtorientHorizontal},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
100 {XtNupdate, XtCInterval, XtRInt, sizeof(int),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
101 offset(gauge.update), XtRImmediate, (XtPointer)0},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
102 {XtNgetValue, XtCCallback, XtRCallback, sizeof(XtPointer),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
103 offset(gauge.getValue), XtRImmediate, (XtPointer)NULL},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
104 };
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
105 #undef offset
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
106
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
107
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
108
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
109 /* member functions */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
110
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
111 static void GaugeClassInit (void);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
112 static void GaugeInit (Widget, Widget, ArgList, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
113 static void GaugeDestroy (Widget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
114 static void GaugeResize (Widget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
115 static void GaugeExpose (Widget, XEvent *, Region);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
116 static Boolean GaugeSetValues (Widget, Widget, Widget, ArgList, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
117 static XtGeometryResult GaugeQueryGeometry (Widget, XtWidgetGeometry *,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
118 XtWidgetGeometry *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
119
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
120 /* action procs */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
121
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
122 static void GaugeSelect (Widget, XEvent *, String *, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
123 static void GaugePaste (Widget, XEvent *, String *, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
124
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
125 /* internal privates */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
126
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
127 static void GaugeSize (GaugeWidget, Dimension *, Dimension *, Dimension);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
128 static void MaxLabel (GaugeWidget, Dimension *, Dimension *,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
129 Dimension *, Dimension *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
130 static void AutoScale (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
131 static void EnableUpdate (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
132 static void DisableUpdate (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
133
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
134 static void GaugeGetValue (XtPointer, XtIntervalId *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
135 static void GaugeMercury (Display *, Window, GC, GaugeWidget, Cardinal, Cardinal);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
136
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
137 static Boolean GaugeConvert (Widget, Atom *, Atom *, Atom *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
138 XtPointer *, unsigned long *, int *);
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
139 static void GaugeLoseSel (Widget, Atom *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
140 static void GaugeDoneSel (Widget, Atom *, Atom *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
141 static void GaugeGetSelCB (Widget, XtPointer, Atom *, Atom *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
142 XtPointer, unsigned long *, int *);
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
143
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
144 static GC Get_GC (GaugeWidget, Pixel);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
145
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
146
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
147 static XtActionsRec actionsList[] =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
148 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
149 {"select", GaugeSelect},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
150 {"paste", GaugePaste},
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
151 } ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
152
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
153
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
154
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
155 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
156 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
157 * Full class record constant
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
158 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
159 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
160
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
161 GaugeClassRec gaugeClassRec = {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
162 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
163 /* core_class fields */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
164 /* superclass */ (WidgetClass) &labelClassRec,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
165 /* class_name */ "Gauge",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
166 /* widget_size */ sizeof(GaugeRec),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
167 /* class_initialize */ GaugeClassInit,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
168 /* class_part_initialize */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
169 /* class_inited */ FALSE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
170 /* initialize */ GaugeInit,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
171 /* initialize_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
172 /* realize */ XtInheritRealize, /* TODO? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
173 /* actions */ actionsList,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
174 /* num_actions */ XtNumber(actionsList),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
175 /* resources */ resources,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
176 /* num_resources */ XtNumber(resources),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
177 /* xrm_class */ NULLQUARK,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
178 /* compress_motion */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
179 /* compress_exposure */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
180 /* compress_enterleave */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
181 /* visible_interest */ FALSE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
182 /* destroy */ GaugeDestroy,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
183 /* resize */ GaugeResize,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
184 /* expose */ GaugeExpose,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
185 /* set_values */ GaugeSetValues,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
186 /* set_values_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
187 /* set_values_almost */ XtInheritSetValuesAlmost,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
188 /* get_values_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
189 /* accept_focus */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
190 /* version */ XtVersion,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
191 /* callback_private */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
192 /* tm_table */ defaultTranslations,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
193 /* query_geometry */ GaugeQueryGeometry,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
194 /* display_accelerator */ XtInheritDisplayAccelerator,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
195 /* extension */ NULL
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
196 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
197 /* Simple class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
198 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
199 /* change_sensitive */ XtInheritChangeSensitive
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
200 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
201 #ifdef _ThreeDP_h
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
202 /* ThreeD class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
203 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
204 XtInheritXaw3dShadowDraw /* shadowdraw */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
205 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
206 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
207 /* Label class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
208 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
209 /* ignore */ 0
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
210 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
211 /* Gauge class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
212 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
213 /* extension */ NULL
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
214 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
215 };
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
216
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
217 WidgetClass gaugeWidgetClass = (WidgetClass)&gaugeClassRec;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
218
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
219
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
220
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
221
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
222 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
223 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
224 * Member Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
225 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
226 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
227
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
228 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
229 GaugeClassInit (void)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
230 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
231 XawInitializeWidgetSet();
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
232 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
233 XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
234 NULL, 0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
235 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
236 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
237
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
238
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
239
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
240 /* ARGSUSED */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
241 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
242 GaugeInit (Widget request,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
243 Widget new,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
244 ArgList args,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
245 Cardinal *num_args)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
246 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
247 GaugeWidget gw = (GaugeWidget) new;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
248
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
249 if( gw->gauge.v0 == 0 && gw->gauge.v1 == 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
250 gw->gauge.autoScaleUp = gw->gauge.autoScaleDown = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
251 AutoScale(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
252 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
253
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
254 /* If size not explicitly set, set it to our preferred size now. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
255
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
256 if( request->core.width == 0 || request->core.height == 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
257 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
258 Dimension w,h ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
259 GaugeSize(gw, &w,&h, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
260 if( request->core.width == 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
261 new->core.width = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
262 if( request->core.height == 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
263 new->core.height = h ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
264 gw->core.widget_class->core_class.resize(new) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
265 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
266
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
267 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
268 gw->gauge.selstr = NULL ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
269
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
270 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
271 EnableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
272
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
273 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
274 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
275
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
276 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
277 GaugeDestroy (Widget w)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
278 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
279 GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
280
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
281 if( gw->gauge.selstr != NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
282 XtFree(gw->gauge.selstr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
283
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
284 if( gw->gauge.selected != None )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
285 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
286
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
287 XtReleaseGC(w, gw->gauge.inverse_GC) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
288
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
289 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
290 DisableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
291 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
292
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
293
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
294 /* React to size change from manager. Label widget will compute some
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
295 * internal stuff, but we need to override.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
296 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
297
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
298 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
299 GaugeResize (Widget w)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
300 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
301 GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
302 int size ; /* height (width) of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
303 int vmargin ; /* vertical (horizontal) margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
304 int hmargin ; /* horizontal (vertical) margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
305
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
306 vmargin = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
307 gw->label.internal_height : gw->label.internal_width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
308 hmargin = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
309 gw->label.internal_width : gw->label.internal_height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
310
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
311 /* TODO: need to call parent resize proc? I don't think so since
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
312 * we're recomputing everything from scratch anyway.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
313 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
314
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
315 /* find total height (width) of contents */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
316
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
317 size = GA_WID+2 ; /* gauge itself + edges */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
318
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
319 if( gw->gauge.ntics > 1 ) /* tic marks */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
320 size += vmargin + TIC_LEN ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
321
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
322 if( gw->gauge.nlabels > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
323 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
324 Dimension lwm, lw0, lw1 ; /* width of max, left, right labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
325 Dimension lh ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
326
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
327 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
328
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
329 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
330 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
331 gw->gauge.margin0 = lw0 / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
332 gw->gauge.margin1 = lw1 / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
333 size += lh + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
334 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
335 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
336 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
337 gw->gauge.margin0 =
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
338 gw->gauge.margin1 = lh / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
339 size += lwm + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
340 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
341 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
342 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
343 gw->gauge.margin0 = gw->gauge.margin1 = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
344
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
345 gw->gauge.margin0 += hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
346 gw->gauge.margin1 += hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
347
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
348 /* Now distribute height (width) over components */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
349
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
350 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
351 gw->gauge.gmargin = (gw->core.height-size)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
352 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
353 gw->gauge.gmargin = (gw->core.width-size)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
354
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
355 gw->gauge.tmargin = gw->gauge.gmargin + GA_WID+2 + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
356 if( gw->gauge.ntics > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
357 gw->gauge.lmargin = gw->gauge.tmargin + TIC_LEN + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
358 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
359 gw->gauge.lmargin = gw->gauge.tmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
360 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
361
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
362 /*
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
363 * Repaint the widget window
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
364 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
365
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
366 /* ARGSUSED */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
367 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
368 GaugeExpose (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
369 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
370 Region region)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
371 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
372 GaugeWidget gw = (GaugeWidget) w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
373 register Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
374 register Window win = XtWindow(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
375 GC gc; /* foreground, background */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
376 GC gctop, gcbot ; /* dark, light shadows */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
377
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
378 int len ; /* length (width or height) of widget */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
379 int hgt ; /* height (width) of widget */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
380 int e0,e1 ; /* ends of the gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
381 int x ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
382 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
383 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
384 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
385 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
386 int value = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
387
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
388 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
389
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
390
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
391 #ifdef _ThreeDP_h
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
392 gctop = gw->threeD.bot_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
393 gcbot = gw->threeD.top_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
394 #else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
395 gctop = gcbot = gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
396 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
397
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
398 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
399 len = gw->core.width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
400 hgt = gw->core.height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
401 } else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
402 len = gw->core.height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
403 hgt = gw->core.width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
404 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
405
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
406 /* if the gauge is selected, signify by drawing the background
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
407 * in a contrasting color.
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
408 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
409
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
410 if( gw->gauge.selected )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
411 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
412 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
413 gc = gw->gauge.inverse_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
414 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
415
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
416 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
417 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
418
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
419 /* Draw the Gauge itself */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
420
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
421 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
422
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
423 if( gw->gauge.orientation == XtorientHorizontal ) /* horizontal */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
424 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
425 XDrawLine(dpy,win,gctop, e0+1,y, e1-1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
426 XDrawLine(dpy,win,gctop, e0,y+1, e0,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
427 XDrawLine(dpy,win,gcbot, e0+1, y+GA_WID+1, e1-1, y+GA_WID+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
428 XDrawLine(dpy,win,gcbot, e1,y+1, e1,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
429 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
430 else /* vertical */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
431 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
432 XDrawLine(dpy,win,gctop, y,e0+1, y,e1-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
433 XDrawLine(dpy,win,gctop, y+1,e0, y+GA_WID,e0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
434 XDrawLine(dpy,win,gcbot, y+GA_WID+1,e0+1, y+GA_WID+1, e1-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
435 XDrawLine(dpy,win,gcbot, y+1,e1, y+GA_WID,e1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
436 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
437
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
438
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
439 /* draw the mercury */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
440
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
441 GaugeMercury(dpy, win, gc, gw, 0,value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
442
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
443
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
444 if( gw->gauge.ntics > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
445 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
446 y = gw->gauge.tmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
447 for(i=0; i<gw->gauge.ntics; ++i)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
448 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
449 x = e0 + i*(e1-e0-1)/(gw->gauge.ntics-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
450 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
451 XDrawLine(dpy,win,gcbot, x,y+1, x,y+TIC_LEN-2) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
452 XDrawLine(dpy,win,gcbot, x,y, x+1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
453 XDrawLine(dpy,win,gctop, x+1,y+1, x+1,y+TIC_LEN-2) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
454 XDrawLine(dpy,win,gctop, x,y+TIC_LEN-1, x+1,y+TIC_LEN-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
455 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
456 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
457 XDrawLine(dpy,win,gcbot, y+1,x, y+TIC_LEN-2,x) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
458 XDrawLine(dpy,win,gcbot, y,x, y,x+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
459 XDrawLine(dpy,win,gctop, y+1,x+1, y+TIC_LEN-2,x+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
460 XDrawLine(dpy,win,gctop, y+TIC_LEN-1,x, y+TIC_LEN-1,x+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
461 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
462 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
463 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
464
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
465 /* draw labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
466 if( gw->gauge.nlabels > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
467 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
468 char label[20], *s = label ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
469 int xlen, wd,h =0 ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
470
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
471 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
472 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
473 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
474 y = gw->gauge.lmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
475 h = gw->label.font->max_bounds.ascent / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
476 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
477
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
478 for(i=0; i<gw->gauge.nlabels; ++i)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
479 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
480 if( gw->gauge.labels == NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
481 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
482 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
483 s = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
484 if( s != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
485 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
486 xlen = strlen(s) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
487 if( gw->gauge.orientation == XtorientHorizontal ) {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
488 wd = XTextWidth(gw->label.font, s, xlen) ;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
489 XDrawString(dpy,win,gc, x-wd/2,y, s,xlen) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
490 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
491 else {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
492 XDrawString(dpy,win,gc, y,x+h, s,xlen) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
493 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
494 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
495 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
496 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
497 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
498
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
499
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
500 /*
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
501 * Set specified arguments into widget
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
502 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
503
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
504 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
505 GaugeSetValues (Widget old,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
506 Widget request,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
507 Widget new,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
508 ArgList args,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
509 Cardinal *num_args)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
510 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
511 GaugeWidget oldgw = (GaugeWidget) old;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
512 GaugeWidget gw = (GaugeWidget) new;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
513 Boolean was_resized = False;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
514
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
515 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
516 XtDisownSelection(new, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
517 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
518 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
519
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
520 /* Changes to v0,v1,labels, ntics, nlabels require resize & redraw. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
521 /* Change to value requires redraw and possible resize if autoscale */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
522
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
523 was_resized =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
524 gw->gauge.v0 != oldgw->gauge.v0 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
525 gw->gauge.v1 != oldgw->gauge.v1 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
526 gw->gauge.ntics != oldgw->gauge.ntics ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
527 gw->gauge.nlabels != oldgw->gauge.nlabels ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
528 gw->gauge.labels != oldgw->gauge.labels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
529
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
530 if( (gw->gauge.autoScaleUp && gw->gauge.value > gw->gauge.v1) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
531 (gw->gauge.autoScaleDown && gw->gauge.value < gw->gauge.v1/3 ))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
532 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
533 AutoScale(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
534 was_resized = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
535 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
536
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
537 if( was_resized ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
538 if( gw->label.resize )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
539 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
540 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
541 GaugeResize(new) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
542 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
543
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
544 if( gw->gauge.update != oldgw->gauge.update )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
545 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
546 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
547 EnableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
548 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
549 DisableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
550 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
551
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
552 if( gw->core.background_pixel != oldgw->core.background_pixel )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
553 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
554 XtReleaseGC(new, gw->gauge.inverse_GC) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
555 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
556 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
557
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
558 return was_resized || gw->gauge.value != oldgw->gauge.value ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
559 XtIsSensitive(old) != XtIsSensitive(new);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
560 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
561
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
562
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
563 static XtGeometryResult
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
564 GaugeQueryGeometry (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
565 XtWidgetGeometry *intended,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
566 XtWidgetGeometry *preferred)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
567 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
568 register GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
569
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
570 if( intended->width == w->core.width &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
571 intended->height == w->core.height )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
572 return XtGeometryNo ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
573
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
574 preferred->request_mode = CWWidth | CWHeight;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
575 GaugeSize(gw, &preferred->width, &preferred->height, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
576
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
577 if( (!(intended->request_mode & CWWidth) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
578 intended->width >= preferred->width) &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
579 (!(intended->request_mode & CWHeight) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
580 intended->height >= preferred->height) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
581 return XtGeometryYes;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
582 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
583 return XtGeometryAlmost;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
584 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
585
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
586
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
587
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
588
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
589 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
590 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
591 * Action Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
592 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
593 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
594
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
595 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
596 GaugeSelect (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
597 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
598 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
599 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
600 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
601 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
602 Atom seln = XA_PRIMARY ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
603
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
604 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
605 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
606 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
607 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
608
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
609 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
610 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
611 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
612 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
613
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
614 if( ! XtOwnSelection(w, seln, event->xbutton.time, GaugeConvert,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
615 GaugeLoseSel, GaugeDoneSel) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
616 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
617 /* in real code, this error message would be replaced by
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
618 * something more elegant, or at least deleted
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
619 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
620
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
621 fprintf(stderr, "Gauge failed to get selection, try again\n") ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
622 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
623 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
624 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
625 gw->gauge.selected = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
626 gw->gauge.selstr = (String)XtMalloc(4*sizeof(int)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
627 sprintf(gw->gauge.selstr, "%d", gw->gauge.value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
628 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
629 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
630 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
631
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
632
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
633 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
634 GaugeConvert (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
635 Atom *selection, /* usually XA_PRIMARY */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
636 Atom *target, /* requested target */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
637 Atom *type, /* returned type */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
638 XtPointer *value, /* returned value */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
639 unsigned long *length, /* returned length */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
640 int *format) /* returned format */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
641 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
642 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
643 XSelectionRequestEvent *req ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
644
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
645 printf( "requesting selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
646 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
647 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
648
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
649 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
650 if( *target == XA_TARGETS(XtDisplay(w)) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
651 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
652 Atom *rval, *stdTargets ;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
653 unsigned long stdLength ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
654
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
655 /* XmuConvertStandardSelection can handle this. This function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
656 * will return a list of standard targets. We prepend TEXT,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
657 * STRING and INTEGER to the list and return it.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
658 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
659
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
660 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
661 XmuConvertStandardSelection(w, req->time, selection, target,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
662 type, (XPointer*)&stdTargets, &stdLength, format) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
663
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
664 *type = XA_ATOM ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
665 *length = stdLength + 3 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
666 rval = (Atom *) XtMalloc(sizeof(Atom)*(stdLength+3)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
667 *value = (XtPointer) rval ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
668 *rval++ = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
669 *rval++ = XA_STRING ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
670 *rval++ = XA_TEXT(XtDisplay(w)) ;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
671 memcpy((char *)rval, (char *)stdTargets, stdLength*sizeof(Atom)) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
672 XtFree((char*) stdTargets) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
673 *format = 8*sizeof(Atom) ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
674 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
675 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
676
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
677 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
678 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
679 if( *target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
680 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
681 *type = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
682 *length = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
683 *value = (XtPointer) &gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
684 *format = 8*sizeof(int) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
685 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
686 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
687
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
688 else if( *target == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
689 #ifdef HAVE_XMU
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
690 ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
691 *target == XA_TEXT(XtDisplay(w))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
692 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
693 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
694 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
695 *type = *target ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
696 *length = strlen(gw->gauge.selstr)*sizeof(char) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
697 *value = (XtPointer) gw->gauge.selstr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
698 *format = 8 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
699 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
700 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
701
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
702 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
703 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
704 /* anything else, we just give it to XmuConvertStandardSelection() */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
705 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
706 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
707 if( XmuConvertStandardSelection(w, req->time, selection, target,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
708 type, (XPointer *) value, length, format) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
709 return True ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
710 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
711 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
712 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
713 printf(
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
714 "Gauge: requestor is requesting unsupported selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
715 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
716 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
717 return False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
718 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
719 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
720 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
721
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
722
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
723
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
724 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
725 GaugeLoseSel (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
726 Atom *selection) /* usually XA_PRIMARY */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
727 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
728 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
729 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
730 Window win = XtWindow(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
731
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
732 if( gw->gauge.selstr != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
733 XtFree(gw->gauge.selstr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
734 gw->gauge.selstr = NULL ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
735 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
736
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
737 gw->gauge.selected = False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
738 XClearWindow(dpy,win) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
739 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
740 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
741
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
742
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
743 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
744 GaugeDoneSel (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
745 Atom *selection, /* usually XA_PRIMARY */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
746 Atom *target) /* requested target */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
747 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
748 /* selection done, anything to do? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
749 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
750
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
751
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
752 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
753 GaugePaste (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
754 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
755 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
756 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
757 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
758 Atom seln = XA_PRIMARY ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
759
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
760 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
761 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
762 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
763 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
764
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
765 /* try for integer value first */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
766 XtGetSelectionValue(w, seln, XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
767 GaugeGetSelCB, (XtPointer)XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
768 event->xbutton.time) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
769 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
770
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
771 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
772 GaugeGetSelCB (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
773 XtPointer client,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
774 Atom *selection,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
775 Atom *type,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
776 XtPointer value,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
777 unsigned long *length,
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
778 int *format)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
779 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
780 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
781 Atom target = (Atom)client ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
782 int *iptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
783 char *cptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
784
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
785 if( *type == XA_INTEGER ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
786 iptr = (int *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
787 XawGaugeSetValue(w, *iptr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
788 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
789
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
790 else if( *type == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
791 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
792 ||
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
793 *type == XA_TEXT(dpy)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
794 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
795 )
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
796 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
797 cptr = (char *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
798 XawGaugeSetValue(w, atoi(cptr)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
799 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
800
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
801 /* failed, try string */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
802 else if( *type == None && target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
803 XtGetSelectionValue(w, *selection, XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
804 GaugeGetSelCB, (XtPointer)XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
805 CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
806 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
807
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
808
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
809
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
810 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
811 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
812 * Public Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
813 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
814 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
815
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
816
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
817 /* Change gauge value. Only undraw or draw what needs to be
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
818 * changed.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
819 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
820
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
821 void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
822 XawGaugeSetValue (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
823 Cardinal value)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
824 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
825 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
826 int oldvalue ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
827 GC gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
828
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
829 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
830 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
831 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
832 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
833
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
834 if( !XtIsRealized(w) ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
835 gw->gauge.value = value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
836 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
837 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
838
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
839 /* need to rescale? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
840 if(( gw->gauge.autoScaleUp && value > gw->gauge.v1) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
841 (gw->gauge.autoScaleDown && value < gw->gauge.v1/3 ))
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
842 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
843 XtVaSetValues(w, XtNvalue, value, 0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
844 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
845 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
846
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
847 oldvalue = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
848 gw->gauge.value = value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
849
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
850 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
851 GaugeMercury(XtDisplay(w), XtWindow(w), gc, gw, oldvalue,value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
852 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
853
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
854
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
855 Cardinal
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
856 XawGaugeGetValue (Widget w)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
857 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
858 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
859 return gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
860 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
861
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
862
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
863
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
864
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
865 /****************************************************************
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
866 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
867 * Private Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
868 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
869 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
870
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
871 /* draw the mercury over a specific region */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
872
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
873 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
874 GaugeMercury (Display *dpy,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
875 Window win,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
876 GC gc,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
877 GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
878 Cardinal val0,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
879 Cardinal val1)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
880 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
881 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
882 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
883 int vd = v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
884 Dimension len ; /* length (width or height) of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
885 Position e0, e1 ; /* gauge ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
886 Position p0, p1 ; /* mercury ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
887 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
888 Boolean undraw = FALSE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
889
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
890 len = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
891 gw->core.width : gw->core.height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
892
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
893 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
894 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
895
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
896 if( vd <= 0 ) vd = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
897
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
898 if( val0 < v0 ) val0 = v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
899 else if( val0 > v1 ) val0 = v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
900 if( val1 < v0 ) val1 = v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
901 else if( val1 > v1 ) val1 = v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
902
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
903 p0 = (val0-v0)*(e1-e0-1)/vd ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
904 p1 = (val1-v0)*(e1-e0-1)/vd ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
905
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
906 if( p1 == p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
907 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
908
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
909 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
910
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
911 if( p1 < p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
912 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
913 Position tmp = p0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
914 p0 = p1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
915 p1 = tmp ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
916 gc = gw->label.normal_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
917 XSetForeground(dpy,gc, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
918 undraw = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
919 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
920
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
921 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
922 XFillRectangle(dpy,win,gc, e0+p0+1,y+1, p1-p0,GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
923 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
924 XFillRectangle(dpy,win,gc, y+1,e1-p1, GA_WID,p1-p0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
925
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
926 if( undraw )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
927 XSetForeground(dpy,gc, gw->label.foreground) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
928 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
929
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
930
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
931
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
932 /* Search the labels, find the largest one. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
933 /* TODO: handle vertical fonts? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
934
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
935 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
936 MaxLabel (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
937 Dimension *wid, /* max label width */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
938 Dimension *hgt, /* max label height */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
939 Dimension *w0, /* width of first label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
940 Dimension *w1) /* width of last label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
941 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
942 char lstr[80], *lbl ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
943 int w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
944 XFontStruct *font = gw->label.font ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
945 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
946 int lw = 0;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
947 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
948 int dv = gw->gauge.v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
949 int n = gw->gauge.nlabels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
950
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
951 if( n > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
952 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
953 if( --n <= 0 ) {n = 1 ; v0 += dv/2 ;}
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
954
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
955 /* loop through all labels, figure out how much room they
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
956 * need.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
957 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
958 w = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
959 for(i=0; i<gw->gauge.nlabels; ++i)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
960 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
961 if( gw->gauge.labels == NULL ) /* numeric labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
962 sprintf(lbl = lstr,"%d", v0 + i*dv/n) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
963 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
964 lbl = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
965
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
966 if( lbl != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
967 lw = XTextWidth(font, lbl, strlen(lbl)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
968 w = Max( w, lw ) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
969 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
970 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
971 lw = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
972
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
973 if( i == 0 && w0 != NULL ) *w0 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
974 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
975 if( w1 != NULL ) *w1 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
976
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
977 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
978 *hgt = font->max_bounds.ascent + font->max_bounds.descent ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
979 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
980 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
981 *wid = *hgt = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
982 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
983
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
984
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
985 /* Determine the preferred size for this widget. choose 100x100 for
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
986 * debugging.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
987 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
988
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
989 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
990 GaugeSize (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
991 Dimension *wid,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
992 Dimension *hgt,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
993 Dimension min_len)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
994 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
995 int w,h ; /* width, height of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
996 int vmargin ; /* vertical margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
997 int hmargin ; /* horizontal margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
998
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
999 hmargin = gw->label.internal_width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1000 vmargin = gw->label.internal_height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1001
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1002 /* find total height (width) of contents */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1003
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1004
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1005 /* find minimum size for undecorated gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1006
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1007 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1008 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1009 w = min_len ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1010 h = GA_WID+2 ; /* gauge itself + edges */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1011 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1012 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1013 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1014 w = GA_WID+2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1015 h = min_len ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1016 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1017
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1018 if( gw->gauge.ntics > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1019 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1020 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1021 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1022 w = Max(w, gw->gauge.ntics*3) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1023 h += vmargin + TIC_LEN ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1024 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1025 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1026 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1027 w += hmargin + TIC_LEN ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1028 h = Max(h, gw->gauge.ntics*3) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1029 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1030 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1031
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1032
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1033 /* If labels are requested, this gets a little interesting.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1034 * We want the end labels centered on the ends of the gauge and
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1035 * the centers of the labels evenly spaced. The labels at the ends
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1036 * will not be the same width, meaning that the gauge itself need
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1037 * not be centered in the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1038 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1039 * First, determine the spacing. This is the width of the widest
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1040 * label, plus the internal margin. Total length of the gauge is
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1041 * spacing * (nlabels-1). To this, we add half the width of the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1042 * left-most label and half the width of the right-most label
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1043 * to get the entire desired width of the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1044 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1045 if( gw->gauge.nlabels > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1046 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1047 Dimension lwm, lw0, lw1 ; /* width of max, left, right labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1048 Dimension lh ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1049
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1050 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1051
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1052 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1053 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1054 lwm = (lwm+hmargin) * (gw->gauge.nlabels-1) + (lw0+lw1)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1055 w = Max(w, lwm) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1056 h += lh + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1057 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1058 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1059 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1060 lh = lh*gw->gauge.nlabels + (gw->gauge.nlabels - 1)*vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1061 h = Max(h, lh) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1062 w += lwm + hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1063 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1064 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1065
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1066 w += hmargin*2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1067 h += vmargin*2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1068
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1069 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1070 *hgt = h ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1071 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1072
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1073
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1074
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1075 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1076 AutoScale (GaugeWidget gw)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1077 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1078 static int scales[3] = {1,2,5} ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1079 int sptr = 0, smult=1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1080
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1081 if( gw->gauge.autoScaleDown )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1082 gw->gauge.v1 = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1083 while( gw->gauge.value > gw->gauge.v1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1084 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1085 if( ++sptr > 2 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1086 sptr = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1087 smult *= 10 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1088 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1089 gw->gauge.v1 = scales[sptr] * smult ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1090 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1091 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1092
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1093 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1094 EnableUpdate (GaugeWidget gw)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1095 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1096 gw->gauge.intervalId =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1097 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)gw),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1098 gw->gauge.update * MS_PER_SEC, GaugeGetValue,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1099 (XtPointer)gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1100 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1101
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1102 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1103 DisableUpdate (GaugeWidget gw)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1104 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1105 XtRemoveTimeOut(gw->gauge.intervalId) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1106 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1107
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1108 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1109 GaugeGetValue (XtPointer clientData,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1110 XtIntervalId *intervalId)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1111 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1112 GaugeWidget gw = (GaugeWidget)clientData ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1113 Cardinal value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1114
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1115 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1116 EnableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1117
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1118 if( gw->gauge.getValue != NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1119 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1120 XtCallCallbackList((Widget)gw, gw->gauge.getValue, (XtPointer)&value);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1121 XawGaugeSetValue((Widget)gw, value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1122 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1123 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1124
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1125
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1126 static GC
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1127 Get_GC (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1128 Pixel fg)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1129 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1130 XGCValues values ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1131 #define vmask GCForeground
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1132 #define umask (GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1133 |GCFont|GCDashList|GCArcMode)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1134
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1135 values.foreground = fg ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1136
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1137 return XtAllocateGC((Widget)gw, 0, vmask, &values, 0L, umask) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1138 }