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

  1. /*------------------------------------------------------------*/
  2. /* filename -       stddlg.cpp                                */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  Member functions of following classes     */
  6. /*                      TFileInputLine                        */
  7. /*                      TSortedListBox                        */
  8. /*                      TSearchRec                            */
  9. /*                      TFileInfoPane                         */
  10. /*------------------------------------------------------------*/
  11.  
  12. /*------------------------------------------------------------*/
  13. /*                                                            */
  14. /*    Turbo Vision -  Version 1.0                             */
  15. /*                                                            */
  16. /*                                                            */
  17. /*    Copyright (c) 1991 by Borland International             */
  18. /*    All Rights Reserved.                                    */
  19. /*                                                            */
  20. /*------------------------------------------------------------*/
  21.  
  22.  
  23. #define Uses_MsgBox
  24. #define Uses_TKeys
  25. #define Uses_TFileInputLine
  26. #define Uses_TEvent
  27. #define Uses_TSortedListBox
  28. #define Uses_TSearchRec
  29. #define Uses_TFileInfoPane
  30. #define Uses_TDrawBuffer
  31. #define Uses_TFileDialog
  32. #define Uses_TSortedCollection
  33. #include <tv.h>
  34.  
  35. #if !defined( __DOS_H )
  36. #include <dos.h>
  37. #endif  // __DOS_H
  38.  
  39. #if !defined( __DIR_H )
  40. #include <Dir.h>
  41. #endif  // __DIR_H
  42.  
  43. #if !defined( __ERRNO_H )
  44. #include <Errno.h>
  45. #endif  // __ERRNO_H
  46.  
  47. #if !defined( __IO_H )
  48. #include <io.h>
  49. #endif  // __IO_H
  50.  
  51. #if !defined( __STDIO_H )
  52. #include <Stdio.h>
  53. #endif  // __STDIO_H
  54.  
  55. #if !defined( __CTYPE_H )
  56. #include <ctype.h>
  57. #endif  // __CTYPE_H
  58.  
  59. #if !defined( __STRING_H )
  60. #include <String.h>
  61. #endif  // __STRING_H
  62.  
  63. #if !defined( __STDLIB_H )
  64. #include <StdLib.h>
  65. #endif  // __STDLIB_H
  66.  
  67. #if !defined( __LIMITS_H )
  68. #include <Limits.h>
  69. #endif  // __LIMITS_H
  70.  
  71. char &shiftKeys = *(char far *)MK_FP( 0x40, 0x17 );
  72.  
  73. void fexpand( char * );
  74.  
  75. #define cpInfoPane "\x1E"
  76.  
  77. TFileInputLine::TFileInputLine( const TRect& bounds, short aMaxLen ) :
  78.     TInputLine( bounds, aMaxLen )
  79. {
  80.     eventMask = eventMask | evBroadcast;
  81. }
  82.  
  83. void TFileInputLine::handleEvent( TEvent& event )
  84. {
  85.     TInputLine::handleEvent(event);
  86.     if( event.what == evBroadcast &&
  87.         event.message.command == cmFileFocused &&
  88.         !(state & sfSelected)
  89.       )
  90.         {
  91.         if( (((TSearchRec *)event.message.infoPtr)->attr & FA_DIREC) != 0 )
  92.             {
  93.             strcpy( data, ((TSearchRec *)event.message.infoPtr)->name );
  94.             strcat( data, "\\" );
  95.             strcat( data, ((TFileDialog *)owner)->wildCard );
  96.             }
  97.         else
  98.             strcpy( data, ((TSearchRec *)event.message.infoPtr)->name );
  99.         drawView();
  100.         }
  101. }
  102.  
  103. TSortedListBox::TSortedListBox( const TRect& bounds,
  104.                                 ushort aNumCols,
  105.                                 TScrollBar *aScrollBar) :
  106.     TListBox(bounds, aNumCols, aScrollBar),
  107.     searchPos( -1 ),
  108.     shiftState( 0 )
  109. {
  110.     showCursor();
  111.     setCursor(1, 0);
  112. }
  113.  
  114. static Boolean equal( const char *s1, const char *s2, ushort count)
  115. {
  116.     return Boolean( strnicmp( s1, s2, count ) == 0 );
  117. }
  118.  
  119. void TSortedListBox::handleEvent(TEvent& event)
  120. {
  121. char curString[256], newString[256];
  122. void* k;
  123. int value, oldPos, oldValue;
  124.  
  125.     oldValue = focused;
  126.     TListBox::handleEvent( event );
  127.     if( oldValue != focused )
  128.         searchPos = USHRT_MAX;
  129.     if( event.what == evKeyDown )
  130.         {
  131.         if( event.keyDown.charScan.charCode != 0 )
  132.             {
  133.             value = focused;
  134.             if( value < range )
  135.                 getText( curString, value, 255 );
  136.             else
  137.                 *curString = EOS;
  138.             oldPos = searchPos;
  139.             if( event.keyDown.keyCode == kbBack )
  140.                 {
  141.                 if( searchPos == USHRT_MAX )
  142.                     return;
  143.                 searchPos--;
  144.                 if( searchPos == USHRT_MAX )
  145.                     shiftState = shiftKeys;
  146.                 curString[searchPos] = EOS;
  147.                 }
  148.             else if( (event.keyDown.charScan.charCode == '.') )
  149.                 {
  150.                 char *loc = strchr( curString, '.' );
  151.                 if( loc == 0 )
  152.                     searchPos = USHRT_MAX;
  153.                 else
  154.                     searchPos = ushort(loc - curString);
  155.                 }
  156.             else
  157.                 {
  158.                 searchPos++;
  159.                 if( searchPos == 0 )
  160.                     shiftState = shiftKeys;
  161.                 curString[searchPos] = event.keyDown.charScan.charCode;
  162.                 curString[searchPos+1] = EOS;
  163.                 }
  164.             k = getKey(curString);
  165.             list()->search( k, value );
  166.             if( value < range )
  167.                 {
  168.                 getText( newString, value, 255 );
  169.                 if( equal( curString, newString, searchPos+1 ) )
  170.                     {
  171.                     if( value != oldValue )
  172.                         {
  173.                         focusItem(value);
  174.                         setCursor( cursor.x+searchPos, cursor.y );
  175.                         }
  176.                     else
  177.                         setCursor(cursor.x+(searchPos-oldPos), cursor.y );
  178.                     }
  179.                 else
  180.                     searchPos = oldPos;
  181.                 }
  182.             else
  183.                 searchPos = oldPos;
  184.             if( searchPos != oldPos ||
  185.                 isalpha( event.keyDown.charScan.charCode )
  186.               )
  187.                 clearEvent(event);
  188.             }
  189.         }
  190. }
  191.  
  192. void* TSortedListBox::getKey( const char *s )
  193. {
  194.     return (void *)s;
  195. }
  196.  
  197. void TSortedListBox::newList( TSortedCollection *aList )
  198. {
  199.     TListBox::newList( aList );
  200.     searchPos = -1;
  201. }
  202.  
  203. TFileInfoPane::TFileInfoPane( const TRect& bounds ) :
  204.     TView(bounds)
  205. {
  206.     eventMask |= evBroadcast;
  207. }
  208.  
  209. void TFileInfoPane::draw()
  210. {
  211.     Boolean PM;
  212.     TDrawBuffer b;
  213.     ushort  color;
  214.     ftime *time;
  215.     char path[MAXPATH];
  216.  
  217.     strcpy( path, ((TFileDialog *)owner)->directory );
  218.     strcat( path, ((TFileDialog *)owner)->wildCard );
  219.     fexpand( path );
  220.  
  221.     color = getColor(0x01);
  222.     b.moveChar( 0, ' ', color, size.x );
  223.     b.moveStr( 1, path, color );
  224.     writeLine( 0, 0, size.x, 1, b );
  225.  
  226.     b.moveChar( 0, ' ', color, size.x );
  227.     b.moveStr( 1, file_block.name, color );
  228.  
  229.     if( *(file_block.name) != EOS )
  230.         {
  231.  
  232.         char buf[10];
  233.         ltoa( file_block.size, buf, 10 );
  234.         b.moveStr( 14, buf, color );
  235.  
  236.         time = (ftime *) &file_block.time;
  237.         b.moveStr( 25, months[time->ft_month], color );
  238.  
  239.         if( time->ft_day >= 10 )
  240.             itoa( time->ft_day, buf, 10 );
  241.         else
  242.             {
  243.             buf[0] = '0';
  244.             itoa( time->ft_day, buf+1, 10 );
  245.             }
  246.         b.moveStr( 29, buf, color );
  247.  
  248.         b.putChar( 31, ',' );
  249.  
  250.         itoa( time->ft_year+1980, buf, 10 );
  251.         b.moveStr( 32, buf, color );
  252.  
  253.         PM = Boolean(time->ft_hour >= 12 );
  254.         time->ft_hour %= 12;
  255.  
  256.         if( time->ft_hour == 0 )
  257.             time->ft_hour = 12;
  258.  
  259.         if( time->ft_hour >= 10 )
  260.             itoa( time->ft_hour, buf, 10 );
  261.         else
  262.             {
  263.             buf[0] = '0';
  264.             itoa( time->ft_hour, buf+1, 10 );
  265.             }
  266.         b.moveStr( 38, buf, color );
  267.         b.putChar( 40, ':' );
  268.  
  269.         if( time->ft_min >= 10 )
  270.             itoa( time->ft_min, buf, 10 );
  271.         else
  272.             {
  273.             buf[0] = '0';
  274.             itoa( time->ft_min, buf+1, 10 );
  275.             }
  276.         b.moveStr( 41, buf, color );
  277.  
  278.         if( PM )
  279.             b.moveStr( 43, pmText, color );
  280.         else
  281.             b.moveStr( 43, amText, color );
  282.         }
  283.  
  284.     writeLine(0, 1, size.x, 1, b );
  285.     b.moveChar( 0, ' ', color, size. x);
  286.     writeLine( 0, 2, size.x, size.y-2, b);
  287. }
  288.  
  289. TPalette& TFileInfoPane::getPalette() const
  290. {
  291.     static TPalette palette( cpInfoPane, sizeof( cpInfoPane )-1 );
  292.     return palette;
  293. }
  294.  
  295. void TFileInfoPane::handleEvent( TEvent& event )
  296. {
  297.     TView::handleEvent(event);
  298.     if( event.what == evBroadcast && event.message.command == cmFileFocused )
  299.         {
  300.         file_block = *((TSearchRec *)(event.message.infoPtr));
  301.         drawView();
  302.         }
  303. }
  304.  
  305. TStreamable *TFileInfoPane::build()
  306. {
  307.     return new TFileInfoPane( streamableInit );
  308. }
  309.