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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_tool.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_tool.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsXm_tw_tool.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Tina windows top level tool
 44  *
 45  *********
 46 */
 47 
 48 #include "wdgtsXm_tw_tool.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #   include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <setjmp.h>
 56 
 57 #include <X11/Intrinsic.h>
 58 #include <Xm/Xm.h>
 59 #include <Xm/Form.h>
 60 #include <Xm/BulletinB.h>
 61 
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/sys/sysPro.h>
 64 #include <tinatool/wdgts/xm/wdgts_XmDef.h>
 65 #include <tinatool/wdgts/xm/wdgtsXm_tw_command.h>
 66 #include <tinatool/wdgts/xm/wdgtsXm_tw_init.h>
 67 #include <tinatool/gphx/x11/gphxX11_tw_cursor.h>
 68 
 69 #define TW_DEFAULT_charWIDTH 6
 70 #define TW_DEFAULT_charHEIGHT 13
 71 #define PROGRAM_CLASS "tinatool"
 72 
 73 /* STATIC GLOBALS */
 74 static Display *active_display = (Display *) NULL;
 75 static Widget first_tool, toptool, tool;
 76 static Widget form;
 77 static Widget panel;
 78 static Window active_window = (Window) NULL;
 79 static char *first_display_string = (char *) NULL;
 80 static char *toolname;
 81 
 82 /* FORWARD REFS */
 83 static Widget toptool_find(char *display_string);
 84 static void tw_tool_quit_callback(Widget widget);
 85 static void tw_panel(void);
 86 
 87 /** Info about each row of widgets to allow centering **/
 88 static int nwidgets;
 89 static Widget widgets[64];
 90 static int heights[64], maxheight;
 91 static int widths[64];
 92 static int ypos;
 93 static int totwidth, totheight;
 94 static int toolx, tooly;
 95 
 96 /* EXTERNS */
 97 void    exit(int);
 98 
 99 /* GLOBALS */
