home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / src / TMenuBar.cpp < prev    next >
C/C++ Source or Header  |  1999-05-21  |  3KB  |  116 lines

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