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

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