// Gets displayed string representation of the value.
virtual wxString GetStringValue() const = 0;
+ // Called to check if the popup - when an item container - actually
+ // has matching item. Case-sensitivity checking etc. is up to the
+ // implementation. If the found item matched the string, but is
+ // different, it should be written back to pItem. Default implementation
+ // always return true and does not alter trueItem.
+ virtual bool FindItem(const wxString& item, wxString* trueItem=NULL);
+
// This is called to custom paint in the combo control itself (ie. not the popup).
// Default implementation draws value as string.
virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
virtual void OnComboCharEvent( wxKeyEvent& event );
virtual void OnComboDoubleClick();
virtual bool LazyCreate();
+ virtual bool FindItem(const wxString& item, wxString* trueItem);
// Item management
void SetSelection( int item );
*/
void Dismiss();
+ /**
+ Implement to customize matching of value string to an item container
+ entry.
+
+ @param item
+ String entered, usually by user or from SetValue() call.
+
+ @param trueItem
+ When item matches an entry, but the entry's string representation
+ is not exactly the same (case mismatch, for example), then the
+ true item string should be written back to here, if it is not
+ a NULL pointer.
+
+ @remarks
+ Default implementation always return true and does not alter
+ trueItem.
+ */
+ virtual bool FindItem(const wxString& item, wxString* trueItem=NULL);
+
/**
The derived class may implement this to return adjusted size for the
popup control, according to the variables given.
Useful in conjunction with LazyCreate().
*/
bool IsCreated() const;
-
+
/**
The derived class may implement this to return @true if it wants to
delay call to Create() until the popup is shown for the first time. It
{
}
+bool wxComboPopup::FindItem(const wxString& WXUNUSED(item),
+ wxString* WXUNUSED(trueItem))
+{
+ return true;
+}
+
bool wxComboPopup::LazyCreate()
{
return false;
// to set the string value here (as well as sometimes in ShowPopup).
if ( m_valueString != value )
{
- m_valueString = value;
+ bool found = true;
+ wxString trueValue = value;
+
+ // Conform to wxComboBox behavior: read-only control can only accept
+ // valid list items and empty string
+ if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() )
+ {
+ found = m_popupInterface->FindItem(value,
+ &trueValue);
+ }
- EnsurePopupControl();
+ if ( found )
+ {
+ m_valueString = trueValue;
- if (m_popupInterface)
- m_popupInterface->SetStringValue(value);
+ EnsurePopupControl();
+
+ if ( m_popupInterface )
+ m_popupInterface->SetStringValue(trueValue);
+ }
}
Refresh();
return m_strings.Index(s, bCase);
}
+bool wxVListBoxComboPopup::FindItem(const wxString& item, wxString* trueItem)
+{
+ int idx = m_strings.Index(item, false);
+ if ( idx == wxNOT_FOUND )
+ return false;
+ if ( trueItem != NULL )
+ *trueItem = m_strings[idx];
+ return true;
+}
+
unsigned int wxVListBoxComboPopup::GetCount() const
{
return m_strings.GetCount();