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