// 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.");
+ m_datas.RemoveAt(n);
+ GetComboPeer()->RemoveItem(n);
}
void wxComboBox::DoClear()
{
- wxFAIL_MSG("Method Not Implemented.");
-}
-
-int wxComboBox::GetSelection() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return 0;
+ m_datas.Clear();
+ 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()
+int wxComboBox::GetSelection() const
{
- wxFAIL_MSG("Method Not Implemented.");
+ return GetComboPeer()->GetSelectedItem();
}
-void wxComboBox::Redo()
+void wxComboBox::SetSelection(int n)
{
- wxFAIL_MSG("Method Not Implemented.");
+ GetComboPeer()->SetSelectedItem(n);
}
-void wxComboBox::SelectAll()
+void wxComboBox::SetSelection(long from, long to)
{
- wxFAIL_MSG("Method Not Implemented.");
+ wxTextEntry::SetSelection(from, to);
}
-bool wxComboBox::CanCopy() 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::CanCut() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ return GetComboPeer()->FindString(s);
}
-bool wxComboBox::CanPaste() const
+wxString wxComboBox::GetString(unsigned int n) const
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
-}
+ wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" );
-bool wxComboBox::CanUndo() const
-{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ return GetComboPeer()->GetStringAtIndex(n);
}
-bool wxComboBox::CanRedo() const
+wxString wxComboBox::GetStringSelection() const
{
- wxFAIL_MSG("Method Not Implemented.");
- return false;
+ const int sel = GetSelection();
+ return sel == wxNOT_FOUND ? wxString() : GetString(sel);
}
-void wxComboBox::EnableTextChangedEvents(bool enable)
+void wxComboBox::SetString(unsigned int n, const wxString& s)
{
- wxFAIL_MSG("Method Not Implemented.");
+ // Notice that we shouldn't delete and insert the item in this control
+ // itself as this would also affect the client data which we need to
+ // preserve here.
+ GetComboPeer()->RemoveItem(n);
+ GetComboPeer()->InsertItem(n, s);
+ SetValue(s); // changing the item in the list won't update the display item
}
-void wxComboBox::WriteText(const wxString& text)
+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
}
-wxString wxComboBox::DoGetValue() const
+bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
{
- wxFAIL_MSG("Method Not Implemented.");
- return wxEmptyString;
+ wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
+ event.SetInt(GetSelection());
+ event.SetEventObject(this);
+ event.SetString(GetStringSelection());
+ ProcessCommand(event);
+ return true;
}
-wxClientDataType wxComboBox::GetClientDataType() const
+wxComboWidgetImpl* wxComboBox::GetComboPeer() const
{
- wxFAIL_MSG("Method Not Implemented.");
- return wxClientData_None;
+ return dynamic_cast<wxComboWidgetImpl*> (GetPeer());
}
-void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType)
+void wxComboBox::Popup()
{
- wxFAIL_MSG("Method Not Implemented.");
+ GetComboPeer()->Popup();
}
-bool wxComboBox::OSXHandleClicked( double timestampsec )
+void wxComboBox::Dismiss()
{
- wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
- event.SetInt(GetSelection());
- event.SetEventObject(this);
- event.SetString(GetStringSelection());
- ProcessCommand(event);
- return true;
+ GetComboPeer()->Dismiss();
}
-#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+#endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA