menu.h

Go to the documentation of this file.
00001 #ifndef MENU_CLASS
00002 #define MENU_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : menu                                                              *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Provides a fairly simplified interface to the window system's menus.     *
00012 *                                                                             *
00013 *******************************************************************************
00014 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00015 * redistribute it and/or modify it under the terms of the GNU General Public  *
00016 * License as published by the Free Software Foundation; either version 2 of   *
00017 * the License or (at your option) any later version.  This is online at:      *
00018 *     http://www.fsf.org/copyleft/gpl.html                                    *
00019 * Please send any updates to: fred@gruntose.com                               *
00020 \*****************************************************************************/
00021 
00022 #include "dll_wp_active.h"
00023 
00024 #include <wp_passive/argument_list.h>
00025 #include <wp_passive/worker.h>
00026 
00027 class wp_menu_item;
00028 
00029 class WP_ACTIVE_CLASS_STYLE menu : public worker
00030 {
00031 public:
00032   menu(manager &parent, const c_point &origin, const char *title,
00033        const color &foreground = colors::WHITE, const color &background = colors::BLACK);
00034     // this constructor creates a menu bar with "title" as the name of the
00035     // application?
00036   ~menu();
00037 
00038   void add(wp_menu_item *to_add);
00039     // puts another top-level menu item on the menu bar.  if that item is
00040     // to have sub-menus and so forth, then the wp_menu_item must be connected
00041     // to another wp_menu_item.
00042 
00043   virtual void draw();
00044 
00045   static void wp_menu_item_callback(window_handle w, wp_menu_item *the_item, caddr_t call_data);
00046     // invoked by motif when the menu is triggered by the user.
00047 
00048 private:
00049   amorph<wp_menu_item> menu_list;
00050   istring _title;
00051 
00052   void recursively_create(window_handle parent, const char *title,
00053           amorph<wp_menu_item> *menulist);
00054 };
00055 
00056 class WP_ACTIVE_CLASS_STYLE wp_menu_item : public nub
00057 {
00058 public:
00059   wp_menu_item(menu &parent, const char *name = NIL, bool label = false);
00060     // constructs a new item.  if the "name" is NIL, then the item's space in
00061     // the menu is a separator instead of a choosable option.  if "label" is
00062     // true, then the item is only a label and will not trigger an event when
00063     // it is selected.  also, if another item is connected to this item (by
00064     // calling connect with "this" as the wp_menu_item to connect), then no event
00065     // is triggered when the item connected to this is selected (instead, the
00066     // submenu represented by this menu item appears).
00067 
00068   virtual ~wp_menu_item();
00069 
00070   void connect(wp_menu_item *to_connect);
00071     // attaches a sub-menu to this menu item.  when a wp_menu_item has sub-menu_
00072     // items connected to it, the wp_menu_item does not trigger the
00073     // item_selected_event.  "name" is the name for the sub-menu.  "to_connect"
00074     // is an item to connect to "this" wp_menu_item.  Multiple sub-menu items
00075     // can be connected to a wp_menu_item.
00076 
00077   void submenu_name(const istring &name);
00078     // sets the name of the submenu.  only used if one is connected.
00079 
00080   virtual void item_selected_event();
00081     // This event function is triggered when this wp_menu_item is selected by the
00082     // user as long as this item is: 1) visible, 2) not a separator, 3) not a
00083     // label, and 4) not a wp_menu_item with a sub_menu connected to it.
00084 
00085   IMPLEMENT_CLASS_NAME("wp_menu_item");
00086 
00087 private:
00088   istring name;
00089   bool i_am_label;
00090   amorph<wp_menu_item> sub_menus;
00091   istring sub_menu_title;
00092 
00093   friend class menu;
00094   menu &parent;
00095 };
00096 
00097 #endif

Generated on Fri Nov 28 04:29:04 2008 for HOOPLE Libraries by  doxygen 1.5.1