wxControl and wxChoice derive from the base classes under wxGTK too now
[wxWidgets.git] / include / wx / choice.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/choice.h
3 // Purpose: wxChoice class interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CHOICE_H_BASE_
13 #define _WX_CHOICE_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #ifdef __GNUG__
20 #pragma interface "choicebase.h"
21 #endif
22
23 #include "wx/control.h" // the base class
24
25 // ----------------------------------------------------------------------------
26 // global data
27 // ----------------------------------------------------------------------------
28
29 WXDLLEXPORT_DATA(extern const wxChar*) wxChoiceNameStr;
30
31 // ----------------------------------------------------------------------------
32 // wxChoice allows to select one of a non-modifiable list of strings
33 // ----------------------------------------------------------------------------
34
35 class WXDLLEXPORT wxChoiceBase : public wxControl
36 {
37 public:
38 // ctor
39 wxChoiceBase() { m_clientDataItemsType = ClientData_None; }
40
41 // add a new item to the list
42 // no client data
43 void Append(const wxString& item) { DoAppend(item); }
44 // with client data which belongs to the caller
45 void Append(const wxString &item, void* clientData)
46 { int n = DoAppend(item); SetClientData(n, clientData); }
47 // with client data which will be deleted by the control
48 void Append(const wxString &item, wxClientData* clientData)
49 { int n = DoAppend(item); SetClientObject(n, clientData); }
50
51 // delete items from the list
52 // one item
53 virtual void Delete(int n) = 0;
54 // all of them
55 virtual void Clear() = 0;
56
57 // selection (at most one item may be selected in wxChoice)
58 // get the index of currently selected item or -1
59 virtual int GetSelection() const = 0;
60 // get the text of the currently selected item or empty string
61 virtual wxString GetStringSelection() const;
62
63 // set selectionto current item
64 virtual void SetSelection(int n) = 0;
65 // set selection to the current item, returns TRUE if ok
66 virtual bool SetStringSelection(const wxString& sel);
67
68 // accessors to the list of strings
69 // get the number of items in the list of strings
70 virtual int GetCount() const = 0;
71
72 // find string in the list, return wxNOT_FOUND if not found
73 virtual int FindString(const wxString& s) const = 0;
74 // get the string with the specified index
75 virtual wxString GetString(int n) const = 0;
76
77 // set/get the number of columns in the control (as they're not supporte on
78 // most platforms, they do nothing by default)
79 virtual void SetColumns(int WXUNUSED(n) = 1 ) { }
80 virtual int GetColumns() const { return 1 ; }
81
82 // client data
83 // untyped (isn't deleted by the control)
84 void SetClientData( int n, void* clientData );
85 void* GetClientData( int n ) const;
86 // typed (is owned and deleted by the control)
87 void SetClientObject( int n, wxClientData* clientData );
88 wxClientData* GetClientObject( int n ) const;
89
90 // emulate selecting the item event.GetInt() from the control
91 virtual void Command(wxCommandEvent &event);
92
93 // deprecated functions, heer for backwards compatibility only
94 int Number() const { return GetCount(); }
95
96 protected:
97 // pure virtuals to implement in the derived classes
98 virtual int DoAppend(const wxString& item) = 0;
99
100 virtual void DoSetClientData( int n, void* clientData ) = 0;
101 virtual void* DoGetClientData( int n ) const = 0;
102 virtual void DoSetClientObject( int n, wxClientData* clientData ) = 0;
103 virtual wxClientData* DoGetClientObject( int n ) const = 0;
104
105 // the above pure virtuals hide these virtuals in wxWindowBase
106 virtual void DoSetClientData(void* clientData )
107 { wxWindowBase::DoSetClientData(clientData); };
108 virtual void* DoGetClientData() const
109 { return(wxWindowBase::DoGetClientData()); };
110 virtual void DoSetClientObject( wxClientData* clientData )
111 { wxWindowBase::DoSetClientObject(clientData); };
112 virtual wxClientData* DoGetClientObject() const
113 { return(wxWindowBase::DoGetClientObject()); };
114
115 // the type of the client data for the items
116 wxClientDataType m_clientDataItemsType;
117 };
118
119 // ----------------------------------------------------------------------------
120 // include the platform-dependent class definition
121 // ----------------------------------------------------------------------------
122
123 #if defined(__WXMSW__)
124 #include "wx/msw/choice.h"
125 #elif defined(__WXMOTIF__)
126 #include "wx/motif/choice.h"
127 #elif defined(__WXGTK__)
128 #include "wx/gtk/choice.h"
129 #elif defined(__WXQT__)
130 #include "wx/qt/choice.h"
131 #elif defined(__WXMAC__)
132 #include "wx/mac/choice.h"
133 #elif defined(__WXPM__)
134 #include "wx/os2/choice.h"
135 #elif defined(__WXSTUBS__)
136 #include "wx/stubs/choice.h"
137 #endif
138
139 #endif
140 // _WX_CHOICE_H_BASE_