1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGDIObject base header
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GDIOBJ_H_BASE_
12 #define _WX_GDIOBJ_H_BASE_
14 #include "wx/object.h"
16 // ----------------------------------------------------------------------------
17 // wxGDIRefData is the base class for wxXXXData structures which contain the
18 // real data for the GDI object and are shared among all wxWin objects sharing
19 // the same native GDI object
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_CORE wxGDIRefData
: public wxObjectRefData
25 // Default ctor which needs to be defined just because we use
26 // wxDECLARE_NO_COPY_CLASS() below.
29 // override this in the derived classes to check if this data object is
30 // really fully initialized
31 virtual bool IsOk() const { return true; }
34 wxDECLARE_NO_COPY_CLASS(wxGDIRefData
);
37 // ----------------------------------------------------------------------------
38 // wxGDIObject: base class for bitmaps, pens, brushes, ...
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxGDIObject
: public wxObject
44 // checks if the object can be used
45 virtual bool IsOk() const
47 // the cast here is safe because the derived classes always create
48 // wxGDIRefData objects
49 return m_refData
&& static_cast<wxGDIRefData
*>(m_refData
)->IsOk();
52 // don't use in the new code, use IsOk() instead
53 bool IsNull() const { return m_refData
== NULL
; }
55 // older version, for backwards compatibility only (but not deprecated
56 // because it's still widely used)
57 bool Ok() const { return IsOk(); }
59 #if defined(__WXMSW__) || defined(__WXPM__)
60 // Creates the resource
61 virtual bool RealizeResource() { return false; }
64 virtual bool FreeResource(bool WXUNUSED(force
) = false) { return false; }
66 virtual bool IsFree() const { return false; }
69 virtual WXHANDLE
GetResourceHandle() const { return 0; }
70 #endif // defined(__WXMSW__) || defined(__WXPM__)
73 // replace base class functions using wxObjectRefData with our own which
74 // use wxGDIRefData to ensure that we always work with data objects of the
75 // correct type (i.e. derived from wxGDIRefData)
76 virtual wxObjectRefData
*CreateRefData() const
78 return CreateGDIRefData();
81 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const
83 return CloneGDIRefData(static_cast<const wxGDIRefData
*>(data
));
86 virtual wxGDIRefData
*CreateGDIRefData() const = 0;
87 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const = 0;
89 DECLARE_DYNAMIC_CLASS(wxGDIObject
)
92 #endif // _WX_GDIOBJ_H_BASE_