home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WMENU.HPP < prev    next >
C/C++ Source or Header  |  1997-01-10  |  10KB  |  331 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WMenu -- Wrapper for the Windows 95 Menu control.
  14.  *
  15.  *
  16.  *   Events:
  17.  *
  18.  *       MeasureItem --
  19.  *
  20.  *       DrawItem --
  21.  *
  22.  *       InitMenu --
  23.  *
  24.  *************************************************************************/
  25.  
  26. #ifndef _WMENU_HPP_INCLUDED
  27. #define _WMENU_HPP_INCLUDED
  28.  
  29. #ifndef _WNO_PRAGMA_PUSH
  30. #pragma pack(push,8);
  31. #pragma enum int;
  32. #endif
  33.  
  34. #ifndef _WSTRING_HPP_INCLUDED
  35. #  include "wstring.hpp"
  36. #endif
  37. #ifndef _WOBJECT_HPP_INCLUDED
  38. #  include "wobject.hpp"
  39. #endif
  40. #ifndef _WRESID_HPP_INCLUDED
  41. #  include "wresid.hpp"
  42. #endif
  43. #ifndef _WEVENTD_HPP_INCLUDED
  44. #  include "weventd.hpp"
  45. #endif
  46. #ifndef _WACCEL_HPP_INCLUDED
  47. #  include "waccel.hpp"
  48. #endif
  49. #ifndef _WVECTOR_HPP_INCLUDED
  50. #  include "wvector.hpp"
  51. #endif
  52.  
  53. class WForm;
  54.  
  55. class WMenu;
  56. class WMenuItem;
  57. class WPopupMenu;
  58. class WAcceleratorTable;
  59. struct WMessageEventData;
  60.  
  61. enum WNegotiatePosition {
  62.     WNPNone = 0,
  63.     WNPLeft = 1,
  64.     WNPMiddle = 2,
  65.     WNPRight = 3
  66. };
  67.  
  68. class WCMCLASS WMenuObject : public WEventGenerator {
  69.     WDeclareSubclass( WMenuObject, WEventGenerator );
  70.  
  71.     friend class WMenu;
  72.  
  73.     public:
  74.  
  75.         /**********************************************************
  76.          * Constructors and Destructors
  77.          *********************************************************/
  78.  
  79.         WMenuObject( WUShort id, const WChar * text=NULL,
  80.                      const WChar * hinttext=NULL );
  81.  
  82.         ~WMenuObject();
  83.  
  84.         /**********************************************************
  85.          * Properties
  86.          *********************************************************/
  87.     
  88.         // HintText
  89.  
  90.         WString GetHintText() const { return _hintText; }
  91.         WBool   SetHintText( const WString & str );
  92.  
  93.         // ID
  94.  
  95.         WUShort GetID() const { return _id; }
  96.  
  97.         // NegotiatePosition
  98.  
  99.         WNegotiatePosition GetNegotiatePosition() const;
  100.         WBool              SetNegotiatePosition( const WNegotiatePosition pos );
  101.  
  102.         // Parent
  103.  
  104.         WObject *GetParent() const { return _parent; }
  105.         WBool    SetParent( WObject * parent );
  106.  
  107.         // Text
  108.  
  109.         virtual WString GetText();
  110.         virtual WBool   SetText( const WString & text );
  111.  
  112.         // UserData
  113.  
  114.         virtual void *GetUserData() const;
  115.         virtual WBool SetUserData( void * userData );
  116.  
  117.         /**********************************************************
  118.          * Methods
  119.          *********************************************************/
  120.     
  121.         /**********************************************************
  122.          * Others
  123.          *********************************************************/
  124.     
  125.         int operator ==( const WMenuObject & obj ) const;
  126.         int operator !=( const WMenuObject & obj ) const;
  127.  
  128.         /**********************************************************
  129.          * Data Members
  130.          *********************************************************/
  131.     
  132.     protected:
  133.  
  134.         WUShort                 _id;
  135.         WBool                   _internallyAllocated;
  136.         WBool                   _previouslyExisted;
  137.         WString                 _text;
  138.         WString                 _hintText;
  139.         WNegotiatePosition      _negotiatePos;
  140.         WObject *               _parent;
  141.         void *                  _userData;
  142. };
  143.  
  144. extern template WVector<WMenuObject>;
  145.  
  146. class WCMCLASS WMenu : public WMenuObject {
  147.     WDeclareSubclass( WMenu, WMenuObject );
  148.     
  149.     public:
  150.  
  151.         /**********************************************************
  152.          * Constructors and Destructors
  153.          *********************************************************/
  154.     
  155.         WMenu( const WResourceID & id, WModuleHandle module=_ApplicationModule,
  156.                WBool loadAccelerators=TRUE,
  157.                WBool appendAcceleratorName=TRUE );
  158.  
  159.         WMenu( WBool create=TRUE, WMenuHandle handle=NULLHMNU );
  160.     
  161.         ~WMenu();
  162.  
  163.         /**********************************************************
  164.          * Properties
  165.          *********************************************************/
  166.  
  167.         // AcceleratorTable
  168.  
  169.         WAcceleratorTable GetAcceleratorTable() const;
  170.         WBool SetAcceleratorTable( const WAcceleratorTable & table,
  171.                                    WBool append=FALSE );
  172.  
  173.         // Count
  174.  
  175.         WInt GetCount();
  176.  
  177.         // Handle
  178.  
  179.         WMenuHandle GetHandle() const { return _handle; }
  180.     
  181.         // HelpID
  182.  
  183.         WULong GetHelpID();
  184.         WBool  SetHelpID( WULong helpID );
  185.  
  186.         /**********************************************************
  187.          * Methods
  188.          *********************************************************/
  189.  
  190.         // CheckItem
  191.  
  192.         WBool CheckItem( WBool check, const WResourceID & id,
  193.                          WBool exclusive=FALSE, WBool recurse=TRUE );
  194.         WBool CheckItem( WBool check, WInt index, WBool exclusive=FALSE );
  195.  
  196.         // Clear (remove and destroy) all items & submenus
  197.  
  198.         void Clear();
  199.  
  200.         // EnableItem
  201.     
  202.         WBool EnableItem( WBool enable, const WResourceID & id,
  203.                           WBool recurse=TRUE, WBool grayIfDisabled=TRUE );
  204.         WBool EnableItem( WBool enable, WInt index,
  205.                           WBool grayIfDisabled=TRUE );
  206.     
  207.         // Find
  208.  
  209.         WMenuObject *Find( WUShort id, WClassID classid=0, WBool recurse=TRUE,
  210.                            WInt * position=NULL,
  211.                            WObject **parent=NULL ) const;
  212.  
  213.         WMenuObject *Find( const WChar * name, WClassID classid=0,
  214.                            WBool recurse=TRUE,
  215.                            WInt * position=NULL,
  216.                            WObject ** parent=NULL ) const;
  217.  
  218.         WMenuObject *Find( WMenuHandle mhandle, WClassID classid=0,
  219.                            WBool recurse=TRUE,
  220.                            WInt * position=NULL,
  221.                            WObject ** parent=NULL ) const;
  222.  
  223.         // GrayItem
  224.     
  225.         WBool GrayItem( WBool gray, const WResourceID & id,
  226.                         WBool recurse=TRUE );
  227.         WBool GrayItem( WBool gray, WInt index );
  228.     
  229.         // IndexOf
  230.  
  231.         WInt IndexOf( const WMenuItem * ) const;
  232.         WInt IndexOf( const WPopupMenu * ) const;
  233.  
  234.         // AddItem -- add an item into the menu
  235.  
  236.         WMenuItem  * AddItem( WMenuItem * item, WInt index=-1,
  237.                               WBool selfDelete=FALSE );
  238.  
  239.         // AddPopup -- add a popup menu into the menu
  240.  
  241.         WPopupMenu * AddPopup( WPopupMenu * popup, WInt index=-1,
  242.                                WBool selfDelete=FALSE );
  243.  
  244.         // AddSeparator -- add a separator into the menu
  245.  
  246.         WMenuItem * AddSeparator( WInt index=-1 );
  247.     
  248.         // IsItemChecked
  249.  
  250.         WBool IsItemChecked( const WResourceID & id, WBool recurse=TRUE );
  251.         WBool IsItemChecked( WInt index );
  252.  
  253.         // IsItemEnabled
  254.  
  255.         WBool IsItemEnabled( const WResourceID & id, WBool recurse=TRUE );
  256.         WBool IsItemEnabled( WInt index );
  257.     
  258.         // IsItemGrayed
  259.  
  260.         WBool IsItemGrayed( const WResourceID & id, WBool recurse=TRUE );
  261.         WBool IsItemGrayed( WInt index );
  262.  
  263.         // RemoveItem -- remove (but don't delete) an item from the menu
  264.  
  265.         WMenuItem * RemoveItem( const WResourceID & id, WBool recurse=TRUE );
  266.         WMenuItem * RemoveItem( WInt index );
  267.         WMenuItem * RemoveItem( WMenuItem * item );
  268.     
  269.         // RemovePopup -- remove (but don't delete) an popup from the menu
  270.  
  271.         WPopupMenu * RemovePopup( const WResourceID & id,
  272.                                   WBool recurse=TRUE );
  273.         WPopupMenu * RemovePopup( WInt index );
  274.         WPopupMenu * RemovePopup( WPopupMenu * popup );
  275.  
  276.         /**********************************************************
  277.          * Item Properties
  278.          *********************************************************/
  279.  
  280.         // Item -- Get a menu item by index or resid or name
  281.     
  282.         WMenuItem * GetItem( WInt index );
  283.         WMenuItem * GetItem( const WChar * name, WBool recurse=TRUE );
  284.         WMenuItem * GetItem( const WResourceID & id, WBool recurse=TRUE );
  285.  
  286.         // PopupMenu -- Get a popup menu by index or resid or name
  287.     
  288.         WPopupMenu * GetPopupMenu( const WResourceID & id,
  289.                                    WBool recurse=TRUE );
  290.         WPopupMenu * GetPopupMenu( WInt index );
  291.         WPopupMenu * GetPopupMenu( const WChar * name, WBool recurse=TRUE );
  292.  
  293.         /**********************************************************
  294.          * Others
  295.          *********************************************************/
  296.  
  297.         // ConstructChildren
  298.  
  299.         void ConstructChildren( WBool previouslyExisted=FALSE );
  300.  
  301.         void ConstructChildren( WBool previouslyExisted, WBool fromResource,
  302.                                 const WResourceID & baseID,
  303.                                 WModuleHandle baseModuleHandle );
  304.  
  305.         // InitMenu
  306.  
  307.         WBool InitMenuEventHandler( WMenu * menu, WMessageEventData * event );
  308.  
  309.         // Destroy
  310.  
  311.         virtual WBool Destroy();
  312.  
  313.         /**********************************************************
  314.          * Data Members
  315.          *********************************************************/
  316.  
  317.     protected:
  318.  
  319.         WMenuHandle             _handle;
  320.         WVector<WMenuObject>    _children;
  321.         WAcceleratorTable *     _accelTable;
  322.         void *                  _internalData;
  323. };
  324.  
  325. #ifndef _WNO_PRAGMA_PUSH
  326. #pragma enum pop;
  327. #pragma pack(pop);
  328. #endif
  329.  
  330. #endif // _WMENU_HPP_INCLUDED
  331.