]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
added mingw32 host platform to configure.in, added WINVER define for windows
[wxWidgets.git] / src / generic / imaglist.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: imaglist.cpp
3// Purpose:
4// Author: Robert Roebling
01111366
RR
5// Id: $id$
6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "imaglist.h"
12#endif
13
1e6d9499
JS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
17#ifdef __BORLANDC__
18#pragma hdrstop
19#endif
20
f60d0f94 21#include "wx/generic/imaglist.h"
64698f9a 22#include "wx/icon.h"
c801d85f
KB
23
24//-----------------------------------------------------------------------------
25// wxImageList
26//-----------------------------------------------------------------------------
27
28IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
29
219f895a 30wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
c801d85f 31{
b46e8696
RR
32 m_width = width;
33 m_height = height;
34 Create();
e1e955e1 35}
c801d85f 36
0423b685 37wxImageList::~wxImageList()
c801d85f 38{
e1e955e1 39}
c801d85f 40
0423b685 41int wxImageList::GetImageCount() const
c801d85f 42{
b46e8696 43 return m_images.Number();
e1e955e1 44}
c801d85f 45
0423b685 46bool wxImageList::Create()
c801d85f 47{
b46e8696
RR
48 m_images.DeleteContents( TRUE );
49 return TRUE;
e1e955e1 50}
c801d85f
KB
51
52int wxImageList::Add( const wxBitmap &bitmap )
53{
f60d0f94
JS
54 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
55 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
56 else
57 m_images.Append( new wxBitmap(bitmap) );
b00c5607 58 return m_images.Number()-1;
e1e955e1 59}
c801d85f 60
b46e8696
RR
61const wxBitmap *wxImageList::GetBitmap( int index ) const
62{
63 wxNode *node = m_images.Nth( index );
64
87138c52 65 wxCHECK_MSG( node, (wxBitmap *) NULL, _T("wrong index in image list") );
b46e8696 66
8b21b87f 67 return (wxBitmap*)node->Data();
40413a5b
DP
68}
69
0423b685 70bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 71{
b46e8696
RR
72 wxNode *node = m_images.Nth( index );
73
87138c52 74 wxCHECK_MSG( node, FALSE, _T("wrong index in image list") );
f60d0f94
JS
75
76 wxBitmap* newBitmap = NULL;
77 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
78 newBitmap = new wxIcon( (const wxIcon&) bitmap );
79 else
80 newBitmap = new wxBitmap(bitmap) ;
81
b46e8696
RR
82 if (index == m_images.Number()-1)
83 {
84 m_images.DeleteNode( node );
f60d0f94 85 m_images.Append( newBitmap );
b46e8696
RR
86 }
87 else
88 {
89 wxNode *next = node->Next();
90 m_images.DeleteNode( node );
f60d0f94 91 m_images.Insert( next, newBitmap );
b46e8696 92 }
c801d85f 93
b46e8696 94 return TRUE;
e1e955e1 95}
c801d85f 96
0423b685 97bool wxImageList::Remove( int index )
c801d85f 98{
b46e8696
RR
99 wxNode *node = m_images.Nth( index );
100
87138c52 101 wxCHECK_MSG( node, FALSE, _T("wrong index in image list") );
b46e8696
RR
102
103 m_images.DeleteNode( node );
104
105 return TRUE;
e1e955e1 106}
c801d85f 107
0423b685 108bool wxImageList::RemoveAll()
c801d85f 109{
b46e8696
RR
110 m_images.Clear();
111
112 return TRUE;
e1e955e1 113}
c801d85f 114
0423b685 115bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 116{
b46e8696
RR
117 width = 0;
118 height = 0;
119
120 wxNode *node = m_images.Nth( index );
121
87138c52 122 wxCHECK_MSG( node, FALSE, _T("wrong index in image list") );
b46e8696 123
c801d85f
KB
124 wxBitmap *bm = (wxBitmap*)node->Data();
125 width = bm->GetWidth();
126 height = bm->GetHeight();
b46e8696 127
c801d85f 128 return TRUE;
e1e955e1 129}
c801d85f 130
219f895a
RR
131bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
132 int flags, bool WXUNUSED(solidBackground) )
c801d85f 133{
b46e8696
RR
134 wxNode *node = m_images.Nth( index );
135
87138c52 136 wxCHECK_MSG( node, FALSE, _T("wrong index in image list") );
b46e8696
RR
137
138 wxBitmap *bm = (wxBitmap*)node->Data();
f60d0f94
JS
139
140 if (bm->IsKindOf(CLASSINFO(wxIcon)))
141 dc.DrawIcon( * ((wxIcon*) bm), x, y);
142 else
143 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 144
b46e8696 145 return TRUE;
e1e955e1 146}
c801d85f
KB
147
148