OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / X11 / winval.c
1 /* NetHack 3.6  winval.c        $NHDT-Date: 1432512808 2015/05/25 00:13:28 $  $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
2 /* Copyright (c) Dean Luick, 1992                                 */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /*
6  * Routines that define a name-value label widget pair that fit inside a
7  * form widget.
8  */
9 #include <stdio.h>
10
11 #ifndef SYSV
12 #define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
13 #endif
14
15 #include <X11/Intrinsic.h>
16 #include <X11/StringDefs.h>
17 #include <X11/Xaw/Label.h>
18 #include <X11/Xaw/Form.h>
19 #include <X11/Xaw/Cardinals.h>
20
21 #ifdef PRESERVE_NO_SYSV
22 #ifdef SYSV
23 #undef SYSV
24 #endif
25 #undef PRESERVE_NO_SYSV
26 #endif
27
28 #include "hack.h" /* #define for const for non __STDC__ compilers */
29 /*JP*/
30 #ifdef XAW_I18N
31 #include <X11/Xaw/Xawi18n.h>
32 #endif
33 #include "winX.h"
34
35 #define WNAME "name"
36 #define WVALUE "value"
37
38 Widget
39 create_value(parent, name_value)
40 Widget parent;
41 const char *name_value;
42 {
43     Widget form, name;
44     Arg args[8];
45     Cardinal num_args;
46
47     num_args = 0;
48     XtSetArg(args[num_args], XtNborderWidth, 0);
49     num_args++;
50     XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0);
51     num_args++;
52     form = XtCreateManagedWidget(name_value, formWidgetClass, parent, args,
53                                  num_args);
54
55     num_args = 0;
56     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
57     num_args++;
58     XtSetArg(args[num_args], XtNborderWidth, 0);
59     num_args++;
60     XtSetArg(args[num_args], XtNlabel, name_value);
61     num_args++;
62 /*JP*/
63 #if defined(X11R6) && defined(XI18N)
64     XtSetArg(args[num_args], XtNinternational, True);
65     num_args++;
66 #endif
67     XtSetArg(args[num_args], XtNinternalHeight, 0);
68     num_args++;
69     name =
70         XtCreateManagedWidget(WNAME, labelWidgetClass, form, args, num_args);
71
72     num_args = 0;
73     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
74     num_args++;
75     XtSetArg(args[num_args], XtNborderWidth, 0);
76     num_args++;
77     XtSetArg(args[num_args], nhStr(XtNfromHoriz), name);
78     num_args++;
79 /*JP*/
80 #if defined(X11R6) && defined(XI18N)
81     XtSetArg(args[num_args], XtNinternational, True);
82     num_args++;
83 #endif
84     XtSetArg(args[num_args], XtNinternalHeight, 0);
85     num_args++;
86     (void) XtCreateManagedWidget(WVALUE, labelWidgetClass, form, args,
87                                  num_args);
88     return form;
89 }
90
91 void
92 set_name(w, new_label)
93 Widget w;
94 const char *new_label;
95 {
96     Arg args[1];
97     Widget name;
98
99     name = XtNameToWidget(w, WNAME);
100     XtSetArg(args[0], XtNlabel, new_label);
101     XtSetValues(name, args, ONE);
102 }
103
104 void
105 set_name_width(w, new_width)
106 Widget w;
107 int new_width;
108 {
109     Arg args[1];
110     Widget name;
111
112     name = XtNameToWidget(w, WNAME);
113     XtSetArg(args[0], XtNwidth, new_width);
114     XtSetValues(name, args, ONE);
115 }
116
117 int
118 get_name_width(w)
119 Widget w;
120 {
121     Arg args[1];
122     Dimension width;
123     Widget name;
124
125     name = XtNameToWidget(w, WNAME);
126     XtSetArg(args[0], XtNwidth, &width);
127     XtGetValues(name, args, ONE);
128     return (int) width;
129 }
130
131 void
132 set_value(w, new_value)
133 Widget w;
134 const char *new_value;
135 {
136     Arg args[1];
137     Widget val;
138
139     val = XtNameToWidget(w, WVALUE);
140     XtSetArg(args[0], XtNlabel, new_value);
141     XtSetValues(val, args, ONE);
142 }
143
144 void
145 set_value_width(w, new_width)
146 Widget w;
147 int new_width;
148 {
149     Arg args[1];
150     Widget val;
151
152     val = XtNameToWidget(w, WVALUE);
153     XtSetArg(args[0], XtNwidth, new_width);
154     XtSetValues(val, args, ONE);
155 }
156
157 int
158 get_value_width(w)
159 Widget w;
160 {
161     Arg args[1];
162     Widget val;
163     Dimension width;
164
165     val = XtNameToWidget(w, WVALUE);
166     XtSetArg(args[0], XtNwidth, &width);
167     XtGetValues(val, args, ONE);
168     return (int) width;
169 }
170
171 /* Swap foreground and background colors (this is the best I can do with */
172 /* a label widget, unless I can get some init hook in there).            */
173 void
174 hilight_value(w)
175 Widget w;
176 {
177     swap_fg_bg(XtNameToWidget(w, WVALUE));
178 }
179
180 /* Swap the foreground and background colors of the given widget */
181 void
182 swap_fg_bg(w)
183 Widget w;
184 {
185     Arg args[2];
186     Pixel fg, bg;
187
188     XtSetArg(args[0], XtNforeground, &fg);
189     XtSetArg(args[1], XtNbackground, &bg);
190     XtGetValues(w, args, TWO);
191
192     XtSetArg(args[0], XtNforeground, bg);
193     XtSetArg(args[1], XtNbackground, fg);
194     XtSetValues(w, args, TWO);
195 }