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

  1. /*------------------------------------------------------------*/
  2. /* filename -       thistory.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  THistory 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_THistory
  19. #define Uses_TKeys
  20. #define Uses_TRect
  21. #define Uses_TEvent
  22. #define Uses_TInputLine
  23. #define Uses_THistoryWindow
  24. #define Uses_opstream
  25. #define Uses_ipstream
  26. #include <tv.h>
  27.  
  28. #if !defined( __CTYPE_H )
  29. #include <ctype.h>
  30. #endif  // __CTYPE_H
  31.  
  32. #if !defined( __STRING_H )
  33. #include <String.h>
  34. #endif  // __STRING_H
  35.  
  36. #if !defined( __DOS_H )
  37. #include <Dos.h>
  38. #endif  // __DOS_H
  39.  
  40. #define cpHistory "\x16\x17"
  41.  
  42. THistory::THistory( const TRect& bounds,
  43.                     TInputLine *aLink,
  44.                     ushort aHistoryId) :
  45.     TView(bounds),
  46.     link( aLink ),
  47.     historyId( aHistoryId )
  48. {
  49.     options |= ofPostProcess;
  50.     eventMask |= evBroadcast;
  51. }
  52.  
  53. void THistory::shutDown()
  54. {
  55.     link = 0;
  56.     TView::shutDown();
  57. }
  58.  
  59. void THistory::draw()
  60. {
  61.     TDrawBuffer b;
  62.  
  63.     b.moveCStr( 0, icon, getColor(0x0102) );
  64.     writeLine( 0, 0, size.x, size.y, b );
  65. }
  66.  
  67. TPalette& THistory::getPalette() const
  68. {
  69.     static TPalette palette( cpHistory, sizeof( cpHistory )-1 );
  70.     return palette;
  71. }
  72.  
  73. void THistory::handleEvent( TEvent& event )
  74. {
  75.     THistoryWindow *historyWindow;
  76.     TRect  r, p;
  77.     ushort c;
  78.  
  79.     TView::handleEvent( event );
  80.     if( event.what == evMouseDown ||
  81.           ( event.what == evKeyDown &&
  82.             ctrlToArrow( event.keyDown.keyCode ) ==  kbDown &&
  83.             (link->state & sfFocused) != 0
  84.           )
  85.       )
  86.         {
  87.         link->select();
  88.         historyAdd( historyId, link->data );
  89.         r = link->getBounds();
  90.         r.a.x--;
  91.         r.b.x++;
  92.         r.b.y += 7;
  93.         r.a.y--;
  94.         p = owner->getExtent();
  95.         r.intersect( p );
  96.         r.b.y--;
  97.         historyWindow = initHistoryWindow( r );
  98.         if( historyWindow != 0 )
  99.             {
  100.             c = owner->execView( historyWindow );
  101.             if( c == cmOK )
  102.                 {
  103.                 char rslt[256];
  104.                 historyWindow->getSelection( rslt );
  105.                 strncpy( link->data, rslt, link->maxLen );
  106.                 link->selectAll( True );
  107.                 link->drawView();
  108.                 }
  109.             destroy( historyWindow );
  110.             }
  111.         clearEvent( event );
  112.         }
  113.     else
  114.         if( event.what == evBroadcast )
  115.             if( (event.message.command == cmReleasedFocus &&
  116.                  event.message.infoPtr ==  link) ||
  117.                 event.message.command ==  cmRecordHistory
  118.               )
  119.                 historyAdd( historyId, link->data );
  120. }
  121.  
  122. THistoryWindow *THistory::initHistoryWindow( const TRect& bounds )
  123. {
  124.     THistoryWindow *p = new THistoryWindow( bounds, historyId );
  125.     p->helpCtx = link->helpCtx;
  126.     return p;
  127. }
  128.  
  129. void THistory::write( opstream& os )
  130. {
  131.     TView::write( os );
  132.     os << link << historyId;
  133. }
  134.  
  135. void *THistory::read( ipstream& is )
  136. {
  137.     TView::read( is );
  138.     is >> link >> historyId;
  139.     return this;
  140. }
  141.  
  142. TStreamable *THistory::build()
  143. {
  144.     return new THistory( streamableInit );
  145. }
  146.  
  147. THistory::THistory( StreamableInit ) : TView( streamableInit )
  148. {
  149. }
  150.  
  151.  
  152.