// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_DC_H_
-#define _WX_DC_H_
+#ifndef _WX_MSW_DC_H_
+#define _WX_MSW_DC_H_
#include "wx/defs.h"
};
#endif
+// this is an ABC: use one of the derived classes to create a DC associated
+// with a window, screen, printer and so on
class WXDLLEXPORT wxDC : public wxDCBase
{
public:
- wxDC();
+ wxDC(WXHDC hDC) { Init(); m_hDC = hDC; }
~wxDC();
// implement base class pure virtuals
#endif
protected:
+ void Init()
+ {
+ m_canvas = NULL;
+ m_bOwnsDC = false;
+ m_hDC = NULL;
+
+ m_oldBitmap = NULL;
+ m_oldPen = NULL;
+ m_oldBrush = NULL;
+ m_oldFont = NULL;
+
+#if wxUSE_PALETTE
+ m_oldPalette = NULL;
+#endif // wxUSE_PALETTE
+ }
+
+ // create an uninitialized DC: this should be only used by the derived
+ // classes
+ wxDC() { Init(); }
+
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
int style = wxFLOOD_SURFACE);
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const;
- virtual void DoGetSize(int *width, int *height) const;
virtual void DoGetSizeMM(int* width, int* height) const;
virtual void DoDrawLines(int n, wxPoint points[],
// common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
void SetClippingHrgn(WXHRGN hrgn);
+ // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
+ // returns the size of the entire device this DC is associated with
+ //
+ // notice that we intentionally put it in a separate function instead of
+ // DoGetSize() itself because we want it to remain pure virtual both
+ // because each derived class should take care to define it as needed (this
+ // implementation is not at all always appropriate) and because we want
+ // wxDC to be an ABC to prevent it from being created directly
+ void GetDeviceSize(int *width, int *height) const;
+
+
// MSW-specific member variables
// -----------------------------
class WXDLLEXPORT wxDCTemp : public wxDC
{
public:
- wxDCTemp(WXHDC hdc) { SetHDC(hdc); }
- virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); }
+ wxDCTemp(WXHDC hdc) : wxDC(hdc)
+ {
+ }
+
+ virtual ~wxDCTemp()
+ {
+ // prevent base class dtor from freeing it
+ SetHDC((WXHDC)NULL);
+ }
+
+ virtual void DoGetSize(int *w, int *h) const
+ {
+ wxFAIL_MSG( _T("no way to retrieve the size of generic DC") );
+
+ if ( w )
+ *w = 0;
+ if ( h )
+ *h = 0;
+ }
private:
DECLARE_NO_COPY_CLASS(wxDCTemp)
};
-#endif
- // _WX_DC_H_
+#endif // _WX_MSW_DC_H_
+
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_DCPRINT_H_
-#define _WX_DCPRINT_H_
+#ifndef _WX_MSW_DCPRINT_H_
+#define _WX_MSW_DCPRINT_H_
#if wxUSE_PRINTING_ARCHITECTURE
wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
+ virtual void DoGetSize(int *w, int *h) const
+ {
+ GetDeviceSize(w, h);
+ }
+
// init the dc
void Init();
#endif // wxUSE_PRINTING_ARCHITECTURE
-#endif
- // _WX_DCPRINT_H_
+#endif // _WX_MSW_DCPRINT_H_
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_DCSCREEN_H_
-#define _WX_DCSCREEN_H_
+#ifndef _WX_MSW_DCSCREEN_H_
+#define _WX_MSW_DCSCREEN_H_
-#include "wx/dcclient.h"
+#include "wx/dc.h"
-class WXDLLEXPORT wxScreenDC : public wxWindowDC
+class WXDLLEXPORT wxScreenDC : public wxDC
{
public:
// Create a DC representing the whole screen
wxScreenDC();
+ // these functions are obsolete and shouldn't be used
+
// Compatibility with X's requirements for drawing on top of all windows
- static bool StartDrawingOnTop(wxWindow* WXUNUSED(window)) { return true; }
- static bool StartDrawingOnTop(wxRect* WXUNUSED(rect) = NULL) { return true; }
- static bool EndDrawingOnTop() { return true; }
+ wxDEPRECATED( static bool StartDrawingOnTop(wxWindow* window) );
+ wxDEPRECATED( static bool StartDrawingOnTop(wxRect* rect = NULL) );
+ wxDEPRECATED( static bool EndDrawingOnTop() );
protected:
- virtual void DoGetSize(int *width, int *height) const;
+ virtual void DoGetSize(int *w, int *h) const
+ {
+ GetDeviceSize(w, h);
+ }
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxScreenDC)
};
-#endif
- // _WX_DCSCREEN_H_
+#endif // _WX_MSW_DCSCREEN_H_
}
// draw the bitmap
- wxDC dst;
- dst.SetHDC((WXHDC) hDC, false);
+ wxDCTemp dst((WXHDC)hDC);
dst.DrawBitmap(*bitmap, x1, y1, true);
// draw focus / disabled state, if auto-drawing
// wxDC
// ---------------------------------------------------------------------------
-// Default constructor
-wxDC::wxDC()
-{
- m_canvas = NULL;
-
- m_oldBitmap = 0;
- m_oldPen = 0;
- m_oldBrush = 0;
- m_oldFont = 0;
-#if wxUSE_PALETTE
- m_oldPalette = 0;
-#endif // wxUSE_PALETTE
-
- m_bOwnsDC = false;
- m_hDC = 0;
-}
-
wxDC::~wxDC()
{
if ( m_hDC != 0 )
return success;
}
-void wxDC::DoGetSize(int *w, int *h) const
+void wxDC::GetDeviceSize(int *width, int *height) const
{
WXMICROWIN_CHECK_HDC
- if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES);
- if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES);
+ if ( width )
+ *width = ::GetDeviceCaps(GetHdc(), HORZRES);
+ if ( height )
+ *height = ::GetDeviceCaps(GetHdc(), VERTRES);
}
void wxDC::DoGetSizeMM(int *w, int *h) const
#include "wx/dcscreen.h"
-IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
+IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC)
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
::SetBkMode( GetHdc(), TRANSPARENT );
}
-void wxScreenDC::DoGetSize(int *width, int *height) const
+// deprecated functions
+bool wxScreenDC::StartDrawingOnTop(wxWindow* WXUNUSED(window))
{
- // skip wxWindowDC version because it doesn't work without a valid m_canvas
- // (which we don't have)
- wxDC::DoGetSize(width, height);
+ return true;
}
+bool wxScreenDC::StartDrawingOnTop(wxRect* WXUNUSED(rect))
+{
+ return true;
+}
+
+bool wxScreenDC::EndDrawingOnTop()
+{
+ return true;
+}
HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0);
#endif
- wxDC dc;
- dc.SetHDC((WXHDC)hdc);
- dc.SetFont(GetFont());
-
- pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
- pStruct->itemWidth = dc.GetCharWidth();
+ {
+ wxDCTemp dc((WXHDC)hdc);
+ dc.SetFont(GetFont());
- dc.SetHDC(0);
+ pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
+ pStruct->itemWidth = dc.GetCharWidth();
+ }
+#ifdef __WXWINCE__
+ ReleaseDC(NULL, hdc);
+#else
DeleteDC(hdc);
+#endif
return true;
}