home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / Include / FWMnuItm.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  10.4 KB  |  358 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuItm.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUITM_H
  11. #define FWMNUITM_H
  12.  
  13. #ifndef FWMENU_K
  14. #include "FWMenu.k"
  15. #endif
  16.  
  17. #ifndef FWODTYPS_H
  18. #include "FWODTyps.h"
  19. #endif
  20.  
  21. // ----- Foundation Includes -----
  22.  
  23. #ifndef FWSTRS_H
  24. #include "FWStrs.h"
  25. #endif
  26.  
  27. #ifndef FWSTREAM_H
  28. #include "FWStream.h"
  29. #endif
  30.  
  31. #ifndef FWTCOLL_H
  32. #include "FWTColl.h"
  33. #endif
  34.  
  35. // ----- OpenDoc Includes -----
  36.  
  37. #ifndef SOM_Module_OpenDoc_Commands_defined
  38. #include <CmdDefs.xh>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward Declarations
  43. //========================================================================================
  44.  
  45. class FW_CPullDownMenu;
  46. class FW_CString;
  47. class FW_CMenuBar;
  48.  
  49.  
  50.  
  51. //========================================================================================
  52. //    Defines
  53. //========================================================================================
  54.  
  55. typedef short FW_MenuKey;
  56. const FW_MenuKey FW_kMenuKeyCharMask = 0x00FF;
  57.  
  58. #ifdef FW_BUILD_MAC
  59. const short FW_kScriptCodeKeyEquivalent = 28;    // key equiv value of $1C indicates that the icon field contains a script code
  60. #endif
  61.  
  62. const ODMenuID FW_kFirstMenuID = 4;
  63.  
  64.  
  65.  
  66. //========================================================================================
  67. //    class FW_CMenuItem
  68. //========================================================================================
  69.  
  70. class FW_CMenuItem
  71. {
  72. public:
  73.     FW_DECLARE_CLASS
  74.     FW_DECLARE_AUTO(FW_CMenuItem)
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    Constructors/Destructors
  78. //
  79. public:
  80.     FW_CMenuItem(Environment* ev, 
  81.                 FW_CReadableStream& stream);
  82.     FW_CMenuItem(Environment* ev, 
  83.                 FW_CPullDownMenu* ownerMenu, 
  84.                 short index);
  85.     
  86.     virtual     ~FW_CMenuItem();
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    New API
  90. //
  91. public:
  92.     //----- Getters/setters -----
  93.     ODCommandID            GetCommandID(Environment* ev) const;
  94.     
  95.     FW_CPullDownMenu*    GetOwnerMenu(Environment* ev) const;
  96.     short                GetIndex(Environment* ev) const;
  97.  
  98.     //----- Archiving -----
  99.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);    
  100.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  101.     static void         Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  102.     
  103. //----------------------------------------------------------------------------------------
  104. //    Implementation only
  105. //
  106. public:
  107.     virtual void            PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  108.     virtual void            PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  109.     virtual void            PrivDisableAll(Environment* ev);
  110.     virtual void            PrivEnableAll(Environment* ev);
  111.     virtual FW_CMenuItem*     PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  112.     
  113.     virtual FW_CPullDownMenu* PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  114.     
  115.     void                    PrivSetIndex(Environment* ev, short newIndex);
  116.     
  117. //----------------------------------------------------------------------------------------
  118. //    Data Members
  119. //
  120. protected:
  121. #ifdef FW_BUILD_MAC
  122.     ODCommandID            fCommandID;        // On windows call the toolbox
  123. #endif
  124.     FW_CPullDownMenu*    fOwnerMenu;
  125.     short                fIndex;            // one-based
  126. };
  127.  
  128.  
  129. //========================================================================================
  130. //    class FW_CSeparatorItem
  131. //========================================================================================
  132.  
  133. class FW_CSeparatorItem : public FW_CMenuItem
  134. {
  135. public:
  136.     FW_DECLARE_CLASS
  137.     FW_DECLARE_AUTO(FW_CSeparatorItem)
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    Constructors/Destructors
  141. //
  142. public:
  143.     FW_CSeparatorItem(Environment* ev, 
  144.                 FW_CReadableStream& stream);
  145.     FW_CSeparatorItem(Environment* ev, 
  146.                 FW_CPullDownMenu* ownerMenu, 
  147.                 short index);
  148.                 
  149.     virtual     ~FW_CSeparatorItem();
  150.  
  151. protected:
  152.     void        InitSeparator(Environment* ev, const ODPlatformMenu& platformMenu);
  153.     
  154. //----------------------------------------------------------------------------------------
  155. //    Inherited API
  156. //
  157. public:
  158.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    Implementation only
  162. //
  163. public:
  164.     virtual void        PrivDisableAll(Environment* ev);
  165.     virtual void        PrivEnableAll(Environment* ev);
  166. };
  167.  
  168.  
  169.  
  170. //========================================================================================
  171. //    class FW_CTextItem
  172. //========================================================================================
  173.  
  174. class FW_CTextItem : public FW_CMenuItem
  175. {
  176. public:
  177.     FW_DECLARE_CLASS
  178.     FW_DECLARE_AUTO(FW_CTextItem)
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    Constructors/Destructors
  182. //
  183. public:
  184.     FW_CTextItem(Environment* ev, 
  185.                 FW_CReadableStream& stream);
  186.     FW_CTextItem(Environment* ev,
  187.                 FW_CPullDownMenu* ownerMenu, 
  188.                 short index,            
  189.                 const FW_CString& text,
  190.                 ODCommandID commandID,
  191.                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  192.     virtual ~FW_CTextItem();
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    Inherited API
  196. //
  197. public:
  198.     //----- Archiving -----
  199.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  200.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  201.     
  202. //----------------------------------------------------------------------------------------
  203. //    Implementation only
  204. //
  205. public:
  206. #ifdef FW_BUILD_MAC
  207.     virtual void        PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  208.     virtual void        PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  209. #endif
  210. private:
  211.     void                PrivInitTextItem(Environment* ev,
  212.                                          const ODPlatformMenu&    platformMenu,
  213.                                           const FW_CString& text,
  214.                                          ODCommandID commandID,
  215.                                           FW_MenuKey menuKey);
  216.                               
  217. };
  218.  
  219.  
  220.  
  221. //========================================================================================
  222. //    class FW_CToggleItem
  223. //========================================================================================
  224.  
  225. class FW_CToggleItem : public FW_CTextItem
  226. {
  227. public:
  228.     FW_DECLARE_CLASS
  229.     FW_DECLARE_AUTO(FW_CToggleItem)
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    Constructors/Destructors
  233. //
  234. public:
  235.     FW_CToggleItem(Environment* ev, 
  236.                 FW_CReadableStream& stream);
  237.     FW_CToggleItem(Environment* ev,
  238.                 FW_CPullDownMenu* ownerMenu, 
  239.                 short index,            
  240.                 const FW_CString& trueText,
  241.                 const FW_CString& falseText,
  242.                 ODCommandID commandID,
  243.                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  244.     virtual     ~FW_CToggleItem();
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    New API
  248. //
  249. public:
  250.     void                ToggleItem(Environment* ev, FW_Boolean newState);
  251.     
  252.     //----- Archiving -----
  253.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  254.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  255.  
  256. //----------------------------------------------------------------------------------------
  257. //    Data Members
  258. //
  259. private:
  260.     FW_Boolean            fToggleState;
  261.     FW_CString            fOtherText;
  262. };
  263.  
  264.  
  265.  
  266. //========================================================================================
  267. //    class FW_CSubMenuItem
  268. //========================================================================================
  269.  
  270. class FW_CSubMenuItem : public FW_CMenuItem
  271. {
  272. public:
  273.     FW_DECLARE_CLASS
  274.     FW_DECLARE_AUTO(FW_CSubMenuItem)
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    Constructors/Destructors
  278. //
  279. public:
  280.     FW_CSubMenuItem(Environment* ev, 
  281.                 FW_CReadableStream& stream);
  282.     FW_CSubMenuItem(Environment* ev,
  283.                 FW_CPullDownMenu* ownerMenu, 
  284.                 short index,
  285.                 FW_CPullDownMenu* adoptSubMenu);
  286.     virtual     ~FW_CSubMenuItem();
  287.  
  288. //----------------------------------------------------------------------------------------
  289. //    New API
  290. //
  291. public:
  292.     //----- Getters/setters -----
  293.     FW_CPullDownMenu*    GetSubMenu(Environment* ev) const;
  294.  
  295.     //----- Archiving -----
  296.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream);
  297.     static void*        Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  298.  
  299. //----------------------------------------------------------------------------------------
  300. //    Implementation only
  301. //
  302. public:
  303.     virtual void            PrivAttach(Environment* ev, FW_CMenuBar* menuBar);
  304.     virtual void            PrivDetach(Environment* ev, FW_CMenuBar* menuBar);
  305.     virtual void            PrivDisableAll(Environment* ev);
  306.     virtual void            PrivEnableAll(Environment* ev);
  307.     virtual FW_CMenuItem*     PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  308.  
  309.     virtual FW_CPullDownMenu* PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  310.  
  311. private:
  312.     void                    PrivInitSubMenu(Environment* ev, const ODPlatformMenu&    platformMenu);
  313.     
  314. //----------------------------------------------------------------------------------------
  315. //    Data Members
  316. //
  317. private:
  318.     FW_CPullDownMenu*    fSubMenu;
  319. };
  320.  
  321. //========================================================================================
  322. //    FW_CMenuItem inlines
  323. //========================================================================================
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    FW_CMenuItem::GetOwnerMenu
  327. //----------------------------------------------------------------------------------------
  328. inline FW_CPullDownMenu* FW_CMenuItem::GetOwnerMenu(Environment*) const
  329. {
  330.     return fOwnerMenu;
  331. }
  332.  
  333. //----------------------------------------------------------------------------------------
  334. //    FW_CMenuItem::GetIndex
  335. //----------------------------------------------------------------------------------------
  336. inline short FW_CMenuItem::GetIndex(Environment*) const
  337. {
  338.     return fIndex;
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. //    FW_CSubMenuItem::GetSubMenu
  343. //----------------------------------------------------------------------------------------
  344. inline FW_CPullDownMenu* FW_CSubMenuItem::GetSubMenu(Environment*) const
  345. {
  346.     return fSubMenu;
  347. }
  348.  
  349. //----------------------------------------------------------------------------------------
  350. //    FW_CMenuItem::PrivSetIndex
  351. //----------------------------------------------------------------------------------------
  352. inline void FW_CMenuItem::PrivSetIndex(Environment*, short newIndex)
  353. {
  354.     fIndex = newIndex;
  355. }
  356.  
  357. #endif
  358.