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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_button.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_button.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsXm_tw_button.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "wdgtsXm_tw_button.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #   include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <math.h>
 56 
 57 #include <Xm/PushB.h>
 58 
 59 #include <tinatool/wdgts/xm/wdgts_XmDef.h>
 60 #include <tinatool/wdgts/xm/wdgtsXm_tw_tool.h>
 61 #include <tinatool/wdgts/xm/wdgtsXm_tw_command.h>
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/math/mathDef.h>
 64 #include <tinatool/gphx/gphxDef.h>
 65 #include <tinatool/gphx/gphxPro.h>
 66 #include <tinatool/wdgts/xm/wdgtsXm_tw_init.h>
 67 
 68 /* STATICS */
 69 static Widget interrupt_button = None;
 70 
 71 static void button_call(Tw_callback * twc)
 72 {
 73     tw_set_tool(twc->tool);
 74     (*twc->func) (twc->data1);
 75 }
 76 
 77 static void button_cmnd(Tw_callback * twc)
 78 {
 79     tw_set_tool(twc->tool);
 80     (*twc->func) (twc->data1);
 81 }
 82 
 83 static void button_prnt(FILE * fp, Tw_callback * twc)
 84 {
 85     (void) fprintf(fp, "%s\n", twc->name);
 86 }
 87 
 88 int   tw_button(char *name, void (*func) ( /* ??? */ ), void *data)
 89 {
 90     XmString xmstring;
 91     int     nargs;
 92     Arg     wargs[1];
 93     int     w, h;
 94     Tw_callback *twc;
 95     Widget  panel = tw_get_panel(), button;
 96     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
 97 
 98     nargs = 0;
 99     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
100     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
101     nargs++;
102     button = XtCreateManagedWidget("twbutton", xmPushButtonWidgetClass,
103                                    panel, wargs, nargs);
104     XmStringFree(xmstring);
105 
106     twc = tw_callback_make(fullname, tw_get_tool(), button,
107     button_call, button_cmnd, button_prnt, func, (void *) data, NULL);
108     /* warning: argument #3 is incompatible with prototype:
109         prototype: pointer to function(pointer to struct _WidgetRec {}, pointer to void, pointer to void) returning void : "/usr/include/X11/Intrinsic.h", line 1528
110         argument : pointer to void */
111     XtAddCallback(button, XmNactivateCallback, (void *) tw_callback, (XtPointer) twc);
112 
113     w = tw_charwidth(2.0 + strlen(name));
114     h = tw_charheight(2.0);
115     tw_set_entry(button, w, h);
116     return (int)xmstring;
117 }
118 
119 Widget tw_icon_button(char *name, int w, int h,char *image_bits,
120                        void (*func) ( /* ??? */ ), int data)
121 
122 {
123     int     row;
124     Pixel foreground,background;
125     Arg     wargs[4];
126     Tw_callback *twc;
127     Widget  panel = tw_get_panel(), button;
128     Pixmap pix;
129     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
130     Display *display=tw_get_display();
131     int screen=DefaultScreen(display);
132     int depth=DefaultDepth(display,screen);
133     Drawable window=DefaultRootWindow(display);
134 
135     button=XtCreateManagedWidget("twiconbutton", xmPushButtonWidgetClass,
136                                  panel, wargs, 0);
137     XtSetArg(wargs[0],XmNforeground,&foreground);
138     XtSetArg(wargs[1],XmNbackground,&background);
139     XtGetValues(button,wargs,2);
140 
141     pix=XCreatePixmapFromBitmapData(display,window,image_bits,w,h,
142                                     foreground,background,depth);
143     XtSetArg(wargs[0], XmNlabelPixmap, pix);
144     XtSetArg(wargs[1],XmNlabelType,XmPIXMAP);
145     XtSetValues(button,wargs,2);
146 
147     twc = tw_callback_make(fullname, tw_get_tool(), button,
148                            button_call, button_cmnd, button_prnt, 
149                            func, (void *) data, NULL);
150     /* warning: argument #3 is incompatible with prototype:
151         prototype: pointer to function(pointer to struct _WidgetRec {}, pointer to void, pointer to void) returning void : "/usr/include/X11/Intrinsic.h", line 1528
152         argument : pointer to void */
153     XtAddCallback(button, XmNactivateCallback, (void *) tw_callback, (XtPointer) twc);
154 
155     tw_set_entry(button, w+10, h+10);
156     return button;
157 }
158 
159 void tw_button_reset_image(Widget button,int w, int h,
160                            char *image_bits)
161 {
162   Pixel foreground,background;
163   Pixmap pix;
164   Arg wargs[4];
165   Display *display=tw_get_display();
166   int screen=DefaultScreen(display);
167   int depth=DefaultDepth(display,screen);
168   Drawable window=DefaultRootWindow(display);
169   
170   XtSetArg(wargs[0],XmNforeground,&foreground);
171   XtSetArg(wargs[1],XmNbackground,&background);
172   XtGetValues(button,wargs,2);
173   pix=XCreatePixmapFromBitmapData(display,window,image_bits,w,h,
174                                   foreground,background,depth);
175   XtSetArg(wargs[0], XmNlabelPixmap, pix);
176   XtSetArg(wargs[1],XmNlabelType,XmPIXMAP);
177   XtSetValues(button,wargs,2);
178 
179 }
180 static void interrupt_calc_proc(void)
181 {
182     format("Nothing to interrupt.\n");
183 }
184 
185 /* Add a 'interrupt' button to abandon lengthy processing. */
186 void    tw_interrupt_button(void)
187 {
188     XmString xmstring;
189     int     nargs;
190     Arg     wargs[1];
191     int     w, h;
192     Widget  panel = tw_get_panel();
193     static char name[] = "Interrupt";
194 
195     /* global static     Widget          interrupt_button; */
196     static Bool first_time = true;
197 
198     if (first_time)
199     {
200         first_time = false;
201 
202         nargs = 0;
203         xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
204         XtSetArg(wargs[nargs], XmNlabelString, xmstring);
205         nargs++;
206         interrupt_button = XtCreateManagedWidget("twbutton", xmPushButtonWidgetClass,
207                                                  panel, wargs, nargs);
208         XmStringFree(xmstring);
209 
210         /* warning: passing argument 3 of 'XtAddCallback' from incompatible pointer type */
211         XtAddCallback(interrupt_button, XmNactivateCallback, interrupt_calc_proc,
212                       (XtPointer) NULL);
213 
214         w = tw_charwidth(3.0 + strlen(name));
215         h = tw_charheight(2.0);
216         tw_set_entry(interrupt_button, w, h);
217     } else
218     {
219         (void) fprintf(stderr, "Only one tw_interrupt_button allowed.\n");
220     }
221 
222 }
223 
224 void    interrupt_button_data_get(Display ** display, Window * window)
225 {
226     *display = XtDisplay(interrupt_button);
227     *window = XtWindow(interrupt_button);
228 }
229 

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