]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement native OS X ComboBox for OS X Cocoa, and implement wxTextEntry methods...
authorKevin Ollivier <kevino@theolliviers.com>
Sat, 9 Jan 2010 19:50:55 +0000 (19:50 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Sat, 9 Jan 2010 19:50:55 +0000 (19:50 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
build/bakefiles/files.bkl
include/wx/osx/cocoa/private/textimpl.h
include/wx/osx/combobox.h
include/wx/osx/core/private.h
include/wx/osx/textctrl.h
include/wx/osx/textentry.h [new file with mode: 0644]
include/wx/textentry.h
src/osx/carbon/combobox.cpp
src/osx/cocoa/combobox.mm
src/osx/cocoa/textctrl.mm
src/osx/combobox_osx.cpp
src/osx/textctrl_osx.cpp
src/osx/textentry_osx.cpp [new file with mode: 0644]

index 404da548a2294f7388ca78f4f1a904ed7e103035..5e6d7bb6040e78c36bc6887065835811c85bd60e 100644 (file)
@@ -2249,6 +2249,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     src/osx/statbox_osx.cpp
     src/osx/statline_osx.cpp
     src/osx/stattext_osx.cpp
+    src/osx/textentry_osx.cpp
     src/osx/textctrl_osx.cpp
     src/osx/tglbtn_osx.cpp
     src/osx/toolbar_osx.cpp
index 51bf090d2a25449497bc963de23cac7cec541ae7..54800ace4a2f33b5d387a974acb5ff4f04a3874e 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
 #define _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
 
+#include "wx/combobox.h"
 #include "wx/osx/private.h"
 
 // implementation exposed, so that search control can pull it
@@ -19,7 +20,7 @@
 class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
 {
 public :
-    wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w );
+    wxNSTextFieldControl( wxWindow *wxPeer, WXWidget w );
     virtual ~wxNSTextFieldControl();
 
     virtual wxString GetStringValue() const ;
@@ -69,4 +70,27 @@ protected:
     NSTextView* m_textView;
 };
 
+class wxNSComboBoxControl : public wxNSTextFieldControl, public wxComboWidgetImpl
+{
+public :
+    wxNSComboBoxControl( wxWindow *wxPeer, WXWidget w );
+    virtual ~wxNSComboBoxControl();
+    
+    virtual int GetSelectedItem() const;
+    virtual void SetSelectedItem(int item);
+    
+    virtual int GetNumberOfItems() const;
+    
+    virtual void InsertItem(int pos, const wxString& item);
+    virtual void RemoveItem(int pos);
+    
+    virtual void Clear();
+    
+    virtual wxString GetStringAtIndex(int pos) const;
+    
+    virtual int FindString(const wxString& text) const;
+private:
+    NSComboBox* m_comboBox;
+};
+
 #endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
index 7eef53a199a7d33c57f8190cfbfa424b7c22e377..bf1b20861bf7a8d6367c315cdf8b3c01f87a471d 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        wx/mac/carbon/combobox.h
+// Name:        wx/osx/combobox.h
 // Purpose:     wxComboBox class
 // Author:      Stefan Csomor
 // Modified by:
 
 #include "wx/containr.h"
 #include "wx/choice.h"
+#include "wx/textctrl.h"
 
 WXDLLIMPEXP_DATA_CORE(extern const char) wxComboBoxNameStr[];
 
+WX_DEFINE_ARRAY( char * , wxComboBoxDataArray ) ;
+
 // forward declaration of private implementation classes
 
 class wxComboBoxText;
 class wxComboBoxChoice;
+class wxComboWidgetImpl;
 
 // Combobox item
 class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
@@ -30,7 +34,7 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
  public:
     virtual ~wxComboBox();
 
-#ifndef wxOSX_USE_NATIVE_COMBOBOX
+#if wxOSX_USE_CARBON
     // forward these functions to all subcontrols
     virtual bool Enable(bool enable = true);
     virtual bool Show(bool show = true);
@@ -87,17 +91,22 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
            const wxString& name = wxComboBoxNameStr);
 
     virtual int GetSelection() const;
+    virtual void GetSelection(long *from, long *to) const;
     virtual void SetSelection(int n);
+    virtual void SetSelection(long from, long to);
     virtual int FindString(const wxString& s, bool bCase = false) const;
     virtual wxString GetString(unsigned int n) const;
     virtual wxString GetStringSelection() const;
     virtual void SetString(unsigned int n, const wxString& s);
 
+    virtual unsigned int GetCount() const;
+    
+// these methods are provided by wxTextEntry for the native impl.
+#if wxOSX_USE_CARBON
     // Text field functions
     virtual void SetValue(const wxString& value);
     virtual wxString GetValue() const;
     virtual void WriteText(const wxString& text);
-    virtual void GetSelection(long *from, long *to) const;
 
     // Clipboard operations
     virtual void Copy();
@@ -109,12 +118,9 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
     virtual wxTextPos GetLastPosition() const;
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
-    virtual void SetSelection(long from, long to);
     virtual void SetEditable(bool editable);
     virtual bool IsEditable() const;
 
-    virtual unsigned int GetCount() const;
-
     virtual void Undo();
     virtual void Redo();
     virtual void SelectAll();
@@ -126,17 +132,27 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
     virtual bool CanRedo() const;
 
     virtual wxClientDataType GetClientDataType() const;
+#endif
+
+
 
     // osx specific event handling common for all osx-ports
 
     virtual bool        OSXHandleClicked( double timestampsec );
 
-#ifndef wxOSX_USE_NATIVE_COMBOBOX
+#if wxOSX_USE_CARBON
     wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
 
     WX_DECLARE_CONTROL_CONTAINER();
 #endif
 
+    // only used by the native Cocoa combobox, but we must define it everywhere
+    // to maintain the wxTextEntry abstraction.
+    virtual wxTextWidgetImpl * GetTextPeer() const;
+
+#if wxOSX_USE_COCOA
+    wxComboWidgetImpl* GetComboPeer() const;
+#endif
 protected:
     // common part of all ctors
     void Init();
@@ -146,10 +162,12 @@ protected:
     virtual void DoClear();
 
     // wxTextEntry functions
+#if wxOSX_USE_CARBON
     virtual wxString DoGetValue() const;
+#endif
     virtual wxWindow *GetEditableWindow() { return this; }
 
-#ifndef wxOSX_USE_NATIVE_COMBOBOX
+#if wxOSX_USE_CARBON
     // override the base class virtuals involved in geometry calculations
     virtual wxSize DoGetBestSize() const;
     virtual void DoMoveWindow(int x, int y, int width, int height);
@@ -162,7 +180,9 @@ protected:
     virtual void DoSetItemClientData(unsigned int n, void* clientData);
     virtual void * DoGetItemClientData(unsigned int n) const;
 
+#if wxOSX_USE_CARBON
     virtual void SetClientDataType(wxClientDataType clientDataItemsType);
+#endif
 
     virtual void EnableTextChangedEvents(bool enable);
 
@@ -170,7 +190,9 @@ protected:
     wxComboBoxText*     m_text;
     wxComboBoxChoice*   m_choice;
 
-#ifndef wxOSX_USE_NATIVE_COMBOBOX
+    wxComboBoxDataArray m_datas;
+
+#if wxOSX_USE_CARBON
     DECLARE_EVENT_TABLE()
 #endif
 };
index c106c39ca73af78b8b2ea477f2b9929f6dac33c6..79b652409832f5b4a223f7502ce5ec956aea3ad8 100644 (file)
@@ -470,7 +470,7 @@ public :
                                     long style,
                                     long extraStyle);
 
-#ifdef wxOSX_USE_NATIVE_COMBOBOX
+#if wxOSX_USE_COCOA
     static wxWidgetImplType*    CreateComboBox( wxWindowMac* wxpeer, 
                                     wxWindowMac* parent, 
                                     wxWindowID id, 
@@ -612,6 +612,31 @@ public :
     virtual wxSize GetBestSize() const { return wxDefaultSize; }
 };
 
+// common interface for all implementations
+class WXDLLIMPEXP_CORE wxComboWidgetImpl
+
+{
+public :
+    wxComboWidgetImpl() {}
+
+    virtual ~wxComboWidgetImpl() {}
+  
+    virtual int GetSelectedItem() const { return -1; };
+    virtual void SetSelectedItem(int WXUNUSED(item)) {};
+    
+    virtual int GetNumberOfItems() const { return -1; };
+    
+    virtual void InsertItem(int WXUNUSED(pos), const wxString& WXUNUSED(item)) {}
+    
+    virtual void RemoveItem(int WXUNUSED(pos)) {}
+    
+    virtual void Clear() {}
+    
+    virtual wxString GetStringAtIndex(int WXUNUSED(pos)) const { return wxEmptyString; }
+    
+    virtual int FindString(const wxString& WXUNUSED(text)) const { return -1; }
+};
+
 //
 // common interface for buttons
 //
index c7c934144af23dafb2003a5666cc50e33eb83999..aa010f84c19f9bd1010eabfcfd5146b5500eed25 100644 (file)
@@ -69,17 +69,10 @@ public:
     virtual int GetNumberOfLines() const;
 
     virtual bool IsModified() const;
-    virtual bool IsEditable() const;
-
-    // If the return values from and to are the same, there is no selection.
-    virtual void GetSelection(long* from, long* to) const;
 
     // operations
     // ----------
 
-    // editing
-    virtual void Clear();
-    virtual void Remove(long from, long to);
 
     // sets/clears the dirty flag
     virtual void MarkDirty();
