]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
argh, another for GetVisibleLinesRange
[wxWidgets.git] / src / generic / imaglist.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f6bcfd97 2// Name: generic/imaglist.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
01111366
RR
5// Id: $id$
6// Copyright: (c) 1998 Robert Roebling
f6bcfd97 7// Licence: wxWindows licence
c801d85f
KB
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"
4d449473 23#include "wx/image.h"
c801d85f
KB
24
25//-----------------------------------------------------------------------------
26// wxImageList
27//-----------------------------------------------------------------------------
28
29IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
30
f6bcfd97 31wxImageList::wxImageList( int width, int height, bool mask, int initialCount )
c801d85f 32{
f6bcfd97 33 (void)Create(width, height, mask, initialCount);
e1e955e1 34}
c801d85f 35
0423b685 36wxImageList::~wxImageList()
c801d85f 37{
e1e955e1 38}
c801d85f 39
0423b685 40int wxImageList::GetImageCount() const
c801d85f 41{
b46e8696 42 return m_images.Number();
e1e955e1 43}
c801d85f 44
f6bcfd97
BP
45bool 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
0423b685 53bool wxImageList::Create()
c801d85f 54{
b46e8696
RR
55 m_images.DeleteContents( TRUE );
56 return TRUE;
e1e955e1 57}
c801d85f
KB
58
59int wxImageList::Add( const wxBitmap &bitmap )
60{
f60d0f94
JS
61 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
62 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
63 else
64 m_images.Append( new wxBitmap(bitmap) );
b00c5607 65 return m_images.Number()-1;
e1e955e1 66}
c801d85f 67
4d449473
VS
68int 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
75int 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
43543d98 82const wxBitmap *wxImageList::GetBitmap( int index ) const
b46e8696
RR
83{
84 wxNode *node = m_images.Nth( index );
43543d98 85
223d09f6 86 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 87
8b21b87f 88 return (wxBitmap*)node->Data();
40413a5b 89}
43543d98 90
0423b685 91bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 92{
b46e8696 93 wxNode *node = m_images.Nth( index );
43543d98 94
223d09f6 95 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
f60d0f94
JS
96
97 wxBitmap* newBitmap = NULL;
98 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
43543d98
DW
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
8f177c8e 104 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
43543d98 105#endif
f60d0f94
JS
106 else
107 newBitmap = new wxBitmap(bitmap) ;
108
b46e8696
RR
109 if (index == m_images.Number()-1)
110 {
111 m_images.DeleteNode( node );
f60d0f94 112 m_images.Append( newBitmap );
b46e8696
RR
113 }
114 else
115 {
116 wxNode *next = node->Next();
117 m_images.DeleteNode( node );
f60d0f94 118 m_images.Insert( next, newBitmap );
b46e8696 119 }
43543d98 120
b46e8696 121 return TRUE;
e1e955e1 122}
c801d85f 123
0423b685 124bool wxImageList::Remove( int index )
c801d85f 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
b46e8696 130 m_images.DeleteNode( node );
43543d98 131
b46e8696 132 return TRUE;
e1e955e1 133}
c801d85f 134
0423b685 135bool wxImageList::RemoveAll()
c801d85f 136{
b46e8696 137 m_images.Clear();
43543d98 138
b46e8696 139 return TRUE;
e1e955e1 140}
c801d85f 141
0423b685 142bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 143{
b46e8696
RR
144 width = 0;
145 height = 0;
43543d98 146
b46e8696 147 wxNode *node = m_images.Nth( index );
43543d98 148
223d09f6 149 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 150
c801d85f
KB
151 wxBitmap *bm = (wxBitmap*)node->Data();
152 width = bm->GetWidth();
153 height = bm->GetHeight();
43543d98 154
c801d85f 155 return TRUE;
e1e955e1 156}
c801d85f 157
219f895a
RR
158bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
159 int flags, bool WXUNUSED(solidBackground) )
c801d85f 160{
b46e8696 161 wxNode *node = m_images.Nth( index );
43543d98 162
223d09f6 163 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 164
b46e8696 165 wxBitmap *bm = (wxBitmap*)node->Data();
f60d0f94
JS
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 );
219f895a 171
b46e8696 172 return TRUE;
e1e955e1 173}
c801d85f
KB
174
175