gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11042: migrated Keyboard actionscri


From: Ben Limmer
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11042: migrated Keyboard actionscript class to new namespace
Date: Mon, 08 Jun 2009 16:15:34 -0600
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11042
committer: Ben Limmer <address@hidden>
branch nick: trunk
timestamp: Mon 2009-06-08 16:15:34 -0600
message:
  migrated Keyboard actionscript class to new namespace
removed:
  libcore/asobj/Key_as.cpp
  libcore/asobj/Key_as.h
modified:
  libcore/ClassHierarchy.cpp
  libcore/MovieClip.cpp
  libcore/TextField.cpp
  libcore/asobj/Global.cpp
  libcore/asobj/Makefile.am
  libcore/asobj/flash.am
  libcore/asobj/flash/ui/Keyboard_as.cpp
  libcore/asobj/flash/ui/Keyboard_as.h
  libcore/asobj/flash/ui/uiclasses.h
  libcore/movie_root.cpp
  libcore/movie_root.h
    ------------------------------------------------------------
    revno: 11039.3.1
    committer: Ben Limmer <address@hidden>
    branch nick: branch_5
    timestamp: Mon 2009-06-08 15:40:22 -0600
    message:
      migrated Keyboard class to new namespace
    removed:
      libcore/asobj/Key_as.cpp
      libcore/asobj/Key_as.h
    modified:
      libcore/ClassHierarchy.cpp
      libcore/MovieClip.cpp
      libcore/TextField.cpp
      libcore/asobj/Global.cpp
      libcore/asobj/Makefile.am
      libcore/asobj/flash.am
      libcore/asobj/flash/ui/Keyboard_as.cpp
      libcore/asobj/flash/ui/Keyboard_as.h
      libcore/asobj/flash/ui/uiclasses.h
      libcore/movie_root.cpp
      libcore/movie_root.h
=== modified file 'libcore/ClassHierarchy.cpp'
--- a/libcore/ClassHierarchy.cpp        2009-06-08 22:05:50 +0000
+++ b/libcore/ClassHierarchy.cpp        2009-06-08 22:15:34 +0000
@@ -33,7 +33,7 @@
 #include "Global.h"
 #include "int_as.h"
 #include "String_as.h"
-#include "Key_as.h"
+#include "flash/ui/Keyboard_as.h"
 #include "LoadVars_as.h"
 #include "LocalConnection_as.h"
 #include "Microphone.h"
@@ -312,7 +312,7 @@
        { number_class_init, NSV::CLASS_NUMBER, NSV::CLASS_OBJECT, NS_GLOBAL, 5 
},
        { TextFormat_as::init, NSV::CLASS_TEXT_FORMAT, NSV::CLASS_OBJECT,
         NS_GLOBAL, 5 },
