Author: toshok
Date: 2007-07-11 23:15:14 -0400 (Wed, 11 Jul 2007)
New Revision: 81842

Modified:
   trunk/moon/plugin/ChangeLog
   trunk/moon/plugin/plugin-class.cpp
   trunk/moon/plugin/plugin-class.h
   trunk/moon/plugin/plugin-glue.cpp
   trunk/moon/plugin/plugin.cpp
   trunk/moon/plugin/plugin.h
Log:
        * plugin-class.cpp, plugin-class.h, plugin-glue.cpp, plugin.h,
        plugin.cpp: I know this looks like a scary change, but 90% of the
        code is the same.  I just took advantage of the fact that we
        already have structs with all the function pointers in them.
        there's no reason to proxy from a function pointer in the struct
        to an instance method on a singleton class - just use the function
        pointer.

        Also, add a binding for Points, which we'll need to wrap mouse
        events.

2007-07-11  Chris Toshok  <[EMAIL PROTECTED]>



Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/ChangeLog 2007-07-12 03:15:14 UTC (rev 81842)
@@ -1,5 +1,18 @@
 2007-07-11  Chris Toshok  <[EMAIL PROTECTED]>
 
+       * plugin-class.cpp, plugin-class.h, plugin-glue.cpp, plugin.h,
+       plugin.cpp: I know this looks like a scary change, but 90% of the
+       code is the same.  I just took advantage of the fact that we
+       already have structs with all the function pointers in them.
+       there's no reason to proxy from a function pointer in the struct
+       to an instance method on a singleton class - just use the function
+       pointer.
+
+       Also, add a binding for Points, which we'll need to wrap mouse
+       events.
+
+2007-07-11  Chris Toshok  <[EMAIL PROTECTED]>
+
        * moonlight.h (DEBUG_WARN_NOTIMPLEMENTED): add this macro so we
        can get spew to the console when we hit unimplemented bits.
 

Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp  2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/plugin-class.cpp  2007-07-12 03:15:14 UTC (rev 81842)
@@ -15,7 +15,13 @@
 #include "plugin.h"
 #include "plstr.h"
 
-bool
+#define HAS_PROPERTY(x,v) \
+               (index_of_name (v, x, (sizeof (x) / sizeof (char *))) > -1)
+#define HAS_METHOD(x,v) \
+               (index_of_name (v, x, (sizeof (x) / sizeof (char *))) > -1)
+
+
+static bool
 name_matches (NPIdentifier id, const char *name)
 {
        if (id == NPN_GetStringIdentifier (name))
@@ -34,221 +40,201 @@
        return rv;
 }
 
-/*** Static wrapper functions 
*************************************************/
-
-NPObject*
-MoonlightClass::moonlightAllocate (NPP instance, NPClass *aClass)
+static int
+index_of_name (NPIdentifier name, const char *const names[], int count)
 {
-       return (NPObject*)((MoonlightClass *) aClass)->AllocateObject 
(instance);
-}
+       for (int i = 0; i < count; i++) {
+               if (name_matches (name, names[i]))
+                       return i;
+       }
 
-void
-MoonlightClass::moonlightDeallocate (NPObject *npobj)
-{
-       ((MoonlightClass*)npobj->_class)->DeallocateObject 
((MoonlightObject*)npobj);
+       return -1;
 }
 
-void
-MoonlightClass::moonlightInvalidate (NPObject *npobj)
+static void
+string_to_npvariant (char *value, NPVariant *result)
 {
-       ((MoonlightClass *) npobj->_class)->InvalidateObject ((MoonlightObject 
*) npobj);
-}
+       char * retval;
 
-bool
-MoonlightClass::moonlightHasProperty (NPObject *npobj, NPIdentifier name)
-{
-       return ((MoonlightClass *) npobj->_class)->HasProperty 
((MoonlightObject *) npobj, name);
-}
+       if (value)
+               retval = PL_strdup (value);
+       else
+               retval = PL_strdup ("");
 
-bool
-MoonlightClass::moonlightGetProperty (NPObject *npobj, NPIdentifier name, 
NPVariant *result)
-{
-       return ((MoonlightClass *) npobj->_class)->GetProperty 
((MoonlightObject *) npobj, name, result);
+       STRINGZ_TO_NPVARIANT (retval, *result);
 }
 
-bool
-MoonlightClass::moonlightSetProperty (NPObject *npobj, NPIdentifier name, 
const NPVariant *value)
+/*** Points ***/
+static NPObject* point_allocate (NPP instance, NPClass *)
 {
-       return ((MoonlightClass *) npobj->_class)->SetProperty 
((MoonlightObject *) npobj, name, value);
+       MoonlightPoint *p = new MoonlightPoint ();
+       p->x = p->y = 0.0;
 }
 
-bool
-MoonlightClass::moonlightRemoveProperty (NPObject *npobj, NPIdentifier name)
+static void point_deallocate (NPObject *npobject)
 {
-       return ((MoonlightClass *) npobj->_class)->RemoveProperty 
((MoonlightObject *) npobj, name);
+       // XXX is delete broken in plugins?
+       // delete (MoonlightPoint*)npobject;
 }
 
-bool
-MoonlightClass::moonlightHasMethod (NPObject *npobj, NPIdentifier name)
+static bool point_has_property (NPObject *npobj, NPIdentifier name)
 {
-       return ((MoonlightClass *) npobj->_class)->HasMethod ((MoonlightObject 
*) npobj, name);
+       return (name_matches (name, "x") ||
+               name_matches (name, "y"));
 }
 
-bool
-MoonlightClass::moonlightInvoke (NPObject *npobj, NPIdentifier name, const 
NPVariant *args, 
-                                uint32_t argCount, NPVariant *result)
+static bool point_get_property (NPObject *npobj, NPIdentifier name, NPVariant 
*result)
 {
-       return ((MoonlightClass *) npobj->_class)->Invoke ((MoonlightObject *) 
npobj, name, args, argCount, result);
+       MoonlightPoint *p = (MoonlightPoint*)npobj;
+       if (name_matches (name, "x")) {
+               DOUBLE_TO_NPVARIANT (p->x, *result);
+               return true;
+       }
+       else if (name_matches (name, "y")) {
+               DOUBLE_TO_NPVARIANT (p->y, *result);
+               return true;
+       }
+       else
+               return false;
 }
 
-bool
-MoonlightClass::moonlightInvokeDefault (NPObject *npobj, const NPVariant *args,
-                                       uint32_t argCount, NPVariant *result)
+static bool point_set_property (NPObject *npobj, NPIdentifier name, const 
NPVariant *value)
 {
-       return ((MoonlightClass *) npobj->_class)->InvokeDefault 
((MoonlightObject *) npobj, args, argCount, result);
+       MoonlightPoint *p = (MoonlightPoint*)npobj;
+       if (name_matches (name, "x")) {
+               p->x = NPVARIANT_TO_DOUBLE (*value);
+               return true;
+       }
+       else if (name_matches (name, "y")) {
+               p->y = NPVARIANT_TO_DOUBLE (*value);
+               return true;
+       }
+       else
+               return false;
 }
 
