home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / tvision / menus.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  14KB  |  521 lines

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