Get para password

Get para password

Postby mastintin » Sun Jul 04, 2010 8:14 pm

Seguro que se puede implementar mucho mejor pero he conseguido hacerlo funcionar asi :
He duplicado la clase get y le he renombrado a Sget luego le he cambiado las llamadas a las funciones de abajo.

Code: Select all  Expand view

#import <Cocoa/Cocoa.h>

#define HB_DONT_DEFINE_BOOL
#include <hbapi.h>
#include <hbvm.h>
#include <fmsgs.h> // FiveMac messages

NSView * GetView( NSWindow * window );

static PHB_SYMB symFMH = NULL;

@interface SGet : NSSecureTextField
{
   @public NSWindow * hWnd; 
}
- (BOOL) textShouldEndEditing : ( NSText * ) text;
@end

@implementation SGet
- (BOOL) textShouldEndEditing : ( NSText * ) text
{
   if( symFMH == NULL )
      symFMH = hb_dynsymSymbol( hb_dynsymFindName( "_FMH" ) );
   
   hb_vmPushSymbol( symFMH );
   hb_vmPushNil();
   hb_vmPushLong( ( LONG ) hWnd );
   hb_vmPushLong( WM_GETVALID );
   hb_vmPushLong( ( LONG ) self );
   hb_vmDo( 3 );

   return hb_parl( -1 );   
}
@end

HB_FUNC( SGETCREATE )
{
   SGet * edit = [ [ SGet alloc ]
              initWithFrame : NSMakeRect( hb_parnl( 2 ), hb_parnl( 1 ), hb_parnl( 3 ), hb_parnl( 4 ) ) ];
   NSWindow * window = ( NSWindow * ) hb_parnl( 5 );

   [ GetView( window ) addSubview : edit ];
   edit->hWnd = window;
   
   hb_retnl( ( LONG ) edit );
}  

HB_FUNC( SGETSETTEXT )
{
   NSSecureTextField  * get = ( NSSecureTextField  * ) hb_parnl( 1 );
   NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 2 ) ? hb_parc( 2 ) : "" ] autorelease ];
   
   [ get setStringValue : string ];
}  

HB_FUNC( SGETGETTEXT ) // hGet --> cText
{
   NSSecureTextField  * get = ( NSSecureTextField  * ) hb_parnl( 1 );
   NSString * string = [ get stringValue ];
   
   hb_retc( [ string cStringUsingEncoding : NSASCIIStringEncoding ] );
}  
 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Get para password

Postby Antonio Linares » Sun Jul 04, 2010 9:20 pm

Manuel,

Tu implementación es correcta, lo único es que como la clase NSSecureTextField hereda de la Clase NSTextField, en realidad solo necesitamos la función SGetCreate() y es apropiado el crear sgets.m para separar la Clase SGet de la Get.

Para mantener la máxima compatibilidad con FWH, lo que hacemos es añadir una nueva claúsula PASSWORD para el GET y desde el constructor de TGet se decide si llamar a GetCreate() ó a SGetCreate().

Asi queda el comando GET ahora:
Code: Select all  Expand view

 #xcommand @ <nRow>, <nCol> GET [ <oGet> VAR ] <uVar> ;
               [ OF <oWnd> ] ;
               [ SIZE <nWidth>, <nHeight> ] ;
               [ VALID <uValid> ] ;
               [ <update: UPDATE> ] ;
               [ <password: PASSWORD> ] ;  
          => ;
               [ <oGet> := ] TGet():New( <nRow>, <nCol>, <nWidth>, <nHeight>,;
                                         <oWnd>, bSETGET(<uVar>), [\{||(<uValid>)\}],;
                                         <.update.>, <.password.> )
 

En unos minutos publicamos un nuevo build de FiveMac con todos los cambios. Gracias! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Get para password

Postby Antonio Linares » Sun Jul 04, 2010 9:28 pm

Hay una pega que solucionar con los GETs y es que hasta que no pierden el foco, no asignan a su variable relacionada su texto.

Esto se puede comprobar en el ejemplo login.prg. Hasta que no se cambia el foco del GET con PASSWORD al primer GET, la variable cPassw no se actualiza. Hay que localizar un evento que se genere cada vez que se pulsa una tecla en el GET.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 3 guests