]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
Moved definition
[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 // wxItemContainerImmutable implementation
40 // ============================================================================
41
42 wxItemContainerImmutable::~wxItemContainerImmutable()
43 {
44 // this destructor is required for Darwin
45 }
46
47 // ----------------------------------------------------------------------------
48 // selection
49 // ----------------------------------------------------------------------------
50
51 wxString wxItemContainerImmutable::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 wxItemContainerImmutable::SetStringSelection(const wxString& s)
62 {
63 const int sel = FindString(s);
64 if ( sel == wxNOT_FOUND )
65 return false;
66
67 SetSelection(sel);
68
69 return true;
70 }
71
72 wxArrayString wxItemContainerImmutable::GetStrings() const
73 {
74 wxArrayString result;
75
76 const size_t count = GetCount();
77 result.Alloc(count);
78 for ( size_t n = 0; n < count; n++ )
79 result.Add(GetString(n));
80
81 return result;
82 }
83
84 // ============================================================================
85 // wxItemContainer implementation
86 // ============================================================================
87
88 wxItemContainer::~wxItemContainer()
89 {
90 // this destructor is required for Darwin
91 }
92
93 // ----------------------------------------------------------------------------
94 // appending items
95 // ----------------------------------------------------------------------------
96
97 void wxItemContainer::Append(const wxArrayString& strings)
98 {
99 size_t count = strings.GetCount();
100 for ( size_t n = 0; n < count; n++ )
101 {
102 Append(strings[n]);
103 }
104 }
105
106 int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
107 {
108 int n = DoInsert(item, pos);
109 if ( n != wxNOT_FOUND )
110 SetClientData(n, clientData);
111
112 return n;
113 }
114
115 int
116 wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
117 {
118 int n = DoInsert(item, pos);
119 if ( n != wxNOT_FOUND )
120 SetClientObject(n, clientData);
121
122 return n;
123 }
124
125 // ----------------------------------------------------------------------------
126 // client data
127 // ----------------------------------------------------------------------------
128
129 void wxItemContainer::SetClientObject(int n, wxClientData *data)
130 {
131 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
132 wxT("can't have both object and void client data") );
133
134 // when we call SetClientObject() for the first time, m_clientDataItemsType
135 // is still wxClientData_None and so calling DoGetItemClientObject() would
136 // fail (in addition to being useless) - don't do it
137 if ( m_clientDataItemsType == wxClientData_Object )
138 {
139 wxClientData *clientDataOld = DoGetItemClientObject(n);
140 if ( clientDataOld )
141 delete clientDataOld;
142 }
143 else // m_clientDataItemsType == wxClientData_None
144 {
145 // now we have object client data
146 m_clientDataItemsType = wxClientData_Object;
147 }
148
149 DoSetItemClientObject(n, data);
150 }
151
152 wxClientData *wxItemContainer::GetClientObject(int n) const
153 {
154 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
155 wxT("this window doesn't have object client data") );
156
157 return DoGetItemClientObject(n);
158 }
159
160 void wxItemContainer::SetClientData(int n, void *data)
161 {
162 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
163 wxT("can't have both object and void client data") );
164
165 DoSetItemClientData(n, data);
166 m_clientDataItemsType = wxClientData_Void;
167 }
168
169 void *wxItemContainer::GetClientData(int n) const
170 {
171 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
172 wxT("this window doesn't have void client data") );
173
174 return DoGetItemClientData(n);
175 }
176
177 wxControlWithItems::~wxControlWithItems()
178 {
179 // this destructor is required for Darwin
180 }
181
182 #endif // wxUSE_CONTROLS