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:
@@ -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_
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/mac/carbon/combobox.h
|
||||
// Name: wx/osx/combobox.h
|
||||
// Purpose: wxComboBox class
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
@@ -14,13 +14,17 @@
|
||||
|
||||
#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
|
||||
};
|
||||
|
@@ -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
|
||||
//
|
||||
|
@@ -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
|
||||
|
107
include/wx/osx/textentry.h
Normal file
107
include/wx/osx/textentry.h
Normal 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_
|
Reference in New Issue
Block a user