1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/palmos/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
5 // Author: William Osborne
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "gdiimage.h"
23 #include "wx/gdiobj.h" // base class
24 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
27 class WXDLLEXPORT wxGDIImageRefData
;
28 class WXDLLEXPORT wxGDIImageHandler
;
29 class WXDLLEXPORT wxGDIImage
;
31 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler
, wxGDIImageHandlerList
);
33 // ----------------------------------------------------------------------------
34 // wxGDIImageRefData: common data fields for all derived classes
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxGDIImageRefData
: public wxGDIRefData
42 m_width
= m_height
= m_depth
= 0;
48 bool IsOk() const { return m_handle
!= 0; }
50 void SetSize(int w
, int h
) { m_width
= w
; m_height
= h
; }
52 // free the ressources we allocated
53 virtual void Free() = 0;
55 // for compatibility, the member fields are public
57 // the size of the image
58 int m_width
, m_height
;
60 // the depth of the image
66 WXHANDLE m_handle
; // for untyped access
73 // ----------------------------------------------------------------------------
74 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
75 // ----------------------------------------------------------------------------
77 class WXDLLEXPORT wxGDIImageHandler
: public wxObject
81 wxGDIImageHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
82 wxGDIImageHandler(const wxString
& name
,
85 : m_name(name
), m_extension(ext
)
91 void SetName(const wxString
& name
) { m_name
= name
; }
92 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
93 void SetType(long type
) { m_type
= type
; }
95 wxString
GetName() const { return m_name
; }
96 wxString
GetExtension() const { return m_extension
; }
97 long GetType() const { return m_type
; }
99 // real handler operations: to implement in derived classes
100 virtual bool Create(wxGDIImage
*image
,
103 int width
, int height
, int depth
= 1) = 0;
104 virtual bool Load(wxGDIImage
*image
,
105 const wxString
& name
,
107 int desiredWidth
, int desiredHeight
) = 0;
108 virtual bool Save(wxGDIImage
*image
,
109 const wxString
& name
,
114 wxString m_extension
;
118 // ----------------------------------------------------------------------------
119 // wxGDIImage: this class supports GDI image handlers which may be registered
120 // dynamically and will be used for loading/saving the images in the specified
121 // format. It also falls back to wxImage if no appropriate image is found.
122 // ----------------------------------------------------------------------------
124 class WXDLLEXPORT wxGDIImage
: public wxGDIObject
127 // handlers list interface
128 static wxGDIImageHandlerList
& GetHandlers() { return ms_handlers
; }
130 static void AddHandler(wxGDIImageHandler
*handler
);
131 static void InsertHandler(wxGDIImageHandler
*handler
);
132 static bool RemoveHandler(const wxString
& name
);
134 static wxGDIImageHandler
*FindHandler(const wxString
& name
);
135 static wxGDIImageHandler
*FindHandler(const wxString
& extension
, long type
);
136 static wxGDIImageHandler
*FindHandler(long type
);
138 static void InitStandardHandlers();
139 static void CleanUpHandlers();
141 // access to the ref data casted to the right type
142 wxGDIImageRefData
*GetGDIImageData() const
143 { return (wxGDIImageRefData
*)m_refData
; }
145 // create data if we don't have it yet
146 void EnsureHasData() { if ( IsNull() ) m_refData
= CreateData(); }
149 WXHANDLE
GetHandle() const
150 { return IsNull() ? 0 : GetGDIImageData()->m_handle
; }
151 void SetHandle(WXHANDLE handle
)
152 { EnsureHasData(); GetGDIImageData()->m_handle
= handle
; }
154 bool Ok() const { return GetHandle() != 0; }
156 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width
; }
157 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height
; }
158 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth
; }
160 void SetWidth(int w
) { EnsureHasData(); GetGDIImageData()->m_width
= w
; }
161 void SetHeight(int h
) { EnsureHasData(); GetGDIImageData()->m_height
= h
; }
162 void SetDepth(int d
) { EnsureHasData(); GetGDIImageData()->m_depth
= d
; }
164 void SetSize(int w
, int h
)
167 GetGDIImageData()->SetSize(w
, h
);
169 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
171 // forward some of base class virtuals to wxGDIImageRefData
172 bool FreeResource(bool force
= FALSE
);
173 virtual WXHANDLE
GetResourceHandle() const;
176 // create the data for the derived class here
177 virtual wxGDIImageRefData
*CreateData() const = 0;
179 static wxGDIImageHandlerList ms_handlers
;
182 #endif // _WX_PALMOS_GDIIMAGE_H_