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