]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/gdiimage.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / msw / gdiimage.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/gdiimage.h
3 // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
4 // under MSW
5 // Author: Vadim Zeitlin
6 // Modified by:
7 // Created: 20.11.99
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // NB: this is a private header, it is not intended to be directly included by
13 // user code (but may be included from other, public, wxWin headers
14
15 #ifndef _WX_MSW_GDIIMAGE_H_
16 #define _WX_MSW_GDIIMAGE_H_
17
18 #include "wx/gdiobj.h" // base class
19 #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
20 #include "wx/list.h"
21
22 class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
23 class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
24 class WXDLLIMPEXP_FWD_CORE wxGDIImage;
25
26 WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
27
28 // ----------------------------------------------------------------------------
29 // wxGDIImageRefData: common data fields for all derived classes
30 // ----------------------------------------------------------------------------
31
32 class WXDLLIMPEXP_CORE wxGDIImageRefData : public wxGDIRefData
33 {
34 public:
35 wxGDIImageRefData()
36 {
37 m_width = m_height = m_depth = 0;
38
39 m_handle = 0;
40 }
41
42 wxGDIImageRefData(const wxGDIImageRefData& data) : wxGDIRefData()
43 {
44 m_width = data.m_width;
45 m_height = data.m_height;
46 m_depth = data.m_depth;
47
48 // can't copy handles like this, derived class copy ctor must do it!
49 m_handle = NULL;
50 }
51
52 // accessors
53 virtual bool IsOk() const { return m_handle != 0; }
54
55 void SetSize(int w, int h) { m_width = w; m_height = h; }
56
57 // free the ressources we allocated
58 virtual void Free() = 0;
59
60 // for compatibility, the member fields are public
61
62 // the size of the image
63 int m_width, m_height;
64
65 // the depth of the image
66 int m_depth;
67
68 // the handle to it
69 union
70 {
71 WXHANDLE m_handle; // for untyped access
72 WXHBITMAP m_hBitmap;
73 WXHICON m_hIcon;
74 WXHCURSOR m_hCursor;
75 };
76 };
77
78 // ----------------------------------------------------------------------------
79 // wxGDIImage: this class supports GDI image handlers which may be registered
80 // dynamically and will be used for loading/saving the images in the specified
81 // format. It also falls back to wxImage if no appropriate image is found.
82 // ----------------------------------------------------------------------------
83
84 class WXDLLIMPEXP_CORE wxGDIImage : public wxGDIObject
85 {
86 public:
87 // handlers list interface
88 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
89
90 static void AddHandler(wxGDIImageHandler *handler);
91 static void InsertHandler(wxGDIImageHandler *handler);
92 static bool RemoveHandler(const wxString& name);
93
94 static wxGDIImageHandler *FindHandler(const wxString& name);
95 static wxGDIImageHandler *FindHandler(const wxString& extension, long type);
96 static wxGDIImageHandler *FindHandler(long type);
97
98 static void InitStandardHandlers();
99 static void CleanUpHandlers();
100
101 // access to the ref data casted to the right type
102 wxGDIImageRefData *GetGDIImageData() const
103 { return (wxGDIImageRefData *)m_refData; }
104
105 // accessors
106 WXHANDLE GetHandle() const
107 { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
108 void SetHandle(WXHANDLE handle)
109 { AllocExclusive(); GetGDIImageData()->m_handle = handle; }
110
111 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
112 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
113 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
114
115 wxSize GetSize() const
116 {
117 return IsNull() ? wxSize(0,0) :
118 wxSize(GetGDIImageData()->m_width, GetGDIImageData()->m_height);
119 }
120
121 void SetWidth(int w) { AllocExclusive(); GetGDIImageData()->m_width = w; }
122 void SetHeight(int h) { AllocExclusive(); GetGDIImageData()->m_height = h; }
123 void SetDepth(int d) { AllocExclusive(); GetGDIImageData()->m_depth = d; }
124
125 void SetSize(int w, int h)
126 {
127 AllocExclusive();
128 GetGDIImageData()->SetSize(w, h);
129 }
130 void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
131
132 // forward some of base class virtuals to wxGDIImageRefData
133 bool FreeResource(bool force = false);
134 virtual WXHANDLE GetResourceHandle() const;
135
136 protected:
137 // create the data for the derived class here
138 virtual wxGDIImageRefData *CreateData() const = 0;
139
140 // implement the wxGDIObject method in terms of our, more specific, one
141 virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
142
143 // we can't [efficiently] clone objects of this class
144 virtual wxGDIRefData *
145 CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
146 {
147 wxFAIL_MSG( wxT("must be implemented if used") );
148
149 return NULL;
150 }
151
152 static wxGDIImageHandlerList ms_handlers;
153 };
154
155 // ----------------------------------------------------------------------------
156 // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
157 // ----------------------------------------------------------------------------
158
159 class WXDLLIMPEXP_CORE wxGDIImageHandler : public wxObject
160 {
161 public:
162 // ctor
163 wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
164 wxGDIImageHandler(const wxString& name,
165 const wxString& ext,
166 wxBitmapType type)
167 : m_name(name), m_extension(ext), m_type(type) { }
168
169 // accessors
170 void SetName(const wxString& name) { m_name = name; }
171 void SetExtension(const wxString& ext) { m_extension = ext; }
172 void SetType(wxBitmapType type) { m_type = type; }
173
174 const wxString& GetName() const { return m_name; }
175 const wxString& GetExtension() const { return m_extension; }
176 wxBitmapType GetType() const { return m_type; }
177
178 // real handler operations: to implement in derived classes
179 virtual bool Create(wxGDIImage *image,
180 const void* data,
181 wxBitmapType flags,
182 int width, int height, int depth = 1) = 0;
183 virtual bool Load(wxGDIImage *image,
184 const wxString& name,
185 wxBitmapType flags,
186 int desiredWidth, int desiredHeight) = 0;
187 virtual bool Save(const wxGDIImage *image,
188 const wxString& name,
189 wxBitmapType type) const = 0;
190
191 protected:
192 wxString m_name;
193 wxString m_extension;
194 wxBitmapType m_type;
195 };
196
197 #endif // _WX_MSW_GDIIMAGE_H_