]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
DP: Just came back from 3 days fishing and found that forget to commit some
[wxWidgets.git] / src / generic / imaglist.cpp
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
21 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
22
23 wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
24 {
25 m_width = width;
26 m_height = height;
27 Create();
28 };
29
30 wxImageList::~wxImageList()
31 {
32 };
33
34 int wxImageList::GetImageCount() const
35 {
36 return m_images.Number();
37 };
38
39 bool wxImageList::Create()
40 {
41 m_images.DeleteContents( TRUE );
42 return TRUE;
43 };
44
45 int wxImageList::Add( const wxBitmap &bitmap )
46 {
47 m_images.Append( new wxBitmap(bitmap) );
48 return m_images.Number();
49 };
50
51 wxBitmap *wxImageList::GetBitmap(int index) {
52 wxNode *node = m_images.Nth(index);
53 if (node != NULL)
54 return (wxBitmap*)node->Data();
55
56 return NULL;
57 }
58
59 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
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) );
74 };
75
76 return TRUE;
77 };
78
79 bool wxImageList::Remove( int index )
80 {
81 wxNode *node = m_images.Nth( index );
82 if (node) m_images.DeleteNode( node );
83 return (node != NULL);
84 };
85
86 bool wxImageList::RemoveAll()
87 {
88 m_images.Clear();
89 return TRUE;
90 };
91
92 bool wxImageList::GetSize( int index, int &width, int &height ) const
93 {
94 #ifdef __WXGTK__
95
96 width = m_width;
97 height = m_height;
98
99 return (m_images.Nth( index ) != NULL);
100
101 #else
102
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;
116 };
117
118 #endif
119 };
120
121 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
122 int flags, bool WXUNUSED(solidBackground) )
123 {
124 wxNode *node = m_images.Nth( index );
125 if (!node) return FALSE;
126 wxBitmap *bm = (wxBitmap*)node->Data();
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 );
137 };
138
139 #endif
140
141 wxIcon *icon = (wxIcon*)bm;
142 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
143
144 return TRUE;
145 };
146
147