]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/combobox.mm
Fit the generic preferences editor dialog to its pages size initially.
[wxWidgets.git] / src / cocoa / combobox.mm
index 9be77501acda5c54c921d86df919f19e0dc93162..f9d8da8edf0b00a31de13a99f3699f422163affb 100644 (file)
@@ -6,13 +6,13 @@
 // Created:     2005/02/16
 // RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 //
 // Impl notes:
 // There is no custom data source because doing so unnecessarily sacrifices
-// some native autocompletion behavior (we would have to make our own -
+// some native autocompletion behaviour (we would have to make our own -
 // the SimpleComboBox sample does so in the developer folder that
 // comes with OSX).  One reason you might want this would be to have
 // only one array or be able to display numbers returned by an NSNumber
 
 #if wxUSE_COMBOBOX
 
+#include "wx/combobox.h"
+
+#include "wx/cocoa/objc/objc_uniquifying.h"
+
 #ifndef WX_PRECOMP
     #include "wx/window.h"
+    #include "wx/log.h"
+    #include "wx/app.h"
 #endif // WX_PRECOMP
 
-#include "wx/cocoa/ObjcPose.h"
-#include "wx/combobox.h"
-
 #import <AppKit/NSComboBox.h>
 #import <Foundation/NSNotification.h>
 #import <Foundation/NSString.h>
@@ -131,6 +134,7 @@ void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox)
 - (void)comboBoxWillDismiss:(NSNotification *)notification;
 - (void)comboBoxWillPopUp:(NSNotification *)notification;
 @end // wxPoserNSComboBox
+WX_DECLARE_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox)
 
 //WX_IMPLEMENT_POSER(wxPoserNSComboBox);
 @implementation wxPoserNSComboBox : NSComboBox
@@ -157,20 +161,17 @@ void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox)
 }
 
 @end // implementation wxPoserNSComboBox
-
-#include "wx/app.h"
-#include "wx/combobox.h"
-#include "wx/log.h"
+WX_IMPLEMENT_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox)
 
 #include "wx/cocoa/autorelease.h"
 #include "wx/cocoa/string.h"
 
 #import <AppKit/NSComboBox.h>
 
-IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxTextCtrl)
-BEGIN_EVENT_TABLE(wxComboBox, wxTextCtrl)
+BEGIN_EVENT_TABLE(wxComboBox, wxControl)
 END_EVENT_TABLE()
 WX_IMPLEMENT_COCOA_OWNER(wxComboBox,NSComboBox,NSTextField,NSView)
