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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/gtk/wdgtsGtk_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/gtk/wdgtsGtk_tw_menubar.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_menubar.c,v 1.5 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  giob@man.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  wdgtsGtk_tw_menubar.c
 47  *  @brief Define and create GTK menus and their associated callbacks.
 48  *
 49  *  This makes use of the static hbox menubox (in wdgtsGtk_tw_tool.c) and a local
 50  *  static menubar.  The menubox associated with the tool ensures that all menus 
 51  *  appear at the top of the tool window, the local menubar creates a new menubar for
 52  *  each call to tw_menubar().  This is not (at all) good practice in GTK, but it is
 53  *  compatible with Tina's Xv past, which dictates how tools are assembled with user
 54  *  function calls.
 55  *
 56  *  Note that the functions in this file are duplicated for each widget set 
 57  *  (xv, GTK, xm, etc ...).
 58  */
 59 
 60 #include "wdgtsGtk_tw_menubar.h"
 61 
 62 #if HAVE_CONFIG_H
 63 #   include <config.h>
 64 #endif
 65 
 66 #include <stdio.h>
 67 
 68 #if !HAVE_STDARG_H
 69   error GTK demands stdarg.h
 70 #else
 71   #include <stdarg.h>
 72 #endif /* !HAVE_STDARG_H */
 73 
 74 #ifndef va_copy
 75 # ifdef __va_copy
 76 #  define va_copy(DEST,SRC) __va_copy((DEST),(SRC))
 77 # endif
 78 #endif
 79 
 80 #include <gtk/gtk.h>
 81 #include <tinatool/wdgts/gtk/wdgts_GtkDef.h>
 82 #include <tinatool/wdgts/gtk/wdgtsGtk_tw_command.h>
 83 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 84 
 85 static  GtkWidget  *menubar = NULL;
 86 
 87 
 88 /**
 89  * @brief  Invoke menu item function.  
 90  * @param  twc  Pointer to Tw_callback associated with this menu item.
 91  */
 92 static void menu_call(Tw_callback * twc)
 93 {
 94     (*twc->func) (twc->data1);
 95 }
 96 
 97 /**
 98  * @brief  Replay menu selection from current macro file.  
 99  * @param  twc  Pointer to Tw_callback associated with this menu item.
100  */
101 static void menu_cmnd(Tw_callback * twc)
102 {
103     (*twc->func) (twc->data1);
104 }
105 
106 /**
107  * @brief  Record menu item selection in current macro file.  
108  * @param  fp   Pointer to current macro file.
109  * @param  twc  Pointer to Tw_callback associated with this menu item.
110  */
111 static void menu_prnt(FILE * fp, Tw_callback * twc)
112 {
113     (void) fprintf(fp, "%s\n", twc->name);
114 }
115 
116 
117 /**
118  * @brief  Create GTK menu items and add to the current menubar.  
119  * @param  menubarname  String to be used as menubar identifier and label.
120  * @param  name         String to be used as name of current menu.
121  * @param  ptr          Pointer to varargs list passed to caller.
122  * 
123  * Creates new menu and packs in menubar hbox. Creates the set of menu items for
124  * this menu and and packs them in the menu.  Creates the Tw_callback for each
125  * menu item and registers it.
126  *
127  * Invokes callback for each menu selection, via call to tw_button_callback 
128  * (in wdgtsGtk_tw_command.c).
129  *
130  */
131  
132 static void tw_submenu_add(char *menubarname, char *name, va_list *ptr)
133 {
134   va_list va;
135   GtkWidget  *menubox = tw_get_menubox();
136   GtkWidget  *menu;
137   GtkWidget  *menu_item;
138 
139   char *menuname = tw_extend_fullname(menubarname, name);
140   int   n;
141   int   i;
142 
143   #ifdef va_copy
144         va_copy(va, *ptr);
145         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
146         {
147           va_arg(*ptr, void *);
148           va_arg(*ptr, void *);
149         }
150   #else
151         va = *ptr;
152         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
153         {
154          va_arg(*ptr, void *);
155          va_arg(*ptr, void *);
156         }
157   #endif
158 
159   menu = gtk_menu_new();
160   gtk_widget_show(menu);
161 
162   /**
163    * Create a menu, append it to the menubar and define it as a menu heading.
164    * The last action causes automatic drop-down when the menu heading is clicked.
165    */
166   menu_item = gtk_menu_item_new_with_label(name);
167   gtk_widget_show(menu_item);
168   gtk_menu_bar_append(GTK_MENU_BAR(menubar), menu_item);
169   gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu);
170 
171   /** Create and attach menu items ... */
172   for (i = 0; i < n; i++)
173   {
174     Tw_callback *twc;
175 
176     char   *item_name =  va_arg(va, char *);
177     void  (*func)()   = (void(*)()) va_arg(va, void *);
178     void   *data      =  va_arg(va, void *);
179 
180     char   *fullname  =  tw_extend_fullname(menubarname, item_name);
181 
182     menu_item = gtk_menu_item_new_with_label(item_name);
183     gtk_menu_append(GTK_MENU(menu), menu_item);
184     gtk_widget_show(menu_item);
185 
186     /* Make and attach callback ... */
187     twc = tw_callback_make(fullname, menu_item,
188                            menu_call, menu_cmnd, menu_prnt, func, 
189                            data, NULL);
190 
191     gtk_signal_connect(GTK_OBJECT(menu_item), "activate", 
192                        GTK_SIGNAL_FUNC(tw_gtk_callback),
193                        (gpointer)twc);
194     
195   }
196   #ifdef va_copy
197        va_end(va);
198   #endif 
199 }
200 
201 
202 /**
203  * @brief  Create new GTK menubar and add its menus.  
204  * @param  name  String to be used as menubar identifier and label.
205  * @param  args...  Vararg list of parameters.
206  * 
207  * Creates new menubar and packs in the menus and menu items specified in
208  * the varargs parameter list.  
209  *
210  * The parameter list must have the following items, in the order shown:
211  * string name (for menubar),
212  * ... then for each menu ... 
213  * string name (for each menu in menubar),
214  * ... then for each menu item ... 
215  * string name (for each menu item in menu),
216  * pointer to callback function,
217  * pointer to data for callback function,
218  * ...
219  * NULL to terminate list of menu items,
220  * ...
221  * NULL to terminate list of menus. 
222  * (Look in e.g. tv_tool_remote() in tlbaseDisp_tool.c for an example.)
223  *
224  */
225 void tw_menubar(char *name, ...)
226 {
227   va_list     ap;
228 
229   GtkWidget  *menubox = tw_get_menubox();
230   GtkWidget  *label;
231 
232   char       *menubarname;
233 
234   va_start(ap, name);
235 
236   if (strcmp(name, "") != 0)
237   {
238     label = gtk_label_new(name);
239     gtk_widget_show(label);
240     gtk_box_pack_start(GTK_BOX(menubox), label, FALSE, FALSE, 0);
241   }
242 
243   /** Each call generates a new GTK menubar in the tool's static menu hbox */
244   menubarname = tw_extend_fullname(tw_get_toolname(), name);
245   menubar     = gtk_menu_bar_new();
246   gtk_widget_show(menubar);
247   gtk_box_pack_start(GTK_BOX(menubox), menubar, FALSE, FALSE, 0);
248 
249   /** Now process the varargs list to generate menus and menu items */
250   while ((name = va_arg(ap, char *)) != NULL)
251     tw_submenu_add(menubarname, name, &ap);
252 
253   va_end(ap);
254 }
255 

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