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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/xv/wdgtsXv_tw_menubar.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/xv/wdgtsXv_tw_menubar.c,v $
 37  * Date    :  $Date: 2007/03/21 12:47:02 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: wdgtsXv_tw_menubar.c,v 1.6 2007/03/21 12:47:02 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "wdgtsXv_tw_menubar.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #   include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 
 56 #if !HAVE_STDARG_H
 57   error Xview demands stdarg.h
 58 #else
 59   #include <stdarg.h>
 60 #endif /* !HAVE_STDARG_H */
 61 
 62 #ifndef va_copy
 63 # ifdef __va_copy
 64 #  define va_copy(DEST,SRC) __va_copy((DEST),(SRC))
 65 # endif
 66 #endif
 67 
 68 #include <xview/panel.h>
 69 #include <xview/openmenu.h>
 70 #include <xview/frame.h>
 71 #include <xview/generic.h>
 72 
 73 #include <tina/sys/sysDef.h>
 74 #include <tina/sys/sysPro.h>
 75 #include <tinatool/wdgts/xv/wdgts_XvDef.h>
 76 #include <tinatool/wdgts/xv/wdgtsXv_tw_tool.h>
 77 #include <tinatool/wdgts/xv/wdgtsXv_tw_command.h>
 78 #include <tinatool/wdgts/xv/wdgtsXv_tw_label.h>
 79 
 80 static void menu_call(Tw_callback * twc)
 81 {
 82     (*twc->func) (twc->data1);
 83 }
 84 
 85 static void menu_cmnd(Tw_callback * twc)
 86 {
 87     (*twc->func) (twc->data1);
 88 }
 89 
 90 static void menu_prnt(FILE * fp, Tw_callback * twc)
 91 {
 92     (void) fprintf(fp, "%s\n", twc->name);
 93 }
 94 
 95 void    tw_submenu_add(char *menubarname, char *name, va_list *ptr)
 96 {
 97     Tw_callback **twc;
 98     va_list va;
 99     Panel_item button;
100     Bool    tw_get_newrow();
101     Panel   panel, tw_get_panel();
102     Frame   tool, tw_get_tool();
103     Menu    menu;
104     int     i, n;
105     char   *menuname = tw_extend_fullname(menubarname, name);
106 
107     /* count no of menu items and allocate callbacks */
108 
109     #ifdef va_copy
110         va_copy(va, *ptr);
111         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
112         {
113           va_arg(*ptr, void *);
114           va_arg(*ptr, void *);
115         }
116     #else
117         va = *ptr;
118         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
119         {
120          va_arg(*ptr, void *);
121          va_arg(*ptr, void *);
122         }
123     #endif
124     
125     /* allocate callbacks for each menu item */
126     twc = (Tw_callback **) ralloc((unsigned) n * sizeof(Tw_callback *));
127 
128     panel = tw_get_panel();
129     tool = tw_get_tool();
130 
131     /* add button to call menu */
132 
133     menu = xv_create((int)NULL, MENU_CHOICE_MENU, NULL);
134     button = xv_create(panel, PANEL_BUTTON,
135                        PANEL_LABEL_STRING, name,
136                        PANEL_ITEM_MENU, menu,
137                        NULL);
138 
139     for (i = 0; i < n; i++)
140     {
141         Menu_item mi;
142         char   *item_name = va_arg(va, char *);
143         void    (*func) () = (void (*) ()) va_arg(va, void *);
144         void   *data = va_arg(va, void *);
145         char   *fullname;
146 
147         fullname = tw_extend_fullname(menubarname, item_name);
148 
149         /* read name off arglist */
150         mi = (Menu_item) xv_create((int)NULL, MENUITEM,
151                                    MENU_STRING, item_name,
152                                    MENU_VALUE, i,
153                                    MENU_NOTIFY_PROC, tw_menu_callback,  /* for pin up */
154                                    NULL);
155         xv_set(menu, MENU_APPEND_ITEM, mi, NULL);
156 
157         twc[i] = tw_callback_make(fullname, mi,
158                    menu_call, menu_cmnd, menu_prnt, func, data, NULL);
159     }
160     #ifdef va_copy
161        va_end(va);
162     #endif 
163 
164     xv_set(menu,
165            MENU_GEN_PIN_WINDOW, tool, "",
166            MENU_NOTIFY_PROC, tw_menu_callback,
167            MENU_CLIENT_DATA, twc,
168            NULL);
169 
170     if (tw_get_newrow())
171     {
172         xv_set(button,
173                XV_X, xv_col(panel, 0),
174                XV_Y, xv_row(panel, tw_get_row()),
175                NULL);
176         tw_set_newrow(false);
177     }
178     rfree((void *) menuname);
179 }
180 
181 
182 void tw_menubar(char *name,...)
183 {
184     va_list ap;
185     char   *menubarname;
186     Panel   panel = tw_get_panel();
187     int     gap;
188 
189     va_start(ap, name);
190 
191     if (name != NULL)
192         (void) tw_label(name);
193     menubarname = tw_extend_fullname(tw_get_toolname(), name);
194 
195     gap = (int) xv_get(panel, PANEL_ITEM_X_GAP);
196     xv_set(panel, PANEL_ITEM_X_GAP, 2, NULL);
197 
198     while ((name = va_arg(ap, char *)) != NULL)
199         tw_submenu_add(menubarname, name, &ap);
200     va_end(ap);
201 
202     xv_set(panel, PANEL_ITEM_X_GAP, gap, NULL);
203 
204     rfree((void *) menubarname);
205 }
206 
207 

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