1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/osx/combobox.h
3 // Purpose:     wxComboBox class
4 // Author:      Stefan Csomor
5 // Modified by:
6 // Created:     1998-01-01
7 // Copyright:   (c) Stefan Csomor
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_COMBOBOX_H_
12 #define _WX_COMBOBOX_H_
13 
14 #include "wx/containr.h"
15 #include "wx/choice.h"
16 #include "wx/textctrl.h"
17 
18 WX_DEFINE_ARRAY( char * , wxComboBoxDataArray ) ;
19 
20 // forward declaration of private implementation classes
21 
22 class wxComboBoxText;
23 class wxComboBoxChoice;
24 class wxComboWidgetImpl;
25 
26 // Combobox item
27 class WXDLLIMPEXP_CORE wxComboBox :
28     public wxWindowWithItems<
29                 wxControl,
30                 wxComboBoxBase>
31 {
32     wxDECLARE_DYNAMIC_CLASS(wxComboBox);
33 
34  public:
35     virtual ~wxComboBox();
36 
37     // callback functions
38     virtual void DelegateTextChanged( const wxString& value );
39     virtual void DelegateChoice( const wxString& value );
40 
wxComboBox()41     wxComboBox() { }
42 
43     wxComboBox(wxWindow *parent, wxWindowID id,
44            const wxString& value = wxEmptyString,
45            const wxPoint& pos = wxDefaultPosition,
46            const wxSize& size = wxDefaultSize,
47            int n = 0, const wxString choices[] = NULL,
48            long style = 0,
49            const wxValidator& validator = wxDefaultValidator,
50            const wxString& name = wxASCII_STR(wxComboBoxNameStr))
51     {
52         Create(parent, id, value, pos, size, n, choices, style, validator, name);
53     }
54 
55     wxComboBox(wxWindow *parent, wxWindowID id,
56            const wxString& value,
57            const wxPoint& pos,
58            const wxSize& size,
59            const wxArrayString& choices,
60            long style = 0,
61            const wxValidator& validator = wxDefaultValidator,
62            const wxString& name = wxASCII_STR(wxComboBoxNameStr))
63     {
64         Create(parent, id, value, pos, size, choices, style, validator, name);
65     }
66 
67     bool Create(wxWindow *parent, wxWindowID id,
68            const wxString& value = wxEmptyString,
69            const wxPoint& pos = wxDefaultPosition,
70            const wxSize& size = wxDefaultSize,
71            int n = 0, const wxString choices[] = NULL,
72            long style = 0,
73            const wxValidator& validator = wxDefaultValidator,
74            const wxString& name = wxASCII_STR(wxComboBoxNameStr));
75 
76     bool Create(wxWindow *parent, wxWindowID id,
77            const wxString& value,
78            const wxPoint& pos,
79            const wxSize& size,
80            const wxArrayString& choices,
81            long style = 0,
82            const wxValidator& validator = wxDefaultValidator,
83            const wxString& name = wxASCII_STR(wxComboBoxNameStr));
84 
85     virtual int GetSelection() const wxOVERRIDE;
86     virtual void GetSelection(long *from, long *to) const wxOVERRIDE;
87     virtual void SetSelection(int n) wxOVERRIDE;
88     virtual void SetSelection(long from, long to) wxOVERRIDE;
89     virtual int FindString(const wxString& s, bool bCase = false) const wxOVERRIDE;
90     virtual wxString GetString(unsigned int n) const wxOVERRIDE;
91     virtual wxString GetStringSelection() const wxOVERRIDE;
92     virtual void SetString(unsigned int n, const wxString& s) wxOVERRIDE;
93 
94     virtual unsigned int GetCount() const wxOVERRIDE;
95 
96     virtual void SetValue(const wxString& value) wxOVERRIDE;
97 // these methods are provided by wxTextEntry for the native impl.
98 
99 #if wxOSX_USE_COCOA
100     virtual void Popup() wxOVERRIDE;
101     virtual void Dismiss() wxOVERRIDE;
102 #endif // wxOSX_USE_COCOA
103 
104 
WXGetTextEntry()105     virtual const wxTextEntry* WXGetTextEntry() const wxOVERRIDE { return this; }
106 
107     // osx specific event handling common for all osx-ports
108 
109     virtual bool OSXHandleClicked(double timestampsec) wxOVERRIDE;
110 
111 #if wxOSX_USE_COCOA
112     wxComboWidgetImpl* GetComboPeer() const;
113 #endif
114 protected:
115     // List functions
116     virtual void DoDeleteOneItem(unsigned int n) wxOVERRIDE;
117     virtual void DoClear() wxOVERRIDE;
118 
119     // wxTextEntry functions
GetEditableWindow()120     virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; }
121 
122     // override the base class virtuals involved in geometry calculations
123     virtual wxSize DoGetBestSize() const wxOVERRIDE;
124 
125     virtual int DoInsertItems(const wxArrayStringsAdapter& items,
126                               unsigned int pos,
127                               void **clientData, wxClientDataType type) wxOVERRIDE;
128 
129     virtual void DoSetItemClientData(unsigned int n, void* clientData) wxOVERRIDE;
130     virtual void * DoGetItemClientData(unsigned int n) const wxOVERRIDE;
131 
132 
133     virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE;
134 
135     // callbacks
136     void OnChar(wxKeyEvent& event); // Process 'enter' if required
137     void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts
138 
139     // the subcontrols
140     wxComboBoxText*     m_text;
141     wxComboBoxChoice*   m_choice;
142 
143     wxComboBoxDataArray m_datas;
144 
145 private:
146     wxDECLARE_EVENT_TABLE();
147 };
148 
149 #endif // _WX_COMBOBOX_H_
150