home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / src / TFrame.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  5KB  |  206 lines

  1. /*
  2.  * TFrame.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_TFrame
  13. #define Uses_TDrawBuffer
  14. #define Uses_TWindow
  15. #define Uses_TRect
  16. #define Uses_TPoint
  17. #define Uses_TEvent
  18. #include <tvision/tv.h>
  19.  
  20. #include <string.h>
  21.  
  22. #define cpFrame "\x01\x01\x02\x02\x03"
  23.  
  24. TFrame::TFrame( const TRect& bounds ) : TView( bounds )
  25. {
  26.     growMode = gfGrowHiX + gfGrowHiY;
  27.     eventMask |= evBroadcast | evMouseUp;
  28. }
  29.  
  30. void TFrame::draw()
  31. {
  32.     ushort cFrame, cTitle;
  33.     short  f, i, l, width;
  34.     TDrawBuffer b;
  35.  
  36.     if( (state & sfDragging) != 0 )
  37.         {
  38.         cFrame = 0x0505;
  39.         cTitle = 0x0005;
  40.         f = 0;
  41.         }
  42.     else if( (state & sfActive) == 0 )
  43.         {
  44.         cFrame = 0x0101;
  45.         cTitle = 0x0002;
  46.         f = 0;
  47.         }
  48.     else
  49.         {
  50.         cFrame = 0x0503;
  51.         cTitle = 0x0004;
  52.         f = 9;
  53.         }
  54.  
  55.     cFrame = getColor(cFrame);
  56.     cTitle = getColor(cTitle);
  57.  
  58.     width = size.x;
  59.     l = width - 10;
  60.  
  61.     if( ( ((TWindow *)owner)->flags & (wfClose | wfZoom) ) != 0 )
  62.         l -= 6;
  63.     frameLine( b, 0, f, uchar(cFrame) );
  64.     if( ((TWindow *)owner)->number != wnNoNumber &&
  65.         ((TWindow *)owner)->number < 10
  66.       )
  67.         {
  68.         l -= 4;
  69.         if( ( ((TWindow *)owner)->flags & wfZoom ) != 0 )
  70.             i = 7;
  71.         else
  72.             i = 3;
  73.         b.putChar( width-i, ((TWindow *)owner)->number + '0' );
  74.         }
  75.  
  76.     if( owner != 0 )
  77.         {
  78.         const char *title = ((TWindow *)owner)->getTitle(l);
  79.         if( title != 0 )
  80.             {
  81.             l = min( cstrlen(title), width - 10 );
  82.             l = max( l, 0 );
  83.             i = (width - l) >> 1;
  84.             b.putChar( i-1, ' ' );
  85.             b.moveBuf( i, title, cTitle, l );
  86.             b.putChar( i+l, ' ' );
  87.             }
  88.         }
  89.  
  90.     if( (state & sfActive) != 0 )
  91.         {
  92.         if( ( ((TWindow *)owner)->flags & wfClose ) != 0 )
  93.             b.moveCStr( 2, closeIcon, cFrame );
  94.         if( ( ((TWindow *)owner)->flags & wfZoom ) != 0 )
  95.             {
  96.             TPoint minSize, maxSize;
  97.             owner->sizeLimits( minSize, maxSize );
  98.             if( owner->size == maxSize )
  99.                 b.moveCStr( width-5, unZoomIcon, cFrame );
  100.             else
  101.                 b.moveCStr( width-5, zoomIcon, cFrame );
  102.             }
  103.         }
  104.  
  105.     writeLine( 0, 0, size.x, 1, b );
  106.     for( i = 1; i <=  size.y - 2; i++ )
  107.         {
  108.         frameLine( b, i, f +  3, cFrame );
  109.         writeLine( 0, i, size.x, 1, b );
  110.         }
  111.     frameLine( b, size.y - 1, f +  6, cFrame );
  112.     if( (state & sfActive) != 0 )
  113.         if( ( ((TWindow *)owner)->flags & wfGrow ) != 0 )
  114.             b.moveCStr( width-2, dragIcon, cFrame );
  115.     writeLine( 0, size.y - 1, size.x, 1, b );
  116. }
  117.  
  118. TPalette& TFrame::getPalette() const
  119. {
  120.     static TPalette palette( cpFrame, sizeof( cpFrame )-1 );
  121.     return palette;
  122. }
  123.  
  124. void TFrame::dragWindow( TEvent& event, uchar mode )
  125. {
  126.     TRect  limits;
  127.     TPoint min, max;
  128.  
  129.     limits = owner->owner->getExtent();
  130.     owner->sizeLimits( min, max );
  131.     owner->dragView( event, owner->dragMode | mode, limits, min, max );
  132.     clearEvent( event );
  133. }
  134.  
  135. void TFrame::handleEvent( TEvent& event )
  136. {
  137.     TView::handleEvent(event);
  138.     if( event.what == evMouseDown  )
  139.         {
  140.         TPoint mouse = makeLocal( event.mouse.where );
  141.         if( mouse.y == 0 )
  142.             {
  143.             if( (((TWindow *)owner)->flags & wfClose ) != 0 &&
  144.                 (state & sfActive) &&
  145.                  mouse.x >= 2 &&
  146.                  mouse.x <= 4
  147.               )
  148.                 {
  149.                 while(mouseEvent( event, evMouse ))
  150.                     ;
  151.                 mouse = makeLocal( event.mouse.where );
  152.                 if( mouse.y == 0 && mouse.x >= 2 && mouse.x <= 4 )
  153.                     {
  154.                     event.what = evCommand;
  155.                     event.message.command = cmClose;
  156.                     event.message.infoPtr = owner;
  157.                     putEvent( event );
  158.                     clearEvent( event );
  159.                     }
  160.                 }
  161.             else
  162.                 if( (((TWindow *)owner)->flags & wfZoom) != 0 &&
  163.                     (state & sfActive) &&
  164.                     ((mouse.x >= size.x - 5 && mouse.x <= size.x - 3) ||
  165.                      (event.mouse.eventFlags & meDoubleClick)
  166.                     )
  167.                   )
  168.                     {
  169.                     event.what = evCommand;
  170.                     event.message.command = cmZoom;
  171.                     event.message.infoPtr = owner;
  172.                     putEvent( event );
  173.                     clearEvent( event );
  174.                     }
  175.                 else
  176.                     if( ( ((TWindow *)owner)->flags & wfMove ) != 0 )
  177.                         dragWindow( event, dmDragMove );
  178.             }
  179.         else
  180.             if( (mouse.x >= size.x - 2 && mouse.y >= size.y - 1 ) &&
  181.             (state & sfActive))
  182.                 if( ( ((TWindow *)owner)->flags & wfGrow ) != 0 )
  183.                     dragWindow( event, dmDragGrow );
  184.         }
  185. }
  186.  
  187. void TFrame::setState( ushort aState, Boolean enable )
  188. {
  189.     TView::setState( aState, enable );
  190.     if( (aState & (sfActive | sfDragging)) != 0 )
  191.         drawView();
  192. }
  193.  
  194. #if !defined(NO_STREAMABLE)
  195.  
  196. TStreamable *TFrame::build()
  197. {
  198.     return new TFrame( streamableInit );
  199. }
  200.  
  201. TFrame::TFrame( StreamableInit ) : TView( streamableInit )
  202. {
  203. }
  204.  
  205. #endif
  206.