@@ -97,10 +90,6 @@ public:
     virtual bool SetStyle(long start, long end, const wxTextAttr& style);
     virtual bool SetDefaultStyle(const wxTextAttr& style);
 
-    // writing text inserts it at the current position;
-    // appending always inserts it at the end
-    virtual void WriteText(const wxString& text);
-
     // translate between the position (which is just an index into the textctrl
     // considering all its contents as a single strings) and (x, y) coordinates
     // which represent column and line.
@@ -109,30 +98,13 @@ public:
 
     virtual void ShowPosition(long pos);
 
-    // Clipboard operations
-    virtual void Copy();
+    // overrides so that we can send text updated events
     virtual void Cut();
     virtual void Paste();
-
-    virtual bool CanCopy() const;
-    virtual bool CanCut() const;
-    virtual bool CanPaste() const;
-
-    // Undo/redo
-    virtual void Undo();
-    virtual void Redo();
-
-    virtual bool CanUndo() const;
-    virtual bool CanRedo() const;
-
-    // Insertion point
-    virtual void SetInsertionPoint(long pos);
-    virtual void SetInsertionPointEnd();
-    virtual long GetInsertionPoint() const;
-    virtual wxTextPos GetLastPosition() const;
-
-    virtual void SetSelection(long from, long to);
-    virtual void SetEditable(bool editable);
+    
+    virtual void WriteText(const wxString& text);
+    virtual void Clear();
+    virtual void Remove(long from, long to);
 
     // Implementation
     // --------------
@@ -168,15 +140,13 @@ public:
     virtual void MacSuperChangedPosition();
     virtual void MacCheckSpelling(bool check);
 
-    wxTextWidgetImpl * GetTextPeer() const;
+    virtual wxTextWidgetImpl * GetTextPeer() const;
 protected:
     // common part of all ctors
     void Init();
 
     virtual wxSize DoGetBestSize() const;
 
-    virtual wxString DoGetValue() const;
-
     bool  m_editable;
 
     // flag is set to true when the user edits the controls contents
diff --git a/include/wx/osx/textentry.h b/include/wx/osx/textentry.h
new file mode 100644 (file)
index 0000000..14ab4a0
--- /dev/null
@@ -0,0 +1,107 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        wx/osx/textentry.h
+// Purpose:     wxTextEntry class
+// Author:      Stefan Csomor
+// Modified by: Kevin Ollivier
+// Created:     1998-01-01
+// RCS-ID:      $Id: textctrl.h 62531 2009-11-01 00:58:04Z KO $
+// Copyright:   (c) Stefan Csomor
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_OSX_TEXTENTRY_H_
+#define _WX_OSX_TEXTENTRY_H_
+
+#if wxUSE_SYSTEM_OPTIONS
+    // set this to 'true' if you want to use the 'classic' MLTE-based implementation
+    // instead of the HIView-based implementation in 10.3 and upwards, the former
+    // has more features (backgrounds etc.), but may show redraw artefacts and other
+    // problems depending on your usage; hence, the default is 'false'.
+    #define wxMAC_TEXTCONTROL_USE_MLTE wxT("mac.textcontrol-use-mlte")
+    // set this to 'true' if you want editable text controls to have spell checking turned
+    // on by default, you can change this setting individually on a control using MacCheckSpelling
+    #define wxMAC_TEXTCONTROL_USE_SPELL_CHECKER wxT("mac.textcontrol-use-spell-checker")
+#endif
+
+#include "wx/control.h"
+
+// forward decl for wxListWidgetImpl implementation type.
+class WXDLLIMPEXP_FWD_CORE wxTextWidgetImpl;
+
+class WXDLLIMPEXP_CORE wxTextEntry: public wxTextEntryBase
+{
+
+public:
+    wxTextEntry()
+    { }
+    
+    virtual ~wxTextEntry() {};
+
+    virtual bool IsEditable() const;
+
+    // If the return values from and to are the same, there is no selection.
+    virtual void GetSelection(long* from, long* to) const;
+
+    // operations
+    // ----------
+
+    // editing
+    virtual void Clear();
+    virtual void Remove(long from, long to);
+
+    // set the max number of characters which may be entered
+    // in a single line text control
+    virtual void SetMaxLength(unsigned long len);
+
+    // writing text inserts it at the current position;
+    // appending always inserts it at the end
+    virtual void WriteText(const wxString& text);
+
+    // Clipboard operations
+    virtual void Copy();
+    virtual void Cut();
+    virtual void Paste();
+
+    virtual bool CanCopy() const;
+    virtual bool CanCut() const;
+    virtual bool CanPaste() const;
+
+    // Undo/redo
+    virtual void Undo();
+    virtual void Redo();
+
+    virtual bool CanUndo() const;
+    virtual bool CanRedo() const;
+
+    // Insertion point
+    virtual void SetInsertionPoint(long pos);
+    virtual void SetInsertionPointEnd();
+    virtual long GetInsertionPoint() const;
+    virtual wxTextPos GetLastPosition() const;
+
+    virtual void SetSelection(long from, long to);
+    virtual void SetEditable(bool editable);
+
+    // Implementation
+    // --------------
+
+    virtual wxTextWidgetImpl * GetTextPeer() const;
+protected:
+
+    virtual wxString DoGetValue() const;
+    
+    bool  m_editable;
+
+  // need to make this public because of the current implementation via callbacks
+    unsigned long  m_maxLength;
+
+    virtual void EnableTextChangedEvents(bool enable)
+    {
+        m_triggerUpdateEvents = enable;
+    }
+
+    bool m_triggerUpdateEvents ;
+
+};
+
+#endif // _WX_OSX_TEXTENTRY_H_
index 130446a4a316071a6b06fe17ed5d00eba0ab0982..f773635ea111d2e388aab192767c4c4670d0d120 100644 (file)
@@ -248,6 +248,8 @@ private:
     };
 #elif defined(__WXGTK20__)
     #include "wx/gtk/textentry.h"
+#elif defined(__WXMAC__)
+    #include "wx/osx/textentry.h"
 #elif defined(__WXMSW__)
     #include "wx/msw/textentry.h"
 #elif defined(__WXMOTIF__)
index c37811805ce604807db7b8d5eafcc7c69e54293e..2dd77998678eb8374bc4e40fa1301777e2ecbd3f 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "wx/wxprec.h"
 
-#if wxUSE_COMBOBOX && !defined(wxOSX_USE_NATIVE_COMBOBOX)
+#if wxUSE_COMBOBOX && wxOSX_USE_CARBON
 
 #include "wx/combobox.h"
 
@@ -686,4 +686,12 @@ bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
     return true ;
 }
 
-#endif // wxUSE_COMBOBOX && !defined(wxOSX_USE_NATIVE_COMBOBOX)
+wxTextWidgetImpl* wxComboBox::GetTextPeer() const
+{
+    if (m_text)
+        return m_text->GetTextPeer();
+    
+    return NULL;
+}
+
+#endif // wxUSE_COMBOBOX && wxOSX_USE_CARBON
index bd58b492d70f462548a0280e27ea8def3edd9fa4..0438d1486608bbdc1bb449916ef9b82d3430e514 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "wx/wxprec.h"
 
-#if wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+#if wxUSE_COMBOBOX
 
 #include "wx/combobox.h"
 
@@ -20,7 +20,7 @@
     #include "wx/dcclient.h"
 #endif
 
-#include "wx/osx/private.h"
+#include "wx/osx/cocoa/private/textimpl.h"
 
 // work in progress
 
     }
 }
 
-- (int) intValue
+- (void)controlTextDidChange:(NSNotification *)aNotification
 {
-   return [self indexOfSelectedItem];
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer ) {
+            wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetString( static_cast<wxComboBox*>(wxpeer)->GetValue() );
+            wxpeer->HandleWindowEvent( event );
+        }
+    }
 }
 
-- (void) setIntValue: (int) v
+- (void)comboBoxSelectionDidChange:(NSNotification *)notification
 {
-    [self selectItemAtIndex:v];
+    wxUnusedVar(notification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer ) {
+            wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetInt( static_cast<wxComboBox*>(wxpeer)->GetSelection() );
+            // For some reason, wxComboBox::GetValue will not return the newly selected item 
+            // while we're inside this callback, so use AddPendingEvent to make sure
+            // GetValue() returns the right value.
+            wxpeer->GetEventHandler()->AddPendingEvent( event );
+        }
+    }
 }
-
 @end
 
+wxNSComboBoxControl::wxNSComboBoxControl( wxWindow *wxPeer, WXWidget w ) : wxNSTextFieldControl(wxPeer, w)
+{
+    m_comboBox = (NSComboBox*)w;
+}
+
+wxNSComboBoxControl::~wxNSComboBoxControl()
+{
+}
+
+int wxNSComboBoxControl::GetSelectedItem() const
+{
+    return [m_comboBox indexOfSelectedItem];
+}
+
+void wxNSComboBoxControl::SetSelectedItem(int item)
+{
+    [m_comboBox selectItemAtIndex: item];
+}
+
+int wxNSComboBoxControl::GetNumberOfItems() const
+{
+    return [m_comboBox numberOfItems];
+}
+
+void wxNSComboBoxControl::InsertItem(int pos, const wxString& item)
+{
+    [m_comboBox insertItemWithObjectValue:wxCFStringRef( item , m_wxPeer->GetFont().GetEncoding() ).AsNSString() atIndex:pos];
+}
+
+void wxNSComboBoxControl::RemoveItem(int pos)
+{
+    [m_comboBox removeItemAtIndex:pos];
+}
+
+void wxNSComboBoxControl::Clear()
+{
+    [m_comboBox removeAllItems];
+}
+
+wxString wxNSComboBoxControl::GetStringAtIndex(int pos) const
+{
+    return wxCFStringRef::AsString([m_comboBox itemObjectValueAtIndex:pos], m_wxPeer->GetFont().GetEncoding());
+}
+
+int wxNSComboBoxControl::FindString(const wxString& text) const
+{
+    return [m_comboBox indexOfItemWithObjectValue:wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
+}
+
 wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer, 
                                     wxWindowMac* WXUNUSED(parent), 
                                     wxWindowID WXUNUSED(id), 
@@ -65,8 +138,8 @@ wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer,
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSComboBox* v = [[wxNSComboBox alloc] initWithFrame:r];
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
+    wxNSComboBoxControl* c = new wxNSComboBoxControl( wxpeer, v );
     return c;
 }
 
