Ayuda browse con imagenes

Ayuda browse con imagenes

Postby mastintin » Sat Jul 10, 2010 4:30 pm

He vuelto sobre el tema :
la idea es la siguiente , con una func
ion le digo que columna quiero que tenga imagenes .
Code: Select all  Expand view

HB_FUNC( BRWSETCOLBMP ) // hTableView, nIndex, lOnOff
{
   
    NSTableView * browse = ( NSTableView * ) hb_parnl( 1 );
   
    NSTableColumn * column =  [ [ browse tableColumns ] objectAtIndex :(hb_parnl( 2 ) - 1 ) ] ;
    NSImageCell  *imageCell = [[[NSImageCell alloc] init] autorelease];
    [column setDataCell : imageCell ]

}
 


luego en el tableview le digo que carge imagenes en vez string
Code: Select all  Expand view

- ( id ) tableView : ( NSTableView * ) aTableView objectValueForTableColumn : ( NSTableColumn * ) aTableColumn row : ( NSInteger ) rowIndex
{
    if( symFMH == NULL )
      symFMH = hb_dynsymSymbol( hb_dynsymFindName( "_FMH" ) );
   
   hb_vmPushSymbol( symFMH );
   hb_vmPushNil();
   hb_vmPushLong( ( LONG ) hWnd );
   hb_vmPushLong( WM_BRWVALUE );
   hb_vmPushLong( ( LONG ) aTableView );
   hb_vmPushLong( ( ( TableColumn * ) aTableColumn )->id );
   hb_vmPushLong( rowIndex );
   hb_vmDo( 5 );
   NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( -1 ) ? hb_parc( -1 ) : "" ] autorelease ];
    NSInteger * type =  [[aTableColumn dataCell ] type ] ;
    if( type  ==  NSImageCellType ) return [ [ NSImage alloc ] initWithContentsOfFile : string  ] ;    
    return [ [ NSImage alloc ] initWithContentsOfFile : string  ] ;
    return string ;
}  
@end

 


el problema esta en las lineas :
Code: Select all  Expand view

NSInteger * type =  [[aTableColumn dataCell ] type ] ;
    if( type  ==  NSImageCellType ) return [ [ NSImage alloc ] initWithContentsOfFile : string  ] ;    
 

no consiguo que me devuelva in integer para comparar .... que otras opciones tengo?
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Ayuda browse con imagenes

Postby mastintin » Sat Jul 10, 2010 9:50 pm

porfin me funciona :
Code: Select all  Expand view

- ( id ) tableView : ( NSTableView * ) aTableView objectValueForTableColumn : ( NSTableColumn * ) aTableColumn row : ( NSInteger ) rowIndex
{
    if( symFMH == NULL )
      symFMH = hb_dynsymSymbol( hb_dynsymFindName( "_FMH" ) );
   
   hb_vmPushSymbol( symFMH );
   hb_vmPushNil();
   hb_vmPushLong( ( LONG ) hWnd );
   hb_vmPushLong( WM_BRWVALUE );
   hb_vmPushLong( ( LONG ) aTableView );
   hb_vmPushLong( ( ( TableColumn * ) aTableColumn )->id );
   hb_vmPushLong( rowIndex );
   hb_vmDo( 5 );
   NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( -1 ) ? hb_parc( -1 ) : "" ] autorelease ];
   NSCell * celda = [aTableColumn dataCell ]  ;
    if( [celda type ] ==  0 )   return [ [ NSImage alloc ] initWithContentsOfFile : string  ] ;    

        return string ;
   
    }  
 


Image
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Ayuda browse con imagenes

Postby Antonio Linares » Sun Jul 11, 2010 7:13 am

Manuel,

He modificado el código así:
Code: Select all  Expand view
- ( id ) tableView : ( NSTableView * ) aTableView objectValueForTableColumn : ( NSTableColumn * ) aTableColumn row : ( NSInteger ) rowIndex
{
   NSString * string;

   if( symFMH == NULL )
      symFMH = hb_dynsymSymbol( hb_dynsymFindName( "_FMH" ) );
   
   hb_vmPushSymbol( symFMH );
   hb_vmPushNil();
   hb_vmPushLong( ( LONG ) hWnd );
   hb_vmPushLong( WM_BRWVALUE );
   hb_vmPushLong( ( LONG ) aTableView );
   hb_vmPushLong( ( ( TableColumn * ) aTableColumn )->id );
   hb_vmPushLong( rowIndex );
   hb_vmDo( 5 );
   
   string = [ [ [ NSString alloc ] initWithCString: ISCHAR( -1 ) ? hb_parc( -1 ) : "" ] autorelease ];
    
   if( ( NSCellType ) [ [ aTableColumn dataCell ] type ] == NSImageCellType )
      return [ [ [ NSImage alloc ] initWithContentsOfFile : string ] autorelease ];
   else 
      return string;
}  
 

Solo faltaría antes de intentar crear la imagen, ver si el nombre del fichero existe pues si no da error al no encontrarlo y no poder crear la imagen. Creo recordar que publicastes el código para detectar la existencia de un fichero, ando buscándolo :-)
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: Ayuda browse con imagenes

Postby mastintin » Sun Jul 11, 2010 8:40 am

He mirado una cosa no funciona bien porque :
Code: Select all  Expand view

 if( ( NSCellType ) [ [ aTableColumn dataCell ] type ] == NSImageCellType )
      return [ [ [ NSImage alloc ] initWithContentsOfFile : string ] autorelease ];
 

NSImageCellType tiene valor 3 y type devuelve valor 0 porque aun no tiene datos .

aun mejor pues sirve para mas tipos de NSCells y funciona :

Code: Select all  Expand view


    if( [ [ [aTableColumn dataCell ] className ] isEqual : @"NSImageCell" ] )   
        return [ [ [ NSImage alloc ] initWithContentsOfFile : string ] autorelease ];
 
 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Ayuda browse con imagenes

Postby Antonio Linares » Sun Jul 11, 2010 9:43 am

Manuel,

Realmente buena tu solución ! :-)

Es una gran satisfacción estar programando contigo en FiveMac :-)

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: Ayuda browse con imagenes

Postby mastintin » Sun Jul 11, 2010 4:19 pm

Antonio Linares wrote:Manuel,

Realmente buena tu solución ! :-)

Es una gran satisfacción estar programando contigo en FiveMac :-)

gracias!

La satisfación es mía al poder aportar algo a este gran proyecto .
faltaba el control de la existencia de imagen ....
Code: Select all  Expand view


 if( [ [ [aTableColumn dataCell ] className ] isEqual : @"NSImageCell" ] ) 
      {
          if( [[NSFileManager defaultManager] fileExistsAtPath: string ]  == YES ){
               return [ [ NSImage alloc ] initWithContentsOfFile : string  ] ;
          }
          else return (NULL) ;
      }
            return string ;


 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm


Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 2 guests