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

  1. /*
  2.  * THistoryViewer.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_TKeys
  13. #define Uses_THistoryViewer
  14. #define Uses_TScrollBar
  15. #define Uses_TEvent
  16. #include <tvision/tv.h>
  17.  
  18. #include <ctype.h>
  19. #include <string.h>
  20.  
  21. #define cpHistoryViewer "\x06\x06\x07\x06\x06"
  22.  
  23. THistoryViewer::THistoryViewer( const TRect& bounds,
  24.                                 TScrollBar *aHScrollBar,
  25.                                 TScrollBar *aVScrollBar,
  26.                                 ushort aHistoryId) :
  27.     TListViewer(bounds, 1, aHScrollBar, aVScrollBar),
  28.     historyId( aHistoryId )
  29. {
  30.     setRange( historyCount( aHistoryId ) );
  31.     if( range > 1 )
  32.         focusItem( 1 );
  33.     hScrollBar->setRange( 0, historyWidth() - size.x + 3 );
  34. }
  35.  
  36. TPalette& THistoryViewer::getPalette() const
  37. {
  38.     static TPalette palette( cpHistoryViewer, sizeof( cpHistoryViewer )-1 );
  39.     return palette;
  40. }
  41.  
  42. void THistoryViewer::getText( char *dest, short item, short maxChars )
  43. {
  44.     const char *str = historyStr( historyId, item );
  45.     if( str != 0 )
  46.         {
  47.         strncpy( dest, str, maxChars );
  48.         dest[maxChars] = '\0';
  49.         }
  50.     else
  51.         *dest = EOS;
  52. }
  53.  
  54. void THistoryViewer::handleEvent( TEvent& event )
  55. {
  56.     if( (event.what == evMouseDown && (event.mouse.eventFlags & meDoubleClick) ) ||
  57.         (event.what == evKeyDown && event.keyDown.keyCode == kbEnter)
  58.       )
  59.         {
  60.         endModal( cmOK );
  61.         clearEvent( event );
  62.         }
  63.     else
  64.         if( (event.what ==  evKeyDown && event.keyDown.keyCode == kbEsc) ||
  65.             (event.what ==  evCommand && event.message.command ==  cmCancel)
  66.           )
  67.             {
  68.             endModal( cmCancel );
  69.             clearEvent( event );
  70.             }
  71.         else
  72.             TListViewer::handleEvent( event );
  73. }
  74.  
  75. int THistoryViewer::historyWidth()
  76. {
  77.     int width = 0;
  78.     int count = historyCount( historyId );
  79.     for( int i = 0; i < count; i++ )
  80.         {
  81.         int T = strlen( historyStr( historyId, i ) );
  82.         width = max( width, T );
  83.         }
  84.     return width;
  85. }
  86.