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