OSDN Git Service

Initial Import
[nethackexpress/trunk.git] / win / X11 / winval.c
1 /*      SCCS Id: @(#)winval.c   3.4     1992/3/7        */
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 #include "winX.h"
30
31 #define WNAME "name"
32 #define WVALUE "value"
33
34
35 Widget
36 create_value(parent, name_value)
37     Widget parent;
38     const char *name_value;
39 {
40     Widget form, name;
41     Arg args[8];
42     Cardinal num_args;
43
44     num_args = 0;
45     XtSetArg(args[num_args], XtNborderWidth, 0);                num_args++;
46     XtSetArg(args[num_args], XtNdefaultDistance, 0);            num_args++;
47     form = XtCreateManagedWidget(name_value,
48                                 formWidgetClass,
49                                 parent, args, num_args);
50
51     num_args = 0;
52     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);       num_args++;
53     XtSetArg(args[num_args], XtNborderWidth, 0);                num_args++;
54     XtSetArg(args[num_args], XtNlabel, name_value);             num_args++;
55     XtSetArg(args[num_args], XtNinternalHeight, 0);             num_args++;
56     name = XtCreateManagedWidget(WNAME,
57                                 labelWidgetClass,
58                                 form, args, num_args);
59
60     num_args = 0;
61     XtSetArg(args[num_args], XtNjustify, XtJustifyRight);       num_args++;
62     XtSetArg(args[num_args], XtNborderWidth, 0);                num_args++;
63     XtSetArg(args[num_args], XtNfromHoriz, name);               num_args++;
64     XtSetArg(args[num_args], XtNinternalHeight, 0);             num_args++;
65     (void) XtCreateManagedWidget(WVALUE,
66                                 labelWidgetClass,
67                                 form, args, num_args);
68     return form;
69 }
70
71 void
72 set_name(w, new_label)
73     Widget w;
74     char *new_label;
75 {
76     Arg args[1];
77     Widget name;
78
79     name = XtNameToWidget(w, WNAME);
80     XtSetArg(args[0], XtNlabel, new_label);
81     XtSetValues(name, args, ONE);
82 }
83
84 void
85 set_name_width(w, new_width)
86     Widget w;
87     int new_width;
88 {
89     Arg args[1];
90     Widget name;
91
92     name = XtNameToWidget(w, WNAME);
93     XtSetArg(args[0], XtNwidth, new_width);
94     XtSetValues(name, args, ONE);
95 }
96
97 int
98 get_name_width(w)
99     Widget w;
100 {
101     Arg args[1];
102     Dimension width;
103     Widget name;
104
105     name = XtNameToWidget(w, WNAME);
106     XtSetArg(args[0], XtNwidth, &width);
107     XtGetValues(name, args, ONE);
108     return (int) width;
109 }
110
111
112 void
113 set_value(w, new_value)
114     Widget w;
115     const char *new_value;
116 {
117     Arg args[1];
118     Widget val;
119
120     val = XtNameToWidget(w, WVALUE);
121     XtSetArg(args[0], XtNlabel, new_value);
122     XtSetValues(val, args, ONE);
123 }
124
125 void
126 set_value_width(w, new_width)
127     Widget w;
128     int new_width;
129 {
130     Arg args[1];
131     Widget val;
132
133     val = XtNameToWidget(w, WVALUE);
134     XtSetArg(args[0], XtNwidth, new_width);
135     XtSetValues(val, args, ONE);
136 }
137
138 int
139 get_value_width(w)
140     Widget w;
141 {
142     Arg args[1];
143     Widget val;
144     Dimension width;
145
146     val = XtNameToWidget(w, WVALUE);
147     XtSetArg(args[0], XtNwidth, &width);
148     XtGetValues(val, args, ONE);
149     return (int) width;
150 }
151
152 /* Swap foreground and background colors (this is the best I can do with */
153 /* a label widget, unless I can get some init hook in there).            */
154 void
155 hilight_value(w)
156     Widget w;
157 {
158     swap_fg_bg(XtNameToWidget(w, WVALUE));
159 }
160
161 /* Swap the foreground and background colors of the given widget */
162 void
163 swap_fg_bg(w)
164     Widget w;
165 {
166     Arg args[2];
167     Pixel fg, bg;
168
169     XtSetArg(args[0], XtNforeground, &fg);
170     XtSetArg(args[1], XtNbackground, &bg);
171     XtGetValues(w, args, TWO);
172
173     XtSetArg(args[0], XtNforeground, bg);
174     XtSetArg(args[1], XtNbackground, fg);
175     XtSetValues(w, args, TWO);
176 }
177