Implement native OS X ComboBox for OS X Cocoa, and implement wxTextEntry methods to share code between wxComboBox and wxTextCtrl.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2010-01-09 19:50:55 +00:00
parent 4f42c05a1a
commit c84030e020
13 changed files with 617 additions and 395 deletions

View File

@@ -2249,6 +2249,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/statbox_osx.cpp src/osx/statbox_osx.cpp
src/osx/statline_osx.cpp src/osx/statline_osx.cpp
src/osx/stattext_osx.cpp src/osx/stattext_osx.cpp
src/osx/textentry_osx.cpp
src/osx/textctrl_osx.cpp src/osx/textctrl_osx.cpp
src/osx/tglbtn_osx.cpp src/osx/tglbtn_osx.cpp
src/osx/toolbar_osx.cpp src/osx/toolbar_osx.cpp

View File

@@ -12,6 +12,7 @@
#ifndef _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_ #ifndef _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
#define _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_ #define _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
#include "wx/combobox.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
// implementation exposed, so that search control can pull it // implementation exposed, so that search control can pull it
@@ -19,7 +20,7 @@
class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
{ {
public : public :
wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ); wxNSTextFieldControl( wxWindow *wxPeer, WXWidget w );
virtual ~wxNSTextFieldControl(); virtual ~wxNSTextFieldControl();
virtual wxString GetStringValue() const ; virtual wxString GetStringValue() const ;
@@ -69,4 +70,27 @@ protected:
NSTextView* m_textView; 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_ #endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/mac/carbon/combobox.h // Name: wx/osx/combobox.h
// Purpose: wxComboBox class // Purpose: wxComboBox class
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: // Modified by:
@@ -14,13 +14,17 @@
#include "wx/containr.h" #include "wx/containr.h"
#include "wx/choice.h" #include "wx/choice.h"
#include "wx/textctrl.h"
WXDLLIMPEXP_DATA_CORE(extern const char) wxComboBoxNameStr[]; WXDLLIMPEXP_DATA_CORE(extern const char) wxComboBoxNameStr[];
WX_DEFINE_ARRAY( char * , wxComboBoxDataArray ) ;
// forward declaration of private implementation classes // forward declaration of private implementation classes
class wxComboBoxText; class wxComboBoxText;
class wxComboBoxChoice; class wxComboBoxChoice;
class wxComboWidgetImpl;
// Combobox item // Combobox item
class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
@@ -30,7 +34,7 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
public: public:
virtual ~wxComboBox(); virtual ~wxComboBox();
#ifndef wxOSX_USE_NATIVE_COMBOBOX #if wxOSX_USE_CARBON
// forward these functions to all subcontrols // forward these functions to all subcontrols
virtual bool Enable(bool enable = true); virtual bool Enable(bool enable = true);
virtual bool Show(bool show = true); virtual bool Show(bool show = true);
@@ -87,17 +91,22 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
const wxString& name = wxComboBoxNameStr); const wxString& name = wxComboBoxNameStr);
virtual int GetSelection() const; virtual int GetSelection() const;
virtual void GetSelection(long *from, long *to) const;
virtual void SetSelection(int n); virtual void SetSelection(int n);
virtual void SetSelection(long from, long to);
virtual int FindString(const wxString& s, bool bCase = false) const; virtual int FindString(const wxString& s, bool bCase = false) const;
virtual wxString GetString(unsigned int n) const; virtual wxString GetString(unsigned int n) const;
virtual wxString GetStringSelection() const; virtual wxString GetStringSelection() const;
virtual void SetString(unsigned int n, const wxString& s); 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 // Text field functions
virtual void SetValue(const wxString& value); virtual void SetValue(const wxString& value);
virtual wxString GetValue() const; virtual wxString GetValue() const;
virtual void WriteText(const wxString& text); virtual void WriteText(const wxString& text);
virtual void GetSelection(long *from, long *to) const;
// Clipboard operations // Clipboard operations
virtual void Copy(); virtual void Copy();
@@ -109,12 +118,9 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
virtual wxTextPos GetLastPosition() const; virtual wxTextPos GetLastPosition() const;
virtual void Replace(long from, long to, const wxString& value); virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to); virtual void Remove(long from, long to);
virtual void SetSelection(long from, long to);
virtual void SetEditable(bool editable); virtual void SetEditable(bool editable);
virtual bool IsEditable() const; virtual bool IsEditable() const;
virtual unsigned int GetCount() const;
virtual void Undo(); virtual void Undo();
virtual void Redo(); virtual void Redo();
virtual void SelectAll(); virtual void SelectAll();
@@ -126,17 +132,27 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
virtual bool CanRedo() const; virtual bool CanRedo() const;
virtual wxClientDataType GetClientDataType() const; virtual wxClientDataType GetClientDataType() const;
#endif
// osx specific event handling common for all osx-ports // osx specific event handling common for all osx-ports
virtual bool OSXHandleClicked( double timestampsec ); virtual bool OSXHandleClicked( double timestampsec );
#ifndef wxOSX_USE_NATIVE_COMBOBOX #if wxOSX_USE_CARBON
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
WX_DECLARE_CONTROL_CONTAINER(); WX_DECLARE_CONTROL_CONTAINER();
#endif #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: protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
@@ -146,10 +162,12 @@ protected:
virtual void DoClear(); virtual void DoClear();
// wxTextEntry functions // wxTextEntry functions
#if wxOSX_USE_CARBON
virtual wxString DoGetValue() const; virtual wxString DoGetValue() const;
#endif
virtual wxWindow *GetEditableWindow() { return this; } virtual wxWindow *GetEditableWindow() { return this; }
#ifndef wxOSX_USE_NATIVE_COMBOBOX #if wxOSX_USE_CARBON
// override the base class virtuals involved in geometry calculations // override the base class virtuals involved in geometry calculations
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
virtual void DoMoveWindow(int x, int y, int width, int height); 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 DoSetItemClientData(unsigned int n, void* clientData);
virtual void * DoGetItemClientData(unsigned int n) const; virtual void * DoGetItemClientData(unsigned int n) const;
#if wxOSX_USE_CARBON
virtual void SetClientDataType(wxClientDataType clientDataItemsType); virtual void SetClientDataType(wxClientDataType clientDataItemsType);
#endif
virtual void EnableTextChangedEvents(bool enable); virtual void EnableTextChangedEvents(bool enable);
@@ -170,7 +190,9 @@ protected:
wxComboBoxText* m_text; wxComboBoxText* m_text;
wxComboBoxChoice* m_choice; wxComboBoxChoice* m_choice;
#ifndef wxOSX_USE_NATIVE_COMBOBOX wxComboBoxDataArray m_datas;
#if wxOSX_USE_CARBON
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
#endif #endif
}; };

