]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
added "access" parameter to wxFile::Create and Open. The default value is
[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 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
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
71 bool wxImageList::Remove( int index )
72 {
73 wxNode *node = m_images.Nth( index );
74 if (node) m_images.DeleteNode( node );
75 return (node != NULL);
76 };
77
78 bool wxImageList::RemoveAll()
79 {
80 m_images.Clear();
81 return TRUE;
82 };
83
84 bool wxImageList::GetSize( int index, int &width, int &height ) const
85 {
86 #ifdef __WXGTK__
87
88 width = m_width;
89 height = m_height;
90
91 return (m_images.Nth( index ) != NULL);
92
93 #else
94
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 };
109
110 #endif
111 };
112
113 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
114 int flags, bool WXUNUSED(solidBackground) )
115 {
116 wxNode *node = m_images.Nth( index );
117 if (!node) return FALSE;
118 wxBitmap *bm = (wxBitmap*)node->Data();
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
133 wxIcon *icon = (wxIcon*)bm;
134 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
135
136 return TRUE;
137 };
138
139