]> git.saurik.com Git - wxWidgets.git/blame - src/common/bmpbase.cpp
don't crash when loading images with verbose==false (patch 1449823)
[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
7220e455
WS
18#if defined(__WXMGL__) || \
19 defined(__WXMAC__) || \
20 defined(__WXGTK__) || \
21 defined(__WXMOTIF__) || \
22 defined(__WXX11__)
ee058011 23
a04eec87
VS
24#include "wx/utils.h"
25#include "wx/palette.h"
26#include "wx/bitmap.h"
27#include "wx/icon.h"
28#include "wx/log.h"
29#include "wx/image.h"
30#include "wx/module.h"
31
32IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
33IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
34
35wxList wxBitmapBase::sm_handlers;
36
37void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
38{
39 sm_handlers.Append(handler);
40}
41
42void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
43{
44 sm_handlers.Insert(handler);
45}
46
47bool wxBitmapBase::RemoveHandler(const wxString& name)
48{
49 wxBitmapHandler *handler = FindHandler(name);
50 if ( handler )
51 {
52 sm_handlers.DeleteObject(handler);
c9d59ee7 53 return true;
a04eec87
VS
54 }
55 else
c9d59ee7 56 return false;
a04eec87
VS
57}
58
59wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
60{
ac32ba44 61 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
62 while ( node )
63 {
1bc822df 64 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
65 if ( handler->GetName() == name )
66 return handler;
1bc822df 67 node = node->GetNext();
a04eec87
VS
68 }
69 return NULL;
70}
71
72wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
73{
ac32ba44 74 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
75 while ( node )
76 {
1bc822df 77 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87 78 if ( handler->GetExtension() == extension &&
4b232264 79 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
a04eec87 80 return handler;
1bc822df 81 node = node->GetNext();
a04eec87
VS
82 }
83 return NULL;
84}
85
86wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
87{
ac32ba44 88 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
89 while ( node )
90 {
1bc822df 91 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
92 if (handler->GetType() == bitmapType)
93 return handler;
1bc822df 94 node = node->GetNext();
a04eec87
VS
95 }
96 return NULL;
97}
98
99void wxBitmapBase::CleanUpHandlers()
100{
ac32ba44 101 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
102 while ( node )
103 {
1bc822df 104 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
ac32ba44 105 wxList::compatibility_iterator next = node->GetNext();
a04eec87 106 delete handler;
ac32ba44 107 sm_handlers.Erase(node);
a04eec87
VS
108 node = next;
109 }
110}
111
a04eec87
VS
112class wxBitmapBaseModule: public wxModule
113{
114DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
115public:
116 wxBitmapBaseModule() {}
c9d59ee7 117 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
a04eec87
VS
118 void OnExit() { wxBitmap::CleanUpHandlers(); };
119};
120
121IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
ee058011 122
7220e455 123#endif // __WXMGL__ || __WXMAC__ || __WXCOCOA__ || __WXMOTIF__ || __WXX11__