-#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+#endif // wxUSE_COMBOBOX
\ No newline at end of file
index 9dbb445eed3d256b7779859ed9f22ade7f86a6e9..aca568bcea4f2bcdb7d40ae2f17e8cc58ea4deab 100644 (file)
@@ -528,7 +528,7 @@ wxSize wxNSTextViewControl::GetBestSize() const
 
 // wxNSTextFieldControl
 
-wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
+wxNSTextFieldControl::wxNSTextFieldControl( wxWindow *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 {
     m_textField = (NSTextField*) w;
     [m_textField setDelegate: w];
index 3a0e884c7a7c8f90ede51366adabc122167ab4da..91bc6fa638b90532c6f713dfd9b295ce19979b28 100644 (file)
@@ -11,7 +11,7 @@
 
 #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"
@@ -63,6 +63,12 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
     if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
         return false;
         
+    if (style & wxCB_READONLY)
+        wxLogWarning("wxCB_READONLY style not supported by OS X Cocoa. Use wxChoice instead.");
+    
+    if (style & wxCB_SORT)
+        wxLogWarning("wxCB_SORT style not currently supported by OS X Cocoa.");
+        
     m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() );
 
     MacPostControlCreate( pos, size );
@@ -89,197 +95,105 @@ void wxComboBox::DelegateChoice( const wxString& value )
     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()
+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::SetEditable(bool editable)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
+        idx = pos;
+        GetComboPeer()->InsertItem( idx, items[i] );
 
-void wxComboBox::SetInsertionPoint(long pos)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
+        if (idx > m_datas.GetCount())
+            m_datas.SetCount(idx);
+        m_datas.Insert( NULL, idx );
+        AssignNewItemClientData(idx, clientData, i, type);
+    }
 
-void wxComboBox::SetInsertionPointEnd()
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
+    m_peer->SetMaximum( GetCount() );
 
-long wxComboBox::GetInsertionPoint() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return 0;
+    return pos - 1;
 }
 
-wxTextPos wxComboBox::GetLastPosition() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return 0;
-}
-
-void wxComboBox::Replace(long from, long to, const wxString& value)
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
+void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
 {
-    wxFAIL_MSG("Method Not Implemented.");
-}
+    wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") );
 
-void wxComboBox::Remove(long from, long to)
-{
-    wxFAIL_MSG("Method Not Implemented.");
+    m_datas[n] = (char*)clientData ;
 }
 
-void wxComboBox::SetSelection(long from, long to)
+void * wxComboBox::DoGetItemClientData(unsigned int n) const
 {
-    wxFAIL_MSG("Method Not Implemented.");
-}
+    wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") );
 
-int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
-                              unsigned int pos,
-                              void **clientData, wxClientDataType type)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return 0;
-}
-
-void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
-
-void* wxComboBox::DoGetItemClientData(unsigned int n) const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return NULL;
+    return (void *)m_datas[n];
 }
 
 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.");
+    GetComboPeer()->Clear();
+    SetValue(wxEmptyString);
 }
 
+void wxComboBox::GetSelection(long *from, long *to) const
+{
+    wxTextEntry::GetSelection(from, to);
+}
+    
 int wxComboBox::GetSelection() const
 {
-    wxFAIL_MSG("Method Not Implemented.");
-    return 0;
+    return GetComboPeer()->GetSelectedItem();
 }
 
-void wxComboBox::GetSelection(long *from, long *to) const
+void wxComboBox::SetSelection(int n)
 {
-    wxFAIL_MSG("Method Not Implemented.");
+    GetComboPeer()->SetSelectedItem(n);
 }
 
