]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/gdiimage.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / msw / gdiimage.h
CommitLineData
0d0512bd 1///////////////////////////////////////////////////////////////////////////////
233f5738 2// Name: wx/msw/gdiimage.h
0d0512bd
VZ
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
0d0512bd 8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
0d0512bd
VZ
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
0d0512bd 18#include "wx/gdiobj.h" // base class
10a0bdb1
VZ
19#include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
20#include "wx/list.h"
0d0512bd 21
b5dbe15d
VS
22class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
23class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
24class WXDLLIMPEXP_FWD_CORE wxGDIImage;
0d0512bd 25
cca78463 26WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
d162a7ee 27
0d0512bd
VZ
28// ----------------------------------------------------------------------------
29// wxGDIImageRefData: common data fields for all derived classes
30// ----------------------------------------------------------------------------
31
53a2db12 32class WXDLLIMPEXP_CORE wxGDIImageRefData : public wxGDIRefData
0d0512bd
VZ
33{
34public:
35 wxGDIImageRefData()
36 {
37 m_width = m_height = m_depth = 0;
38
39 m_handle = 0;
0d0512bd
VZ
40 }
41
fd08ccd2 42 wxGDIImageRefData(const wxGDIImageRefData& data) : wxGDIRefData()
7ff64980
VZ
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
0d0512bd 52 // accessors
8f884a0d 53 virtual bool IsOk() const { return m_handle != 0; }
0d0512bd
VZ
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 };
0d0512bd
VZ
76};
77
0d0512bd
VZ
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
53a2db12 84class WXDLLIMPEXP_CORE wxGDIImage : public wxGDIObject
0d0512bd
VZ
85{
86public:
87 // handlers list interface
d162a7ee 88 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
0d0512bd
VZ
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
0d0512bd
VZ
105 // accessors
106 WXHANDLE GetHandle() const
107 { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
108 void SetHandle(WXHANDLE handle)
7ff64980 109 { AllocExclusive(); GetGDIImageData()->m_handle = handle; }
0d0512bd 110
0d0512bd
VZ
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
339cfab6
FM
115 wxSize GetSize() const
116 {
117 return IsNull() ? wxSize(0,0) :
118 wxSize(GetGDIImageData()->m_width, GetGDIImageData()->m_height);
119 }
120
7ff64980
VZ
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; }
0d0512bd
VZ
124
125 void SetSize(int w, int h)
126 {
7ff64980 127 AllocExclusive();
0d0512bd
VZ
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
213ceb3f 133 bool FreeResource(bool force = false);
2b5f62a0 134 virtual WXHANDLE GetResourceHandle() const;
0d0512bd
VZ
135
136protected:
137 // create the data for the derived class here
138 virtual wxGDIImageRefData *CreateData() const = 0;
139
8f884a0d
VZ
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 {
9a83f860 147 wxFAIL_MSG( wxT("must be implemented if used") );
8f884a0d
VZ
148
149 return NULL;
150 }
7ff64980 151
d162a7ee 152 static wxGDIImageHandlerList ms_handlers;
0d0512bd
VZ
153};
154
e86f2cc8
FM
155// ----------------------------------------------------------------------------
156// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
157// ----------------------------------------------------------------------------
158
53a2db12 159class WXDLLIMPEXP_CORE wxGDIImageHandler : public wxObject
e86f2cc8
FM
160{
161public:
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
191protected:
192 wxString m_name;
193 wxString m_extension;
194 wxBitmapType m_type;
195};
196
0d0512bd 197#endif // _WX_MSW_GDIIMAGE_H_