/////////////////////////////////////////////////////////////////////////////
-// Name: univ/combobox.cpp
+// Name: src/univ/combobox.cpp
// Purpose: wxComboControl and wxComboBox implementation
// Author: Vadim Zeitlin
// Modified by:
// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "univcombobox.h"
-#endif
-
#include "wx/wxprec.h"
#ifdef __BORLANDC__
virtual ~wxComboListBox();
// implement wxComboPopup methods
- virtual bool SetSelection(const wxString& value);
- virtual void SetSelection(int n, bool select)
- { wxListBox::SetSelection( n, select); };
+ virtual bool SetSelection(const wxString& s);
virtual wxControl *GetControl() { return this; }
virtual void OnShow();
virtual wxCoord GetBestWidth() const;
+ // fix virtual function hiding
+ virtual void SetSelection(int n) { DoSetSelection(n, true); }
+ void SetSelection(int n, bool select) { DoSetSelection(n, select); }
+
+ // used to process wxUniv actions
+ bool PerformAction(const wxControlAction& action,
+ long numArg,
+ const wxString& strArg);
+
protected:
// we shouldn't return height too big from here
virtual wxSize DoGetBestClientSize() const;
// called whenever the user selects or activates a listbox item
void OnSelect(wxCommandEvent& event);
- // used to process wxUniv actions
- bool PerformAction(const wxControlAction& action,
- long numArg,
- const wxString& strArg);
-
private:
// has the mouse been released on this control?
bool m_clicked;
widthPopup = m_popup->GetBestWidth();
}
- return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup),
+ return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup),
wxMax(sizeBtn.y, sizeText.y));
}
#if wxUSE_TOOLTIPS
void wxComboControl::DoSetToolTip(wxToolTip *tooltip)
{
- wxControl::DoSetToolTip(tooltip);
+ wxControl::DoSetToolTip(tooltip);
// Set tool tip for button and text box
if (m_text && m_btn)
// always matches), but we want to show the first one in such case
if ( value.empty() )
{
- if ( GetCount() )
+ if ( GetCount() > 0 )
{
wxListBox::SetSelection(0);
}
event2.SetId(m_combo->GetId());
m_combo->ProcessEvent(event2);
}
- //else: ignore the events resultign from just moving the mouse initially
+ //else: ignore the events resulting from just moving the mouse initially
}
void wxComboListBox::OnShow()
// while a wxComboListBox is shown, it always has capture, so if it doesn't
// we're about to go away anyhow (normally this shouldn't happen at all,
// but I don't put assert here as it just might do on other platforms and
- // it doesn't break anythign anyhow)
+ // it doesn't break anything anyhow)
if ( this == wxWindow::GetCapture() )
{
if ( HitTest(event.GetPosition()) == wxHT_WINDOW_INSIDE )
return GetText()->GetInsertionPoint();
}
-long wxComboBox::GetLastPosition() const
+wxTextPos wxComboBox::GetLastPosition() const
{
return GetText()->GetLastPosition();
}
void wxComboBox::Delete(int n)
{
- wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Delete") );
+ wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::Delete") );
if (GetSelection() == n)
GetText()->SetValue(wxEmptyString);
GetLBox()->Delete(n);
}
-int wxComboBox::GetCount() const
+size_t wxComboBox::GetCount() const
{
return GetLBox()->GetCount();
}
wxString wxComboBox::GetString(int n) const
{
- wxCHECK_MSG( (n >= 0) && (n < GetCount()), wxEmptyString, _T("invalid index in wxComboBox::GetString") );
+ wxCHECK_MSG( IsValid(n), wxEmptyString, _T("invalid index in wxComboBox::GetString") );
return GetLBox()->GetString(n);
}
void wxComboBox::SetString(int n, const wxString& s)
{
- wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::SetString") );
+ wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::SetString") );
GetLBox()->SetString(n, s);
}
-int wxComboBox::FindString(const wxString& s) const
+int wxComboBox::FindString(const wxString& s, bool bCase) const
{
- return GetLBox()->FindString(s);
+ return GetLBox()->FindString(s, bCase);
}
-void wxComboBox::Select(int n)
+void wxComboBox::SetSelection(int n)
{
- wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Select") );
+ wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::Select") );
GetLBox()->SetSelection(n);
GetText()->SetValue(GetLBox()->GetString(n));
#if 1 // FIXME:: What is the correct behavior?
// if the current value isn't one of the listbox strings, return -1
return GetLBox()->GetSelection();
-#else
- // Why oh why is this done this way?
- // It is not because the value displayed in the text can be found
+#else
+ // Why oh why is this done this way?
+ // It is not because the value displayed in the text can be found
// in the list that it is the item that is selected!
return FindString(GetText()->GetValue());
#endif
int wxComboBox::DoInsert(const wxString& item, 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"));
- if (pos == GetCount())
+ if ((size_t)pos == GetCount())
return DoAppend(item);
GetLBox()->Insert(item, pos);
return GetLBox()->GetClientObject(n);
}
+bool wxComboBox::IsEditable() const
+{
+ return GetText() != NULL && (!HasFlag(wxCB_READONLY) || GetText()->IsEditable());
+}
+
+void wxComboBox::Undo()
+{
+ if (IsEditable())
+ GetText()->Undo();
+}
+
+void wxComboBox::Redo()
+{
+ if (IsEditable())
+ GetText()->Redo();
+}
+
+void wxComboBox::SelectAll()
+{
+ GetText()->SelectAll();
+}
+
+bool wxComboBox::CanCopy() const
+{
+ if (GetText() != NULL)
+ return GetText()->CanCopy();
+ else
+ return false;
+}
+
+bool wxComboBox::CanCut() const
+{
+ if (GetText() != NULL)
+ return GetText()->CanCut();
+ else
+ return false;
+}
+
+bool wxComboBox::CanPaste() const
+{
+ if (IsEditable())
+ return GetText()->CanPaste();
+ else
+ return false;
+}
+
+bool wxComboBox::CanUndo() const
+{
+ if (IsEditable())
+ return GetText()->CanUndo();
+ else
+ return false;
+}
+
+bool wxComboBox::CanRedo() const
+{
+ if (IsEditable())
+ return GetText()->CanRedo();
+ else
+ return false;
+}
+
+
// ----------------------------------------------------------------------------
// input handling
// ----------------------------------------------------------------------------