Back to index

plt-scheme  4.2.1
Menu.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: simple menu class
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifndef Menu_h
00028 #define Menu_h
00029 
00030 #ifdef __GNUG__
00031 #pragma interface
00032 #endif
00033 
00034 #if defined(Have_Xt_Types)
00035 class wxMenu_Widgets : public gc {
00036 public:
00037     Widget shell;
00038     Widget menu;
00039 };
00040 #else
00041 class wxMenu_Widgets;
00042 #endif
00043 
00044 class wxCommandEvent;
00045 class wxColour;
00046 class wxFont;
00047 
00048 typedef void (*wxFunction)(wxObject*, wxCommandEvent*);
00049 
00050 typedef void *wxMenuItem;
00051 
00052 class wxMenu : public wxObject {
00053 public:
00054     wxMenu(char *title=NULL, wxFunction func=NULL, wxFont *_font = NULL);
00055     ~wxMenu(void);
00056 
00057     // popup menu (used by wxWindow);
00058 #   ifdef Have_Xt_Types
00059     Bool  PopupMenu(Widget in_w, int root_x, int root_y, Bool for_choice = FALSE, int top_extra = 0);
00060 #   endif
00061 
00062     int Number(void);
00063 
00064     // add items to menu
00065     void  Append(long id, char *label, char *help=NULL, Bool checkable=FALSE);
00066     void  Append(long id, char *label, wxMenu *submenu, char *help=NULL);
00067     void  AppendSeparator(void);
00068     Bool  DeleteItem(long id, int pos);
00069     Bool  Delete(long id);
00070     Bool  DeleteByPosition(int pos);
00071     // modify items
00072     void  Break(void) {}; // not supported
00073     void  Check(long id, Bool flag);
00074     Bool  Checked(long id);
00075     void  Enable(long id, Bool flag);
00076     char  *GetHelpString(long id);
00077     char  *GetLabel(long id);
00078     char  *GetTitle(void);
00079     void  SetHelpString(long id, char *help);
00080     void  SetLabel(long id, char *label);
00081     void  SetTitle(char *title);
00082     wxFont *GetFont() { return font; }
00083     // miscellaneous
00084     void  *GetClientData(void) { return client_data; }
00085     void  SetClientData(void *data) { client_data = data; }
00086     // search for item by label
00087     int   FindItem(char *label, int strip = 1);
00088 
00089     void Stop(void);
00090     void Unpop(void);
00091 
00092     void SetWidth(int w);
00093 
00094 private:
00095     // allow callback and menubar access to private data
00096     friend class wxMenuBar;
00097 
00098     wxMenuItem  *FindItemForId(long id, wxMenu **menu=NULL); // search for internal data
00099 #   ifdef Have_Xt_Types
00100     static void EventCallback(Widget, XtPointer, XtPointer);
00101 #   endif
00102 
00103     // necessary for popup menus
00104     wxMenu_Widgets* X;
00105     wxFunction callback;
00106     // font & colours
00107     wxFont*   font;
00108     // internal representation
00109     wxMenuItem* title;             // title, if specified with constructor
00110     wxMenuItem* top;        // first menu item
00111     wxMenuItem* last;              // last menu item for wxMenu::Append
00112     wxMenuItem* topdummy;
00113     wxMenuItem **owner; /* MATTHEW: Pointer to pointer to top */
00114 
00115 #ifdef MZ_PRECISE_GC
00116     wxChildList *children;
00117 #endif
00118 
00119     int requested_width;
00120 
00121     void *client_data;
00122     void **saferefs; /* cons-like chain of saferefs */
00123 };
00124 
00125 extern void wxInitPopupMgr(void);
00126 extern void wxUnpopMenu(void);
00127 
00128 #ifdef MZ_PRECISE_GC
00129 extern char *copystring_xt(const char *s);
00130 # define MALLOC_MENU_ITEM()      (menu_item *)XtMalloc(sizeof(menu_item))
00131 # define FREE_MENU_ITEM(i)       XtFree((char *)i)
00132 # define MAKE_MENU_STRING(s)     copystring_xt(s)
00133 # define FREE_MENU_STRING(s)     XtFree((char *)s)
00134 # define EXTRACT_TOP_MENU(item)  ((wxMenu*)GET_SAFEREF(item->user_data))
00135 # define BUNDLE_TOP_MENU(menu)   GC_malloc_immobile_box(GC_malloc_weak_box(gcOBJ_TO_PTR(menu), NULL, 0))
00136 # define FREE_TOP_POINTER(p)     GC_free_immobile_box((void **)p)
00137 #else
00138 # define MALLOC_MENU_ITEM()      (new WXGC_PTRS menu_item)
00139 # define FREE_MENU_ITEM(i)       /* nothing */
00140 # define MAKE_MENU_STRING(s)     s
00141 # define FREE_MENU_STRING(s)     /* nothing */
00142 # define EXTRACT_TOP_MENU(item)  ((wxMenu*)(item->user_data))
00143 # define BUNDLE_TOP_MENU(menu)   ((void*)menu)
00144 # define FREE_TOP_POINTER(p)     /* nothing */
00145 #endif
00146 
00147 #endif // Menu_h