View File

@@ -470,7 +470,7 @@ public :
long style, long style,
long extraStyle); long extraStyle);
#ifdef wxOSX_USE_NATIVE_COMBOBOX #if wxOSX_USE_COCOA
static wxWidgetImplType* CreateComboBox( wxWindowMac* wxpeer, static wxWidgetImplType* CreateComboBox( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
wxWindowID id, wxWindowID id,
@@ -612,6 +612,31 @@ public :
virtual wxSize GetBestSize() const { return wxDefaultSize; } 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 // common interface for buttons
// //

View File

@@ -69,17 +69,10 @@ public:
virtual int GetNumberOfLines() const; virtual int GetNumberOfLines() const;
virtual bool IsModified() 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 // operations
// ---------- // ----------
// editing
virtual void Clear();
virtual void Remove(long from, long to);
// sets/clears the dirty flag // sets/clears the dirty flag
virtual void MarkDirty(); virtual void MarkDirty();
@@ -97,10 +90,6 @@ public:
virtual bool SetStyle(long start, long end, const wxTextAttr& style); virtual bool SetStyle(long start, long end, const wxTextAttr& style);
virtual bool SetDefaultStyle(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 // translate between the position (which is just an index into the textctrl
// considering all its contents as a single strings) and (x, y) coordinates // considering all its contents as a single strings) and (x, y) coordinates
// which represent column and line. // which represent column and line.
@@ -109,30 +98,13 @@ public:
virtual void ShowPosition(long pos); virtual void ShowPosition(long pos);
// Clipboard operations // overrides so that we can send text updated events
virtual void Copy();
virtual void Cut(); virtual void Cut();
virtual void Paste(); virtual void Paste();
virtual bool CanCopy() const; virtual void WriteText(const wxString& text);
virtual bool CanCut() const; virtual void Clear();
virtual bool CanPaste() const; virtual void Remove(long from, long to);
// 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 // Implementation
// -------------- // --------------
@@ -168,15 +140,13 @@ public:
virtual void MacSuperChangedPosition(); virtual void MacSuperChangedPosition();
virtual void MacCheckSpelling(bool check); virtual void MacCheckSpelling(bool check);
wxTextWidgetImpl * GetTextPeer() const; virtual wxTextWidgetImpl * GetTextPeer() const;
protected: protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
virtual wxString DoGetValue() const;
bool m_editable; bool m_editable;
// flag is set to true when the user edits the controls contents // flag is set to true when the user edits the controls contents

107
include/wx/osx/textentry.h Normal file
View File

@@ -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_

View File

@@ -248,6 +248,8 @@ private:
}; };
#elif defined(__WXGTK20__) #elif defined(__WXGTK20__)
#include "wx/gtk/textentry.h" #include "wx/gtk/textentry.h"
#elif defined(__WXMAC__)
#include "wx/osx/textentry.h"
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
#include "wx/msw/textentry.h" #include "wx/msw/textentry.h"
#elif defined(__WXMOTIF__) #elif defined(__WXMOTIF__)

View File

@@ -11,7 +11,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_COMBOBOX && !defined(wxOSX_USE_NATIVE_COMBOBOX) #if wxUSE_COMBOBOX && wxOSX_USE_CARBON
#include "wx/combobox.h" #include "wx/combobox.h"
@@ -686,4 +686,12 @@ bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) )
return true ; 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

