]> git.saurik.com Git - wxWidgets.git/blame - src/common/bmpbase.cpp
Store property name and value in wxPropertyGridEvent, keep track of live event instan...
[wxWidgets.git] / src / common / bmpbase.cpp
CommitLineData
a04eec87 1/////////////////////////////////////////////////////////////////////////////
f03e8f9b 2// Name: src/common/bmpbase.cpp
a04eec87
VS
3// Purpose: wxBitmapBase
4// Author: VaclavSlavik
5// Created: 2001/04/11
6// RCS-ID: $Id$
7// Copyright: (c) 2001, Vaclav Slavik
65571936 8// Licence: wxWindows licence
a04eec87
VS
9/////////////////////////////////////////////////////////////////////////////
10
9d4ca3aa
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
da8cebb2
WS
18#include "wx/bitmap.h"
19
20#ifndef WX_PRECOMP
21 #include "wx/colour.h"
d4f6dbf6 22 #include "wx/icon.h"
1deb3af2 23 #include "wx/image.h"
da8cebb2
WS
24#endif // WX_PRECOMP
25
bae328c1
WS
26// ----------------------------------------------------------------------------
27// wxVariant support
28// ----------------------------------------------------------------------------
29
30#if wxUSE_VARIANT
55ccdb93
VZ
31IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
32IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
bae328c1
WS
33#endif
34
91885f46
VZ
35// ----------------------------------------------------------------------------
36// wxBitmapBase
37// ----------------------------------------------------------------------------
38
ab00f409
WS
39#if wxUSE_BITMAP_BASE
40
e4db172a
WS
41#ifndef WX_PRECOMP
42 #include "wx/log.h"
de6185e2 43 #include "wx/utils.h"
559a723c 44 #include "wx/palette.h"
02761f6c 45 #include "wx/module.h"
e4db172a
WS
46#endif // WX_PRECOMP
47
6f5d7825 48
a04eec87 49IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
e86f2cc8 50IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxObject)
a04eec87
VS
51
52wxList wxBitmapBase::sm_handlers;
53
c822d4ca 54void wxBitmapBase::AddHandler(wxBitmapHandler *handler)
a04eec87
VS
55{
56 sm_handlers.Append(handler);
57}
58
c822d4ca 59void wxBitmapBase::InsertHandler(wxBitmapHandler *handler)
a04eec87
VS
60{
61 sm_handlers.Insert(handler);
62}
63
64bool wxBitmapBase::RemoveHandler(const wxString& name)
65{
66 wxBitmapHandler *handler = FindHandler(name);
67 if ( handler )
68 {
69 sm_handlers.DeleteObject(handler);
c9d59ee7 70 return true;
a04eec87
VS
71 }
72 else
c9d59ee7 73 return false;
a04eec87
VS
74}
75
76wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
77{
ac32ba44 78 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
79 while ( node )
80 {
1bc822df 81 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
82 if ( handler->GetName() == name )
83 return handler;
1bc822df 84 node = node->GetNext();
a04eec87
VS
85 }
86 return NULL;
87}
88
89wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
90{
ac32ba44 91 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
92 while ( node )
93 {
1bc822df 94 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87 95 if ( handler->GetExtension() == extension &&
4b232264 96 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
a04eec87 97 return handler;
1bc822df 98 node = node->GetNext();
a04eec87
VS
99 }
100 return NULL;
101}
102
103wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
104{
ac32ba44 105 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
106 while ( node )
107 {
1bc822df 108 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
109 if (handler->GetType() == bitmapType)
110 return handler;
1bc822df 111 node = node->GetNext();
a04eec87
VS
112 }
113 return NULL;
114}
115
116void wxBitmapBase::CleanUpHandlers()
117{
ac32ba44 118 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
119 while ( node )
120 {
1bc822df 121 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
ac32ba44 122 wxList::compatibility_iterator next = node->GetNext();
a04eec87 123 delete handler;
ac32ba44 124 sm_handlers.Erase(node);
a04eec87
VS
125 node = next;
126 }
127}
128
a04eec87
VS
129class wxBitmapBaseModule: public wxModule
130{
131DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
132public:
133 wxBitmapBaseModule() {}
98d6e4b4
PC
134 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
135 void OnExit() { wxBitmap::CleanUpHandlers(); }
a04eec87
VS
136};
137
198c264d
JS
138wxBitmap wxBitmapBase::ConvertToDisabled(unsigned char brightness) const
139{
140 wxBitmap bmp;
141#if wxUSE_IMAGE
142 wxImage image = ConvertToImage();
143 bmp = wxBitmap(image.ConvertToDisabled(brightness));
144#endif
145 return bmp;
146}
147
a04eec87 148IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
ee058011 149
91885f46
VZ
150#endif // wxUSE_BITMAP_BASE
151
452418c4
PC
152// ----------------------------------------------------------------------------
153// wxBitmap common
154// ----------------------------------------------------------------------------
155
156#if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
157
158wxBitmap::wxBitmap(const char* const* bits)
159{
160 wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
161
162#if wxUSE_IMAGE && wxUSE_XPM
163 wxImage image(bits);
164 wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
165
166 *this = wxBitmap(image);
167#else
9a83f860 168 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
452418c4
PC
169#endif // wxUSE_IMAGE && wxUSE_XPM
170}
171#endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
172
87f83ac8
VZ
173// ----------------------------------------------------------------------------
174// wxMaskBase
175// ----------------------------------------------------------------------------
176
177bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
178{
179 FreeData();
180
181 return InitFromColour(bitmap, colour);
182}
183
184#if wxUSE_PALETTE
185
186bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
187{
188 wxPalette *pal = bitmap.GetPalette();
189
190 wxCHECK_MSG( pal, false,
191 wxT("Cannot create mask from palette index of a bitmap without palette") );
192
193 unsigned char r,g,b;
194 pal->GetRGB(paletteIndex, &r, &g, &b);
195
196 return Create(bitmap, wxColour(r, g, b));
197}
198
199#endif // wxUSE_PALETTE
200
201bool wxMaskBase::Create(const wxBitmap& bitmap)
202{
203 FreeData();
204
205 return InitFromMonoBitmap(bitmap);
206}