Manuel,
Super bien! ![]()
El tag lo podemos usar como el equivalente del nId de los controles de FiveWin ![]()
Ando pensando ahora como hacer todo esto genérico, e implementar el REDEFINE de FiveWin
Manuel,
Super bien! ![]()
El tag lo podemos usar como el equivalente del nId de los controles de FiveWin ![]()
Ando pensando ahora como hacer todo esto genérico, e implementar el REDEFINE de FiveWin
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" ];
}#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 nilManuel,
Voy a salir ahora con la familia, pero te cuento la que estoy liando ![]()
He cogido el prototipo de la Clase View en windows.m y lo he copiado a nibs.m y ahora le asigno un View de los "nuestros" a la ventana del recurso.
Esta funcionando bien, lo único es que ahora pierdo lo controles al cambiar el View. Deberiamos ver si hay una forma de portar los controles de un NSView a otro como hacemos en Windows con SetParent() ![]()
Luego seguimos...
#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#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 );
}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 );
}Si no entiendo mal el codigo lo que intentas es quedarte con la ventana y una vez la tienes crear nuestro propio view de codigo y ir insertandole los controles copiados del view del nib . ¿No ?
¿ Puede ser que al remover los objetos si estas procesando el nsview "primario" se carge los demas objetos ? .
Manuel,
Si, esa es la idea. La cuestion es comprobar si falla por eso y ver una forma de solucionarlo.
Tal vez exista un método para clonar un objeto...
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 );
}
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 );
} REDEFINE BUTTON oBtn ID 20 OF oWnd ACTION MsgInfo( "Button click!" )
Hombre, dificil seguirlos
Aun asi me da gusto que se este avanzando pronto.
Saludos
Osvaldo Ramirez
