menuitem.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:13k
- /*
- * menuitem.h
- *
- * Menu Item class.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: menuitem.h,v $
- * Revision 1.21 1999/03/10 03:49:52 robertj
- * More documentation adjustments.
- *
- * Revision 1.20 1999/03/09 08:01:49 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.19 1999/02/16 08:08:46 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.18 1998/09/23 06:24:21 robertj
- * Added open source copyright license.
- *
- * Revision 1.17 1995/03/14 12:41:47 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.16 1995/02/19 04:11:21 robertj
- * Changed mechanism for implementing menu item check groups.
- * Added dynamically linked command processing.
- *
- * Revision 1.15 1995/01/03 09:36:16 robertj
- * Documentation.
- *
- * Revision 1.14 1994/11/19 00:06:03 robertj
- * Removed variable argument list binding for menus and controls.
- *
- * Revision 1.13 1994/10/30 11:46:50 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.12 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.11 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.10 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.9 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.8 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.7 1993/12/16 06:20:57 robertj
- * Changes to callback function definition due to GCC.
- *
- * Revision 1.6 1993/12/01 16:09:05 robertj
- * Windows NT port.
- *
- * Revision 1.5 1993/10/16 20:33:20 robertj
- * Added extra parameter to common contstructor code for Unix compatibility.
- *
- * Revision 1.4 1993/08/27 18:17:47 robertj
- * Added group menu mutually exclusive checking.
- *
- * Revision 1.3 1993/08/21 01:50:33 robertj
- * Made Clone() function optional, default will assert if called.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PMENUITEM
- #ifdef __GNUC__
- #pragma interface
- #endif
- class PMenuItem;
- /**A class representing a menu item.
- A menu item is a selectable command within a menu. The menu may carry with
- it a callback function which is executed when the menu item is selected.
- Also a menu item may have an {it accelerator} attached to it. This is a
- Ref{PKeyCode} that represents a key that will execute the menu command
- when pressed.
-
- All menu items have a unique identifier across all items in a particular
- tree of menus, ie for a given Ref{PRootMenu} class instance. The system
- will automatically guarentee this when menus are built manually. If they
- come from resources, they PWLib resource compiler takes this responsibility.
- If resources are generated in some other way then it is up to the
- programmer.
-
- The menu name is processed for the special character '&' to place an
- underline attribute on the next character. To place an '&' itself into the
- string then two censecutive ampersands ("&&") must be used. The character
- in the string marked with the ampersand is the letter that selects the menu
- item when the menu selection operation is in progress, This is different
- from the accelerator which may be pressed at any time to select the menu
- item.
-
- A menu may also be {it enabled} or {it disabled}. A disabled menu is
- visually distinct from an enabled menu item. This is also referred to as
- "greying" the menu item.
- A menu item may also have a {it check mark} next to it indicating a state
- for the menu item. The exact appearance is platform dependent.
- */
- class PMenuItem : public PMenuEntry
- {
- PCLASSINFO(PMenuItem, PMenuEntry);
- public:
- /**Create a new menu items in the specified menu that has the specified
- name, accelerator key code and notification function.
- */
- PMenuItem(
- PSubMenu & menu, /// Menu into which the new entry is to be placed.
- const PString & itemName, /// Name of the menu item.
- PMenuEntry * before = NULL
- /**Menu entry before which the entry is to be inserted. If this is NULL
- then the menu entry is appended to the end of the menu.
- */
- );
- PMenuItem(
- PSubMenu & menu, /// Menu into which the new entry is to be placed.
- const PString & itemName, /// Name of the menu item.
- const PNotifier & notify, /// Notification function when item selected.
- BOOL notifyForStateUpdate = FALSE,
- /**Notification function is to be called when a menu item requires its
- enable or check state updated. If FALSE the notification function is
- only called when the item is selected.
- */
- PMenuEntry * before = NULL
- /**Menu entry before which the entry is to be inserted. If this is NULL
- then the menu entry is appended to the end of the menu.
- */
- );
- PMenuItem(
- PSubMenu & menu, /// Menu into which the new entry is to be placed.
- const PString & itemName, /// Name of the menu item.
- const PKeyCode & accel, /// Key code for accelerator on menu function.
- const PNotifier & notify, /// Notification function when item selected.
- BOOL notifyForStateUpdate = FALSE,
- /**Notification function is to be called when a menu item requires its
- enable or check state updated. If FALSE the notification function is
- only called when the item is selected.
- */
- PMenuEntry * before = NULL
- /**Menu entry before which the entry is to be inserted. If this is NULL
- then the menu entry is appended to the end of the menu.
- */
- );
- /**Helper constructor for when creating menu from a resource. Creates the
- object given the menu ID as used in the resource template.
- */
- PMenuItem(
- PRESOURCE_ID newID,
- PSubMenu & menu, /// Menu into which the new entry is to be placed.
- const char * itemName, /// Name of the menu item.
- const PKeyCode & accel /// Key code for accelerator on menu function.
- );
- /** Destroy the menu item removing it from its owner menu. */
- virtual ~PMenuItem();
- /**@name Overrides from class PMenuEntry */
- /**Set the string contents of the menu item. This string is scanned for the
- special character '&' to place an underline attribute on the next
- character.
- */
- virtual void SetString(
- const PString & str /// New string for the menu entry.
- );
- /**Get the current string name of the menu entry.
- @return
- string for the menu item name.
- */
- virtual PString GetString() const;
- /**Determine if the menu entry is in a menu item check group. If the entry
- is not a menu item or does not have the same notification function, the
- qualification for being in a menu check group, then returns FALSE.
- @return
- TRUE if in check group, FALSE otherwise.
- */
- virtual BOOL IsMenuItemCheckGroup(const PMenuItem& groupItem) const;
- /**@name New functions for class */
- /** Set the accelerator key code associated with the menu item. */
- void SetAccelerator(
- const PKeyCode & accel /// New accelerator for the menu item.
- );
- /**Get the accelerator key code associated with the menu item.
-
- @return
- key code for accelerator.
- */
- PKeyCode GetAccelerator() const;
- /**Set the notification function associated with the menu item. The extra
- integer on the indicates whether the menu item was selected (FALSE) or
- requires its state updated (TRUE). The latter is only called if the
- #notifyForStateUpdate# flag is set to TRUE.
- */
- void SetNotifier(
- const PNotifier & notify, /// New notification function for menu item
- BOOL notifyForStateUpdate = FALSE
- /**Notification function is to be called when a menu item requires its
- enable or check state updated. If FALSE the notification function is
- only called when the item is selected.
- */
- );
- /**Get the notification function associated with the menu item.
-
- @return
- notification function for menu item.
- */
- const PNotifier & GetNotifier() const;
- /**Get the flag for notification function called when a menu item requires
- its enable or check state updated.
-
- @return
- current update flag for menu item.
- */
- BOOL WillNotifyOnStateUpdate() const;
- /** Enable or disable the menu item. */
- void Enable(
- BOOL enabled = TRUE /// New enable state for menu item.
- );
- /**Disable the menu item. This is equivalent to
- #Enable(FALSE)#.
- */
- void Disable();
- /**Determine if the menu item is currently enabled or disabled.
-
- @return
- TRUE if the menu item is enabled.
- */
- BOOL IsEnabled() const;
- /** Check or uncheck the menu item. */
- void Check(
- BOOL checked = TRUE /// New state for the menu check mark.
- );
- /** Uncheck the menu item. This is equivalent to #Check(FALSE)#. */
- void Uncheck();
- /**Determine if the menu item is currently checked or unchecked.
- @return
- TRUE if the menu item is checked.
- */
- BOOL IsChecked() const;
- /**Set the current check state value pointer associated with the menu item.
- The boolean pointed to by this is automatically updated to the state
- of the check mark.
- */
- void SetCheckPointer(
- BOOL * ptr /// Pointer to variable to be updated with check state.
- );
- /**Get the current check state value pointer associated with the menu item.
- The boolean pointed to by this is automatically updated to the state
- of the check mark.
-
- @return
- pointer to check state variable.
- */
- BOOL * GetCheckPointer() const;
- /**Check this item, or the specified item, and uncheck all other items in
- the menu with the same notification function as this menu item.
- The index numbers start with one for the first item with the same
- notification function. A value of zero indicates no item is checked.
- This will give a similar functionality to a set of radio button
- controls, setting one of mutually exclusive options.
- */
- void SetGroupCheck(
- PINDEX newItem /// Index of the menu item to be checked in the group.
- );
- void SetGroupCheck();
- /**Get the index of the menu item that is checked in the set of items in
- the menu with the same notification function as this item.
- The index numbers start with one for the first item with the same
- notification function. A value of zero indicates no item is checked.
- This will give a similar functionality to a set of radio button
- controls, setting one of mutually exclusive options.
-
- @return
- index of selected menu item.
- */
- PINDEX GetGroupCheck() const;
- protected:
- /**@name New functions for class */
- /** Do the common initialisation of a menu item amongst the constructors. */
- void Construct(
- BOOL setID /// Flag for generating a new menu resource ID for the item.
- );
- /**Scan through all menu items in the menu and execute their notification
- function to enable or disable and check or uncheck the menu item.
- For a menu item this calls the notification function if allowed by the
- #notifyForStateUpdate# flag.
- This function is used internally by the library. It would normally not
- be called directly.
- */
- virtual void UpdateMyCommandSources();
- // Member variables
- /** Name of the menu item. */
- PString name;
- /** Accelerator for the menu item. */
- PKeyCode accelerator;
- /** Notification function to call on menu selection. */
- PNotifier callback;
-
- /** Pointer to variable to contain the check state of the menu item. */
- BOOL * checkPointer;
- /** Unique menu ID for resource binding */
- PRESOURCE_ID menuID;
- /**Flag for notification function called when a menu item requires its
- enable or check state updated.
- */
- BOOL notifyForStateUpdate;
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////