]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
* wxMemory*Stream link problem fix.
[wxWidgets.git] / src / generic / imaglist.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: imaglist.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "imaglist.h"
13#endif
14
15#include "wx/imaglist.h"
16
17//-----------------------------------------------------------------------------
18// wxImageList
19//-----------------------------------------------------------------------------
20
21IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
22
219f895a 23wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
c801d85f 24{
219f895a
RR
25 m_width = width;
26 m_height = height;
c801d85f
KB
27 Create();
28};
29
0423b685 30wxImageList::~wxImageList()
c801d85f
KB
31{
32};
33
0423b685 34int wxImageList::GetImageCount() const
c801d85f
KB
35{
36 return m_images.Number();
37};
38
0423b685 39bool wxImageList::Create()
c801d85f
KB
40{
41 m_images.DeleteContents( TRUE );
42 return TRUE;
43};
44
45int wxImageList::Add( const wxBitmap &bitmap )
46{
47 m_images.Append( new wxBitmap(bitmap) );
48 return m_images.Number();
49};
50
0423b685 51bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f
KB
52{
53 wxNode *node = m_images.Nth( index );
54 if (!node) return FALSE;
55
56 if (index == m_images.Number()-1)
57 {
58 m_images.DeleteNode( node );
59 m_images.Append( new wxBitmap(bitmap) );
60 }
61 else
62 {
63 wxNode *next = node->Next();
64 m_images.DeleteNode( node );
65 m_images.Insert( next, new wxBitmap(bitmap) );
66 };
67
68 return TRUE;
69};
70
0423b685 71bool wxImageList::Remove( int index )
c801d85f
KB
72{
73 wxNode *node = m_images.Nth( index );
74 if (node) m_images.DeleteNode( node );
75 return (node != NULL);
76};
77
0423b685 78bool wxImageList::RemoveAll()
c801d85f
KB
79{
80 m_images.Clear();
81 return TRUE;
82};
83
0423b685 84bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 85{
219f895a
RR
86#ifdef __WXGTK__
87
88 width = m_width;
89 height = m_height;
90
91 return (m_images.Nth( index ) != NULL);
92
93#else
94
c801d85f
KB
95 wxNode *node = m_images.Nth( index );
96 if (node)
97 {
98 wxBitmap *bm = (wxBitmap*)node->Data();
99 width = bm->GetWidth();
100 height = bm->GetHeight();
101 return TRUE;
102 }
103 else
104 {
105 width = 0;
106 height = 0;
107 return FALSE;
108 };
219f895a
RR
109
110#endif
c801d85f
KB
111};
112
219f895a
RR
113bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
114 int flags, bool WXUNUSED(solidBackground) )
c801d85f
KB
115{
116 wxNode *node = m_images.Nth( index );
117 if (!node) return FALSE;
118 wxBitmap *bm = (wxBitmap*)node->Data();
219f895a
RR
119
120#ifdef __WXGTK__
121
122 // As X doesn't have a standard size for icons, we resize here.
123 // Otherwise we'd simply have to forbid different bitmap sizes.
124
125 if ((m_width != bm->GetWidth()) ||
126 (m_height != bm->GetHeight()))
127 {
128 bm->Resize( m_width, m_height );
129 };
130
131#endif
132
c801d85f 133 wxIcon *icon = (wxIcon*)bm;
219f895a
RR
134 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
135
c801d85f
KB
136 return TRUE;
137};
138
139