]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dcbase.cpp
Fix Ok/IsOk() mess in wxGDIObject-derived classes; also added
[wxWidgets.git] / src / common / dcbase.cpp
index 9ef2b86534f491cf350728bc2cfb236fad5cd6cb..c0e98a3bdb6aea12993a1251c84c6426e7b8f789 100644 (file)
 #include "wx/dcmemory.h"
 #include "wx/dcscreen.h"
 #include "wx/dcprint.h"
-#include "wx/dcbuffer.h" // for IMPLEMENT_DYNAMIC_CLASS
 #include "wx/prntbase.h"
 
 #ifndef WX_PRECOMP
     #include "wx/math.h"
+    #include "wx/module.h"
 #endif
 
 #ifdef __WXMSW__
-#include "wx/msw/dcclient.h"
-#include "wx/msw/dcmemory.h"
-#include "wx/msw/dcscreen.h"
+    #include "wx/msw/dcclient.h"
+    #include "wx/msw/dcmemory.h"
+    #include "wx/msw/dcscreen.h"
 #endif
 
 #ifdef __WXGTK__
-#include "wx/gtk/dcclient.h"
-#include "wx/gtk/dcmemory.h"
-#include "wx/gtk/dcscreen.h"
+    #include "wx/gtk/dcclient.h"
+    #include "wx/gtk/dcmemory.h"
+    #include "wx/gtk/dcscreen.h"
 #endif
 
 #ifdef __WXMAC__
-#include "wx/mac/dcclient.h"
-#include "wx/mac/dcmemory.h"
-#include "wx/mac/dcscreen.h"
+    #include "wx/mac/dcclient.h"
+    #include "wx/mac/dcmemory.h"
+    #include "wx/mac/dcscreen.h"
+#endif
+
+#ifdef __WXCOCOA__
+    #include "wx/cocoa/dcclient.h"
+    #include "wx/cocoa/dcmemory.h"
+    #include "wx/cocoa/dcscreen.h"
+#endif
+
+#ifdef __WXMOTIF__
+    #include "wx/motif/dcclient.h"
+    #include "wx/motif/dcmemory.h"
+    #include "wx/motif/dcscreen.h"
 #endif
 
 #ifdef __WXX11__
-#include "wx/x11/dcclient.h"
-#include "wx/x11/dcmemory.h"
-#include "wx/x11/dcscreen.h"
+    #include "wx/x11/dcclient.h"
+    #include "wx/x11/dcmemory.h"
+    #include "wx/x11/dcscreen.h"
+#endif
+
+#ifdef __WXDFB__
+    #include "wx/dfb/dcclient.h"
+    #include "wx/dfb/dcmemory.h"
+    #include "wx/dfb/dcscreen.h"
+#endif
+
+#ifdef __WXPALMOS__
+    #include "wx/palmos/dcclient.h"
+    #include "wx/palmos/dcmemory.h"
+    #include "wx/palmos/dcscreen.h"
 #endif
 
 //----------------------------------------------------------------------------
 
 wxDCFactory *wxDCFactory::m_factory = NULL;
 
-void wxDCFactory::SetDCFactory( wxDCFactory *factory )
+void wxDCFactory::Set(wxDCFactory *factory)
 {
-    if (wxDCFactory::m_factory)
-        delete wxDCFactory::m_factory;
+    delete m_factory;
 
-    wxDCFactory::m_factory = factory;
+    m_factory = factory;
 }
 
-wxDCFactory *wxDCFactory::GetFactory()
+wxDCFactory *wxDCFactory::Get()
 {
-    if (!wxDCFactory::m_factory)
-        wxDCFactory::m_factory = new wxNativeDCFactory;
+    if ( !m_factory )
+        m_factory = new wxNativeDCFactory;
 
-    return wxDCFactory::m_factory;
+    return m_factory;
 }
 
+class wxDCFactoryCleanupModule : public wxModule
+{
+public:
+    virtual bool OnInit() { return true; }
+    virtual void OnExit() { wxDCFactory::Set(NULL); }
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxDCFactoryCleanupModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDCFactoryCleanupModule, wxModule)
+
 //-----------------------------------------------------------------------------
 // wxNativeDCFactory
 //-----------------------------------------------------------------------------
 
 wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner )
-{ 
+{
     return new wxWindowDCImpl( owner );
 }
 
 wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window )
