annotate lwlib/xlwgauge.c @ 4522:fc7067b7f407

Backout last patch; forgot to specify file.
author Stephen J. Turnbull <stephen@xemacs.org>
date Wed, 29 Oct 2008 03:37:16 +0900
parents 383ab474a241
children 726060ee587c
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
4522
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
80 #define offset(field) XtOffsetOf(GaugeRec, field)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
81 static XtResource resources[] = {
4522
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
82 {XtNvalue, XtCValue, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
83 offset(gauge.value), XtRImmediate, (XtPointer)0},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
84 {XtNminValue, XtCMinValue, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
85 offset(gauge.v0), XtRImmediate, (XtPointer)0},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
86 {XtNmaxValue, XtCMaxValue, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
87 offset(gauge.v1), XtRImmediate, (XtPointer)100},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
88 {XtNntics, XtCNTics, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
89 offset(gauge.ntics), XtRImmediate, (XtPointer) 0},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
90 {XtNnlabels, XtCNLabels, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
91 offset(gauge.nlabels), XtRImmediate, (XtPointer) 0},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
92 {XtNlabels, XtCLabels, XtRStringArray, sizeof(String *),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
93 offset(gauge.labels), XtRStringArray, NULL},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
94 {XtNautoScaleUp, XtCAutoScaleUp, XtRBoolean, sizeof(Boolean),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
95 offset(gauge.autoScaleUp), XtRImmediate, FALSE},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
96 {XtNautoScaleDown, XtCAutoScaleDown, XtRBoolean, sizeof(Boolean),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
97 offset(gauge.autoScaleDown), XtRImmediate, FALSE},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
98 {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
99 offset(gauge.orientation), XtRImmediate, (XtPointer)XtorientHorizontal},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
100 {XtNupdate, XtCInterval, XtRInt, sizeof(int),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
101 offset(gauge.update), XtRImmediate, (XtPointer)0},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
102 {XtNgetValue, XtCCallback, XtRCallback, sizeof(XtPointer),
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
103 offset(gauge.getValue), XtRImmediate, (XtPointer)NULL},
424
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
4522
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
106
424
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 *);
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
135 static void GaugeMercury (Display *, Window, GC, GaugeWidget, int, int);
424
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 {
4522
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
149 {"select", GaugeSelect},
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
150 {"paste", GaugePaste},
424
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,
4522
fc7067b7f407 Backout last patch; forgot to specify file.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4521
diff changeset
165 /* class_name */ "Gauge",
424
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,
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
243 Widget new_,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
244 ArgList UNUSED (args),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
245 Cardinal *UNUSED (num_args))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
246 {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
247 GaugeWidget gw = (GaugeWidget) new_;
424
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 )
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
261 new_->core.width = w ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
262 if( request->core.height == 0 )
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
263 new_->core.height = h ;
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
264 gw->core.widget_class->core_class.resize(new_) ;
424
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,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
369 XEvent *UNUSED (event),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
370 Region UNUSED (region))
424
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 e0,e1 ; /* ends of the gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
380 int x ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
381 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
382 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
383 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
384 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
385 int value = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
386
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
387 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
388
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 #ifdef _ThreeDP_h
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
391 gctop = gw->threeD.bot_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
392 gcbot = gw->threeD.top_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
393 #else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
394 gctop = gcbot = gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
395 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
396
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
397 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
398 len = gw->core.width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
399 } else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
400 len = gw->core.height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
401 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
402
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
403 /* if the gauge is selected, signify by drawing the background
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
404 * in a contrasting color.
424
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
407 if( gw->gauge.selected )
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 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
410 gc = gw->gauge.inverse_GC ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
413 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
414 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
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 /* Draw the Gauge itself */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
417
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
418 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
419
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
420 if( gw->gauge.orientation == XtorientHorizontal ) /* horizontal */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
421 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
422 XDrawLine(dpy,win,gctop, e0+1,y, e1-1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
423 XDrawLine(dpy,win,gctop, e0,y+1, e0,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
424 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
425 XDrawLine(dpy,win,gcbot, e1,y+1, e1,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
426 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
427 else /* vertical */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
428 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
429 XDrawLine(dpy,win,gctop, y,e0+1, y,e1-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
430 XDrawLine(dpy,win,gctop, y+1,e0, y+GA_WID,e0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
431 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
432 XDrawLine(dpy,win,gcbot, y+1,e1, y+GA_WID,e1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
433 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
434
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
435
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
436 /* draw the mercury */
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 GaugeMercury(dpy, win, gc, gw, 0,value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
439
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 if( gw->gauge.ntics > 1 )
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 y = gw->gauge.tmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
444 for(i=0; i<gw->gauge.ntics; ++i)
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 x = e0 + i*(e1-e0-1)/(gw->gauge.ntics-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
447 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
448 XDrawLine(dpy,win,gcbot, x,y+1, x,y+TIC_LEN-2) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
449 XDrawLine(dpy,win,gcbot, x,y, x+1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
450 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
451 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
452 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
453 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
454 XDrawLine(dpy,win,gcbot, y+1,x, y+TIC_LEN-2,x) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
455 XDrawLine(dpy,win,gcbot, y,x, y,x+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
456 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
457 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
458 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
459 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
460 }
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 /* draw labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
463 if( gw->gauge.nlabels > 1 )
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 char label[20], *s = label ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
466 int xlen, wd,h =0 ;
424
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
469 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
470 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
471 y = gw->gauge.lmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
472 h = gw->label.font->max_bounds.ascent / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
473 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
474
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
475 for(i=0; i<gw->gauge.nlabels; ++i)
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 if( gw->gauge.labels == NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
478 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
479 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
480 s = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
481 if( s != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
482 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
483 xlen = strlen(s) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
484 if( gw->gauge.orientation == XtorientHorizontal ) {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
485 wd = XTextWidth(gw->label.font, s, xlen) ;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
486 XDrawString(dpy,win,gc, x-wd/2,y, s,xlen) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
487 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
488 else {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
489 XDrawString(dpy,win,gc, y,x+h, 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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
492 }
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 * Set specified arguments into widget
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 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
502 GaugeSetValues (Widget old,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
503 Widget UNUSED (request),
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
504 Widget new_,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
505 ArgList UNUSED (args),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
506 Cardinal *UNUSED (num_args))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
507 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
508 GaugeWidget oldgw = (GaugeWidget) old;
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
509 GaugeWidget gw = (GaugeWidget) new_;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
510 Boolean was_resized = False;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
511
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
512 if( gw->gauge.selected != None ) {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
513 XtDisownSelection(new_, gw->gauge.selected, CurrentTime) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
514 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
515 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
516
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
517 /* Changes to v0,v1,labels, ntics, nlabels require resize & redraw. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
518 /* Change to value requires redraw and possible resize if autoscale */
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 was_resized =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
521 gw->gauge.v0 != oldgw->gauge.v0 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
522 gw->gauge.v1 != oldgw->gauge.v1 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
523 gw->gauge.ntics != oldgw->gauge.ntics ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
524 gw->gauge.nlabels != oldgw->gauge.nlabels ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
525 gw->gauge.labels != oldgw->gauge.labels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
526
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
527 if( (gw->gauge.autoScaleUp && gw->gauge.value > gw->gauge.v1) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
528 (gw->gauge.autoScaleDown && gw->gauge.value < gw->gauge.v1/3 ))
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 AutoScale(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
531 was_resized = TRUE ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
534 if( was_resized ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
535 if( gw->label.resize )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
536 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
537 else
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
538 GaugeResize(new_) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
539 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
540
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
541 if( gw->gauge.update != oldgw->gauge.update )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
542 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
543 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
544 EnableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
545 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
546 DisableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
547 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
548
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
549 if( gw->core.background_pixel != oldgw->core.background_pixel )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
550 {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
551 XtReleaseGC(new_, gw->gauge.inverse_GC) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
552 gw->gauge.inverse_GC = Get_GC(gw, gw->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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
555 return was_resized || gw->gauge.value != oldgw->gauge.value ||
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
556 XtIsSensitive(old) != XtIsSensitive(new_);
424
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
559
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
560 static XtGeometryResult
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
561 GaugeQueryGeometry (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
562 XtWidgetGeometry *intended,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
563 XtWidgetGeometry *preferred)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
564 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
565 register GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
566
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
567 if( intended->width == w->core.width &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
568 intended->height == w->core.height )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
569 return XtGeometryNo ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
570
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
571 preferred->request_mode = CWWidth | CWHeight;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
572 GaugeSize(gw, &preferred->width, &preferred->height, DEF_LEN) ;
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 if( (!(intended->request_mode & CWWidth) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
575 intended->width >= preferred->width) &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
576 (!(intended->request_mode & CWHeight) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
577 intended->height >= preferred->height) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
578 return XtGeometryYes;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
579 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
580 return XtGeometryAlmost;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
581 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
582
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
583
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 * Action Procedures
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
592 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
593 GaugeSelect (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
594 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
595 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
596 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
597 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
598 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
599 Atom seln = XA_PRIMARY ;
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 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
602 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
603 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
604 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
605
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
606 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
607 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
608 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
609 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
610
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
611 if( ! XtOwnSelection(w, seln, event->xbutton.time, GaugeConvert,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
612 GaugeLoseSel, GaugeDoneSel) )
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 /* in real code, this error message would be replaced by
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
615 * something more elegant, or at least deleted
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
618 fprintf(stderr, "Gauge failed to get selection, try again\n") ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
621 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
622 gw->gauge.selected = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
623 gw->gauge.selstr = (String)XtMalloc(4*sizeof(int)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
624 sprintf(gw->gauge.selstr, "%d", gw->gauge.value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
625 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
626 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
627 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
628
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 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
631 GaugeConvert (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
632 Atom *selection, /* usually XA_PRIMARY */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
633 Atom *target, /* requested target */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
634 Atom *type, /* returned type */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
635 XtPointer *value, /* returned value */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
636 unsigned long *length, /* returned length */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
637 int *format) /* returned format */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
638 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
639 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
640 XSelectionRequestEvent *req ;
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 printf( "requesting selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
643 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
644 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
645
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
646 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
647 if( *target == XA_TARGETS(XtDisplay(w)) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
648 {
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
649 XPointer stdTargets;
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
650 Atom *rval ;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
651 unsigned long stdLength ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
652
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
653 /* XmuConvertStandardSelection can handle this. This function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
654 * will return a list of standard targets. We prepend TEXT,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
655 * STRING and INTEGER to the list and return it.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
656 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
657
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
658 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
659 XmuConvertStandardSelection(w, req->time, selection, target,
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
660 type, &stdTargets, &stdLength, format) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
661
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
662 *type = XA_ATOM ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
663 *length = stdLength + 3 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
664 rval = (Atom *) XtMalloc(sizeof(Atom)*(stdLength+3)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
665 *value = (XtPointer) rval ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
666 *rval++ = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
667 *rval++ = XA_STRING ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
668 *rval++ = XA_TEXT(XtDisplay(w)) ;
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
669 memcpy(rval, stdTargets, stdLength*sizeof(Atom)) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
670 XtFree((char*) stdTargets) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
671 *format = 8*sizeof(Atom) ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
672 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
673 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
674
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
675 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
676 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
677 if( *target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
678 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
679 *type = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
680 *length = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
681 *value = (XtPointer) &gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
682 *format = 8*sizeof(int) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
683 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
684 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
685
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
686 else if( *target == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
687 #ifdef HAVE_XMU
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
688 ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
689 *target == XA_TEXT(XtDisplay(w))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
690 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
691 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
692 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
693 *type = *target ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
694 *length = strlen(gw->gauge.selstr)*sizeof(char) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
695 *value = (XtPointer) gw->gauge.selstr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
696 *format = 8 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
697 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
698 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
699
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
700 else
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 /* anything else, we just give it to XmuConvertStandardSelection() */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
703 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
704 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
705 if( XmuConvertStandardSelection(w, req->time, selection, target,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
706 type, (XPointer *) value, length, format) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
707 return True ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
708 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
709 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
710 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
711 printf(
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
712 "Gauge: requestor is requesting unsupported selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
713 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
714 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
715 return False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
716 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
717 }
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
723 GaugeLoseSel (Widget w,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
724 Atom *UNUSED (selection)) /* usually XA_PRIMARY */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
725 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
726 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
727 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
728 Window win = XtWindow(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
729
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
730 if( gw->gauge.selstr != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
731 XtFree(gw->gauge.selstr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
732 gw->gauge.selstr = NULL ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
733 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
734
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
735 gw->gauge.selected = False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
736 XClearWindow(dpy,win) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
737 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
738 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
739
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 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
742 GaugeDoneSel (Widget UNUSED (w),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
743 Atom *UNUSED (selection), /* usually XA_PRIMARY */
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
744 Atom *UNUSED (target)) /* requested target */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
745 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
746 /* selection done, anything to do? */
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
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
751 GaugePaste (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
752 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
753 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
754 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
755 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
756 Atom seln = XA_PRIMARY ;
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 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
759 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
760 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
761 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
762
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
763 /* try for integer value first */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
764 XtGetSelectionValue(w, seln, XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
765 GaugeGetSelCB, (XtPointer)XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
766 event->xbutton.time) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
767 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
768
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
769 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
770 GaugeGetSelCB (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
771 XtPointer client,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
772 Atom *selection,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
773 Atom *type,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
774 XtPointer value,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
775 unsigned long *UNUSED (length),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
776 int *UNUSED (format))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
777 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
778 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
779 Atom target = (Atom)client ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
780 int *iptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
781 char *cptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
782
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
783 if( *type == XA_INTEGER ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
784 iptr = (int *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
785 XawGaugeSetValue(w, *iptr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
786 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
787
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
788 else if( *type == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
789 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
790 ||
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
791 *type == XA_TEXT(dpy)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
792 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
793 )
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
794 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
795 cptr = (char *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
796 XawGaugeSetValue(w, atoi(cptr)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
797 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
798
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
799 /* failed, try string */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
800 else if( *type == None && target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
801 XtGetSelectionValue(w, *selection, XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
802 GaugeGetSelCB, (XtPointer)XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
803 CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
804 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
805
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 * Public Procedures
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 ****************************************************************/
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 /* Change gauge value. Only undraw or draw what needs to be
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
816 * changed.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
817 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
818
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
819 void
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
820 XawGaugeSetValue (Widget w, int value)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
821 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
822 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
823 int oldvalue ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
824 GC gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
825
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
826 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
827 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
828 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
829 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
830
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
831 if( !XtIsRealized(w) ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
832 gw->gauge.value = value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
833 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
834 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
835
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
836 /* need to rescale? */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 458
diff changeset
837 if(( gw->gauge.autoScaleUp && (int) value > gw->gauge.v1) ||
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 458
diff changeset
838 (gw->gauge.autoScaleDown && (int) value < gw->gauge.v1/3 ))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
839 {
3374
174eb4da74fb [xemacs-hg @ 2006-05-02 15:30:31 by james]
james
parents: 3055
diff changeset
840 XtVaSetValues(w, XtNvalue, value, NULL) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
841 return ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
844 oldvalue = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
845 gw->gauge.value = value ;
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 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
848 GaugeMercury(XtDisplay(w), XtWindow(w), gc, gw, oldvalue,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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
851
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
852 int
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
853 XawGaugeGetValue (Widget w)
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 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
856 return gw->gauge.value ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
859
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 * Private Procedures
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
868 /* draw the mercury over a specific region */
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
871 GaugeMercury (Display *dpy,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
872 Window win,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
873 GC gc,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
874 GaugeWidget gw,
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
875 int val0,
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
876 int val1)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
877 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
878 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
879 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
880 int vd = v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
881 Dimension len ; /* length (width or height) of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
882 Position e0, e1 ; /* gauge ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
883 Position p0, p1 ; /* mercury ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
884 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
885 Boolean undraw = FALSE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
886
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
887 len = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
888 gw->core.width : gw->core.height ;
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 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
891 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
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 if( vd <= 0 ) vd = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
894
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
895 if( val0 < v0 ) val0 = v0 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
896 else if( val0 > v1 ) val0 = v1 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
897 if( val1 < v0 ) val1 = v0 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
898 else if( val1 > v1 ) val1 = v1 ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
899
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
900 p0 = (val0-v0)*(e1-e0-1)/vd ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
901 p1 = (val1-v0)*(e1-e0-1)/vd ;
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 if( p1 == p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
904 return ;
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 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
907
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
908 if( p1 < p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
909 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
910 Position tmp = p0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
911 p0 = p1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
912 p1 = tmp ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
913 gc = gw->label.normal_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
914 XSetForeground(dpy,gc, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
915 undraw = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
916 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
917
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
918 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
919 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
920 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
921 XFillRectangle(dpy,win,gc, y+1,e1-p1, GA_WID,p1-p0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
922
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
923 if( undraw )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
924 XSetForeground(dpy,gc, gw->label.foreground) ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
927
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 /* Search the labels, find the largest one. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
930 /* TODO: handle vertical fonts? */
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
933 MaxLabel (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
934 Dimension *wid, /* max label width */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
935 Dimension *hgt, /* max label height */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
936 Dimension *w0, /* width of first label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
937 Dimension *w1) /* width of last label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
938 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
939 char lstr[80], *lbl ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
940 int w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
941 XFontStruct *font = gw->label.font ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
942 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
943 int lw = 0;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
944 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
945 int dv = gw->gauge.v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
946 int n = gw->gauge.nlabels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
947
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
948 if( n > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
949 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
950 if( --n <= 0 ) {n = 1 ; v0 += dv/2 ;}
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
951
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
952 /* loop through all labels, figure out how much room they
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
953 * need.
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 w = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
956 for(i=0; i<gw->gauge.nlabels; ++i)
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 if( gw->gauge.labels == NULL ) /* numeric labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
959 sprintf(lbl = lstr,"%d", v0 + i*dv/n) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
960 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
961 lbl = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
962
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
963 if( lbl != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
964 lw = XTextWidth(font, lbl, strlen(lbl)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
965 w = Max( w, lw ) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
966 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
967 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
968 lw = 0 ;
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 if( i == 0 && w0 != NULL ) *w0 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
971 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
972 if( w1 != NULL ) *w1 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
973
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
974 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
975 *hgt = font->max_bounds.ascent + font->max_bounds.descent ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
978 *wid = *hgt = 0 ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
981
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
982 /* Determine the preferred size for this widget. choose 100x100 for
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
983 * debugging.
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
986 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
987 GaugeSize (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
988 Dimension *wid,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
989 Dimension *hgt,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
990 Dimension min_len)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
991 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
992 int w,h ; /* width, height of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
993 int vmargin ; /* vertical margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
994 int hmargin ; /* horizontal margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
995
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
996 hmargin = gw->label.internal_width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
997 vmargin = gw->label.internal_height ;
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 /* find total height (width) of contents */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1000
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 minimum size for undecorated gauge */
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1005 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1006 w = min_len ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1007 h = GA_WID+2 ; /* gauge itself + edges */
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1010 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1011 w = GA_WID+2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1012 h = min_len ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1015 if( gw->gauge.ntics > 0 )
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1018 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1019 w = Max(w, gw->gauge.ntics*3) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1020 h += vmargin + TIC_LEN ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1023 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1024 w += hmargin + TIC_LEN ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1025 h = Max(h, gw->gauge.ntics*3) ;
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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1028
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 /* If labels are requested, this gets a little interesting.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1031 * 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
1032 * the centers of the labels evenly spaced. The labels at the ends
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1033 * will not be the same width, meaning that the gauge itself need
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1034 * not be centered in the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1035 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1036 * First, determine the spacing. This is the width of the widest
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1037 * label, plus the internal margin. Total length of the gauge is
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1038 * spacing * (nlabels-1). To this, we add half the width of the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1039 * left-most label and half the width of the right-most label
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1040 * to get the entire desired width of the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1041 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1042 if( gw->gauge.nlabels > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1043 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1044 Dimension lwm, lw0, lw1 ; /* width of max, left, right labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1045 Dimension lh ;
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 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1048
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1049 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1050 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1051 lwm = (lwm+hmargin) * (gw->gauge.nlabels-1) + (lw0+lw1)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1052 w = Max(w, lwm) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1053 h += lh + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1054 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1055 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1056 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1057 lh = lh*gw->gauge.nlabels + (gw->gauge.nlabels - 1)*vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1058 h = Max(h, lh) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1059 w += lwm + hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1060 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1061 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1062
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1063 w += hmargin*2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1064 h += vmargin*2 ;
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 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1067 *hgt = h ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1070
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1073 AutoScale (GaugeWidget gw)
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 int scales[3] = {1,2,5} ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1076 int sptr = 0, smult=1 ;
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 if( gw->gauge.autoScaleDown )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1079 gw->gauge.v1 = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1080 while( gw->gauge.value > gw->gauge.v1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1081 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1082 if( ++sptr > 2 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1083 sptr = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1084 smult *= 10 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1085 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1086 gw->gauge.v1 = scales[sptr] * smult ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1087 }
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1090 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1091 EnableUpdate (GaugeWidget gw)
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 gw->gauge.intervalId =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1094 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)gw),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1095 gw->gauge.update * MS_PER_SEC, GaugeGetValue,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1096 (XtPointer)gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1097 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1098
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1099 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1100 DisableUpdate (GaugeWidget gw)
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 XtRemoveTimeOut(gw->gauge.intervalId) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1103 }
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1106 GaugeGetValue (XtPointer clientData,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
1107 XtIntervalId *UNUSED (intervalId))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1108 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1109 GaugeWidget gw = (GaugeWidget)clientData ;
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
1110 int value ;
424
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 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1113 EnableUpdate(gw) ;
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.getValue != NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1116 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1117 XtCallCallbackList((Widget)gw, gw->gauge.getValue, (XtPointer)&value);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1118 XawGaugeSetValue((Widget)gw, value) ;
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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1121
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 static GC
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1124 Get_GC (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1125 Pixel fg)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1126 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1127 XGCValues values ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1128 #define vmask GCForeground
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1129 #define umask (GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1130 |GCFont|GCDashList|GCArcMode)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1131
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1132 values.foreground = fg ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1133
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1134 return XtAllocateGC((Widget)gw, 0, vmask, &values, 0L, umask) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1135 }