View File

@@ -11,7 +11,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX) #if wxUSE_COMBOBOX
#include "wx/combobox.h" #include "wx/combobox.h"
@@ -20,7 +20,7 @@
#include "wx/dcclient.h" #include "wx/dcclient.h"
#endif #endif
#include "wx/osx/private.h" #include "wx/osx/cocoa/private/textimpl.h"
// work in progress // work in progress
@@ -42,18 +42,91 @@
} }
} }
- (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 @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, wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
wxWindowID WXUNUSED(id), wxWindowID WXUNUSED(id),
@@ -65,8 +138,8 @@ wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer,
{ {
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSComboBox* v = [[wxNSComboBox alloc] initWithFrame:r]; wxNSComboBox* v = [[wxNSComboBox alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxNSComboBoxControl* c = new wxNSComboBoxControl( wxpeer, v );
return c; return c;
} }
#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX) #endif // wxUSE_COMBOBOX

View File

@@ -528,7 +528,7 @@ wxSize wxNSTextViewControl::GetBestSize() const
// wxNSTextFieldControl // 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 = (NSTextField*) w;
[m_textField setDelegate: w]; [m_textField setDelegate: w];

View File

@@ -11,7 +11,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX) #if wxUSE_COMBOBOX && wxOSX_USE_COCOA
#include "wx/combobox.h" #include "wx/combobox.h"
#include "wx/osx/private.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 ) ) if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
return false; 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() ); m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() );
MacPostControlCreate( pos, size ); MacPostControlCreate( pos, size );
@@ -89,197 +95,105 @@ void wxComboBox::DelegateChoice( const wxString& value )
SetStringSelection( 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()
{
wxFAIL_MSG("Method Not Implemented.");
}
void wxComboBox::SetEditable(bool editable)
{
wxFAIL_MSG("Method Not Implemented.");
}
void wxComboBox::SetInsertionPoint(long pos)
{
wxFAIL_MSG("Method Not Implemented.");
}
void wxComboBox::SetInsertionPointEnd()
{
wxFAIL_MSG("Method Not Implemented.");
}
long wxComboBox::GetInsertionPoint() const
{
wxFAIL_MSG("Method Not Implemented.");
return 0;
}
wxTextPos wxComboBox::GetLastPosition() const
{
wxFAIL_MSG("Method Not Implemented.");
return 0;
}
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, int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
unsigned int pos, unsigned int pos,
void **clientData, wxClientDataType type) void **clientData, wxClientDataType type)
{ {
wxFAIL_MSG("Method Not Implemented."); const unsigned int numItems = items.GetCount();
return 0; for( unsigned int i = 0; i < numItems; ++i, ++pos )
{
unsigned int idx;
idx = pos;
GetComboPeer()->InsertItem( idx, items[i] );
if (idx > m_datas.GetCount())
m_datas.SetCount(idx);
m_datas.Insert( NULL, idx );
AssignNewItemClientData(idx, clientData, i, type);
} }
m_peer->SetMaximum( GetCount() );
return pos - 1;
}
// ----------------------------------------------------------------------------
// client data
// ----------------------------------------------------------------------------
void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
{ {
wxFAIL_MSG("Method Not Implemented."); wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") );
m_datas[n] = (char*)clientData ;
} }
void * wxComboBox::DoGetItemClientData(unsigned int n) const void * wxComboBox::DoGetItemClientData(unsigned int n) const
{ {
wxFAIL_MSG("Method Not Implemented."); wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") );
return NULL;
return (void *)m_datas[n];
} }
unsigned int wxComboBox::GetCount() const unsigned int wxComboBox::GetCount() const
{ {
wxFAIL_MSG("Method Not Implemented."); return GetComboPeer()->GetNumberOfItems();
return 0;
} }
void wxComboBox::DoDeleteOneItem(unsigned int n) void wxComboBox::DoDeleteOneItem(unsigned int n)
{ {
wxFAIL_MSG("Method Not Implemented."); GetComboPeer()->RemoveItem(n);
} }
void wxComboBox::DoClear() void wxComboBox::DoClear()
{ {
wxFAIL_MSG("Method Not Implemented."); GetComboPeer()->Clear();
} SetValue(wxEmptyString);
int wxComboBox::GetSelection() const
{
wxFAIL_MSG("Method Not Implemented.");
return 0;
} }
void wxComboBox::GetSelection(long *from, long *to) const void wxComboBox::GetSelection(long *from, long *to) const
{ {
wxFAIL_MSG("Method Not Implemented."); wxTextEntry::GetSelection(from, to);
}
int wxComboBox::GetSelection() const
{
return GetComboPeer()->GetSelectedItem();
} }
void wxComboBox::SetSelection(int n) void wxComboBox::SetSelection(int n)
{ {
wxFAIL_MSG("Method Not Implemented."); GetComboPeer()->SetSelectedItem(n);
}
void wxComboBox::SetSelection(long from, long to)
{
wxTextEntry::SetSelection(from, to);
} }
int wxComboBox::FindString(const wxString& s, bool bCase) const int wxComboBox::FindString(const wxString& s, bool bCase) const
{ {
wxFAIL_MSG("Method Not Implemented."); if (!bCase)
return 0; wxLogWarning("wxComboBox::FindString on Mac doesn't currently support case insensitive search.");
return GetComboPeer()->FindString(s);
} }
wxString wxComboBox::GetString(unsigned int n) const wxString wxComboBox::GetString(unsigned int n) const
{ {
wxFAIL_MSG("Method Not Implemented."); return GetComboPeer()->GetStringAtIndex(n);
return wxEmptyString;
} }
wxString wxComboBox::GetStringSelection() const wxString wxComboBox::GetStringSelection() const
{ {
wxFAIL_MSG("Method Not Implemented."); return GetString(GetSelection());
return wxEmptyString;
} }
void wxComboBox::SetString(unsigned int n, const wxString& s) void wxComboBox::SetString(unsigned int n, const wxString& s)
{ {
wxFAIL_MSG("Method Not Implemented."); Delete(n);
} Insert(s, n);
SetValue(s); // changing the item in the list won't update the display item
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;
} }
void wxComboBox::EnableTextChangedEvents(bool enable) void wxComboBox::EnableTextChangedEvents(bool enable)
@@ -287,28 +201,6 @@ void wxComboBox::EnableTextChangedEvents(bool enable)
wxFAIL_MSG("Method Not Implemented."); 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 ) bool wxComboBox::OSXHandleClicked( double timestampsec )
{ {
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
@@ -319,4 +211,14 @@ bool wxComboBox::OSXHandleClicked( double timestampsec )
return true; 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

View File

@@ -163,16 +163,6 @@ void wxTextCtrl::MacCheckSpelling(bool check)
GetTextPeer()->CheckSpelling(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) void wxTextCtrl::SetMaxLength(unsigned long len)
{ {
m_maxLength = len ; m_maxLength = len ;
@@ -204,132 +194,11 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
return true ; 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 bool wxTextCtrl::IsModified() const
{ {
return m_dirty; return m_dirty;
} }
bool wxTextCtrl::IsEditable() const
{
return IsEnabled() && m_editable ;
}
bool wxTextCtrl::AcceptsFocus() const bool wxTextCtrl::AcceptsFocus() const
{ {
// we don't want focus if we can't be edited // 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); 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() void wxTextCtrl::MarkDirty()
{ {
m_dirty = true; m_dirty = true;
@@ -458,10 +295,45 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
return GetTextPeer()->GetLineText(lineNo) ; return GetTextPeer()->GetLineText(lineNo) ;
} }
void wxTextCtrl::Command(wxCommandEvent & event) void wxTextCtrl::Remove(long from, long to)
{ {
SetValue(event.GetString()); wxTextEntry::Remove(from, to);
ProcessCommand(event); 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) void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
@@ -614,10 +486,18 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
#endif #endif
} }
void wxTextCtrl::Command(wxCommandEvent & event)
{
SetValue(event.GetString());
ProcessCommand(event);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// standard handlers for standard edit menu events // 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)) void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
{ {
Cut(); Cut();
@@ -695,8 +575,6 @@ void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
event.Enable(GetLastPosition() > 0); event.Enable(GetLastPosition() > 0);
} }
// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
{ {
if ( GetTextPeer()->HasOwnContextMenu() ) if ( GetTextPeer()->HasOwnContextMenu() )

210
src/osx/textentry_osx.cpp Normal file
View File

@@ -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