-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbmpbase.cpp
More file actions
211 lines (170 loc) · 5.56 KB
/
bmpbase.cpp
File metadata and controls
211 lines (170 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/////////////////////////////////////////////////////////////////////////////
// Name: src/common/bmpbase.cpp
// Purpose: wxBitmapBase
// Author: VaclavSlavik
// Created: 2001/04/11
// RCS-ID: $Id: bmpbase.cpp 42752 2006-10-30 19:26:48Z VZ $
// Copyright: (c) 2001, Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/bitmap.h"
#ifndef WX_PRECOMP
#include "wx/colour.h"
#include "wx/icon.h"
#include "wx/image.h"
#endif // WX_PRECOMP
// ----------------------------------------------------------------------------
// wxVariant support
// ----------------------------------------------------------------------------
#if wxUSE_VARIANT
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
#endif
// ----------------------------------------------------------------------------
// wxBitmapBase
// ----------------------------------------------------------------------------
#if wxUSE_BITMAP_BASE
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/utils.h"
#include "wx/palette.h"
#include "wx/module.h"
#endif // WX_PRECOMP
IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
wxList wxBitmapBase::sm_handlers;
void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
{
sm_handlers.Append(handler);
}
void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
{
sm_handlers.Insert(handler);
}
bool wxBitmapBase::RemoveHandler(const wxString& name)
{
wxBitmapHandler *handler = FindHandler(name);
if ( handler )
{
sm_handlers.DeleteObject(handler);
return true;
}
else
return false;
}
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
{
wxList::compatibility_iterator node = sm_handlers.GetFirst();
while ( node )
{
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
if ( handler->GetName() == name )
return handler;
node = node->GetNext();
}
return NULL;
}
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
{
wxList::compatibility_iterator node = sm_handlers.GetFirst();
while ( node )
{
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
if ( handler->GetExtension() == extension &&
(bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
return handler;
node = node->GetNext();
}
return NULL;
}
wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
{
wxList::compatibility_iterator node = sm_handlers.GetFirst();
while ( node )
{
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
if (handler->GetType() == bitmapType)
return handler;
node = node->GetNext();
}
return NULL;
}
void wxBitmapBase::CleanUpHandlers()
{
wxList::compatibility_iterator node = sm_handlers.GetFirst();
while ( node )
{
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
wxList::compatibility_iterator next = node->GetNext();
delete handler;
sm_handlers.Erase(node);
node = next;
}
}
bool wxBitmapHandlerBase::Create(wxBitmap*, const void*, long, int, int, int)
{
return false;
}
bool wxBitmapHandlerBase::LoadFile(wxBitmap*, const wxString&, long, int, int)
{
return false;
}
bool wxBitmapHandlerBase::SaveFile(const wxBitmap*, const wxString&, int, const wxPalette*)
{
return false;
}
class wxBitmapBaseModule: public wxModule
{
DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
public:
wxBitmapBaseModule() {}
bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
void OnExit() { wxBitmap::CleanUpHandlers(); }
};
IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
#endif // wxUSE_BITMAP_BASE
// ----------------------------------------------------------------------------
// wxBitmap common
// ----------------------------------------------------------------------------
#if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
wxBitmap::wxBitmap(const char* const* bits)
{
wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
#if wxUSE_IMAGE && wxUSE_XPM
wxImage image(bits);
wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
*this = wxBitmap(image);
#else
wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
#endif // wxUSE_IMAGE && wxUSE_XPM
}
#endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
// ----------------------------------------------------------------------------
// wxMaskBase
// ----------------------------------------------------------------------------
bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
{
FreeData();
return InitFromColour(bitmap, colour);
}
#if wxUSE_PALETTE
bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
{
wxPalette *pal = bitmap.GetPalette();
wxCHECK_MSG( pal, false,
wxT("Cannot create mask from palette index of a bitmap without palette") );
unsigned char r,g,b;
pal->GetRGB(paletteIndex, &r, &g, &b);
return Create(bitmap, wxColour(r, g, b));
}
#endif // wxUSE_PALETTE
bool wxMaskBase::Create(const wxBitmap& bitmap)
{
FreeData();
return InitFromMonoBitmap(bitmap);
}