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