-       { key_class_init, NSV::CLASS_KEY, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
+       { Keyboard_as::init, NSV::CLASS_KEY, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
        { AsBroadcaster::init, NSV::CLASS_AS_BROADCASTER, NSV::CLASS_OBJECT,
         NS_GLOBAL, 5 },
        { TextSnapshot_as::init, NSV::CLASS_TEXT_SNAPSHOT, NSV::CLASS_OBJECT,

=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp     2009-06-03 13:34:35 +0000
+++ b/libcore/MovieClip.cpp     2009-06-08 21:40:22 +0000
@@ -31,7 +31,7 @@
 #include "TextField.h"
 #include "ControlTag.h"
 #include "fn_call.h"
-#include "Key_as.h"
+#include "flash/ui/Keyboard_as.h"
 #include "movie_root.h"
 #include "Movie.h"
 #include "swf_event.h"

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2009-06-08 18:31:05 +0000
+++ b/libcore/TextField.cpp     2009-06-08 22:15:34 +0000
@@ -28,7 +28,7 @@
 #include "movie_definition.h" // to extract version info
 #include "MovieClip.h"
 #include "TextField.h"
-#include "Key_as.h" // for keyboard events
+#include "flash/ui/Keyboard_as.h" // for keyboard events
 #include "movie_root.h"     // for killing focus
 #include "as_environment.h" // for parse_path
 #include "action.h" // for as_standard_member enum

=== modified file 'libcore/asobj/Global.cpp'
--- a/libcore/asobj/Global.cpp  2009-06-08 22:05:50 +0000
+++ b/libcore/asobj/Global.cpp  2009-06-08 22:15:34 +0000
@@ -37,7 +37,7 @@
 #include "Error_as.h"
 #include "Global.h"
 #include "String_as.h"
-#include "Key_as.h"
+#include "flash/ui/Keyboard_as.h"
 #include "Selection_as.h"
 #include "Microphone.h"
 #include "Number_as.h"

=== removed file 'libcore/asobj/Key_as.cpp'
--- a/libcore/asobj/Key_as.cpp  2009-04-03 09:18:40 +0000
+++ b/libcore/asobj/Key_as.cpp  1970-01-01 00:00:00 +0000
@@ -1,285 +0,0 @@
-// Key.cpp:  ActionScript "Key" class (keyboards), for Gnash.
-// 
-//   Copyright (C) 2005, 2006, 2007, 2008, 2009 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
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-//
-
-#include "smart_ptr.h" // GNASH_USE_GC
-#include "log.h"
-#include "Key_as.h"
-#include "fn_call.h"
-#include "movie_root.h"
-#include "action.h" // for call_method
-#include "VM.h" // for registerNative
-#include "builtin_function.h"
-#include "Object.h" // for getObjectInterface()
-#include "AsBroadcaster.h" // for initializing self as a broadcaster
-#include "namedStrings.h"
-#include "GnashKey.h" // key::code
-
-// Define this to get DEBUG lines on key events
-//#define GNASH_DEBUG_KEYEVENTS
-
-namespace gnash {
-
-/************************************************************************
-*
-* This has been moved from action.cpp, when things are clean
-* everything should have been moved up
-*
-************************************************************************/
-
-Key_as::Key_as()
-    :
-    as_object(getObjectInterface()),
-    _unreleasedKeys(0),
-    _lastKeyEvent(0)
-{
-    // Key is a broadcaster only in SWF6 and up (correct?)
-    int swfversion = _vm.getSWFVersion();
-    if ( swfversion > 5 )
-    {
-        AsBroadcaster::initialize(*this);
-    }
-}
-
-bool
-Key_as::is_key_down(int keycode)
-{
-    // caller must check this
-    assert (keycode >= 0 && keycode < key::KEYCOUNT);
-
-    if (_unreleasedKeys.test(keycode)) return true;
-    return false;
-}
-
-void
-Key_as::set_key_down(key::code code)
-{
-    if (code >= key::KEYCOUNT)
-    {
-        // programmatic error, as only movie_root calls us
-        log_error("Key_as::set_key_down(%d): code out of range", code);
-        return;
-    }
-
-    // This is used for getAscii() of the last key event, so we store
-    // the unique gnash::key::code.
-    _lastKeyEvent = code;
-
-    // Key.isDown() only cares about flash keycode, not DisplayObject, so
-    // we lookup keycode to add to _unreleasedKeys.   
-    size_t keycode = key::codeMap[code][key::KEY];
-
-#ifdef GNASH_DEBUG_KEYEVENTS
-    log_debug("Key_as::set_key_down(%d): setting unreleased keycode %d (from 
code %d)", keycode, code);
-#endif
-    _unreleasedKeys.set(keycode, 1);
-}
-
-void
-Key_as::set_key_up(key::code code)
-{
-    if (code >= key::KEYCOUNT)
-    {
-        // programmatic error, as only movie_root calls us
-        log_error("Key_as::set_key_up(%d): code out of range", code);
-        return;
-    }
-
-    // This is used for getAscii() of the last key event, so we store
-    // the unique gnash::key::code.    
-    _lastKeyEvent = code;
-
-    // Key.isDown() only cares about flash keycode, not DisplayObject, so
-    // we lookup keycode to add to _unreleasedKeys.
-    size_t keycode = key::codeMap[code][key::KEY];
-
-#ifdef GNASH_DEBUG_KEYEVENTS
-    log_debug("Key_as::set_key_down(%d): setting released keycode %d (from 
code %d)", keycode, code);
-#endif
-    _unreleasedKeys.set(keycode, 0);
-}
-
-
-void 
-Key_as::notify_listeners(const event_id& ev)
-{  
-    // There is no user defined "onKeyPress" event handler
-    if((ev.id() != event_id::KEY_DOWN) &&
-            (ev.id() != event_id::KEY_UP)) return;
-
-#ifdef GNASH_DEBUG_KEYEVENTS
-    log_debug("notify_listeners calling broadcastMessage with arg %s", ev);
-#endif
-    callMethod(NSV::PROP_BROADCAST_MESSAGE, ev.functionName());
-}
-
-int
-Key_as::get_last_key() const
-{
-    return _lastKeyEvent;
-}
-
-static as_value
-key_is_accessible(const fn_call& fn)
-{
-
-    boost::intrusive_ptr<Key_as> ko = 
-        ensureType<Key_as>(fn.this_ptr);
-
-    log_unimpl("Key.isAccessible");
-    return as_value();
-}
-
-
-/// Return the ascii number of the last key pressed.
-static as_value   
-key_get_ascii(const fn_call& fn)
-{
-    boost::intrusive_ptr<Key_as> ko = 
-        ensureType<Key_as>(fn.this_ptr);
-
-    int code = ko->get_last_key();
-
-    return as_value(gnash::key::codeMap[code][key::ASCII]);
-}
-
-/// Returns the keycode of the last key pressed.
-static as_value   
-key_get_code(const fn_call& fn)
-{
-    boost::intrusive_ptr<Key_as> ko = 
-        ensureType<Key_as>(fn.this_ptr);
-
-    int code = ko->get_last_key();
-
-    return as_value(key::codeMap[code][key::KEY]);
-}
-
-/// Return true if the specified (first arg keycode) key is pressed.
-static as_value   
-key_is_down(const fn_call& fn)
-{
-    boost::intrusive_ptr<Key_as> ko = 
-        ensureType<Key_as>(fn.this_ptr);
-
-    if (fn.nargs < 1)
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("Key.isDown needs one argument (the key code)"));
-        );
-        return as_value();
-    }
-
-    int keycode = fn.arg(0).to_int();
-    if (keycode < 0 || keycode >= key::KEYCOUNT)
-    {
-        // AS coding error !
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror("Key.isKeyDown(%d): keycode out of range", keycode);
-        );
-        return as_value(false);
-    }
-
-    return as_value(ko->is_key_down(keycode));
-}
-
-/// \brief
-/// Given the keycode of NUM_LOCK or CAPSLOCK, returns true if
-/// the associated state is on.
-///
-static as_value   
-key_is_toggled(const fn_call& /* fn */)
-{
-    log_unimpl("Key.isToggled");
-    // @@ TODO
-    return as_value(false);
-}
-
-void key_class_init(as_object& global)
-{
-
-    //  GNASH_REPORT_FUNCTION;
-    //
-
-    // Create built-in key object.
-    // NOTE: _global.Key *is* an object, not a constructor
-    as_object*  key_obj = new Key_as;
-
-    const int flags = as_prop_flags::readOnly |
-                      as_prop_flags::dontDelete |
-                      as_prop_flags::dontEnum;
-
-    // constants
-#define KEY_CONST(k) key_obj->init_member(#k, key::codeMap[key::k][key::KEY], 
flags)
-    KEY_CONST(BACKSPACE);
-    KEY_CONST(CAPSLOCK);
-    KEY_CONST(CONTROL);
-    KEY_CONST(DELETEKEY);
-    KEY_CONST(DOWN);
-    KEY_CONST(END);
-    KEY_CONST(ENTER);
-    KEY_CONST(ESCAPE);
-    KEY_CONST(HOME);
-    KEY_CONST(INSERT);
-    KEY_CONST(LEFT);
-    KEY_CONST(PGDN);
-    KEY_CONST(PGUP);
-    KEY_CONST(RIGHT);
-    KEY_CONST(SHIFT);
-    KEY_CONST(SPACE);
-    KEY_CONST(TAB);
-    KEY_CONST(UP);
-    KEY_CONST(ALT);
-
-    // methods
-
-    VM& vm = global.getVM();
-
-    vm.registerNative(key_get_ascii, 800, 0);
-    key_obj->init_member("getAscii", vm.getNative(800, 0), flags);
-
-    vm.registerNative(key_get_code, 800, 1);
-    key_obj->init_member("getCode", vm.getNative(800, 1), flags);
-
-    vm.registerNative(key_is_down, 800, 2);
-    key_obj->init_member("isDown", vm.getNative(800, 2), flags);
-
-    vm.registerNative(key_is_toggled, 800, 3);
-    key_obj->init_member("isToggled", vm.getNative(800, 3), flags);
-
-    key_obj->init_member("isAccessible", 
-            new builtin_function(key_is_accessible), flags);
-
-    global.init_member("Key", key_obj);
-}
-
-#ifdef GNASH_USE_GC
-void
-Key_as::markReachableResources() const
-{
-    markAsObjectReachable();
-    for (Listeners::const_iterator i=_listeners.begin(), e=_listeners.end();
-                i != e; ++i)
-    {
-        (*i)->setReachable();
-    }
-}
-#endif // def GNASH_USE_GC
-
-} // end of gnash namespace
-

