home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / c / actlib11 / tvtools / inpasswd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  2.2 KB  |  95 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #define Uses_TButton
  4. #define Uses_TDeskTop
  5. #define Uses_TDialog
  6. #define Uses_TLabel
  7. #define Uses_TProgram
  8. #define Uses_TStreamable
  9. #define Uses_MsgBox
  10. #define Uses_TInputPasswd
  11. #include "tvtools.h"
  12. __link( RInputLine )
  13.  
  14.  
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <values.h>
  18. #include <stdlib.h>
  19. #include <strstream.h>
  20.  
  21.  
  22. // TInputPasswd
  23.  
  24. const char *const TInputPasswd::name = "TInputPasswd";
  25.  
  26. TStreamable *TInputPasswd::build()
  27. {
  28.   return new TInputPasswd( streamableInit );
  29. }
  30.  
  31. TInputPasswd::TInputPasswd( const TRect& bounds, int aMaxLen )
  32.              :TInputLine( bounds, aMaxLen )
  33. {
  34. }
  35.  
  36. TStreamableClass RInputPasswd( TInputPasswd::name,
  37.                                TInputPasswd::build,
  38.                                __DELTA(TInputPasswd)
  39.                              );
  40.  
  41.  
  42. void TInputPasswd::draw()
  43. {
  44.     char stars[256], *inData = data;
  45.     int len = strlen( inData );
  46.  
  47.     memset( stars, '*', len );
  48.     stars[len] = EOS;
  49.     data = stars;
  50.     TInputLine::draw();
  51.     data = inData;
  52. }
  53.  
  54.  
  55.  
  56. ushort inputPasswdBoxRect( const TRect &bounds,
  57.                            const char *Title,
  58.                            const char *aLabel,
  59.                            char *s,
  60.                            uchar limit )
  61. {
  62.     TDialog *dialog;
  63.     TView* control;
  64.     TRect r;
  65.  
  66.     dialog = new TDialog(bounds, Title);
  67.  
  68.     uchar x = 4 + strlen( aLabel );
  69.     r = TRect( x, 2, min(x + limit + 2, dialog->size.x - 3), 3 );
  70.     control = new TInputPasswd( r, limit );
  71.     dialog->insert( control );
  72.  
  73.     r = TRect( 2, 2, 3 + strlen(aLabel), 3 );
  74.     dialog->insert( new TLabel( r, aLabel, control ) );
  75.  
  76.     OKCancelButtons( dialog );
  77.  
  78.     dialog->selectNext(False);
  79.     *s = EOS;
  80.     return execDialog( dialog, s );
  81. }
  82.  
  83.  
  84. ushort inputPasswdBox( const char *Title, const char *aLabel, char *s, uchar limit )
  85. {
  86.     ushort len = max( strlen(aLabel) + 9 + limit, strlen(Title) + 10 );
  87.     len = min( len, 60 );
  88.     len = max( len , 24 );
  89.     TRect r(0, 0, len, 8);
  90.     r.move((TProgram::deskTop->size.x - r.b.x) / 2,
  91.            (TProgram::deskTop->size.y - r.b.y) / 2);
  92.     return inputPasswdBoxRect(r, Title, aLabel, s, limit);
  93. }
  94.  
  95.