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:
parent
f23d32554f
commit
7d09b97f53
@ -9,8 +9,8 @@
|
||||
// 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"
|
||||
|
||||
@ -40,10 +40,12 @@ public:
|
||||
};
|
||||
#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
|
||||
@ -138,6 +140,26 @@ public:
|
||||
#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);
|
||||
|
||||
@ -186,7 +208,6 @@ protected:
|
||||
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[],
|
||||
@ -216,6 +237,17 @@ protected:
|
||||
// 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
|
||||
// -----------------------------
|
||||
|
||||
@ -259,12 +291,29 @@ protected:
|
||||
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_
|
||||
|
||||
|
@ -9,8 +9,8 @@
|
||||
// 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
|
||||
|
||||
@ -41,6 +41,11 @@ protected:
|
||||
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();
|
||||
@ -59,6 +64,5 @@ WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& data);
|
||||
|
||||
#endif // wxUSE_PRINTING_ARCHITECTURE
|
||||
|
||||
#endif
|
||||
// _WX_DCPRINT_H_
|
||||
#endif // _WX_MSW_DCPRINT_H_
|
||||
|
||||
|
@ -9,29 +9,33 @@
|
||||
// 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_
|
||||
|
||||
|
@ -304,8 +304,7 @@ bool wxBitmapButton::MSWOnDraw(WXDRAWITEMSTRUCT *item)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -258,23 +258,6 @@ wxColourChanger::~wxColourChanger()
|
||||
// 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 )
|
||||
@ -2285,12 +2268,14 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
|
||||
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
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include "wx/dcscreen.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC)
|
||||
|
||||
// Create a DC representing the whole screen
|
||||
wxScreenDC::wxScreenDC()
|
||||
@ -37,10 +37,18 @@ 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;
|
||||
}
|
||||
|
@ -776,16 +776,19 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
|
||||
HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0);
|
||||
#endif
|
||||
|
||||
wxDC dc;
|
||||
dc.SetHDC((WXHDC)hdc);
|
||||
dc.SetFont(GetFont());
|
||||
{
|
||||
wxDCTemp dc((WXHDC)hdc);
|
||||
dc.SetFont(GetFont());
|
||||
|
||||
pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
|
||||
pStruct->itemWidth = dc.GetCharWidth();
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user