=== removed file 'libcore/asobj/Key_as.h'
--- a/libcore/asobj/Key_as.h    2009-06-03 16:05:40 +0000
+++ b/libcore/asobj/Key_as.h    1970-01-01 00:00:00 +0000
@@ -1,89 +0,0 @@
-// 
-//   Copyright (C) 2005, 2006, 2007, 2008, 2009 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
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-// 
-
-
-#ifndef HAVE_KEY_H
-#define HAVE_KEY_H
-
-#include "smart_ptr.h" // GNASH_USE_GC
-#include "as_object.h" // for inheritance
-#include "GnashKey.h" // for key::code
-#include "dsodefs.h"
-#include <bitset>
-
-namespace gnash {
-
-class event_id;
-    
-/************************************************************************
- *
- * This has been moved from action.cpp, when things are clean
- * everything should have been moved up
- *
- ************************************************************************/
-
-class Key_as : public as_object
-{
-
-protected:
-
-#ifdef GNASH_USE_GC
-    // Mark all key listeners as reachable
-    void markReachableResources() const;
-#endif // def GNASH_USE_GC
-
-public:
-
-    Key_as();
-
-    // Pass SWF keycode, returns true if currently pressed.
-    bool is_key_down(int keycode);
-
-    // Pass gnash::key::code. Changes m_last_key_event
-    // and adds appropriate SWF keycode to bit array of keys
-    // pressed (_unreleasedKeys)
-    void set_key_down(key::code code);
-
-    // Pass gnash::key::code. Changes m_last_key_event
-    // and removes appropriate SWF keycode from bit array of keys
-    // pressed (_unreleasedKeys)
-    void set_key_up(key::code code);
-    
-    int get_last_key() const;
-
-    /// Responsible for user defined key events handlers only;
-    /// take over both DisplayObjects and non-DisplayObjects object.
-    void notify_listeners(const event_id& key_event_type);
-
-private:
-    /// bit-array for recording the unreleased keys
-    std::bitset<key::KEYCOUNT> _unreleasedKeys;   
-
-    typedef std::list<boost::intrusive_ptr<as_object> > Listeners;
-    Listeners _listeners;
-
-    int _lastKeyEvent;
-};
-
-void key_class_init(as_object& global);
-
-} // end of gnash namespace
-
-// HAVE_KEY_H
-#endif
-

