Added wxComboPopup::FindItem() to help in deciding how SetValue() should change the value of a read-only wxComboCtrl. This allows wxOwnerDrawnComboBox to have the same behavior as wxComboBox in that respect.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -774,6 +774,13 @@ public:
|
|||||||
// Gets displayed string representation of the value.
|
// Gets displayed string representation of the value.
|
||||||
virtual wxString GetStringValue() const = 0;
|
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).
|
// This is called to custom paint in the combo control itself (ie. not the popup).
|
||||||
// Default implementation draws value as string.
|
// Default implementation draws value as string.
|
||||||
virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
|
virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
|
||||||
|
@@ -93,6 +93,7 @@ public:
|
|||||||
virtual void OnComboCharEvent( wxKeyEvent& event );
|
virtual void OnComboCharEvent( wxKeyEvent& event );
|
||||||
virtual void OnComboDoubleClick();
|
virtual void OnComboDoubleClick();
|
||||||
virtual bool LazyCreate();
|
virtual bool LazyCreate();
|
||||||
|
virtual bool FindItem(const wxString& item, wxString* trueItem);
|
||||||
|
|
||||||
// Item management
|
// Item management
|
||||||
void SetSelection( int item );
|
void SetSelection( int item );
|
||||||
|
@@ -41,6 +41,25 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Dismiss();
|
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
|
The derived class may implement this to return adjusted size for the
|
||||||
popup control, according to the variables given.
|
popup control, according to the variables given.
|
||||||
|
@@ -590,6 +590,12 @@ void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxComboPopup::FindItem(const wxString& WXUNUSED(item),
|
||||||
|
wxString* WXUNUSED(trueItem))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxComboPopup::LazyCreate()
|
bool wxComboPopup::LazyCreate()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -2575,12 +2581,26 @@ void wxComboCtrlBase::OnSetValue(const wxString& value)
|
|||||||
// to set the string value here (as well as sometimes in ShowPopup).
|
// to set the string value here (as well as sometimes in ShowPopup).
|
||||||
if ( m_valueString != value )
|
if ( m_valueString != value )
|
||||||
{
|
{
|
||||||
m_valueString = value;
|
bool found = true;
|
||||||
|
wxString trueValue = value;
|
||||||
|
|
||||||
EnsurePopupControl();
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_popupInterface)
|
if ( found )
|
||||||
m_popupInterface->SetStringValue(value);
|
{
|
||||||
|
m_valueString = trueValue;
|
||||||
|
|
||||||
|
EnsurePopupControl();
|
||||||
|
|
||||||
|
if ( m_popupInterface )
|
||||||
|
m_popupInterface->SetStringValue(trueValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
|
@@ -642,6 +642,16 @@ int wxVListBoxComboPopup::FindString(const wxString& s, bool bCase) const
|
|||||||
return m_strings.Index(s, bCase);
|
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
|
unsigned int wxVListBoxComboPopup::GetCount() const
|
||||||
{
|
{
|
||||||
return m_strings.GetCount();
|
return m_strings.GetCount();
|
||||||
|
Reference in New Issue
Block a user