gdiobj.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef _WX_GDIOBJ_H_BASE_
  11. #define _WX_GDIOBJ_H_BASE_
  12. #include "wx/object.h"
  13. // ----------------------------------------------------------------------------
  14. // wxGDIRefData is the base class for wxXXXData structures which contain the
  15. // real data for the GDI object and are shared among all wxWin objects sharing
  16. // the same native GDI object
  17. // ----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_CORE wxGDIRefData : public wxObjectRefData
  19. {
  20. public:
  21. // Default ctor which needs to be defined just because we use
  22. // wxDECLARE_NO_COPY_CLASS() below.
  23. wxGDIRefData() { }
  24. // override this in the derived classes to check if this data object is
  25. // really fully initialized
  26. virtual bool IsOk() const { return true; }
  27. private:
  28. wxDECLARE_NO_COPY_CLASS(wxGDIRefData);
  29. };
  30. // ----------------------------------------------------------------------------
  31. // wxGDIObject: base class for bitmaps, pens, brushes, ...
  32. // ----------------------------------------------------------------------------
  33. class WXDLLIMPEXP_CORE wxGDIObject : public wxObject
  34. {
  35. public:
  36. // checks if the object can be used
  37. virtual bool IsOk() const
  38. {
  39. // the cast here is safe because the derived classes always create
  40. // wxGDIRefData objects
  41. return m_refData && static_cast<wxGDIRefData *>(m_refData)->IsOk();
  42. }
  43. // don't use in the new code, use IsOk() instead
  44. bool IsNull() const { return m_refData == NULL; }
  45. // older version, for backwards compatibility only (but not deprecated
  46. // because it's still widely used)
  47. bool Ok() const { return IsOk(); }
  48. #if defined(__WXMSW__) || defined(__WXPM__)
  49. // Creates the resource
  50. virtual bool RealizeResource() { return false; }
  51. // Frees the resource
  52. virtual bool FreeResource(bool WXUNUSED(force) = false) { return false; }
  53. virtual bool IsFree() const { return false; }
  54. // Returns handle.
  55. virtual WXHANDLE GetResourceHandle() const { return 0; }
  56. #endif // defined(__WXMSW__) || defined(__WXPM__)
  57. protected:
  58. // replace base class functions using wxObjectRefData with our own which
  59. // use wxGDIRefData to ensure that we always work with data objects of the
  60. // correct type (i.e. derived from wxGDIRefData)
  61. virtual wxObjectRefData *CreateRefData() const
  62. {
  63. return CreateGDIRefData();
  64. }
  65. virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const
  66. {
  67. return CloneGDIRefData(static_cast<const wxGDIRefData *>(data));
  68. }
  69. virtual wxGDIRefData *CreateGDIRefData() const = 0;
  70. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const = 0;
  71. DECLARE_DYNAMIC_CLASS(wxGDIObject)
  72. };
  73. #endif // _WX_GDIOBJ_H_BASE_