=== modified file 'libcore/asobj/Makefile.am'
--- a/libcore/asobj/Makefile.am 2009-06-08 22:05:50 +0000
+++ b/libcore/asobj/Makefile.am 2009-06-08 22:15:34 +0000
@@ -62,7 +62,6 @@
        Error_as.cpp \
        Global.cpp \
        int_as.cpp \
-       Key_as.cpp      \
        LoadVars_as.cpp \
        LocalConnection_as.cpp\
        Math_as.cpp \
@@ -94,7 +93,6 @@
        Math_as.h       \
        Global.h\
        int_as.h \
-       Key_as.h \
        LoadVars_as.h \
        LocalConnection_as.h\
        Microphone.h \

=== modified file 'libcore/asobj/flash.am'
--- a/libcore/asobj/flash.am    2009-06-08 22:05:50 +0000
+++ b/libcore/asobj/flash.am    2009-06-08 22:15:34 +0000
@@ -36,7 +36,6 @@
        asobj/Error_as.cpp \
        asobj/Global.cpp \
        asobj/int_as.cpp \
-       asobj/Key_as.cpp        \
        asobj/LoadVars_as.cpp \
        asobj/LocalConnection_as.cpp\
        asobj/Math_as.cpp \
@@ -68,7 +67,6 @@
        asobj/Math_as.h \
        asobj/Global.h\
        asobj/int_as.h \
