]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/gdiimage.h
Added event handler macro
[wxWidgets.git] / include / wx / msw / gdiimage.h
CommitLineData
0d0512bd
VZ
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>
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
33class WXDLLEXPORT wxGDIImageRefData : public wxGDIRefData
34{
35public:
36 wxGDIImageRefData()
37 {
38 m_width = m_height = m_depth = 0;
39
40 m_handle = 0;
0d0512bd
VZ
41 }
42
4dddb8a2 43 wxGDIImageRefData(const wxGDIImageRefData& data) : wxGDIRefData(data)
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
79// ----------------------------------------------------------------------------
80// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
81// ----------------------------------------------------------------------------
82
83class WXDLLEXPORT wxGDIImageHandler : public wxObject
84{
85public:
86 // ctor
87 wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
88 wxGDIImageHandler(const wxString& name,
89 const wxString& ext,
90 long type)
91 : m_name(name), m_extension(ext)
92 {
93 m_type = type;
94 }
95
96 // accessors
97 void SetName(const wxString& name) { m_name = name; }
98 void SetExtension(const wxString& ext) { m_extension = ext; }
99 void SetType(long type) { m_type = type; }
100
6a168c17
VZ
101 const wxString& GetName() const { return m_name; }
102 const wxString& GetExtension() const { return m_extension; }
0d0512bd
VZ
103 long GetType() const { return m_type; }
104
105 // real handler operations: to implement in derived classes
106 virtual bool Create(wxGDIImage *image,
452418c4 107 const void* data,
0d0512bd
VZ
108 long flags,
109 int width, int height, int depth = 1) = 0;
110 virtual bool Load(wxGDIImage *image,
111 const wxString& name,
112 long flags,
113 int desiredWidth, int desiredHeight) = 0;
114 virtual bool Save(wxGDIImage *image,
115 const wxString& name,
116 int type) = 0;
117
118protected:
119 wxString m_name;
120 wxString m_extension;
121 long m_type;
122};
123
124// ----------------------------------------------------------------------------
125// wxGDIImage: this class supports GDI image handlers which may be registered
126// dynamically and will be used for loading/saving the images in the specified
127// format. It also falls back to wxImage if no appropriate image is found.
128// ----------------------------------------------------------------------------
129
130class WXDLLEXPORT wxGDIImage : public wxGDIObject
131{
132public:
133 // handlers list interface
d162a7ee 134 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
0d0512bd
VZ
135
136 static void AddHandler(wxGDIImageHandler *handler);
137 static void InsertHandler(wxGDIImageHandler *handler);
138 static bool RemoveHandler(const wxString& name);
139
140 static wxGDIImageHandler *FindHandler(const wxString& name);
141 static wxGDIImageHandler *FindHandler(const wxString& extension, long type);
142 static wxGDIImageHandler *FindHandler(long type);
143
144 static void InitStandardHandlers();
145 static void CleanUpHandlers();
146
147 // access to the ref data casted to the right type
148 wxGDIImageRefData *GetGDIImageData() const
149 { return (wxGDIImageRefData *)m_refData; }
150
0d0512bd
VZ
151 // accessors
152 WXHANDLE GetHandle() const
153 { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
154 void SetHandle(WXHANDLE handle)
7ff64980 155 { AllocExclusive(); GetGDIImageData()->m_handle = handle; }
0d0512bd 156
0d0512bd
VZ
157 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
158 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
159 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
160
7ff64980
VZ
161 void SetWidth(int w) { AllocExclusive(); GetGDIImageData()->m_width = w; }
162 void SetHeight(int h) { AllocExclusive(); GetGDIImageData()->m_height = h; }
163 void SetDepth(int d) { AllocExclusive(); GetGDIImageData()->m_depth = d; }
0d0512bd
VZ
164
165 void SetSize(int w, int h)
166 {
7ff64980 167 AllocExclusive();
0d0512bd
VZ
168 GetGDIImageData()->SetSize(w, h);
169 }
170 void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
171
172 // forward some of base class virtuals to wxGDIImageRefData
213ceb3f 173 bool FreeResource(bool force = false);
2b5f62a0 174 virtual WXHANDLE GetResourceHandle() const;
0d0512bd
VZ
175
176protected:
177 // create the data for the derived class here
178 virtual wxGDIImageRefData *CreateData() const = 0;
179
8f884a0d
VZ
180 // implement the wxGDIObject method in terms of our, more specific, one
181 virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
182
183 // we can't [efficiently] clone objects of this class
184 virtual wxGDIRefData *
185 CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
186 {
187 wxFAIL_MSG( _T("must be implemented if used") );
188
189 return NULL;
190 }
7ff64980 191
d162a7ee 192 static wxGDIImageHandlerList ms_handlers;
0d0512bd
VZ
193};
194
195#endif // _WX_MSW_GDIIMAGE_H_