]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: imaglist.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "imaglist.h" | |
12 | #endif | |
13 | ||
14 | // For compilers that support precompilation, includes "wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #include "wx/generic/imaglist.h" | |
22 | #include "wx/icon.h" | |
23 | #include "wx/image.h" | |
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // wxImageList | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) | |
30 | ||
31 | wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) | |
32 | { | |
33 | m_width = width; | |
34 | m_height = height; | |
35 | Create(); | |
36 | } | |
37 | ||
38 | wxImageList::~wxImageList() | |
39 | { | |
40 | } | |
41 | ||
42 | int wxImageList::GetImageCount() const | |
43 | { | |
44 | return m_images.Number(); | |
45 | } | |
46 | ||
47 | bool wxImageList::Create() | |
48 | { | |
49 | m_images.DeleteContents( TRUE ); | |
50 | return TRUE; | |
51 | } | |
52 | ||
53 | int wxImageList::Add( const wxBitmap &bitmap ) | |
54 | { | |
55 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) | |
56 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
57 | else | |
58 | m_images.Append( new wxBitmap(bitmap) ); | |
59 | return m_images.Number()-1; | |
60 | } | |
61 | ||
62 | int wxImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) | |
63 | { | |
64 | wxBitmap bmp(bitmap); | |
65 | bmp.SetMask(new wxMask(mask)); | |
66 | return Add(bmp); | |
67 | } | |
68 | ||
69 | int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour ) | |
70 | { | |
71 | wxImage img(bitmap); | |
72 | img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue()); | |
73 | return Add(img.ConvertToBitmap()); | |
74 | } | |
75 | ||
76 | const wxBitmap *wxImageList::GetBitmap( int index ) const | |
77 | { | |
78 | wxNode *node = m_images.Nth( index ); | |
79 | ||
80 | wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") ); | |
81 | ||
82 | return (wxBitmap*)node->Data(); | |
83 | } | |
84 | ||
85 | bool wxImageList::Replace( int index, const wxBitmap &bitmap ) | |
86 | { | |
87 | wxNode *node = m_images.Nth( index ); | |
88 | ||
89 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); | |
90 | ||
91 | wxBitmap* newBitmap = NULL; | |
92 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) | |
93 | #if defined(__VISAGECPP__) | |
94 | //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff | |
95 | //so construct it from a bitmap object until I can figure this nonsense out. (DW) | |
96 | newBitmap = new wxBitmap(bitmap) ; | |
97 | #else | |
98 | newBitmap = new wxBitmap( (const wxIcon&) bitmap ); | |
99 | #endif | |
100 | else | |
101 | newBitmap = new wxBitmap(bitmap) ; | |
102 | ||
103 | if (index == m_images.Number()-1) | |
104 | { | |
105 | m_images.DeleteNode( node ); | |
106 | m_images.Append( newBitmap ); | |
107 | } | |
108 | else | |
109 | { | |
110 | wxNode *next = node->Next(); | |
111 | m_images.DeleteNode( node ); | |
112 | m_images.Insert( next, newBitmap ); | |
113 | } | |
114 | ||
115 | return TRUE; | |
116 | } | |
117 | ||
118 | bool wxImageList::Remove( int index ) | |
119 | { | |
120 | wxNode *node = m_images.Nth( index ); | |
121 | ||
122 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); | |
123 | ||
124 | m_images.DeleteNode( node ); | |
125 | ||
126 | return TRUE; | |
127 | } | |
128 | ||
129 | bool wxImageList::RemoveAll() | |
130 | { | |
131 | m_images.Clear(); | |
132 | ||
133 | return TRUE; | |
134 | } | |
135 | ||
136 | bool wxImageList::GetSize( int index, int &width, int &height ) const | |
137 | { | |
138 | width = 0; | |
139 | height = 0; | |
140 | ||
141 | wxNode *node = m_images.Nth( index ); | |
142 | ||
143 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); | |
144 | ||
145 | wxBitmap *bm = (wxBitmap*)node->Data(); | |
146 | width = bm->GetWidth(); | |
147 | height = bm->GetHeight(); | |
148 | ||
149 | return TRUE; | |
150 | } | |
151 | ||
152 | bool wxImageList::Draw( int index, wxDC &dc, int x, int y, | |
153 | int flags, bool WXUNUSED(solidBackground) ) | |
154 | { | |
155 | wxNode *node = m_images.Nth( index ); | |
156 | ||
157 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); | |
158 | ||
159 | wxBitmap *bm = (wxBitmap*)node->Data(); | |
160 | ||
161 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
162 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
163 | else | |
164 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
165 | ||
166 | return TRUE; | |
167 | } | |
168 | ||
169 |