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

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/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/gtk2/wdgtsGtk_tw_menubar.c,v $
 37  * Date    :  $Date: 2009/05/13 15:38:15 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_menubar.c,v 1.5 2009/05/13 15:38:15 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 #include <string.h>
 68 
 69 #if !HAVE_STDARG_H
 70   error GTK demands stdarg.h
 71 #else
 72   #include <stdarg.h>
 73 #endif /* !HAVE_STDARG_H */
 74 
 75 #ifndef va_copy
 76 # ifdef __va_copy
 77 #  define va_copy(DEST,SRC) __va_copy((DEST),(SRC))
 78 # endif
 79 #endif
 80 
 81 #include <gtk/gtk.h>
 82 #include <tina/sys/sysPro.h>
 83 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 84 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 85 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 86 
 87 static  GtkWidget  *menubar = NULL;
 88 
 89 
 90 /**
 91  * @brief  Invoke menu item function.  
 92  * @param  twc  Pointer to Tw_callback associated with this menu item.
 93  */
 94 static void menu_call(Tw_callback * twc)
 95 {
 96     (*twc->func) (twc->data1);
 97 }
 98 
 99 /**
100  * @brief  Replay menu selection from current macro file.  
101  * @param  twc  Pointer to Tw_callback associated with this menu item.
102  */
103 static void menu_cmnd(Tw_callback * twc)
104 {
105     (*twc->func) (twc->data1);
106 }
107 
108 /**
109  * @brief  Record menu item selection in current macro file.  
110  * @param  fp   Pointer to current macro file.
111  * @param  twc  Pointer to Tw_callback associated with this menu item.
112  */
113 static void menu_prnt(FILE * fp, Tw_callback * twc)
114 {
115     (void) fprintf(fp, "%s\n", twc->name);
116 }
117 
118 
119 /**
120  * @brief  Create GTK menu items and add to the current menubar.  
121  * @param  menubarname  String to be used as menubar identifier and label.
122  * @param  name         String to be used as name of current menu.
123  * @param  ptr          Pointer to varargs list passed to caller.
124  * 
125  * Creates new menu and packs in menubar hbox. Creates the set of menu items for
126  * this menu and and packs them in the menu.  Creates the Tw_callback for each
127  * menu item and registers it.
128  *
129  * Invokes callback for each menu selection, via call to tw_button_callback 
130  * (in wdgtsGtk_tw_command.c).
131  *
132  */
133 static void tw_submenu_add(char *menubarname, char *name, va_list *ptr)
134 {
135   va_list va;
136   char *undscrname=NULL;
137   GtkWidget  *menubox = tw_get_menubox();
138   GtkWidget  *menu;
139   GtkWidget  *menu_item;
140 
141   char *menuname = tw_extend_fullname(menubarname, name);
142   int   n;
143   int   i;
144 
145   #ifdef va_copy
146         va_copy(va, *ptr);
147         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
148         {
149           va_arg(*ptr, void *);
150           va_arg(*ptr, void *);
151         }
152   #else
153         va = *ptr;
154         for (n = 0; va_arg(*ptr, char *) !=NULL; n++)
155         {
156          va_arg(*ptr, void *);
157          va_arg(*ptr, void *);
158         }
159   #endif
160 
161   menu = gtk_menu_new();
162   gtk_widget_show(menu);
163 
164   /**
165    * Create a menu, append it to the menubar and define it as a menu heading.
166    * The last action causes automatic drop-down when the menu heading is clicked.
167    */
168 
169 
170   undscrname = string_alloc_append("_", name, NULL);
171   menu_item = gtk_menu_item_new_with_mnemonic(undscrname);
172   gtk_widget_show(menu_item);
173   gtk_menu_bar_append(GTK_MENU_BAR(menubar), menu_item);
174   gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu);
175 
176   /** Create and attach menu items ... */
177   for (i = 0; i < n; i++)
178   {
179     Tw_callback *twc;
180 
181     char   *item_name =  va_arg(va, char *);
182     void  (*func)()   = (void(*)()) va_arg(va, void *);
183     void   *data      =  va_arg(va, void *);
184 
185     char   *fullname  =  tw_extend_fullname(menubarname, item_name);
186 
187     menu_item = gtk_menu_item_new_with_label(item_name);
188     gtk_menu_append(GTK_MENU(menu), menu_item);
189     gtk_widget_show(menu_item);
190 
191     /* Make and attach callback ... */
192     twc = tw_callback_make(fullname, menu_item,
193                            menu_call, menu_cmnd, menu_prnt, func, 
194                            data, NULL);
195 
196     gtk_signal_connect(GTK_OBJECT(menu_item), "activate", 
197                        GTK_SIGNAL_FUNC(tw_gtk_callback),
198                        (gpointer)twc);
199     
200   }
201   #ifdef va_copy
202        va_end(va);
203   #endif 
204 }
205 
206 
207 /**
208  * @brief  Create new GTK menubar and add its menus.  
209  * @param  name  String to be used as menubar identifier and label.
210  * @param  args...  Vararg list of parameters.
211  * 
212  * Creates new menubar and packs in the menus and menu items specified in
213  * the varargs parameter list.  
214  *
215  * The parameter list must have the following items, in the order shown:
216  * string name (for menubar),
217  * ... then for each menu ... 
218  * string name (for each menu in menubar),
219  * ... then for each menu item ... 
220  * string name (for each menu item in menu),
221  * pointer to callback function,
222  * pointer to data for callback function,
223  * ...
224  * NULL to terminate list of menu items,
225  * ...
226  * NULL to terminate list of menus. 
227  * (Look in e.g. tv_tool_remote() in tlbaseDisp_tool.c for an example.)
228  *
229  */
230 void tw_menubar(char *name, ...)
231 {
232   va_list     ap;
233 
234   GtkWidget  *menubox = tw_get_menubox();
235   GtkWidget  *label;
236   char       *menubarname, *name_for_label=NULL;
237 
238   va_start(ap, name);
239 
240   if (strcmp(name, "") != 0)
241   {
242     name_for_label = string_alloc_append("<i>", name, "</i>", NULL);
243     label = gtk_label_new (NULL);
244     gtk_label_set_markup (GTK_LABEL (label), name_for_label);
245 
246     /* Old style: label = gtk_label_new(name); */
247     gtk_widget_show(label);
248     gtk_box_pack_start(GTK_BOX(menubox), label, FALSE, FALSE, 0);
249   }
250 
251   /** Each call generates a new GTK menubar in the tool's static menu hbox */
252 
253   menubarname = tw_extend_fullname(tw_get_toolname(), name);
254   menubar     = gtk_menu_bar_new();
255   gtk_widget_show(menubar);
256   gtk_box_pack_start(GTK_BOX(menubox), menubar, FALSE, FALSE, 0);
257 
258 
259   /** Now process the varargs list to generate menus and menu items */
260   while ((name = va_arg(ap, char *)) != NULL)
261     tw_submenu_add(menubarname, name, &ap);
262 
263   va_end(ap);
264 }
265 

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