/////////////////////////////////////////////////////////////////////////////
-// Name: src/msw/bmpcboxg.cpp
+// Name: src/msw/bmpcbox.cpp
// Purpose: wxBitmapComboBox
// Author: Jaakko Salli
// Created: 2008-04-06
-// RCS-ID: $Id:$
+// RCS-ID: $Id$
// Copyright: (c) 2008 Jaakko Salli
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#endif
#include "wx/settings.h"
+#include "wx/vector.h"
#include "wx/msw/dcclient.h"
#include "wx/msw/private.h"
wxString value = GetValue();
wxPoint pos = GetPosition();
wxSize size = GetSize();
- wxArrayString strings = GetStrings();
+ size.y = GetBestSize().y;
+ const wxArrayString strings = GetStrings();
+ const unsigned numItems = strings.size();
+ unsigned i;
+
+ // Save the client data pointers before clearing the control, if any.
+ const wxClientDataType clientDataType = GetClientDataType();
+ wxVector<wxClientData*> objectClientData;
+ wxVector<void*> voidClientData;
+ switch ( clientDataType )
+ {
+ case wxClientData_None:
+ break;
+
+ case wxClientData_Object:
+ objectClientData.reserve(numItems);
+ for ( i = 0; i < numItems; ++i )
+ objectClientData.push_back(GetClientObject(i));
+ break;
+
+ case wxClientData_Void:
+ voidClientData.reserve(numItems);
+ for ( i = 0; i < numItems; ++i )
+ voidClientData.push_back(GetClientData(i));
+ break;
+ }
wxComboBox::DoClear();
DissociateHandle();
::DestroyWindow(hwnd);
- if ( !MSWCreateControl(wxT("COMBOBOX"), value, pos, size) )
+ if ( !MSWCreateControl(wxT("COMBOBOX"), wxEmptyString, pos, size) )
return;
// initialize the controls contents
- for ( unsigned int i = 0; i < strings.size(); i++ )
+ for ( i = 0; i < numItems; i++ )
{
wxComboBox::Append(strings[i]);
+
+ if ( !objectClientData.empty() )
+ SetClientObject(i, objectClientData[i]);
+ else if ( !voidClientData.empty() )
+ SetClientData(i, objectClientData[i]);
}
// and make sure it has the same attributes as before
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
}
+
+ ::SendMessage(GetHwnd(), CB_SETITEMHEIGHT, 0, MeasureItem(0));
+
+ // Revert the old string value
+ if ( !HasFlag(wxCB_READONLY) )
+ ChangeValue(value);
}
wxBitmapComboBox::~wxBitmapComboBox()
Clear();
}
+wxSize wxBitmapComboBox::DoGetBestSize() const
+{
+ wxSize best = wxComboBox::DoGetBestSize();
+ wxSize bitmapSize = GetBitmapSize();
+
+ wxCoord useHeightBitmap = EDIT_HEIGHT_FROM_CHAR_HEIGHT(bitmapSize.y);
+ if ( best.y < useHeightBitmap )
+ {
+ best.y = useHeightBitmap;
+ CacheBestSize(best);
+ }
+ return best;
+}
+
// ----------------------------------------------------------------------------
// Item manipulation
// ----------------------------------------------------------------------------
return n;
}
+int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap,
+ unsigned int pos, void *clientData)
+{
+ OnAddBitmap(bitmap);
+ const int n = wxComboBox::Insert(item, pos, clientData);
+ if ( n != wxNOT_FOUND )
+ DoSetItemBitmap(n, bitmap);
+ return n;
+}
+
int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap,
unsigned int pos, wxClientData *clientData)
{
const unsigned int numItems = items.GetCount();
const unsigned int countNew = GetCount() + numItems;
+ wxASSERT( numItems == 1 || !HasFlag(wxCB_SORT) ); // Sanity check
+
m_bitmaps.Alloc(countNew);
for ( unsigned int i = 0; i < numItems; i++ )
for ( int i = numItems-1; i >= 0; i-- )
BCBDoDeleteOneItem(pos + i);
}
+ else if ( ((unsigned int)index) != pos )
+ {
+ // Move pre-inserted empty bitmap into correct position
+ // (usually happens when combo box has wxCB_SORT style)
+ wxBitmap* bmp = static_cast<wxBitmap*>(m_bitmaps[pos]);
+ m_bitmaps.RemoveAt(pos);
+ m_bitmaps.Insert(bmp, index);
+ }
return index;
}
return true;
}
-
+
return false;
}
if ( pos == -1 )
return FALSE;
- int flags = 0;
+ int flags = 0;
if ( lpDrawItem->itemState & ODS_COMBOBOXEDIT )
flags |= wxODCB_PAINTING_CONTROL;
if ( lpDrawItem->itemState & ODS_SELECTED )