Use RIAA wrapper for wxSpinCtrl event disabling in wxGTK.
[wxWidgets.git] / include / wx / gdiobj.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gdiobj.h
3 // Purpose: wxGDIObject base header
4 // Author: Julian Smart
5 // Modified by:
6 // Created:
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GDIOBJ_H_BASE_
12 #define _WX_GDIOBJ_H_BASE_
13
14 #include "wx/object.h"
15
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 // ----------------------------------------------------------------------------
21
22 class WXDLLIMPEXP_CORE wxGDIRefData : public wxObjectRefData
23 {
24 public:
25 // Default ctor which needs to be defined just because we use
26 // wxDECLARE_NO_COPY_CLASS() below.
27 wxGDIRefData() { }
28
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; }
32
33 private:
34 wxDECLARE_NO_COPY_CLASS(wxGDIRefData);
35 };
36
37 // ----------------------------------------------------------------------------
38 // wxGDIObject: base class for bitmaps, pens, brushes, ...
39 // ----------------------------------------------------------------------------
40
41 class WXDLLIMPEXP_CORE wxGDIObject : public wxObject
42 {
43 public:
44 // checks if the object can be used
45 virtual bool IsOk() const
46 {
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();
50 }
51
52 // don't use in the new code, use IsOk() instead
53 bool IsNull() const { return m_refData == NULL; }
54
55 // older version, for backwards compatibility only (but not deprecated
56 // because it's still widely used)
57 bool Ok() const { return IsOk(); }
58
59 #if defined(__WXMSW__) || defined(__WXPM__)
60 // Creates the resource
61 virtual bool RealizeResource() { return false; }
62
63 // Frees the resource
64 virtual bool FreeResource(bool WXUNUSED(force) = false) { return false; }
65
66 virtual bool IsFree() const { return false; }
67
68 // Returns handle.
69 virtual WXHANDLE GetResourceHandle() const { return 0; }
70 #endif // defined(__WXMSW__) || defined(__WXPM__)
71
72 protected:
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
77 {
78 return CreateGDIRefData();
79 }
80
81 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const
82 {
83 return CloneGDIRefData(static_cast<const wxGDIRefData *>(data));
84 }
85
86 virtual wxGDIRefData *CreateGDIRefData() const = 0;
87 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const = 0;
88
89 DECLARE_DYNAMIC_CLASS(wxGDIObject)
90 };
91
92 #endif // _WX_GDIOBJ_H_BASE_