1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
5 // Author: William Osborne - minimal working wxPalmOS port
9 // Copyright: (c) William Osborne
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
13 // NB: this is a private header, it is not intended to be directly included by
14 // user code (but may be included from other, public, wxWin headers
16 #ifndef _WX_PALMOS_GDIIMAGE_H_
17 #define _WX_PALMOS_GDIIMAGE_H_
19 #include "wx/gdiobj.h" // base class
20 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
23 class WXDLLEXPORT wxGDIImageRefData
;
24 class WXDLLEXPORT wxGDIImageHandler
;
25 class WXDLLEXPORT wxGDIImage
;
27 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
29 // ----------------------------------------------------------------------------
30 // wxGDIImageRefData: common data fields for all derived classes
31 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxGDIImageRefData
: public wxGDIRefData
38 m_width
= m_height
= m_depth
= 0;
44 bool IsOk() const { return m_handle
!= 0; }
46 void SetSize(int w
, int h
) { m_width
= w
; m_height
= h
; }
48 // free the ressources we allocated
49 virtual void Free() = 0;
51 // for compatibility, the member fields are public
53 // the size of the image
54 int m_width
, m_height
;
56 // the depth of the image
62 WXHANDLE m_handle
; // for untyped access
69 // ----------------------------------------------------------------------------
70 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
71 // ----------------------------------------------------------------------------
73 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
77 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
78 wxGDIImageHandler(const wxString
& name
,
81 : m_name(name
), m_extension(ext
)
87 void SetName(const wxString
& name
) { m_name
= name
; }
88 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
89 void SetType(long type
) { m_type
= type
; }
91 wxString
GetName() const { return m_name
; }
92 wxString
GetExtension() const { return m_extension
; }
93 long GetType() const { return m_type
; }
95 // real handler operations: to implement in derived classes
96 virtual bool Create(wxGDIImage
*image
,
99 int width
, int height
, int depth
= 1) = 0;
100 virtual bool Load(wxGDIImage
*image
,
101 const wxString
& name
,
103 int desiredWidth
, int desiredHeight
) = 0;
104 virtual bool Save(wxGDIImage
*image
,
105 const wxString
& name
,
110 wxString m_extension
;
114 // ----------------------------------------------------------------------------
115 // wxGDIImage: this class supports GDI image handlers which may be registered
116 // dynamically and will be used for loading/saving the images in the specified
117 // format. It also falls back to wxImage if no appropriate image is found.
118 // ----------------------------------------------------------------------------
120 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
123 // handlers list interface
124 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
126 static void AddHandler(wxGDIImageHandler
*handler
);
127 static void InsertHandler(wxGDIImageHandler
*handler
);
128 static bool RemoveHandler(const wxString
& name
);
130 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
131 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
132 static wxGDIImageHandler
*FindHandler(long type
);
134 static void InitStandardHandlers();
135 static void CleanUpHandlers();
137 // access to the ref data casted to the right type
138 wxGDIImageRefData
*GetGDIImageData() const
139 { return (wxGDIImageRefData
*)m_refData
; }
141 // create data if we don't have it yet
142 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
145 WXHANDLE
GetHandle() const
146 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
147 void SetHandle(WXHANDLE handle
)
148 { EnsureHasData(); GetGDIImageData()->m_handle
= handle
; }
150 bool Ok() const { return GetHandle() != 0; }
152 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
153 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
154 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
156 void SetWidth(int w
) { EnsureHasData(); GetGDIImageData()->m_width
= w
; }
157 void SetHeight(int h
) { EnsureHasData(); GetGDIImageData()->m_height
= h
; }
158 void SetDepth(int d
) { EnsureHasData(); GetGDIImageData()->m_depth
= d
; }
160 void SetSize(int w
, int h
)
163 GetGDIImageData()->SetSize(w
, h
);
165 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
167 // forward some of base class virtuals to wxGDIImageRefData
168 bool FreeResource(bool force
= FALSE
);
169 virtual WXHANDLE
GetResourceHandle() const;
172 // create the data for the derived class here
173 virtual wxGDIImageRefData
*CreateData() const = 0;
175 static wxGDIImageHandlerList ms_handlers
;
178 #endif // _WX_PALMOS_GDIIMAGE_H_