100 jmp_buf interrupt_reentry_point;
101 Display *display;
102 
103 static int tw_indent = 7;
104 
105 void    tw_indent_set(int indent)
106 {
107     tw_indent = indent;
108 }
109 
110 int     tw_indent_get(void)
111 {
112     return tw_indent;
113 }
114 
115 int     tw_nwidgets_get(void)
116 {
117     return nwidgets;
118 }
119 
120 /* Set display & window of latest button press BEING PROCESSED (ie
121  * whose callback has been called.)  Used by tw_callback to reset
122  * cursor on interrupt */
123 void    tw_active_tool_data_set(Display * display, Window window)
124 {
125     active_display = display;
126     active_window = window;
127 }
128 
129 /* Get display & window of latest button press BEING PROCESSED (ie
130  * whose callback has been called.)  Used by tw_callback to reset
131  * cursor on interrupt */
132 void    tw_active_tool_data_get(Display ** display, Window * window)
133 {
134     *display = active_display;
135     *window = active_window;
136 }
137 
138 
139 
140 int     tw_get_totwidth(void)
141 {
142     return (totwidth);
143 }
144 
145 int     tw_get_totheight(void)
146 {
147     return (totheight);
148 }
149 
150 void    tw_inc_totwidth(int w)
151 {
152     totwidth = MAX(w, totwidth);
153 }
154 
155 void    tw_inc_totheight(int dh)
156 {
157     totheight += dh;
158 }
159 
160 int     tw_charwidth(double l)
161 {
162     return ((int) (TW_DEFAULT_charWIDTH * l));
163 }
164 
165 int     tw_charheight(double l)
166 {
167     return ((int) (TW_DEFAULT_charHEIGHT * l));
168 }
169 
170 /* position widget w.r.t. parent */
171 void    tw_set_pos(Widget w, int x, int y)
172 {
173     int     nargs;
174     Arg     wargs[2];
175 
176     nargs = 0;
177     XtSetArg(wargs[nargs], XmNx, x);
178     nargs++;
179     XtSetArg(wargs[nargs], XmNy, y);
180     nargs++;
181     XtSetValues(w, wargs, nargs);
182 }
183 
184 void    tw_set_geom(Widget widget, int x, int y, int w, int h)
185 {
186     int     nargs;
187     Arg     wargs[4];
188 
189     nargs = 0;
190     XtSetArg(wargs[nargs], XmNx, x);
191     nargs++;
192     XtSetArg(wargs[nargs], XmNy, y);
193     nargs++;
194     XtSetArg(wargs[nargs], XmNwidth, w);
195     nargs++;
196     XtSetArg(wargs[nargs], XmNheight, h);
197     nargs++;
198     XtSetValues(widget, wargs, nargs);
199 }
200 
201 void    tw_set_size(Widget widget, int w, int h)
202 {
203     int     nargs;
204     Arg     wargs[4];
205 
206     nargs = 0;
207     XtSetArg(wargs[nargs], XmNwidth, w);
208     nargs++;
209     XtSetArg(wargs[nargs], XmNheight, h);
210     nargs++;
211     XtSetValues(widget, wargs, nargs);
212 }
213 
214 void    tw_get_geom(Widget widget, int *x, int *y, int *w, int *h)
215 {
216     XtWidgetGeometry geom;
217 
218     XtQueryGeometry(widget, NULL, &geom);
219     *x = geom.x;
220     *y = geom.y;
221     *w = geom.width;
222     *h = geom.height;
223 }
224 int tw_get_closed(void *tool)
225 {
226   return 0;                     /* cannot query ???*/
227 }
228 void tw_set_closed(void *tool, int closed)
229 {
230   /* do nothing */
231 }
232 
233 void    tw_firstrow(void)
234 {
235     ypos = tw_indent;           /** fixes problem with ypos = 0 **/
236     maxheight = 0;
237     nwidgets = 0;
238 
239     totheight = totwidth = 0;
240 }
241 
242 /* Save an estimate of width & height for widgets on a row */
243 void    tw_set_entry(Widget w, int width, int height)
244 {
245     widgets[nwidgets] = w;
246     widths[nwidgets] = width;
247     heights[nwidgets] = height;
248     if (maxheight < height)
249         maxheight = height;
250     nwidgets++;
251 }
252 
253 
254 /* Poition a whole row of widgets, use estimated widths to space
255  * widgets along row use estimated heights to centre widgets along row */
256 void    tw_newrow(void)
257 {
258     int     i;
259     int     x = tw_indent;      /** fixes problem with xpos = 0 **/
260     int     y;
261 
262     for (i = 0; i < nwidgets; i++)
263     {
264         if (i == 0)
265             x = tw_indent;
266         else
267             x += widths[i - 1];
268         y = ypos + (maxheight - heights[i]) / 2;
269         tw_set_pos(widgets[i], x, y);
270     }
271 
272     tw_inc_totheight(maxheight);
273     tw_inc_totwidth(x + widths[nwidgets - 1] + tw_indent);
274 
275     ypos += maxheight;
276     maxheight = 0;
277     nwidgets = 0;
278 }
279 
280 
281 void    tw_set_toolname(char *name)
282 {
283     toolname = name;
284 }
285 
286 
287 char   *tw_get_toolname(void)
288 {
289     return (toolname);
290 }
291 
292 
293 Widget  tw_get_tool(void)
294 {
295     return (tool);
296 }
297 
298 
299 void    tw_set_tool(Widget newtool)
300 {
301     tool = newtool;
302 }
303 
304 
305 Widget  tw_get_toptool(void)
306 {
307     return (toptool);
308 }
309 
310 
311 void    tw_set_toptool(Widget newtool)
312 {
313     toptool = newtool;
314 }
315 
316 
317 void    tw_first_tool_set(Widget newtool)
318 {
319     first_tool = newtool;
320     first_display_string = DisplayString(XtDisplay(newtool));
321 }
322 
323 
324 Widget  tw_get_form(void)
325 {
326     return (form);
327 }
328 
329 
330 Widget  tw_get_panel(void)
331 {
332     return (panel);
333 }
334 
335 
336 void    tw_set_panel(Widget w)
337 {
338     panel = w;
339 }
340 
341 
342 void    tw_hide_tool(Widget tool)
343 {
344     XtPopdown(tool);
345 }
346 
347 
348 void    tw_show_tool(Widget tool)
349 {
350     XtPopup(tool, XtGrabNone);
351 }
352 
353 /* Tool manages a form widget form manages: bulletin board + optional
354  * canvas or textsw */
355 static void tool_cmnd(Tw_callback * twc, char *args)
356 {
357     int     x, y, w, h;
358 
359     (void) sscanf(args, "%*s %d %d %d %d", &x, &y, &w, &h);
360     tw_set_geom(twc->widget, x, y, w, h);
361 }
362 
363 
364 static void tool_prnt(FILE * fp, Tw_callback * twc)
365 {
366     int     x, y, w, h;
367 
368     tw_get_geom(twc->widget, &x, &y, &w, &h);
369     (void) fprintf(fp, "%s %d %d %d %d\n", twc->name, x, y, w, h);
370 }
371 
372 
373 static void test(void)
374 {
375     (void) fprintf(stderr, "bye bye!\n");
376 }
377 
378 
379 /* Compare the display_string in toptool_data with a key string.  If
380  * match return toptool_data else return NULL */
381 void   *toptool_match(char *display_string, Toptool_data * data)
382 {
383     /* strcmp returns 0 if strings match (ie data matches) */
384     return (display_string &&
385             !strcmp(display_string, data->display_string)) ? (void *) data : NULL;
386 }
387 
388 
389 /* Find (create or get from database) a tool on a given display/screen */
390 Widget  tool_find(char *name, char *display_string)
391 {
392     toptool = toptool_find(display_string);
393     tool = XtCreatePopupShell(name, topLevelShellWidgetClass, toptool, NULL, 0);
394 
395     return tool;
396 }
397 
398 
399 /* Find (create or get from database) a top level tool on a given
400  * display/screen */
401 static Widget toptool_find(char *display_string)
402 {
403     Display *display;
404     Toptool_data *toptool_data;
405     Widget  toptool;
406     int     argc = 0;
407     static List *toptool_database = NULL;
408 
409     /* display_string NULL etc, toptool = first_tool */
410     if (!display_string || !*display_string ||
411         !strcmp(display_string, first_display_string))
412     {
413         toptool = first_tool;
414     } else
415         /* Search database for top level tool on display */
416         if (toptool_data = (Toptool_data *) list_query(toptool_database,
417                               toptool_match, (void *) display_string))
418     {
419         toptool = toptool_data->toptool;
420     } else
421         /* Create top level tool on  display. */
422         if (display = XtOpenDisplay(tw_get_context(), display_string, NULL,
423                                  PROGRAM_CLASS, NULL, 0, &argc, NULL))
424     {
425         /* Create top level tool on  display. */
426         toptool = XtAppCreateShell(display_string, "twtool",
427                        applicationShellWidgetClass, display, NULL, 0);
428 
429         /* Add toptool to database. */
430         toptool_data = ts_ralloc(Toptool_data);
431         toptool_data->toptool = toptool;
432         toptool_data->display_string = DisplayString(display);
433         ref_addtostart(toptool_database, toptool_data, 0);
434     } else
435         /* Use first_tool  */
436     {
437         toptool = first_tool;
438         format("tw_tool_remote: Can't open display: %s.\n", display_string);
439         format("Created tool on first display: %s\n", first_display_string);
440     }
441     return toptool;
442 }
443 void tw_tool_icon_title(int tool, char *name)
444 {
445 }
446 
447 /* Complete creation of tw_tool stated with tw_tool or tw_tool_remote */
448 void    tw_end_tool(void)
449 {
450     int     nargs;
451     Arg     wargs[1];
452 
453     tw_newrow();
454 
455     nargs = 0;
456     XtSetArg(wargs[nargs], XmNbottomAttachment, XmATTACH_FORM);
457     nargs++;
458     XtSetValues(panel, wargs, nargs);
459 
460     XtRealizeWidget(tool);
461     tw_inc_totheight(tw_indent);
462     tw_set_tina_cursor(XtDisplay(tool), XtWindow(tool));
463     if (tool != toptool)
464         XtPopup(tool, XtGrabNone);
465     tw_set_geom(tool, toolx, tooly, totwidth, totheight);
466 
467     /* Add callback so quitting tool removes connections to it.  Eg
468      * tv's installed on tools containing tv_screen's
469     XtAddCallback(tool, XtNdestroyCallback, tw_tool_quit_callback, (XtPointer) NULL);
470 */
471 }
472 
473 
474 void    tw_handle_calls(void)
475 {
476     char   *tw_get_progname();
477     if (tw_recover() && tw_save())
478     {
479         tw_read_call_file(tw_get_progname());
480         tw_open_call_file(tw_get_progname(),"a");
481     } else if (tw_recover())
482         tw_read_call_file(tw_get_progname());
483     else if (tw_save())
484         tw_open_call_file(tw_get_progname(),"w");
485 }
486 int tw_next_event(void)
487 {
488   if(XtPending())
489     {
490       while(XtPending())
491         {
492           XEvent event;
493           XtNextEvent(&event);
494           XtDispatchEvent(&event);
495         }
496       return 1;
497     }
498   else
499     return 0;
500 }
501 
502 void    tw_main_loop(void)
503 {
504     display = (Display *) tw_get_display();     /* was void display ie
505                                                  * local JB 24/11/92 */
506 
507     tw_handle_calls();
508 
509     (void) setjmp(interrupt_reentry_point);
510 
511     XtAppMainLoop(tw_get_context());
512 }
513 
514 /* Create a user defined 'tool' ie window with buttons, menus, graphics
515  * canvas's etc. Create on a remote workstation if display_string is
516  * not "" or NULL */
517 Widget  tw_tool_remote(char *name, int x, int y, char *display_string)
518 {
519     Arg     wargs[10];
520     Tw_callback *twc;
521     int     nargs = 0;
522 
523     toolx = x;
524     tooly = y;
525     tool = tool_find(name, display_string);
526 
527     XtSetArg(wargs[nargs], XmNallowShellResize, True);
528     nargs++;
529     XtSetArg(wargs[nargs], XmNtitle, name);
530     nargs++;
531     XtSetValues(tool, wargs, nargs);
532 
533     form = XtCreateManagedWidget("twform", xmFormWidgetClass,
534                                  tool, (ArgList) NULL, 0);
535 
536     tw_panel();
537     tw_firstrow();
538 
539     /** replay callbacks for tool placement **/
540     toolname = tw_extend_fullname(name, (char *) NULL);
541     twc = tw_callback_make(toolname, tool, tool, (void (*) ()) NULL, tool_cmnd,
542                            tool_prnt, (void (*) ()) NULL, NULL,
543                            NULL);
544     tw_register_callfrom(twc);
545 
546     return (tool);
547 }
548 
549 
550 /* Create a user defined 'tool' ie window with buttons, menus, graphics
551  * canvas's etc. Create on 'local' workstation, ie one on which the
552  * session is running. */
553 Widget  tw_tool(char *name, int x, int y)
554 {
555     return (Widget) tw_tool_remote(name, x, y, "");
556 }
557 
558 static void tw_panel(void)
559 {
560     Arg     wargs[10];
561     int     nargs = 0;
562 
563     nargs = 0;
564     XtSetArg(wargs[nargs], XmNtopAttachment, XmATTACH_FORM);
565     nargs++;
566     XtSetArg(wargs[nargs], XmNleftAttachment, XmATTACH_FORM);
567     nargs++;
568     XtSetArg(wargs[nargs], XmNrightAttachment, XmATTACH_FORM);
569     nargs++;
570     panel = XtCreateManagedWidget("twpanel", xmBulletinBoardWidgetClass,
571                                   form, wargs, nargs);
572 }
573 
574 void    tw_no_panel(void)
575 {
576     XtDestroyWidget(panel);
577     panel = 0;
578 }
579 
580 void tw_tool_title_reset(Widget tool, char *name)
581 {
582     Arg     wargs[10];
583     int     nargs = 0;
584 
585     if (tool == NULL)
586         return;
587 
588     XtSetArg(wargs[nargs], XmNtitle, name);
589     nargs++;
590     XtSetValues(tool, wargs, nargs);
591 }
592 
593 /* Callback called on quitting tool removes connections to it.  Eg tv's
594  * installed on tools containing tv_screen's */
595 static void tw_tool_quit_callback(Widget widget)
596 {
597     Display *display = XtDisplay(widget);
598     int     screen = XScreenNumberOfScreen(XtScreen(widget));
599 
600     format("tw_tool_quit_callback: display %x\tscreen: %d\n", display, screen);
601 }
602 
603 int tw_tool_destroy(void *item)
604 {
605   Widget widget=(Widget)item;
606 
607   XtDestroyWidget(widget);
608   return 1;                     /* always OK ???? */
609 }
610 

~ [ 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.