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

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

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <math.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/tv.h>
  9 #include <tina/mtw.h>
 10 #include <tina/tv_screen.h>
 11 #include <tina/Xmfuncs.h>
 12 
 13 /* STATICS */
 14 static Widget interrupt_button = None;
 15 
 16 static void button_call(Tw_callback * twc)
 17 {
 18     tw_set_tool(twc->tool);
 19     (*twc->func) (twc->data1);
 20 }
 21 
 22 static void button_cmnd(Tw_callback * twc)
 23 {
 24     tw_set_tool(twc->tool);
 25     (*twc->func) (twc->data1);
 26 }
 27 
 28 static void button_prnt(FILE * fp, Tw_callback * twc)
 29 {
 30     (void) fprintf(fp, "%s\n", twc->name);
 31 }
 32 
 33 int   tw_button(char *name, void (*func) ( /* ??? */ ), void *data)
 34 {
 35     XmString xmstring;
 36     int     nargs;
 37     Arg     wargs[1];
 38     int     w, h;
 39     Tw_callback *twc;
 40     Widget  panel = tw_get_panel(), button;
 41     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
 42 
 43     nargs = 0;
 44     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
 45     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
 46     nargs++;
 47     button = XtCreateManagedWidget("twbutton", xmPushButtonWidgetClass,
 48                                    panel, wargs, nargs);
 49     XmStringFree(xmstring);
 50 
 51     twc = tw_callback_make(fullname, tw_get_tool(), button,
 52     button_call, button_cmnd, button_prnt, func, (void *) data, NULL);
 53     XtAddCallback(button, XmNactivateCallback, (void *) tw_callback, (XtPointer) twc);
 54 
 55     w = tw_charwidth(2.0 + strlen(name));
 56     h = tw_charheight(2.0);
 57     tw_set_entry(button, w, h);
 58     return (int)xmstring;
 59 }
 60 
 61 Widget tw_icon_button(char *name, int w, int h,char *image_bits,
 62                        void (*func) ( /* ??? */ ), int data)
 63 
 64 {
 65     int     row;
 66     Pixel foreground,background;
 67     Arg     wargs[4];
 68     Tw_callback *twc;
 69     Widget  panel = tw_get_panel(), button;
 70     Pixmap pix;
 71     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
 72     Display *display=tw_get_display();
 73     int screen=DefaultScreen(display);
 74     int depth=DefaultDepth(display,screen);
 75     Drawable window=DefaultRootWindow(display);
 76 
 77     button=XtCreateManagedWidget("twiconbutton", xmPushButtonWidgetClass,
 78                                  panel, wargs, 0);
 79     XtSetArg(wargs[0],XmNforeground,&foreground);
 80     XtSetArg(wargs[1],XmNbackground,&background);
 81     XtGetValues(button,wargs,2);
 82 
 83     pix=XCreatePixmapFromBitmapData(display,window,image_bits,w,h,
 84                                     foreground,background,depth);
 85     XtSetArg(wargs[0], XmNlabelPixmap, pix);
 86     XtSetArg(wargs[1],XmNlabelType,XmPIXMAP);
 87     XtSetValues(button,wargs,2);
 88 
 89     twc = tw_callback_make(fullname, tw_get_tool(), button,
 90                            button_call, button_cmnd, button_prnt, 
 91                            func, (void *) data, NULL);
 92     XtAddCallback(button, XmNactivateCallback, (void *) tw_callback, (XtPointer) twc);
 93 
 94     tw_set_entry(button, w+10, h+10);
 95     return button;
 96 }
 97 
 98 void tw_button_reset_image(Widget button,int w, int h,
 99                            char *image_bits)
100 {
101   Pixel foreground,background;
102   Pixmap pix;
103   Arg wargs[4];
104   Display *display=tw_get_display();
105   int screen=DefaultScreen(display);
106   int depth=DefaultDepth(display,screen);
107   Drawable window=DefaultRootWindow(display);
108   
109   XtSetArg(wargs[0],XmNforeground,&foreground);
110   XtSetArg(wargs[1],XmNbackground,&background);
111   XtGetValues(button,wargs,2);
112   pix=XCreatePixmapFromBitmapData(display,window,image_bits,w,h,
113                                   foreground,background,depth);
114   XtSetArg(wargs[0], XmNlabelPixmap, pix);
115   XtSetArg(wargs[1],XmNlabelType,XmPIXMAP);
116   XtSetValues(button,wargs,2);
117 
118 }
119 static void interrupt_calc_proc(void)
120 {
121     format("Nothing to interrupt.\n");
122 }
123 
124 /* Add a 'interrupt' button to abandon lengthy processing. */
125 void    tw_interrupt_button(void)
126 {
127     XmString xmstring;
128     int     nargs;
129     Arg     wargs[1];
130     int     w, h;
131     Widget  panel = tw_get_panel();
132     static char name[] = "Interrupt";
133 
134     /* global static     Widget          interrupt_button; */
135     static Bool first_time = true;
136 
137     if (first_time)
138     {
139         first_time = false;
140 
141         nargs = 0;
142         xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
143         XtSetArg(wargs[nargs], XmNlabelString, xmstring);
144         nargs++;
145         interrupt_button = XtCreateManagedWidget("twbutton", xmPushButtonWidgetClass,
146                                                  panel, wargs, nargs);
147         XmStringFree(xmstring);
148 
149         XtAddCallback(interrupt_button, XmNactivateCallback, interrupt_calc_proc,
150                       (XtPointer) NULL);
151 
152         w = tw_charwidth(3.0 + strlen(name));
153         h = tw_charheight(2.0);
154         tw_set_entry(interrupt_button, w, h);
155     } else
156     {
157         (void) fprintf(stderr, "Only one tw_interrupt_button allowed.\n");
158     }
159 
160 }
161 
162 void    interrupt_button_data_get(Display ** display, Window * window)
163 {
164     *display = XtDisplay(interrupt_button);
165     *window = XtWindow(interrupt_button);
166 }
167 

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