1 /*
2 **
3 ** widgets_misc.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 */
31 
32 #include "ac_config.h"
33 
34 
35 /*
36 #define MESSAGES
37 */
38 #include "message.h"
39 
40 #include <stdio.h>
41 
42 #include "paths.h"
43 #include INC_X11(Intrinsic.h)
44 #include INC_X11(StringDefs.h)
45 #include INC_XAW(AsciiText.h)
46 #include INC_XAW(Cardinals.h)
47 #include "Button.h"
48 #include "Frame.h"
49 #include "Switch.h"
50 
51 #include "types.h"
52 #include "main_resources.h"
53 #include "main_globals.h"
54 #include "widgets_misc.h"
55 
56 /*##################################################*/
57 /* widgets_setSelectedBitmap */
58 /*##################################################*/
59 
60 void
widgets_setSelectedBitmap(w,on)61 widgets_setSelectedBitmap(w,on)
62   Widget w;
63   int on;
64 {
65   Arg args[1];
66   Pixmap bitmap;
67 
68   BEGINMESSAGE(widgets_setSelectedBitmap)
69   if (on) bitmap = app_res.selected_bitmap;
70   else    bitmap = None;
71   XtSetArg(args[0], XtNleftBitmap, bitmap);
72   XtSetValues(w,args, ONE);
73   ENDMESSAGE(widgets_setSelectedBitmap)
74 }
75 
76 /*##################################################*/
77 /* widgets_setToggle */
78 /*##################################################*/
79 
80 void
widgets_setToggle(w,value)81 widgets_setToggle(w,value)
82    Widget   w;
83    int      value;
84 {
85    BEGINMESSAGE(widgets_setToggle)
86    if (value) ButtonSet(w,NULL,NULL,NULL);
87    else ButtonUnset(w,NULL,NULL,NULL);
88    ENDMESSAGE(widgets_setToggle)
89 }
90 
91 /*##################################################*/
92 /* widgets_createLabeledLineTextField */
93 /* Create a label/single-line-text-field */
94 /* widget pair. */
95 /*##################################################*/
96 
97 static char *LineTextTr =  "\
98 <Key>Return: no-op()\n\
99 <Key>Escape: no-op()\n\
100 <Key>Down: no-op()\n\
101 <Key>Up: no-op()\n\
102 <Key>Linefeed: no-op()\n\
103 Ctrl<Key>J: no-op()\n\
104 Ctrl<Key>M: no-op()\n\
105 Ctrl<Key>N: no-op()\n\
106 Ctrl<Key>O: no-op()\n\
107 Ctrl<Key>P: no-op()\n\
108 Ctrl<Key>R: no-op()\n\
109 Ctrl<Key>S: no-op()\n\
110 Ctrl<Key>V: no-op()\n\
111 Ctrl<Key>Z: no-op()\n\
112 Meta<Key>V: no-op()\n\
113 Meta<Key>Z: no-op()\n\
114 <Key>BackSpace: delete-previous-character()\n\
115 <Key>Delete: delete-next-character()\n\
116 <Key>Right: forward-character()\n\
117 <Key>Left: backward-character()\n\
118 <MapNotify>:display-caret(on,always)display-caret(off,always)\n\
119 <EnterNotify>:display-caret(on,always)\n\
120 <LeaveNotify>:display-caret(off,always)\
121 ";
122 
123 Widget
widgets_createLabeledLineTextField(name,parent)124 widgets_createLabeledLineTextField(name, parent)
125    String   name;
126    Widget   parent;
127 {
128    Arg      args[9];
129    Cardinal n;
130    char     tmp[50];
131    Widget   frame,text;
132    static XtTranslations trans=NULL;
133 
134    INFMESSAGE(executing widgets_createLabeledLineTextField)
135           sprintf(tmp,"%sLabel",name);
136 
137           XtSetArg(args[0], XtNresize, False);
138    XtCreateManagedWidget(tmp,labelWidgetClass,parent,args,ONE);
139 
140           sprintf(tmp,"%sFrame",name);
141    frame = XtCreateManagedWidget(tmp,frameWidgetClass,parent,NULL,ZERO);
142           								n=0;
143           XtSetArg(args[n], XtNtype, XawAsciiString);			n++;
144           XtSetArg(args[n], XtNuseStringInPlace, False);		n++;
145           XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollNever);	n++;
146           XtSetArg(args[n], XtNscrollVertical, XawtextScrollNever);	n++;
147           XtSetArg(args[n], XtNdisplayCaret, False);			n++;
148           XtSetArg(args[n], XtNeditType, XawtextEdit);			n++;
149           XtSetArg(args[n], XtNresize, XawtextResizeWidth);		n++;
150    text = XtCreateManagedWidget(name,asciiTextWidgetClass,frame,args,n);
151           if (!trans) trans=XtParseTranslationTable(LineTextTr);
152           XtOverrideTranslations(text,trans);
153 
154    return text;
155 }
156 
157 /*##################################################*/
158 /* widgets_createLabeledTextField */
159 /* Create a label/text-field widget pair. */
160 /*##################################################*/
161 
162 static char *TextTr =  "\
163 <Key>Escape: no-op()\n\
164 Ctrl<Key>J: no-op()\n\
165 Ctrl<Key>M: no-op()\n\
166 Ctrl<Key>N: no-op()\n\
167 Ctrl<Key>O: no-op()\n\
168 Ctrl<Key>P: no-op()\n\
169 Ctrl<Key>R: no-op()\n\
170 Ctrl<Key>S: no-op()\n\
171 Ctrl<Key>V: no-op()\n\
172 Ctrl<Key>Z: no-op()\n\
173 Meta<Key>V: no-op()\n\
174 Meta<Key>Z: no-op()\n\
175 <Key>BackSpace: delete-previous-character()\n\
176 <Key>Delete: delete-next-character()\n\
177 <Key>Right: forward-character()\n\
178 <Key>Left: backward-character()\n\
179 <MapNotify>:display-caret(on,always)display-caret(off,always)\n\
180 <EnterNotify>:display-caret(on,always)\n\
181 <LeaveNotify>:display-caret(off,always)\
182 ";
183 
184 Widget
widgets_createLabeledTextField(name,parent)185 widgets_createLabeledTextField(name, parent)
186    String   name;
187    Widget   parent;
188 {
189    Arg      args[9];
190    Cardinal n;
191    char     tmp[50];
192    Widget   frame,text;
193    static XtTranslations trans=NULL;
194 
195    INFMESSAGE(executing widgets_createLabeledTextField)
196           sprintf(tmp,"%sLabel",name);
197 
198           XtSetArg(args[0], XtNresize, False);
199    XtCreateManagedWidget(tmp,labelWidgetClass,parent,args,ONE);
200 
201           sprintf(tmp,"%sFrame",name);
202    frame = XtCreateManagedWidget(tmp,frameWidgetClass,parent,NULL,ZERO);
203           								n=0;
204           XtSetArg(args[n], XtNtype, XawAsciiString);			n++;
205           XtSetArg(args[n], XtNuseStringInPlace, False);		n++;
206           XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollNever);	n++;
207           XtSetArg(args[n], XtNscrollVertical, XawtextScrollWhenNeeded);n++;
208           XtSetArg(args[n], XtNdisplayCaret, False);			n++;
209           XtSetArg(args[n], XtNeditType, XawtextEdit);			n++;
210           XtSetArg(args[n], XtNresize, XawtextResizeWidth);		n++;
211    text = XtCreateManagedWidget(name,asciiTextWidgetClass,frame,args,n);
212           if (!trans) trans=XtParseTranslationTable(TextTr);
213           XtOverrideTranslations(text,trans);
214 
215    return text;
216 }
217 
218 /*##################################################*/
219 /* widgets_getText */
220 /*##################################################*/
221 
222 char *
widgets_getText(w)223 widgets_getText(w)
224    Widget w;
225 {
226    Arg    args[1];
227    String value;
228 
229    BEGINMESSAGE(widgets_getText)
230    XtSetArg(args[0], XtNstring, &value);
231    XtGetValues(w, args, ONE);
232    ENDMESSAGE(widgets_getText)
233    return value;
234 }
235 
236 /*##################################################*/
237 /* widgets_setText */
238 /*##################################################*/
239 
240 void
widgets_setText(w,value)241 widgets_setText(w,value)
242   Widget w;
243   String value;
244 {
245   Arg args[1];
246 
247   BEGINMESSAGE(widgets_setText)
248   if (value) {
249     XtSetArg(args[0], XtNstring, value);
250     XtSetValues(w,args,ONE);
251     XtSetArg(args[0], XtNinsertPosition, strlen(value));
252     XtSetValues(w,args,ONE);
253   }
254   ENDMESSAGE(widgets_setText)
255 }
256 
257 /*##################################################*/
258 /* widgets_preferButton */
259 /*##################################################*/
260 
261 void
widgets_preferButton(w,prefer)262 widgets_preferButton(w,prefer)
263    Widget   w;
264    int prefer;
265 {
266    BEGINMESSAGE(widgets_preferButton)
267    if (w) {
268      if (prefer) ButtonHighlight(w,NULL,NULL,NULL);
269      else        ButtonReset(w,NULL,NULL,NULL);
270    }
271    ENDMESSAGE(widgets_preferButton)
272 #if 0
273       XEvent event;
274       Position rx,ry;
275       XtTranslateCoords(w, 0, 0, &rx, &ry);
276       event.xcrossing.type        = prefer ? EnterNotify : LeaveNotify;
277       event.xcrossing.display     = XtDisplay(w);
278       event.xcrossing.window      = XtWindow(w);
279       event.xcrossing.root        = RootWindowOfScreen(XtScreen(w));
280       event.xcrossing.subwindow   = None;
281       event.xcrossing.time        = 0;
282       event.xcrossing.x           = 0;
283       event.xcrossing.y           = 0;
284       event.xcrossing.x_root      = (int)rx;
285       event.xcrossing.y_root      = (int)ry;
286       event.xcrossing.mode        = 0;
287       event.xcrossing.detail      = 0;
288       event.xcrossing.same_screen = 0;
289       event.xcrossing.focus       = 0;
290       event.xcrossing.state       = 0;
291       XSendEvent(XtDisplay(w),XtWindow(w), False,
292                  prefer ? EnterWindowMask : LeaveWindowMask, &event);
293 #endif
294 }
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 
305