]> git.saurik.com Git - wxWidgets.git/commitdiff
Static object -> pointer
authorJulian Smart <julian@anthemion.co.uk>
Fri, 8 Aug 2003 11:08:11 +0000 (11:08 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Fri, 8 Aug 2003 11:08:11 +0000 (11:08 +0000)
Clean up renderer in module OnExit or we get a crash
on exit (under wxX11 at least). To-do: we need to add
priorities to wxModule so we can clean this up last.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/renderg.cpp

index 3fefc8eba4dc6c8936840fd2bc064550723fbefa..9e66312b2d1fe79d1a3c06e319720d428ad3650b 100644 (file)
@@ -33,9 +33,8 @@
 
 #include "wx/settings.h"
 #include "wx/splitter.h"
-
 #include "wx/dcmirror.h"
-
+#include "wx/module.h"
 #include "wx/renderer.h"
 
 // ----------------------------------------------------------------------------
@@ -72,6 +71,11 @@ public:
 
     virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
 
+    // Cleanup by deleting standard renderer
+    static void Cleanup();
+
+    // Get the generic object
+    static wxRendererGeneric* DoGetGeneric();
 
 protected:
     // draw the rectange using the first pen for the left and top sides and
@@ -84,12 +88,22 @@ protected:
           m_penDarkGrey,
           m_penLightGrey,
           m_penHighlight;
+
+    static wxRendererGeneric* sm_rendererGeneric;
 };
 
 // ============================================================================
 // wxRendererGeneric implementation
 // ============================================================================
 
+// Get the generic object
+wxRendererGeneric* wxRendererGeneric::DoGetGeneric()
+{
+    if (!sm_rendererGeneric)
+        sm_rendererGeneric = new wxRendererGeneric;
+    return sm_rendererGeneric;
+}
+
 // ----------------------------------------------------------------------------
 // wxRendererGeneric creation
 // ----------------------------------------------------------------------------
@@ -97,11 +111,19 @@ protected:
 /* static */
 wxRendererNative& wxRendererNative::GetGeneric()
 {
-    static wxRendererGeneric s_rendererGeneric;
+    return * wxRendererGeneric::DoGetGeneric();
+}
 
-    return s_rendererGeneric;
+void wxRendererGeneric::Cleanup()
+{
+    if (sm_rendererGeneric)
+        delete sm_rendererGeneric;
+    
+    sm_rendererGeneric = NULL;
 }
 
+wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL;
+
 wxRendererGeneric::wxRendererGeneric()
     : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)),
       m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)),
@@ -300,3 +322,15 @@ wxRendererGeneric::DrawSplitterSash(wxWindow *win,
     }
 }
 
+// A module to allow cleanup of generic renderer.
+class wxGenericRendererModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxGenericRendererModule)
+public:
+    wxGenericRendererModule() {}
+    bool OnInit() { return true; };
+    void OnExit() { wxRendererGeneric::Cleanup(); };
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule)
+