1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/bmpcboxg.cpp
3 // Purpose: wxBitmapComboBox
4 // Author: Jaakko Salli
6 // Created: Aug-31-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
26 #if wxUSE_BITMAPCOMBOBOX
28 #include "wx/bmpcbox.h"
30 #if defined(wxGENERIC_BITMAPCOMBOBOX)
36 #include "wx/odcombo.h"
37 #include "wx/settings.h"
45 #define IMAGE_SPACING_CTRL_VERTICAL 7 // Spacing used in control size calculation
48 // ============================================================================
50 // ============================================================================
53 BEGIN_EVENT_TABLE(wxBitmapComboBox
, wxOwnerDrawnComboBox
)
54 EVT_SIZE(wxBitmapComboBox::OnSize
)
58 IMPLEMENT_DYNAMIC_CLASS(wxBitmapComboBox
, wxOwnerDrawnComboBox
)
60 void wxBitmapComboBox::Init()
65 wxBitmapComboBox::wxBitmapComboBox(wxWindow
*parent
,
67 const wxString
& value
,
70 const wxArrayString
& choices
,
72 const wxValidator
& validator
,
74 : wxOwnerDrawnComboBox(),
75 wxBitmapComboBoxBase()
79 Create(parent
,id
,value
,pos
,size
,choices
,style
,validator
,name
);
82 bool wxBitmapComboBox::Create(wxWindow
*parent
,
84 const wxString
& value
,
87 const wxArrayString
& choices
,
89 const wxValidator
& validator
,
92 if ( !wxOwnerDrawnComboBox::Create(parent
, id
, value
,
105 bool wxBitmapComboBox::Create(wxWindow
*parent
,
107 const wxString
& value
,
111 const wxString choices
[],
113 const wxValidator
& validator
,
114 const wxString
& name
)
116 if ( !wxOwnerDrawnComboBox::Create(parent
, id
, value
,
129 wxBitmapComboBox::~wxBitmapComboBox()
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void wxBitmapComboBox::SetItemBitmap(unsigned int n
, const wxBitmap
& bitmap
)
141 DoSetItemBitmap(n
, bitmap
);
143 if ( (int)n
== GetSelection() )
147 int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
149 void **clientData
, wxClientDataType type
)
151 const unsigned int numItems
= items
.GetCount();
152 const unsigned int countNew
= GetCount() + numItems
;
154 m_bitmaps
.Alloc(countNew
);
156 for ( unsigned int i
= 0; i
< numItems
; i
++ )
158 m_bitmaps
.Insert(new wxBitmap(wxNullBitmap
), pos
+ i
);
161 const int index
= wxOwnerDrawnComboBox::DoInsertItems(items
, pos
,
164 if ( index
== wxNOT_FOUND
)
166 for ( int i
= numItems
-1; i
>= 0; i
-- )
167 BCBDoDeleteOneItem(pos
+ i
);
173 int wxBitmapComboBox::Append(const wxString
& item
, const wxBitmap
& bitmap
)
175 const int n
= wxOwnerDrawnComboBox::Append(item
);
177 SetItemBitmap(n
, bitmap
);
181 int wxBitmapComboBox::Append(const wxString
& item
, const wxBitmap
& bitmap
,
184 const int n
= wxOwnerDrawnComboBox::Append(item
, clientData
);
186 SetItemBitmap(n
, bitmap
);
190 int wxBitmapComboBox::Append(const wxString
& item
, const wxBitmap
& bitmap
,
191 wxClientData
*clientData
)
193 const int n
= wxOwnerDrawnComboBox::Append(item
, clientData
);
195 SetItemBitmap(n
, bitmap
);
199 int wxBitmapComboBox::Insert(const wxString
& item
,
200 const wxBitmap
& bitmap
,
203 const int n
= wxOwnerDrawnComboBox::Insert(item
, pos
);
205 SetItemBitmap(n
, bitmap
);
209 int wxBitmapComboBox::Insert(const wxString
& item
, const wxBitmap
& bitmap
,
210 unsigned int pos
, void *clientData
)
212 const int n
= wxOwnerDrawnComboBox::Insert(item
, pos
, clientData
);
214 SetItemBitmap(n
, bitmap
);
218 int wxBitmapComboBox::Insert(const wxString
& item
, const wxBitmap
& bitmap
,
219 unsigned int pos
, wxClientData
*clientData
)
221 const int n
= wxOwnerDrawnComboBox::Insert(item
, pos
, clientData
);
223 SetItemBitmap(n
, bitmap
);
227 void wxBitmapComboBox::DoClear()
229 wxOwnerDrawnComboBox::DoClear();
230 wxBitmapComboBoxBase::BCBDoClear();
233 void wxBitmapComboBox::DoDeleteOneItem(unsigned int n
)
235 wxOwnerDrawnComboBox::DoDeleteOneItem(n
);
236 wxBitmapComboBoxBase::BCBDoDeleteOneItem(n
);
239 // ----------------------------------------------------------------------------
240 // wxBitmapComboBox event handlers and such
241 // ----------------------------------------------------------------------------
243 void wxBitmapComboBox::OnSize(wxSizeEvent
& event
)
245 // Prevent infinite looping
256 wxSize
wxBitmapComboBox::DoGetBestSize() const
258 wxSize sz
= wxOwnerDrawnComboBox::DoGetBestSize();
260 if ( HasFlag(wxCB_READONLY
) )
262 // Scale control to match height of highest image.
263 int h2
= m_usedImgSize
.y
+ IMAGE_SPACING_CTRL_VERTICAL
;
274 // ----------------------------------------------------------------------------
275 // wxBitmapComboBox miscellaneous
276 // ----------------------------------------------------------------------------
278 bool wxBitmapComboBox::SetFont(const wxFont
& font
)
280 bool res
= wxOwnerDrawnComboBox::SetFont(font
);
285 // ----------------------------------------------------------------------------
286 // wxBitmapComboBox item drawing and measuring
287 // ----------------------------------------------------------------------------
289 void wxBitmapComboBox::OnDrawBackground(wxDC
& dc
,
294 if ( GetCustomPaintWidth() == 0 ||
295 !(flags
& wxODCB_PAINTING_SELECTED
) ||
297 ( (flags
& wxODCB_PAINTING_CONTROL
) && (GetInternalFlags() & wxCC_FULL_BUTTON
)) )
299 wxOwnerDrawnComboBox::OnDrawBackground(dc
, rect
, item
, flags
);
303 wxBitmapComboBoxBase::DrawBackground(dc
, rect
, item
, flags
);
306 void wxBitmapComboBox::OnDrawItem(wxDC
& dc
,
312 int imgAreaWidth
= m_imgAreaWidth
;
314 if ( imgAreaWidth
== 0 )
316 wxOwnerDrawnComboBox::OnDrawItem(dc
, rect
, item
, flags
);
320 if ( flags
& wxODCB_PAINTING_CONTROL
)
323 if ( !HasFlag(wxCB_READONLY
) )
328 text
= GetString(item
);
331 wxBitmapComboBoxBase::DrawItem(dc
, rect
, item
, text
, flags
);
334 wxCoord
wxBitmapComboBox::OnMeasureItem(size_t item
) const
336 return wxBitmapComboBoxBase::MeasureItem(item
);
339 wxCoord
wxBitmapComboBox::OnMeasureItemWidth(size_t item
) const
342 GetTextExtent(GetString(item
), &x
, &y
, 0, 0);
347 #endif // defined(wxGENERIC_BITMAPCOMBOBOX)
349 #endif // wxUSE_BITMAPCOMBOBOX