Permalink
Browse files

Implement native OS X ComboBox for OS X Cocoa, and implement wxTextEn…

…try 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
  • Loading branch information...
kollivier committed Jan 9, 2010
1 parent 4f42c05 commit c84030e020e56735cb4b7c1534e99d21a8bb48c0
@@ -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
@@ -12,14 +12,15 @@
#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
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 @@ class wxNSTextViewControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
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_
View
@@ -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 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
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,15 +180,19 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
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);
// the subcontrols
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
//
View
@@ -69,17 +69,10 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
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 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
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 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
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 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
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
Oops, something went wrong.

0 comments on commit c84030e

Please sign in to comment.