]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
Added RTLD_GLOBAL to dlopen() flags which is needed if libraries depend
[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"
4d449473 23#include "wx/image.h"
c801d85f
KB
24
25//-----------------------------------------------------------------------------
26// wxImageList
27//-----------------------------------------------------------------------------
28
29IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
30
219f895a 31wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
c801d85f 32{
b46e8696
RR
33 m_width = width;
34 m_height = height;
35 Create();
e1e955e1 36}
c801d85f 37
0423b685 38wxImageList::~wxImageList()
c801d85f 39{
e1e955e1 40}
c801d85f 41
0423b685 42int wxImageList::GetImageCount() const
c801d85f 43{
b46e8696 44 return m_images.Number();
e1e955e1 45}
c801d85f 46
0423b685 47bool wxImageList::Create()
c801d85f 48{
b46e8696
RR
49 m_images.DeleteContents( TRUE );
50 return TRUE;
e1e955e1 51}
c801d85f
KB
52
53int wxImageList::Add( const wxBitmap &bitmap )
54{
f60d0f94
JS
55 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
56 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
57 else
58 m_images.Append( new wxBitmap(bitmap) );
b00c5607 59 return m_images.Number()-1;
e1e955e1 60}
c801d85f 61
4d449473
VS
62int wxImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
63{
64 wxBitmap bmp(bitmap);
65 bmp.SetMask(new wxMask(mask));
66 return Add(bmp);
67}
68
69int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
70{
71 wxImage img(bitmap);
72 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
73 return Add(img.ConvertToBitmap());
74}
75
43543d98 76const wxBitmap *wxImageList::GetBitmap( int index ) const
b46e8696
RR
77{
78 wxNode *node = m_images.Nth( index );
43543d98 79
223d09f6 80 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 81
8b21b87f 82 return (wxBitmap*)node->Data();
40413a5b 83}
43543d98 84
0423b685 85bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 86{
b46e8696 87 wxNode *node = m_images.Nth( index );
43543d98 88
223d09f6 89 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
f60d0f94
JS
90
91 wxBitmap* newBitmap = NULL;
92 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
43543d98
DW
93#if defined(__VISAGECPP__)
94//just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
95//so construct it from a bitmap object until I can figure this nonsense out. (DW)
96 newBitmap = new wxBitmap(bitmap) ;
97#else
8f177c8e 98 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
43543d98 99#endif
f60d0f94
JS
100 else
101 newBitmap = new wxBitmap(bitmap) ;
102
b46e8696
RR
103 if (index == m_images.Number()-1)
104 {
105 m_images.DeleteNode( node );
f60d0f94 106 m_images.Append( newBitmap );
b46e8696
RR
107 }
108 else
109 {
110 wxNode *next = node->Next();
111 m_images.DeleteNode( node );
f60d0f94 112 m_images.Insert( next, newBitmap );
b46e8696 113 }
43543d98 114
b46e8696 115 return TRUE;
e1e955e1 116}
c801d85f 117
0423b685 118bool wxImageList::Remove( int index )
c801d85f 119{
b46e8696 120 wxNode *node = m_images.Nth( index );
43543d98 121
223d09f6 122 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 123
b46e8696 124 m_images.DeleteNode( node );
43543d98 125
b46e8696 126 return TRUE;
e1e955e1 127}
c801d85f 128
0423b685 129bool wxImageList::RemoveAll()
c801d85f 130{
b46e8696 131 m_images.Clear();
43543d98 132
b46e8696 133 return TRUE;
e1e955e1 134}
c801d85f 135
0423b685 136bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 137{
b46e8696
RR
138 width = 0;
139 height = 0;
43543d98 140
b46e8696 141 wxNode *node = m_images.Nth( index );
43543d98 142
223d09f6 143 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 144
c801d85f
KB
145 wxBitmap *bm = (wxBitmap*)node->Data();
146 width = bm->GetWidth();
147 height = bm->GetHeight();
43543d98 148
c801d85f 149 return TRUE;
e1e955e1 150}
c801d85f 151
219f895a
RR
152bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
153 int flags, bool WXUNUSED(solidBackground) )
c801d85f 154{
b46e8696 155 wxNode *node = m_images.Nth( index );
43543d98 156
223d09f6 157 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 158
b46e8696 159 wxBitmap *bm = (wxBitmap*)node->Data();
f60d0f94
JS
160
161 if (bm->IsKindOf(CLASSINFO(wxIcon)))
162 dc.DrawIcon( * ((wxIcon*) bm), x, y);
163 else
164 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 165
b46e8696 166 return TRUE;
e1e955e1 167}
c801d85f
KB
168
169