]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
crash under FreeBSD corrected (patch by David Hobley)
[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 27 Create();
e1e955e1 28}
c801d85f 29
0423b685 30wxImageList::~wxImageList()
c801d85f 31{
e1e955e1 32}
c801d85f 33
0423b685 34int wxImageList::GetImageCount() const
c801d85f
KB
35{
36 return m_images.Number();
e1e955e1 37}
c801d85f 38
0423b685 39bool wxImageList::Create()
c801d85f
KB
40{
41 m_images.DeleteContents( TRUE );
42 return TRUE;
e1e955e1 43}
c801d85f
KB
44
45int wxImageList::Add( const wxBitmap &bitmap )
46{
47 m_images.Append( new wxBitmap(bitmap) );
48 return m_images.Number();
e1e955e1 49}
c801d85f 50
d069d02e 51const wxBitmap *wxImageList::GetBitmap(int index) const {
8b21b87f
DP
52 wxNode *node = m_images.Nth(index);
53 if (node != NULL)
54 return (wxBitmap*)node->Data();
55
c67daf87 56 return (wxBitmap *) NULL;
40413a5b
DP
57}
58
0423b685 59bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f
KB
60{
61 wxNode *node = m_images.Nth( index );
62 if (!node) return FALSE;
63
64 if (index == m_images.Number()-1)
65 {
66 m_images.DeleteNode( node );
67 m_images.Append( new wxBitmap(bitmap) );
68 }
69 else
70 {
71 wxNode *next = node->Next();
72 m_images.DeleteNode( node );
73 m_images.Insert( next, new wxBitmap(bitmap) );
e1e955e1 74 }
c801d85f
KB
75
76 return TRUE;
e1e955e1 77}
c801d85f 78
0423b685 79bool wxImageList::Remove( int index )
c801d85f
KB
80{
81 wxNode *node = m_images.Nth( index );
82 if (node) m_images.DeleteNode( node );
83 return (node != NULL);
e1e955e1 84}
c801d85f 85
0423b685 86bool wxImageList::RemoveAll()
c801d85f
KB
87{
88 m_images.Clear();
89 return TRUE;
e1e955e1 90}
c801d85f 91
0423b685 92bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 93{
219f895a
RR
94#ifdef __WXGTK__
95
96 width = m_width;
97 height = m_height;
98
99 return (m_images.Nth( index ) != NULL);
100
101#else
102
c801d85f
KB
103 wxNode *node = m_images.Nth( index );
104 if (node)
105 {
106 wxBitmap *bm = (wxBitmap*)node->Data();
107 width = bm->GetWidth();
108 height = bm->GetHeight();
109 return TRUE;
110 }
111 else
112 {
113 width = 0;
114 height = 0;
115 return FALSE;
e1e955e1 116 }
219f895a
RR
117
118#endif
e1e955e1 119}
c801d85f 120
219f895a
RR
121bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
122 int flags, bool WXUNUSED(solidBackground) )
c801d85f
KB
123{
124 wxNode *node = m_images.Nth( index );
125 if (!node) return FALSE;
126 wxBitmap *bm = (wxBitmap*)node->Data();
219f895a
RR
127
128#ifdef __WXGTK__
129
130 // As X doesn't have a standard size for icons, we resize here.
131 // Otherwise we'd simply have to forbid different bitmap sizes.
132
133 if ((m_width != bm->GetWidth()) ||
134 (m_height != bm->GetHeight()))
135 {
136 bm->Resize( m_width, m_height );
e1e955e1 137 }
219f895a
RR
138
139#endif
140
c801d85f 141 wxIcon *icon = (wxIcon*)bm;
219f895a
RR
142 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
143
c801d85f 144 return TRUE;
e1e955e1 145}
c801d85f
KB
146
147