[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/ContextMenu.cpp te...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/ContextMenu.cpp te... |
Date: |
Wed, 07 Mar 2007 22:47:53 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/03/07 22:47:53
Modified files:
. : ChangeLog
server/asobj : ContextMenu.cpp
testsuite/actionscript.all: ContextMenu.as
Log message:
* server/asobj/ContextMenu.cpp: Some more stubs.
* testsuite/actionscript.all/ContextMenu.as: Some more tests.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2571&r2=1.2572
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/ContextMenu.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/ContextMenu.as?cvsroot=gnash&r1=1.8&r2=1.9
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2571
retrieving revision 1.2572
diff -u -b -r1.2571 -r1.2572
--- ChangeLog 7 Mar 2007 19:46:46 -0000 1.2571
+++ ChangeLog 7 Mar 2007 22:47:52 -0000 1.2572
@@ -1,5 +1,7 @@
2007-03-07 Sandro Santilli <address@hidden>
+ * server/asobj/ContextMenu.cpp: Some more stubs.
+ * testsuite/actionscript.all/ContextMenu.as: Some more tests.
* server/as_value.cpp (to_bool) don't choke
when converting a movieclip value to a boolean.
* testsuite/actionscript.all/Boolean.as:
Index: server/asobj/ContextMenu.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/ContextMenu.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/asobj/ContextMenu.cpp 4 Mar 2007 01:39:01 -0000 1.7
+++ server/asobj/ContextMenu.cpp 7 Mar 2007 22:47:53 -0000 1.8
@@ -26,76 +26,157 @@
#include "fn_call.h"
#include "smart_ptr.h" // for boost intrusive_ptr
#include "builtin_function.h" // need builtin_function
+#include "GnashException.h"
namespace gnash {
-void contextmenu_copy(const fn_call& fn);
-void contextmenu_hidebuiltinitems(const fn_call& fn);
-void contextmenu_ctor(const fn_call& fn);
-
-static void
-attachContextMenuInterface(as_object& o)
-{
- o.init_member("copy", new builtin_function(contextmenu_copy));
- o.init_member("hideBuiltInItems", new
builtin_function(contextmenu_hidebuiltinitems));
-}
-
-static as_object*
-getContextMenuInterface()
-{
- static boost::intrusive_ptr<as_object> o;
- if ( ! o )
- {
- o = new as_object();
- attachContextMenuInterface(*o);
- }
- return o.get();
-}
-
-class contextmenu_as_object: public as_object
+class ContextMenu: public as_object
{
public:
- contextmenu_as_object()
+ ContextMenu()
:
- as_object(getContextMenuInterface())
+ as_object(getExportedInterface())
{}
+ ContextMenu(const as_value& callback)
+ :
+ as_object(getExportedInterface())
+ {
+ setCallback(callback);
+ }
+
+ ContextMenu(as_function* callback)
+ :
+ as_object(getExportedInterface())
+ {
+ setCallback(callback);
+ }
+
+ static void registerConstructor(as_object& global);
+
// override from as_object ?
//const char* get_text_value() const { return "ContextMenu"; }
// override from as_object ?
//double get_numeric_value() const { return 0; }
+
+private:
+
+ /// Get the callback to call when user invokes the context menu.
+ //
+ /// If NULL, no action will be taken on select.
+ ///
+ as_function* getCallback()
+ {
+ as_value tmp;
+ if ( get_member("onSelect", &tmp) )
+ return tmp.to_as_function();
+ else return NULL;
+ }
+
+ /// Set the callback to call when user invokes the context menu.
+ //
+ /// @param callback
+ /// The function to call. If the value is not a function, no
+ /// action will be taken on select.
+ ///
+ void setCallback(const as_value& callback)
+ {
+ set_member("onSelect", callback);
+ }
+
+ static ContextMenu* ensureContextMenu(as_object* obj)
+ {
+ ContextMenu* ret = dynamic_cast<ContextMenu*>(obj);
+ if ( ! ret )
+ {
+ throw ActionException("builtin method or gettersetter
for ContextMenu objects called against non-ContextMenu instance");
+ }
+ return ret;
+ }
+
+ /// Attach the exported interface of this ActionScript class
+ /// to the given object.
+ static void attachExportedInterface(as_object& o);
+
+ /// Get the ContextMenu.prototype ActionScript object
+ static as_object* getExportedInterface();
+
+ static void ctor_method(const fn_call& fn);
+
+ static void hideBuiltInItems_method(const fn_call& fn);
+
+ static void copy_method(const fn_call& fn);
};
-void contextmenu_copy(const fn_call& /*fn*/) {
- log_warning("%s: unimplemented \n", __FUNCTION__);
+/* static private */
+void
+ContextMenu::attachExportedInterface(as_object& o)
+{
+ o.init_member("copy", new builtin_function(ContextMenu::copy_method));
+ o.init_member("hideBuiltInItems", new
builtin_function(ContextMenu::hideBuiltInItems_method));
}
-void contextmenu_hidebuiltinitems(const fn_call& /*fn*/) {
- log_warning("%s: unimplemented \n", __FUNCTION__);
+
+/* static private */
+as_object*
+ContextMenu::getExportedInterface()
+{
+ static boost::intrusive_ptr<as_object> o;
+ if ( ! o )
+ {
+ o = new as_object();
+ attachExportedInterface(*o);
+ }
+ return o.get();
}
+
+/* static private */
void
-contextmenu_ctor(const fn_call& fn)
+ContextMenu::copy_method(const fn_call& fn)
{
- boost::intrusive_ptr<as_object> obj = new contextmenu_as_object;
+ ContextMenu* ptr = ensureContextMenu(fn.this_ptr);
+ UNUSED(ptr);
+ log_warning("%s: unimplemented", __FUNCTION__);
+}
+
+/* static private */
+void
+ContextMenu::hideBuiltInItems_method(const fn_call& fn)
+{
+ ContextMenu* ptr = ensureContextMenu(fn.this_ptr);
+ UNUSED(ptr);
+ log_warning("%s: unimplemented", __FUNCTION__);
+}
+
+/* static private */
+void
+ContextMenu::ctor_method(const fn_call& fn)
+{
+ boost::intrusive_ptr<as_object> obj;
+ if ( fn.nargs > 0 )
+ obj = new ContextMenu(fn.arg(0));
+ else
+ obj = new ContextMenu();
fn.result->set_as_object(obj.get()); // will keep alive
}
-// extern (used by Global.cpp)
-void contextmenu_class_init(as_object& global)
+/* static public */
+void
+ContextMenu::registerConstructor(as_object& global)
{
// This is going to be the global ContextMenu "class"/"function"
static boost::intrusive_ptr<builtin_function> cl;
if ( cl == NULL )
{
- cl=new builtin_function(&contextmenu_ctor,
getContextMenuInterface());
+ cl=new builtin_function(ContextMenu::ctor_method,
ContextMenu::getExportedInterface());
// replicate all interface to class, to be able to access
// all methods as static functions
- attachContextMenuInterface(*cl);
+ ContextMenu::attachExportedInterface(*cl);
}
@@ -104,6 +185,12 @@
}
+// extern (used by Global.cpp)
+void contextmenu_class_init(as_object& global)
+{
+ ContextMenu::registerConstructor(global);
+}
+
} // end of gnash namespace
Index: testsuite/actionscript.all/ContextMenu.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/ContextMenu.as,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- testsuite/actionscript.all/ContextMenu.as 11 Jan 2007 12:15:03 -0000
1.8
+++ testsuite/actionscript.all/ContextMenu.as 7 Mar 2007 22:47:53 -0000
1.9
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -20,17 +20,13 @@
// compile this test case with Ming makeswf, and then
// execute it like this gnash -1 -r 0 -v out.swf
-rcsid="$Id: ContextMenu.as,v 1.8 2007/01/11 12:15:03 strk Exp $";
+rcsid="$Id: ContextMenu.as,v 1.9 2007/03/07 22:47:53 strk Exp $";
#include "check.as"
#if OUTPUT_VERSION < 7
-// there was no ContextMenu before SWF7, still
-// it seems the player allows instantiating one (?)
-xcheck_equals(typeof(ContextMenu), 'function');
-var contextmenuObj = new ContextMenu;
-xcheck_equals (typeof(contextmenuObj), 'object');
+note("You can't rely on availability of ContextMenu class with an SWF < 7");
#else // OUTPUT_VERSION >= 7
@@ -44,7 +40,40 @@
// test the ContextMenu::copy method
check_equals (typeof(contextmenuObj.copy), 'function');
+
// test the ContextMenu::hideBuiltinItems method
check_equals (typeof(contextmenuObj.hideBuiltInItems), 'function');
+// test existance of ContextMenu::builtInItems object
+xcheck_equals (typeof(contextmenuObj.builtInItems), 'object');
+check ( ! contextmenuObj.builtInItems instanceOf Array );
+check_equals (typeof(contextmenuObj.builtInItems.length), 'undefined');
+
+// test existance of ContextMenu::customItems object
+xcheck_equals (typeof(contextmenuObj.customItems), 'object');
+check ( ! contextmenuObj.builtInItems instanceOf Array );
+xcheck_equals (typeof(contextmenuObj.customItems.length), 'number');
+
+// test existance of ContextMenu::onSelect object
+check_equals (typeof(contextmenuObj.onSelect), 'undefined');
+
+//----------------------------------------------
+// Test onSelect
+//----------------------------------------------
+
+function callback() { }
+var contextMenuObj2 = new ContextMenu(callback);
+check_equals(typeof(contextMenuObj2.onSelect), 'function');
+check_equals(contextMenuObj2.onSelect, callback);
+function callback2() { }
+contextMenuObj2.onSelect = callback2;
+check_equals(typeof(contextMenuObj2.onSelect), 'function');
+check_equals(contextMenuObj2.onSelect, callback2);
+contextMenuObj2.onSelect = null;
+check_equals(typeof(contextMenuObj2.onSelect), 'null');
+contextMenuObj2.onSelect = undefined;
+check_equals(typeof(contextMenuObj2.onSelect), 'undefined');
+contextMenuObj2.onSelect = 4;
+check_equals(typeof(contextMenuObj2.onSelect), 'number');
+
#endif
- [Gnash-commit] gnash ChangeLog server/asobj/ContextMenu.cpp te...,
Sandro Santilli <=