]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
Committing in .
[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
43543d98 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
43543d98 61const wxBitmap *wxImageList::GetBitmap( int index ) const
b46e8696
RR
62{
63 wxNode *node = m_images.Nth( index );
43543d98 64
223d09f6 65 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 66
8b21b87f 67 return (wxBitmap*)node->Data();
40413a5b 68}
43543d98 69
0423b685 70bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 71{
b46e8696 72 wxNode *node = m_images.Nth( index );
43543d98 73
223d09f6 74 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
f60d0f94
JS
75
76 wxBitmap* newBitmap = NULL;
77 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
43543d98
DW
78#if defined(__VISAGECPP__)
79//just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
80//so construct it from a bitmap object until I can figure this nonsense out. (DW)
81 newBitmap = new wxBitmap(bitmap) ;
82#else
8f177c8e 83 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
43543d98 84#endif
f60d0f94
JS
85 else
86 newBitmap = new wxBitmap(bitmap) ;
87
b46e8696
RR
88 if (index == m_images.Number()-1)
89 {
90 m_images.DeleteNode( node );
f60d0f94 91 m_images.Append( newBitmap );
b46e8696
RR
92 }
93 else
94 {
95 wxNode *next = node->Next();
96 m_images.DeleteNode( node );
f60d0f94 97 m_images.Insert( next, newBitmap );
b46e8696 98 }
43543d98 99
b46e8696 100 return TRUE;
e1e955e1 101}
c801d85f 102
0423b685 103bool wxImageList::Remove( int index )
c801d85f 104{
b46e8696 105 wxNode *node = m_images.Nth( index );
43543d98 106
223d09f6 107 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 108
b46e8696 109 m_images.DeleteNode( node );
43543d98 110
b46e8696 111 return TRUE;
e1e955e1 112}
c801d85f 113
0423b685 114bool wxImageList::RemoveAll()
c801d85f 115{
b46e8696 116 m_images.Clear();
43543d98 117
b46e8696 118 return TRUE;
e1e955e1 119}
c801d85f 120
0423b685 121bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 122{
b46e8696
RR
123 width = 0;
124 height = 0;
43543d98 125
b46e8696 126 wxNode *node = m_images.Nth( index );
43543d98 127
223d09f6 128 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 129
c801d85f
KB
130 wxBitmap *bm = (wxBitmap*)node->Data();
131 width = bm->GetWidth();
132 height = bm->GetHeight();
43543d98 133
c801d85f 134 return TRUE;
e1e955e1 135}
c801d85f 136
219f895a
RR
137bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
138 int flags, bool WXUNUSED(solidBackground) )
c801d85f 139{
b46e8696 140 wxNode *node = m_images.Nth( index );
43543d98 141
223d09f6 142 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 143
b46e8696 144 wxBitmap *bm = (wxBitmap*)node->Data();
f60d0f94
JS
145
146 if (bm->IsKindOf(CLASSINFO(wxIcon)))
147 dc.DrawIcon( * ((wxIcon*) bm), x, y);
148 else
149 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 150
b46e8696 151 return TRUE;
e1e955e1 152}
c801d85f
KB
153
154