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