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