-void wxComboBox::SetSelection(int n)
+void wxComboBox::SetSelection(long from, long to)
 {
-    wxFAIL_MSG("Method Not Implemented.");
+    wxTextEntry::SetSelection(from, to);
 }
 
 int wxComboBox::FindString(const wxString& s, bool bCase) const
 {
-    wxFAIL_MSG("Method Not Implemented.");
-    return 0;
+    if (!bCase)
+        wxLogWarning("wxComboBox::FindString on Mac doesn't currently support case insensitive search.");
+    
+    return GetComboPeer()->FindString(s);
 }
 
 wxString wxComboBox::GetString(unsigned int n) const
 {
-    wxFAIL_MSG("Method Not Implemented.");
-    return wxEmptyString;
+    return GetComboPeer()->GetStringAtIndex(n);
 }
 
 wxString wxComboBox::GetStringSelection() const
 {
-    wxFAIL_MSG("Method Not Implemented.");
-    return wxEmptyString;
+    return GetString(GetSelection());
 }
 
 void wxComboBox::SetString(unsigned int n, const wxString& s)
 {
-    wxFAIL_MSG("Method Not Implemented.");
-}
-
-bool wxComboBox::IsEditable() const
-{
-    return !HasFlag(wxCB_READONLY);
-}
-
-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
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return false;
-}
-
-bool wxComboBox::CanCut() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return false;
-}
-
-bool wxComboBox::CanPaste() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return false;
-}
-
-bool wxComboBox::CanUndo() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return false;
-}
-
-bool wxComboBox::CanRedo() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return false;
+    Delete(n);
+    Insert(s, n);
+    SetValue(s); // changing the item in the list won't update the display item
 }
 
 void wxComboBox::EnableTextChangedEvents(bool enable)
@@ -287,28 +201,6 @@ void wxComboBox::EnableTextChangedEvents(bool enable)
     wxFAIL_MSG("Method Not Implemented.");
 }
 
-void wxComboBox::WriteText(const wxString& text)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
-
-wxString wxComboBox::DoGetValue() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return wxEmptyString;
-}
-
-wxClientDataType wxComboBox::GetClientDataType() const
-{
-    wxFAIL_MSG("Method Not Implemented.");
-    return wxClientData_None;
-}
-
-void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType)
-{
-    wxFAIL_MSG("Method Not Implemented.");
-}
-
 bool wxComboBox::OSXHandleClicked( double timestampsec )
 {
     wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
@@ -319,4 +211,14 @@ bool wxComboBox::OSXHandleClicked( double timestampsec )
     return true;
 }
 
-#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX)
+wxTextWidgetImpl* wxComboBox::GetTextPeer() const
+{
+    return dynamic_cast<wxTextWidgetImpl*> (m_peer);
+}
+
+wxComboWidgetImpl* wxComboBox::GetComboPeer() const
+{
+    return dynamic_cast<wxComboWidgetImpl*> (m_peer);
+}
+
+#endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA
index 573fd4c6ae5973d05a15800230c4a1332fa8ebd4..5bef77a56d936aa367aa412252ac3f04ee45e359 100644 (file)
@@ -163,16 +163,6 @@ void wxTextCtrl::MacCheckSpelling(bool check)
     GetTextPeer()->CheckSpelling(check);
 }
 
-wxString wxTextCtrl::DoGetValue() const
-{
-    return GetTextPeer()->GetStringValue() ;
-}
-
-void wxTextCtrl::GetSelection(long* from, long* to) const
-{
-    GetTextPeer()->GetSelection( from , to ) ;
-}
-
 void wxTextCtrl::SetMaxLength(unsigned long len)
 {
     m_maxLength = len ;
@@ -204,132 +194,11 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
     return true ;
 }
 
-// Clipboard operations
-
-void wxTextCtrl::Copy()
-{
-    if (CanCopy())
-        GetTextPeer()->Copy() ;
-}
-
-void wxTextCtrl::Cut()
-{
-    if (CanCut())
-    {
-        GetTextPeer()->Cut() ;
-
-        SendTextUpdatedEvent();
-    }
-}
-
-void wxTextCtrl::Paste()
-{
-    if (CanPaste())
-    {
-        GetTextPeer()->Paste() ;
-
-        // TODO: eventually we should add setting the default style again
-        SendTextUpdatedEvent();
-    }
-}
-
-bool wxTextCtrl::CanCopy() const
-{
-    // Can copy if there's a selection
-    long from, to;
-    GetSelection( &from, &to );
-
-    return (from != to);
-}
-
-bool wxTextCtrl::CanCut() const
-{
-    if ( !IsEditable() )
-        return false;
-
-    // Can cut if there's a selection
-    long from, to;
-    GetSelection( &from, &to );
-
-    return (from != to);
-}
-
-bool wxTextCtrl::CanPaste() const
-{
-    if (!IsEditable())
-        return false;
-
-    return GetTextPeer()->CanPaste() ;
-}
-
-void wxTextCtrl::SetEditable(bool editable)
-{
-    if ( editable != m_editable )
-    {
-        m_editable = editable ;
-        GetTextPeer()->SetEditable( editable ) ;
-    }
-}
-
-void wxTextCtrl::SetInsertionPoint(long pos)
-{
-    SetSelection( pos , pos ) ;
-}
-
-void wxTextCtrl::SetInsertionPointEnd()
-{
-    long pos = GetLastPosition();
-    SetInsertionPoint( pos );
-}
-
-long wxTextCtrl::GetInsertionPoint() const
-{
-    long begin, end ;
-    GetSelection( &begin , &end ) ;
-
-    return begin ;
-}
-
-wxTextPos wxTextCtrl::GetLastPosition() const
-{
-    return GetTextPeer()->GetLastPosition() ;
-}
-
-void wxTextCtrl::Remove(long from, long to)
-{
-    GetTextPeer()->Remove( from , to ) ;
-    if ( m_triggerUpdateEvents )
-        SendTextUpdatedEvent();
-}
-
-void wxTextCtrl::SetSelection(long from, long to)
-{
-    GetTextPeer()->SetSelection( from , to ) ;
-}
-
-void wxTextCtrl::WriteText(const wxString& str)
-{
-    GetTextPeer()->WriteText( str ) ;
-    if ( m_triggerUpdateEvents )
-        SendTextUpdatedEvent();
-}
-
-void wxTextCtrl::Clear()
-{
-    GetTextPeer()->Clear() ;
-    SendTextUpdatedEvent();
-}
-
 bool wxTextCtrl::IsModified() const
 {
     return m_dirty;
 }
 
