+#ifdef __WXMAC__
+ #include "wx/osx/dcclient.h"
+ #include "wx/osx/dcmemory.h"
+ #include "wx/osx/dcscreen.h"
+#endif
+
+#ifdef __WXPM__
+ #include "wx/os2/dcclient.h"
+ #include "wx/os2/dcmemory.h"
+ #include "wx/os2/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"
+#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 *wxDCFactory::m_factory = NULL;
+
+void wxDCFactory::Set(wxDCFactory *factory)
+{
+ delete m_factory;
+
+ m_factory = factory;
+}
+
+wxDCFactory *wxDCFactory::Get()
+{
+ if ( !m_factory )
+ m_factory = new wxNativeDCFactory;
+
+ 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, wxWindow *window )
+{
+ wxDCImpl * const impl = new wxWindowDCImpl( owner, window );
+ impl->InheritAttributes(window);
+ return impl;
+}
+
+wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner, wxWindow *window )
+{
+ wxDCImpl * const impl = new wxClientDCImpl( owner, window );
+ impl->InheritAttributes(window);
+ return impl;
+}
+
+wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner, wxWindow *window )
+{
+ wxDCImpl * const impl = new wxPaintDCImpl( owner, window );
+ impl->InheritAttributes(window);
+ return impl;
+}
+
+wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner )
+{
+ return new wxMemoryDCImpl( owner );
+}
+
+wxDCImpl* wxNativeDCFactory::CreateMemoryDC(wxMemoryDC *owner, wxBitmap& bitmap)
+{
+ // the bitmap may be modified when it's selected into a memory DC so make
+ // sure changing this bitmap doesn't affect any other shallow copies of it
+ // (see wxMemoryDC::SelectObject())
+ //
+ // notice that we don't provide any ctor equivalent to SelectObjectAsSource
+ // method because this should be rarely needed and easy to work around by
+ // using the default ctor and calling SelectObjectAsSource itself
+ if ( bitmap.IsOk() )
+ bitmap.UnShare();
+
+ return new wxMemoryDCImpl(owner, bitmap);
+}
+
+wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxDC *dc )
+{
+ return new wxMemoryDCImpl( owner, dc );
+}
+
+wxDCImpl* wxNativeDCFactory::CreateScreenDC( wxScreenDC *owner )
+{
+ return new wxScreenDCImpl( owner );
+}
+
+#if wxUSE_PRINTING_ARCHITECTURE
+wxDCImpl *wxNativeDCFactory::CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data )
+{
+ wxPrintFactory *factory = wxPrintFactory::GetFactory();
+ return factory->CreatePrinterDCImpl( owner, data );
+}
+#endif
+
+//-----------------------------------------------------------------------------
+// wxWindowDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxWindowDC, wxDC)
+
+wxWindowDC::wxWindowDC(wxWindow *win)
+ : wxDC(wxDCFactory::Get()->CreateWindowDC(this, win))
+{
+}
+
+//-----------------------------------------------------------------------------
+// wxClientDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxClientDC, wxWindowDC)
+
+wxClientDC::wxClientDC(wxWindow *win)
+ : wxWindowDC(wxDCFactory::Get()->CreateClientDC(this, win))
+{
+}
+
+//-----------------------------------------------------------------------------
+// wxMemoryDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
+
+wxMemoryDC::wxMemoryDC()
+ : wxDC(wxDCFactory::Get()->CreateMemoryDC(this))
+{
+}
+
+wxMemoryDC::wxMemoryDC(wxBitmap& bitmap)
+ : wxDC(wxDCFactory::Get()->CreateMemoryDC(this, bitmap))
+{
+}
+
+wxMemoryDC::wxMemoryDC(wxDC *dc)
+ : wxDC(wxDCFactory::Get()->CreateMemoryDC(this, dc))
+{
+}
+
+void wxMemoryDC::SelectObject(wxBitmap& bmp)
+{
+ // make sure that the given wxBitmap is not sharing its data with other
+ // wxBitmap instances as its contents will be modified by any drawing
+ // operation done on this DC
+ if (bmp.IsOk())
+ bmp.UnShare();
+
+ GetImpl()->DoSelect(bmp);
+}
+
+void wxMemoryDC::SelectObjectAsSource(const wxBitmap& bmp)
+{
+ GetImpl()->DoSelect(bmp);
+}
+
+const wxBitmap& wxMemoryDC::GetSelectedBitmap() const
+{
+ return GetImpl()->GetSelectedBitmap();
+}
+
+wxBitmap& wxMemoryDC::GetSelectedBitmap()
+{
+ return GetImpl()->GetSelectedBitmap();
+}
+
+
+//-----------------------------------------------------------------------------
+// wxPaintDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxPaintDC, wxClientDC)
+
+wxPaintDC::wxPaintDC(wxWindow *win)
+ : wxClientDC(wxDCFactory::Get()->CreatePaintDC(this, win))
+{
+}
+
+//-----------------------------------------------------------------------------
+// wxScreenDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
+
+wxScreenDC::wxScreenDC()
+ : wxDC(wxDCFactory::Get()->CreateScreenDC(this))
+{
+}
+
+//-----------------------------------------------------------------------------
+// wxPrinterDC
+//-----------------------------------------------------------------------------
+
+#if wxUSE_PRINTING_ARCHITECTURE
+
+IMPLEMENT_DYNAMIC_CLASS(wxPrinterDC, wxDC)
+
+wxPrinterDC::wxPrinterDC()
+ : wxDC(wxDCFactory::Get()->CreatePrinterDC(this, wxPrintData()))
+{
+}