home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / TVINC.ZIP / MENUS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  14.0 KB  |  493 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   MENUS.H                                                               */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TMenuItem, TMenu, TMenuView, TSubMenu,            */
  9. /*   TMenuBar, TMenuBox, TStatusItem, TStatusDef, and TStatusLine          */
  10. /*                                                                         */
  11. /* ------------------------------------------------------------------------*/
  12.  
  13. #pragma option -Vo-
  14. #if defined( __BCOPT__ )
  15. #pragma option -po-
  16. #endif
  17.  
  18. class far TSubMenu;
  19. class far TMenuItem;
  20. class far TStatusDef;
  21. class far TStatusItem;
  22.  
  23. TSubMenu& operator + ( TSubMenu& s, TMenuItem& i );
  24. TSubMenu& operator + ( TSubMenu& s1, TSubMenu& s2 );
  25. TStatusDef& operator + ( TStatusDef& s1, TStatusItem& s2 );
  26. TStatusDef& operator + ( TStatusDef& s1, TStatusDef& s2 );
  27.  
  28. #if defined( Uses_TMenuItem ) && !defined( __TMenuItem )
  29. #define __TMenuItem
  30.  
  31. class far TMenu;
  32.  
  33. class TMenuItem
  34. {
  35.  
  36. public:
  37.  
  38.     TMenuItem( const char *aName,
  39.                ushort aCommand,
  40.                ushort aKeyCode,
  41.                ushort aHelpCtx = hcNoContext,
  42.                char *p = 0,
  43.                TMenuItem *aNext = 0
  44.              );
  45.     TMenuItem( const char *aName,
  46.                ushort aKeyCode,
  47.                TMenu *aSubMenu,
  48.                ushort aHelpCtx = hcNoContext,
  49.                TMenuItem *aNext = 0
  50.              );
  51.  
  52.     ~TMenuItem();
  53.  
  54.     void append( TMenuItem *aNext );
  55.  
  56.     TMenuItem *next;
  57.     const char *name;
  58.     ushort command;
  59.     Boolean disabled;
  60.     ushort keyCode;
  61.     ushort helpCtx;
  62.     union
  63.         {
  64.         const char *param;
  65.         TMenu *subMenu;
  66.         };
  67. };
  68.  
  69. inline void TMenuItem::append( TMenuItem *aNext )
  70. {
  71.     next = aNext;
  72. }
  73.  
  74. inline TMenuItem &newLine()
  75. {
  76.     return *new TMenuItem( 0, 0, 0, hcNoContext, 0, 0 );
  77. }
  78.  
  79. #endif  // Uses_TMenuItem
  80.  
  81. #if defined( Uses_TSubMenu ) && !defined( __TSubMenu )
  82. #define __TSubMenu
  83.  
  84. class TSubMenu : public TMenuItem
  85. {
  86.  
  87. public:
  88.  
  89.     TSubMenu( const char *, ushort, ushort = hcNoContext );
  90.  
  91. };
  92.  
  93. #endif  // Uses_TSubMenu
  94.  
  95. #if defined( Uses_TMenu ) && !defined( __TMenu )
  96. #define __TMenu
  97.  
  98. class TMenu
  99. {
  100.  
  101. public:
  102.  
  103.     TMenu() : items(0), deflt(0) {};
  104.     TMenu( TMenuItem& itemList )
  105.         { items = &itemList; deflt = &itemList; }
  106.     TMenu( TMenuItem& itemList, TMenuItem& TheDefault )
  107.         { items = &itemList; deflt = &TheDefault; }
  108.     ~TMenu();
  109.  
  110.     TMenuItem *items;
  111.     TMenuItem *deflt;
  112.  
  113. };
  114.  
  115. #endif  // Uses_TMenu
  116.  
  117. /* ---------------------------------------------------------------------- */
  118. /*      class TMenuView                                                   */
  119. /*                                                                        */
  120. /*      Palette layout                                                    */
  121. /*        1 = Normal text                                                 */
  122. /*        2 = Disabled text                                               */
  123. /*        3 = Shortcut text                                               */
  124. /*        4 = Normal selection                                            */
  125. /*        5 = Disabled selection                                          */
  126. /*        6 = Shortcut selection                                          */
  127. /* ---------------------------------------------------------------------- */
  128.  
  129. #if defined( Uses_TMenuView ) && !defined( __TMenuView )
  130. #define __TMenuView
  131.  
  132. class far TRect;
  133. class far TMenu;
  134. class far TEvent;
  135.  
  136. class TMenuView : public TView
  137. {
  138.  
  139. public:
  140.  
  141.     TMenuView( const TRect& bounds, TMenu *aMenu, TMenuView *aParent );
  142.     TMenuView( const TRect& bounds );
  143.  
  144.     void setBounds( const TRect& bounds );
  145.     virtual ushort execute();
  146.     TMenuItem *findItem( char ch );
  147.     virtual TRect getItemRect( TMenuItem *item );
  148.     virtual ushort getHelpCtx();
  149.     virtual TPalette& getPalette() const;
  150.     virtual void handleEvent( TEvent& event );
  151.     TMenuItem *hotKey( ushort keyCode );
  152.     TMenuView *newSubView( const TRect& bounds,
  153.                            TMenu *aMenu,
  154.                            TMenuView *aParentMenu
  155.                          );
  156.  
  157. protected:
  158.  
  159.     TMenuView *parentMenu;
  160.     TMenu *menu;
  161.     TMenuItem *current;
  162.  
  163. private:
  164.  
  165.     void nextItem();
  166.     void prevItem();
  167.     void trackKey( Boolean findNext );
  168.     Boolean mouseInOwner( TEvent& e );
  169.     Boolean mouseInMenus( TEvent& e );
  170.     void trackMouse( TEvent& e );
  171.     TMenuView *topMenu();
  172.     Boolean updateMenu( TMenu *menu );
  173.     void do_a_select( TEvent& );
  174.     TMenuItem *findHotKey( TMenuItem *p, ushort keyCode );
  175.  
  176. private:
  177.  
  178.     virtual const char *streamableName() const
  179.         { return name; }
  180.     static void writeMenu( opstream&, TMenu * );
  181.     static TMenu *readMenu( ipstream& );
  182.  
  183. protected:
  184.  
  185.     TMenuView( StreamableInit );
  186.     virtual void write( opstream& );
  187.     virtual void *read( ipstream& );
  188.  
  189. public:
  190.  
  191.     static const char * const near name;
  192.     static TStreamable *build();
  193.  
  194. };
  195.  
  196. inline ipstream& operator >> ( ipstream& is, TMenuView& cl )
  197.     { return is >> (TStreamable&)cl; }
  198. inline ipstream& operator >> ( ipstream& is, TMenuView*& cl )
  199.     { return is >> (void *&)cl; }
  200.  
  201. inline opstream& operator << ( opstream& os, TMenuView& cl )
  202.     { return os << (TStreamable&)cl; }
  203. inline opstream& operator << ( opstream& os, TMenuView* cl )
  204.     { return os << (TStreamable *)cl; }
  205.  
  206. inline TMenuView::TMenuView( const TRect& bounds,
  207.                              TMenu *aMenu,
  208.                              TMenuView *aParent
  209.                            ) :
  210.     TView(bounds), current( 0 ), menu( aMenu ), parentMenu( aParent )
  211. {
  212.      eventMask |= evBroadcast;
  213. }
  214.  
  215. inline TMenuView::TMenuView( const TRect& bounds ) :
  216.     TView(bounds), parentMenu(0), menu(0), current(0)
  217. {
  218.      eventMask |= evBroadcast;
  219. }
  220.  
  221. #endif  // Uses_TMenuView
  222.  
  223. /* ---------------------------------------------------------------------- */
  224. /*      class TMenuBar                                                    */
  225. /*                                                                        */
  226. /*      Palette layout                                                    */
  227. /*        1 = Normal text                                                 */
  228. /*        2 = Disabled text                                               */
  229. /*        3 = Shortcut text                                               */
  230. /*        4 = Normal selection                                            */
  231. /*        5 = Disabled selection                                          */
  232. /*        6 = Shortcut selection                                          */
  233. /* ---------------------------------------------------------------------- */
  234.  
  235. #if defined( Uses_TMenuBar ) && !defined( __TMenuBar )
  236. #define __TMenuBar
  237.  
  238. class far TRect;
  239. class far TMenu;
  240.  
  241. class TMenuBar : public TMenuView
  242. {
  243.  
  244. public:
  245.  
  246.     TMenuBar( const TRect& bounds, TMenu *aMenu );
  247.     TMenuBar( const TRect& bounds, TSubMenu &aMenu );
  248.     ~TMenuBar();
  249.  
  250.     virtual void draw();
  251.     virtual TRect getItemRect( TMenuItem *item );
  252.  
  253. private:
  254.  
  255.     virtual const char *streamableName() const
  256.         { return name; }
  257.  
  258. protected:
  259.  
  260.     TMenuBar( StreamableInit );
  261.  
  262. public:
  263.  
  264.     static const char * const near name;
  265.     static TStreamable *build();
  266.  
  267. };
  268.  
  269. inline ipstream& operator >> ( ipstream& is, TMenuBar& cl )
  270.     { return is >> (TStreamable&)cl; }
  271. inline ipstream& operator >> ( ipstream& is, TMenuBar*& cl )
  272.     { return is >> (void *&)cl; }
  273.  
  274. inline opstream& operator << ( opstream& os, TMenuBar& cl )
  275.     { return os << (TStreamable&)cl; }
  276. inline opstream& operator << ( opstream& os, TMenuBar* cl )
  277.     { return os << (TStreamable *)cl; }
  278.  
  279. #endif  // Uses_TMenuBar
  280.  
  281. /* ---------------------------------------------------------------------- */
  282. /*      class TMenuBox                                                    */
  283. /*                                                                        */
  284. /*      Palette layout                                                    */
  285. /*        1 = Normal text                                                 */
  286. /*        2 = Disabled text                                               */
  287. /*        3 = Shortcut text                                               */
  288. /*        4 = Normal selection                                            */
  289. /*        5 = Disabled selection                                          */
  290. /*        6 = Shortcut selection                                          */
  291. /* ---------------------------------------------------------------------- */
  292.  
  293. #if defined( Uses_TMenuBox ) && !defined( __TMenuBox )
  294. #define __TMenuBox
  295.  
  296. class far TRect;
  297. class far TMenu;
  298. class far TMenuView;
  299. class far TDrawBuffer;
  300.  
  301. class TMenuBox : public TMenuView
  302. {
  303.  
  304. public:
  305.  
  306.     TMenuBox( const TRect& bounds, TMenu *aMenu, TMenuView *aParentMenu);
  307.  
  308.     virtual void draw();
  309.     virtual TRect getItemRect( TMenuItem *item );
  310.  
  311. private:
  312.  
  313.     void frameLine( TDrawBuffer&, short n );
  314.     void drawLine( TDrawBuffer& );
  315.  
  316.     static const char * near frameChars;
  317.     virtual const char *streamableName() const
  318.         { return name; }
  319.  
  320. protected:
  321.  
  322.     TMenuBox( StreamableInit );
  323.  
  324. public:
  325.  
  326.     static const char * const near name;
  327.     static TStreamable *build();
  328.  
  329. };
  330.  
  331. inline ipstream& operator >> ( ipstream& is, TMenuBox& cl )
  332.     { return is >> (TStreamable&)cl; }
  333. inline ipstream& operator >> ( ipstream& is, TMenuBox*& cl )
  334.     { return is >> (void *&)cl; }
  335.  
  336. inline opstream& operator << ( opstream& os, TMenuBox& cl )
  337.     { return os << (TStreamable&)cl; }
  338. inline opstream& operator << ( opstream& os, TMenuBox* cl )
  339.     { return os << (TStreamable *)cl; }
  340.  
  341. #endif  // Uses_TMenuBox
  342.  
  343.  
  344. #if defined( Uses_TStatusItem ) && !defined( __TStatusItem )
  345. #define __TStatusItem
  346.  
  347. class TStatusItem
  348. {
  349.  
  350. public:
  351.  
  352.     TStatusItem( const char *aText,
  353.                  ushort key,
  354.                  ushort cmd,
  355.                  TStatusItem *aNext = 0
  356.                 );
  357.  
  358.     TStatusItem *next;
  359.     const char *text;
  360.     ushort keyCode;
  361.     ushort command;
  362.  
  363. };
  364.  
  365. inline TStatusItem::TStatusItem( const char *aText,
  366.                                  ushort key,
  367.                                  ushort cmd,
  368.                                  TStatusItem *aNext
  369.                                 ) :
  370.     text( aText ), keyCode( key ), command( cmd ), next( aNext )
  371. {
  372. }
  373.  
  374. #endif  // Uses_TStatusItem
  375.  
  376. #if defined( Uses_TStatusDef ) && !defined( __TStatusDef )
  377. #define __TStatusDef
  378.  
  379. class TStatusDef
  380. {
  381.  
  382. public:
  383.  
  384.     TStatusDef( ushort aMin,
  385.                 ushort aMax,
  386.                 TStatusItem *someItems = 0,
  387.                 TStatusDef *aNext = 0
  388.               );
  389.  
  390.     TStatusDef *next;
  391.     ushort min;
  392.     ushort max;
  393.     TStatusItem *items;
  394. };
  395.  
  396. inline TStatusDef::TStatusDef( ushort aMin,
  397.                                ushort aMax,
  398.                                TStatusItem *someItems,
  399.                                TStatusDef *aNext
  400.                              ) :
  401.     min( aMin ), max( aMax ), items( someItems ), next( aNext )
  402. {
  403. }
  404.  
  405. #endif  // Uses_TStatusDef
  406.  
  407. /* ---------------------------------------------------------------------- */
  408. /*      class TStatusLine                                                 */
  409. /*                                                                        */
  410. /*      Palette layout                                                    */
  411. /*        1 = Normal text                                                 */
  412. /*        2 = Disabled text                                               */
  413. /*        3 = Shortcut text                                               */
  414. /*        4 = Normal selection                                            */
  415. /*        5 = Disabled selection                                          */
  416. /*        6 = Shortcut selection                                          */
  417. /* ---------------------------------------------------------------------- */
  418.  
  419. #if defined( Uses_TStatusLine ) && !defined( __TStatusLine )
  420. #define __TStatusLine
  421.  
  422. class far TRect;
  423. class far TEvent;
  424. class far TPoint;
  425.  
  426. class TStatusLine : public TView
  427. {
  428.  
  429. public:
  430.  
  431.     TStatusLine( const TRect& bounds, TStatusDef& aDefs );
  432.     ~TStatusLine();
  433.  
  434.     virtual void draw();
  435.     virtual TPalette& getPalette() const;
  436.     virtual void handleEvent( TEvent& event );
  437.     virtual const char* hint( ushort aHelpCtx );
  438.     void update();
  439.  
  440. protected:
  441.  
  442.     TStatusItem *items;
  443.     TStatusDef *defs;
  444.  
  445. private:
  446.  
  447.     void drawSelect( TStatusItem *selected );
  448.     void findItems();
  449.     TStatusItem *itemMouseIsIn( TPoint );
  450.     void disposeItems( TStatusItem *item );
  451.  
  452.     static const char * near hintSeparator;
  453.     
  454.     virtual const char *streamableName() const
  455.         { return name; }
  456.  
  457.     static void writeItems( opstream&, TStatusItem * );
  458.     static void writeDefs( opstream&, TStatusDef * );
  459.     static TStatusItem *readItems( ipstream& );
  460.     static TStatusDef *readDefs( ipstream& );
  461.  
  462.  
  463. protected:
  464.  
  465.     TStatusLine( StreamableInit );
  466.     virtual void write( opstream& );
  467.     virtual void *read( ipstream& );
  468.  
  469. public:
  470.  
  471.     static const char * const near name;
  472.     static TStreamable *build();
  473.  
  474. };
  475.  
  476. inline ipstream& operator >> ( ipstream& is, TStatusLine& cl )
  477.     { return is >> (TStreamable&)cl; }
  478. inline ipstream& operator >> ( ipstream& is, TStatusLine*& cl )
  479.     { return is >> (void *&)cl; }
  480.  
  481. inline opstream& operator << ( opstream& os, TStatusLine& cl )
  482.     { return os << (TStreamable&)cl; }
  483. inline opstream& operator << ( opstream& os, TStatusLine* cl )
  484.     { return os << (TStreamable *)cl; }
  485.  
  486. #endif  // Uses_TStatusLine
  487.  
  488. #pragma option -Vo.
  489. #if defined( __BCOPT__ )
  490. #pragma option -po.
  491. #endif
  492.  
  493.