-       asobj/Key_as.h \
        asobj/LoadVars_as.h \
        asobj/LocalConnection_as.h\
        asobj/Microphone.h \
@@ -90,7 +88,7 @@
 
 EXTENSIONS_API += \
        asobj/Array_as.h \
-       asobj/Key_as.h \
+       asobj/flash/ui/Keyboard_as.h \
        $(NULL)
 
 CLEANFILES = *classes.h

=== modified file 'libcore/asobj/flash/ui/Keyboard_as.cpp'
--- a/libcore/asobj/flash/ui/Keyboard_as.cpp    2009-05-28 17:11:56 +0000
+++ b/libcore/asobj/flash/ui/Keyboard_as.cpp    2009-06-08 21:40:22 +0000
@@ -21,11 +21,18 @@
 #include "gnashconfig.h"
 #endif
 
+#include "smart_ptr.h" //GNASH_USE_GC
 #include "ui/Keyboard_as.h"
 #include "log.h"
 #include "fn_call.h"
-#include "smart_ptr.h" // for boost intrusive_ptr
+#include "movie_root.h"
+#include "action.h" // for call_method
+#include "VM.h" // for registerNative
 #include "builtin_function.h" // need builtin_function
+#include "Object.h"
+#include "AsBroadcaster.h" //for initializing self as a broadcaster
+#include "namedStrings.h"
+#include "GnashKey.h"
 #include "GnashException.h" // for ActionException
 
 namespace gnash {
@@ -85,34 +92,247 @@
     as_value keyboard_UP(const fn_call& fn);
     as_value keyboard_ctor(const fn_call& fn);
     void attachKeyboardInterface(as_object& o);
-    void attachKeyboardStaticInterface(as_object& o);
     as_object* getKeyboardInterface();
-
-}
-
-class Keyboard_as : public as_object
-{
-
-public:
-
-    Keyboard_as()
-        :
-        as_object(getKeyboardInterface())
-    {}
-};
+}
+
+Keyboard_as::Keyboard_as()
+    :
+    as_object(getObjectInterface()),
+    _unreleasedKeys(0),
+    _lastKeyEvent(0)
+{
+    // Key is a broadcaster only in SWF6 and up (correct?)
+    int swfversion = _vm.getSWFVersion();
+    if ( swfversion > 5 )
+    {
+        AsBroadcaster::initialize(*this);
+    }
+}
+
+bool
+Keyboard_as::is_key_down(int keycode)
+{
+    // caller must check this
+    assert (keycode >= 0 && keycode < key::KEYCOUNT);
+
+    if (_unreleasedKeys.test(keycode)) return true;
+    return false;
+}
+
+void
+Keyboard_as::set_key_down(key::code code)
+{
+    if (code >= key::KEYCOUNT)
+    {
+        // programmatic error, as only movie_root calls us
+        log_error("Key_as::set_key_down(%d): code out of range", code);
+        return;
+    }
+
+    // This is used for getAscii() of the last key event, so we store
+    // the unique gnash::key::code.
+    _lastKeyEvent = code;
+
+    // Key.isDown() only cares about flash keycode, not DisplayObject, so
+    // we lookup keycode to add to _unreleasedKeys.   
+    size_t keycode = key::codeMap[code][key::KEY];
+
+#ifdef GNASH_DEBUG_KEYEVENTS
+    log_debug("Key_as::set_key_down(%d): setting unreleased keycode %d (from 
code %d)", keycode, code);
+#endif
+    _unreleasedKeys.set(keycode, 1);
+}
+
+void
+Keyboard_as::set_key_up(key::code code)
+{
+    if (code >= key::KEYCOUNT)
+    {
+        // programmatic error, as only movie_root calls us
+        log_error("Key_as::set_key_up(%d): code out of range", code);
+        return;
+    }
+
+    // This is used for getAscii() of the last key event, so we store
+    // the unique gnash::key::code.    
+    _lastKeyEvent = code;
+
+    // Key.isDown() only cares about flash keycode, not DisplayObject, so
+    // we lookup keycode to add to _unreleasedKeys.
+    size_t keycode = key::codeMap[code][key::KEY];
+
+#ifdef GNASH_DEBUG_KEYEVENTS
+    log_debug("Key_as::set_key_down(%d): setting released keycode %d (from 
code %d)", keycode, code);
+#endif
+    _unreleasedKeys.set(keycode, 0);
+}
+
+
+void 
+Keyboard_as::notify_listeners(const event_id& ev)
+{  
+    // There is no user defined "onKeyPress" event handler
+    if((ev.id() != event_id::KEY_DOWN) &&
+            (ev.id() != event_id::KEY_UP)) return;
+
+#ifdef GNASH_DEBUG_KEYEVENTS
+    log_debug("notify_listeners calling broadcastMessage with arg %s", ev);
+#endif
+    callMethod(NSV::PROP_BROADCAST_MESSAGE, ev.functionName());
+}
+
+int
+Keyboard_as::get_last_key() const
+{
+    return _lastKeyEvent;
+}
+
+static as_value
+key_is_accessible(const fn_call& fn)
+{
+
+    boost::intrusive_ptr<Keyboard_as> ko = 
+        ensureType<Keyboard_as>(fn.this_ptr);
+
+    log_unimpl("Key.isAccessible");
+    return as_value();
+}
+
+
+/// Return the ascii number of the last key pressed.
+static as_value   
+key_get_ascii(const fn_call& fn)
+{
+    boost::intrusive_ptr<Keyboard_as> ko = 
+        ensureType<Keyboard_as>(fn.this_ptr);
+
+    int code = ko->get_last_key();
+
+    return as_value(gnash::key::codeMap[code][key::ASCII]);
+}
+
+/// Returns the keycode of the last key pressed.
+static as_value   
+key_get_code(const fn_call& fn)
+{
+    boost::intrusive_ptr<Keyboard_as> ko = 
+        ensureType<Keyboard_as>(fn.this_ptr);
+
+    int code = ko->get_last_key();
+
+    return as_value(key::codeMap[code][key::KEY]);
+}
+
+/// Return true if the specified (first arg keycode) key is pressed.
+static as_value   
+key_is_down(const fn_call& fn)
+{
+    boost::intrusive_ptr<Keyboard_as> ko = 
+        ensureType<Keyboard_as>(fn.this_ptr);
+
+    if (fn.nargs < 1)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("Key.isDown needs one argument (the key code)"));
+        );
+        return as_value();
+    }
+
+    int keycode = fn.arg(0).to_int();
+    if (keycode < 0 || keycode >= key::KEYCOUNT)
+    {
+        // AS coding error !
+        IF_VERBOSE_ASCODING_ERRORS(
+        log_aserror("Key.isKeyDown(%d): keycode out of range", keycode);
+        );
+        return as_value(false);
+    }
+
+    return as_value(ko->is_key_down(keycode));
+}
+
+/// \brief
+/// Given the keycode of NUM_LOCK or CAPSLOCK, returns true if
+/// the associated state is on.
+///
+static as_value   
+key_is_toggled(const fn_call& /* fn */)
+{
+    log_unimpl("Key.isToggled");
+    // @@ TODO
+    return as_value(false);
+}
+
+#ifdef GNASH_USE_GC
+void
+Keyboard_as::markReachableResources() const
+{
+    markAsObjectReachable();
+    for (Listeners::const_iterator i=_listeners.begin(), e=_listeners.end();
+                i != e; ++i)
+    {
+        (*i)->setReachable();
+    }
+}
+#endif // def GNASH_USE_GC
 
 // extern (used by Global.cpp)
