Skip to content

Commit c84030e

Browse files
committed
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
1 parent 4f42c05 commit c84030e

File tree

13 files changed

+613
-391
lines changed

13 files changed

+613
-391
lines changed

build/bakefiles/files.bkl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
22492249
src/osx/statbox_osx.cpp
22502250
src/osx/statline_osx.cpp
22512251
src/osx/stattext_osx.cpp
2252+
src/osx/textentry_osx.cpp
22522253
src/osx/textctrl_osx.cpp
22532254
src/osx/tglbtn_osx.cpp
22542255
src/osx/toolbar_osx.cpp

include/wx/osx/cocoa/private/textimpl.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
#ifndef _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
1313
#define _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
1414

15+
#include "wx/combobox.h"
1516
#include "wx/osx/private.h"
1617

1718
// implementation exposed, so that search control can pull it
1819

1920
class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
2021
{
2122
public :
22-
wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w );
23+
wxNSTextFieldControl( wxWindow *wxPeer, WXWidget w );
2324
virtual ~wxNSTextFieldControl();
2425

2526
virtual wxString GetStringValue() const ;
@@ -69,4 +70,27 @@ class wxNSTextViewControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
6970
NSTextView* m_textView;
7071
};
7172

73+
class wxNSComboBoxControl : public wxNSTextFieldControl, public wxComboWidgetImpl
74+
{
75+
public :
76+
wxNSComboBoxControl( wxWindow *wxPeer, WXWidget w );
77+
virtual ~wxNSComboBoxControl();
78+
79+
virtual int GetSelectedItem() const;
80+
virtual void SetSelectedItem(int item);
81+
82+
virtual int GetNumberOfItems() const;
83+
84+
virtual void InsertItem(int pos, const wxString& item);
85+
virtual void RemoveItem(int pos);
86+
87+
virtual void Clear();
88+
89+
virtual wxString GetStringAtIndex(int pos) const;
90+
91+
virtual int FindString(const wxString& text) const;
92+
private:
93+
NSComboBox* m_comboBox;
94+
};
95+
7296
#endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_

include/wx/osx/combobox.h

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/////////////////////////////////////////////////////////////////////////////
2-
// Name: wx/mac/carbon/combobox.h
2+
// Name: wx/osx/combobox.h
33
// Purpose: wxComboBox class
44
// Author: Stefan Csomor
55
// Modified by:
@@ -14,13 +14,17 @@
1414

1515
#include "wx/containr.h"
1616
#include "wx/choice.h"
17+
#include "wx/textctrl.h"
1718

1819
WXDLLIMPEXP_DATA_CORE(extern const char) wxComboBoxNameStr[];
1920

21+
WX_DEFINE_ARRAY( char * , wxComboBoxDataArray ) ;
22+
2023
// forward declaration of private implementation classes
2124

2225
class wxComboBoxText;
2326
class wxComboBoxChoice;
27+
class wxComboWidgetImpl;
2428

2529
// Combobox item
2630
class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
@@ -30,7 +34,7 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
3034
public:
3135
virtual ~wxComboBox();
3236

33-
#ifndef wxOSX_USE_NATIVE_COMBOBOX
37+
#if wxOSX_USE_CARBON
3438
// forward these functions to all subcontrols
3539
virtual bool Enable(bool enable = true);
3640
virtual bool Show(bool show = true);
@@ -87,17 +91,22 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
8791
const wxString& name = wxComboBoxNameStr);
8892

8993
virtual int GetSelection() const;
94+
virtual void GetSelection(long *from, long *to) const;
9095
virtual void SetSelection(int n);
96+
virtual void SetSelection(long from, long to);
9197
virtual int FindString(const wxString& s, bool bCase = false) const;
9298
virtual wxString GetString(unsigned int n) const;
9399
virtual wxString GetStringSelection() const;
94100
virtual void SetString(unsigned int n, const wxString& s);
95101

102+
virtual unsigned int GetCount() const;
103+
104+
// these methods are provided by wxTextEntry for the native impl.
105+
#if wxOSX_USE_CARBON
96106
// Text field functions
97107
virtual void SetValue(const wxString& value);
98108
virtual wxString GetValue() const;
99109
virtual void WriteText(const wxString& text);
100-
virtual void GetSelection(long *from, long *to) const;
101110

102111
// Clipboard operations
103112
virtual void Copy();
@@ -109,12 +118,9 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
109118
virtual wxTextPos GetLastPosition() const;
110119
virtual void Replace(long from, long to, const wxString& value);
111120
virtual void Remove(long from, long to);
112-
virtual void SetSelection(long from, long to);
113121
virtual void SetEditable(bool editable);
114122
virtual bool IsEditable() const;
115123

116-
virtual unsigned int GetCount() const;
117-
118124
virtual void Undo();
119125
virtual void Redo();
120126
virtual void SelectAll();
@@ -126,17 +132,27 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
126132
virtual bool CanRedo() const;
127133

128134
virtual wxClientDataType GetClientDataType() const;
135+
#endif
136+
137+
129138

130139
// osx specific event handling common for all osx-ports
131140

132141
virtual bool OSXHandleClicked( double timestampsec );
133142

134-
#ifndef wxOSX_USE_NATIVE_COMBOBOX
143+
#if wxOSX_USE_CARBON
135144
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
136145

137146
WX_DECLARE_CONTROL_CONTAINER();
138147
#endif
139148

149+
// only used by the native Cocoa combobox, but we must define it everywhere
150+
// to maintain the wxTextEntry abstraction.
151+
virtual wxTextWidgetImpl * GetTextPeer() const;
152+
153+
#if wxOSX_USE_COCOA
154+
wxComboWidgetImpl* GetComboPeer() const;
155+
#endif
140156
protected:
141157
// common part of all ctors
142158
void Init();
@@ -146,10 +162,12 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
146162
virtual void DoClear();
147163

