disallow creation of wxDC objects and made wxDC an ABC; use wxDCTemp instead of wxDC in wx code; fixed WinCE bug with deleting a DC which should be released in wxListBox::MSWOnMeasure()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36564 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_DC_H_
|
#ifndef _WX_MSW_DC_H_
|
||||||
#define _WX_DC_H_
|
#define _WX_MSW_DC_H_
|
||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
@@ -40,10 +40,12 @@ public:
|
|||||||
};
|
};
|
||||||
#endif
|
#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
|
class WXDLLEXPORT wxDC : public wxDCBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDC();
|
wxDC(WXHDC hDC) { Init(); m_hDC = hDC; }
|
||||||
~wxDC();
|
~wxDC();
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
@@ -138,6 +140,26 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
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,
|
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
|
||||||
int style = wxFLOOD_SURFACE);
|
int style = wxFLOOD_SURFACE);
|
||||||
|
|
||||||
@@ -186,7 +208,6 @@ protected:
|
|||||||
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
|
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
|
||||||
wxCoord *w, wxCoord *h) const;
|
wxCoord *w, wxCoord *h) const;
|
||||||
|
|
||||||
virtual void DoGetSize(int *width, int *height) const;
|
|
||||||
virtual void DoGetSizeMM(int* width, int* height) const;
|
virtual void DoGetSizeMM(int* width, int* height) const;
|
||||||
|
|
||||||
virtual void DoDrawLines(int n, wxPoint points[],
|
virtual void DoDrawLines(int n, wxPoint points[],
|
||||||
@@ -216,6 +237,17 @@ protected:
|
|||||||
// common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
|
// common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
|
||||||
void SetClippingHrgn(WXHRGN hrgn);
|
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
|
// MSW-specific member variables
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
@@ -259,12 +291,29 @@ protected:
|
|||||||
class WXDLLEXPORT wxDCTemp : public wxDC
|
class WXDLLEXPORT wxDCTemp : public wxDC
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDCTemp(WXHDC hdc) { SetHDC(hdc); }
|
wxDCTemp(WXHDC hdc) : wxDC(hdc)
|
||||||
virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
DECLARE_NO_COPY_CLASS(wxDCTemp)
|
DECLARE_NO_COPY_CLASS(wxDCTemp)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _WX_MSW_DC_H_
|
||||||
// _WX_DC_H_
|
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_DCPRINT_H_
|
#ifndef _WX_MSW_DCPRINT_H_
|
||||||
#define _WX_DCPRINT_H_
|
#define _WX_MSW_DCPRINT_H_
|
||||||
|
|
||||||
#if wxUSE_PRINTING_ARCHITECTURE
|
#if wxUSE_PRINTING_ARCHITECTURE
|
||||||
|
|
||||||
@@ -41,6 +41,11 @@ protected:
|
|||||||
wxCoord width, wxCoord height,
|
wxCoord width, wxCoord height,
|
||||||
wxDC *source, wxCoord xsrc, wxCoord ysrc,
|
wxDC *source, wxCoord xsrc, wxCoord ysrc,
|
||||||
int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
|
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
|
// init the dc
|
||||||
void Init();
|
void Init();
|
||||||
@@ -59,6 +64,5 @@ WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& data);
|
|||||||
|
|
||||||
#endif // wxUSE_PRINTING_ARCHITECTURE
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
||||||
|
|
||||||
#endif
|
#endif // _WX_MSW_DCPRINT_H_
|
||||||
// _WX_DCPRINT_H_
|
|
||||||
|
|
||||||
|
@@ -9,29 +9,33 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_DCSCREEN_H_
|
#ifndef _WX_MSW_DCSCREEN_H_
|
||||||
#define _WX_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:
|
public:
|
||||||
// Create a DC representing the whole screen
|
// Create a DC representing the whole screen
|
||||||
wxScreenDC();
|
wxScreenDC();
|
||||||
|
|
||||||
|
// these functions are obsolete and shouldn't be used
|
||||||
|
|
||||||
// Compatibility with X's requirements for drawing on top of all windows
|
// Compatibility with X's requirements for drawing on top of all windows
|
||||||
static bool StartDrawingOnTop(wxWindow* WXUNUSED(window)) { return true; }
|
wxDEPRECATED( static bool StartDrawingOnTop(wxWindow* window) );
|
||||||
static bool StartDrawingOnTop(wxRect* WXUNUSED(rect) = NULL) { return true; }
|
wxDEPRECATED( static bool StartDrawingOnTop(wxRect* rect = NULL) );
|
||||||
static bool EndDrawingOnTop() { return true; }
|
wxDEPRECATED( static bool EndDrawingOnTop() );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DoGetSize(int *width, int *height) const;
|
virtual void DoGetSize(int *w, int *h) const
|
||||||
|
{
|
||||||
|
GetDeviceSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxScreenDC)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxScreenDC)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _WX_MSW_DCSCREEN_H_
|
||||||
// _WX_DCSCREEN_H_
|
|
||||||
|
|
||||||
|
@@ -304,8 +304,7 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draw the bitmap
|
// draw the bitmap
|
||||||
wxDC dst;
|
wxDCTemp dst((WXHDC)hDC);
|
||||||
dst.SetHDC((WXHDC) hDC, false);
|
|
||||||
dst.DrawBitmap(*bitmap, x1, y1, true);
|
dst.DrawBitmap(*bitmap, x1, y1, true);
|
||||||
|
|
||||||
// draw focus / disabled state, if auto-drawing
|
// draw focus / disabled state, if auto-drawing
|
||||||
|
@@ -258,23 +258,6 @@ wxColourChanger::~wxColourChanger()
|
|||||||
// wxDC
|
// 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()
|
wxDC::~wxDC()
|
||||||
{
|
{
|
||||||
if ( m_hDC != 0 )
|
if ( m_hDC != 0 )
|
||||||
@@ -2285,12 +2268,14 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDC::DoGetSize(int *w, int *h) const
|
void wxDC::GetDeviceSize(int *width, int *height) const
|
||||||
{
|
{
|
||||||
WXMICROWIN_CHECK_HDC
|
WXMICROWIN_CHECK_HDC
|
||||||
|
|
||||||
if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES);
|
if ( width )
|
||||||
if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES);
|
*width = ::GetDeviceCaps(GetHdc(), HORZRES);
|
||||||
|
if ( height )
|
||||||
|
*height = ::GetDeviceCaps(GetHdc(), VERTRES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDC::DoGetSizeMM(int *w, int *h) const
|
void wxDC::DoGetSizeMM(int *w, int *h) const
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "wx/dcscreen.h"
|
#include "wx/dcscreen.h"
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
|
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC)
|
||||||
|
|
||||||
// Create a DC representing the whole screen
|
// Create a DC representing the whole screen
|
||||||
wxScreenDC::wxScreenDC()
|
wxScreenDC::wxScreenDC()
|
||||||
@@ -37,10 +37,18 @@ wxScreenDC::wxScreenDC()
|
|||||||
::SetBkMode( GetHdc(), TRANSPARENT );
|
::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
|
return true;
|
||||||
// (which we don't have)
|
|
||||||
wxDC::DoGetSize(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxScreenDC::StartDrawingOnTop(wxRect* WXUNUSED(rect))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxScreenDC::EndDrawingOnTop()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@@ -776,16 +776,19 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
|
|||||||
HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0);
|
HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxDC dc;
|
{
|
||||||
dc.SetHDC((WXHDC)hdc);
|
wxDCTemp dc((WXHDC)hdc);
|
||||||
dc.SetFont(GetFont());
|
dc.SetFont(GetFont());
|
||||||
|
|
||||||
pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
|
pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
|
||||||
pStruct->itemWidth = dc.GetCharWidth();
|
pStruct->itemWidth = dc.GetCharWidth();
|
||||||
|
}
|
||||||
|
|
||||||
dc.SetHDC(0);
|
#ifdef __WXWINCE__
|
||||||
|
ReleaseDC(NULL, hdc);
|
||||||
|
#else
|
||||||
DeleteDC(hdc);
|
DeleteDC(hdc);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user