~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/Xm/tw_tool.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /** @(#)Tina tool creation.  Ie  a user defined 'tool' ie window with buttons,
  2  * menus, graphics canvas's etc. Create either 'localy', ie one on the
  3  * workstation on which the session is running or remotely.
  4  */
  5 
  6 #include <stdio.h>
  7 #include <tina/sys.h>
  8 #include <tina/sysfuncs.h>
  9 #include <tina/math.h>
 10 #include <tina/tv.h>
 11 #include  <tina/mtw.h>
 12 #include  <tina/tv_screen.h>
 13 #include <tina/Xmfuncs.h>
 14 #include <setjmp.h>
 15 
 16 #define TW_DEFAULT_charWIDTH 6
 17 #define TW_DEFAULT_charHEIGHT 13
 18 #define PROGRAM_CLASS "tinatool"
 19 
 20 /* STATIC GLOBALS */
 21 static Display *active_display = (Display *) NULL;
 22 static Widget first_tool, toptool, tool;
 23 static Widget form;
 24 static Widget panel;
 25 static Window active_window = (Window) NULL;
 26 static char *first_display_string = (char *) NULL;
 27 static char *toolname;
 28 
 29 /* FORWARD REFS */
 30 static Widget toptool_find(char *display_string);
 31 static void tw_tool_quit_callback(Widget widget);
 32 static void tw_panel(void);
 33 
 34 /** Info about each row of widgets to allow centering **/
 35 static int nwidgets;
 36 static Widget widgets[64];
 37 static int heights[64], maxheight;
 38 static int widths[64];
 39 static int ypos;
 40 static int totwidth, totheight;
 41 static int toolx, tooly;
 42 
 43 /* EXTERNS */
 44 void    exit(int);
 45 
 46 /* GLOBALS */
 47 jmp_buf interrupt_reentry_point;
 48 Display *display;
 49 
 50 static int tw_indent = 7;
 51 
 52 void    tw_indent_set(int indent)
 53 {
 54     tw_indent = indent;
 55 }
 56 
 57 int     tw_indent_get(void)
 58 {
 59     return tw_indent;
 60 }
 61 
 62 int     tw_nwidgets_get(void)
 63 {
 64     return nwidgets;
 65 }
 66 
 67 /* Set display & window of latest button press BEING PROCESSED (ie
 68  * whose callback has been called.)  Used by tw_callback to reset
 69  * cursor on interrupt */
 70 void    tw_active_tool_data_set(Display * display, Window window)
 71 {
 72     active_display = display;
 73     active_window = window;
 74 }
 75 
 76 /* Get display & window of latest button press BEING PROCESSED (ie
 77  * whose callback has been called.)  Used by tw_callback to reset
 78  * cursor on interrupt */
 79 void    tw_active_tool_data_get(Display ** display, Window * window)
 80 {
 81     *display = active_display;
 82     *window = active_window;
 83 }
 84 
 85 
 86 
 87 int     tw_get_totwidth(void)
 88 {
 89     return (totwidth);
 90 }
 91 
 92 int     tw_get_totheight(void)
 93 {
 94     return (totheight);
 95 }
 96 
 97 void    tw_inc_totwidth(int w)
 98 {
 99     totwidth = MAX(w, totwidth);
100 }
101 
102 void    tw_inc_totheight(int dh)
103 {
104     totheight += dh;
105 }
106 
107 int     tw_charwidth(double l)
108 {
109     return ((int) (TW_DEFAULT_charWIDTH * l));
110 }
111 
112 int     tw_charheight(double l)
113 {
114     return ((int) (TW_DEFAULT_charHEIGHT * l));
115 }
116 
117 /* position widget w.r.t. parent */
118 void    tw_set_pos(Widget w, int x, int y)
119 {
120     int     nargs;
121     Arg     wargs[2];
122 
123     nargs = 0;
124     XtSetArg(wargs[nargs], XmNx, x);
125     nargs++;
126     XtSetArg(wargs[nargs], XmNy, y);
127     nargs++;
128     XtSetValues(w, wargs, nargs);
129 }
130 
131 void    tw_set_geom(Widget widget, int x, int y, int w, int h)
132 {
133     int     nargs;
134     Arg     wargs[4];
135 
136     nargs = 0;
137     XtSetArg(wargs[nargs], XmNx, x);
138     nargs++;
139     XtSetArg(wargs[nargs], XmNy, y);
140     nargs++;
141     XtSetArg(wargs[nargs], XmNwidth, w);
142     nargs++;
143     XtSetArg(wargs[nargs], XmNheight, h);
144     nargs++;
145     XtSetValues(widget, wargs, nargs);
146 }
147 
148 void    tw_set_size(Widget widget, int w, int h)
149 {
150     int     nargs;
151     Arg     wargs[4];
152 
153     nargs = 0;
154     XtSetArg(wargs[nargs], XmNwidth, w);
155     nargs++;
156     XtSetArg(wargs[nargs], XmNheight, h);
157     nargs++;
158     XtSetValues(widget, wargs, nargs);
159 }
160 
161 void    tw_get_geom(Widget widget, int *x, int *y, int *w, int *h)
162 {
163     XtWidgetGeometry geom;
164 
165     XtQueryGeometry(widget, NULL, &geom);
166     *x = geom.x;
167     *y = geom.y;
168     *w = geom.width;
169     *h = geom.height;
170 }
171 int tw_get_closed(void *tool)
172 {
173   return 0;                     /* cannot query ???*/
174 }
175 void tw_set_closed(void *tool, int closed)
176 {
177   /* do nothing */
178 }
179 
180 void    tw_firstrow(void)
181 {
182     ypos = tw_indent;           /** fixes problem with ypos = 0 **/
183     maxheight = 0;
184     nwidgets = 0;
185 
186     totheight = totwidth = 0;
187 }
188 
189 /* Save an estimate of width & height for widgets on a row */
190 void    tw_set_entry(Widget w, int width, int height)
191 {
192     widgets[nwidgets] = w;
193     widths[nwidgets] = width;
194     heights[nwidgets] = height;
195     if (maxheight < height)
196         maxheight = height;
197     nwidgets++;
198 }
199 
200 
201 /* Poition a whole row of widgets, use estimated widths to space
202  * widgets along row use estimated heights to centre widgets along row */
203 void    tw_newrow(void)
204 {
205     int     i;
206     int     x = tw_indent;      /** fixes problem with xpos = 0 **/
207     int     y;
208 
209     for (i = 0; i < nwidgets; i++)
210     {
211         if (i == 0)
212             x = tw_indent;
213         else
214             x += widths[i - 1];
215         y = ypos + (maxheight - heights[i]) / 2;
216         tw_set_pos(widgets[i], x, y);
217     }
218 
219     tw_inc_totheight(maxheight);
220     tw_inc_totwidth(x + widths[nwidgets - 1] + tw_indent);
221 
222     ypos += maxheight;
223     maxheight = 0;
224     nwidgets = 0;
225 }
226 
227 
228 void    tw_set_toolname(char *name)
229 {
230     toolname = name;
231 }
232 
233 
234 char   *tw_get_toolname(void)
235 {
236     return (toolname);
237 }
238 
239 
240 Widget  tw_get_tool(void)
241 {
242     return (tool);
243 }
244 
245 
246 void    tw_set_tool(Widget newtool)
247 {
248     tool = newtool;
249 }
250 
251 
252 Widget  tw_get_toptool(void)
253 {
254     return (toptool);
255 }
256 
257 
258 void    tw_set_toptool(Widget newtool)
259 {
260     toptool = newtool;
261 }
262 
263 
264 void    tw_first_tool_set(Widget newtool)
265 {
266     first_tool = newtool;
267     first_display_string = DisplayString(XtDisplay(newtool));
268 }
269 
270 
271 Widget  tw_get_form(void)
272 {
273     return (form);
274 }
275 
276 
277 Widget  tw_get_panel(void)
278 {
279     return (panel);
280 }
281 
282 
283 void    tw_set_panel(Widget w)
284 {
285     panel = w;
286 }
287 
288 
289 void    tw_hide_tool(Widget tool)
290 {
291     XtPopdown(tool);
292 }
293 
294 
295 void    tw_show_tool(Widget tool)
296 {
297     XtPopup(tool, XtGrabNone);
298 }
299 
300 /* Tool manages a form widget form manages: bulletin board + optional
301  * canvas or textsw */
302 static void tool_cmnd(Tw_callback * twc, char *args)
303 {
304     int     x, y, w, h;
305 
306     (void) sscanf(args, "%*s %d %d %d %d", &x, &y, &w, &h);
307     tw_set_geom(twc->widget, x, y, w, h);
308 }
309 
310 
311 static void tool_prnt(FILE * fp, Tw_callback * twc)
312 {
313     int     x, y, w, h;
314 
315     tw_get_geom(twc->widget, &x, &y, &w, &h);
316     (void) fprintf(fp, "%s %d %d %d %d\n", twc->name, x, y, w, h);
317 }
318 
319 
320 static void test(void)
321 {
322     (void) fprintf(stderr, "bye bye!\n");
323 }
324 
325 
326 /* Compare the display_string in toptool_data with a key string.  If
327  * match return toptool_data else return NULL */
328 void   *toptool_match(char *display_string, Toptool_data * data)
329 {
330     /* strcmp returns 0 if strings match (ie data matches) */
331     return (display_string &&
332             !strcmp(display_string, data->display_string)) ? (void *) data : NULL;
333 }
334 
335 
336 /* Find (create or get from database) a tool on a given display/screen */
337 Widget  tool_find(char *name, char *display_string)
338 {
339     toptool = toptool_find(display_string);
340     tool = XtCreatePopupShell(name, topLevelShellWidgetClass, toptool, NULL, 0);
341 
342     return tool;
343 }
344 
345 
346 /* Find (create or get from database) a top level tool on a given
347  * display/screen */
348 static Widget toptool_find(char *display_string)
349 {
350     Display *display;
351     Toptool_data *toptool_data;
352     Widget  toptool;
353     int     argc = 0;
354     static List *toptool_database = NULL;
355 
356     /* display_string NULL etc, toptool = first_tool */
357     if (!display_string || !*display_string ||
358         !strcmp(display_string, first_display_string))
359     {
360         toptool = first_tool;
361     } else
362         /* Search database for top level tool on display */
363         if (toptool_data = (Toptool_data *) list_query(toptool_database,
364                               toptool_match, (void *) display_string))
365     {
366         toptool = toptool_data->toptool;
367     } else
368         /* Create top level tool on  display. */
369         if (display = XtOpenDisplay(tw_get_context(), display_string, NULL,
370                                  PROGRAM_CLASS, NULL, 0, &argc, NULL))
371     {
372         /* Create top level tool on  display. */
373         toptool = XtAppCreateShell(display_string, "twtool",
374                        applicationShellWidgetClass, display, NULL, 0);
375 
376         /* Add toptool to database. */
377         toptool_data = ts_ralloc(Toptool_data);
378         toptool_data->toptool = toptool;
379         toptool_data->display_string = DisplayString(display);
380         ref_addtostart(toptool_database, toptool_data, 0);
381     } else
382         /* Use first_tool  */
383     {
384         toptool = first_tool;
385         format("tw_tool_remote: Can't open display: %s.\n", display_string);
386         format("Created tool on first display: %s\n", first_display_string);
387     }
388     return toptool;
389 }
390 void tw_tool_icon_title(int tool, char *name)
391 {
392 }
393 
394 /* Complete creation of tw_tool stated with tw_tool or tw_tool_remote */
395 void    tw_end_tool(void)
396 {
397     int     nargs;
398     Arg     wargs[1];
399 
400     tw_newrow();
401 
402     nargs = 0;
403     XtSetArg(wargs[nargs], XmNbottomAttachment, XmATTACH_FORM);
404     nargs++;
405     XtSetValues(panel, wargs, nargs);
406 
407     XtRealizeWidget(tool);
408     tw_inc_totheight(tw_indent);
409     tw_set_tina_cursor(XtDisplay(tool), XtWindow(tool));
410     if (tool != toptool)
411         XtPopup(tool, XtGrabNone);
412     tw_set_geom(tool, toolx, tooly, totwidth, totheight);
413 
414     /* Add callback so quitting tool removes connections to it.  Eg
415      * tv's installed on tools containing tv_screen's
416     XtAddCallback(tool, XtNdestroyCallback, tw_tool_quit_callback, (XtPointer) NULL);
417 */
418 }
419 
420 
421 void    tw_handle_calls(void)
422 {
423     char   *tw_get_progname();
424     if (tw_recover() && tw_save())
425     {
426         tw_read_call_file(tw_get_progname());
427         tw_open_call_file(tw_get_progname(),"a");
428     } else if (tw_recover())
429         tw_read_call_file(tw_get_progname());
430     else if (tw_save())
431         tw_open_call_file(tw_get_progname(),"w");
432 }
433 int tw_next_event(void)
434 {
435   if(XtPending())
436     {
437       while(XtPending())
438         {
439           XEvent event;
440           XtNextEvent(&event);
441           XtDispatchEvent(&event);
442         }
443       return 1;
444     }
445   else
446     return 0;
447 }
448 
449 void    tw_main_loop(void)
450 {
451     display = (Display *) tw_get_display();     /* was void display ie
452                                                  * local JB 24/11/92 */
453 
454     tw_handle_calls();
455 
456     (void) setjmp(interrupt_reentry_point);
457 
458     XtAppMainLoop(tw_get_context());
459 }
460 
461 /* Create a user defined 'tool' ie window with buttons, menus, graphics
462  * canvas's etc. Create on a remote workstation if display_string is
463  * not "" or NULL */
464 Widget  tw_tool_remote(char *name, int x, int y, char *display_string)
465 {
466     Arg     wargs[10];
467     Tw_callback *twc;
468     int     nargs = 0;
469 
470     toolx = x;
471     tooly = y;
472     tool = tool_find(name, display_string);
473 
474     XtSetArg(wargs[nargs], XmNallowShellResize, True);
475     nargs++;
476     XtSetArg(wargs[nargs], XmNtitle, name);
477     nargs++;
478     XtSetValues(tool, wargs, nargs);
479 
480     form = XtCreateManagedWidget("twform", xmFormWidgetClass,
481                                  tool, (ArgList) NULL, 0);
482 
483     tw_panel();
484     tw_firstrow();
485 
486     /** replay callbacks for tool placement **/
487     toolname = tw_extend_fullname(name, (char *) NULL);
488     twc = tw_callback_make(toolname, tool, tool, (void (*) ()) NULL, tool_cmnd,
489                            tool_prnt, (void (*) ()) NULL, NULL,
490                            NULL);
491     tw_register_callfrom(twc);
492 
493     return (tool);
494 }
495 
496 
497 /* Create a user defined 'tool' ie window with buttons, menus, graphics
498  * canvas's etc. Create on 'local' workstation, ie one on which the
499  * session is running. */
500 Widget  tw_tool(char *name, int x, int y)
501 {
502     return (Widget) tw_tool_remote(name, x, y, "");
503 }
504 
505 static void tw_panel(void)
506 {
507     Arg     wargs[10];
508     int     nargs = 0;
509 
510     nargs = 0;
511     XtSetArg(wargs[nargs], XmNtopAttachment, XmATTACH_FORM);
512     nargs++;
513     XtSetArg(wargs[nargs], XmNleftAttachment, XmATTACH_FORM);
514     nargs++;
515     XtSetArg(wargs[nargs], XmNrightAttachment, XmATTACH_FORM);
516     nargs++;
517     panel = XtCreateManagedWidget("twpanel", xmBulletinBoardWidgetClass,
518                                   form, wargs, nargs);
519 }
520 
521 void    tw_no_panel(void)
522 {
523     XtDestroyWidget(panel);
524     panel = 0;
525 }
526 
527 tw_tool_title_reset(Widget tool, char *name)
528 {
529     Arg     wargs[10];
530     int     nargs = 0;
531 
532     if (tool == NULL)
533         return;
534 
535     XtSetArg(wargs[nargs], XmNtitle, name);
536     nargs++;
537     XtSetValues(tool, wargs, nargs);
538 }
539 
540 /* Callback called on quitting tool removes connections to it.  Eg tv's
541  * installed on tools containing tv_screen's */
542 static void tw_tool_quit_callback(Widget widget)
543 {
544     Display *display = XtDisplay(widget);
545     int     screen = XScreenNumberOfScreen(XtScreen(widget));
546 
547     format("tw_tool_quit_callback: display %x\tscreen: %d\n", display, screen);
548 }
549 
550 int tw_tool_destroy(void *item)
551 {
552   Widget widget=(Widget)item;
553 
554   XtDestroyWidget(widget);
555   return 1;                     /* always OK ???? */
556 }
557 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.