[Spiderape-cvs] SF.net SVN: spiderape: [55] plugins/ncurses
Status: Beta
Brought to you by:
sgbeal
|
From: <sg...@us...> - 2007-10-05 15:07:18
|
Revision: 55
http://spiderape.svn.sourceforge.net/spiderape/?rev=55&view=rev
Author: sgbeal
Date: 2007-10-05 08:07:07 -0700 (Fri, 05 Oct 2007)
Log Message:
-----------
NCursesPanel subclassing appears to work.
Modified Paths:
--------------
plugins/ncurses/NCursesPanel.cpp
plugins/ncurses/NCursesPanel.js
plugins/ncurses/NCursesWindow.cpp
plugins/ncurses/NCursesWindow.hpp
Modified: plugins/ncurses/NCursesPanel.cpp
===================================================================
--- plugins/ncurses/NCursesPanel.cpp 2007-10-05 12:54:45 UTC (rev 54)
+++ plugins/ncurses/NCursesPanel.cpp 2007-10-05 15:07:07 UTC (rev 55)
@@ -1,4 +1,4 @@
-#error "DO NOT USE THIS CODE! It doesn't work!"
+//#error "DO NOT USE THIS CODE! It doesn't work!"
#include <map>
#include <sf.net/ape/plugin.hpp>
@@ -40,26 +40,69 @@
namespace nc {
NCursesPanel::NCursesPanel( JSContext * cx, JSObject * obj, uint32 argc, jsval * argv, jsval * rval )
- : NCursesWindow( cx, obj, argc, argv, rval )
+ : NCursesWindow( cx, obj, 0, 0, 0 )
{
- jsval pv = JSVAL_NULL;
- jsval av[1] = { this->window_handle_jsval() };
- nc_new_panel( cx, JS_GetGlobalObject(cx), 1, av, &pv );
- PANEL * p = jsval_to<PANEL>( cx, pv );
- if( ! p )
+ if( 1 == argc )
+ { // ctor(WINDOW)
+ if( WINDOW * ncw = jsval_to_WINDOW(cx,argv[0]) )
+ { // ctor(WINDOW)
+ this->set_window( ncw );
+ jsval av[1] = {
+ this->window_handle_jsval()
+ };
+ jsval pv = JSVAL_NULL;
+ nc_new_panel( cx, JS_GetGlobalObject(cx), 1, av, &pv );
+ PANEL * p = jsval_to_PANEL( cx, pv );
+ if( ! p )
+ {
+ throw ape::exception( cx, "%s(WINDOW) ctor: nc_new_panel(WINDOW) failed!",
+ NCursesPanel::strings::class_name);
+ }
+ this->set_window( ncw );
+ this->set_panel( p );
+ }
+ //else if( NCursesWindow * par = ape::jsval_to<NCursesWindow>( cx, argv[0] ) )
+ // we can't do this like i want to because of WINDOW ownership issues.
+ else
+ {
+ throw new ape::exception( cx, "%s(WINDOW) ctor: requires a WINDOW argument!",
+ NCursesPanel::strings::class_name );
+ }
+ }
+ else if( 4 == argc )
+ { // ctor(lines,cols,width,height)
+ jsval wjv = JSVAL_NULL;
+ nc_newwin( cx, JS_GetGlobalObject(cx), argc, argv, &wjv );
+ WINDOW * w = jsval_to_WINDOW( cx, wjv );
+ if( ! w )
+ {
+ throw new ape::exception( cx, "%s(lines,cols,width,height) ctor: nc_newwin() failed!",
+ NCursesPanel::strings::class_name );
+ }
+ this->set_window( w );
+ jsval pjv = JSVAL_NULL;
+ jsval av[1] = { wjv };
+ nc_new_panel( cx, JS_GetGlobalObject(cx), 1, av, &pjv );
+ PANEL * p = jsval_to_PANEL( cx, pjv );
+ if( ! p )
+ {
+ throw new ape::exception( cx, "%s(lines,cols,width,height) ctor: nc_new_panel() failed!",
+ NCursesPanel::strings::class_name );
+ }
+ this->set_panel( p );
+ }
+ else
{
- throw ape::exception( cx, "NCursesPanel::ctor couldn't get PANEL handle." );
+ throw new ape::exception( cx,
+ "%s() ctor got no valid arguments! RTFM!",
+ NCursesPanel::strings::class_name );
}
- this->set_panel( p );
ape::bind::bind_native<NCursesPanel>( cx, obj, this );
- //ape::bind::bind_native<PANEL>( cx, pv, p );
-// this->add_function("tryit",
-// "function(){nc_hide_panel(");
}
NCursesPanel::~NCursesPanel()
{
- ape::bind::unbind_native<NCursesPanel>( cx, obj, this );
+ ape::bind::unbind_native<NCursesPanel>( this->js_context(), this->js_object(), this );
}
char const * NCursesPanel::strings::class_name = "NCursesPanel";
Modified: plugins/ncurses/NCursesPanel.js
===================================================================
--- plugins/ncurses/NCursesPanel.js 2007-10-05 12:54:45 UTC (rev 54)
+++ plugins/ncurses/NCursesPanel.js 2007-10-05 15:07:07 UTC (rev 55)
@@ -34,7 +34,7 @@
}
}
-var root = new NCursesWindow(nc_new_panel(nc_newwin(0,0,0,0)));
+var root = new NCursesPanel(0,0,0,0);
root.background( ascii('~') | nc_color('black','yellow'));
nc_curs_set(0);
nc_capture_cout(root.ncwindow());
@@ -47,14 +47,14 @@
var woffset = {x:5,y:2};
var wpos = {y:3,x:3,incr:function(){this.x+=woffset.x;this.y+=woffset.y}};
var cpnl = null;
-curpnl = wins[pos] = new NCursesWindow( nc_new_panel(nc_newwin(rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x)));
+curpnl = wins[pos] = new NCursesPanel( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x );
wpos.incr();
curpnl.background( nc_color('white',pos) );
curpnl.addString( "geom=="+curpnl.geometry().toSource() );
curpnl.refresh();
pos = 'red';
-curpnl = wins[pos] = new NCursesWindow(nc_new_panel(nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x )));
+curpnl = wins[pos] = new NCursesPanel( nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x ) );
wpos.incr();
curpnl.background( nc_color('white',pos) );
curpnl.addString( "geom=="+curpnl.geometry().toSource() );
@@ -64,14 +64,15 @@
pos = 'cyan';
-curpnl = wins[pos] = new NCursesWindow(nc_new_panel(nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x )));
+curpnl = wins[pos] = new NCursesPanel( nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x ) );
wpos.incr();
curpnl.background( nc_color('black',pos) );
curpnl.addString( "geom=="+curpnl.geometry().toSource() );
curpnl.refresh();
pos = 'green';
-curpnl = wins[pos] = new NCursesWindow(nc_new_panel(nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x )));
+curpnl = wins[pos] = new NCursesPanel( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x );
+ //new NCursesWindow(nc_new_panel(nc_newwin( rootgeom.h / 2, rootgeom.w / 2, wpos.y, wpos.x )));
wpos.incr();
curpnl.background( nc_color('black',pos) );
curpnl.addString( "geom=="+curpnl.geometry().toSource() );
@@ -98,6 +99,8 @@
curpnl = wins['cyan'];
+print("instanceof NCursesWindow ??? ==",curpnl instanceof NCursesWindow);
+
//curpnl.moveWindow( rootgeom.h/3, 1 );
//curpnl.hide();
// var bogo = new NCursesWindow(1,1,0,0);
Modified: plugins/ncurses/NCursesWindow.cpp
===================================================================
--- plugins/ncurses/NCursesWindow.cpp 2007-10-05 12:54:45 UTC (rev 54)
+++ plugins/ncurses/NCursesWindow.cpp 2007-10-05 15:07:07 UTC (rev 55)
@@ -159,13 +159,15 @@
{
NCursesWindow::shared_init(cx);
if( (! argc) && rval )
- {
+ { // called via empty JS ctor
this->m_ncwin = stdscr;
}
else if( argc || argv || rval )
{
this->setup( cx, obj, argc, argv );
}
+ // else assume subclass will run setup().
+
if( rval ) *rval = this->js_value();
ape::bind::bind_native<NCursesWindow>( this->js_context(),
this->js_value(),
@@ -609,8 +611,8 @@
(*it).first.c_str() );
}
}
- //return NCursesPanel::init_context(cx,obj);
- return JS_TRUE;
+ return NCursesPanel::init_context(cx,obj);
+ //return JS_TRUE;
}
Modified: plugins/ncurses/NCursesWindow.hpp
===================================================================
--- plugins/ncurses/NCursesWindow.hpp 2007-10-05 12:54:45 UTC (rev 54)
+++ plugins/ncurses/NCursesWindow.hpp 2007-10-05 15:07:07 UTC (rev 55)
@@ -167,7 +167,9 @@
/** Sets this object's PANEL, which must be registered
with SpiderApe's native binding system, using the same
- jsval as the one used by this->window_handle().
+ jsval as the one used by this->window_handle(). p MUST
+ be associated with this->window_handle() or results
+ are undefined.
*/
void set_panel( PANEL * p );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|