]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/imaglist.cpp
wxLongLongWx::Assign(double) works - thanks Guillermo
[wxWidgets.git] / src / generic / imaglist.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
24//-----------------------------------------------------------------------------
25// wxImageList
26//-----------------------------------------------------------------------------
27
28IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
29
30wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
31{
32 m_width = width;
33 m_height = height;
34 Create();
35}
36
37wxImageList::~wxImageList()
38{
39}
40
41int wxImageList::GetImageCount() const
42{
43 return m_images.Number();
44}
45
46bool wxImageList::Create()
47{
48 m_images.DeleteContents( TRUE );
49 return TRUE;
50}
51
52int wxImageList::Add( const wxBitmap &bitmap )
53{
54 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
55 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
56 else
57 m_images.Append( new wxBitmap(bitmap) );
58 return m_images.Number()-1;
59}
60
61const wxBitmap *wxImageList::GetBitmap( int index ) const
62{
63 wxNode *node = m_images.Nth( index );
64
65 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
66
67 return (wxBitmap*)node->Data();
68}
69
70bool wxImageList::Replace( int index, const wxBitmap &bitmap )
71{
72 wxNode *node = m_images.Nth( index );
73
74 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
75
76 wxBitmap* newBitmap = NULL;
77 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
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
83 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
84#endif
85 else
86 newBitmap = new wxBitmap(bitmap) ;
87
88 if (index == m_images.Number()-1)
89 {
90 m_images.DeleteNode( node );
91 m_images.Append( newBitmap );
92 }
93 else
94 {
95 wxNode *next = node->Next();
96 m_images.DeleteNode( node );
97 m_images.Insert( next, newBitmap );
98 }
99
100 return TRUE;
101}
102
103bool wxImageList::Remove( int index )
104{
105 wxNode *node = m_images.Nth( index );
106
107 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
108
109 m_images.DeleteNode( node );
110
111 return TRUE;
112}
113
114bool wxImageList::RemoveAll()
115{
116 m_images.Clear();
117
118 return TRUE;
119}
120
121bool wxImageList::GetSize( int index, int &width, int &height ) const
122{
123 width = 0;
124 height = 0;
125
126 wxNode *node = m_images.Nth( index );
127
128 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
129
130 wxBitmap *bm = (wxBitmap*)node->Data();
131 width = bm->GetWidth();
132 height = bm->GetHeight();
133
134 return TRUE;
135}
136
137bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
138 int flags, bool WXUNUSED(solidBackground) )
139{
140 wxNode *node = m_images.Nth( index );
141
142 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
143
144 wxBitmap *bm = (wxBitmap*)node->Data();
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 );
150
151 return TRUE;
152}
153
154