]> git.saurik.com Git - wxWidgets.git/blame - src/generic/bmpcboxg.cpp
use wxWindow::GetClientSize() instead of ::GetClientRect() in wxActiveXContainer...
[wxWidgets.git] / src / generic / bmpcboxg.cpp
CommitLineData
95a46303
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/bmpcboxg.cpp
3// Purpose: wxBitmapComboBox
4// Author: Jaakko Salli
5// Modified by:
6// Created: Aug-31-2006
1c4e8f38 7// RCS-ID: $Id$
95a46303
RR
8// Copyright: (c) 2005 Jaakko Salli
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_BITMAPCOMBOBOX
27
28#include "wx/bmpcbox.h"
29
30#if defined(wxGENERIC_BITMAPCOMBOBOX)
31
32#ifndef WX_PRECOMP
33 #include "wx/log.h"
34#endif
35
36#include "wx/odcombo.h"
37#include "wx/settings.h"
84140dc9 38#include "wx/dc.h"
95a46303
RR
39
40#if wxUSE_IMAGE
41 #include "wx/image.h"
42#endif
43
44
95a46303
RR
45#define IMAGE_SPACING_CTRL_VERTICAL 7 // Spacing used in control size calculation
46
95a46303
RR
47
48// ============================================================================
49// implementation
50// ============================================================================
51
52
53BEGIN_EVENT_TABLE(wxBitmapComboBox, wxOwnerDrawnComboBox)
012967ef 54 EVT_SIZE(wxBitmapComboBox::OnSize)
95a46303
RR
55END_EVENT_TABLE()
56
57
58IMPLEMENT_DYNAMIC_CLASS(wxBitmapComboBox, wxOwnerDrawnComboBox)
59
60void wxBitmapComboBox::Init()
61{
95a46303
RR
62 m_inResize = false;
63}
64
65wxBitmapComboBox::wxBitmapComboBox(wxWindow *parent,
66 wxWindowID id,
67 const wxString& value,
68 const wxPoint& pos,
69 const wxSize& size,
70 const wxArrayString& choices,
71 long style,
72 const wxValidator& validator,
73 const wxString& name)
74 : wxOwnerDrawnComboBox(),
75 wxBitmapComboBoxBase()
76{
77 Init();
78
79 Create(parent,id,value,pos,size,choices,style,validator,name);
80}
81
82bool wxBitmapComboBox::Create(wxWindow *parent,
83 wxWindowID id,
84 const wxString& value,
85 const wxPoint& pos,
86 const wxSize& size,
87 const wxArrayString& choices,
88 long style,
89 const wxValidator& validator,
90 const wxString& name)
91{
92 if ( !wxOwnerDrawnComboBox::Create(parent, id, value,
93 pos, size,
94 choices, style,
95 validator, name) )
96 {
97 return false;
98 }
99
f696015c 100 UpdateInternals();
95a46303
RR
101
102 return true;
103}
104
105bool wxBitmapComboBox::Create(wxWindow *parent,
106 wxWindowID id,
107 const wxString& value,
108 const wxPoint& pos,
109 const wxSize& size,
110 int n,
111 const wxString choices[],
112 long style,
113 const wxValidator& validator,
114 const wxString& name)
115{
116 if ( !wxOwnerDrawnComboBox::Create(parent, id, value,
117 pos, size, n,
118 choices, style,
119 validator, name) )
120 {
121 return false;
122 }
123
f696015c 124 UpdateInternals();
95a46303
RR
125
126 return true;
127}
128
95a46303
RR
129wxBitmapComboBox::~wxBitmapComboBox()
130{
131 Clear();
132}
133
134// ----------------------------------------------------------------------------
135// Item manipulation
136// ----------------------------------------------------------------------------
137
138void wxBitmapComboBox::SetItemBitmap(unsigned int n, const wxBitmap& bitmap)
139{
95a46303 140 OnAddBitmap(bitmap);
f696015c 141 DoSetItemBitmap(n, bitmap);
95a46303
RR
142
143 if ( (int)n == GetSelection() )
144 Refresh();
145}
146
a236aa20
VZ
147int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items,
148 unsigned int pos,
149 void **clientData, wxClientDataType type)
150{
151 const unsigned int numItems = items.GetCount();
152 const unsigned int countNew = GetCount() + numItems;
153
154 m_bitmaps.Alloc(countNew);
155
f696015c 156 for ( unsigned int i = 0; i < numItems; i++ )
a236aa20
VZ
157 {
158 m_bitmaps.Insert(new wxBitmap(wxNullBitmap), pos + i);
159 }
160
161 const int index = wxOwnerDrawnComboBox::DoInsertItems(items, pos,
162 clientData, type);
163
164 if ( index == wxNOT_FOUND )
165 {
f696015c
VZ
166 for ( int i = numItems-1; i >= 0; i-- )
167 BCBDoDeleteOneItem(pos + i);
a236aa20 168 }
f696015c 169
a236aa20
VZ
170 return index;
171}
172
173int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap)
174{
175 const int n = wxOwnerDrawnComboBox::Append(item);
176 if(n != wxNOT_FOUND)
177 SetItemBitmap(n, bitmap);
178 return n;
179}
180
181int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap,
182 void *clientData)
183{
184 const int n = wxOwnerDrawnComboBox::Append(item, clientData);
185 if(n != wxNOT_FOUND)
186 SetItemBitmap(n, bitmap);
187 return n;
188}
189
190int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap,
191 wxClientData *clientData)
192{
193 const int n = wxOwnerDrawnComboBox::Append(item, clientData);
194 if(n != wxNOT_FOUND)
195 SetItemBitmap(n, bitmap);
196 return n;
197}
198
199int wxBitmapComboBox::Insert(const wxString& item,
200 const wxBitmap& bitmap,
201 unsigned int pos)
202{
203 const int n = wxOwnerDrawnComboBox::Insert(item, pos);
204 if(n != wxNOT_FOUND)
205 SetItemBitmap(n, bitmap);
206 return n;
207}
208
95a46303
RR
209int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap,
210 unsigned int pos, void *clientData)
211{
a236aa20
VZ
212 const int n = wxOwnerDrawnComboBox::Insert(item, pos, clientData);
213 if(n != wxNOT_FOUND)
214 SetItemBitmap(n, bitmap);
95a46303
RR
215 return n;
216}
217
218int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap,
219 unsigned int pos, wxClientData *clientData)
220{
a236aa20
VZ
221 const int n = wxOwnerDrawnComboBox::Insert(item, pos, clientData);
222 if(n != wxNOT_FOUND)
223 SetItemBitmap(n, bitmap);
95a46303
RR
224 return n;
225}
226
a236aa20 227void wxBitmapComboBox::DoClear()
95a46303 228{
a236aa20 229 wxOwnerDrawnComboBox::DoClear();
f696015c 230 wxBitmapComboBoxBase::BCBDoClear();
95a46303
RR
231}
232
a236aa20 233void wxBitmapComboBox::DoDeleteOneItem(unsigned int n)
95a46303 234{
a236aa20 235 wxOwnerDrawnComboBox::DoDeleteOneItem(n);
f696015c 236 wxBitmapComboBoxBase::BCBDoDeleteOneItem(n);
95a46303
RR
237}
238
239// ----------------------------------------------------------------------------
240// wxBitmapComboBox event handlers and such
241// ----------------------------------------------------------------------------
242
012967ef 243void wxBitmapComboBox::OnSize(wxSizeEvent& event)
95a46303
RR
244{
245 // Prevent infinite looping
246 if ( !m_inResize )
247 {
248 m_inResize = true;
249 DetermineIndent();
250 m_inResize = false;
251 }
252
253 event.Skip();
254}
255
256wxSize wxBitmapComboBox::DoGetBestSize() const
257{
258 wxSize sz = wxOwnerDrawnComboBox::DoGetBestSize();
259
f696015c
VZ
260 if ( HasFlag(wxCB_READONLY) )
261 {
262 // Scale control to match height of highest image.
263 int h2 = m_usedImgSize.y + IMAGE_SPACING_CTRL_VERTICAL;
95a46303 264
f696015c
VZ
265 if ( h2 > sz.y )
266 sz.y = h2;
267
268 CacheBestSize(sz);
269 }
95a46303 270
95a46303
RR
271 return sz;
272}
273
274// ----------------------------------------------------------------------------
275// wxBitmapComboBox miscellaneous
276// ----------------------------------------------------------------------------
277
278bool wxBitmapComboBox::SetFont(const wxFont& font)
279{
280 bool res = wxOwnerDrawnComboBox::SetFont(font);
f696015c 281 UpdateInternals();
95a46303
RR
282 return res;
283}
284
285// ----------------------------------------------------------------------------
286// wxBitmapComboBox item drawing and measuring
287// ----------------------------------------------------------------------------
288
289void wxBitmapComboBox::OnDrawBackground(wxDC& dc,
290 const wxRect& rect,
291 int item,
292 int flags) const
293{
294 if ( GetCustomPaintWidth() == 0 ||
295 !(flags & wxODCB_PAINTING_SELECTED) ||
c905c0d6
VZ
296 item < 0 ||
297 ( (flags & wxODCB_PAINTING_CONTROL) && (GetInternalFlags() & wxCC_FULL_BUTTON)) )
95a46303
RR
298 {
299 wxOwnerDrawnComboBox::OnDrawBackground(dc, rect, item, flags);
300 return;
301 }
302
f696015c 303 wxBitmapComboBoxBase::DrawBackground(dc, rect, item, flags);
95a46303
RR
304}
305
306void wxBitmapComboBox::OnDrawItem(wxDC& dc,
307 const wxRect& rect,
308 int item,
309 int flags) const
310{
311 wxString text;
312 int imgAreaWidth = m_imgAreaWidth;
95a46303
RR
313
314 if ( imgAreaWidth == 0 )
315 {
316 wxOwnerDrawnComboBox::OnDrawItem(dc, rect, item, flags);
317 return;
318 }
319
320 if ( flags & wxODCB_PAINTING_CONTROL )
321 {
322 text = GetValue();
f696015c
VZ
323 if ( !HasFlag(wxCB_READONLY) )
324 text.clear();
95a46303
RR
325 }
326 else
327 {
328 text = GetString(item);
95a46303 329 }
f696015c
VZ
330
331 wxBitmapComboBoxBase::DrawItem(dc, rect, item, text, flags);
95a46303
RR
332}
333
f696015c 334wxCoord wxBitmapComboBox::OnMeasureItem(size_t item) const
95a46303 335{
f696015c 336 return wxBitmapComboBoxBase::MeasureItem(item);
95a46303
RR
337}
338
339wxCoord wxBitmapComboBox::OnMeasureItemWidth(size_t item) const
340{
341 wxCoord x, y;
342 GetTextExtent(GetString(item), &x, &y, 0, 0);
343 x += m_imgAreaWidth;
344 return x;
345}
346
347#endif // defined(wxGENERIC_BITMAPCOMBOBOX)
348
349#endif // wxUSE_BITMAPCOMBOBOX