-{ 
+{
     return new wxWindowDCImpl( owner, window );
 }
 
@@ -148,34 +183,24 @@ wxDCImpl *wxNativeDCFactory::CreatePrinterDC( wxPrinterDC *owner, const wxPrintD
 // wxWindowDC
 //-----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
+IMPLEMENT_ABSTRACT_CLASS(wxWindowDC, wxDC)
 
-wxWindowDC::wxWindowDC()
+wxWindowDC::wxWindowDC(wxWindow *win)
+          : wxDC(wxDCFactory::Get()->CreateWindowDC(this, win))
 {
 }
 
-wxWindowDC::wxWindowDC( wxWindow *win )
-{
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateWindowDC( this, win );
-}
-
 //-----------------------------------------------------------------------------
 // wxClientDC
 //-----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
+IMPLEMENT_ABSTRACT_CLASS(wxClientDC, wxWindowDC)
 
-wxClientDC::wxClientDC()
+wxClientDC::wxClientDC(wxWindow *win)
+          : wxWindowDC(wxDCFactory::Get()->CreateClientDC(this, win))
 {
 }
 
-wxClientDC::wxClientDC( wxWindow *win )
-{
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateClientDC( this, win );
-}
-
 //-----------------------------------------------------------------------------
 // wxMemoryDC
 //-----------------------------------------------------------------------------
@@ -183,21 +208,18 @@ wxClientDC::wxClientDC( wxWindow *win )
 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
 
 wxMemoryDC::wxMemoryDC()
+          : wxDC(wxDCFactory::Get()->CreateMemoryDC(this))
 {
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateMemoryDC( this );
 }
 
-wxMemoryDC::wxMemoryDC( wxBitmap& bitmap )
+wxMemoryDC::wxMemoryDC(wxBitmap& bitmap)
+          : wxDC(wxDCFactory::Get()->CreateMemoryDC(this, bitmap))
 {
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateMemoryDC( this, bitmap );
 }
 
-wxMemoryDC::wxMemoryDC( wxDC *dc )
+wxMemoryDC::wxMemoryDC(wxDC *dc)
+          : wxDC(wxDCFactory::Get()->CreateMemoryDC(this, dc))
 {
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateMemoryDC( this, dc );
 }
 
 void wxMemoryDC::SelectObject(wxBitmap& bmp)
@@ -226,23 +248,18 @@ wxBitmap& wxMemoryDC::GetSelectedBitmap()
     return GetImpl()->GetSelectedBitmap();
 }
 
-    
+
 //-----------------------------------------------------------------------------
 // wxPaintDC
 //-----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
+IMPLEMENT_ABSTRACT_CLASS(wxPaintDC, wxClientDC)
 
-wxPaintDC::wxPaintDC()
+wxPaintDC::wxPaintDC(wxWindow *win)
+         : wxClientDC(wxDCFactory::Get()->CreatePaintDC(this, win))
 {
 }
 
-wxPaintDC::wxPaintDC( wxWindow *win )
-{
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreatePaintDC( this, win );
-}
-
 //-----------------------------------------------------------------------------
 // wxScreenDC
 //-----------------------------------------------------------------------------
@@ -250,9 +267,8 @@ wxPaintDC::wxPaintDC( wxWindow *win )
 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
 
 wxScreenDC::wxScreenDC()
+          : wxDC(wxDCFactory::Get()->CreateScreenDC(this))
 {
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreateScreenDC( this );
 }
 
 //-----------------------------------------------------------------------------
@@ -264,19 +280,12 @@ wxScreenDC::wxScreenDC()
 IMPLEMENT_DYNAMIC_CLASS(wxPrinterDC, wxDC)
 
 wxPrinterDC::wxPrinterDC()
+           : wxDC(wxDCFactory::Get()->CreatePrinterDC(this, wxPrintData()))
 {
-    wxPrintData data;  // Does this make sense?
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreatePrinterDC( this, data );
 }
 
-wxPrinterDC::wxPrinterDC( const wxPrintData &data )
-{
-    wxDCFactory *factory = wxDCFactory::GetFactory();
-    m_pimpl = factory->CreatePrinterDC( this, data );
-}
-
-wxPrinterDC::~wxPrinterDC()
+wxPrinterDC::wxPrinterDC(const wxPrintData& data)
+           : wxDC(wxDCFactory::Get()->CreatePrinterDC(this, data))
 {
 }
 
@@ -290,7 +299,7 @@ int wxPrinterDC::GetResolution()
     return GetImpl()->GetResolution();
 }
 
-#endif
+#endif // wxUSE_PRINTING_ARCHITECTURE
 
 //-----------------------------------------------------------------------------
 // wxDCImpl
@@ -334,7 +343,7 @@ wxDCImpl::wxDCImpl( wxDC *owner )
                     (double)wxGetDisplaySizeMM().GetWidth();
     m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
                     (double)wxGetDisplaySizeMM().GetHeight();
-                    
+
     ResetBoundingBox();
     ResetClipping();
 }
@@ -1289,7 +1298,7 @@ void wxDC::GetTextExtent(const wxString& string,
             *externalLeading = externalLeading2;
     }
 
-void wxDC::GetLogicalOrigin(long *x, long *y) const 
+void wxDC::GetLogicalOrigin(long *x, long *y) const
     {
         wxCoord x2, y2;
         m_pimpl->DoGetLogicalOrigin(&x2, &y2);
@@ -1299,7 +1308,7 @@ void wxDC::GetLogicalOrigin(long *x, long *y) const
             *y = y2;
     }
 
-void wxDC::GetDeviceOrigin(long *x, long *y) const 
+void wxDC::GetDeviceOrigin(long *x, long *y) const
     {
         wxCoord x2, y2;
         m_pimpl->DoGetDeviceOrigin(&x2, &y2);
@@ -1307,9 +1316,9 @@ void wxDC::GetDeviceOrigin(long *x, long *y) const
             *x = x2;
         if ( y )
             *y = y2;
-    } 
-    
-void wxDC::GetClippingBox(long *x, long *y, long *w, long *h) const 
+    }
+
+void wxDC::GetClippingBox(long *x, long *y, long *w, long *h) const
     {
         wxCoord xx,yy,ww,hh;
         m_pimpl->DoGetClippingBox(&xx, &yy, &ww, &hh);
@@ -1317,6 +1326,6 @@ void wxDC::GetClippingBox(long *x, long *y, long *w, long *h) const
         if (y) *y = yy;
         if (w) *w = ww;
         if (h) *h = hh;
-    } 
-    
+    }
+
 #endif  // WXWIN_COMPATIBILITY_2_8