Ayuda browse con imagenes

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

Ayuda browse con imagenes

Post by mastintin »

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

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

- ( 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

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

Post by mastintin »

porfin me funciona :

Code: Select all | Expand

- ( 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
Antonio Linares
Site Admin
Posts: 42516
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 75 times
Contact:

Re: Ayuda browse con imagenes

Post by Antonio Linares »

Manuel,

He modificado el código así:

Code: Select all | Expand

- ( 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
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Ayuda browse con imagenes

Post by mastintin »

He mirado una cosa no funciona bien porque :

Code: Select all | Expand

 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

    if( [ [ [aTableColumn dataCell ] className ] isEqual : @"NSImageCell" ] )           return [ [ [ NSImage alloc ] initWithContentsOfFile : string ] autorelease ];  
User avatar
Antonio Linares
Site Admin
Posts: 42516
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 75 times
Contact:

Re: Ayuda browse con imagenes

Post by Antonio Linares »

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
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Ayuda browse con imagenes

Post by mastintin »

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

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