1 /**@(#)
2 **/
3 /**
4 tw_tool.c:
5 Tina windows top level tool
6 **/
7
8 #include <stdio.h>
9 #include <math.h>
10 #include <tina/sys.h>
11 #include <tina/math.h>
12 #include <tina/tw.h>
13 #include <tina/tv.h>
14 #include <tina/tvfuncs.h>
15 #include <tina/tv_screen.h>
16 #include <xview/xview.h>
17 #include <xview/frame.h>
18 #include <xview/panel.h>
19 #include <xview/textsw.h>
20 #include <xview/font.h>
21 #include <xview/canvas.h>
22 #include <xview/cms.h>
23 #include <xview/xv_xrect.h>
24 #include <xview/openmenu.h>
25 #include <tina/Xvfuncs.h>
26 #include <tina/X11funcs.h>
27
28 #include <setjmp.h> /* Unused in Xview. Used in
29 * libtinaX11.a */
30
31 /* STATIC GLOBALS */
32 static Bool newrow;
33 static Display *active_display = NULL;
34 static Frame tool, toptool = (int)NULL;
35 static Panel panel;
36 static Window active_window = (int)NULL;
37 static Window lowest;
38 static char *toolname;
39 static int row;
40 static int width;
41 static int xpos, ypos;
42
43 /* GLOBALS */
44 jmp_buf interrupt_reentry_point;/* Unused in Xview. Used in
45 * libtinaX11.a */
46
47 /* Set display & window of latest button press BEING PROCESSED (ie
48 * whose callback has been called.) Used by tw_callback to reset
49 * cursor on interrupt */
50 void tw_active_tool_data_set(Display * display, Window window)
51 {
52 active_display = display;
53 active_window = window;
54 }
55
56 /* Get display & window of latest button press BEING PROCESSED (ie
57 * whose callback has been called.) Used by tw_callback to reset
58 * cursor on interrupt */
59 void tw_active_tool_data_get(Display ** display, Window * window)
60 /* NB pointer to pointer */
61
62 {
63 *display = active_display;
64 *window = active_window;
65 }
66
67 int tw_get_width(void)
68 {
69 return (width);
70 }
71
72 void tw_set_width(int w)
73 {
74 width = w;
75 }
76
77 void tw_get_pos(Frame tool, int *x, int *y)
78 {
79 *x = xv_get(tool, XV_X);
80 *y = xv_get(tool, XV_Y);
81 }
82
83 void tw_correct_pos(Frame tool, int *x, int *y)
84 {
85 int dx, dy;
86 Frame owner = (Frame) xv_get(tool, XV_OWNER);
87
88 if (owner == (int)NULL)
89 return;
90 tw_get_pos(owner, &dx, &dy);
91 *x += dx;
92 *y += dy;
93 tw_correct_pos(owner, x, y);
94 }
95
96 void tw_set_pos(Frame tool, int x, int y)
97 {
98 /** Open windows bug fix **/
99 tw_correct_pos(tool, &x, &y);
100 xv_set(tool,
101 XV_X, x, XV_Y, y,
102 NULL);
103 }
104 int tw_get_closed(Frame tool)
105 {
106 return xv_get(tool,FRAME_CLOSED, NULL);
107 }
108
109 void tw_set_closed(Frame tool, int closed)
110 {
111 xv_set(tool,FRAME_CLOSED,closed,NULL);
112 }
113
114 void tw_get_geom(Frame tool, int *x, int *y, int *w, int *h)
115 {
116 *x = xv_get(tool, XV_X);
117 *y = xv_get(tool, XV_Y);
118 *w = xv_get(tool, XV_WIDTH);
119 *h = xv_get(tool, XV_HEIGHT);
120 }
121
122 void tw_set_geom(Frame tool, int x, int y, int w, int h)
123 {
124 /** Open windows bug fix **/
125 tw_correct_pos(tool, &x, &y);
126 xv_set(tool,
127 XV_X, x, XV_Y, y,
128 XV_WIDTH, w, XV_HEIGHT, h,
129 NULL);
130 }
131
132 static void tool_cmnd(Tw_callback * twc, char *args)
133 {
134 int x, y, w, h, closed;
135
136 (void) sscanf(args, "%*s %d %d %d %d %d",
137 &x, &y, &w, &h, &closed);
138 tw_set_geom((Frame) twc->window, x, y, w, h);
139 xv_set(twc->window, FRAME_CLOSED, closed, NULL);
140 }
141
142 static void tool_prnt(FILE * fp, Tw_callback * twc)
143 {
144 int x, y, w, h, closed;
145 int x_top, y_top;
146
147 tw_get_geom(toptool, &x_top, &y_top, &w, &h);
148 tw_get_geom((Frame) twc->window, &x, &y, &w, &h);
149 if (x_top+x == 0 && y_top+y == 0)
150 {
151 format("poorly defined location from xv_get() for %s \n",twc->name);
152 format("append macro and reposition \n");
153 x = 0;
154 y = 0;
155 }
156 closed = (int) xv_get((Frame)twc->window, FRAME_CLOSED);
157 (void) fprintf(fp, "%s %d %d %d %d %d\n",
158 twc->name, x, y, w, h, closed);
159 }
160
161 /**
162 tool & panel handling
163 **/
164
165 Frame tw_get_toptool(void)
166 {
167 return (toptool);
168 }
169
170 Frame tw_get_tool(void)
171 {
172 return (tool);
173 }
174
175 void tw_set_tool(Frame newtool)
176 {
177 tool = newtool;
178 }
179
180 int tw_get_row(void)
181 {
182 return (row);
183 }
184
185 void tw_firstrow(void)
186 {
187 newrow = false;
188 row = 0;
189 }
190
191 void tw_newrow(void)
192 {
193 newrow = true;
194 row++;
195 }
196
197 Bool tw_get_newrow(void)
198 {
199 return (newrow);
200 }
201
202 void tw_set_newrow(Bool val)
203 {
204 newrow = val;
205 }
206
207 Panel tw_get_panel(void)
208 {
209 return (panel);
210 }
211
212 void tw_set_panel(Panel newpanel)
213 {
214 panel = newpanel;
215 }
216
217 Window tw_get_lowest(void)
218 {
219 return (lowest);
220 }
221
222 void tw_set_lowest(Window newlowest)
223 {
224 lowest = newlowest;
225 }
226
227 void tw_set_toolname(char *name)
228 {
229 toolname = name;
230 }
231
232 char *tw_get_toolname(void)
233 {
234 return (toolname);
235 }
236
237 void tw_show_tool(Frame tool)
238 {
239 xv_set(tool,
240 XV_SHOW, TRUE,
241 NULL);
242 xv_set(tool,
243 FRAME_CLOSED, FALSE,
244 NULL);
245 }
246
247
248 /* NB Unable to implement remote display in XView. */
249 /* ARGSUSED quieten lint. */
250 Frame tw_tool_remote(char *name, int x, int y, char *display_string)
251 {
252 Xv_font font;
253 Tw_callback *twc;
254
255 tw_set_width(0);
256
257 tool = (Frame) xv_create(toptool, FRAME,
258 FRAME_LABEL, name,
259 XV_SHOW, FALSE,
260 NULL);
261 xpos = x;
262 ypos = y;
263
264 if (toptool == (int)NULL)
265 toptool = tool;
266
267 panel = (Panel) xv_create(tool, PANEL,
268 PANEL_ITEM_X_GAP, 3,
269 WIN_ROW_GAP, 7,
270 NULL);
271
272 row = 0;
273 newrow = false;
274
275 if (toptool == (int)NULL)
276 toptool = tool;
277
278 font = (Xv_font) xv_find((int)NULL, FONT, FONT_NAME, "6x13", NULL);
279 if (font != (int) NULL)
280 xv_set(tool, XV_FONT, font, NULL);
281
282 toolname = tw_extend_fullname(name, (char *) NULL);
283 twc = tw_callback_make(toolname, tool,
284 (void (*) ()) NULL, tool_cmnd, tool_prnt, (void (*) ()) NULL, NULL,
285 NULL);
286 tw_register_callfrom(twc);
287
288 tw_set_lowest(panel);
289
290 return (tool);
291 }
292
293 void tw_no_panel(void)
294 {
295 /** motif function **/
296 }
297
298 /* v6*/
299 Frame tw_tool(char *name, int x, int y)
300 {
301 return tw_tool_remote(name, x, y, (char *) NULL);
302 }
303
304 void tw_tool_title_reset(Frame tool, char *name)
305 {
306 if (tool == (int)NULL)
307 return;
308 xv_set(tool, FRAME_LABEL, name, NULL);
309
310 }
311 void tw_tool_icon_title(Frame tool, char *name)
312 {
313 Icon icon;
314 if ((int)tool == (int)NULL)
315 return;
316 icon=xv_get(tool, FRAME_ICON,NULL);
317 xv_set(icon, XV_LABEL,name,NULL);
318 }
319
320 void tw_end_tool(void)
321 {
322 if (width == 0)
323 window_fit(panel);
324 else
325 xv_set(panel, WIN_WIDTH, width, NULL);
326 window_fit(tool);
327 tw_set_pos(tool, xpos, ypos);
328 xv_set(tool, XV_SHOW, TRUE, NULL);
329 }
330
331 int tw_next_event(void)
332 {
333 notify_dispatch();
334 tw_flush();
335 return 1;
336 }
337
338
339 void tw_main_loop(void)
340 {
341 char *tw_get_progname();
342 if ((int) tw_recover() & (int) tw_save())
343 {
344 tw_read_call_file(tw_get_progname());
345 tw_open_call_file(tw_get_progname(),"a");
346 } else if (tw_recover())
347 tw_read_call_file(tw_get_progname());
348 else if (tw_save())
349 tw_open_call_file(tw_get_progname(),"w");
350
351 window_main_loop(tool);
352 }
353
354 void tw_flush(void)
355 {
356 if (toptool)
357 {
358 XFlush((Display *) xv_get(toptool, XV_DISPLAY));
359 }
360 }
361
362
363
364 Display *tw_get_display(void)
365 {
366 return (Display *) xv_get(toptool, XV_DISPLAY);
367 }
368
369 int tw_tool_destroy(void *item)
370 {
371 int val;
372
373 val=xv_destroy_safe((int)item);
374 if(val==XV_ERROR)
375 {
376 printf("Unable to destroy that frame item\n");
377 val=0; /* error */
378 }
379 else
380 val=1; /* OK */
381 return val;
382 }
383
384 int tw_dialog_destroy(void *item)
385 {
386 return tw_tool_destroy(item);
387 }
388
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.