Do not #include an header where a forward declaration suffixes. Do not
[wxWidgets.git] / src / common / bmpbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.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 #ifdef __GNUG__
12 #pragma implementation "bitmapbase.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXMOTIF__)
23
24 #include "wx/setup.h"
25 #include "wx/utils.h"
26 #include "wx/palette.h"
27 #include "wx/bitmap.h"
28 #include "wx/icon.h"
29 #include "wx/log.h"
30 #include "wx/image.h"
31 #include "wx/module.h"
32
33 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
34 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
35
36 wxList wxBitmapBase::sm_handlers;
37
38 void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
39 {
40 sm_handlers.Append(handler);
41 }
42
43 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
44 {
45 sm_handlers.Insert(handler);
46 }
47
48 bool wxBitmapBase::RemoveHandler(const wxString& name)
49 {
50 wxBitmapHandler *handler = FindHandler(name);
51 if ( handler )
52 {
53 sm_handlers.DeleteObject(handler);
54 return TRUE;
55 }
56 else
57 return FALSE;
58 }
59
60 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
61 {
62 wxList::Node *node = sm_handlers.GetFirst();
63 while ( node )
64 {
65 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
66 if ( handler->GetName() == name )
67 return handler;
68 node = node->GetNext();
69 }
70 return NULL;
71 }
72
73 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
74 {
75 wxList::Node *node = sm_handlers.GetFirst();
76 while ( node )
77 {
78 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
79 if ( handler->GetExtension() == extension &&
80 (bitmapType == -1 || handler->GetType() == bitmapType) )
81 return handler;
82 node = node->GetNext();
83 }
84 return NULL;
85 }
86
87 wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
88 {
89 wxList::Node *node = sm_handlers.GetFirst();
90 while ( node )
91 {
92 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
93 if (handler->GetType() == bitmapType)
94 return handler;
95 node = node->GetNext();
96 }
97 return NULL;
98 }
99
100 void wxBitmapBase::CleanUpHandlers()
101 {
102 wxList::Node *node = sm_handlers.GetFirst();
103 while ( node )
104 {
105 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
106 wxList::Node *next = node->GetNext();
107 delete handler;
108 delete node;
109 node = next;
110 }
111 }
112
113 class wxBitmapBaseModule: public wxModule
114 {
115 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
116 public:
117 wxBitmapBaseModule() {}
118 bool OnInit() { wxBitmap::InitStandardHandlers(); return TRUE; };
119 void OnExit() { wxBitmap::CleanUpHandlers(); };
120 };
121
122 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
123
124 #endif // defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXMOTIF__)
125