home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / TVSRC.ZIP / TMENUBAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.4 KB  |  122 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tmenubar.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TMenuBar member functions                 */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TMenuBar
  19. #define Uses_TDrawBuffer
  20. #define Uses_TMenu
  21. #define Uses_TMenuItem
  22. #define Uses_TRect
  23. #define Uses_TSubMenu
  24. #include <tv.h>
  25.  
  26. #if !defined( __STRING_H )
  27. #include <String.h>
  28. #endif  // __STRING_H
  29.  
  30. TMenuBar::TMenuBar( const TRect& bounds, TMenu *aMenu ) :
  31.     TMenuView( bounds )
  32. {
  33.     menu = aMenu;
  34.     growMode = gfGrowHiX;
  35.     options |= ofPreProcess;
  36. }
  37.  
  38. TMenuBar::TMenuBar( const TRect& bounds, TSubMenu& aMenu ) :
  39.     TMenuView( bounds )
  40. {
  41.     menu = new TMenu( aMenu );
  42.     growMode = gfGrowHiX;
  43.     options |= ofPreProcess;
  44. }
  45.  
  46. TMenuBar::~TMenuBar()
  47. {
  48.     delete menu;
  49. }
  50.  
  51. void TMenuBar::draw()
  52. {
  53.     ushort color;
  54.     short x, l;
  55.     TMenuItem *p;
  56.     TDrawBuffer b;
  57.  
  58.     ushort cNormal = getColor(0x0301);
  59.     ushort cSelect = getColor(0x0604);
  60.     ushort cNormDisabled =  getColor(0x0202);
  61.     ushort cSelDisabled =  getColor(0x0505);
  62.     b.moveChar( 0, ' ', cNormal, size.x );
  63.     if( menu != 0 )
  64.         {
  65.         x = 1;
  66.         p = menu->items;
  67.         while( p != 0 )
  68.             {
  69.             if( p->name != 0 )
  70.                 {
  71.                 l = cstrlen(p->name);
  72.                 if( x + l < size.x )
  73.                     {
  74.                     if( p->disabled )
  75.                         if( p == current )
  76.                             color = cSelDisabled;
  77.                         else
  78.                             color = cNormDisabled;
  79.                     else
  80.                         if( p == current )
  81.                             color = cSelect;
  82.                         else
  83.                             color = cNormal;
  84.  
  85.                     b.moveChar( x, ' ', color, 1 );
  86.                     b.moveCStr( x+1, p->name, color );
  87.                     b.moveChar( x+l+1, ' ', color, 1 );
  88.                     }
  89.                 x += l + 2;
  90.                 }
  91.             p = p->next;
  92.             }
  93.         }
  94.     writeBuf( 0, 0, size.x, 1, b );
  95. }
  96.  
  97. TRect TMenuBar::getItemRect( TMenuItem *item )
  98. {
  99.     TRect r( 1, 0, 1, 1 );
  100.     TMenuItem *p = menu->items;
  101.     while( True )
  102.         {
  103.         r.a.x = r.b.x;
  104.         if( p->name != 0 )
  105.             r.b.x += cstrlen(p->name) + 2;
  106.         if( p == item )
  107.             return r;
  108.         p = p->next;
  109.         }
  110. }
  111.  
  112. TStreamable *TMenuBar::build()
  113. {
  114.     return new TMenuBar( streamableInit );
  115. }
  116.  
  117. TMenuBar::TMenuBar( StreamableInit ) : TMenuView( streamableInit )
  118. {
  119. }
  120.  
  121.  
  122.