source: trunk/FACT++/dim/src/did/dui_util.c@ 17010

Last change on this file since 17010 was 11071, checked in by tbretz, 13 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 5.6 KB
Line 
1/*
2**++
3** FACILITY: DUI
4**
5** MODULE DESCRIPTION:
6**
7** Implements MOTIF utility functions
8**
9** AUTHORS:
10**
11** C. Gaspar
12**
13** CREATION DATE: 24-01-1993
14**
15**--
16*/
17#include <stdio.h>
18#include <Mrm/MrmAppl.h> /* Motif Toolkit */
19#include <Xm/Xm.h>
20
21#include <dim.h>
22#include "dui_util.h"
23
24/* compound strings */
25
26
27static XmString Active_str;
28
29XmString get_str(text)
30char *text;
31{
32
33 Active_str = XmStringCreateLtoR ( text, XmSTRING_DEFAULT_CHARSET);
34 return(Active_str);
35}
36
37
38void free_str()
39{
40
41 XmStringFree(Active_str);
42}
43
44
45XmString create_str(text)
46char *text;
47{
48XmString str;
49
50
51 str = XmStringCreate ( text, XmSTRING_DEFAULT_CHARSET);
52 return(str);
53}
54
55void delete_str(str)
56XmString str;
57{
58
59 XmStringFree(str);
60}
61
62void set_something(w, resource, value)
63 Widget w;
64 char *resource, *value;
65{
66 Arg al[1];
67 int free = 0;
68DISABLE_AST
69 if( (!strcmp(resource,XmNlabelString)) ||
70 (!strcmp(resource,XmNmessageString)) ||
71 (!strcmp(resource,XmNtextString)) ||
72 (!strcmp(resource,XmNlistLabelString)) ||
73 (!strcmp(resource,XmNselectionLabelString)) )
74 {
75 free = 1;
76 value = (char *)get_str(value);
77 }
78 XtSetArg(al[0], resource, value);
79 XtSetValues(w, al, 1);
80 if(free)
81 free_str();
82 /*
83 printf("Flushing %s for widget %s...\n",resource,w->core.name);
84 */
85 /*
86 XFlush(XtDisplay(w));
87 */
88 /*
89 printf("Flushed!\n");
90 */
91ENABLE_AST
92}
93
94void get_something(w, resource, value)
95 Widget w;
96 char *resource, *value;
97{
98
99 Arg al[1];
100 int free = 0;
101 XmString str;
102 char *cstr;
103
104 if( (!strcmp(resource,XmNlabelString)) ||
105 (!strcmp(resource,XmNmessageString)) ||
106 (!strcmp(resource,XmNtextString)) ||
107 (!strcmp(resource,XmNlistLabelString)) ||
108 (!strcmp(resource,XmNselectionLabelString)) )
109 {
110 free = 1;
111 XtSetArg(al[0], resource, &str);
112 }
113 else
114 XtSetArg(al[0], resource, value);
115 XtGetValues(w, al, 1);
116 if(free)
117 {
118 XmStringGetLtoR(str, XmSTRING_DEFAULT_CHARSET, &cstr);
119 strcpy(value,cstr);
120 XtFree(cstr);
121 }
122}
123/*
124void set_something_uid(hid, w, resource, value)
125 MrmHierarchy hid;
126 Widget w;
127 char *resource, *value;
128{
129 Arg al[1];
130
131 XtSetArg(al[0], resource, value);
132
133 MrmFetchSetValues(hid, w, al, 1);
134}
135*/
136
137static XmString str_table[50];
138
139XmStringTable create_str_table(strs)
140char strs[50][256];
141{
142int i;
143
144 for(i=0;strs[i][0];i++)
145 {
146 str_table[i] = XmStringCreate ( strs[i], XmSTRING_DEFAULT_CHARSET);
147 }
148 str_table[i] = (XmString)0;
149 return((XmStringTable)str_table);
150}
151
152void del_str_table()
153{
154int i;
155
156 for(i=0;str_table[i];i++)
157 XmStringFree(str_table[i]);
158
159}
160
161Pixel rgb_colors[MAX_COLORS];
162static Pixmap pixmap_colors[MAX_COLORS];
163static Pixmap watch_colors[MAX_COLORS];
164static Pixmap locks[MAX_COLORS];
165static Pixmap unlock;
166static Pixmap faces[MAX_COLORS];
167
168Pixel get_named_color(color)
169int color;
170{
171 return(rgb_colors[color]);
172}
173
174void set_color(w, resource, color)
175Widget w;
176char *resource;
177int color;
178{
179
180DISABLE_AST
181/*
182 if(resource == XmNbackgroundPixmap)
183*/
184 if(!strcmp(resource,XmNbackgroundPixmap))
185 set_something(w,resource,pixmap_colors[color]);
186 else
187 set_something(w,resource,rgb_colors[color]);
188ENABLE_AST
189}
190
191void set_watch(w, color)
192Widget w;
193int color;
194{
195 set_something(w,XmNbackgroundPixmap,watch_colors[color]);
196}
197
198void set_lock(w, color)
199Widget w;
200int color;
201{
202 set_something(w,XmNbackgroundPixmap,locks[color]);
203}
204
205void set_unlock(w)
206Widget w;
207{
208 set_something(w,XmNbackgroundPixmap,unlock);
209}
210
211void set_face(w, color)
212Widget w;
213int color;
214{
215 set_something(w,XmNbackgroundPixmap,faces[color]);
216}
217
218void get_all_colors(display, w)
219 Display *display;
220 Widget w;
221{
222 XColor a,b;
223 Colormap cm;
224 cm = DefaultColormap ( display, DefaultScreen(display));
225
226 XAllocNamedColor ( display, cm, "Medium Aquamarine", &a,&b );
227 rgb_colors[GREEN] = b.pixel;
228
229 XAllocNamedColor ( display, cm, "Turquoise", &a,&b );
230 rgb_colors[BLUE] = b.pixel;
231
232 XAllocNamedColor ( display, cm, "Yellow", &a,&b );
233 rgb_colors[YELLOW] = b.pixel;
234
235 XAllocNamedColor ( display, cm, "Orange", &a,&b );
236 rgb_colors[ORANGE] = b.pixel;
237
238 XAllocNamedColor ( display, cm, "Red", &a,&b );
239 rgb_colors[RED] = b.pixel;
240
241 XAllocNamedColor ( display, cm, "Black", &a,&b );
242 rgb_colors[BLACK] = b.pixel;
243
244 XAllocNamedColor ( display, cm, "White", &a,&b );
245 rgb_colors[WHITE] = b.pixel;
246
247 XAllocNamedColor ( display, cm, "Light Gray", &a,&b );
248 rgb_colors[GRAY] = b.pixel;
249
250 XAllocNamedColor ( display, cm, "Gainsboro", &a,&b );
251 rgb_colors[LIGHTGRAY] = b.pixel;
252/*
253 MrmFetchColorLiteral(hid, "green", display, 0, &rgb_colors[GREEN]);
254 MrmFetchColorLiteral(hid, "blue", display, 0, &rgb_colors[BLUE]);
255 MrmFetchColorLiteral(hid, "yellow", display, 0, &rgb_colors[YELLOW]);
256 MrmFetchColorLiteral(hid, "orange", display, 0, &rgb_colors[ORANGE]);
257 MrmFetchColorLiteral(hid, "red", display, 0, &rgb_colors[RED]);
258 MrmFetchColorLiteral(hid, "black", display, 0, &rgb_colors[BLACK]);
259 MrmFetchColorLiteral(hid, "white", display, 0, &rgb_colors[WHITE]);
260*/
261 get_something(w,XmNbackground,&rgb_colors[NONE]);
262}
263
264
265static int was_sensitive = 0;
266
267void set_sensitive(widget_id)
268Widget widget_id;
269{
270
271 if(was_sensitive)
272 XtSetSensitive(widget_id,True);
273}
274
275void set_insensitive(widget_id)
276Widget widget_id;
277{
278
279 if( (was_sensitive = XtIsSensitive(widget_id)) )
280 XtSetSensitive(widget_id,False);
281}
282
283void set_title(w, title)
284 Widget w;
285 char *title;
286{
287 Arg al[1];
288
289 XtSetArg(al[0], XmNtitle, title);
290 XtSetValues(w, al, 1);
291 /*
292 XFlush(XtDisplay(w));
293 */
294}
295
296void set_icon_title(w, title)
297 Widget w;
298 char *title;
299{
300 Arg al[1];
301
302 XtSetArg(al[0], XmNiconName, title);
303 XtSetValues(w, al, 1);
304 /*
305 XFlush(XtDisplay(w));
306 */
307}
308
Note: See TracBrowser for help on using the repository browser.