]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/odcombo.cpp
Avoid an assert if no alignment style is specified
[wxWidgets.git] / src / generic / odcombo.cpp
index eb126c330fa3a1a6a8473c1b1fd27b073d908e40..f19b8309d04391eab992de737e88e9f5a6a5bf62 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        odcombo.cpp
+// Name:        src/generic/odcombo.cpp
 // Purpose:     wxOwnerDrawnComboBox, wxVListBoxComboPopup
 // Author:      Jaakko Salli
 // Modified by:
@@ -23,7 +23,9 @@
     #pragma hdrstop
 #endif
 
-#if wxUSE_OWNERDRAWNCOMBOBOX
+#if wxUSE_ODCOMBOBOX
+
+#include "wx/odcombo.h"
 
 #ifndef WX_PRECOMP
     #include "wx/log.h"
@@ -34,8 +36,6 @@
 #endif
 
 #include "wx/combo.h"
-#include "wx/odcombo.h"
-
 
 // ============================================================================
 // implementation
@@ -56,8 +56,6 @@ END_EVENT_TABLE()
 
 
 void wxVListBoxComboPopup::Init()
-/*                                           : wxVListBox(),
-                                             wxComboPopup(combo)*/
 {
     m_widestWidth = 0;
     m_avgCharWidth = 0;
@@ -132,11 +130,6 @@ void wxVListBoxComboPopup::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) co
 
 wxCoord wxVListBoxComboPopup::OnMeasureItem(size_t WXUNUSED(n)) const
 {
-    /*
-    int itemHeight = m_combo->OnMeasureListItem(n);
-    if ( itemHeight < 0 )
-        itemHeight = m_itemHeight;
-    */
     return m_itemHeight;
 }
 
@@ -234,16 +227,6 @@ bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate )
     {
         value-=10;
     }
-    /*
-    else if ( keycode == WXK_END )
-    {
-        value = itemCount-1;
-    }
-    else if ( keycode == WXK_HOME )
-    {
-        value = 0;
-    }
-    */
     else
         return false;
 
@@ -401,6 +384,8 @@ void wxVListBoxComboPopup::Clear()
 
     ClearClientDatas();
 
+    m_value = wxNOT_FOUND;
+
     if ( IsCreated() )
         wxVListBox::SetItemCount(0);
 }
@@ -453,9 +438,9 @@ void wxVListBoxComboPopup::Delete( unsigned int item )
         wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
 }
 
-int wxVListBoxComboPopup::FindString(const wxString& s) const
+int wxVListBoxComboPopup::FindString(const wxString& s, bool bCase) const
 {
-    return m_strings.Index(s);
+    return m_strings.Index(s, bCase);
 }
 
 unsigned int wxVListBoxComboPopup::GetCount() const
@@ -482,9 +467,8 @@ wxString wxVListBoxComboPopup::GetStringValue() const
 
 void wxVListBoxComboPopup::SetSelection( int item )
 {
-    // This seems to be necessary (2.5.3 w/ MingW atleast)
-    if ( item < -1 || item >= (int)m_strings.GetCount() )
-        item = -1;
+    wxCHECK_RET( item == wxNOT_FOUND || ((unsigned int)item < GetCount()),
+                 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
 
     m_value = item;
 
@@ -575,11 +559,11 @@ void wxVListBoxComboPopup::Populate( const wxArrayString& choices )
 // ----------------------------------------------------------------------------
 
 
-BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox, wxComboControl)
+BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox, wxComboCtrl)
 END_EVENT_TABLE()
 
 
-IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox, wxComboControl, wxControlWithItems)
+IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox, wxComboCtrl, wxControlWithItems)
 
 void wxOwnerDrawnComboBox::Init()
 {
@@ -595,7 +579,7 @@ bool wxOwnerDrawnComboBox::Create(wxWindow *parent,
                                   const wxValidator& validator,
                                   const wxString& name)
 {
-    return wxComboControl::Create(parent,id,value,pos,size,style,validator,name);
+    return wxComboCtrl::Create(parent,id,value,pos,size,style,validator,name);
 }
 
 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent,
@@ -607,7 +591,7 @@ wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent,
                                            long style,
                                            const wxValidator& validator,
                                            const wxString& name)
-    : wxComboControl()
+    : wxComboCtrl()
 {
     Init();
 
@@ -671,7 +655,7 @@ void wxOwnerDrawnComboBox::SetPopupControl( wxComboPopup* popup )
         popup = new wxVListBoxComboPopup();
     }
 
-    wxComboControl::SetPopupControl(popup);
+    wxComboCtrl::SetPopupControl(popup);
 
     wxASSERT(popup);
     m_popupInterface = (wxVListBoxComboPopup*) popup;
@@ -695,12 +679,12 @@ void wxOwnerDrawnComboBox::Clear()
 
     m_popupInterface->Clear();
 
-    GetTextCtrl()->SetValue(wxEmptyString);
+    SetValue(wxEmptyString);
 }
 
 void wxOwnerDrawnComboBox::Delete(unsigned int n)
 {
-    wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
+    wxCHECK_RET( IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
 
     if ( GetSelection() == (int) n )
         SetValue(wxEmptyString);
@@ -716,25 +700,25 @@ unsigned int wxOwnerDrawnComboBox::GetCount() const
 
 wxString wxOwnerDrawnComboBox::GetString(unsigned int n) const
 {
-    wxCHECK_MSG( (n >= 0) && (n < GetCount()), wxEmptyString, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
+    wxCHECK_MSG( IsValid(n), wxEmptyString, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
     return m_popupInterface->GetString(n);
 }
 
 void wxOwnerDrawnComboBox::SetString(unsigned int n, const wxString& s)
 {
-    wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
+    wxCHECK_RET( IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
     m_popupInterface->SetString(n,s);
 }
 
-int wxOwnerDrawnComboBox::FindString(const wxString& s) const
+int wxOwnerDrawnComboBox::FindString(const wxString& s, bool bCase) const
 {
     wxASSERT_MSG( m_popupInterface, wxT("no popup interface") );
-    return m_popupInterface->FindString(s);
+    return m_popupInterface->FindString(s, bCase);
 }
 
 void wxOwnerDrawnComboBox::Select(int n)
 {
-    wxCHECK_RET( (n >= -1) && (n < (int)GetCount()), _T("invalid index in wxOwnerDrawnComboBox::Select") );
+    wxCHECK_RET( (n == wxNOT_FOUND) || IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::Select") );
     EnsurePopupControl();
 
     m_popupInterface->SetSelection(n);
@@ -768,7 +752,7 @@ int wxOwnerDrawnComboBox::DoAppend(const wxString& item)
 int wxOwnerDrawnComboBox::DoInsert(const wxString& item, unsigned int pos)
 {
     wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
-    wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
+    wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index"));
 
     EnsurePopupControl();
     m_popupInterface->Insert(item,pos);
@@ -798,4 +782,4 @@ wxClientData* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n) const
     return (wxClientData*) DoGetItemClientData(n);
 }
 
-#endif // wxUSE_OWNERDRAWNCOMBOBOX
+#endif // wxUSE_ODCOMBOBOX