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