Super bien!
![Smile :-)](./images/smilies/icon_smile.gif)
El tag lo podemos usar como el equivalente del nId de los controles de FiveWin
![Smile :-)](./images/smilies/icon_smile.gif)
Ando pensando ahora como hacer todo esto genérico, e implementar el REDEFINE de FiveWin
Code: Select all | Expand
HB_FUNC( WINDOWCONTROLCREATE ) // hWnd
{
WindowController * mynibWindow = [[WindowController alloc]
initWithWindowNibName:@"MainMenu"];
[mynibWindow showWindow: nil];
NSWindow * ventana = [mynibWindow window] ;
hb_retnl( ( LONG ) ventana );
}
HB_FUNC( LLAMABOTON ) // hWnd
{
NSWindow * ventana = ( NSWindow * ) hb_parnl( 1 );
NSView * myview = [ventana contentView ] ;
NSButton * boton = ( NSButton * ) [myview viewWithTag : hb_parnl( 2 ) ];
[boton setTitle : @"LA monda" ];
}
Code: Select all | Expand
#include "FiveMac.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd
@ 20, 20 BUTTON "Another" ACTION Another()
ACTIVATE WINDOW oWnd
return nil
function Another()
local oWnd
DEFINE WINDOW oWnd RESOURCE "HudWindow"
ACTIVATE WINDOW oWnd
return nil
Code: Select all | Expand
#include "FiveMac.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd
@ 20, 20 BUTTON "Another" ACTION Another()
ACTIVATE WINDOW oWnd
return nil
function Another()
local oWnd
DEFINE WINDOW oWnd RESOURCE "HudWindow"
ACTIVATE WINDOW oWnd ;
ON CLICK oWnd:SetText( Time() ) // MsgInfo( "click" )
return nil
Code: Select all | Expand
#import <Cocoa/Cocoa.h>
#define HB_DONT_DEFINE_BOOL
#include <hbapi.h>
// NSView * GetView( NSWindow * window );
@interface View : NSView
{
@public NSWindow * hWnd;
}
- (BOOL) windowShouldClose : ( NSNotification * ) notification;
- (void) windowWillClose: ( NSNotification * ) notification;
- (void) mouseDown : ( NSEvent * ) theEvent;
- (void) mouseMoved : ( NSEvent * ) theEvent;
- (void) keyDown : ( NSEvent * ) theEvent;
- (void) MenuItem : ( id ) sender;
- (void) BtnClick : ( id ) sender;
- (void) CbxChange : ( id ) sender;
- (void) ChkClick : ( id ) sender;
- (void) RadClick : ( id ) sender;
- (void) TbrClick : ( id ) sender;
- (void) OnTimerEvent : ( NSTimer * ) timer;
- (void) SliderChanged : (id) sender;
@end
@interface WindowController : NSWindowController
{
}
- ( void ) BtnClick : ( id ) sender;
@end
@implementation WindowController
- ( void ) BtnClick : ( id ) sender;
{
NSRunAlertPanel( @"click", @"", @"OK", NULL, NULL );
}
@end
HB_FUNC( WNDFROMNIB )
{
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
WindowController * wndController = [ [ WindowController alloc ] initWithWindowNibName : string ];
NSWindow * window = [ wndController window ];
NSArray * controls = [ [ window contentView ] subviews ];
int i;
View * view = [ [ View alloc ] init ];
view->hWnd = window;
[ window setContentView : view ];
[ window setDelegate : view ];
for( i = 0; i < [ controls count ]; i++ )
{
NSControl * control = [ controls objectAtIndex : i ];
NSString * className = [ control className ];
if( [ className isEqual : @"NSButton" ] )
{
NSButton * button = ( NSButton * ) control;
[ button setAction : @selector( BtnClick: ) ];
}
}
hb_retnl( ( LONG ) window );
}
Code: Select all | Expand
HB_FUNC( WNDFROMNIB )
{
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
NSWindowController * wndController = [ [ NSWindowController alloc ] initWithWindowNibName : string ];
NSWindow * window = [ wndController window ];
NSArray * controls = [ [ window contentView ] subviews ];
int i;
View * view = [ [ View alloc ] init ];
view->hWnd = window;
for( i = 0; i < [ controls count ]; i++ )
{
NSControl * control = [ controls objectAtIndex : i ];
NSString * className = [ control className ];
if( [ className isEqual : @"NSButton" ] )
{
NSButton * button = ( NSButton * ) control;
[ button setAction : @selector( BtnClick: ) ];
}
[ control retain ];
[ view addSubview : control ];
[ control removeFromSuperview ];
}
[ window setContentView : view ];
[ window setDelegate : view ];
hb_retnl( ( LONG ) window );
}
Code: Select all | Expand
HB_FUNC( WNDFROMNIB )
{
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
NSWindowController * wndController = [ [ NSWindowController alloc ] initWithWindowNibName : string ];
NSWindow * window = [ wndController window ];
NSArray * controls = [ [ window contentView ] subviews ];
View * view = [ [ View alloc ] init ];
[ window setContentView : view ];
[ window setDelegate : view ];
view->hWnd = window;
while( [ controls count ] > 0 )
{
NSControl * control = [ controls objectAtIndex : 0 ];
NSString * className = [ control className ];
[ view addSubview : control ];
if( [ className isEqual : @"NSButton" ] )
{
NSButton * button = ( NSButton * ) control;
[ button setAction : @selector( BtnClick: ) ];
}
}
hb_retnl( ( LONG ) window );
}
Code: Select all | Expand
HB_FUNC( WNDFROMNIB )
{
NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
NSWindowController * wndController = [ [ NSWindowController alloc ] initWithWindowNibName : string ];
NSWindow * window = [ wndController window ];
NSView * myview = [ window contentView ] ;
NSArray * controls = [ [ window contentView ] subviews ];
View * view = [ [ View alloc ] init ];
[ window setContentView : view ];
[ window setDelegate : view ];
view->hWnd = window;
[ view addSubview : myview ];
while( [ controls count ] > 0 )
{
NSControl * control = [ controls objectAtIndex : 0 ];
NSString * className = [ control className ];
if( [ className isEqual : @"NSButton" ] )
{
NSButton * button = ( NSButton * ) control;
[ button setAction : @selector( BtnClick: ) ];
}
}
hb_retnl( ( LONG ) window );
}
Code: Select all | Expand
REDEFINE BUTTON oBtn ID 20 OF oWnd ACTION MsgInfo( "Button click!" )