Author: toshok
Date: 2007-09-20 14:14:43 -0400 (Thu, 20 Sep 2007)
New Revision: 86095

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/animation.cpp
   trunk/moon/src/animation.h
   trunk/moon/src/clock.cpp
   trunk/moon/src/clock.h
   trunk/moon/src/dependencyobject.cpp
   trunk/moon/src/dependencyobject.h
   trunk/moon/src/downloader.cpp
   trunk/moon/src/downloader.h
   trunk/moon/src/media.cpp
   trunk/moon/src/media.h
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
   trunk/moon/src/type.cpp
   trunk/moon/src/type.cpp.in
   trunk/moon/src/type.h
   trunk/moon/src/type.h.in
   trunk/moon/src/typegen.cs
   trunk/moon/src/uielement.cpp
   trunk/moon/src/uielement.h
Log:
2007-09-20  Chris Toshok  <[EMAIL PROTECTED]>

        * typegen.cs (GenerateTypeCpp): add a call to
        types_init_register_events.

        * type.h.in, type.cpp.in: add Type::RegisterEvent,
        Type::LookupEvent, Type::GetEventCount, and Type::GetEventBase.

        * type.cpp.in: add types_init_register_events, which registers all
        the events we care about for all the types.  we do it here to
        guarantee that events have been registered by the time any
        instance code is run for any type.
        
        * dependencyobject.h, dependencyobject.cpp: remove the event
        registration from EventObject, it's moving to Type.  so the Type
        will contain the name to id hash, and the EventObject will only
        contain an array of GSLists, where the index into that array is
        the event's id.
        
        * clock.cpp (clock_init): lookup the static events here.

        * runtime.cpp (runtime_init): same.

        * animation.cpp (animation_init): same.

        * downloader.cpp (downloader_init): same.

        * uielement.cpp (uielement_init): same.

        * src/clock.h, src/uielement.h, src/media.h, src/animation.h,
        src/type.h, src/runtime.h, src/downloader.h: events are static to
        the classes now, instead of being per-instance.

        * src/types.h src/types.cpp: regen.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/ChangeLog    2007-09-20 18:14:43 UTC (rev 86095)
@@ -1,3 +1,38 @@
+2007-09-20  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * typegen.cs (GenerateTypeCpp): add a call to
+       types_init_register_events.
+
+       * type.h.in, type.cpp.in: add Type::RegisterEvent,
+       Type::LookupEvent, Type::GetEventCount, and Type::GetEventBase.
+
+       * type.cpp.in: add types_init_register_events, which registers all
+       the events we care about for all the types.  we do it here to
+       guarantee that events have been registered by the time any
+       instance code is run for any type.
+       
+       * dependencyobject.h, dependencyobject.cpp: remove the event
+       registration from EventObject, it's moving to Type.  so the Type
+       will contain the name to id hash, and the EventObject will only
+       contain an array of GSLists, where the index into that array is
+       the event's id.
+       
+       * clock.cpp (clock_init): lookup the static events here.
+
+       * runtime.cpp (runtime_init): same.
+
+       * animation.cpp (animation_init): same.
+
+       * downloader.cpp (downloader_init): same.
+
+       * uielement.cpp (uielement_init): same.
+
+       * src/clock.h, src/uielement.h, src/media.h, src/animation.h,
+       src/type.h, src/runtime.h, src/downloader.h: events are static to
+       the classes now, instead of being per-instance.
+
+       * src/types.h src/types.cpp: regen.
+       
 2007-09-20  Sebastien Pouliot  <[EMAIL PROTECTED]> 
 
        * geometry.cpp: Avoid re-allocating path memory when possible.

Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp        2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/animation.cpp        2007-09-20 18:14:43 UTC (rev 86095)
@@ -110,11 +110,11 @@
 
 DependencyProperty* Storyboard::TargetNameProperty;
 DependencyProperty* Storyboard::TargetPropertyProperty;
+int                 Storyboard::CompletedEvent = -1;
 
 Storyboard::Storyboard ()
   : root_clock (NULL)
 {
-       CompletedEvent = RegisterEvent ("Completed");
 }
 
 void
@@ -1600,6 +1600,9 @@
        ColorAnimationUsingKeyFrames::KeyFramesProperty = 
DependencyObject::Register (Type::COLORANIMATIONUSINGKEYFRAMES, "KeyFrames", 
Type::COLORKEYFRAME_COLLECTION);
        DoubleAnimationUsingKeyFrames::KeyFramesProperty = 
DependencyObject::Register (Type::DOUBLEANIMATIONUSINGKEYFRAMES, "KeyFrames", 
Type::DOUBLEKEYFRAME_COLLECTION);
        PointAnimationUsingKeyFrames::KeyFramesProperty = 
DependencyObject::Register (Type::POINTANIMATIONUSINGKEYFRAMES, "KeyFrames", 
Type::POINTKEYFRAME_COLLECTION);
+
+       /* lookup events */
+       Storyboard::CompletedEvent = Type::Find(Type::STORYBOARD)->LookupEvent 
("Completed");
 }
 
 void

Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h  2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/animation.h  2007-09-20 18:14:43 UTC (rev 86095)
@@ -539,7 +539,7 @@
        static char* GetTargetProperty (DependencyObject *o);
 
        // events you can AddHandler to
