]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | /////////////////////////////////////////////////////////////////////////////// |
e1d63b79 | 2 | // Name: wx/palmos/gdiimage.h |
ffecfa5a JS |
3 | // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor |
4 | // under Palm OS | |
e1d63b79 | 5 | // Author: William Osborne - minimal working wxPalmOS port |
ffecfa5a JS |
6 | // Modified by: |
7 | // Created: 10/13/04 | |
e1d63b79 | 8 | // RCS-ID: $Id$ |
ffecfa5a JS |
9 | // Copyright: (c) William Osborne |
10 | // Licence: wxWindows licence | |
11 | /////////////////////////////////////////////////////////////////////////////// | |
12 | ||
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 | |
15 | ||
16 | #ifndef _WX_PALMOS_GDIIMAGE_H_ | |
17 | #define _WX_PALMOS_GDIIMAGE_H_ | |
18 | ||
ffecfa5a JS |
19 | #include "wx/gdiobj.h" // base class |
20 | #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID | |
21 | #include "wx/list.h" | |
22 | ||
23 | class WXDLLEXPORT wxGDIImageRefData; | |
24 | class WXDLLEXPORT wxGDIImageHandler; | |
25 | class WXDLLEXPORT wxGDIImage; | |
26 | ||
27 | WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList); | |
28 | ||
29 | // ---------------------------------------------------------------------------- | |
30 | // wxGDIImageRefData: common data fields for all derived classes | |
31 | // ---------------------------------------------------------------------------- | |
32 | ||
33 | class WXDLLEXPORT wxGDIImageRefData : public wxGDIRefData | |
34 | { | |
35 | public: | |
36 | wxGDIImageRefData() | |
37 | { | |
38 | m_width = m_height = m_depth = 0; | |
39 | ||
40 | m_handle = 0; | |
41 | } | |
42 | ||
43 | // accessors | |
44 | bool IsOk() const { return m_handle != 0; } | |
45 | ||
46 | void SetSize(int w, int h) { m_width = w; m_height = h; } | |
47 | ||
48 | // free the ressources we allocated | |
49 | virtual void Free() = 0; | |
50 | ||
51 | // for compatibility, the member fields are public | |
52 | ||
53 | // the size of the image | |
54 | int m_width, m_height; | |
55 | ||
56 | // the depth of the image | |
57 | int m_depth; | |
58 | ||
59 | // the handle to it | |
60 | union | |
61 | { | |
62 | WXHANDLE m_handle; // for untyped access | |
63 | WXHBITMAP m_hBitmap; | |
64 | WXHICON m_hIcon; | |
65 | WXHCURSOR m_hCursor; | |
66 | }; | |
67 | }; | |
68 | ||
69 | // ---------------------------------------------------------------------------- | |
70 | // wxGDIImageHandler: a class which knows how to load/save wxGDIImages. | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
73 | class WXDLLEXPORT wxGDIImageHandler : public wxObject | |
74 | { | |
75 | public: | |
76 | // ctor | |
77 | wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; } | |
78 | wxGDIImageHandler(const wxString& name, | |
79 | const wxString& ext, | |
80 | long type) | |
81 | : m_name(name), m_extension(ext) | |
82 | { | |
83 | m_type = type; | |
84 | } | |
85 | ||
86 | // accessors | |
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; } | |
90 | ||
91 | wxString GetName() const { return m_name; } | |
92 | wxString GetExtension() const { return m_extension; } | |
93 | long GetType() const { return m_type; } | |
94 | ||
95 | // real handler operations: to implement in derived classes | |
96 | virtual bool Create(wxGDIImage *image, | |
97 | void *data, | |
98 | long flags, | |
99 | int width, int height, int depth = 1) = 0; | |
100 | virtual bool Load(wxGDIImage *image, | |
101 | const wxString& name, | |
102 | long flags, | |
103 | int desiredWidth, int desiredHeight) = 0; | |
104 | virtual bool Save(wxGDIImage *image, | |
105 | const wxString& name, | |
106 | int type) = 0; | |
107 | ||
108 | protected: | |
109 | wxString m_name; | |
110 | wxString m_extension; | |
111 | long m_type; | |
112 | }; | |
113 | ||
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 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | class WXDLLEXPORT wxGDIImage : public wxGDIObject | |
121 | { | |
122 | public: | |
123 | // handlers list interface | |
124 | static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; } | |
125 | ||
126 | static void AddHandler(wxGDIImageHandler *handler); | |
127 | static void InsertHandler(wxGDIImageHandler *handler); | |
128 | static bool RemoveHandler(const wxString& name); | |
129 | ||
130 | static wxGDIImageHandler *FindHandler(const wxString& name); | |
131 | static wxGDIImageHandler *FindHandler(const wxString& extension, long type); | |
132 | static wxGDIImageHandler *FindHandler(long type); | |
133 | ||
134 | static void InitStandardHandlers(); | |
135 | static void CleanUpHandlers(); | |
136 | ||
137 | // access to the ref data casted to the right type | |
138 | wxGDIImageRefData *GetGDIImageData() const | |
139 | { return (wxGDIImageRefData *)m_refData; } | |
140 | ||
141 | // create data if we don't have it yet | |
142 | void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); } | |
143 | ||
144 | // accessors | |
145 | WXHANDLE GetHandle() const | |
146 | { return IsNull() ? 0 : GetGDIImageData()->m_handle; } | |
147 | void SetHandle(WXHANDLE handle) | |
148 | { EnsureHasData(); GetGDIImageData()->m_handle = handle; } | |
149 | ||
150 | bool Ok() const { return GetHandle() != 0; } | |
151 | ||
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; } | |
155 | ||
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; } | |
159 | ||
160 | void SetSize(int w, int h) | |
161 | { | |
162 | EnsureHasData(); | |
163 | GetGDIImageData()->SetSize(w, h); | |
164 | } | |
165 | void SetSize(const wxSize& size) { SetSize(size.x, size.y); } | |
166 | ||
167 | // forward some of base class virtuals to wxGDIImageRefData | |
168 | bool FreeResource(bool force = FALSE); | |
169 | virtual WXHANDLE GetResourceHandle() const; | |
170 | ||
171 | protected: | |
172 | // create the data for the derived class here | |
173 | virtual wxGDIImageRefData *CreateData() const = 0; | |
174 | ||
175 | static wxGDIImageHandlerList ms_handlers; | |
176 | }; | |
177 | ||
178 | #endif // _WX_PALMOS_GDIIMAGE_H_ |