]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
removed multiple duplicate copies (with subtly different behaviour) of SetStringSelec...
[wxWidgets.git] / src / common / ctrlsub.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/ctrlsub.cpp
3 // Purpose: wxItemContainer implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 22.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "controlwithitems.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_CONTROLS
32
33 #ifndef WX_PRECOMP
34 #include "wx/ctrlsub.h"
35 #include "wx/arrstr.h"
36 #endif
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 wxItemContainer::~wxItemContainer()
43 {
44 // this destructor is required for Darwin
45 }
46
47 // ----------------------------------------------------------------------------
48 // selection
49 // ----------------------------------------------------------------------------
50
51 wxString wxItemContainer::GetStringSelection() const
52 {
53 wxString s;
54 int sel = GetSelection();
55 if ( sel != -1 )
56 s = GetString(sel);
57
58 return s;
59 }
60
61 bool wxItemContainer::SetStringSelection(const wxString& s)
62 {
63 const int sel = FindString(s);
64 if ( sel == wxNOT_FOUND )
65 return false;
66
67 Select(sel);
68
69 return true;
70 }
71
72 wxArrayString wxItemContainer::GetStrings() const
73 {
74 wxArrayString result ;
75 size_t count = GetCount() ;
76 for ( size_t n = 0 ; n < count ; n++ )
77 result.Add(GetString(n));
78 return result ;
79 }
80
81 // ----------------------------------------------------------------------------
82 // appending items
83 // ----------------------------------------------------------------------------
84
85 void wxItemContainer::Append(const wxArrayString& strings)
86 {
87 size_t count = strings.GetCount();
88 for ( size_t n = 0; n < count; n++ )
89 {
90 Append(strings[n]);
91 }
92 }
93
94 int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
95 {
96 int n = DoInsert(item, pos);
97 if ( n != wxNOT_FOUND )
98 SetClientData(n, clientData);
99
100 return n;
101 }
102
103 int
104 wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
105 {
106 int n = DoInsert(item, pos);
107 if ( n != wxNOT_FOUND )
108 SetClientObject(n, clientData);
109
110 return n;
111 }
112
113 // ----------------------------------------------------------------------------
114 // client data
115 // ----------------------------------------------------------------------------
116
117 void wxItemContainer::SetClientObject(int n, wxClientData *data)
118 {
119 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
120 wxT("can't have both object and void client data") );
121
122 // when we call SetClientObject() for the first time, m_clientDataItemsType
123 // is still wxClientData_None and so calling DoGetItemClientObject() would
124 // fail (in addition to being useless) - don't do it
125 if ( m_clientDataItemsType == wxClientData_Object )
126 {
127 wxClientData *clientDataOld = DoGetItemClientObject(n);
128 if ( clientDataOld )
129 delete clientDataOld;
130 }
131 else // m_clientDataItemsType == wxClientData_None
132 {
133 // now we have object client data
134 m_clientDataItemsType = wxClientData_Object;
135 }
136
137 DoSetItemClientObject(n, data);
138 }
139
140 wxClientData *wxItemContainer::GetClientObject(int n) const
141 {
142 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
143 wxT("this window doesn't have object client data") );
144
145 return DoGetItemClientObject(n);
146 }
147
148 void wxItemContainer::SetClientData(int n, void *data)
149 {
150 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
151 wxT("can't have both object and void client data") );
152
153 DoSetItemClientData(n, data);
154 m_clientDataItemsType = wxClientData_Void;
155 }
156
157 void *wxItemContainer::GetClientData(int n) const
158 {
159 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
160 wxT("this window doesn't have void client data") );
161
162 return DoGetItemClientData(n);
163 }
164
165 wxControlWithItems::~wxControlWithItems()
166 {
167 // this destructor is required for Darwin
168 }
169
170 #if WXWIN_COMPATIBILITY_2_2
171
172 int wxItemContainer::Number() const
173 {
174 return GetCount();
175 }
176
177 #endif // WXWIN_COMPATIBILITY_2_2
178
179 #endif // wxUSE_CONTROLS