-       int CompletedEvent;
+       static int CompletedEvent;
 
  private:
        void HookupAnimationsRecurse (Clock *clock);

Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp    2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/clock.cpp    2007-09-20 18:14:43 UTC (rev 86095)
@@ -64,6 +64,8 @@
 
 
 TimeManager* TimeManager::_instance = NULL;
+int TimeManager::UpdateInputEvent = -1;
+int TimeManager::RenderEvent = -1;
 
 TimeManager::TimeManager ()
   : child_clocks (NULL),
@@ -75,9 +77,6 @@
        start_time = get_now ();
 
        tick_call_mutex = g_mutex_new ();
-
-       UpdateInputEvent = RegisterEvent ("update-input");
-       RenderEvent = RegisterEvent ("render");
 }
 
 void
@@ -255,6 +254,10 @@
 
 
 
+int Clock::CurrentTimeInvalidatedEvent = -1;
+int Clock::CurrentStateInvalidatedEvent = -1;
+int Clock::CurrentGlobalSpeedInvalidatedEvent = -1;
+int Clock::CompletedEvent = -1;
 
 
 Clock::Clock (Timeline *tl)
@@ -271,11 +274,6 @@
     queued_events (0),
     is_reversed (false)
 {
-       CurrentTimeInvalidatedEvent = RegisterEvent ("CurrentTimeInvalidated");
-       CurrentStateInvalidatedEvent = RegisterEvent 
("CurrentStateInvalidated");
-       CurrentGlobalSpeedInvalidatedEvent = RegisterEvent 
("CurrentGlobalSpeedInvalidated");
-       CompletedEvent = RegisterEvent ("Completed");
-
        RepeatBehavior *repeat = timeline->GetRepeatBehavior ();
        if (repeat->HasCount ()) {
                // remaining_iterations is an int.. GetCount returns a double.  
badness?
@@ -954,4 +952,16 @@
        TimelineMarker::TextProperty = DependencyObject::Register 
(Type::TIMELINEMARKER, "Text", Type::STRING);
        TimelineMarker::TimeProperty = DependencyObject::Register 
(Type::TIMELINEMARKER, "Time", Type::TIMESPAN);
        TimelineMarker::TypeProperty = DependencyObject::Register 
(Type::TIMELINEMARKER, "Type", Type::STRING);
+
+       /* lookup events */
+
+       Type *t = Type::Find (Type::TIMEMANAGER);
+       TimeManager::UpdateInputEvent = t->LookupEvent ("update-input");
+       TimeManager::RenderEvent = t->LookupEvent ("render");
+
+       t = Type::Find (Type::CLOCK);
+       Clock::CurrentTimeInvalidatedEvent = t->LookupEvent 
("CurrentTimeInvalidated");
+       Clock::CurrentStateInvalidatedEvent = t->LookupEvent 
("CurrentStateInvalidated");
+       Clock::CurrentGlobalSpeedInvalidatedEvent = t->LookupEvent 
("CurrentGlobalSpeedInvalidated");
+       Clock::CompletedEvent = t->LookupEvent ("Completed");
 }

Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h      2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/clock.h      2007-09-20 18:14:43 UTC (rev 86095)
@@ -191,8 +191,8 @@
        void AddTickCall (void (*func)(gpointer), gpointer tick_data);
 
        // Events you can AddHandler to
-       int UpdateInputEvent;
-       int RenderEvent;
+       static int UpdateInputEvent;
+       static int RenderEvent;
 
        virtual Type::Kind GetObjectType () { return Type::TIMEMANAGER; };
        
@@ -288,10 +288,10 @@
        void SetParent (Clock *parent) { parent_clock = parent; }
 
        // Events you can AddHandler to
-       int CurrentTimeInvalidatedEvent;
-       int CurrentStateInvalidatedEvent;
-       int CurrentGlobalSpeedInvalidatedEvent;
-       int CompletedEvent;
+       static int CurrentTimeInvalidatedEvent;
+       static int CurrentStateInvalidatedEvent;
+       static int CurrentGlobalSpeedInvalidatedEvent;
+       static int CompletedEvent;
 
  protected:
        // events to queue up

Modified: trunk/moon/src/dependencyobject.cpp
===================================================================
--- trunk/moon/src/dependencyobject.cpp 2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/dependencyobject.cpp 2007-09-20 18:14:43 UTC (rev 86095)
@@ -832,7 +832,6 @@
 EventObject::EventObject ()
 {
        events = NULL;
-       event_name_hash = NULL;
 }
 
 static void
@@ -841,90 +840,73 @@
        delete (EventClosure *) data;
 }
 
