annotate lwlib/xlwgauge.c @ 4570:e6a7054a9c30

Add check-coding-systems-region, test it and others, fix some bugs. tests/ChangeLog addition: 2008-12-28 Aidan Kehoe <kehoea@parhasard.net> * automated/query-coding-tests.el: Add tests for #'unencodable-char-position, #'check-coding-systems-region, #'encode-coding-char. Remove some debugging statements. lisp/ChangeLog addition: 2008-12-28 Aidan Kehoe <kehoea@parhasard.net> * coding.el (query-coding-region): (query-coding-string): Make these defsubsts, they're short enough and they're called explicitly rarely enough that it make some sense. The alternative would be compiler macros that avoid the binding of the arguments. (unencodable-char-position): Document where the docstring and API are from. Correct a special case for zero--check-argument-type returns nil when it succeeds, we can't usefully chain its result in an and here. (check-coding-systems-region): New. API taken from GNU; docstring and implementation are independent. (encode-coding-char): Add an optional third argument, as used by recent GNU. Document the origen of the docstring. (default-query-coding-region): Add a short docstring to the non-Mule implementation of this function. * unicode.el: Don't set the query-coding-function property for unicode coding systems if we're on non-mule. Unintern unicode-query-coding-region, unicode-query-coding-skip-chars-arg in the same context.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 28 Dec 2008 22:51:14 +0000
parents 726060ee587c
children 5460287a3327
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_
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
56 #include "xt-wrappers.h"
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
57 #include "xlwgaugeP.h"
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
58 #include "../src/xmu.h"
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
59 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
60 #include <X11/Xmu/Atoms.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
61 #include <X11/Xmu/Drawing.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
62 #include <X11/Xmu/StdSel.h>
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
63 #endif
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 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
68 * Gauge resources
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
73 static char defaultTranslations[] =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
74 "<Btn1Up>: select()\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
75 <Key>F1: select(CLIPBOARD)\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
76 <Btn2Up>: paste()\n\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
77 <Key>F2: paste(CLIPBOARD)" ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
78
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
79
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
80
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
81 #define offset(field) XtOffsetOf(GaugeRec, gauge.field)
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
82 #define res(name,_class,intrepr,type,member,extrepr,value) \
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
83 Xt_RESOURCE (name, _class, intrepr, type, offset(member), extrepr, value)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
84 static XtResource resources[] = {
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
85 res (XtNvalue, XtCValue, XtRInt, int, value, XtRImmediate, 0),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
86 res (XtNminValue, XtCMinValue, XtRInt, int, v0, XtRImmediate, 0),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
87 res (XtNmaxValue, XtCMaxValue, XtRInt, int, v1, XtRImmediate, 100),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
88 res (XtNntics, XtCNTics, XtRInt, int, ntics, XtRImmediate, 0),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
89 res (XtNnlabels, XtCNLabels, XtRInt, int, nlabels, XtRImmediate, 0),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
90 res (XtNlabels, XtCLabels, XtRStringArray, String *, labels,
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
91 XtRStringArray, NULL),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
92 res (XtNautoScaleUp, XtCAutoScaleUp, XtRBoolean, Boolean, autoScaleUp,
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
93 XtRImmediate, FALSE),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
94 res (XtNautoScaleDown, XtCAutoScaleDown, XtRBoolean, Boolean,
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
95 autoScaleDown, XtRImmediate, FALSE),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
96 res (XtNorientation, XtCOrientation, XtROrientation, XtOrientation,
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
97 orientation, XtRImmediate, XtorientHorizontal),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
98 res (XtNupdate, XtCInterval, XtRInt, int, update, XtRImmediate, 0),
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
99 res (XtNgetValue, XtCCallback, XtRCallback, XtPointer, getValue,
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
100 XtRImmediate, NULL),
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
101 };
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
102 #undef offset
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
103 #undef res
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
106 /* member functions */
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 static void GaugeClassInit (void);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
109 static void GaugeInit (Widget, Widget, ArgList, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
110 static void GaugeDestroy (Widget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
111 static void GaugeResize (Widget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
112 static void GaugeExpose (Widget, XEvent *, Region);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
113 static Boolean GaugeSetValues (Widget, Widget, Widget, ArgList, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
114 static XtGeometryResult GaugeQueryGeometry (Widget, XtWidgetGeometry *,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
115 XtWidgetGeometry *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
116
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
117 /* action procs */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
118
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
119 static void GaugeSelect (Widget, XEvent *, String *, Cardinal *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
120 static void GaugePaste (Widget, XEvent *, String *, Cardinal *);
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 /* internal privates */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
123
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
124 static void GaugeSize (GaugeWidget, Dimension *, Dimension *, Dimension);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
125 static void MaxLabel (GaugeWidget, Dimension *, Dimension *,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
126 Dimension *, Dimension *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
127 static void AutoScale (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
128 static void EnableUpdate (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
129 static void DisableUpdate (GaugeWidget);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
130
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
131 static void GaugeGetValue (XtPointer, XtIntervalId *);
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
132 static void GaugeMercury (Display *, Window, GC, GaugeWidget, int, int);
424
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 Boolean GaugeConvert (Widget, Atom *, Atom *, Atom *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
135 XtPointer *, unsigned long *, int *);
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
136 static void GaugeLoseSel (Widget, Atom *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
137 static void GaugeDoneSel (Widget, Atom *, Atom *);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
138 static void GaugeGetSelCB (Widget, XtPointer, Atom *, Atom *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
139 XtPointer, unsigned long *, int *);
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
140
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
141 static GC Get_GC (GaugeWidget, Pixel);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
142
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 XtActionsRec actionsList[] =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
145 {
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
146 { (String) "select", GaugeSelect },
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
147 { (String) "paste", GaugePaste },
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
148 } ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
149
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
150
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 * Full class record constant
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
158 GaugeClassRec gaugeClassRec = {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
159 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
160 /* core_class fields */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
161 /* superclass */ (WidgetClass) &labelClassRec,
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
162 /* class_name */ (String) "Gauge",
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
163 /* widget_size */ sizeof(GaugeRec),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
164 /* class_initialize */ GaugeClassInit,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
165 /* class_part_initialize */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
166 /* class_inited */ FALSE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
167 /* initialize */ GaugeInit,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
168 /* initialize_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
169 /* realize */ XtInheritRealize, /* TODO? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
170 /* actions */ actionsList,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
171 /* num_actions */ XtNumber(actionsList),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
172 /* resources */ resources,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
173 /* num_resources */ XtNumber(resources),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
174 /* xrm_class */ NULLQUARK,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
175 /* compress_motion */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
176 /* compress_exposure */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
177 /* compress_enterleave */ TRUE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
178 /* visible_interest */ FALSE,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
179 /* destroy */ GaugeDestroy,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
180 /* resize */ GaugeResize,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
181 /* expose */ GaugeExpose,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
182 /* set_values */ GaugeSetValues,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
183 /* set_values_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
184 /* set_values_almost */ XtInheritSetValuesAlmost,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
185 /* get_values_hook */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
186 /* accept_focus */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
187 /* version */ XtVersion,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
188 /* callback_private */ NULL,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
189 /* tm_table */ defaultTranslations,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
190 /* query_geometry */ GaugeQueryGeometry,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
191 /* display_accelerator */ XtInheritDisplayAccelerator,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
192 /* extension */ NULL
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
193 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
194 /* Simple class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
195 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
196 /* change_sensitive */ XtInheritChangeSensitive
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
197 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
198 #ifdef _ThreeDP_h
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
199 /* ThreeD class fields initialization */
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 XtInheritXaw3dShadowDraw /* shadowdraw */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
202 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
203 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
204 /* Label class fields initialization */
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 /* ignore */ 0
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
207 },
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
208 /* Gauge class fields initialization */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
209 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
210 /* extension */ NULL
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
211 },
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
214 WidgetClass gaugeWidgetClass = (WidgetClass)&gaugeClassRec;
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
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 * Member Procedures
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
225 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
226 GaugeClassInit (void)
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 XawInitializeWidgetSet();
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
229 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
230 XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
231 NULL, 0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
232 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
233 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
234
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
235
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 /* ARGSUSED */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
238 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
239 GaugeInit (Widget request,
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
240 Widget new_,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
241 ArgList UNUSED (args),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
242 Cardinal *UNUSED (num_args))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
243 {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
244 GaugeWidget gw = (GaugeWidget) new_;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
245
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
246 if( gw->gauge.v0 == 0 && gw->gauge.v1 == 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
247 gw->gauge.autoScaleUp = gw->gauge.autoScaleDown = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
248 AutoScale(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
249 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
250
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
251 /* If size not explicitly set, set it to our preferred size now. */
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 if( request->core.width == 0 || request->core.height == 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
254 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
255 Dimension w,h ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
256 GaugeSize(gw, &w,&h, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
257 if( request->core.width == 0 )
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
258 new_->core.width = w ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
259 if( request->core.height == 0 )
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
260 new_->core.height = h ;
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
261 gw->core.widget_class->core_class.resize(new_) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
262 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
263
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
264 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
265 gw->gauge.selstr = NULL ;
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 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
268 EnableUpdate(gw) ;
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 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
271 }
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
274 GaugeDestroy (Widget w)
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 GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
277
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
278 if( gw->gauge.selstr != NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
279 XtFree(gw->gauge.selstr) ;
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.selected != None )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
282 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
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 XtReleaseGC(w, gw->gauge.inverse_GC) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
285
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
286 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
287 DisableUpdate(gw) ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
290
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
291 /* React to size change from manager. Label widget will compute some
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
292 * internal stuff, but we need to override.
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
295 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
296 GaugeResize (Widget w)
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 GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
299 int size ; /* height (width) of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
300 int vmargin ; /* vertical (horizontal) margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
301 int hmargin ; /* horizontal (vertical) margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
302
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
303 vmargin = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
304 gw->label.internal_height : gw->label.internal_width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
305 hmargin = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
306 gw->label.internal_width : gw->label.internal_height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
307
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
308 /* 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
309 * we're recomputing everything from scratch anyway.
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
312 /* find total height (width) of contents */
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 size = GA_WID+2 ; /* gauge itself + edges */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
315
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
316 if( gw->gauge.ntics > 1 ) /* tic marks */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
317 size += vmargin + TIC_LEN ;
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.nlabels > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
320 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
321 Dimension lwm, lw0, lw1 ; /* width of max, left, right labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
322 Dimension lh ;
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 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
325
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
326 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
327 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
328 gw->gauge.margin0 = lw0 / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
329 gw->gauge.margin1 = lw1 / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
330 size += lh + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
331 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
332 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
333 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
334 gw->gauge.margin0 =
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
335 gw->gauge.margin1 = lh / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
336 size += lwm + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
337 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
338 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
339 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
340 gw->gauge.margin0 = gw->gauge.margin1 = 0 ;
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 gw->gauge.margin0 += hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
343 gw->gauge.margin1 += hmargin ;
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 /* Now distribute height (width) over components */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
346
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
347 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
348 gw->gauge.gmargin = (gw->core.height-size)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
349 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
350 gw->gauge.gmargin = (gw->core.width-size)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
351
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
352 gw->gauge.tmargin = gw->gauge.gmargin + GA_WID+2 + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
353 if( gw->gauge.ntics > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
354 gw->gauge.lmargin = gw->gauge.tmargin + TIC_LEN + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
355 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
356 gw->gauge.lmargin = gw->gauge.tmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
357 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
358
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
359 /*
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
360 * Repaint the widget window
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 /* ARGSUSED */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
364 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
365 GaugeExpose (Widget w,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
366 XEvent *UNUSED (event),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
367 Region UNUSED (region))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
368 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
369 GaugeWidget gw = (GaugeWidget) w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
370 register Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
371 register Window win = XtWindow(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
372 GC gc; /* foreground, background */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
373 GC gctop, gcbot ; /* dark, light shadows */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
374
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
375 int len ; /* length (width or height) of widget */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
376 int e0,e1 ; /* ends of the gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
377 int x ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
378 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
379 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
380 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
381 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
382 int value = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
383
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
384 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
385
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 #ifdef _ThreeDP_h
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
388 gctop = gw->threeD.bot_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
389 gcbot = gw->threeD.top_shadow_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
390 #else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
391 gctop = gcbot = gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
392 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
393
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
394 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
395 len = gw->core.width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
396 } else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
397 len = gw->core.height ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
398 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
399
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
400 /* if the gauge is selected, signify by drawing the background
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
401 * in a contrasting color.
424
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
404 if( gw->gauge.selected )
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 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
407 gc = gw->gauge.inverse_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
408 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
409
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
410 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
411 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
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 /* Draw the Gauge itself */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
414
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
415 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
416
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
417 if( gw->gauge.orientation == XtorientHorizontal ) /* horizontal */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
418 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
419 XDrawLine(dpy,win,gctop, e0+1,y, e1-1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
420 XDrawLine(dpy,win,gctop, e0,y+1, e0,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
421 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
422 XDrawLine(dpy,win,gcbot, e1,y+1, e1,y+GA_WID) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
423 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
424 else /* vertical */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
425 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
426 XDrawLine(dpy,win,gctop, y,e0+1, y,e1-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
427 XDrawLine(dpy,win,gctop, y+1,e0, y+GA_WID,e0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
428 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
429 XDrawLine(dpy,win,gcbot, y+1,e1, y+GA_WID,e1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
430 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
431
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
432
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
433 /* draw the mercury */
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 GaugeMercury(dpy, win, gc, gw, 0,value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
436
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
437
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
438 if( gw->gauge.ntics > 1 )
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 y = gw->gauge.tmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
441 for(i=0; i<gw->gauge.ntics; ++i)
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 x = e0 + i*(e1-e0-1)/(gw->gauge.ntics-1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
444 if( gw->gauge.orientation == XtorientHorizontal ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
445 XDrawLine(dpy,win,gcbot, x,y+1, x,y+TIC_LEN-2) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
446 XDrawLine(dpy,win,gcbot, x,y, x+1,y) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
447 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
448 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
449 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
450 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
451 XDrawLine(dpy,win,gcbot, y+1,x, y+TIC_LEN-2,x) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
452 XDrawLine(dpy,win,gcbot, y,x, y,x+1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
453 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
454 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
455 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
456 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
457 }
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 /* draw labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
460 if( gw->gauge.nlabels > 1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
461 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
462 char label[20], *s = label ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
463 int xlen, wd,h =0 ;
424
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
466 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
467 else {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
468 y = gw->gauge.lmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
469 h = gw->label.font->max_bounds.ascent / 2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
470 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
471
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
472 for(i=0; i<gw->gauge.nlabels; ++i)
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 if( gw->gauge.labels == NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
475 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
476 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
477 s = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
478 if( s != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
479 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
480 xlen = strlen(s) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
481 if( gw->gauge.orientation == XtorientHorizontal ) {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
482 wd = XTextWidth(gw->label.font, s, xlen) ;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
483 XDrawString(dpy,win,gc, x-wd/2,y, s,xlen) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
484 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
485 else {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
486 XDrawString(dpy,win,gc, y,x+h, 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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
489 }
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 * Set specified arguments into widget
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 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
499 GaugeSetValues (Widget old,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
500 Widget UNUSED (request),
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
501 Widget new_,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
502 ArgList UNUSED (args),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
503 Cardinal *UNUSED (num_args))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
504 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
505 GaugeWidget oldgw = (GaugeWidget) old;
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
506 GaugeWidget gw = (GaugeWidget) new_;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
507 Boolean was_resized = False;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
508
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
509 if( gw->gauge.selected != None ) {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
510 XtDisownSelection(new_, gw->gauge.selected, CurrentTime) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
511 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
512 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
513
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
514 /* Changes to v0,v1,labels, ntics, nlabels require resize & redraw. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
515 /* Change to value requires redraw and possible resize if autoscale */
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 was_resized =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
518 gw->gauge.v0 != oldgw->gauge.v0 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
519 gw->gauge.v1 != oldgw->gauge.v1 ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
520 gw->gauge.ntics != oldgw->gauge.ntics ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
521 gw->gauge.nlabels != oldgw->gauge.nlabels ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
522 gw->gauge.labels != oldgw->gauge.labels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
523
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
524 if( (gw->gauge.autoScaleUp && gw->gauge.value > gw->gauge.v1) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
525 (gw->gauge.autoScaleDown && gw->gauge.value < gw->gauge.v1/3 ))
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 AutoScale(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
528 was_resized = TRUE ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
531 if( was_resized ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
532 if( gw->label.resize )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
533 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
534 else
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
535 GaugeResize(new_) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
536 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
537
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
538 if( gw->gauge.update != oldgw->gauge.update )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
539 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
540 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
541 EnableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
542 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
543 DisableUpdate(gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
544 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
545
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
546 if( gw->core.background_pixel != oldgw->core.background_pixel )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
547 {
3055
6c9e392b4307 [xemacs-hg @ 2005-11-10 15:47:33 by crestani]
crestani
parents: 2286
diff changeset
548 XtReleaseGC(new_, gw->gauge.inverse_GC) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
549 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
550 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
551
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
552 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
553 XtIsSensitive(old) != XtIsSensitive(new_);
424
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
556
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
557 static XtGeometryResult
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
558 GaugeQueryGeometry (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
559 XtWidgetGeometry *intended,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
560 XtWidgetGeometry *preferred)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
561 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
562 register GaugeWidget gw = (GaugeWidget)w;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
563
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
564 if( intended->width == w->core.width &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
565 intended->height == w->core.height )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
566 return XtGeometryNo ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
567
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
568 preferred->request_mode = CWWidth | CWHeight;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
569 GaugeSize(gw, &preferred->width, &preferred->height, DEF_LEN) ;
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 if( (!(intended->request_mode & CWWidth) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
572 intended->width >= preferred->width) &&
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
573 (!(intended->request_mode & CWHeight) ||
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
574 intended->height >= preferred->height) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
575 return XtGeometryYes;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
576 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
577 return XtGeometryAlmost;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
578 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
579
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
580
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 * Action Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
586 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
587 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
588
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
589 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
590 GaugeSelect (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
591 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
592 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
593 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
594 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
595 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
596 Atom seln = XA_PRIMARY ;
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 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
599 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
600 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
601 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
602
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
603 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
604 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
605 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
606 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
607
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
608 if( ! XtOwnSelection(w, seln, event->xbutton.time, GaugeConvert,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
609 GaugeLoseSel, GaugeDoneSel) )
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 /* in real code, this error message would be replaced by
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
612 * something more elegant, or at least deleted
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
615 fprintf(stderr, "Gauge failed to get selection, try again\n") ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
618 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
619 gw->gauge.selected = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
620 gw->gauge.selstr = (String)XtMalloc(4*sizeof(int)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
621 sprintf(gw->gauge.selstr, "%d", gw->gauge.value) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
622 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
623 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
624 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
625
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 static Boolean
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
628 GaugeConvert (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
629 Atom *selection, /* usually XA_PRIMARY */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
630 Atom *target, /* requested target */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
631 Atom *type, /* returned type */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
632 XtPointer *value, /* returned value */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
633 unsigned long *length, /* returned length */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
634 int *format) /* returned format */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
635 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
636 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
637 XSelectionRequestEvent *req ;
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 printf( "requesting selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
640 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
641 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
642
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
643 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
644 if( *target == XA_TARGETS(XtDisplay(w)) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
645 {
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
646 XPointer stdTargets;
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
647 Atom *rval ;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
648 unsigned long stdLength ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
649
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
650 /* XmuConvertStandardSelection can handle this. This function
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
651 * will return a list of standard targets. We prepend TEXT,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
652 * STRING and INTEGER to the list and return it.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
653 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
654
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
655 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
656 XmuConvertStandardSelection(w, req->time, selection, target,
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
657 type, &stdTargets, &stdLength, format) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
658
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
659 *type = XA_ATOM ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
660 *length = stdLength + 3 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
661 rval = (Atom *) XtMalloc(sizeof(Atom)*(stdLength+3)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
662 *value = (XtPointer) rval ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
663 *rval++ = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
664 *rval++ = XA_STRING ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
665 *rval++ = XA_TEXT(XtDisplay(w)) ;
2271
0dfff19d20da [xemacs-hg @ 2004-09-14 20:26:40 by james]
james
parents: 647
diff changeset
666 memcpy(rval, stdTargets, stdLength*sizeof(Atom)) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
667 XtFree((char*) stdTargets) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
668 *format = 8*sizeof(Atom) ; /* TODO: needed? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
669 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
670 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
671
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
672 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
673 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
674 if( *target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
675 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
676 *type = XA_INTEGER ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
677 *length = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
678 *value = (XtPointer) &gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
679 *format = 8*sizeof(int) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
680 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
681 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
682
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
683 else if( *target == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
684 #ifdef HAVE_XMU
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
685 ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
686 *target == XA_TEXT(XtDisplay(w))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
687 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
688 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
689 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
690 *type = *target ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
691 *length = strlen(gw->gauge.selstr)*sizeof(char) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
692 *value = (XtPointer) gw->gauge.selstr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
693 *format = 8 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
694 return True ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
695 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
696
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
697 else
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 /* anything else, we just give it to XmuConvertStandardSelection() */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
700 #ifdef HAVE_XMU
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
701 req = XtGetSelectionRequest(w, *selection, NULL) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
702 if( XmuConvertStandardSelection(w, req->time, selection, target,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
703 type, (XPointer *) value, length, format) )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
704 return True ;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
705 else
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
706 #endif
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
707 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
708 printf(
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
709 "Gauge: requestor is requesting unsupported selection %s:%s\n",
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
710 XGetAtomName(XtDisplay(w),*selection),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
711 XGetAtomName(XtDisplay(w),*target));
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
712 return False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
713 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
714 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
715 }
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
720 GaugeLoseSel (Widget w,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
721 Atom *UNUSED (selection)) /* usually XA_PRIMARY */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
722 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
723 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
724 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
725 Window win = XtWindow(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
726
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
727 if( gw->gauge.selstr != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
728 XtFree(gw->gauge.selstr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
729 gw->gauge.selstr = NULL ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
730 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
731
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
732 gw->gauge.selected = False ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
733 XClearWindow(dpy,win) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
734 GaugeExpose(w,0,0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
735 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
736
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
737
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
738 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
739 GaugeDoneSel (Widget UNUSED (w),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
740 Atom *UNUSED (selection), /* usually XA_PRIMARY */
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
741 Atom *UNUSED (target)) /* requested target */
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
742 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
743 /* selection done, anything to do? */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
744 }
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
747 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
748 GaugePaste (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
749 XEvent *event,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
750 String *params,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
751 Cardinal *num_params)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
752 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
753 Atom seln = XA_PRIMARY ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
754
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
755 if( *num_params > 0 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
756 seln = XInternAtom(XtDisplay(w), params[0], False) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
757 printf("atom %s is %ld\n", params[0], seln) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
758 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
759
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
760 /* try for integer value first */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
761 XtGetSelectionValue(w, seln, XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
762 GaugeGetSelCB, (XtPointer)XA_INTEGER,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
763 event->xbutton.time) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
764 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
765
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
766 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
767 GaugeGetSelCB (Widget w,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
768 XtPointer client,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
769 Atom *selection,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
770 Atom *type,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
771 XtPointer value,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
772 unsigned long *UNUSED (length),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
773 int *UNUSED (format))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
774 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
775 Display *dpy = XtDisplay(w) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
776 Atom target = (Atom)client ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
777 int *iptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
778 char *cptr ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
779
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
780 if( *type == XA_INTEGER ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
781 iptr = (int *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
782 XawGaugeSetValue(w, *iptr) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
783 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
784
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
785 else if( *type == XA_STRING
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
786 #ifdef HAVE_XMU
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 *type == XA_TEXT(dpy)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
789 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
790 )
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
791 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
792 cptr = (char *)value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
793 XawGaugeSetValue(w, atoi(cptr)) ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
796 /* failed, try string */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
797 else if( *type == None && target == XA_INTEGER )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
798 XtGetSelectionValue(w, *selection, XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
799 GaugeGetSelCB, (XtPointer)XA_STRING,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
800 CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
801 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
802
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
803
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 * Public Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
808 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
809 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
810
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
811
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
812 /* Change gauge value. Only undraw or draw what needs to be
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
813 * changed.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
814 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
815
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
816 void
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
817 XawGaugeSetValue (Widget w, int value)
424
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 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
820 int oldvalue ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
821 GC gc ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
822
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
823 if( gw->gauge.selected != None ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
824 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
825 gw->gauge.selected = None ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
826 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
827
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
828 if( !XtIsRealized(w) ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
829 gw->gauge.value = value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
830 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
831 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
832
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
833 /* need to rescale? */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 458
diff changeset
834 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
835 (gw->gauge.autoScaleDown && (int) value < gw->gauge.v1/3 ))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
836 {
3374
174eb4da74fb [xemacs-hg @ 2006-05-02 15:30:31 by james]
james
parents: 3055
diff changeset
837 XtVaSetValues(w, XtNvalue, value, NULL) ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
838 return ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
839 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
840
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
841 oldvalue = gw->gauge.value ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
842 gw->gauge.value = value ;
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 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
845 GaugeMercury(XtDisplay(w), XtWindow(w), gc, gw, oldvalue,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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
848
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
849 int
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
850 XawGaugeGetValue (Widget w)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
851 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
852 GaugeWidget gw = (GaugeWidget)w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
853 return gw->gauge.value ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
856
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 * Private Procedures
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
862 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
863 ****************************************************************/
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
864
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
865 /* draw the mercury over a specific region */
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
868 GaugeMercury (Display *dpy,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
869 Window win,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
870 GC gc,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
871 GaugeWidget gw,
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
872 int val0,
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
873 int val1)
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
874 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
875 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
876 int v1 = gw->gauge.v1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
877 int vd = v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
878 Dimension len ; /* length (width or height) of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
879 Position e0, e1 ; /* gauge ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
880 Position p0, p1 ; /* mercury ends */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
881 int y ; /* vertical (horizontal) position */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
882 Boolean undraw = FALSE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
883
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
884 len = gw->gauge.orientation == XtorientHorizontal ?
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
885 gw->core.width : gw->core.height ;
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 e0 = gw->gauge.margin0 ; /* left (top) end */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
888 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */
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 if( vd <= 0 ) vd = 1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
891
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
892 if( val0 < v0 ) val0 = v0 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
893 else if( val0 > v1 ) val0 = v1 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
894 if( val1 < v0 ) val1 = v0 ;
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
895 else if( val1 > v1 ) val1 = v1 ;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
896
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
897 p0 = (val0-v0)*(e1-e0-1)/vd ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
898 p1 = (val1-v0)*(e1-e0-1)/vd ;
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 if( p1 == p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
901 return ;
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 y = gw->gauge.gmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
904
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
905 if( p1 < p0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
906 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
907 Position tmp = p0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
908 p0 = p1 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
909 p1 = tmp ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
910 gc = gw->label.normal_GC ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
911 XSetForeground(dpy,gc, gw->core.background_pixel) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
912 undraw = TRUE ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
913 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
914
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
915 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
916 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
917 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
918 XFillRectangle(dpy,win,gc, y+1,e1-p1, GA_WID,p1-p0) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
919
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
920 if( undraw )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
921 XSetForeground(dpy,gc, gw->label.foreground) ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
924
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 /* Search the labels, find the largest one. */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
927 /* TODO: handle vertical fonts? */
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
930 MaxLabel (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
931 Dimension *wid, /* max label width */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
932 Dimension *hgt, /* max label height */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
933 Dimension *w0, /* width of first label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
934 Dimension *w1) /* width of last label */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
935 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
936 char lstr[80], *lbl ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
937 int w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
938 XFontStruct *font = gw->label.font ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
939 int i ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
940 int lw = 0;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
941 int v0 = gw->gauge.v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
942 int dv = gw->gauge.v1 - v0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
943 int n = gw->gauge.nlabels ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
944
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
945 if( n > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
946 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
947 if( --n <= 0 ) {n = 1 ; v0 += dv/2 ;}
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
948
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
949 /* loop through all labels, figure out how much room they
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
950 * need.
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 w = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
953 for(i=0; i<gw->gauge.nlabels; ++i)
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 if( gw->gauge.labels == NULL ) /* numeric labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
956 sprintf(lbl = lstr,"%d", v0 + i*dv/n) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
957 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
958 lbl = gw->gauge.labels[i] ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
959
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
960 if( lbl != NULL ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
961 lw = XTextWidth(font, lbl, strlen(lbl)) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
962 w = Max( w, lw ) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
963 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
964 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
965 lw = 0 ;
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 if( i == 0 && w0 != NULL ) *w0 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
968 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
969 if( w1 != NULL ) *w1 = lw ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
970
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
971 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
972 *hgt = font->max_bounds.ascent + font->max_bounds.descent ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
975 *wid = *hgt = 0 ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
978
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
979 /* Determine the preferred size for this widget. choose 100x100 for
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
980 * debugging.
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
983 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
984 GaugeSize (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
985 Dimension *wid,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
986 Dimension *hgt,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
987 Dimension min_len)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
988 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
989 int w,h ; /* width, height of gauge */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
990 int vmargin ; /* vertical margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
991 int hmargin ; /* horizontal margin */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
992
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
993 hmargin = gw->label.internal_width ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
994 vmargin = gw->label.internal_height ;
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 /* find total height (width) of contents */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
997
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 minimum size for undecorated gauge */
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1002 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1003 w = min_len ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1004 h = GA_WID+2 ; /* gauge itself + edges */
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1007 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1008 w = GA_WID+2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1009 h = min_len ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1012 if( gw->gauge.ntics > 0 )
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 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1015 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1016 w = Max(w, gw->gauge.ntics*3) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1017 h += vmargin + TIC_LEN ;
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 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1020 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1021 w += hmargin + TIC_LEN ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1022 h = Max(h, gw->gauge.ntics*3) ;
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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1025
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 /* If labels are requested, this gets a little interesting.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1028 * 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
1029 * the centers of the labels evenly spaced. The labels at the ends
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1030 * will not be the same width, meaning that the gauge itself need
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1031 * not be centered in the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1032 *
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1033 * First, determine the spacing. This is the width of the widest
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1034 * label, plus the internal margin. Total length of the gauge is
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1035 * spacing * (nlabels-1). To this, we add half the width of the
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1036 * left-most label and half the width of the right-most label
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1037 * to get the entire desired width of the widget.
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1038 */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1039 if( gw->gauge.nlabels > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1040 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1041 Dimension lwm, lw0, lw1 ; /* width of max, left, right labels */
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1042 Dimension lh ;
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 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1045
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1046 if( gw->gauge.orientation == XtorientHorizontal )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1047 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1048 lwm = (lwm+hmargin) * (gw->gauge.nlabels-1) + (lw0+lw1)/2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1049 w = Max(w, lwm) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1050 h += lh + vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1051 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1052 else
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1053 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1054 lh = lh*gw->gauge.nlabels + (gw->gauge.nlabels - 1)*vmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1055 h = Max(h, lh) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1056 w += lwm + hmargin ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1057 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1058 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1059
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1060 w += hmargin*2 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1061 h += vmargin*2 ;
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 *wid = w ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1064 *hgt = h ;
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
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1067
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 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1070 AutoScale (GaugeWidget gw)
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 int scales[3] = {1,2,5} ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1073 int sptr = 0, smult=1 ;
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 if( gw->gauge.autoScaleDown )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1076 gw->gauge.v1 = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1077 while( gw->gauge.value > gw->gauge.v1 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1078 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1079 if( ++sptr > 2 ) {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1080 sptr = 0 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1081 smult *= 10 ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1082 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1083 gw->gauge.v1 = scales[sptr] * smult ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1084 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1085 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1086
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1087 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1088 EnableUpdate (GaugeWidget gw)
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 gw->gauge.intervalId =
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1091 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)gw),
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1092 gw->gauge.update * MS_PER_SEC, GaugeGetValue,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1093 (XtPointer)gw) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1094 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1095
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1096 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1097 DisableUpdate (GaugeWidget gw)
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 XtRemoveTimeOut(gw->gauge.intervalId) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1100 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1101
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1102 static void
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1103 GaugeGetValue (XtPointer clientData,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2271
diff changeset
1104 XtIntervalId *UNUSED (intervalId))
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1105 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1106 GaugeWidget gw = (GaugeWidget)clientData ;
3968
16b17fd1dc93 [xemacs-hg @ 2007-05-20 15:56:30 by stephent]
stephent
parents: 3374
diff changeset
1107 int value ;
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 if( gw->gauge.update > 0 )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1110 EnableUpdate(gw) ;
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.getValue != NULL )
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1113 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1114 XtCallCallbackList((Widget)gw, gw->gauge.getValue, (XtPointer)&value);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1115 XawGaugeSetValue((Widget)gw, value) ;
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 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1118
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 static GC
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1121 Get_GC (GaugeWidget gw,
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1122 Pixel fg)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1123 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1124 XGCValues values ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1125 #define vmask GCForeground
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1126 #define umask (GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset\
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1127 |GCFont|GCDashList|GCArcMode)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1128
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1129 values.foreground = fg ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1130
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1131 return XtAllocateGC((Widget)gw, 0, vmask, &values, 0L, umask) ;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents:
diff changeset
1132 }