]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/gdiimage.h
MinGW compilation fixes.
[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>
371a5b4e 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
19#ifdef __GNUG__
20 #pragma interface "gdiimage.h"
21#endif
22
23#include "wx/gdiobj.h" // base class
10a0bdb1
VZ
24#include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
25#include "wx/list.h"
0d0512bd
VZ
26
27class WXDLLEXPORT wxGDIImageRefData;
28class WXDLLEXPORT wxGDIImageHandler;
29class WXDLLEXPORT wxGDIImage;
30
cca78463 31WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
d162a7ee 32
0d0512bd
VZ
33// ----------------------------------------------------------------------------
34// wxGDIImageRefData: common data fields for all derived classes
35// ----------------------------------------------------------------------------
36
37class WXDLLEXPORT wxGDIImageRefData : public wxGDIRefData
38{
39public:
40 wxGDIImageRefData()
41 {
42 m_width = m_height = m_depth = 0;
43
44 m_handle = 0;
45
46#if WXWIN_COMPATIBILITY_2
47 m_ok = FALSE;
48#endif // WXWIN_COMPATIBILITY_2
49 }
50
51 // accessors
52 bool IsOk() const { return m_handle != 0; }
53
54 void SetSize(int w, int h) { m_width = w; m_height = h; }
55
56 // free the ressources we allocated
57 virtual void Free() = 0;
58
59 // for compatibility, the member fields are public
60
61 // the size of the image
62 int m_width, m_height;
63
64 // the depth of the image
65 int m_depth;
66
67 // the handle to it
68 union
69 {
70 WXHANDLE m_handle; // for untyped access
71 WXHBITMAP m_hBitmap;
72 WXHICON m_hIcon;
73 WXHCURSOR m_hCursor;
74 };
75
76 // this filed is redundant and using it is error prone but keep it for
77 // backwards compatibility
78#if WXWIN_COMPATIBILITY_2
79 void SetOk() { m_ok = m_handle != 0; }
80
81 bool m_ok;
82#endif // WXWIN_COMPATIBILITY_2
83};
84
85// ----------------------------------------------------------------------------
86// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
87// ----------------------------------------------------------------------------
88
89class WXDLLEXPORT wxGDIImageHandler : public wxObject
90{
91public:
92 // ctor
93 wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; }
94 wxGDIImageHandler(const wxString& name,
95 const wxString& ext,
96 long type)
97 : m_name(name), m_extension(ext)
98 {
99 m_type = type;
100 }
101
102 // accessors
103 void SetName(const wxString& name) { m_name = name; }
104 void SetExtension(const wxString& ext) { m_extension = ext; }
105 void SetType(long type) { m_type = type; }
106
107 wxString GetName() const { return m_name; }
108 wxString GetExtension() const { return m_extension; }
109 long GetType() const { return m_type; }
110
111 // real handler operations: to implement in derived classes
112 virtual bool Create(wxGDIImage *image,
113 void *data,
114 long flags,
115 int width, int height, int depth = 1) = 0;
116 virtual bool Load(wxGDIImage *image,
117 const wxString& name,
118 long flags,
119 int desiredWidth, int desiredHeight) = 0;
120 virtual bool Save(wxGDIImage *image,
121 const wxString& name,
122 int type) = 0;
123
124protected:
125 wxString m_name;
126 wxString m_extension;
127 long m_type;
128};
129
130// ----------------------------------------------------------------------------
131// wxGDIImage: this class supports GDI image handlers which may be registered
132// dynamically and will be used for loading/saving the images in the specified
133// format. It also falls back to wxImage if no appropriate image is found.
134// ----------------------------------------------------------------------------
135
136class WXDLLEXPORT wxGDIImage : public wxGDIObject
137{
138public:
139 // handlers list interface
d162a7ee 140 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
0d0512bd
VZ
141
142 static void AddHandler(wxGDIImageHandler *handler);
143 static void InsertHandler(wxGDIImageHandler *handler);
144 static bool RemoveHandler(const wxString& name);
145
146 static wxGDIImageHandler *FindHandler(const wxString& name);
147 static wxGDIImageHandler *FindHandler(const wxString& extension, long type);
148 static wxGDIImageHandler *FindHandler(long type);
149
150 static void InitStandardHandlers();
151 static void CleanUpHandlers();
152
153 // access to the ref data casted to the right type
154 wxGDIImageRefData *GetGDIImageData() const
155 { return (wxGDIImageRefData *)m_refData; }
156
157 // create data if we don't have it yet
158 void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); }
159
160 // accessors
161 WXHANDLE GetHandle() const
162 { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
163 void SetHandle(WXHANDLE handle)
164 { EnsureHasData(); GetGDIImageData()->m_handle = handle; }
165
166 bool Ok() const { return GetHandle() != 0; }
167
168 int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; }
169 int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
170 int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
171
172 void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; }
173 void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; }
174 void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; }
175
176 void SetSize(int w, int h)
177 {
178 EnsureHasData();
179 GetGDIImageData()->SetSize(w, h);
180 }
181 void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
182
183 // forward some of base class virtuals to wxGDIImageRefData
184 bool FreeResource(bool force = FALSE);
2b5f62a0 185 virtual WXHANDLE GetResourceHandle() const;
0d0512bd
VZ
186
187protected:
188 // create the data for the derived class here
189 virtual wxGDIImageRefData *CreateData() const = 0;
190
d162a7ee 191 static wxGDIImageHandlerList ms_handlers;
0d0512bd
VZ
192};
193
194#endif // _WX_MSW_GDIIMAGE_H_