// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
-// RCS-ID: $Id: combobox_osx.cpp 58318 2009-01-23 08:36:16Z RR $
+// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
-#if wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+#if wxUSE_COMBOBOX && wxOSX_USE_COCOA
#include "wx/combobox.h"
#include "wx/osx/private.h"
// work in progress
-IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
-
wxComboBox::~wxComboBox()
{
}
-void wxComboBox::Init()
-{
-}
-
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxValidator& validator,
const wxString& name)
{
+ DontCreatePeer();
+
m_text = NULL;
m_choice = NULL;
-
- m_macIsUserPane = false;
-
+
if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
return false;
-
- m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() );
+
+ wxASSERT_MSG( !(style & wxCB_SORT),
+ "wxCB_SORT not currently supported by wxOSX/Cocoa");
+
+ SetPeer(wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() ));
MacPostControlCreate( pos, size );
Append(n, choices);
- // Set the first item as being selected
- if (n > 0)
+ // Set up the initial value, by default the first item is selected.
+ if ( !value.empty() )
+ SetValue(value);
+ else if (n > 0)
SetSelection( 0 );
// Needed because it is a wxControlWithItems
SetStringSelection( value );
}
-wxString wxComboBox::GetValue() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return wxEmptyString;
-}
-
-void wxComboBox::SetValue(const wxString& value)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-// Clipboard operations
-void wxComboBox::Copy()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::Cut()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::Paste()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::SetEditable(bool editable)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::SetInsertionPoint(long pos)
+int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ void **clientData, wxClientDataType type)
{
- wxFAIL_MSG("Method Not Implemented.");
-}
+ const unsigned int numItems = items.GetCount();
+ for( unsigned int i = 0; i < numItems; ++i, ++pos )
+ {
+ unsigned int idx;
-void wxComboBox::SetInsertionPointEnd()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
+ idx = pos;
+ GetComboPeer()->InsertItem( idx, items[i] );
-long wxComboBox::GetInsertionPoint() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
-}
+ if (idx > m_datas.GetCount())
+ m_datas.SetCount(idx);
+ m_datas.Insert( NULL, idx );
+ AssignNewItemClientData(idx, clientData, i, type);
+ }
-wxTextPos wxComboBox::GetLastPosition() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
-}
+ GetPeer()->SetMaximum( GetCount() );
-void wxComboBox::Replace(long from, long to, const wxString& value)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::Remove(long from, long to)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::SetSelection(long from, long to)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
- unsigned int pos,
- void **clientData, wxClientDataType type)
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
+ return pos - 1;
}
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
{
- wxFAIL_MSG("Method Not Implemented.");
+ m_datas[n] = (char*)clientData ;
}
-void* wxComboBox::DoGetItemClientData(unsigned int n) const
+void * wxComboBox::DoGetItemClientData(unsigned int n) const
{
- wxFAIL_MSG("Method Not Implemented.");
- return NULL;
+ return (void *)m_datas[n];
}
-unsigned int wxComboBox::GetCount() const
+unsigned int wxComboBox::GetCount() const
{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
+ return GetComboPeer()->GetNumberOfItems();
}
void wxComboBox::DoDeleteOneItem(unsigned int n)
{
- wxFAIL_MSG("Method Not Implemented.");
+ GetComboPeer()->RemoveItem(n);
}
void wxComboBox::DoClear()
{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-int wxComboBox::GetSelection() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
+ GetComboPeer()->Clear();
}
void wxComboBox::GetSelection(long *from, long *to) const
{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::SetSelection(int n)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-int wxComboBox::FindString(const wxString& s, bool bCase) const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
-}
-
-wxString wxComboBox::GetString(unsigned int n) const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return wxEmptyString;
-}
-
-wxString wxComboBox::GetStringSelection() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return wxEmptyString;
-}
-
-void wxComboBox::SetString(unsigned int n, const wxString& s)
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-bool wxComboBox::IsEditable() const
-{
- return !HasFlag(wxCB_READONLY);
+ wxTextEntry::GetSelection(from, to);
}
-void wxComboBox::Undo()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::Redo()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-void wxComboBox::SelectAll()
-{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-bool wxComboBox::CanCopy() const
+int wxComboBox::GetSelection() const
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ return GetComboPeer()->GetSelectedItem();
}
-bool wxComboBox::CanCut() const
+void wxComboBox::SetSelection(int n)
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ GetComboPeer()->SetSelectedItem(n);
}
-bool wxComboBox::CanPaste() const
+void wxComboBox::SetSelection(long from, long to)
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ wxTextEntry::SetSelection(from, to);
}
-bool wxComboBox::CanUndo() const
+int wxComboBox::FindString(const wxString& s, bool bCase) const
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
-}
+ if (!bCase)
+ {
+ for (unsigned i = 0; i < GetCount(); i++)
+ {
+ if (s.IsSameAs(GetString(i), false))
+ return i;
+ }
+ return wxNOT_FOUND;
+ }
-bool wxComboBox::CanRedo() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ return GetComboPeer()->FindString(s);
}
-void wxComboBox::EnableTextChangedEvents(bool enable)
+wxString wxComboBox::GetString(unsigned int n) const
{
- wxFAIL_MSG("Method Not Implemented.");
-}
+ wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" );
-void wxComboBox::WriteText(const wxString& text)
-{
- wxFAIL_MSG("Method Not Implemented.");
+ return GetComboPeer()->GetStringAtIndex(n);
}
-wxString wxComboBox::DoGetValue() const
+wxString wxComboBox::GetStringSelection() const
{
- wxFAIL_MSG("Method Not Implemented.");
- return wxEmptyString;
+ const int sel = GetSelection();
+ return sel == wxNOT_FOUND ? wxString() : GetString(sel);
}
-wxClientDataType wxComboBox::GetClientDataType() const
+void wxComboBox::SetString(unsigned int n, const wxString& s)
{
- wxFAIL_MSG("Method Not Implemented.");
- return wxClientData_None;
+ Delete(n);
+ Insert(s, n);
+ SetValue(s); // changing the item in the list won't update the display item
}
-void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType)
+void wxComboBox::EnableTextChangedEvents(bool WXUNUSED(enable))
{
- wxFAIL_MSG("Method Not Implemented.");
+ // nothing to do here, events are never generated when we change the
+ // control value programmatically anyhow by Cocoa
}
-bool wxComboBox::OSXHandleClicked( double timestampsec )
+bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
{
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
return true;
}
-#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+wxComboWidgetImpl* wxComboBox::GetComboPeer() const
+{
+ return dynamic_cast<wxComboWidgetImpl*> (GetPeer());
+}
+
+#endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA