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

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