Nuevo control NSSegmentedControl
Posted: Tue Aug 24, 2010 9:45 pm
Es un control similar a los radio agrupados. Son varios botones horizontales que permiten una selección . Son estandard de mac .
la captura :
Es una implementación inicial que está funcionando perfectamente.
el codigo de la clase :
el codigo objective-c :
la captura :
Es una implementación inicial que está funcionando perfectamente.
el codigo de la clase :
Code: Select all
#include "FiveMac.ch"
//----------------------------------------------------------------------------//
CLASS TSegment FROM TControl
DATA bAction
METHOD New( nTop, nLeft, nWidth, nHeight, cPrompt, oWnd, bAction )
METHOD SetCount(nSegments) INLINE SEGMENTSETCOUNT(::hWnd,nSegments)
METHOD SetLabel(nSegments,cLabel) INLINE SEGMENTSETLABEL(::hWnd,nSegments,cLabel )
METHOD SelectedItem() INLINE SEGMENTSELECT(::Hwnd)
METHOD Click() INLINE ( eval(::bAction , ::SelectedItem()+1 ) )
METHOD SetStyle(nStyle) INLINE SEGMENTSETSTYLE(::hWnd,nStyle)
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nTop, nLeft, nWidth, nHeight, bAction ,oWnd) CLASS TSegment
DEFAULT nWidth := 90, nHeight := 30, oWnd := GetWndDefault()
::hWnd = SEGMENTCREATE ( nTop, nLeft, nWidth, nHeight, oWnd:hWnd )
::oWnd = oWnd
::bAction = bAction
oWnd:AddControl( Self )
return Self
Code: Select all
#import <Cocoa/Cocoa.h>
#define HB_DONT_DEFINE_BOOL
#include <hbapi.h>
NSView * GetView( NSWindow * window );
HB_FUNC( SEGMENTCREATE )
{
NSSegmentedControl * segment = [ [ NSSegmentedControl alloc ]
initWithFrame : NSMakeRect( hb_parnl( 2 ), hb_parnl( 1 ), hb_parnl( 3 ), hb_parnl( 4 ) ) ];
NSWindow * window = ( NSWindow * ) hb_parnl( 5 );
[ GetView( window ) addSubview : segment ];
[ segment setAction : @selector( BtnClick: ) ];
hb_retnl( ( LONG ) segment );
}
HB_FUNC( SEGMENTSETSTYLE )
{
NSSegmentedControl * segment = (NSSegmentedControl *) hb_parnl( 1 );
[ segment setSegmentStyle : hb_parnl( 2 ) ];
}
HB_FUNC( SEGMENTSETCOUNT )
{
NSSegmentedControl * segment = (NSSegmentedControl *) hb_parnl( 1 );
[segment setSegmentCount: hb_parnl( 2 ) ];
}
HB_FUNC( SEGMENTSETLABEL )
{
NSSegmentedControl * segment = (NSSegmentedControl *) hb_parnl( 1 );
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 3 ) ? hb_parc( 3 ) : "" ] autorelease ];
[ segment setLabel: string forSegment: hb_parnl( 2 ) ];
}
HB_FUNC( SEGMENTSETSELECT )
{
NSSegmentedControl * segment = (NSSegmentedControl *) hb_parnl( 1 );
[ segment setSelectedSegment: hb_parnl( 2 ) ];
}
HB_FUNC( SEGMENTSELECT )
{
NSSegmentedControl * segment = (NSSegmentedControl *) hb_parnl( 1 );
int numitem =[ segment selectedSegment ] ;
hb_retni(numitem);
}