-static void
-event_list_delete (gpointer l)
-{
-       g_list_foreach ((GList*)l, (GFunc)deleter, NULL);
-}
-
 EventObject::~EventObject ()
 {
-       if (event_name_hash) {
-               g_hash_table_foreach (event_name_hash, (GHFunc)g_free, NULL);
-               g_hash_table_destroy (event_name_hash);
-       }
        if (events) {
-               g_ptr_array_foreach (events, (GFunc)event_list_delete, NULL);
+               for (int i = 0; i < GetType()->GetEventCount(); i ++)
+                       g_slist_foreach (events[i], (GFunc)deleter, NULL);
+               g_free (events);
        }
 }
 
 void
 EventObject::AddHandler (char *event_name, EventHandler handler, gpointer data)
 {
-       gpointer key, value;
+       int id = GetType()->LookupEvent (event_name);
 
-       //printf ("**** Removing handler %s pointing to %p with data %p\n");
-       if (!event_name_hash ||
-           !g_hash_table_lookup_extended (event_name_hash, event_name,
-                                          &key, &value)) {
+       if (id == -1) {
                g_warning ("adding handler to event '%s', which has not been 
registered\n", event_name);
                return;
        }
 
-       int id = GPOINTER_TO_INT (value);
-
        AddHandler (id, handler, data);
 }
 
 void
 EventObject::AddHandler (int event_id, EventHandler handler, gpointer data)
 { 
-       if (!events) {
+       if (GetType()->GetEventCount() <= 0) {
                g_warning ("adding handler to event with id %d, which has not 
been registered\n", event_id);
                return;
        }
 
-       GList *event_list = (GList*)g_ptr_array_index (events, event_id);
+       if (events == NULL) {
+               events = (GSList**)g_new0 (GSList*, GetType()->GetEventCount());
+       }
 
        EventClosure *closure = new EventClosure ();
        closure->func = handler;
        closure->data = data;
 
-       event_list = g_list_append (event_list, closure);
-
-       g_ptr_array_index (events, event_id) = event_list;
+       events[event_id] = g_slist_append (events[event_id], closure);
 }
 
 void
 EventObject::RemoveHandler (char *event_name, EventHandler handler, gpointer 
data)
 {
-       gpointer key, value;
+       int id = GetType()->LookupEvent (event_name);
 
-       //printf ("**** Removing handler %s pointing to %p with data %p\n");
-       if (!event_name_hash ||
-           !g_hash_table_lookup_extended (event_name_hash, event_name,
-                                          &key, &value)) {
+       if (id == -1) {
                g_warning ("removing handler for event '%s', which has not been 
registered\n", event_name);
                return;
        }
 
-       int id = GPOINTER_TO_INT (value);
-
        RemoveHandler (id, handler, data);
 }
 
 void
 EventObject::RemoveHandler (int event_id, EventHandler handler, gpointer data)
 {
-       if (!events) {
+       if (GetType()->GetEventCount() <= 0) {
                g_warning ("removing handler for event with id %d, which has 
not been registered\n", event_id);
                return;
        }
 
-       GList *event_list = (GList*)g_ptr_array_index (events, event_id);
+       if (events == NULL)
+               return;
 
-       GList *l;
-       for (l = event_list; l; l = l->next) {
+       GSList *l;
+       for (l = events[event_id]; l; l = l->next) {
                EventClosure *closure = (EventClosure*)l->data;
                if (closure->func == handler && closure->data == data)
                        break;
@@ -934,69 +916,41 @@
                return;
 
        delete (EventClosure*)l->data;
-       event_list = g_list_delete_link (event_list, l);
-
-       g_ptr_array_index (events, event_id) = event_list;
+       events[event_id] = g_slist_delete_link (events[event_id], l);
 }
 
-int
-EventObject::RegisterEvent (const char *event_name)
-{
-       if (events == NULL) {
-               event_name_hash = g_hash_table_new (g_str_hash, g_str_equal);
-               events = g_ptr_array_new ();
-       }
-
-       int id = events->len;
-
-       g_hash_table_insert (event_name_hash, g_strdup (event_name), 
GINT_TO_POINTER (id));
-
-       g_ptr_array_add (events, NULL);
-
-       return id;
-}
-
 void
 EventObject::Emit (char *event_name, gpointer calldata)
 {
-       if (events == NULL) {
+       int id = GetType()->LookupEvent (event_name);
+
+       if (id == -1) {
                g_warning ("trying to emit event '%s', which has not been 
registered\n", event_name);
                return;
        }
 
-       gpointer key, value;
-       if (!g_hash_table_lookup_extended (event_name_hash,
-                                          event_name,
-                                          &key,
-                                          &value))
-               return;
-
-       int id = GPOINTER_TO_INT (value);
-
        Emit (id, calldata);
 }
 
 void
 EventObject::Emit (int event_id, gpointer calldata)
 {
-       if (events == NULL) {
+       if (GetType()->GetEventCount() <= 0) {
                g_warning ("trying to emit event with id %d, which has not been 
registered\n", event_id);
                return;
        }
 
-       GList *event_list = (GList*)g_ptr_array_index (events, event_id);
-
-       if (event_list == NULL)
+       if (events == NULL || events[event_id] == NULL)
                return;
        
-       GList *copy = g_list_copy (event_list);
+       GSList *copy = g_slist_copy (events[event_id]);
 
-       for (GList *l = copy; l; l = l->next) {
+       for (GSList *l = copy; l; l = l->next) {
                EventClosure *closure = (EventClosure*)l->data;
                closure->func (this, calldata, closure->data);
        }
 
-       g_list_free (copy);
+       g_slist_free (copy);
 }
 
 void
@@ -1010,4 +964,3 @@
 {
        o->RemoveHandler (event, handler, closure);
 }
-

Modified: trunk/moon/src/dependencyobject.h
===================================================================
--- trunk/moon/src/dependencyobject.h   2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/dependencyobject.h   2007-09-20 18:14:43 UTC (rev 86095)
@@ -96,15 +96,13 @@
        void RemoveHandler (int event_id, EventHandler handler, gpointer data);
 
        virtual Type::Kind GetObjectType () { return Type::EVENTOBJECT; }
-       
+
  protected:
-       int  RegisterEvent (const char *event_name);
        void Emit (char *event_name, gpointer calldata = NULL);
        void Emit (int event_id, gpointer calldata = NULL);
 
  private:
-       GHashTable *event_name_hash;
-       GPtrArray *events;
+       GSList **events;
 };
 
 
@@ -230,7 +228,6 @@
 void event_object_add_event_handler (EventObject *o, char *event, EventHandler 
handler, gpointer closure);
 void event_object_remove_event_handler (EventObject *o, char *event, 
EventHandler handler, gpointer closure);
 
-
 G_END_DECLS
 
 #endif /* __MONO_DEPOBJECT_H__ */

Modified: trunk/moon/src/downloader.cpp
===================================================================
--- trunk/moon/src/downloader.cpp       2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/downloader.cpp       2007-09-20 18:14:43 UTC (rev 86095)
@@ -56,12 +56,12 @@
 downloader_send_func Downloader::send_func = NULL;
 downloader_abort_func Downloader::abort_func = NULL;
 
+int Downloader::CompletedEvent = -1;
+int Downloader::DownloadProgressChangedEvent = -1;
+int Downloader::DownloadFailedEvent = -1;
+
 Downloader::Downloader ()
 {
-       CompletedEvent               = RegisterEvent ("Completed");
-       DownloadProgressChangedEvent = RegisterEvent 
("DownloadProgressChanged");
-       DownloadFailedEvent          = RegisterEvent ("DownloadFailed");
-
        downloader_state = Downloader::create_state (this);
        notify_size = NULL;
        filename = NULL;
@@ -497,6 +497,12 @@
        Downloader::StatusTextProperty = DependencyObject::Register 
(Type::DOWNLOADER, "StatusText", Type::STRING);
        Downloader::UriProperty = DependencyObject::Register (Type::DOWNLOADER, 
"Uri", Type::STRING);
 
+       /* lookup events */
+       Type *t = Type::Find (Type::DOWNLOADER);
+       Downloader::CompletedEvent               = t->LookupEvent ("Completed");
+       Downloader::DownloadProgressChangedEvent = t->LookupEvent 
("DownloadProgressChanged");
+       Downloader::DownloadFailedEvent          = t->LookupEvent 
("DownloadFailed");
+
        Downloader::SetFunctions (dummy_downloader_create_state,
                                  dummy_downloader_destroy_state,
                                  dummy_downloader_open,

Modified: trunk/moon/src/downloader.h
===================================================================
--- trunk/moon/src/downloader.h 2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/downloader.h 2007-09-20 18:14:43 UTC (rev 86095)
@@ -51,9 +51,9 @@
        static DependencyProperty *UriProperty;
 
        // Events you can AddHandler to
-       int CompletedEvent;
-       int DownloadProgressChangedEvent;
-       int DownloadFailedEvent;
+       static int CompletedEvent;
+       static int DownloadProgressChangedEvent;
+       static int DownloadFailedEvent;
 
 
 

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/media.cpp    2007-09-20 18:14:43 UTC (rev 86095)
@@ -160,7 +160,15 @@
 DependencyProperty *MediaElement::PositionProperty;
 DependencyProperty *MediaElement::VolumeProperty;
 
+int MediaElement::BufferingProgressChangedEvent = -1;
+int MediaElement::CurrentStateChangedEvent = -1;
+int MediaElement::DownloadProgressChangedEvent = -1;
+int MediaElement::MarkerReachedEvent = -1;
+int MediaElement::MediaEndedEvent = -1;
+int MediaElement::MediaFailedEvent = -1;
+int MediaElement::MediaOpenedEvent = -1;
 
+
 bool
 MediaElement::AdvanceFrame ()
 {
@@ -208,15 +216,7 @@
        downloader = NULL;
        part_name = NULL;
        source = NULL;
-       
-       BufferingProgressChangedEvent = RegisterEvent 
("BufferingProgressChanged");
-       CurrentStateChangedEvent = RegisterEvent ("CurrentStateChanged");
-       DownloadProgressChangedEvent = RegisterEvent 
("DownloadProgressChanged");
-       MarkerReachedEvent = RegisterEvent ("MarkerReached");
-       MediaEndedEvent = RegisterEvent ("MediaEnded");
-       MediaFailedEvent = RegisterEvent ("MediaFailed");
-       MediaOpenedEvent = RegisterEvent ("MediaOpened");
-       
+
        TimelineMarkerCollection* col = new TimelineMarkerCollection ();
        media_element_set_markers (this, col);
        col->unref ();
@@ -913,6 +913,7 @@
 //
 GHashTable* Image::surface_cache = NULL;
 DependencyProperty* Image::DownloadProgressProperty;
+int Image::ImageFailedEvent = -1;
 
 Image::Image ()
   : create_xlib_surface (true),
@@ -923,7 +924,6 @@
     pattern_opacity (1.0),
     brush (NULL)
 {
-       ImageFailedEvent = RegisterEvent ("ImageFailed");
 }
 
 Image::~Image ()
@@ -1366,4 +1366,17 @@
        MediaElement::NaturalVideoWidthProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "NaturalVideoWidth", Type::DOUBLE);
        MediaElement::PositionProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "Position", Type::TIMESPAN);
        MediaElement::VolumeProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "Volume", new Value (0.5));
+
+       /* lookup events */
+       Type *t = Type::Find(Type::MEDIAELEMENT);
+       MediaElement::BufferingProgressChangedEvent = t->LookupEvent 
("BufferingProgressChanged");
+       MediaElement::CurrentStateChangedEvent = t->LookupEvent 
("CurrentStateChanged");
+       MediaElement::DownloadProgressChangedEvent = t->LookupEvent 
("DownloadProgressChanged");
+       MediaElement::MarkerReachedEvent = t->LookupEvent ("MarkerReached");
+       MediaElement::MediaEndedEvent = t->LookupEvent ("MediaEnded");
+       MediaElement::MediaFailedEvent = t->LookupEvent ("MediaFailed");
+       MediaElement::MediaOpenedEvent = t->LookupEvent ("MediaOpened");
+
+       t = Type::Find (Type::IMAGE);
+       Image::ImageFailedEvent = t->LookupEvent ("ImageFailed");
 }

Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h      2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/media.h      2007-09-20 18:14:43 UTC (rev 86095)
@@ -114,7 +114,7 @@
 
        static GHashTable *surface_cache;
 
-       int ImageFailedEvent;
+       static int ImageFailedEvent;
 };
 
 Image *image_new (void);
@@ -226,13 +226,13 @@
                         && (absolute_xform.yx == 0 && absolute_xform.xy == 0) 
/* no skew */);
        }
        
-       int BufferingProgressChangedEvent;
-       int CurrentStateChangedEvent;
-       int DownloadProgressChangedEvent;
-       int MarkerReachedEvent;
-       int MediaEndedEvent;
-       int MediaFailedEvent;
-       int MediaOpenedEvent;
+       static int BufferingProgressChangedEvent;
+       static int CurrentStateChangedEvent;
+       static int DownloadProgressChangedEvent;
+       static int MarkerReachedEvent;
+       static int MediaEndedEvent;
+       static int MediaFailedEvent;
+       static int MediaOpenedEvent;
 };
 
 MediaElement *media_element_new (void);

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/runtime.cpp  2007-09-20 18:14:43 UTC (rev 86095)
@@ -49,6 +49,9 @@
 #define TIME_CLIP 0
 #define TIME_REDRAW 1
 
+int Surface::ResizeEvent = -1;
+int Surface::FullScreenChangeEvent = -1;
+
 void
 Surface::CreateSimilarSurface ()
 {
@@ -83,7 +86,6 @@
     drawing_area_normal (NULL),
     drawing_area_fullscreen (NULL)
 {
-
        drawing_area = gtk_event_box_new ();
 
        InitializeDrawingArea (drawing_area);
@@ -97,9 +99,6 @@
        toplevel = NULL;
        capture_element = NULL;
 
-       ResizeEvent = RegisterEvent ("Resize");
-       FullScreenChangeEvent = RegisterEvent ("FullScreenChange");
-
        Realloc ();
        
        full_screen = false;
@@ -1052,8 +1051,6 @@
                g_type_init ();
        }
 
-       TimeManager::Instance()->Start();
-
        types_init ();
        namescope_init ();
        uielement_init ();
@@ -1074,6 +1071,13 @@
        media_init ();
        panel_init ();
        stylus_init ();
+
+       /* lookup surface events */
+       Type *t = Type::Find (Type::SURFACE);
+       Surface::ResizeEvent = t->LookupEvent ("Resize");
+       Surface::FullScreenChangeEvent = t->LookupEvent ("FullScreenChange");
+
+       TimeManager::Instance()->Start();
 }
 
 //

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/runtime.h    2007-09-20 18:14:43 UTC (rev 86095)
@@ -70,8 +70,8 @@
 
        UIElement* GetCapturedElement () { return capture_element; }
 
-       int ResizeEvent;
-       int FullScreenChangeEvent;
+       static int ResizeEvent;
+       static int FullScreenChangeEvent;
        
        bool GetFullScreen () { return full_screen; }
        void SetFullScreen (bool value);

Modified: trunk/moon/src/type.cpp
===================================================================
--- trunk/moon/src/type.cpp     2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/type.cpp     2007-09-20 18:14:43 UTC (rev 86095)
@@ -35,13 +35,71 @@
        this->name = strdup (name);
        this->type = type;
        this->parent = parent;
+
+       local_event_count = 0;
+       local_event_base = -1;
+       type_event_count = -1;
+       event_name_hash = NULL;
 }
 
 Type::~Type()
 {
+       if (event_name_hash) {
+               g_hash_table_foreach (event_name_hash, (GHFunc)g_free, NULL);
+               g_hash_table_destroy (event_name_hash);
+       }
+
+       event_name_hash = NULL;
+
        free (name);
 }
 
+void
+Type::RegisterEvent (const char *event_name)
+{
+       if (event_name_hash == NULL)
+               event_name_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+       g_hash_table_insert (event_name_hash, g_strdup (event_name), 
GINT_TO_POINTER (local_event_count++));
+}
+
+int
+Type::LookupEvent (const char *event_name)
+{
+       gpointer key, value;
+       if (!g_hash_table_lookup_extended (event_name_hash,
+                                          event_name,
+                                          &key,
+                                          &value)) {
+               printf ("type lookup of event '%s' failed\n", event_name);
+               return -1;
+       }
+
+       return GPOINTER_TO_INT (value) + GetEventBase();
+}
+
+int
+Type::GetEventBase ()
+{
+       if (local_event_base == -1) {
+               if (parent == Type::INVALID)
+                       local_event_base = 0;
+               else
+                       local_event_base = Type::Find(parent)->GetEventCount();
+       }
+
+       return local_event_base;
+}
+
+int
+Type::GetEventCount ()
+{
+       if (type_event_count == -1)
+               type_event_count = GetEventBase() + local_event_count;
+
+       return type_event_count;
+}
+
 Type *
 Type::RegisterType (const char *name, Type::Kind type, bool value_type)
 {
@@ -140,7 +198,7 @@
        return Type::Find (type)->value_type;
 }
 
-void 
+static void 
 types_init_manually (void)
 {
        // Put types that does not inherit from DependencyObject here (manually)
@@ -180,6 +238,57 @@
 #endif
 }
 
+static void 
+types_init_register_events (void)
+{
+       Type* t;
+
+       t = Type::Find (Type::STORYBOARD);
+       t->RegisterEvent ("Completed");
+
+       t = Type::Find (Type::TIMEMANAGER);
+       t->RegisterEvent ("update-input");
+       t->RegisterEvent ("render");
+
+       t = Type::Find (Type::CLOCK);
+       t->RegisterEvent ("CurrentTimeInvalidated");
+       t->RegisterEvent ("CurrentStateInvalidated");
+       t->RegisterEvent ("CurrentGlobalSpeedInvalidated");
+       t->RegisterEvent ("Completed");
+
+       t = Type::Find (Type::DOWNLOADER);
+       t->RegisterEvent ("Completed");
+       t->RegisterEvent ("DownloadProgressChanged");
+       t->RegisterEvent ("DownloadFailed");
+
+       t = Type::Find (Type::MEDIAELEMENT);
+       t->RegisterEvent ("BufferingProgressChanged");
+       t->RegisterEvent ("CurrentStateChanged");
+       t->RegisterEvent ("DownloadProgressChanged");
+       t->RegisterEvent ("MarkerReached");
+       t->RegisterEvent ("MediaEnded");
+       t->RegisterEvent ("MediaFailed");
+       t->RegisterEvent ("MediaOpened");
+
+       t = Type::Find (Type::IMAGE);
+       t->RegisterEvent ("ImageFailed");
+
+       t = Type::Find(Type::SURFACE);
+       t->RegisterEvent ("Resize");
+       t->RegisterEvent ("FullScreenChange");
+
+       t = Type::Find(Type::UIELEMENT);
+       t->RegisterEvent ("Loaded");
+       t->RegisterEvent ("MouseMove");
+       t->RegisterEvent ("MouseLeftButtonDown");
+       t->RegisterEvent ("MouseLeftButtonUp");
+       t->RegisterEvent ("KeyDown");
+       t->RegisterEvent ("KeyUp");
+       t->RegisterEvent ("MouseEnter");
+       t->RegisterEvent ("MouseLeave");
+       t->RegisterEvent ("Invalidated");
+}
+
 //
 // The generated code will be put at the end of the file
 //
@@ -305,4 +414,5 @@
        Type::RegisterType ("VisualBrush", Type::VISUALBRUSH, Type::TILEBRUSH);
        Type::RegisterType ("VisualCollection", Type::VISUAL_COLLECTION, 
Type::COLLECTION);
        types_init_manually ();
+       types_init_register_events ();
 }

Modified: trunk/moon/src/type.cpp.in
===================================================================
--- trunk/moon/src/type.cpp.in  2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/type.cpp.in  2007-09-20 18:14:43 UTC (rev 86095)
@@ -30,13 +30,71 @@
        this->name = strdup (name);
        this->type = type;
        this->parent = parent;
+
+       local_event_count = 0;
+       local_event_base = -1;
+       type_event_count = -1;
+       event_name_hash = NULL;
 }
 
 Type::~Type()
 {
+       if (event_name_hash) {
+               g_hash_table_foreach (event_name_hash, (GHFunc)g_free, NULL);
+               g_hash_table_destroy (event_name_hash);
+       }
+
+       event_name_hash = NULL;
+
        free (name);
 }
 
+void
+Type::RegisterEvent (const char *event_name)
+{
+       if (event_name_hash == NULL)
+               event_name_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+       g_hash_table_insert (event_name_hash, g_strdup (event_name), 
GINT_TO_POINTER (local_event_count++));
+}
+
+int
+Type::LookupEvent (const char *event_name)
+{
+       gpointer key, value;
+       if (!g_hash_table_lookup_extended (event_name_hash,
+                                          event_name,
+                                          &key,
+                                          &value)) {
+               printf ("type lookup of event '%s' failed\n", event_name);
+               return -1;
+       }
+
+       return GPOINTER_TO_INT (value) + GetEventBase();
+}
+
+int
+Type::GetEventBase ()
+{
+       if (local_event_base == -1) {
+               if (parent == Type::INVALID)
+                       local_event_base = 0;
+               else
+                       local_event_base = Type::Find(parent)->GetEventCount();
+       }
+
+       return local_event_base;
+}
+
+int
+Type::GetEventCount ()
+{
+       if (type_event_count == -1)
+               type_event_count = GetEventBase() + local_event_count;
+
+       return type_event_count;
+}
+
 Type *
 Type::RegisterType (const char *name, Type::Kind type, bool value_type)
 {
@@ -135,7 +193,7 @@
        return Type::Find (type)->value_type;
 }
 
-void 
+static void 
 types_init_manually (void)
 {
        // Put types that does not inherit from DependencyObject here (manually)
@@ -175,6 +233,57 @@
 #endif
 }
 
+static void 
+types_init_register_events (void)
+{
+       Type* t;
+
+       t = Type::Find (Type::STORYBOARD);
+       t->RegisterEvent ("Completed");
+
+       t = Type::Find (Type::TIMEMANAGER);
+       t->RegisterEvent ("update-input");
+       t->RegisterEvent ("render");
+
+       t = Type::Find (Type::CLOCK);
+       t->RegisterEvent ("CurrentTimeInvalidated");
+       t->RegisterEvent ("CurrentStateInvalidated");
+       t->RegisterEvent ("CurrentGlobalSpeedInvalidated");
+       t->RegisterEvent ("Completed");
+
+       t = Type::Find (Type::DOWNLOADER);
+       t->RegisterEvent ("Completed");
+       t->RegisterEvent ("DownloadProgressChanged");
+       t->RegisterEvent ("DownloadFailed");
+
+       t = Type::Find (Type::MEDIAELEMENT);
+       t->RegisterEvent ("BufferingProgressChanged");
+       t->RegisterEvent ("CurrentStateChanged");
+       t->RegisterEvent ("DownloadProgressChanged");
+       t->RegisterEvent ("MarkerReached");
+       t->RegisterEvent ("MediaEnded");
+       t->RegisterEvent ("MediaFailed");
+       t->RegisterEvent ("MediaOpened");
+
+       t = Type::Find (Type::IMAGE);
+       t->RegisterEvent ("ImageFailed");
+
+       t = Type::Find(Type::SURFACE);
+       t->RegisterEvent ("Resize");
+       t->RegisterEvent ("FullScreenChange");
+
+       t = Type::Find(Type::UIELEMENT);
+       t->RegisterEvent ("Loaded");
+       t->RegisterEvent ("MouseMove");
+       t->RegisterEvent ("MouseLeftButtonDown");
+       t->RegisterEvent ("MouseLeftButtonUp");
+       t->RegisterEvent ("KeyDown");
+       t->RegisterEvent ("KeyUp");
+       t->RegisterEvent ("MouseEnter");
+       t->RegisterEvent ("MouseLeave");
+       t->RegisterEvent ("Invalidated");
+}
+
 //
 // The generated code will be put at the end of the file
 //

Modified: trunk/moon/src/type.h
===================================================================
--- trunk/moon/src/type.h       2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/type.h       2007-09-20 18:14:43 UTC (rev 86095)
@@ -181,6 +181,11 @@
        char *name;
        bool value_type;
 
+       void RegisterEvent (const char *event_name);
+       int LookupEvent (const char *event_name);
+       int GetEventCount ();
+       int GetEventBase ();
+
        static void Shutdown ();
 private:
        Type (const char *name, Type::Kind type, Type::Kind parent);
@@ -188,6 +193,10 @@
        static Type** types;
        static GHashTable *types_by_name;
        static void free_type (gpointer v);
+       GHashTable *event_name_hash;
+       int local_event_base;
+       int local_event_count;
+       int type_event_count; /* local_event_base + local_event_count */
 };
 
 bool type_get_value_type (Type::Kind type);

Modified: trunk/moon/src/type.h.in
===================================================================
--- trunk/moon/src/type.h.in    2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/type.h.in    2007-09-20 18:14:43 UTC (rev 86095)
@@ -63,6 +63,11 @@
        char *name;
        bool value_type;
 
+       void RegisterEvent (const char *event_name);
+       int LookupEvent (const char *event_name);
+       int GetEventCount ();
+       int GetEventBase ();
+
        static void Shutdown ();
 private:
        Type (const char *name, Type::Kind type, Type::Kind parent);
@@ -70,6 +75,10 @@
        static Type** types;
        static GHashTable *types_by_name;
        static void free_type (gpointer v);
+       GHashTable *event_name_hash;
+       int local_event_base;
+       int local_event_count;
+       int type_event_count; /* local_event_base + local_event_count */
 };
 
 bool type_get_value_type (Type::Kind type);

Modified: trunk/moon/src/typegen.cs
===================================================================
--- trunk/moon/src/typegen.cs   2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/typegen.cs   2007-09-20 18:14:43 UTC (rev 86095)
@@ -275,6 +275,7 @@
                        }       
                }
                text.AppendLine ("\ttypes_init_manually ();");
+               text.AppendLine ("\ttypes_init_register_events ();");
                text.AppendLine ("}");
                File.WriteAllText ("type.cpp", text.ToString ());
        }

Modified: trunk/moon/src/uielement.cpp
===================================================================
--- trunk/moon/src/uielement.cpp        2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/uielement.cpp        2007-09-20 18:14:43 UTC (rev 86095)
@@ -23,6 +23,16 @@
 
 #define SHOW_BOUNDING_BOXES 0
 
+int UIElement::LoadedEvent = -1;
+int UIElement::MotionEvent = -1;
+int UIElement::ButtonPressEvent = -1;
+int UIElement::ButtonReleaseEvent = -1;
+int UIElement::KeyDownEvent = -1;
+int UIElement::KeyUpEvent = -1;
+int UIElement::EnterEvent = -1;
+int UIElement::LeaveEvent = -1;
+int UIElement::InvalidatedEvent = -1;
+
 void
 UIElement::UpdateBounds (bool force_redraw_of_new_bounds)
 {
@@ -40,16 +50,6 @@
 
 UIElement::UIElement () : opacityMask(NULL), parent(NULL), flags 
(UIElement::RENDER_VISIBLE | UIElement::HIT_TEST_VISIBLE)
 {
-       LoadedEvent = RegisterEvent ("Loaded");
-       MotionEvent = RegisterEvent ("MouseMove");
-       ButtonPressEvent = RegisterEvent ("MouseLeftButtonDown");
-       ButtonReleaseEvent = RegisterEvent ("MouseLeftButtonUp");
-       KeyDownEvent = RegisterEvent ("KeyDown");
-       KeyUpEvent = RegisterEvent ("KeyUp");
-       EnterEvent = RegisterEvent ("MouseEnter");
-       LeaveEvent = RegisterEvent ("MouseLeave");
-       InvalidatedEvent = RegisterEvent("Invalidated");
-
        bounds = Rect (0,0,0,0);
        cairo_matrix_init_identity (&absolute_xform);
 
@@ -531,6 +531,18 @@
        UIElement::TriggersProperty = DependencyObject::Register 
(Type::UIELEMENT, "Triggers", Type::TRIGGER_COLLECTION);
        UIElement::VisibilityProperty = DependencyObject::Register 
(Type::UIELEMENT, "Visibility", new Value ((gint32)VisibilityVisible));
        UIElement::ZIndexProperty = DependencyObject::Register 
(Type::UIELEMENT, "ZIndex", new Value ((gint32)0));;
+
+       /* lookup events */
+       Type* t = Type::Find (Type::UIELEMENT);
+       UIElement::LoadedEvent = t->LookupEvent ("Loaded");
+       UIElement::MotionEvent = t->LookupEvent ("MouseMove");
+       UIElement::ButtonPressEvent = t->LookupEvent ("MouseLeftButtonDown");
+       UIElement::ButtonReleaseEvent = t->LookupEvent ("MouseLeftButtonUp");
+       UIElement::KeyDownEvent = t->LookupEvent ("KeyDown");
+       UIElement::KeyUpEvent = t->LookupEvent ("KeyUp");
+       UIElement::EnterEvent = t->LookupEvent ("MouseEnter");
+       UIElement::LeaveEvent = t->LookupEvent ("MouseLeave");
+       UIElement::InvalidatedEvent = t->LookupEvent("Invalidated");
 }
 
 UIElement*

Modified: trunk/moon/src/uielement.h
===================================================================
--- trunk/moon/src/uielement.h  2007-09-20 18:08:19 UTC (rev 86094)
+++ trunk/moon/src/uielement.h  2007-09-20 18:14:43 UTC (rev 86095)
@@ -288,15 +288,15 @@
        static DependencyProperty* ZIndexProperty;
 
        // Events you can AddHandler to
-       int LoadedEvent;
-       int MotionEvent;
-       int ButtonPressEvent;
-       int ButtonReleaseEvent;
-       int KeyDownEvent;
-       int KeyUpEvent;
-       int EnterEvent;
-       int LeaveEvent;
-       int InvalidatedEvent;
+       static int LoadedEvent;
+       static int MotionEvent;
+       static int ButtonPressEvent;
+       static int ButtonReleaseEvent;
+       static int KeyDownEvent;
+       static int KeyUpEvent;
+       static int EnterEvent;
+       static int LeaveEvent;
+       static int InvalidatedEvent;
 };
 
 G_BEGIN_DECLS

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

Reply via email to