-bool wxTextCtrl::IsEditable() const
-{
-    return IsEnabled() && m_editable ;
-}
-
 bool wxTextCtrl::AcceptsFocus() const
 {
     // we don't want focus if we can't be edited
@@ -386,38 +255,6 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
     return GetTextPeer()->GetStyle(position, style);
 }
 
-// ----------------------------------------------------------------------------
-// Undo/redo
-// ----------------------------------------------------------------------------
-
-void wxTextCtrl::Undo()
-{
-    if (CanUndo())
-        GetTextPeer()->Undo() ;
-}
-
-void wxTextCtrl::Redo()
-{
-    if (CanRedo())
-        GetTextPeer()->Redo() ;
-}
-
-bool wxTextCtrl::CanUndo() const
-{
-    if ( !IsEditable() )
-        return false ;
-
-    return GetTextPeer()->CanUndo() ;
-}
-
-bool wxTextCtrl::CanRedo() const
-{
-    if ( !IsEditable() )
-        return false ;
-
-    return GetTextPeer()->CanRedo() ;
-}
-
 void wxTextCtrl::MarkDirty()
 {
     m_dirty = true;
@@ -458,10 +295,45 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
     return GetTextPeer()->GetLineText(lineNo) ;
 }
 
-void wxTextCtrl::Command(wxCommandEvent & event)
+void wxTextCtrl::Remove(long from, long to)
 {
-    SetValue(event.GetString());
-    ProcessCommand(event);
+    wxTextEntry::Remove(from, to);
+    if ( m_triggerUpdateEvents )
+        SendTextUpdatedEvent();
+}
+
+void wxTextCtrl::WriteText(const wxString& str)
+{
+    wxTextEntry::WriteText( str ) ;
+    if ( m_triggerUpdateEvents )
+        SendTextUpdatedEvent();
+}
+
+void wxTextCtrl::Clear()
+{
+    wxTextEntry::Clear() ;
+    SendTextUpdatedEvent();
+}
+
+void wxTextCtrl::Cut()
+{
+    if (CanCut())
+    {
+        wxTextEntry::Cut() ;
+
+        SendTextUpdatedEvent();
+    }
+}
+
+void wxTextCtrl::Paste()
+{
+    if (CanPaste())
+    {
+        wxTextEntry::Paste();
+
+        // TODO: eventually we should add setting the default style again
+        SendTextUpdatedEvent();
+    }
 }
 
 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
@@ -614,10 +486,18 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
 #endif
 }
 
+void wxTextCtrl::Command(wxCommandEvent & event)
+{
+    SetValue(event.GetString());
+    ProcessCommand(event);
+}
+
 // ----------------------------------------------------------------------------
 // standard handlers for standard edit menu events
 // ----------------------------------------------------------------------------
 
+// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
+
 void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
 {
     Cut();
@@ -695,8 +575,6 @@ void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
     event.Enable(GetLastPosition() > 0);
 }
 
-// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
-
 void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
 {
     if ( GetTextPeer()->HasOwnContextMenu() )
diff --git a/src/osx/textentry_osx.cpp b/src/osx/textentry_osx.cpp
new file mode 100644 (file)
index 0000000..680a4fd
--- /dev/null
@@ -0,0 +1,210 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        src/osx/textentry_osx.cpp
+// Purpose:     wxTextEntry
+// Author:      Stefan Csomor
+// Modified by: Kevin Ollivier
+// Created:     1998-01-01
+// RCS-ID:      $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
+// Copyright:   (c) Stefan Csomor
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#include "wx/wxprec.h"
+
+#if wxUSE_TEXTCTRL
+
+#include "wx/textctrl.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/intl.h"
+    #include "wx/app.h"
+    #include "wx/utils.h"
+    #include "wx/dc.h"
+    #include "wx/button.h"
+    #include "wx/menu.h"
+    #include "wx/settings.h"
+    #include "wx/msgdlg.h"
+    #include "wx/toplevel.h"
+#endif
+
+#ifdef __DARWIN__
+    #include <sys/types.h>
+    #include <sys/stat.h>
+#else
+    #include <stat.h>
+#endif
+
+#if wxUSE_STD_IOSTREAM
+    #if wxUSE_IOSTREAMH
+        #include <fstream.h>
+    #else
+        #include <fstream>
+    #endif
+#endif
+
+#include "wx/filefn.h"
+#include "wx/sysopt.h"
+#include "wx/thread.h"
+
+#include "wx/osx/private.h"
+
+wxString wxTextEntry::DoGetValue() const
+{
+    return GetTextPeer()->GetStringValue() ;
+}
+
+void wxTextEntry::GetSelection(long* from, long* to) const
+{
+    GetTextPeer()->GetSelection( from , to ) ;
+}
+
+void wxTextEntry::SetMaxLength(unsigned long len)
+{
+    m_maxLength = len ;
+}
+
+// Clipboard operations
+
+void wxTextEntry::Copy()
+{
+    if (CanCopy())
+        GetTextPeer()->Copy() ;
+}
+
+void wxTextEntry::Cut()
+{
+    if (CanCut())
+        GetTextPeer()->Cut() ;
+}
+
+void wxTextEntry::Paste()
+{
+    if (CanPaste())
+        GetTextPeer()->Paste() ;
+}
+
+bool wxTextEntry::CanCopy() const
+{
+    // Can copy if there's a selection
+    long from, to;
+    GetSelection( &from, &to );
+
+    return (from != to);
+}
+
+bool wxTextEntry::CanCut() const
+{
+    if ( !IsEditable() )
+        return false;
+
+    // Can cut if there's a selection
+    long from, to;
+    GetSelection( &from, &to );
+
+    return (from != to);
+}
+
+bool wxTextEntry::CanPaste() const
+{
+    if (!IsEditable())
+        return false;
+
+    return GetTextPeer()->CanPaste() ;
+}
+
+void wxTextEntry::SetEditable(bool editable)
+{
+    if ( editable != m_editable )
+    {
+        m_editable = editable ;
+        GetTextPeer()->SetEditable( editable ) ;
+    }
+}
+
+void wxTextEntry::SetInsertionPoint(long pos)
+{
+    SetSelection( pos , pos ) ;
+}
+
+void wxTextEntry::SetInsertionPointEnd()
+{
+    long pos = GetLastPosition();
+    SetInsertionPoint( pos );
+}
+
+long wxTextEntry::GetInsertionPoint() const
+{
+    long begin, end ;
+    GetSelection( &begin , &end ) ;
+
+    return begin ;
+}
+
+wxTextPos wxTextEntry::GetLastPosition() const
+{
+    return GetTextPeer()->GetLastPosition() ;
+}
+
+void wxTextEntry::Remove(long from, long to)
+{
+    GetTextPeer()->Remove( from , to ) ;
+}
+
+void wxTextEntry::SetSelection(long from, long to)
+{
+    GetTextPeer()->SetSelection( from , to ) ;
+}
+
+void wxTextEntry::WriteText(const wxString& str)
+{
+    GetTextPeer()->WriteText( str ) ;
+}
+
+void wxTextEntry::Clear()
+{
+    GetTextPeer()->Clear() ;
+}
+
+bool wxTextEntry::IsEditable() const
+{
+    return m_editable ;
+}
+
+// ----------------------------------------------------------------------------
+// Undo/redo
+// ----------------------------------------------------------------------------
+
+void wxTextEntry::Undo()
+{
+    if (CanUndo())
+        GetTextPeer()->Undo() ;
+}
+
+void wxTextEntry::Redo()
+{
+    if (CanRedo())
+        GetTextPeer()->Redo() ;
+}
+
+bool wxTextEntry::CanUndo() const
+{
+    if ( !IsEditable() )
+        return false ;
+
+    return GetTextPeer()->CanUndo() ;
+}
+
+bool wxTextEntry::CanRedo() const
+{
+    if ( !IsEditable() )
+        return false ;
+
+    return GetTextPeer()->CanRedo() ;
+}
+
+wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
+{
+    wxFAIL_MSG("You need to implement wxTextWidgetImpl* GetTextPeer() in your wxTextEntry subclass if you want to use the native impls of its methods.");
+    return NULL;
+}
+#endif // wxUSE_TEXTCTRL