-/*** MoonlightClass 
**************************************************************/
 
-MoonlightClass::MoonlightClass ()
+MoonlightPointType::MoonlightPointType ()
 {
-       this->allocate       = moonlightAllocate;
-       this->deallocate     = moonlightDeallocate;
-       this->invalidate     = moonlightInvalidate;
-       this->hasProperty    = moonlightHasProperty;
-       this->getProperty    = moonlightGetProperty;
-       this->setProperty    = moonlightSetProperty;
-       this->removeProperty = moonlightRemoveProperty;
-       this->hasMethod      = moonlightHasMethod;
-       this->invoke         = moonlightInvoke;
-       this->invokeDefault  = moonlightInvokeDefault;
-}
+       allocate = point_allocate;
+       deallocate = point_deallocate;
+       hasProperty = point_has_property;
+       getProperty = point_get_property;
+       setProperty = point_set_property;
 
-MoonlightClass::~MoonlightClass ()
-{
-       // nothing to do.
+       invalidate = NULL;
+       hasMethod = NULL;
+       invoke = NULL;
+       invokeDefault = NULL;
 }
 
-MoonlightObject*
-MoonlightClass::AllocateObject (NPP instance)
+MoonlightPointType *MoonlightPointClass;
+
+
+/*** our object base class */
+NPObject*
+moonlight_object_allocate (NPP instance, NPClass*)
 {
        return new MoonlightObject (instance);
 }
 
-void
-MoonlightClass::DeallocateObject (MoonlightObject *npobj)
+static void
+moonlight_object_deallocate (NPObject *npobj)
 {
-  // XXX this is crashing?  bad....
-  //   delete npobj;
+       // XXX is delete broken in plugins?
+       // delete (MoonlightObject*)npobj;
 }
 
-void
-MoonlightClass::InvalidateObject (MoonlightObject *npobj)
+static void
+moonlight_object_invalidate (NPObject *npobj)
 {
-       // nothing to do.
+       // nothing to do
 }
 
-bool
-MoonlightClass::HasProperty (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_object_has_method (NPObject *npobj, NPIdentifier name)
 {
-       NPUTF8 * strname = NPN_UTF8FromIdentifier (name);
-       DEBUGMSG ("*** MoonlightClass::HasProperty %s", strname);
-       NPN_MemFree(strname);
-
        return false;
 }
 
-bool
-MoonlightClass::GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result)
+static bool
+moonlight_object_has_property (NPObject *npobj, NPIdentifier name)
 {
-       DEBUGMSG ("*** MoonlightClass::GetProperty");
        return false;
 }
 
-bool
-MoonlightClass::SetProperty (MoonlightObject *npobj, NPIdentifier name, const 
NPVariant *value)
+static bool
+moonlight_object_get_property (NPObject *npobj, NPIdentifier name, NPVariant 
*result)
 {
-       DEBUGMSG ("*** MoonlightClass::SetProperty");
+       g_warning ("moonlight_object_get_property reached");
        return false;
 }
 