+WX_IMPLEMENT_COCOA_OWNER(wxComboBox,NSTextField,NSControl,NSView)
 
 bool wxComboBox::Create(wxWindow *parent, wxWindowID winid,
             const wxString& value,
@@ -201,7 +202,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID winid,
         return false;
 
     m_cocoaNSView = NULL;
-    SetNSComboBox([[wxPoserNSComboBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
+    SetNSComboBox([[WX_GET_OBJC_CLASS(wxPoserNSComboBox) alloc] initWithFrame:MakeDefaultNSRect(size)]);
     [m_cocoaNSView release];
     [GetNSTextField() setStringValue:wxNSStringWithWxString(value.c_str())];
     [GetNSControl() sizeToFit];
@@ -209,8 +210,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID winid,
         m_parent->CocoaAddChild(this);
     SetInitialFrameRect(pos,size);
 
-    for(int i = 0; i < n; ++i)
-        wxComboBox::DoAppend(choices[i]);
+    wxComboBox::Append(n, choices);
 
     [GetNSComboBox() setCompletes:true]; //autocomplete :)
 
@@ -228,14 +228,14 @@ void wxComboBox::doWxEvent(int nEvent)
     event2.SetInt(GetSelection());
     event2.SetEventObject(this);
     event2.SetString(GetStringSelection());
-    GetEventHandler()->ProcessEvent(event2);
+    HandleWindowEvent(event2);
 
     // For consistency with MSW and GTK, also send a text updated event
     // After all, the text is updated when a selection is made
     wxCommandEvent TextEvent( wxEVT_COMMAND_TEXT_UPDATED, GetId() );
     TextEvent.SetString( GetStringSelection() );
     TextEvent.SetEventObject( this );
-    GetEventHandler()->ProcessEvent( TextEvent );
+    HandleWindowEvent( TextEvent );
 }
 
 
@@ -249,29 +249,29 @@ wxString wxComboBox::GetStringSelection()
     return wxStringWithNSString([GetNSComboBox() objectValueOfSelectedItem]);
 }
 
-void wxComboBox::Clear()
+void wxComboBox::DoClear()
 {
     [GetNSComboBox() removeAllItems];
     m_Datas.Clear();
 }
 
-void wxComboBox::Delete(int nIndex)
+void wxComboBox::DoDeleteOneItem(unsigned int n)
 {
-    [GetNSComboBox() removeItemAtIndex:nIndex];
-    m_Datas.RemoveAt(nIndex);
+    [GetNSComboBox() removeItemAtIndex:n];
+    m_Datas.RemoveAt(n);
 }
 
-size_t wxComboBox::GetCount() const
+unsigned int wxComboBox::GetCount() const
 {
-    return (size_t)[GetNSComboBox() numberOfItems];
+    return (unsigned int)[GetNSComboBox() numberOfItems];
 }
 
-wxString wxComboBox::GetString(int nIndex) const
+wxString wxComboBox::GetString(unsigned int nIndex) const
 {
     return wxStringWithNSString([GetNSComboBox() itemObjectValueAtIndex:nIndex]);
 }
 
-void wxComboBox::SetString(int nIndex, const wxString& szString)
+void wxComboBox::SetString(unsigned int nIndex, const wxString& szString)
 {
     wxAutoNSAutoreleasePool pool;
     //FIXME:  There appears to be no "set item data" method - maybe
@@ -291,40 +291,119 @@ int wxComboBox::GetSelection() const
     return [GetNSComboBox() indexOfSelectedItem];
 }
 
-int wxComboBox::DoAppend(const wxString& szItem)
+int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
+                              unsigned int pos,
+                              void **clientData,
+                              wxClientDataType type)
 {
-    m_Datas.Add(NULL);
     wxAutoNSAutoreleasePool pool;
-    [GetNSComboBox() addItemWithObjectValue:wxNSStringWithWxString(szItem)];
-    return [GetNSComboBox() numberOfItems];
+    const unsigned int numITems = items.GetCount();
+    for ( unsigned int i = 0; i < numITems; ++i, ++pos )
+    {
+        [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(items[i]) atIndex:(pos)];
+        m_Datas.Insert(NULL, pos);
+        AssignNewItemClientData(pos, clientData, i, type);
+    }
+    return pos - 1;
+}
+
+void wxComboBox::DoSetItemClientData(unsigned int nIndex, void* pData)
+{
+    m_Datas[nIndex] = pData;
+}
+
+void* wxComboBox::DoGetItemClientData(unsigned int nIndex) const
+{
+    return m_Datas[nIndex];
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// wxTextEntry virtual implementations:
+
+void wxComboBox::WriteText(wxString const&)
+{
 }
 
-int wxComboBox::DoInsert(const wxString& szItem, int nIndex)
+wxString wxComboBox::GetValue() const
 {
-    m_Datas.Insert(NULL, nIndex);
     wxAutoNSAutoreleasePool pool;
-    [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(szItem) atIndex:nIndex];
-    return nIndex;
+    return wxStringWithNSString([GetNSTextField() stringValue]);
 }
 
-void wxComboBox::DoSetItemClientData(int nIndex, void* pData)
+void wxComboBox::Remove(long, long)
 {
-    m_Datas[nIndex] = pData;
 }
 
-void* wxComboBox::DoGetItemClientData(int nIndex) const
+void wxComboBox::Cut()
 {
-    return m_Datas[nIndex];
 }
 
-void wxComboBox::DoSetItemClientObject(int nIndex, wxClientData* pClientData)
+void wxComboBox::Copy()
+{
+}
+
+void wxComboBox::Paste()
+{
+}
+
+void wxComboBox::Undo()
+{
+}
+
+void wxComboBox::Redo()
+{
+}
+
+bool wxComboBox::CanUndo() const
+{
+    return false;
+}
+
+bool wxComboBox::CanRedo() const
+{
+    return false;
+}
+
+void wxComboBox::SetInsertionPoint(long)
+{
+}
+
+long wxComboBox::GetInsertionPoint() const
+{
+    return 0;
+}
+
+wxTextPos wxComboBox::GetLastPosition() const
 {
-    m_Datas[nIndex] = (void*) pClientData;
+    // working - returns the size of the wxString
+    return (long)(GetValue().Len());
 }
 
-wxClientData* wxComboBox::DoGetItemClientObject(int nIndex) const
+void wxComboBox::SetSelection(long, long)
 {
-    return (wxClientData*) m_Datas[nIndex];
 }
 
-#endif //wxUSE_COMBOBOX
+void wxComboBox::GetSelection(long*, long*) const
+{
+}
+
+bool wxComboBox::IsEditable() const
+{
+    return [GetNSTextField() isEditable];
+}
+
+void wxComboBox::SetEditable(bool editable)
+{
+    // first ensure that the current value is stored (in case the user had not finished editing
+    // before SetEditable(FALSE) was called)
+    DoSetValue(GetValue(),1);
+
+    [GetNSTextField() setEditable: editable];
+
+    // forces the focus on the textctrl to be lost - while focus is still maintained
+    // after SetEditable(FALSE) the user may still edit the control
+    // (might not the best way to do this..)
+    [GetNSTextField() abortEditing];
+}
+
+#endif // wxUSE_COMBOBOX