-void keyboard_class_init(as_object& global)
+void Keyboard_as::init(as_object& global)
 {
-    static boost::intrusive_ptr<builtin_function> cl;
-
-    if (!cl) {
-        cl = new builtin_function(&keyboard_ctor, getKeyboardInterface());
-        attachKeyboardStaticInterface(*cl);
-    }
-
-    // Register _global.Keyboard
-    global.init_member("Keyboard", cl.get());
+
+    //  GNASH_REPORT_FUNCTION;
+    //
+
+    // Create built-in key object.
+    // NOTE: _global.Key *is* an object, not a constructor
+    as_object*  key_obj = new Keyboard_as;
+
+    const int flags = as_prop_flags::readOnly |
+                      as_prop_flags::dontDelete |
+                      as_prop_flags::dontEnum;
+
+    // constants
+#define KEY_CONST(k) key_obj->init_member(#k, key::codeMap[key::k][key::KEY], 
flags)
+    KEY_CONST(BACKSPACE);
+    KEY_CONST(CAPSLOCK);
+    KEY_CONST(CONTROL);
+    KEY_CONST(DELETEKEY);
+    KEY_CONST(DOWN);
+    KEY_CONST(END);
+    KEY_CONST(ENTER);
+    KEY_CONST(ESCAPE);
+    KEY_CONST(HOME);
+    KEY_CONST(INSERT);
+    KEY_CONST(LEFT);
+    KEY_CONST(PGDN);
+    KEY_CONST(PGUP);
+    KEY_CONST(RIGHT);
+    KEY_CONST(SHIFT);
+    KEY_CONST(SPACE);
+    KEY_CONST(TAB);
+    KEY_CONST(UP);
+    KEY_CONST(ALT);
+
+    // methods
+
+    VM& vm = global.getVM();
+
+    vm.registerNative(key_get_ascii, 800, 0);
+    key_obj->init_member("getAscii", vm.getNative(800, 0), flags);
+
+    vm.registerNative(key_get_code, 800, 1);
+    key_obj->init_member("getCode", vm.getNative(800, 1), flags);
+
+    vm.registerNative(key_is_down, 800, 2);
+    key_obj->init_member("isDown", vm.getNative(800, 2), flags);
+
+    vm.registerNative(key_is_toggled, 800, 3);
+    key_obj->init_member("isToggled", vm.getNative(800, 3), flags);
+
+    key_obj->init_member("isAccessible", 
+            new builtin_function(key_is_accessible), flags);
+
+    global.init_member("Key", key_obj);
 }
 
 namespace {
@@ -173,11 +393,6 @@
     o.init_member("UP", new builtin_function(keyboard_UP));
 }
 
