]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
fix typo in drawing slider ticks; added assert to check for it (slightly modified...
[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 #ifdef __GNUG__
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
25 //-----------------------------------------------------------------------------
26 // wxImageList
27 //-----------------------------------------------------------------------------
28
29 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject)
30
31 #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__)
32 /*
33 * wxImageList has to be a real class or we have problems with
34 * the run-time information.
35 */
36
37 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList)
38 #endif
39
40 wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount )
41 {
42 (void)Create(width, height, mask, initialCount);
43 }
44
45 wxGenericImageList::~wxGenericImageList()
46 {
47 }
48
49 int wxGenericImageList::GetImageCount() const
50 {
51 return m_images.Number();
52 }
53
54 bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
55 {
56 m_width = width;
57 m_height = height;
58
59 return Create();
60 }
61
62 bool wxGenericImageList::Create()
63 {
64 m_images.DeleteContents( TRUE );
65 return TRUE;
66 }
67
68 int wxGenericImageList::Add( const wxBitmap &bitmap )
69 {
70 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
71 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
72 else
73 m_images.Append( new wxBitmap(bitmap) );
74 return m_images.Number()-1;
75 }
76
77 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
78 {
79 wxBitmap bmp(bitmap);
80 if (mask.Ok())
81 bmp.SetMask(new wxMask(mask));
82 return Add(bmp);
83 }
84
85 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
86 {
87 wxImage img = bitmap.ConvertToImage();
88 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
89 return Add(wxBitmap(img));
90 }
91
92 const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
93 {
94 wxNode *node = m_images.Nth( index );
95
96 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
97
98 return (wxBitmap*)node->Data();
99 }
100
101 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
102 {
103 wxNode *node = m_images.Nth( index );
104
105 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
106
107 wxBitmap* newBitmap = NULL;
108 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
109 #if defined(__VISAGECPP__)
110 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
111 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
112 newBitmap = new wxBitmap(bitmap) ;
113 #else
114 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
115 #endif
116 else
117 newBitmap = new wxBitmap(bitmap) ;
118
119 if (index == m_images.Number()-1)
120 {
121 m_images.DeleteNode( node );
122 m_images.Append( newBitmap );
123 }
124 else
125 {
126 wxNode *next = node->Next();
127 m_images.DeleteNode( node );
128 m_images.Insert( next, newBitmap );
129 }
130
131 return TRUE;
132 }
133
134 bool wxGenericImageList::Remove( int index )
135 {
136 wxNode *node = m_images.Nth( index );
137
138 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
139
140 m_images.DeleteNode( node );
141
142 return TRUE;
143 }
144
145 bool wxGenericImageList::RemoveAll()
146 {
147 m_images.Clear();
148
149 return TRUE;
150 }
151
152 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
153 {
154 width = 0;
155 height = 0;
156
157 wxNode *node = m_images.Nth( index );
158
159 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
160
161 wxBitmap *bm = (wxBitmap*)node->Data();
162 width = bm->GetWidth();
163 height = bm->GetHeight();
164
165 return TRUE;
166 }
167
168 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
169 int flags, bool WXUNUSED(solidBackground) )
170 {
171 wxNode *node = m_images.Nth( index );
172
173 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
174
175 wxBitmap *bm = (wxBitmap*)node->Data();
176
177 if (bm->IsKindOf(CLASSINFO(wxIcon)))
178 dc.DrawIcon( * ((wxIcon*) bm), x, y);
179 else
180 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
181
182 return TRUE;
183 }
184
185