NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / X11 / winval.c
blob2dc0e25ba8bbbd571852a726faeccbeeacff84f5
1 /* aNetHack 0.0.1 winval.c $ANH-Date: 1432512808 2015/05/25 00:13:28 $ $ANH-Branch: master $:$ANH-Revision: 1.9 $ */
2 /* Copyright (c) Dean Luick, 1992 */
3 /* aNetHack may be freely redistributed. See license for details. */
5 /*
6 * Routines that define a name-value label widget pair that fit inside a
7 * form widget.
8 */
9 #include <stdio.h>
11 #ifndef SYSV
12 #define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
13 #endif
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>
21 #ifdef PRESERVE_NO_SYSV
22 #ifdef SYSV
23 #undef SYSV
24 #endif
25 #undef PRESERVE_NO_SYSV
26 #endif
28 #include "hack.h" /* #define for const for non __STDC__ compilers */
29 #include "winX.h"
31 #define WNAME "name"
32 #define WVALUE "value"
34 Widget
35 create_value(parent, name_value)
36 Widget parent;
37 const char *name_value;
39 Widget form, name;
40 Arg args[8];
41 Cardinal num_args;
43 num_args = 0;
44 XtSetArg(args[num_args], XtNborderWidth, 0);
45 num_args++;
46 XtSetArg(args[num_args], nhStr(XtNdefaultDistance), 0);
47 num_args++;
48 form = XtCreateManagedWidget(name_value, formWidgetClass, parent, args,
49 num_args);
51 num_args = 0;
52 XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
53 num_args++;
54 XtSetArg(args[num_args], XtNborderWidth, 0);
55 num_args++;
56 XtSetArg(args[num_args], XtNlabel, name_value);
57 num_args++;
58 XtSetArg(args[num_args], XtNinternalHeight, 0);
59 num_args++;
60 name =
61 XtCreateManagedWidget(WNAME, labelWidgetClass, form, args, num_args);
63 num_args = 0;
64 XtSetArg(args[num_args], XtNjustify, XtJustifyRight);
65 num_args++;
66 XtSetArg(args[num_args], XtNborderWidth, 0);
67 num_args++;
68 XtSetArg(args[num_args], nhStr(XtNfromHoriz), name);
69 num_args++;
70 XtSetArg(args[num_args], XtNinternalHeight, 0);
71 num_args++;
72 (void) XtCreateManagedWidget(WVALUE, labelWidgetClass, form, args,
73 num_args);
74 return form;
77 void
78 set_name(w, new_label)
79 Widget w;
80 const char *new_label;
82 Arg args[1];
83 Widget name;
85 name = XtNameToWidget(w, WNAME);
86 XtSetArg(args[0], XtNlabel, new_label);
87 XtSetValues(name, args, ONE);
90 void
91 set_name_width(w, new_width)
92 Widget w;
93 int new_width;
95 Arg args[1];
96 Widget name;
98 name = XtNameToWidget(w, WNAME);
99 XtSetArg(args[0], XtNwidth, new_width);
100 XtSetValues(name, args, ONE);
104 get_name_width(w)
105 Widget w;
107 Arg args[1];
108 Dimension width;
109 Widget name;
111 name = XtNameToWidget(w, WNAME);
112 XtSetArg(args[0], XtNwidth, &width);
113 XtGetValues(name, args, ONE);
114 return (int) width;
117 void
118 set_value(w, new_value)
119 Widget w;
120 const char *new_value;
122 Arg args[1];
123 Widget val;
125 val = XtNameToWidget(w, WVALUE);
126 XtSetArg(args[0], XtNlabel, new_value);
127 XtSetValues(val, args, ONE);
130 void
131 set_value_width(w, new_width)
132 Widget w;
133 int new_width;
135 Arg args[1];
136 Widget val;
138 val = XtNameToWidget(w, WVALUE);
139 XtSetArg(args[0], XtNwidth, new_width);
140 XtSetValues(val, args, ONE);
144 get_value_width(w)
145 Widget w;
147 Arg args[1];
148 Widget val;
149 Dimension width;
151 val = XtNameToWidget(w, WVALUE);
152 XtSetArg(args[0], XtNwidth, &width);
153 XtGetValues(val, args, ONE);
154 return (int) width;
157 /* Swap foreground and background colors (this is the best I can do with */
158 /* a label widget, unless I can get some init hook in there). */
159 void
160 hilight_value(w)
161 Widget w;
163 swap_fg_bg(XtNameToWidget(w, WVALUE));
166 /* Swap the foreground and background colors of the given widget */
167 void
168 swap_fg_bg(w)
169 Widget w;
171 Arg args[2];
172 Pixel fg, bg;
174 XtSetArg(args[0], XtNforeground, &fg);
175 XtSetArg(args[1], XtNbackground, &bg);
176 XtGetValues(w, args, TWO);
178 XtSetArg(args[0], XtNforeground, bg);
179 XtSetArg(args[1], XtNbackground, fg);
180 XtSetValues(w, args, TWO);