-bool
-MoonlightClass::RemoveProperty (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_object_set_property (NPObject *npobj, NPIdentifier name, const 
NPVariant *value)
 {
+       g_warning ("moonlight_object_set_property reached");
        return false;
 }
 
-bool
-MoonlightClass::HasMethod (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_object_remove_property (NPObject *npobj, NPIdentifier name)
 {
-       NPUTF8 * strname = NPN_UTF8FromIdentifier (name);
-       DEBUGMSG ("*** MoonlightClass::HasMethod %s", strname);
-       NPN_MemFree(strname);
-
+       g_warning ("moonlight_object_remove_property reached");
        return false;
 }
 
-bool
-MoonlightClass::Invoke (MoonlightObject *npobj, NPIdentifier name, const 
NPVariant *args, 
-                       uint32_t argCount, NPVariant *result)
+static bool
+moonlight_object_invoke (NPObject *npobj, NPIdentifier name,
+                        const NPVariant *args, uint32_t argCount,
+                        NPVariant *result)
 {
-       DEBUGMSG ("*** MoonlightClass::Invoke");
+       g_warning ("moonlight_object_invoke reached");
        return false;
 }
 
-bool
-MoonlightClass::InvokeDefault (MoonlightObject *npobj, const NPVariant *args,
-                              uint32_t argCount, NPVariant *result)
+static bool
+moonlight_object_invoke_default (NPObject *npobj,
+                                const NPVariant *args, uint32_t argCount,
+                                NPVariant *result)
 {
-       DEBUGMSG ("*** MoonlightClass::InvokeDefault");
+       g_warning ("moonlight_object_invoke_default reached");
        return false;
 }
 
-int
-MoonlightClass::IndexOf (NPIdentifier name, const char *const names[], int 
count)
+MoonlightObjectType::MoonlightObjectType ()
 {
-       for (int i = 0; i < count; i++) {
-               if (name_matches (name, names[i]))
-                       return i;
-       }
-
-       return -1;
+       allocate       = moonlight_object_allocate;
+       deallocate     = moonlight_object_deallocate;
+       invalidate     = moonlight_object_invalidate;
+       hasMethod      = moonlight_object_has_method;
+       invoke         = moonlight_object_invoke;
+       invokeDefault  = moonlight_object_invoke_default;
+       hasProperty    = moonlight_object_has_property;
+       getProperty    = moonlight_object_get_property;
+       setProperty    = moonlight_object_set_property;
+       removeProperty = moonlight_object_remove_property;
 }
 
-void
-MoonlightClass::StringToNPVariant (char *value, NPVariant *result)
-{
-       int len;
-       char * retval;
+MoonlightObjectType* MoonlightObjectClass;
 
-       if (value) {
-               len = strlen (value);
-               retval = (char *) NPN_MemAlloc (len + 1);
-               strcpy (retval, value);
-       } else {
-               len = 0;
-               retval = (char *) NPN_MemAlloc (1);
-               retval[0] = 0;
-       }
-
-       STRINGN_TO_NPVARIANT (retval, len, *result);
-}
-
 /*** MoonlightControlClass 
**********************************************************/
-
-MoonlightControlClass* MoonlightControlClass::_class = NULL;
-
-MoonlightControlClass::MoonlightControlClass ()
+static NPObject*
+moonlight_control_allocate (NPP instance, NPClass*)
 {
+  printf ("in moonlight_control_allocate!  yay!\n");
+       return new MoonlightControlObject (instance);
 }
 
-const char *const MoonlightControlClass::properties[] = {
-       "settings",   // read only
-       "content",    // read only
-       "initParams", // read only
-       "isLoaded",   // read only
-       "source"      // read write (cant be set after initialization)
-};
-const char *const MoonlightControlClass::methods[] = { };
-
-MoonlightObject*
-MoonlightControlClass::AllocateObject (NPP instance)
+static void
+moonlight_control_deallocate (NPObject *npobj)
 {
-       return new MoonlightControlObject (instance);
+       // XXX is delete broken in plugins?
+       // delete (MoonlightControlObject*)npobj;
 }
 
-void
-MoonlightControlClass::InvalidateObject (MoonlightObject *npobj)
+static void
+moonlight_control_invalidate (NPObject *npobj)
 {
        MoonlightControlObject *control = (MoonlightControlObject*)npobj;
 
@@ -261,22 +247,23 @@
        control->content = NULL;
 }
 
-bool
-MoonlightControlClass::HasProperty (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_control_has_property (NPObject *npobj, NPIdentifier name)
 {
-       return HAS_PROPERTY (properties, name);
+  printf ("YO NO\n");
+       return (name_matches (name, "settings") ||
+               name_matches (name, "content") ||
+               name_matches (name, "initParams") ||
+               name_matches (name, "isLoaded") ||
+               name_matches (name, "source"));
 }
 
-bool
-MoonlightControlClass::HasMethod (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_control_get_property (NPObject *npobj, NPIdentifier name, NPVariant 
*result)
 {
-       return HAS_METHOD (methods, name);
-}
+  printf ("YO!\n");
 
-bool
-MoonlightControlClass::GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result)
-{
-       PluginInstance *plugin = (PluginInstance*) npobj->instance->pdata;
+       PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
        MoonlightControlObject *rootobj = (MoonlightControlObject*)npobj;
 
        if (name_matches (name, "settings")) {
@@ -290,7 +277,7 @@
        } 
 
        if (name_matches (name, "initParams")) {
-               StringToNPVariant (plugin->getInitParams (), result);
+               string_to_npvariant (plugin->getInitParams (), result);
                return true;
        } 
 
@@ -300,17 +287,17 @@
        } 
 
        if (name_matches (name, "source")) {
-               StringToNPVariant (plugin->getSource (), result);
+               string_to_npvariant (plugin->getSource (), result);
                return true;
        } 
 
        return false;
 }
 
-bool 
-MoonlightControlClass::SetProperty (MoonlightObject *npobj, NPIdentifier name, 
const NPVariant *value)
+static bool
+moonlight_control_set_property (NPObject *npobj, NPIdentifier name, const 
NPVariant *value)
 {
-       PluginInstance *plugin = (PluginInstance*) npobj->instance->pdata;
+       PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
 
        if (name_matches (name, "source")) {
                plugin->setSource (NPVARIANT_TO_STRING (*value).utf8characters);
@@ -320,22 +307,23 @@
        return false;
 }
 
-bool
-MoonlightControlClass::Invoke (MoonlightObject *npobj, NPIdentifier name, 
-                              const NPVariant *args, uint32_t argCount, 
NPVariant *result)
+MoonlightControlType::MoonlightControlType ()
 {
-       return false;
+       allocate = moonlight_control_allocate;
+       deallocate = moonlight_control_deallocate;
+       invalidate = moonlight_control_invalidate;
+
+       hasProperty = moonlight_control_has_property;
+       getProperty = moonlight_control_get_property;
+       setProperty = moonlight_control_set_property;
 }
 
+MoonlightControlType* MoonlightControlClass;
+
 /*** MoonlightSettingsClass 
***********************************************************/
 
-MoonlightSettingsClass* MoonlightSettingsClass::_class = NULL;
-
-MoonlightSettingsClass::MoonlightSettingsClass ()
-{
-}
-
-const char *const MoonlightSettingsClass::properties [] = {
+static const char *const
+moonlight_settings_properties [] = {
        "background",             // read write
        "enableFramerateCounter", // read write (cant be set after 
initialization)
        "enableRedrawRegions",    // read write
@@ -345,19 +333,19 @@
        "windowless"              // read write (cant be set after 
initialization)
 };
 
-bool
-MoonlightSettingsClass::HasProperty (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_settings_has_property (NPObject *npobj, NPIdentifier name)
 {
-       return HAS_PROPERTY (properties, name);
+       return HAS_PROPERTY (moonlight_settings_properties, name);
 }
 
-bool
-MoonlightSettingsClass::GetProperty (MoonlightObject *npobj, NPIdentifier 
name, NPVariant *result)
+static bool
+moonlight_settings_get_property (NPObject *npobj, NPIdentifier name, NPVariant 
*result)
 {
-       PluginInstance *plugin = (PluginInstance*) npobj->instance->pdata;
+       PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
 
        if (name_matches (name, "background")) {
-               StringToNPVariant (plugin->getBackground (), result);
+               string_to_npvariant (plugin->getBackground (), result);
                return true;
        }
 
@@ -383,7 +371,7 @@
        }
 
        if (name_matches (name, "version")) {
-               StringToNPVariant (PLUGIN_VERSION, result);
+               string_to_npvariant (PLUGIN_VERSION, result);
                return true;
        }
 
@@ -395,10 +383,10 @@
        return false;
 }
 
-bool 
-MoonlightSettingsClass::SetProperty (MoonlightObject *npobj, NPIdentifier 
name, const NPVariant *value)
+static bool 
+moonlight_settings_set_property (NPObject *npobj, NPIdentifier name, const 
NPVariant *value)
 {
-       PluginInstance *plugin = (PluginInstance*) npobj->instance->pdata;
+       PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
        if (name_matches (name, "background")) {
                plugin->setBackground (NPVARIANT_TO_STRING 
(*value).utf8characters);
                return true;
@@ -433,44 +421,50 @@
        return false;
 }
 
-/*** MoonlightContentClass 
************************************************************/
-
-MoonlightContentClass* MoonlightContentClass::_class = NULL;
-
-MoonlightContentClass::MoonlightContentClass ()
+MoonlightSettingsType::MoonlightSettingsType ()
 {
+       hasProperty = moonlight_settings_has_property;
+       getProperty = moonlight_settings_get_property;
+       setProperty = moonlight_settings_set_property;
 }
 
+MoonlightSettingsType* MoonlightSettingsClass;
 
-const char *const MoonlightContentClass::properties[] = {
+
+/*** MoonlightContentClass 
************************************************************/
+
+static const char *const
+moonlight_content_properties[] = {
        "actualHeight", // read only
        "actualWidth",  // read only
        "fullScreen",   // read write
        "onResize"
 };
 
-const char *const MoonlightContentClass::methods[] = {
+static const char *const
+moonlight_content_methods[] = {
+       "findName",
        "createObject",
        "createFromXaml",
        "createFromXamlDownloader"
 };
 
-bool
-MoonlightContentClass::HasProperty (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_content_has_property (NPObject *npobj, NPIdentifier name)
 {
-       return HAS_PROPERTY (properties, name);
+       return HAS_PROPERTY (moonlight_content_properties, name);
 }
 
-bool
-MoonlightContentClass::HasMethod (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_content_has_method (NPObject *npobj, NPIdentifier name)
 {
-       return HAS_METHOD (methods, name);
+       return HAS_METHOD (moonlight_content_methods, name);
 }
 
-bool
-MoonlightContentClass::GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result)
+static bool
+moonlight_content_get_property (NPObject *npobj, NPIdentifier name, NPVariant 
*result)
 {
-       PluginInstance *plugin = (PluginInstance*) npobj->instance->pdata;
+       PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
 
        if (name_matches (name, "actualHeight")) {
                // not implemented correctly yet - these only have values in 
fullscreen mode
@@ -496,8 +490,8 @@
        return false;
 }
 
-bool 
-MoonlightContentClass::SetProperty (MoonlightObject *npobj, NPIdentifier name, 
const NPVariant *value)
+static bool
+moonlight_content_set_property (NPObject *npobj, NPIdentifier name, const 
NPVariant *value)
 {
        // not implemented yet.
        if (name_matches (name, "fullScreen")) {
@@ -507,11 +501,28 @@
        return false;
 }
 
-bool
-MoonlightContentClass::Invoke (MoonlightObject *npobj, NPIdentifier name, 
-                              const NPVariant *args, uint32_t argCount, 
NPVariant *result)
+static bool
+moonlight_content_invoke (NPObject *npobj, NPIdentifier name, 
+                         const NPVariant *args, uint32_t argCount, NPVariant 
*result)
 {
-       if (name_matches (name, "createObject")) {
+       if (name_matches (name, "findName")) {
+               PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
+
+               if (!argCount)
+                       return true;
+
+               char *name = (char *) NPVARIANT_TO_STRING 
(args[0]).utf8characters;
+               
+               DependencyObject *element = 
plugin->surface->GetToplevel()->FindName (name);
+               if (!element)
+                       return true;
+
+               MoonlightDependencyObjectObject *depobj = 
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance, element);
+
+               OBJECT_TO_NPVARIANT (depobj, *result);
+               return true;
+       }
+       else if (name_matches (name, "createObject")) {
                // not implemented yet
                DEBUG_WARN_NOTIMPLEMENTED ();
                return true;
@@ -529,7 +540,7 @@
                control->InitializeFromXaml (xaml, &element_type);
 
                MoonlightDependencyObjectObject *depobj =
-                       MoonlightDependencyObjectClass::CreateWrapper 
(npobj->instance, control);
+                       DependencyObjectCreateWrapper 
(((MoonlightObject*)npobj)->instance, control);
 
                OBJECT_TO_NPVARIANT (depobj, *result);
 
@@ -544,24 +555,24 @@
        return false;
 }
 
-/*** MoonlightDependencyObjectClass 
***************************************************/
+MoonlightContentType::MoonlightContentType ()
+{
+       hasProperty = moonlight_content_has_property;
+       getProperty = moonlight_content_get_property;
+       setProperty = moonlight_content_set_property;
 
-MoonlightDependencyObjectClass* MoonlightDependencyObjectClass::_class = NULL;
+       hasMethod = moonlight_content_has_method;
+       invoke = moonlight_content_invoke;
+}
 
-const char *const MoonlightDependencyObjectClass::properties [] = {
-};
+MoonlightContentType* MoonlightContentClass;
 
-const char *const MoonlightDependencyObjectClass::methods [] = {
-       "getHost",
-       "captureMouse",
-       "releaseMouseCapture",
-       "addEventListener",
-       "removeEventListener",
-       "findName"
-};
 
-void
-value_to_variant (MoonlightObject *npobj, Value *v, NPVariant *result)
+
+/*** MoonlightDependencyObjectClass 
***************************************************/
+
+static void
+value_to_variant (NPObject *npobj, Value *v, NPVariant *result)
 {
        switch (v->GetKind ()) {
        case Type::BOOL:
@@ -576,33 +587,45 @@
                DOUBLE_TO_NPVARIANT (v->AsDouble(), *result);
                break;
        case Type::STRING:
-               STRINGZ_TO_NPVARIANT (PL_strdup (v->AsString()), *result);
+               string_to_npvariant (v->AsString(), result);
                break;
 
        /* more builtins.. */
        default:
                if (v->GetKind () >= Type::DEPENDENCY_OBJECT) {
                        MoonlightDependencyObjectObject *depobj =
-                               MoonlightDependencyObjectClass::CreateWrapper 
(npobj->instance, v->AsDependencyObject ());
+                               DependencyObjectCreateWrapper 
(((MoonlightObject*)npobj)->instance, v->AsDependencyObject ());
                        OBJECT_TO_NPVARIANT (depobj, *result);
                }
                break;
        }
 }
 
-MoonlightDependencyObjectClass::MoonlightDependencyObjectClass ()
-       : MoonlightClass ()
+static const char *const
+moonlight_dependency_object_methods [] = {
+       "getHost",
+       "captureMouse",
+       "releaseMouseCapture",
+       "addEventListener",
+       "removeEventListener",
+       "findName"
+};
+
+static NPObject*
+moonlight_dependency_object_allocate (NPP instance, NPClass*)
 {
+       return new MoonlightDependencyObjectObject (instance);
 }
 
-MoonlightObject *
-MoonlightDependencyObjectClass::AllocateObject (NPP instance)
+static void
+moonlight_dependency_object_deallocate (NPObject *npobj)
 {
-       return new MoonlightDependencyObjectObject (instance);
+       // XXX is delete broken in plugins?
+       // delete (MoonlightDependencyObjectObject*)npobj;
 }
 
-void
-MoonlightDependencyObjectClass::InvalidateObject (MoonlightObject *npobj)
+static void
+moonlight_dependency_object_invalidate (NPObject *npobj)
 {
        MoonlightDependencyObjectObject *depobj = 
(MoonlightDependencyObjectObject*)npobj;
 
@@ -611,8 +634,8 @@
        depobj->dob = NULL;
 }
 
-DependencyProperty*
-MoonlightDependencyObjectClass::GetDependencyProperty (DependencyObject *obj, 
char *attrname)
+static DependencyProperty*
+_get_dependency_property (DependencyObject *obj, char *attrname)
 {
        attrname[0] = toupper(attrname[0]);
        DependencyProperty *p = obj->GetDependencyProperty (attrname);
@@ -635,29 +658,26 @@
        return p;
 }
 
-bool
-MoonlightDependencyObjectClass::HasProperty (MoonlightObject *npobj, 
NPIdentifier name)
+static bool
+moonlight_dependency_object_has_property (NPObject *npobj, NPIdentifier name)
 {
-       if (HAS_PROPERTY (properties, name))
-               return true;
-
        DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
 
        NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
-       DependencyProperty *p = GetDependencyProperty (dob, strname);
+       DependencyProperty *p = _get_dependency_property (dob, strname);
        NPN_MemFree (strname);
 
        return (p != NULL);
 }
 
-bool
-MoonlightDependencyObjectClass::GetProperty (MoonlightObject *npobj, 
NPIdentifier name, NPVariant *result)
+static bool
+moonlight_dependency_object_get_property (NPObject *npobj, NPIdentifier name, 
NPVariant *result)
 {
        DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
 
        NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
        strname[0] = toupper(strname[0]);
-       DependencyProperty *p = GetDependencyProperty (dob, strname);
+       DependencyProperty *p = _get_dependency_property (dob, strname);
        NPN_MemFree (strname);
 
        if (!p)
@@ -672,14 +692,14 @@
        return true;
 }
 
-bool 
-MoonlightDependencyObjectClass::SetProperty (MoonlightObject *npobj, 
NPIdentifier name, const NPVariant *value)
+static bool 
+moonlight_dependency_object_set_property (NPObject *npobj, NPIdentifier name, 
const NPVariant *value)
 {
        DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
 
        NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
        strname[0] = toupper(strname[0]);
-       DependencyProperty *p = GetDependencyProperty (dob, strname);
+       DependencyProperty *p = _get_dependency_property (dob, strname);
        NPN_MemFree (strname);
 
        if (!p)
@@ -708,13 +728,10 @@
        return true;
 }
 
-bool
-MoonlightDependencyObjectClass::HasMethod (MoonlightObject *npobj, 
NPIdentifier name)
+static bool
+moonlight_dependency_object_has_method (NPObject *npobj, NPIdentifier name)
 {
-       if (HAS_METHOD (methods, name))
-               return true;
-
-       return false;
+       return HAS_METHOD (moonlight_dependency_object_methods, name);
 }
 
 struct EventListenerProxy {
@@ -736,8 +753,8 @@
        NPVariant args[2];
        NPVariant result;
 
-       MoonlightDependencyObjectObject *depobj = 
MoonlightDependencyObjectClass::CreateWrapper (proxy->instance,
-                                                                               
                 /* XXX ew */ (DependencyObject*)sender);
+       MoonlightDependencyObjectObject *depobj = DependencyObjectCreateWrapper 
(proxy->instance,
+                                                                               
 /* XXX ew */ (DependencyObject*)sender);
 
        NPN_RetainObject (depobj); // XXX
 
@@ -749,10 +766,10 @@
        NPN_ReleaseVariantValue (&result);
 }
 
-bool
-MoonlightDependencyObjectClass::Invoke (MoonlightObject *npobj, NPIdentifier 
name,
-                                       const NPVariant *args, uint32_t 
argCount,
-                                       NPVariant *result)
+static bool
+moonlight_dependency_object_invoke (NPObject *npobj, NPIdentifier name,
+                                   const NPVariant *args, uint32_t argCount,
+                                   NPVariant *result)
 {
        DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
 
@@ -766,13 +783,13 @@
                if (!element)
                        return true;
 
-               MoonlightDependencyObjectObject *depobj = 
MoonlightDependencyObjectClass::CreateWrapper (npobj->instance, element);
+               MoonlightDependencyObjectObject *depobj = 
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance, element);
 
                OBJECT_TO_NPVARIANT (depobj, *result);
                return true;
        }
        else if (name_matches (name, "getHost")) {
-               PluginInstance *plugin = (PluginInstance*) 
npobj->instance->pdata;
+               PluginInstance *plugin = (PluginInstance*) 
((MoonlightObject*)npobj)->instance->pdata;
 
                OBJECT_TO_NPVARIANT ((NPObject*)plugin->getRootObject(), 
*result);
        }
@@ -782,7 +799,7 @@
                name[0] = toupper(name[0]);
 
                EventListenerProxy *proxy = new EventListenerProxy ();
-               proxy->instance = npobj->instance;
+               proxy->instance = ((MoonlightObject*)npobj)->instance;
                proxy->callback = NPVARIANT_TO_OBJECT (args[1]);
 
                NPN_RetainObject (proxy->callback);
@@ -811,21 +828,39 @@
                return true;
        }
        else
-               return MoonlightClass::Invoke (npobj, name,
-                                              args, argCount,
-                                              result);
+               return MoonlightObjectClass->invoke (npobj, name,
+                                                    args, argCount,
+                                                    result);
 }
 
+
+MoonlightDependencyObjectType::MoonlightDependencyObjectType ()
+{
+       allocate = moonlight_dependency_object_allocate;
+       deallocate = moonlight_dependency_object_deallocate;
+       invalidate = moonlight_dependency_object_invalidate;
+
+       hasProperty = moonlight_dependency_object_has_property;
+       setProperty = moonlight_dependency_object_set_property;
+       getProperty = moonlight_dependency_object_get_property;
+
+       hasMethod = moonlight_dependency_object_has_method;
+       invoke    = moonlight_dependency_object_invoke;
+}
+
+MoonlightDependencyObjectType* MoonlightDependencyObjectClass;
+
+
 MoonlightDependencyObjectObject*
-MoonlightDependencyObjectClass::CreateWrapper (NPP instance, DependencyObject 
*obj)
+DependencyObjectCreateWrapper (NPP instance, DependencyObject *obj)
 {
-       NPClass *np_class = MoonlightDependencyObjectClass::Class();
+       NPClass *np_class = MoonlightDependencyObjectClass;
 
        /* for DependencyObject subclasses which have special plugin classes, 
check here */
        if (Type::Find (obj->GetObjectType ())->IsSubclassOf (Type::COLLECTION))
-               np_class = MoonlightCollectionClass::Class();
+               np_class = MoonlightCollectionClass;
        else if (obj->GetObjectType() == Type::STORYBOARD)
-               np_class = MoonlightStoryboardClass::Class();
+               np_class = MoonlightStoryboardClass;
 
        MoonlightDependencyObjectObject *depobj
                = (MoonlightDependencyObjectObject*)NPN_CreateObject (instance,
@@ -837,15 +872,16 @@
 }
 
 
+
 /*** MoonlightCollectionClass 
***************************************************/
 
-MoonlightCollectionClass* MoonlightCollectionClass::_class = NULL;
-
-const char *const MoonlightCollectionClass::properties [] = {
+static const char *const
+moonlight_collection_properties [] = {
        "count"
 };
 
-const char *const MoonlightCollectionClass::methods [] = {
+static const char *const
+moonlight_collection_methods [] = {
        "add",
        "remove",
        "insert",
@@ -853,22 +889,17 @@
        "getItem"
 };
 
-MoonlightCollectionClass::MoonlightCollectionClass ()
-       : MoonlightDependencyObjectClass ()
+static bool
+moonlight_collection_has_property (NPObject *npobj, NPIdentifier name)
 {
-}
-
-bool
-MoonlightCollectionClass::HasProperty (MoonlightObject *npobj, NPIdentifier 
name)
-{
-       if (HAS_PROPERTY (properties, name))
+       if (HAS_PROPERTY (moonlight_collection_properties, name))
                return true;
 
-       return MoonlightDependencyObjectClass::HasProperty (npobj, name);
+       return MoonlightDependencyObjectClass->hasProperty (npobj, name);
 }
 
-bool
-MoonlightCollectionClass::GetProperty (MoonlightObject *npobj, NPIdentifier 
name, NPVariant *result)
+static bool
+moonlight_collection_get_property (NPObject *npobj, NPIdentifier name, 
NPVariant *result)
 {
        Collection *col = 
(Collection*)((MoonlightDependencyObjectObject*)npobj)->dob;
 
@@ -876,23 +907,27 @@
                INT32_TO_NPVARIANT (col->list->Length(), *result);        
                return true;
        }
+       else
+               return MoonlightDependencyObjectClass->getProperty (npobj, 
name, result);
 
        return false;
 }
 
-bool
-MoonlightCollectionClass::HasMethod (MoonlightObject *npobj, NPIdentifier name)
+
+
+static bool
+moonlight_collection_has_method (NPObject *npobj, NPIdentifier name)
 {
-       if (HAS_METHOD (methods, name))
+       if (HAS_METHOD (moonlight_collection_methods, name))
                return true;
 
-       return MoonlightDependencyObjectClass::HasMethod (npobj, name);
+       return MoonlightDependencyObjectClass->hasMethod (npobj, name);
 }
 
-bool
-MoonlightCollectionClass::Invoke (MoonlightObject *npobj, NPIdentifier name,
-                                       const NPVariant *args, uint32_t 
argCount,
-                                       NPVariant *result)
+static bool
+moonlight_collection_invoke (NPObject *npobj, NPIdentifier name,
+                            const NPVariant *args, uint32_t argCount,
+                            NPVariant *result)
 {
        Collection *col = 
(Collection*)((MoonlightDependencyObjectObject*)npobj)->dob;
 
@@ -952,25 +987,35 @@
 
                Collection::Node *n = (Collection::Node*)col->list->Index 
(index);
 
-               MoonlightDependencyObjectObject *depobj = 
MoonlightDependencyObjectClass::CreateWrapper (npobj->instance,
-                                                                               
                         n->obj);
+               MoonlightDependencyObjectObject *depobj = 
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance,
+                                                                               
         n->obj);
                
                OBJECT_TO_NPVARIANT ((NPObject*)depobj, *result);
 
                return true;
        }
        else
-               return MoonlightDependencyObjectClass::Invoke (npobj, name,
+               return MoonlightDependencyObjectClass->invoke (npobj, name,
                                                               args, argCount,
                                                               result);
 }
 
 
+MoonlightCollectionType::MoonlightCollectionType ()
+{
+       hasProperty = moonlight_collection_has_property;
+       getProperty = moonlight_collection_get_property;
+       hasMethod = moonlight_collection_has_method;
+       invoke = moonlight_collection_invoke;
+}
+
+MoonlightCollectionType* MoonlightCollectionClass;
+
+
 /*** MoonlightStoryboardClass 
***************************************************/
 
-MoonlightStoryboardClass* MoonlightStoryboardClass::_class = NULL;
-
-const char *const MoonlightStoryboardClass::methods [] = {
+static const char *const
+moonlight_storyboard_methods [] = {
        "begin",
        "pause",
        "resume",
@@ -978,24 +1023,20 @@
        "stop"
 };
 
-MoonlightStoryboardClass::MoonlightStoryboardClass ()
-       : MoonlightDependencyObjectClass ()
-{
-}
 
-bool
-MoonlightStoryboardClass::HasMethod (MoonlightObject *npobj, NPIdentifier name)
+static bool
+moonlight_storyboard_has_method (NPObject *npobj, NPIdentifier name)
 {
-       if (HAS_METHOD (methods, name))
+       if (HAS_METHOD (moonlight_storyboard_methods, name))
                return true;
 
-       return MoonlightDependencyObjectClass::HasMethod (npobj, name);
+       return MoonlightDependencyObjectClass->hasMethod (npobj, name);
 }
 
-bool
-MoonlightStoryboardClass::Invoke (MoonlightObject *npobj, NPIdentifier name,
-                                 const NPVariant *args, uint32_t argCount,
-                                 NPVariant *result)
+static bool
+moonlight_storyboard_invoke (NPObject *npobj, NPIdentifier name,
+                            const NPVariant *args, uint32_t argCount,
+                            NPVariant *result)
 {
        Storyboard *sb = 
(Storyboard*)((MoonlightDependencyObjectObject*)npobj)->dob;
 
@@ -1053,8 +1094,30 @@
                return true;
        }
        else
-               return MoonlightDependencyObjectClass::Invoke (npobj, name,
+               return MoonlightDependencyObjectClass->invoke (npobj, name,
                                                               args, argCount,
                                                               result);
 }
 
+MoonlightStoryboardType::MoonlightStoryboardType ()
+{
+       hasMethod = moonlight_storyboard_has_method;
+       invoke = moonlight_storyboard_invoke;
+}
+
+MoonlightStoryboardType* MoonlightStoryboardClass;
+
+
+void
+plugin_init_classes ()
+{
+       MoonlightPointClass = new MoonlightPointType ();
+       MoonlightObjectClass = new MoonlightObjectType ();
+       MoonlightControlClass = new MoonlightControlType ();
+       MoonlightContentClass = new MoonlightContentType ();
+       MoonlightSettingsClass = new MoonlightSettingsType ();
+       MoonlightDependencyObjectClass = new MoonlightDependencyObjectType ();
+       MoonlightCollectionClass = new MoonlightCollectionType ();
+       MoonlightStoryboardClass = new MoonlightStoryboardType ();
+}
+

Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h    2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/plugin-class.h    2007-07-12 03:15:14 UTC (rev 81842)
@@ -16,181 +16,82 @@
 #include "moonlight.h"
 #include "plugin.h"
 
-/*** Macros 
*******************************************************************/
+void plugin_init_classes (void);
 
-#define NPID(x) NPN_GetStringIdentifier (x)
+/*** MoonlightPointClass  
**************************************************************/
+struct MoonlightPointType : NPClass {
+       MoonlightPointType ();
+};
 
-#define PLUGIN_PROPERTIES(x) \
-       bool HasProperty (MoonlightObject *npobj, NPIdentifier name); \
-       virtual bool GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result); \
-       virtual bool SetProperty (MoonlightObject *npobj, NPIdentifier name, 
const NPVariant *value);
+extern MoonlightPointType* MoonlightPointClass;
 
-#define PLUGIN_METHODS(x) \
-       bool HasMethod (MoonlightObject *npobj, NPIdentifier name); \
-       virtual bool Invoke (MoonlightObject *npobj, NPIdentifier name, const 
NPVariant *args,  \
-                            uint32_t argCount, NPVariant *result);
+struct MoonlightPoint : NPObject {
+       MoonlightPoint () { x = y = 0.0; }
 
-#define HAS_PROPERTY(x,v) \
-               (IndexOf (v, x, (sizeof (x) / sizeof (char *))) > -1)
-#define HAS_METHOD(x,v) \
-               (IndexOf (v, x, (sizeof (x) / sizeof (char *))) > -1)
+       double x;
+       double y;
+};
 
-/*** MoonlightObject 
*************************************************************/
+/*** MoonlightObjectClass 
**************************************************************/
 
-class MoonlightObject : public NPObject
-{
- public:
-       NPP instance;
+struct MoonlightObjectType : NPClass {
+       MoonlightObjectType ();
+};
 
+extern MoonlightObjectType* MoonlightObjectClass;
+
+struct MoonlightObject : public NPObject
+{
        MoonlightObject (NPP instance)
        {
                this->instance = instance;
        }
-};
 
-/*** MoonlightClass 
**************************************************************/
-
-class MoonlightClass : public NPClass
-{
- public:
-       virtual MoonlightObject* AllocateObject (NPP instance);
-       virtual void DeallocateObject (MoonlightObject *npobj);
-       virtual void InvalidateObject (MoonlightObject *npobj);
-
-       virtual bool HasProperty (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result);
-       virtual bool SetProperty (MoonlightObject *npobj, NPIdentifier name, 
const NPVariant *value);
-       virtual bool RemoveProperty (MoonlightObject *npobj, NPIdentifier name);
-
-       virtual bool HasMethod (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool Invoke (MoonlightObject *npobj, NPIdentifier name,
-                            const NPVariant *args, uint32_t argCount,
-                            NPVariant *result);
-       virtual bool InvokeDefault (MoonlightObject *npobj, const NPVariant 
*args,
-                                   uint32_t argCount, NPVariant *result);
-
- protected:
-       int IndexOf (NPIdentifier name, const char *const names[], int count);
-       void StringToNPVariant (char *value, NPVariant *result);
-
-       MoonlightClass ();
-       virtual ~MoonlightClass ();
-
-       /* these are the entry points through which the NPN_ api calls our code 
*/
-       static NPObject* moonlightAllocate (NPP instance, NPClass *aClass);
-       static void moonlightDeallocate (NPObject *npobj);
-       static void moonlightInvalidate (NPObject *npobj);
-       static bool moonlightHasProperty (NPObject *npobj, NPIdentifier name);
-       static bool moonlightGetProperty (NPObject *npobj, NPIdentifier name, 
NPVariant *result);
-       static bool moonlightSetProperty (NPObject *npobj, NPIdentifier name, 
const NPVariant *value);
-       static bool moonlightRemoveProperty (NPObject *npobj, NPIdentifier 
name);
-       static bool moonlightHasMethod (NPObject *npobj, NPIdentifier name);
-       static bool moonlightInvoke (NPObject *npobj, NPIdentifier name, const 
NPVariant *args, 
-                                    uint32_t argCount, NPVariant *result);
-       static bool moonlightInvokeDefault (NPObject *npobj, const NPVariant 
*args, 
-                                           uint32_t argCount, NPVariant 
*result);
+       NPP instance;
 };
 
 /*** MoonlightSettingsClass 
***********************************************************/
 
-class MoonlightSettingsClass : public MoonlightClass
-{
- public:
-       PLUGIN_PROPERTIES (properties);
-
-       static MoonlightSettingsClass* Class() {
-               if (_class == NULL)
-                       _class = new MoonlightSettingsClass ();
-               return _class;
-       }
-
- public:
-       MoonlightSettingsClass ();
-
- private:
-       static MoonlightSettingsClass *_class;
-
-       static const char *const properties [];
+struct MoonlightSettingsType : MoonlightObjectType {
+       MoonlightSettingsType ();
 };
+extern MoonlightSettingsType* MoonlightSettingsClass;
 
 /*** MoonlightContentClass 
************************************************************/
 
-// TODO:
-//onFullScreenChange = "eventhandlerFunction"
-//onResize = "eventhandlerFunction"
+struct MoonlightContentType : MoonlightObjectType {
+       MoonlightContentType ();
+};
 
-class MoonlightContentClass : public MoonlightClass
-{
- public:
-       PLUGIN_PROPERTIES (properties);
-       PLUGIN_METHODS (methods);
+extern MoonlightContentType* MoonlightContentClass;
 
-       static MoonlightContentClass* Class() {
-               if (_class == NULL)
-                       _class = new MoonlightContentClass ();
-               return _class;
-       }
+/*** MoonlightControlClass 
**********************************************************/
 
- protected:
-       MoonlightContentClass ();
-
- private:
-       static MoonlightContentClass *_class;
-
-       static const char *const properties [];
-       static const char *const methods [];
+struct MoonlightControlType : MoonlightObjectType {
+       MoonlightControlType ();
 };
+extern MoonlightControlType* MoonlightControlClass;
 
-/*** MoonlightControlClass 
**********************************************************/
-
-class MoonlightControlObject : public MoonlightObject
-{
- public:
-       NPObject *content;
-       NPObject *settings;
-
+struct MoonlightControlObject : public MoonlightObject {
        MoonlightControlObject (NPP instance) : MoonlightObject (instance)
        {
-               content = NPN_CreateObject (instance, 
MoonlightContentClass::Class());
-               settings = NPN_CreateObject (instance, 
MoonlightSettingsClass::Class());
+               content = NPN_CreateObject (instance, MoonlightContentClass);
+               settings = NPN_CreateObject (instance, MoonlightSettingsClass);
        }
-};
 
-// TODO:
-// onError = "eventhandlerFunction"
-
-class MoonlightControlClass : public MoonlightClass
-{
- public:
-       virtual MoonlightObject* AllocateObject (NPP instance);
-       virtual void InvalidateObject (MoonlightObject *npobj);
-
-       PLUGIN_PROPERTIES (properties);
-       PLUGIN_METHODS (methods);
-
-       static MoonlightControlClass* Class() {
-               if (_class == NULL)
-                       _class = new MoonlightControlClass ();
-               return _class;
-       }
-
- protected:
-       MoonlightControlClass ();
-
- private:
-       static MoonlightControlClass *_class;
-
-       static const char *const properties [];
-       static const char *const methods [];
+       NPObject *content;
+       NPObject *settings;
 };
 
 /*** MoonlightDependencyObjectClass 
***************************************************/
 
-class MoonlightDependencyObjectObject : public MoonlightObject
-{
- public:
-       DependencyObject *dob;
+struct MoonlightDependencyObjectType : MoonlightObjectType {
+       MoonlightDependencyObjectType ();
+};
+extern MoonlightDependencyObjectType *MoonlightDependencyObjectClass;
 
+struct MoonlightDependencyObjectObject : public MoonlightObject
+{
        MoonlightDependencyObjectObject (NPP instance) : MoonlightObject 
(instance)
        {
                dob = NULL;
@@ -201,94 +102,25 @@
                this->dob = dob;
                dob->ref ();
        }
-};
 
-class MoonlightDependencyObjectClass : public MoonlightClass
-{
- public:
-       virtual MoonlightObject *AllocateObject (NPP instance);
-       virtual void InvalidateObject (MoonlightObject *npobj);
-
-       virtual bool HasProperty (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result);
-       virtual bool SetProperty (MoonlightObject *npobj, NPIdentifier name, 
const NPVariant *value);
-
-       virtual bool HasMethod (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool Invoke (MoonlightObject *npobj, NPIdentifier name,
-                            const NPVariant *args, uint32_t argCount,
-                            NPVariant *result);
-
-       static MoonlightDependencyObjectClass* Class() {
-               if (_class == NULL)
-                       _class = new MoonlightDependencyObjectClass ();
-               return _class;
-       }
-
-       static MoonlightDependencyObjectObject* CreateWrapper (NPP instance, 
DependencyObject *obj);
-
- protected:
-       MoonlightDependencyObjectClass ();
-
- private:
-       DependencyProperty* GetDependencyProperty (DependencyObject *obj, char 
*attrname);
-
-       static MoonlightDependencyObjectClass *_class;
-
-       static const char *const properties [];
-       static const char *const methods [];
+       DependencyObject *dob;
 };
 
+extern MoonlightDependencyObjectObject* DependencyObjectCreateWrapper (NPP 
instance, DependencyObject *obj);
+
 /*** MoonlightCollectionClass 
***************************************************/
 
-class MoonlightCollectionClass : public MoonlightDependencyObjectClass
-{
- public:
-       virtual bool HasProperty (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool GetProperty (MoonlightObject *npobj, NPIdentifier name, 
NPVariant *result);
-       virtual bool HasMethod (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool Invoke (MoonlightObject *npobj, NPIdentifier name,
-                            const NPVariant *args, uint32_t argCount,
-                            NPVariant *result);
-
-       static MoonlightCollectionClass * Class() {
-               if (_class == NULL)
-                       _class = new MoonlightCollectionClass ();
-               return _class;
-       }
-
- protected:
-       MoonlightCollectionClass ();
-
- private:
-       static MoonlightCollectionClass *_class;
-
-       static const char *const properties [];
-       static const char *const methods [];
+struct MoonlightCollectionType : MoonlightDependencyObjectType {
+       MoonlightCollectionType ();
 };
+extern MoonlightCollectionType* MoonlightCollectionClass;
 
 /*** MoonlightCollectionClass 
***************************************************/
 
-class MoonlightStoryboardClass : public MoonlightDependencyObjectClass /* this 
should really inherit from the parallel timeline wrapper class */
-{
- public:
-       virtual bool HasMethod (MoonlightObject *npobj, NPIdentifier name);
-       virtual bool Invoke (MoonlightObject *npobj, NPIdentifier name,
-                            const NPVariant *args, uint32_t argCount,
-                            NPVariant *result);
-
-       static MoonlightStoryboardClass * Class() {
-               if (_class == NULL)
-                       _class = new MoonlightStoryboardClass ();
-               return _class;
-       }
-
- protected:
-       MoonlightStoryboardClass ();
-
- private:
-       static MoonlightStoryboardClass *_class;
-
-       static const char *const methods [];
+struct MoonlightStoryboardType : MoonlightDependencyObjectType {
+  MoonlightStoryboardType ();
 };
 
+extern MoonlightStoryboardType* MoonlightStoryboardClass;
+
 #endif /* PLUGIN_CLASS */

Modified: trunk/moon/plugin/plugin-glue.cpp
===================================================================
--- trunk/moon/plugin/plugin-glue.cpp   2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/plugin-glue.cpp   2007-07-12 03:15:14 UTC (rev 81842)
@@ -12,6 +12,7 @@
 
 #include "moonlight.h"
 #include "plugin.h"
+#include "plugin-class.h"
 #include "moon-mono.h"
 
 NPError 
@@ -223,6 +224,8 @@
                vm_init ();
 #endif
                runtime_init ();
+
+               plugin_init_classes ();
        }
        TimeManager::Instance()->Start();
 

Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp        2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/plugin.cpp        2007-07-12 03:15:14 UTC (rev 81842)
@@ -165,9 +165,9 @@
 
                case NPPVpluginScriptableNPObject:
                        if (rootobject == NULL)
-                               rootobject = 
(MoonlightControlObject*)NPN_CreateObject (instance, 
MoonlightControlClass::Class());
+                               rootobject = NPN_CreateObject (instance, 
MoonlightControlClass);
                        else
-                               NPN_RetainObject ((NPObject*)rootobject);
+                               NPN_RetainObject (rootobject);
 
                        *((NPObject **) result) = rootobject;
                        break;
@@ -314,7 +314,7 @@
        DependencyObject *toplevel = surface->GetToplevel ();
        DEBUGMSG ("In JsRunOnload, toplevel = %p", toplevel);
 
-       MoonlightDependencyObjectObject *depobj = 
MoonlightDependencyObjectClass::CreateWrapper (instance, 
surface->GetToplevel());
+       MoonlightDependencyObjectObject *depobj = DependencyObjectCreateWrapper 
(instance, surface->GetToplevel());
        OBJECT_TO_NPVARIANT ((NPObject*)depobj, args[0]);
 
        if (NPN_Invoke (instance, object, NPID (expression),
@@ -551,7 +551,7 @@
 PluginInstance::getRootObject ()
 {
        NPN_RetainObject (rootobject);
-       return rootobject;
+       return (MoonlightControlObject*)rootobject;
 }
 
 int32

Modified: trunk/moon/plugin/plugin.h
===================================================================
--- trunk/moon/plugin/plugin.h  2007-07-12 01:03:49 UTC (rev 81841)
+++ trunk/moon/plugin/plugin.h  2007-07-12 03:15:14 UTC (rev 81842)
@@ -23,7 +23,7 @@
        uint16 mode;           // NP_EMBED, NP_FULL, or NP_BACKGROUND
        NPWindow *window;      // Mozilla window object
        NPP instance;          // Mozilla instance object
-       MoonlightControlObject* rootobject;  // Mozilla jscript object wrapper
+       NPObject* rootobject;  // Mozilla jscript object wrapper
        bool xembed_supported; // XEmbed Extension supported
 
        // Property fields
@@ -97,6 +97,8 @@
 
 extern GSList *plugin_instances;
 
+#define NPID(x) NPN_GetStringIdentifier (x)
+
 #define STREAM_NOTIFY(x) ((StreamNotify*) x)
 
 #define STREAM_NOTIFY_DATA(x) ((StreamNotify*) x)->pdata

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to