1 |
root |
1.1 |
/* |
2 |
|
|
* CnvUtil.c - miscallenous utilities in one function region |
3 |
|
|
* Copyright (C) 1993 Petri Heinila |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, write to the Free Software |
17 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
|
* |
19 |
|
|
* Author can be connected by email from hevi@lut.fi |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <Cnv.h> |
23 |
|
|
#include <debug.h> |
24 |
|
|
|
25 |
|
|
/* |
26 |
|
|
* include images |
27 |
|
|
*/ |
28 |
|
|
#include "excloff.xbm" |
29 |
|
|
#include "exclon.xbm" |
30 |
|
|
#include "flagoff.xbm" |
31 |
|
|
#include "flagon.xbm" |
32 |
|
|
#include "notify.xbm" |
33 |
|
|
#include "prompt.xbm" |
34 |
|
|
#include "submenu.xbm" |
35 |
|
|
|
36 |
|
|
/********************************************************************** |
37 |
|
|
* Translations |
38 |
|
|
**********************************************************************/ |
39 |
|
|
|
40 |
|
|
static void CnvNop(Widget w,XEvent *e,String *argv,Cardinal *argc) |
41 |
|
|
{ |
42 |
|
|
debug("CnvNop()\n"); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
static XtActionsRec CnvActions[] = { |
46 |
|
|
{ "CnvNop", CnvNop }, |
47 |
|
|
}; |
48 |
|
|
|
49 |
|
|
/********************************************************************** |
50 |
|
|
* Initialization |
51 |
|
|
**********************************************************************/ |
52 |
|
|
|
53 |
|
|
Cnv cnv; |
54 |
|
|
|
55 |
|
|
/* |
56 |
|
|
* initialize Cnv |
57 |
|
|
* CAUTION: used global data, usage restricted to ONE display |
58 |
|
|
*/ |
59 |
|
|
void CnvInitialize(Widget shell) |
60 |
|
|
{ |
61 |
|
|
debug1("CnvInitialize() to %s\n",XtName(shell)); |
62 |
|
|
cnv = (Cnv)XtMalloc(sizeof(struct Cnv)); |
63 |
|
|
cnv->shell = shell; |
64 |
|
|
/* |
65 |
|
|
* initialize images |
66 |
|
|
*/ |
67 |
|
|
cnv->xbm.excloff = XCreateBitmapFromData |
68 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
69 |
|
|
(char*)excloff_bits, |
70 |
|
|
excloff_width, |
71 |
|
|
excloff_height); |
72 |
|
|
cnv->xbm.exclon = XCreateBitmapFromData |
73 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
74 |
|
|
(char*)exclon_bits, |
75 |
|
|
exclon_width, |
76 |
|
|
exclon_height); |
77 |
|
|
cnv->xbm.flagoff = XCreateBitmapFromData |
78 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
79 |
|
|
(char*)flagoff_bits, |
80 |
|
|
flagoff_width, |
81 |
|
|
flagoff_height); |
82 |
|
|
cnv->xbm.flagon = XCreateBitmapFromData |
83 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
84 |
|
|
(char*)flagon_bits, |
85 |
|
|
flagon_width, |
86 |
|
|
flagon_height); |
87 |
|
|
cnv->xbm.notify = XCreateBitmapFromData |
88 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
89 |
|
|
(char*)notify_bits, |
90 |
|
|
notify_width, |
91 |
|
|
notify_height); |
92 |
|
|
cnv->xbm.prompt = XCreateBitmapFromData |
93 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
94 |
|
|
(char*)prompt_bits, |
95 |
|
|
prompt_width, |
96 |
|
|
prompt_height); |
97 |
|
|
cnv->xbm.submenu = XCreateBitmapFromData |
98 |
|
|
(XtDisplay(shell),DefaultRootWindow(XtDisplay(shell)), |
99 |
|
|
(char*)submenu_bits, |
100 |
|
|
submenu_width, |
101 |
|
|
submenu_height); |
102 |
|
|
/* |
103 |
|
|
* actions |
104 |
|
|
*/ |
105 |
|
|
XtAppAddActions(XtWidgetToApplicationContext(cnv->shell), |
106 |
|
|
CnvActions, |
107 |
|
|
XtNumber(CnvActions)); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
/********************************************************************** |
111 |
|
|
* Utility |
112 |
|
|
**********************************************************************/ |
113 |
|
|
|
114 |
|
|
/* |
115 |
|
|
* get shell widget of child |
116 |
|
|
*/ |
117 |
|
|
Widget CnvGetShell (Widget child) |
118 |
|
|
{ |
119 |
|
|
Widget use; |
120 |
|
|
|
121 |
|
|
for (use = child; |
122 |
|
|
use != 0 && XtIsShell (use) == False; |
123 |
|
|
use = XtParent (use) |
124 |
|
|
) |
125 |
|
|
/* Widget cannot live without top shell */ |
126 |
|
|
if (use == 0) { |
127 |
|
|
fprintf (stderr, "getShell: %s\n", "no shell found"); |
128 |
|
|
} |
129 |
|
|
return use; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
/* |
133 |
|
|
* center widget w into rootwindow |
134 |
|
|
*/ |
135 |
|
|
void CnvCenterWidget (Widget w) |
136 |
|
|
{ |
137 |
|
|
Position x, y; |
138 |
|
|
Dimension width, height, border; |
139 |
|
|
|
140 |
|
|
/* center dialog in root window */ |
141 |
|
|
XtRealizeWidget (w); |
142 |
|
|
XtVaGetValues (w, XtNwidth, &width, XtNheight, &height, |
143 |
|
|
XtNborderWidth, &border, NULL); |
144 |
|
|
x = (WidthOfScreen (XtScreen (w)) - width - border) / 2; |
145 |
|
|
y = (HeightOfScreen (XtScreen (w)) - height - border) / 2; |
146 |
|
|
XtVaSetValues (w, XtNx, x, XtNy, y, NULL); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
#if 0 |
150 |
|
|
static String CnvResourceFilePath (Widget w) |
151 |
|
|
{ |
152 |
|
|
String path = 0; |
153 |
|
|
|
154 |
|
|
if (getenv ("XUSERFILESEARCHPATH")) { |
155 |
|
|
path = XtResolvePathname (XtDisplay (w), |
156 |
|
|
NULL, |
157 |
|
|
NULL, |
158 |
|
|
NULL, |
159 |
|
|
getenv ("XUSERFILESEARCHPATH"), |
160 |
|
|
NULL, 0, |
161 |
|
|
NULL |
162 |
|
|
); |
163 |
|
|
} |
164 |
|
|
if (path) { |
165 |
|
|
return path; |
166 |
|
|
} else { |
167 |
|
|
path = XtResolvePathname (XtDisplay (w), |
168 |
|
|
"app-defaults", /* type */ |
169 |
|
|
NULL, |
170 |
|
|
NULL, /* suffix */ |
171 |
|
|
NULL, /* default; XFILESEARCHPATH */ |
172 |
|
|
NULL, 0, /* substitutions, numof */ |
173 |
|
|
NULL |
174 |
|
|
); |
175 |
|
|
} |
176 |
|
|
return path; |
177 |
|
|
} |
178 |
|
|
#endif |
179 |
|
|
/* |
180 |
|
|
* function: message to stderr and exit |
181 |
|
|
* self : any widget |
182 |
|
|
* msg : given message |
183 |
|
|
*/ |
184 |
|
|
void CnvDie(Widget self,String msg) |
185 |
|
|
{ |
186 |
|
|
char buf[BUFSIZ]; |
187 |
|
|
|
188 |
|
|
sprintf(buf, |
189 |
|
|
"%s: %s", |
190 |
|
|
XtName(self), |
191 |
|
|
msg); |
192 |
|
|
XtAppError(XtWidgetToApplicationContext(self),buf); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
/* |
196 |
|
|
* function: message to stderr |
197 |
|
|
* self : any widget |
198 |
|
|
* msg : given message |
199 |
|
|
*/ |
200 |
|
|
void CnvWarn(Widget self,String msg) |
201 |
|
|
{ |
202 |
|
|
char buf[BUFSIZ]; |
203 |
|
|
|
204 |
|
|
sprintf(buf, |
205 |
|
|
"%s: %s", |
206 |
|
|
XtName(self), |
207 |
|
|
msg); |
208 |
|
|
XtAppWarning(XtWidgetToApplicationContext(self),buf); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
/*** end of CnvUtil.c ***/ |