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