-void
-attachKeyboardStaticInterface(as_object& o)
-{
-
-}
 
 as_object*
 getKeyboardInterface()

=== modified file 'libcore/asobj/flash/ui/Keyboard_as.h'
--- a/libcore/asobj/flash/ui/Keyboard_as.h      2009-05-28 17:29:17 +0000
+++ b/libcore/asobj/flash/ui/Keyboard_as.h      2009-06-08 21:40:22 +0000
@@ -24,14 +24,58 @@
 #include "gnashconfig.h"
 #endif
 
+#include "smart_ptr.h" // GNASH_USE_GC
+#include "as_object.h" // for inheritance
+#include "GnashKey.h" // for key::code
+#include "dsodefs.h"
+#include <bitset>
 
 namespace gnash {
 
 // Forward declarations
-class as_object;
-
-/// Initialize the global Keyboard class
-void keyboard_class_init(as_object& global);
+class event_id;
+
+class Keyboard_as : public as_object
+{
+protected:
+
+#ifdef GNASH_USE_GC
+    // Mark all key listeners as reachable
+    void markReachableResources() const;
+#endif // def GNASH_USE_GC
+
+public:
+
+    Keyboard_as();     
+       static void init(as_object& global);
+           // Pass SWF keycode, returns true if currently pressed.
+    bool is_key_down(int keycode);
+
+    // Pass gnash::key::code. Changes m_last_key_event
+    // and adds appropriate SWF keycode to bit array of keys
+    // pressed (_unreleasedKeys)
+    void set_key_down(key::code code);
+
+    // Pass gnash::key::code. Changes m_last_key_event
+    // and removes appropriate SWF keycode from bit array of keys
+    // pressed (_unreleasedKeys)
+    void set_key_up(key::code code);
+    
+    int get_last_key() const;
+
+    /// Responsible for user defined key events handlers only;
+    /// take over both DisplayObjects and non-DisplayObjects object.
+    void notify_listeners(const event_id& key_event_type);
+
+private:
+    /// bit-array for recording the unreleased keys
+    std::bitset<key::KEYCOUNT> _unreleasedKeys;   
+
+    typedef std::list<boost::intrusive_ptr<as_object> > Listeners;
+    Listeners _listeners;
+
+    int _lastKeyEvent;
+};
 
 } // gnash namespace
 

