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 // override this in the derived classes to check if this data object is
27 // really fully initialized
28 virtual bool IsOk() const { return true; }
31 // ----------------------------------------------------------------------------
32 // wxGDIObject: base class for bitmaps, pens, brushes, ...
33 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_CORE wxGDIObject
: public wxObject
38 // checks if the object can be used
39 virtual bool IsOk() const
41 // the cast here is safe because the derived classes always create
42 // wxGDIRefData objects
43 return m_refData
&& wx_static_cast(wxGDIRefData
*, m_refData
)->IsOk();
46 // don't use in the new code, use IsOk() instead
47 bool IsNull() const { return m_refData
== NULL
; }
49 // older version, for backwards compatibility only (but not deprecated
50 // because it's still widely used)
51 bool Ok() const { return IsOk(); }
53 #if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXPALMOS__)
54 // Creates the resource
55 virtual bool RealizeResource() { return false; }
58 virtual bool FreeResource(bool WXUNUSED(force
) = false) { return false; }
60 virtual bool IsFree() const { return false; }
63 virtual WXHANDLE
GetResourceHandle() const { return 0; }
64 #endif // defined(__WXMSW__) || defined(__WXPM__)
67 // replace base class functions using wxObjectRefData with our own which
68 // use wxGDIRefData to ensure that we always work with data objects of the
69 // correct type (i.e. derived from wxGDIRefData)
70 virtual wxObjectRefData
*CreateRefData() const
72 return CreateGDIRefData();
75 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const
77 return CloneGDIRefData(wx_static_cast(const wxGDIRefData
*, data
));
80 virtual wxGDIRefData
*CreateGDIRefData() const = 0;
81 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const = 0;
83 DECLARE_DYNAMIC_CLASS(wxGDIObject
)
86 #endif // _WX_GDIOBJ_H_BASE_