]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
Add a little space so the wxHtmlCell doesn't overwrite the border of
[wxWidgets.git] / src / generic / imaglist.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "imaglist.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "wx/generic/imaglist.h"
22 #include "wx/icon.h"
23 #include "wx/image.h"
24 #include "wx/dc.h"
25
26 //-----------------------------------------------------------------------------
27 // wxImageList
28 //-----------------------------------------------------------------------------
29
30 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject)
31
32 #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__)
33 /*
34 * wxImageList has to be a real class or we have problems with
35 * the run-time information.
36 */
37
38 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList)
39 #endif
40
41 wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount )
42 {
43 (void)Create(width, height, mask, initialCount);
44 }
45
46 wxGenericImageList::~wxGenericImageList()
47 {
48 }
49
50 int wxGenericImageList::GetImageCount() const
51 {
52 return m_images.GetCount();
53 }
54
55 bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
56 {
57 m_width = width;
58 m_height = height;
59
60 return Create();
61 }
62
63 bool wxGenericImageList::Create()
64 {
65 return TRUE;
66 }
67
68 int wxGenericImageList::Add( const wxBitmap &bitmap )
69 {
70 wxASSERT_MSG( bitmap.GetWidth() == m_width &&
71 bitmap.GetHeight() == m_height,
72 _T("invalid bitmap size in wxImageList: this might work ")
73 _T("on this platform but definitely won't under Windows.") );
74
75 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
76 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
77 else
78 m_images.Append( new wxBitmap(bitmap) );
79 return m_images.GetCount()-1;
80 }
81
82 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
83 {
84 wxBitmap bmp(bitmap);
85 if (mask.Ok())
86 bmp.SetMask(new wxMask(mask));
87 return Add(bmp);
88 }
89
90 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
91 {
92 wxImage img = bitmap.ConvertToImage();
93 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
94 return Add(wxBitmap(img));
95 }
96
97 const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
98 {
99 wxList::compatibility_iterator node = m_images.Item( index );
100
101 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
102
103 return (wxBitmap*)node->GetData();
104 }
105
106 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
107 {
108 wxList::compatibility_iterator node = m_images.Item( index );
109
110 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
111
112 wxBitmap* newBitmap = NULL;
113 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
114 #if defined(__VISAGECPP__)
115 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
116 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
117 newBitmap = new wxBitmap(bitmap) ;
118 #else
119 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
120 #endif
121 else
122 newBitmap = new wxBitmap(bitmap) ;
123
124 if (index == (int) m_images.GetCount() - 1)
125 {
126 delete node->GetData();
127 m_images.Erase( node );
128 m_images.Append( newBitmap );
129 }
130 else
131 {
132 wxList::compatibility_iterator next = node->GetNext();
133 delete node->GetData();
134 m_images.Erase( node );
135 m_images.Insert( next, newBitmap );
136 }
137
138 return TRUE;
139 }
140
141 bool wxGenericImageList::Remove( int index )
142 {
143 wxList::compatibility_iterator node = m_images.Item( index );
144
145 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
146
147 delete node->GetData();
148 m_images.Erase( node );
149
150 return TRUE;
151 }
152
153 bool wxGenericImageList::RemoveAll()
154 {
155 WX_CLEAR_LIST(wxList, m_images);
156 m_images.Clear();
157
158 return TRUE;
159 }
160
161 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
162 {
163 width = 0;
164 height = 0;
165
166 wxList::compatibility_iterator node = m_images.Item( index );
167
168 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
169
170 wxBitmap *bm = (wxBitmap*)node->GetData();
171 width = bm->GetWidth();
172 height = bm->GetHeight();
173
174 return TRUE;
175 }
176
177 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
178 int flags, bool WXUNUSED(solidBackground) )
179 {
180 wxList::compatibility_iterator node = m_images.Item( index );
181
182 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
183
184 wxBitmap *bm = (wxBitmap*)node->GetData();
185
186 if (bm->IsKindOf(CLASSINFO(wxIcon)))
187 dc.DrawIcon( * ((wxIcon*) bm), x, y);
188 else
189 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
190
191 return TRUE;
192 }
193
194