Index: include/csplugincommon/canvas/graph2d.h
===================================================================
--- include/csplugincommon/canvas/graph2d.h	(revision 25072)
+++ include/csplugincommon/canvas/graph2d.h	(working copy)
@@ -60,13 +60,9 @@
  * slow since they are too general.
  */
 class CS_CRYSTALSPACE_EXPORT csGraphics2D : 
-  public scfImplementation6<csGraphics2D, 
-			    iGraphics2D,
-			    iComponent,
-			    iNativeWindow,
-			    iNativeWindowManager,
-			    iPluginConfig,
-			    iDebugHelper>
+  public scfImplementation7<csGraphics2D, 
+    iGraphics2D, iComponent, iNativeWindow, iNativeWindowManager,
+    iPluginConfig, iDebugHelper, iEventHandler>
 {
 public:
   /// The configuration file.
@@ -149,6 +145,8 @@
   void CreateDefaultFontCache ();
 
   csString name;
+  csHandlerID weakHandler;
+
 private:
   /// Find a color in palette mode.
   int FindRGBPalette (int r, int g, int b);
@@ -392,17 +390,8 @@
                                csRGBcolor fg = csRGBcolor(255,255,255),
                                csRGBcolor bg = csRGBcolor(0,0,0));
 
-  struct EventHandler : public scfImplementation1<EventHandler, iEventHandler>
-  {
-  private:
-    csGraphics2D* parent;
-  public:
-    EventHandler (csGraphics2D* parent) : scfImplementationType (this), 
-      parent(parent) {}
-    virtual bool HandleEvent (iEvent& e) { return parent->HandleEvent(e); }
-    CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common")
-    CS_EVENTHANDLER_NIL_CONSTRAINTS
-  } * scfiEventHandler;
+  CS_EVENTHANDLER_NAMES("crystalspace.graphics2d.common")
+  CS_EVENTHANDLER_NIL_CONSTRAINTS
 
 protected:
   /**
Index: libs/csplugincommon/canvas/graph2d.cpp
===================================================================
--- libs/csplugincommon/canvas/graph2d.cpp	(revision 25072)
+++ libs/csplugincommon/canvas/graph2d.cpp	(working copy)
@@ -45,7 +45,6 @@
 {
   static uint g2d_count = 0;
 
-  scfiEventHandler = 0;
   Memory = 0;
   LineAddress = 0;
   Palette = 0;
@@ -60,6 +59,7 @@
   AllowResizing = false;
   refreshRate = 0;
   vsync = false;
+  weakHandler = CS_HANDLER_INVALID;
 
   name.Format ("graph2d.%x", g2d_count++);
 
@@ -68,12 +68,11 @@
 
 csGraphics2D::~csGraphics2D ()
 {
-  if (scfiEventHandler)
+  if (weakHandler != CS_HANDLER_INVALID)
   {
     csRef<iEventQueue> q (CS_QUERY_REGISTRY(object_reg, iEventQueue));
     if (q != 0)
-      q->RemoveListener (scfiEventHandler);
-    scfiEventHandler->DecRef ();
+      RemoveWeakListener (q, object_reg, weakHandler);
   }
   Close ();
   delete [] Palette;
@@ -126,15 +125,13 @@
     Palette [i].blue = 0;
   }
 
-  if (!scfiEventHandler)
-    scfiEventHandler = new EventHandler (this);
   csRef<iEventQueue> q (CS_QUERY_REGISTRY(object_reg, iEventQueue));
   if (q != 0)
   {
     csEventID events[3] = { csevSystemOpen (object_reg), 
 			    csevSystemClose (object_reg), 
 			    CS_EVENTLIST_END };
-    q->RegisterListener (scfiEventHandler, events);
+    weakHandler = RegisterWeakListener (q, this, events);
   }
   return true;
 }
@@ -210,7 +207,7 @@
     Palette [i].blue = 0;
   }
 
-  scfiEventHandler = 0;
+  weakHandler = CS_HANDLER_INVALID;
 
   csGraphics2D::ofscb = ofscb;
 
