home *** CD-ROM | disk | FTP | other *** search
- /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Copyright (C) 1994, by WATCOM International Inc. All rights %
- % reserved. No part of this software may be reproduced or %
- % used in any form or by any means - graphic, electronic or %
- % mechanical, including photocopying, recording, taping or %
- % information storage and retrieval systems - except with the %
- % written permission of WATCOM International Inc. %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- */
-
- /*************************************************************************
- *
- * WMenu -- Wrapper for the Windows 95 Menu control.
- *
- *
- * Events:
- *
- * MeasureItem --
- *
- * DrawItem --
- *
- * InitMenu --
- *
- *************************************************************************/
-
- #ifndef _WMENU_HPP_INCLUDED
- #define _WMENU_HPP_INCLUDED
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma pack(push,8);
- #pragma enum int;
- #endif
-
- #ifndef _WSTRING_HPP_INCLUDED
- # include "wstring.hpp"
- #endif
- #ifndef _WOBJECT_HPP_INCLUDED
- # include "wobject.hpp"
- #endif
- #ifndef _WRESID_HPP_INCLUDED
- # include "wresid.hpp"
- #endif
- #ifndef _WEVENTD_HPP_INCLUDED
- # include "weventd.hpp"
- #endif
- #ifndef _WACCEL_HPP_INCLUDED
- # include "waccel.hpp"
- #endif
- #ifndef _WVECTOR_HPP_INCLUDED
- # include "wvector.hpp"
- #endif
-
- class WForm;
-
- class WMenu;
- class WMenuItem;
- class WPopupMenu;
- class WAcceleratorTable;
- struct WMessageEventData;
-
- enum WNegotiatePosition {
- WNPNone = 0,
- WNPLeft = 1,
- WNPMiddle = 2,
- WNPRight = 3
- };
-
- class WCMCLASS WMenuObject : public WEventGenerator {
- WDeclareSubclass( WMenuObject, WEventGenerator );
-
- friend class WMenu;
-
- public:
-
- /**********************************************************
- * Constructors and Destructors
- *********************************************************/
-
- WMenuObject( WUShort id, const WChar * text=NULL,
- const WChar * hinttext=NULL );
-
- ~WMenuObject();
-
- /**********************************************************
- * Properties
- *********************************************************/
-
- // HintText
-
- WString GetHintText() const { return _hintText; }
- WBool SetHintText( const WString & str );
-
- // ID
-
- WUShort GetID() const { return _id; }
-
- // NegotiatePosition
-
- WNegotiatePosition GetNegotiatePosition() const;
- WBool SetNegotiatePosition( const WNegotiatePosition pos );
-
- // Parent
-
- WObject *GetParent() const { return _parent; }
- WBool SetParent( WObject * parent );
-
- // Text
-
- virtual WString GetText();
- virtual WBool SetText( const WString & text );
-
- // UserData
-
- virtual void *GetUserData() const;
- virtual WBool SetUserData( void * userData );
-
- /**********************************************************
- * Methods
- *********************************************************/
-
- /**********************************************************
- * Others
- *********************************************************/
-
- int operator ==( const WMenuObject & obj ) const;
- int operator !=( const WMenuObject & obj ) const;
-
- /**********************************************************
- * Data Members
- *********************************************************/
-
- protected:
-
- WUShort _id;
- WBool _internallyAllocated;
- WBool _previouslyExisted;
- WString _text;
- WString _hintText;
- WNegotiatePosition _negotiatePos;
- WObject * _parent;
- void * _userData;
- };
-
- extern template WVector<WMenuObject>;
-
- class WCMCLASS WMenu : public WMenuObject {
- WDeclareSubclass( WMenu, WMenuObject );
-
- public:
-
- /**********************************************************
- * Constructors and Destructors
- *********************************************************/
-
- WMenu( const WResourceID & id, WModuleHandle module=_ApplicationModule,
- WBool loadAccelerators=TRUE,
- WBool appendAcceleratorName=TRUE );
-
- WMenu( WBool create=TRUE, WMenuHandle handle=NULLHMNU );
-
- ~WMenu();
-
- /**********************************************************
- * Properties
- *********************************************************/
-
- // AcceleratorTable
-
- WAcceleratorTable GetAcceleratorTable() const;
- WBool SetAcceleratorTable( const WAcceleratorTable & table,
- WBool append=FALSE );
-
- // Count
-
- WInt GetCount();
-
- // Handle
-
- WMenuHandle GetHandle() const { return _handle; }
-
- // HelpID
-
- WULong GetHelpID();
- WBool SetHelpID( WULong helpID );
-
- /**********************************************************
- * Methods
- *********************************************************/
-
- // CheckItem
-
- WBool CheckItem( WBool check, const WResourceID & id,
- WBool exclusive=FALSE, WBool recurse=TRUE );
- WBool CheckItem( WBool check, WInt index, WBool exclusive=FALSE );
-
- // Clear (remove and destroy) all items & submenus
-
- void Clear();
-
- // EnableItem
-
- WBool EnableItem( WBool enable, const WResourceID & id,
- WBool recurse=TRUE, WBool grayIfDisabled=TRUE );
- WBool EnableItem( WBool enable, WInt index,
- WBool grayIfDisabled=TRUE );
-
- // Find
-
- WMenuObject *Find( WUShort id, WClassID classid=0, WBool recurse=TRUE,
- WInt * position=NULL,
- WObject **parent=NULL ) const;
-
- WMenuObject *Find( const WChar * name, WClassID classid=0,
- WBool recurse=TRUE,
- WInt * position=NULL,
- WObject ** parent=NULL ) const;
-
- WMenuObject *Find( WMenuHandle mhandle, WClassID classid=0,
- WBool recurse=TRUE,
- WInt * position=NULL,
- WObject ** parent=NULL ) const;
-
- // GrayItem
-
- WBool GrayItem( WBool gray, const WResourceID & id,
- WBool recurse=TRUE );
- WBool GrayItem( WBool gray, WInt index );
-
- // IndexOf
-
- WInt IndexOf( const WMenuItem * ) const;
- WInt IndexOf( const WPopupMenu * ) const;
-
- // AddItem -- add an item into the menu
-
- WMenuItem * AddItem( WMenuItem * item, WInt index=-1,
- WBool selfDelete=FALSE );
-
- // AddPopup -- add a popup menu into the menu
-
- WPopupMenu * AddPopup( WPopupMenu * popup, WInt index=-1,
- WBool selfDelete=FALSE );
-
- // AddSeparator -- add a separator into the menu
-
- WMenuItem * AddSeparator( WInt index=-1 );
-
- // IsItemChecked
-
- WBool IsItemChecked( const WResourceID & id, WBool recurse=TRUE );
- WBool IsItemChecked( WInt index );
-
- // IsItemEnabled
-
- WBool IsItemEnabled( const WResourceID & id, WBool recurse=TRUE );
- WBool IsItemEnabled( WInt index );
-
- // IsItemGrayed
-
- WBool IsItemGrayed( const WResourceID & id, WBool recurse=TRUE );
- WBool IsItemGrayed( WInt index );
-
- // RemoveItem -- remove (but don't delete) an item from the menu
-
- WMenuItem * RemoveItem( const WResourceID & id, WBool recurse=TRUE );
- WMenuItem * RemoveItem( WInt index );
- WMenuItem * RemoveItem( WMenuItem * item );
-
- // RemovePopup -- remove (but don't delete) an popup from the menu
-
- WPopupMenu * RemovePopup( const WResourceID & id,
- WBool recurse=TRUE );
- WPopupMenu * RemovePopup( WInt index );
- WPopupMenu * RemovePopup( WPopupMenu * popup );
-
- /**********************************************************
- * Item Properties
- *********************************************************/
-
- // Item -- Get a menu item by index or resid or name
-
- WMenuItem * GetItem( WInt index );
- WMenuItem * GetItem( const WChar * name, WBool recurse=TRUE );
- WMenuItem * GetItem( const WResourceID & id, WBool recurse=TRUE );
-
- // PopupMenu -- Get a popup menu by index or resid or name
-
- WPopupMenu * GetPopupMenu( const WResourceID & id,
- WBool recurse=TRUE );
- WPopupMenu * GetPopupMenu( WInt index );
- WPopupMenu * GetPopupMenu( const WChar * name, WBool recurse=TRUE );
-
- /**********************************************************
- * Others
- *********************************************************/
-
- // ConstructChildren
-
- void ConstructChildren( WBool previouslyExisted=FALSE );
-
- void ConstructChildren( WBool previouslyExisted, WBool fromResource,
- const WResourceID & baseID,
- WModuleHandle baseModuleHandle );
-
- // InitMenu
-
- WBool InitMenuEventHandler( WMenu * menu, WMessageEventData * event );
-
- // Destroy
-
- virtual WBool Destroy();
-
- /**********************************************************
- * Data Members
- *********************************************************/
-
- protected:
-
- WMenuHandle _handle;
- WVector<WMenuObject> _children;
- WAcceleratorTable * _accelTable;
- void * _internalData;
- };
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma enum pop;
- #pragma pack(pop);
- #endif
-
- #endif // _WMENU_HPP_INCLUDED
-