]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
extending calculation of visible region
[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 (void)RemoveAll();
49 }
50
51 int wxGenericImageList::GetImageCount() const
52 {
53 return m_images.GetCount();
54 }
55
56 bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
57 {
58 m_width = width;
59 m_height = height;
60
61 return Create();
62 }
63
64 bool wxGenericImageList::Create()
65 {
66 return TRUE;
67 }
68
69 int wxGenericImageList::Add( const wxBitmap &bitmap )
70 {
71 wxASSERT_MSG( bitmap.GetWidth() == m_width &&
72 bitmap.GetHeight() == m_height,
73 _T("invalid bitmap size in wxImageList: this might work ")
74 _T("on this platform but definitely won't under Windows.") );
75
76 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
77 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
78 else
79 m_images.Append( new wxBitmap(bitmap) );
80 return m_images.GetCount()-1;
81 }
82
83 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
84 {
85 wxBitmap bmp(bitmap);
86 if (mask.Ok())
87 bmp.SetMask(new wxMask(mask));
88 return Add(bmp);
89 }
90
91 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
92 {
93 wxImage img = bitmap.ConvertToImage();
94 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
95 return Add(wxBitmap(img));
96 }
97
98 const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
99 {
100 wxList::compatibility_iterator node = m_images.Item( index );
101
102 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
103
104 return (wxBitmap*)node->GetData();
105 }
106
107 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
108 {
109 wxList::compatibility_iterator node = m_images.Item( index );
110
111 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
112
113 wxBitmap* newBitmap = (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 new wxBitmap(bitmap)
118 #else
119 new wxBitmap( (const wxIcon&) bitmap )
120 #endif
121 : new wxBitmap(bitmap) ;
122
123 if (index == (int) m_images.GetCount() - 1)
124 {
125 delete node->GetData();
126 m_images.Erase( node );
127 m_images.Append( newBitmap );
128 }
129 else
130 {
131 wxList::compatibility_iterator next = node->GetNext();
132 delete node->GetData();
133 m_images.Erase( node );
134 m_images.Insert( next, newBitmap );
135 }
136
137 return TRUE;
138 }
139
140 bool wxGenericImageList::Remove( int index )
141 {
142 wxList::compatibility_iterator node = m_images.Item( index );
143
144 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
145
146 delete node->GetData();
147 m_images.Erase( node );
148
149 return TRUE;
150 }
151
152 bool wxGenericImageList::RemoveAll()
153 {
154 WX_CLEAR_LIST(wxList, m_images);
155 m_images.Clear();
156
157 return TRUE;
158 }
159
160 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
161 {
162 width = 0;
163 height = 0;
164
165 wxList::compatibility_iterator node = m_images.Item( index );
166
167 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
168
169 wxBitmap *bm = (wxBitmap*)node->GetData();
170 width = bm->GetWidth();
171 height = bm->GetHeight();
172
173 return TRUE;
174 }
175
176 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
177 int flags, bool WXUNUSED(solidBackground) )
178 {
179 wxList::compatibility_iterator node = m_images.Item( index );
180
181 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
182
183 wxBitmap *bm = (wxBitmap*)node->GetData();
184
185 if (bm->IsKindOf(CLASSINFO(wxIcon)))
186 dc.DrawIcon( * ((wxIcon*) bm), x, y);
187 else
188 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
189
190 return TRUE;
191 }
192
193