]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
one more minor wxLogWindow fix (I try to get it really right...)
[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
40413a5b
DP
51wxBitmap *wxImageList::GetBitmap(int index) {
52 wxNode *node = m_images.Nth( index );
53 return (wxBitmap*)node->Data();
54}
55
0423b685 56bool wxImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f
KB
57{
58 wxNode *node = m_images.Nth( index );
59 if (!node) return FALSE;
60
61 if (index == m_images.Number()-1)
62 {
63 m_images.DeleteNode( node );
64 m_images.Append( new wxBitmap(bitmap) );
65 }
66 else
67 {
68 wxNode *next = node->Next();
69 m_images.DeleteNode( node );
70 m_images.Insert( next, new wxBitmap(bitmap) );
71 };
72
73 return TRUE;
74};
75
0423b685 76bool wxImageList::Remove( int index )
c801d85f
KB
77{
78 wxNode *node = m_images.Nth( index );
79 if (node) m_images.DeleteNode( node );
80 return (node != NULL);
81};
82
0423b685 83bool wxImageList::RemoveAll()
c801d85f
KB
84{
85 m_images.Clear();
86 return TRUE;
87};
88
0423b685 89bool wxImageList::GetSize( int index, int &width, int &height ) const
c801d85f 90{
219f895a
RR
91#ifdef __WXGTK__
92
93 width = m_width;
94 height = m_height;
95
96 return (m_images.Nth( index ) != NULL);
97
98#else
99
c801d85f
KB
100 wxNode *node = m_images.Nth( index );
101 if (node)
102 {
103 wxBitmap *bm = (wxBitmap*)node->Data();
104 width = bm->GetWidth();
105 height = bm->GetHeight();
106 return TRUE;
107 }
108 else
109 {
110 width = 0;
111 height = 0;
112 return FALSE;
113 };
219f895a
RR
114
115#endif
c801d85f
KB
116};
117
219f895a
RR
118bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
119 int flags, bool WXUNUSED(solidBackground) )
c801d85f
KB
120{
121 wxNode *node = m_images.Nth( index );
122 if (!node) return FALSE;
123 wxBitmap *bm = (wxBitmap*)node->Data();
219f895a
RR
124
125#ifdef __WXGTK__
126
127 // As X doesn't have a standard size for icons, we resize here.
128 // Otherwise we'd simply have to forbid different bitmap sizes.
129
130 if ((m_width != bm->GetWidth()) ||
131 (m_height != bm->GetHeight()))
132 {
133 bm->Resize( m_width, m_height );
134 };
135
136#endif
137
c801d85f 138 wxIcon *icon = (wxIcon*)bm;
219f895a
RR
139 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
140
c801d85f
KB
141 return TRUE;
142};
143
144