148164
// wxTextEntry functions
165+
#if wxOSX_USE_CARBON
149166
virtual wxString DoGetValue() const;
167+
#endif
150168
virtual wxWindow *GetEditableWindow() { return this; }
151169

152-
#ifndef wxOSX_USE_NATIVE_COMBOBOX
170+
#if wxOSX_USE_CARBON
153171
// override the base class virtuals involved in geometry calculations
154172
virtual wxSize DoGetBestSize() const;
155173
virtual void DoMoveWindow(int x, int y, int width, int height);
@@ -162,15 +180,19 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
162180
virtual void DoSetItemClientData(unsigned int n, void* clientData);
163181
virtual void * DoGetItemClientData(unsigned int n) const;
164182

183+
#if wxOSX_USE_CARBON
165184
virtual void SetClientDataType(wxClientDataType clientDataItemsType);
185+
#endif
166186

167187
virtual void EnableTextChangedEvents(bool enable);
168188

169189
// the subcontrols
170190
wxComboBoxText* m_text;
171191
wxComboBoxChoice* m_choice;
172192

173-
#ifndef wxOSX_USE_NATIVE_COMBOBOX
193+
wxComboBoxDataArray m_datas;
194+
195+
#if wxOSX_USE_CARBON
174196
DECLARE_EVENT_TABLE()
175197
#endif
176198
};

include/wx/osx/core/private.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public :
470470
long style,
471471
long extraStyle);
472472

473-
#ifdef wxOSX_USE_NATIVE_COMBOBOX
473+
#if wxOSX_USE_COCOA
474474
static wxWidgetImplType* CreateComboBox( wxWindowMac* wxpeer,
475475
wxWindowMac* parent,
476476
wxWindowID id,
@@ -612,6 +612,31 @@ public :
612612
virtual wxSize GetBestSize() const { return wxDefaultSize; }
613613
};
614614

615+
// common interface for all implementations
616+
class WXDLLIMPEXP_CORE wxComboWidgetImpl
617+
618+
{
619+
public :
620+
wxComboWidgetImpl() {}
621+
622+
virtual ~wxComboWidgetImpl() {}
623+
624+
virtual int GetSelectedItem() const { return -1; };
625+
virtual void SetSelectedItem(int WXUNUSED(item)) {};
626+
627+
virtual int GetNumberOfItems() const { return -1; };
628+
629+
virtual void InsertItem(int WXUNUSED(pos), const wxString& WXUNUSED(item)) {}
630+
631+
virtual void RemoveItem(int WXUNUSED(pos)) {}
632+
633+
virtual void Clear() {}
634+
635+
virtual wxString GetStringAtIndex(int WXUNUSED(pos)) const { return wxEmptyString; }
636+
637+
virtual int FindString(const wxString& WXUNUSED(text)) const { return -1; }
638+
};
639+
615640
//
616641
// common interface for buttons
617642
//

include/wx/osx/textctrl.h

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,10 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
6969
virtual int GetNumberOfLines() const;
7070

7171
virtual bool IsModified() const;
72-
virtual bool IsEditable() const;
73-
74-
// If the return values from and to are the same, there is no selection.
75-
virtual void GetSelection(long* from, long* to) const;
7672

7773
// operations
7874
// ----------
7975

80-
// editing
81-
virtual void Clear();
82-
virtual void Remove(long from, long to);
8376

8477
// sets/clears the dirty flag
8578
virtual void MarkDirty();
@@ -97,10 +90,6 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
9790
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
9891
virtual bool SetDefaultStyle(const wxTextAttr& style);
9992

100-
// writing text inserts it at the current position;
101-
// appending always inserts it at the end
102-
virtual void WriteText(const wxString& text);
103-
10493
// translate between the position (which is just an index into the textctrl
10594
// considering all its contents as a single strings) and (x, y) coordinates
10695
// which represent column and line.
@@ -109,30 +98,13 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
10998

11099
virtual void ShowPosition(long pos);
111100

112-
// Clipboard operations
113-
virtual void Copy();
101+
// overrides so that we can send text updated events
114102
virtual void Cut();
115103
virtual void Paste();
116-
117-
virtual bool CanCopy() const;
118-
virtual bool CanCut() const;
119-
virtual bool CanPaste() const;
120-
121-
// Undo/redo
122-
virtual void Undo();
123-
virtual void Redo();
124-
125-
virtual bool CanUndo() const;
126-
virtual bool CanRedo() const;
127-
128-
// Insertion point
129-
virtual void SetInsertionPoint(long pos);
130-
virtual void SetInsertionPointEnd();
131-
virtual long GetInsertionPoint() const;
132-
virtual wxTextPos GetLastPosition() const;
133-
134-
virtual void SetSelection(long from, long to);
135-
virtual void SetEditable(bool editable);
104+
105+
virtual void WriteText(const wxString& text);
106+
virtual void Clear();
107+
virtual void Remove(long from, long to);
136108

137109
// Implementation
138110
// --------------
@@ -168,15 +140,13 @@ class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
168140
virtual void MacSuperChangedPosition();
169141
virtual void MacCheckSpelling(bool check);
170142

171-
wxTextWidgetImpl * GetTextPeer() const;
143+
virtual wxTextWidgetImpl * GetTextPeer() const;
172144
protected:
173145
// common part of all ctors
174146
void Init();
175147

176148
virtual wxSize DoGetBestSize() const;
177149

178-
virtual wxString DoGetValue() const;
179-
180150
bool m_editable;
181151

182152
// flag is set to true when the user edits the controls contents

0 commit comments

Comments
 (0)