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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_choice.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_choice.c,v $
 37  * Date    :  $Date: 2009/03/25 13:37:03 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: wdgtsXm_tw_choice.c,v 1.4 2009/03/25 13:37:03 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "wdgtsXm_tw_choice.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #   include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #if !HAVE_STDARG_H
 56   error Motif demands stdarg.h
 57 #else
 58 #  include <stdarg.h>
 59 #endif
 60 
 61 #include <Xm/Label.h>
 62 #include <Xm/ToggleB.h>
 63 #include <Xm/RowColumn.h>
 64         
 65 #include <tina/sys/sysDef.h>
 66 #include <tina/sys/sysLst_list.h>
 67 #include <tinatool/wdgts/xm/wdgts_XmDef.h>
 68 #include <tinatool/wdgts/xm/wdgtsXm_tw_tool.h>
 69 #include <tinatool/wdgts/xm/wdgtsXm_tw_command.h>
 70 #include <tina/sys/sysMem_ralloc.h>
 71 
 72 static char *choicename;
 73 
 74 
 75 void tw_choice_list_style_select(int style)
 76 {
 77   /* Required for GTK: not used in other widget sets */
 78 }
 79 
 80 
 81 static void choice_call(Tw_callback * twc)
 82 {
 83     int     pos = (int) twc->data1;
 84 
 85     (*twc->func) (pos);
 86 }
 87 
 88 static void choice_cmnd(Tw_callback * twc, char *args)
 89 {
 90     int     pos;
 91     int     nargs;
 92     Arg     wargs[1];
 93 
 94     (void) sscanf(args, "%*s %d", &pos);
 95     twc->data1 = (void *) pos;
 96     (*twc->func) (pos);
 97 
 98     nargs = 0;
 99     XtSetArg(wargs[nargs], XmNset, True);
100     nargs++;
101     XtSetValues(twc->widget, wargs, nargs);
102 }
103 
104 static void choice_prnt(FILE * fp, Tw_callback * twc)
105 {
106     (void) fprintf(fp, "%s %d\n", twc->name, (int) twc->data1);
107 }
108 
109 static Widget tw_choice_label(char *name)
110 {
111     Widget  panel = tw_get_panel();
112     Widget  label;
113     XmString xmstring;
114     int     nargs;
115     Arg     wargs[1];
116 
117     label = XtCreateManagedWidget("twlabel", xmLabelWidgetClass,
118                                   panel, (ArgList) NULL, 0);
119     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
120     nargs = 0;
121     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
122     nargs++;
123     XtSetValues(label, wargs, nargs);
124     XmStringFree(xmstring);
125     return (label);
126 }
127 
128 static void *tw_choice_add(Widget box, char *name, void (*func) ( /* ??? */ ), int pos, int *value, double *width)
129 {
130     XmString xmstring;
131     int     nargs;
132     Arg     wargs[3];
133     Tw_callback *twc;
134     Widget  button;
135     char   *fullname = tw_extend_fullname(choicename, name);
136 
137     nargs = 0;
138     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
139     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
140     nargs++;
141     if (pos == *value)
142     {
143         XtSetArg(wargs[nargs], XmNset, True);
144         nargs++;
145     }
146     button = XtCreateManagedWidget("twtoggle", xmToggleButtonWidgetClass,
147                                    box, wargs, nargs);
148     XmStringFree(xmstring);
149 
150     twc = tw_callback_make(fullname, tw_get_tool(), button,
151                            choice_call, choice_cmnd, choice_prnt, func, (void *) pos, (void *) value);
152     /* warning: argument #3 is incompatible with prototype:
153         prototype: pointer to function(pointer to struct _WidgetRec {}, pointer to void, pointer to void) returning void : "/usr/include/X11/Intrinsic.h", line 1528
154         argument : pointer to void */
155     XtAddCallback(button, XmNvalueChangedCallback, (void *) tw_callback, (XtPointer) twc);
156 
157     *width += strlen(name) + 4.0;
158     return(twc);
159 }
160 
161 void *tw_choice(char *name, ...)
162 {
163     va_list ap;
164     int     nargs;
165     Arg     wargs[10];
166     Widget  label, choice, panel = tw_get_panel();
167     void    (*func) ();
168     int     i, w, h, *value;
169     double  width;
170     List *twlist = NULL, *lptr;
171     Tw_callback *twc;
172 
173     nargs = 0;
174     XtSetArg(wargs[nargs], XmNentryClass, xmToggleButtonWidgetClass);
175     nargs++;
176     XtSetArg(wargs[nargs], XmNorientation, XmHORIZONTAL);
177     nargs++;
178     choice = XmCreateRadioBox(panel, "twchoice", wargs, nargs);
179 
180     va_start(ap, name);
181 
182     label = tw_choice_label(name);
183 
184     choicename = tw_extend_fullname(tw_get_toolname(), name);
185 
186     w = tw_charwidth(2.0 + strlen(name));
187     h = tw_charheight(1.5);
188     tw_set_entry(label, w, h);
189 
190     func = (void (*) ()) va_arg(ap, void *);
191     width = 0.0;
192     value = (int *) ralloc(sizeof(int));
193     *value = va_arg(ap, int);
194     for (i = 0; (name = va_arg(ap, char *)) != NULL; i++)
195     {
196         void *twc = tw_choice_add(choice, name, func, i, value, &width);
197         twlist = ref_addtostart(twlist, twc, 0);
198     }
199     twlist = list_reverse(twlist);
200     va_end(ap);
201     XtManageChild(choice);
202 
203     w = tw_charwidth(width);
204     h = tw_charheight(2.5);
205     tw_set_entry(choice, w, h);
206 
207     /** initialise choice **/
208     (*func) (*value);
209     for(lptr = twlist, i = 0; lptr != NULL; lptr = lptr->next, i++)
210     {
211         twc = lptr->to;
212         nargs = 0;
213         XtSetArg(wargs[nargs], XmNset, (i == *value)? True: False);
214         nargs++;
215         XtSetValues(twc->widget, wargs, nargs);
216     }
217 
218     rfree((void *) choicename);
219     return(twlist);
220 }
221 
222 void tw_choice_reset(void *ptr, int val)
223 {
224     List *twlist = ptr, *lptr;
225     Tw_callback *twc;
226     int     nargs, i;
227     Arg     wargs[1];
228     for(lptr = twlist, i = 0; lptr != NULL; lptr = lptr->next, i++)
229     {
230         twc = lptr->to;
231         nargs = 0;
232         XtSetArg(wargs[nargs], XmNset, (i == val)? True: False);
233         nargs++;
234         XtSetValues(twc->widget, wargs, nargs);
235     }
236 }
237 

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