// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-/*
- TODO:
-
- +1. typing in the text should select the string in listbox
- +2. scrollbars in listbox are unusable
- +3. the initially selected item is not selected
- ?4. kbd interface (what does GTK do?)
- 5. there is still autoscrolling without scrollbars - but is it bad?
- */
-
// ============================================================================
// declarations
// ============================================================================
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "univcombobox.h"
#endif
#include "wx/validate.h"
#endif
+#include "wx/tooltip.h"
#include "wx/popupwin.h"
#include "wx/univ/renderer.h"
3. which passes them to the popup window if it is popped up
*/
+// constants
+// ----------------------------------------------------------------------------
+
+// the margin between the text control and the combo button
+static const wxCoord g_comboMargin = 2;
+
// ----------------------------------------------------------------------------
// wxComboButton is just a normal button except that it sends commands to the
// combobox and not its parent
}
protected:
- void OnButton(wxCommandEvent& event) { m_combo->ShowPopup(); }
+ void OnButton(wxCommandEvent& WXUNUSED(event)) { m_combo->ShowPopup(); }
virtual wxSize DoGetBestClientSize() const
{
// implement wxComboPopup methods
virtual bool SetSelection(const wxString& value);
+ virtual void SetSelection(int n, bool select)
+ { wxListBox::SetSelection( n, select); };
virtual wxControl *GetControl() { return this; }
virtual void OnShow();
+ virtual wxCoord GetBestWidth() const;
protected:
// we shouldn't return height too big from here
EVT_TEXT(-1, wxComboTextCtrl::OnText)
END_EVENT_TABLE()
-IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl);
+IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
// ============================================================================
// implementation
// ----------------------------------------------------------------------------
void wxComboControl::DoSetSize(int x, int y,
- int width, int height,
+ int width, int WXUNUSED(height),
int sizeFlags)
{
// combo height is always fixed
{
wxSize sizeBtn = m_btn->GetBestSize(),
sizeText = m_text->GetBestSize();
+ wxCoord widthPopup = 0;
- return wxSize(sizeBtn.x + sizeText.x, wxMax(sizeBtn.y, sizeText.y));
+ if (m_popup)
+ {
+ widthPopup = m_popup->GetBestWidth();
+ }
+
+ return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup),
+ wxMax(sizeBtn.y, sizeText.y));
}
void wxComboControl::DoMoveWindow(int x, int y, int width, int height)
return TRUE;
}
+#if wxUSE_TOOLTIPS
+void wxComboControl::DoSetToolTip(wxToolTip *tooltip)
+{
+ wxControl::DoSetToolTip(tooltip);
+
+ // Set tool tip for button and text box
+ if (m_text && m_btn)
+ {
+ if (tooltip)
+ {
+ const wxString &tip = tooltip->GetTip();
+ m_text->SetToolTip(tip);
+ m_btn->SetToolTip(tip);
+ }
+ else
+ {
+ m_text->SetToolTip(NULL);
+ m_btn->SetToolTip(NULL);
+ }
+ }
+}
+#endif // wxUSE_TOOLTIPS
+
// ----------------------------------------------------------------------------
// popup window handling
// ----------------------------------------------------------------------------
}
}
+wxCoord wxComboListBox::GetBestWidth() const
+{
+ wxSize size = wxListBox::GetBestSize();
+ return size.x;
+}
+
wxSize wxComboListBox::DoGetBestClientSize() const
{
// don't return size too big or we risk to not fit on the screen
m_lbox = (wxListBox *)NULL;
}
+wxComboBox::wxComboBox(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ const wxArrayString& choices,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ Init();
+
+ Create(parent, id, value, pos, size, choices, style, validator, name);
+}
+
+bool wxComboBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ const wxArrayString& choices,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ wxCArrayString chs(choices);
+
+ return Create(parent, id, value, pos, size, chs.GetCount(),
+ chs.GetStrings(), style, validator, name);
+}
+
bool wxComboBox::Create(wxWindow *parent,
wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
int n,
- const wxString *choices,
+ const wxString choices[],
long style,
const wxValidator& validator,
const wxString& name)
void wxComboBox::Clear()
{
GetLBox()->Clear();
+ GetText()->SetValue(wxEmptyString);
}
void wxComboBox::Delete(int n)
{
+ wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Delete") );
+
+ if (GetSelection() == n)
+ GetText()->SetValue(wxEmptyString);
+
GetLBox()->Delete(n);
}
wxString wxComboBox::GetString(int n) const
{
+ wxCHECK_MSG( (n >= 0) && (n < GetCount()), 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") );
+
GetLBox()->SetString(n, s);
}
void wxComboBox::Select(int n)
{
- wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid combobox index") );
+ wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Select") );
GetLBox()->SetSelection(n);
GetText()->SetValue(GetLBox()->GetString(n));
int wxComboBox::GetSelection() const
{
+#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
+ // in the list that it is the item that is selected!
return FindString(GetText()->GetValue());
+#endif
}
int wxComboBox::DoAppend(const wxString& item)
return GetLBox()->Append(item);
}
+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"));
+
+ if (pos == GetCount())
+ return DoAppend(item);
+
+ GetLBox()->Insert(item, pos);
+ return pos;
+}
+
void wxComboBox::DoSetItemClientData(int n, void* clientData)
{
GetLBox()->SetClientData(n, clientData);