=== modified file 'libcore/asobj/flash/ui/uiclasses.h'
--- a/libcore/asobj/flash/ui/uiclasses.h        2009-06-07 00:49:02 +0000
+++ b/libcore/asobj/flash/ui/uiclasses.h        2009-06-08 21:40:22 +0000
@@ -6,7 +6,7 @@
        gnash::contextmenubuiltinitems_class_init,
        gnash::contextmenuitem_class_init,
        gnash::keylocation_class_init,
-       gnash::keyboard_class_init,
+       gnash::Keyboard_as::init,
        gnash::mouse_class_init,
        0
 };

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2009-06-02 07:58:24 +0000
+++ b/libcore/movie_root.cpp    2009-06-08 21:40:22 +0000
@@ -565,7 +565,7 @@
 
 }
 
-boost::intrusive_ptr<Key_as>
+boost::intrusive_ptr<Keyboard_as>
 movie_root::getKeyObject()
 {
        // TODO: test what happens with the global "Key" object
@@ -584,7 +584,7 @@
                if (global->get_member(NSV::CLASS_KEY, &kval)) {
 
                        boost::intrusive_ptr<as_object> obj = kval.to_object();
-                       _keyobject = boost::dynamic_pointer_cast<Key_as>( obj );
+                       _keyobject = boost::dynamic_pointer_cast<Keyboard_as>( 
obj );
                }
        }
 
@@ -612,7 +612,7 @@
 }
 
 
-Key_as*
+Keyboard_as*
 movie_root::notify_global_key(key::code k, bool down)
 {
     // NOTE: we don't check SWF version here
@@ -621,7 +621,7 @@
     //       which would need to query Key object.
     //       Testcase: http://www.ferryhalim.com/orisinal/g3/00dog.swf 
 
-       boost::intrusive_ptr<Key_as> keyobject = getKeyObject();
+       boost::intrusive_ptr<Keyboard_as> keyobject = getKeyObject();
        if ( keyobject )
        {
                if (down) _keyobject->set_key_down(k);
@@ -642,7 +642,7 @@
        //
        // First of all, notify the _global.Key object about key event
        //
-       Key_as * global_key = notify_global_key(k, down);
+       Keyboard_as * global_key = notify_global_key(k, down);
 
        // Notify DisplayObject key listeners for clip key events
        notify_key_listeners(k, down);

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2009-05-25 17:31:02 +0000
+++ b/libcore/movie_root.h      2009-06-08 21:40:22 +0000
@@ -73,7 +73,7 @@
 #include "dsodefs.h" // DSOEXPORT
 #include "MouseButtonState.h" // for composition
 #include "drag_state.h" // for composition
-#include "Key_as.h"
+#include "flash/ui/Keyboard_as.h"
 #include "smart_ptr.h" // for memory management
 #include "URL.h" // for loadMovie
 #include "GnashKey.h" // key::code
@@ -951,7 +951,7 @@
     void executeTimers();
 
     /// Notify the global Key ActionScript object about a key status change
-    Key_as * notify_global_key(key::code k, bool down);
+    Keyboard_as * notify_global_key(key::code k, bool down);
 
     /// Remove unloaded key and mouselisteners.
     void cleanupUnloadedListeners()
@@ -1017,7 +1017,7 @@
     /// Characters for listening key events
     KeyListeners m_key_listeners;
 
-    boost::intrusive_ptr<Key_as> _keyobject;
+    boost::intrusive_ptr<Keyboard_as> _keyobject;
 
     boost::intrusive_ptr<as_object> _mouseobject;
 
@@ -1104,7 +1104,7 @@
     //
     /// @@ might be worth making public
     ///
-    boost::intrusive_ptr<Key_as> getKeyObject();
+    boost::intrusive_ptr<Keyboard_as> getKeyObject();
 
     /// Return the global Mouse object 
     //


reply via email to

[Prev in Thread] Current Thread [Next in Thread]