1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGDIObject base header
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GDIOBJ_H_BASE_
13 #define _WX_GDIOBJ_H_BASE_
15 #include "wx/object.h"
17 // ----------------------------------------------------------------------------
18 // wxGDIRefData is the base class for wxXXXData structures which contain the
19 // real data for the GDI object and are shared among all wxWin objects sharing
20 // the same native GDI object
21 // ----------------------------------------------------------------------------
23 class WXDLLIMPEXP_CORE wxGDIRefData
: public wxObjectRefData
26 // Default ctor which needs to be defined just because we use
27 // wxDECLARE_NO_COPY_CLASS() below.
30 // override this in the derived classes to check if this data object is
31 // really fully initialized
32 virtual bool IsOk() const { return true; }
35 wxDECLARE_NO_COPY_CLASS(wxGDIRefData
);
38 // ----------------------------------------------------------------------------
39 // wxGDIObject: base class for bitmaps, pens, brushes, ...
40 // ----------------------------------------------------------------------------
42 class WXDLLIMPEXP_CORE wxGDIObject
: public wxObject
45 // checks if the object can be used
46 virtual bool IsOk() const
48 // the cast here is safe because the derived classes always create
49 // wxGDIRefData objects
50 return m_refData
&& static_cast<wxGDIRefData
*>(m_refData
)->IsOk();
53 // don't use in the new code, use IsOk() instead
54 bool IsNull() const { return m_refData
== NULL
; }
56 // older version, for backwards compatibility only (but not deprecated
57 // because it's still widely used)
58 bool Ok() const { return IsOk(); }
60 #if defined(__WXMSW__) || defined(__WXPM__)
61 // Creates the resource
62 virtual bool RealizeResource() { return false; }
65 virtual bool FreeResource(bool WXUNUSED(force
) = false) { return false; }
67 virtual bool IsFree() const { return false; }
70 virtual WXHANDLE
GetResourceHandle() const { return 0; }
71 #endif // defined(__WXMSW__) || defined(__WXPM__)
74 // replace base class functions using wxObjectRefData with our own which
75 // use wxGDIRefData to ensure that we always work with data objects of the
76 // correct type (i.e. derived from wxGDIRefData)
77 virtual wxObjectRefData
*CreateRefData() const
79 return CreateGDIRefData();
82 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const
84 return CloneGDIRefData(static_cast<const wxGDIRefData
*>(data
));
87 virtual wxGDIRefData
*CreateGDIRefData() const = 0;
88 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const = 0;
90 DECLARE_DYNAMIC_CLASS(wxGDIObject
)
93 #endif // _WX_GDIOBJ_H_BASE_