]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
digital mars updated
[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 #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 m_images.DeleteContents( TRUE );
66 return TRUE;
67 }
68
69 int wxGenericImageList::Add( const wxBitmap &bitmap )
70 {
71 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
72 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
73 else
74 m_images.Append( new wxBitmap(bitmap) );
75 return m_images.GetCount()-1;
76 }
77
78 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
79 {
80 wxBitmap bmp(bitmap);
81 if (mask.Ok())
82 bmp.SetMask(new wxMask(mask));
83 return Add(bmp);
84 }
85
86 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
87 {
88 wxImage img = bitmap.ConvertToImage();
89 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
90 return Add(wxBitmap(img));
91 }
92
93 const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
94 {
95 wxNode *node = m_images.Item( index );
96
97 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
98
99 return (wxBitmap*)node->GetData();
100 }
101
102 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
103 {
104 wxNode *node = m_images.Item( index );
105
106 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
107
108 wxBitmap* newBitmap = NULL;
109 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
110 #if defined(__VISAGECPP__)
111 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
112 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
113 newBitmap = new wxBitmap(bitmap) ;
114 #else
115 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
116 #endif
117 else
118 newBitmap = new wxBitmap(bitmap) ;
119
120 if (index == (int) m_images.GetCount() - 1)
121 {
122 m_images.DeleteNode( node );
123 m_images.Append( newBitmap );
124 }
125 else
126 {
127 wxNode *next = node->GetNext();
128 m_images.DeleteNode( node );
129 m_images.Insert( next, newBitmap );
130 }
131
132 return TRUE;
133 }
134
135 bool wxGenericImageList::Remove( int index )
136 {
137 wxNode *node = m_images.Item( index );
138
139 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
140
141 m_images.DeleteNode( node );
142
143 return TRUE;
144 }
145
146 bool wxGenericImageList::RemoveAll()
147 {
148 m_images.Clear();
149
150 return TRUE;
151 }
152
153 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
154 {
155 width = 0;
156 height = 0;
157
158 wxNode *node = m_images.Item( index );
159
160 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
161
162 wxBitmap *bm = (wxBitmap*)node->GetData();
163 width = bm->GetWidth();
164 height = bm->GetHeight();
165
166 return TRUE;
167 }
168
169 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
170 int flags, bool WXUNUSED(solidBackground) )
171 {
172 wxNode *node = m_images.Item( index );
173
174 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
175
176 wxBitmap *bm = (wxBitmap*)node->GetData();
177
178 if (bm->IsKindOf(CLASSINFO(wxIcon)))
179 dc.DrawIcon( * ((wxIcon*) bm), x, y);
180 else
181 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
182
183 return TRUE;
184 }
185
186