]> git.saurik.com Git - wxWidgets.git/blob - src/common/bmpbase.cpp
Build fix for !PCH builds.
[wxWidgets.git] / src / common / bmpbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bmpbase.cpp
3 // Purpose: wxBitmapBase
4 // Author: VaclavSlavik
5 // Created: 2001/04/11
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001, Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/bitmap.h"
19
20 #ifndef WX_PRECOMP
21 #include "wx/colour.h"
22 #endif // WX_PRECOMP
23
24 // ----------------------------------------------------------------------------
25 // wxBitmapBase
26 // ----------------------------------------------------------------------------
27
28 #if wxUSE_BITMAP_BASE
29
30 #ifndef WX_PRECOMP
31 #include "wx/log.h"
32 #include "wx/utils.h"
33 #include "wx/palette.h"
34 #include "wx/icon.h"
35 #include "wx/image.h"
36 #include "wx/module.h"
37 #endif // WX_PRECOMP
38
39 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
40 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
41
42 wxList wxBitmapBase::sm_handlers;
43
44 void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
45 {
46 sm_handlers.Append(handler);
47 }
48
49 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
50 {
51 sm_handlers.Insert(handler);
52 }
53
54 bool wxBitmapBase::RemoveHandler(const wxString& name)
55 {
56 wxBitmapHandler *handler = FindHandler(name);
57 if ( handler )
58 {
59 sm_handlers.DeleteObject(handler);
60 return true;
61 }
62 else
63 return false;
64 }
65
66 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
67 {
68 wxList::compatibility_iterator node = sm_handlers.GetFirst();
69 while ( node )
70 {
71 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
72 if ( handler->GetName() == name )
73 return handler;
74 node = node->GetNext();
75 }
76 return NULL;
77 }
78
79 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
80 {
81 wxList::compatibility_iterator node = sm_handlers.GetFirst();
82 while ( node )
83 {
84 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
85 if ( handler->GetExtension() == extension &&
86 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
87 return handler;
88 node = node->GetNext();
89 }
90 return NULL;
91 }
92
93 wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
94 {
95 wxList::compatibility_iterator node = sm_handlers.GetFirst();
96 while ( node )
97 {
98 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
99 if (handler->GetType() == bitmapType)
100 return handler;
101 node = node->GetNext();
102 }
103 return NULL;
104 }
105
106 void wxBitmapBase::CleanUpHandlers()
107 {
108 wxList::compatibility_iterator node = sm_handlers.GetFirst();
109 while ( node )
110 {
111 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
112 wxList::compatibility_iterator next = node->GetNext();
113 delete handler;
114 sm_handlers.Erase(node);
115 node = next;
116 }
117 }
118
119 class wxBitmapBaseModule: public wxModule
120 {
121 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
122 public:
123 wxBitmapBaseModule() {}
124 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
125 void OnExit() { wxBitmap::CleanUpHandlers(); };
126 };
127
128 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
129
130 #endif // wxUSE_BITMAP_BASE
131
132 // ----------------------------------------------------------------------------
133 // wxMaskBase
134 // ----------------------------------------------------------------------------
135
136 bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
137 {
138 FreeData();
139
140 return InitFromColour(bitmap, colour);
141 }
142
143 #if wxUSE_PALETTE
144
145 bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
146 {
147 wxPalette *pal = bitmap.GetPalette();
148
149 wxCHECK_MSG( pal, false,
150 wxT("Cannot create mask from palette index of a bitmap without palette") );
151
152 unsigned char r,g,b;
153 pal->GetRGB(paletteIndex, &r, &g, &b);
154
155 return Create(bitmap, wxColour(r, g, b));
156 }
157
158 #endif // wxUSE_PALETTE
159
160 bool wxMaskBase::Create(const wxBitmap& bitmap)
161 {
162 FreeData();
163
164 return InitFromMonoBitmap(bitmap);
165 }