]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/ctrlsub.cpp
Allow wx parents a chance to handle events fired by non-wx children. (i.e. wxActiveX...
[wxWidgets.git] / src / common / ctrlsub.cpp
... / ...
CommitLineData
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// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_CONTROLS
28
29#ifndef WX_PRECOMP
30 #include "wx/ctrlsub.h"
31 #include "wx/arrstr.h"
32#endif
33
34// ============================================================================
35// wxItemContainerImmutable implementation
36// ============================================================================
37
38wxItemContainerImmutable::~wxItemContainerImmutable()
39{
40 // this destructor is required for Darwin
41}
42
43// ----------------------------------------------------------------------------
44// selection
45// ----------------------------------------------------------------------------
46
47wxString wxItemContainerImmutable::GetStringSelection() const
48{
49 wxString s;
50 int sel = GetSelection();
51 if ( sel != -1 )
52 s = GetString(sel);
53
54 return s;
55}
56
57bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
58{
59 const int sel = FindString(s);
60 if ( sel == wxNOT_FOUND )
61 return false;
62
63 SetSelection(sel);
64
65 return true;
66}
67
68wxArrayString wxItemContainerImmutable::GetStrings() const
69{
70 wxArrayString result;
71
72 const size_t count = GetCount();
73 result.Alloc(count);
74 for ( size_t n = 0; n < count; n++ )
75 result.Add(GetString(n));
76
77 return result;
78}
79
80// ============================================================================
81// wxItemContainer implementation
82// ============================================================================
83
84wxItemContainer::~wxItemContainer()
85{
86 // this destructor is required for Darwin
87}
88
89// ----------------------------------------------------------------------------
90// appending items
91// ----------------------------------------------------------------------------
92
93void wxItemContainer::Append(const wxArrayString& strings)
94{
95 size_t count = strings.GetCount();
96 for ( size_t n = 0; n < count; n++ )
97 {
98 Append(strings[n]);
99 }
100}
101
102int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
103{
104 int n = DoInsert(item, pos);
105 if ( n != wxNOT_FOUND )
106 SetClientData(n, clientData);
107
108 return n;
109}
110
111int
112wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
113{
114 int n = DoInsert(item, pos);
115 if ( n != wxNOT_FOUND )
116 SetClientObject(n, clientData);
117
118 return n;
119}
120
121// ----------------------------------------------------------------------------
122// client data
123// ----------------------------------------------------------------------------
124
125void wxItemContainer::SetClientObject(int n, wxClientData *data)
126{
127 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
128 wxT("can't have both object and void client data") );
129
130 // when we call SetClientObject() for the first time, m_clientDataItemsType
131 // is still wxClientData_None and so calling DoGetItemClientObject() would
132 // fail (in addition to being useless) - don't do it
133 if ( m_clientDataItemsType == wxClientData_Object )
134 {
135 wxClientData *clientDataOld = DoGetItemClientObject(n);
136 if ( clientDataOld )
137 delete clientDataOld;
138 }
139 else // m_clientDataItemsType == wxClientData_None
140 {
141 // now we have object client data
142 m_clientDataItemsType = wxClientData_Object;
143 }
144
145 DoSetItemClientObject(n, data);
146}
147
148wxClientData *wxItemContainer::GetClientObject(int n) const
149{
150 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
151 wxT("this window doesn't have object client data") );
152
153 return DoGetItemClientObject(n);
154}
155
156void wxItemContainer::SetClientData(int n, void *data)
157{
158 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
159 wxT("can't have both object and void client data") );
160
161 DoSetItemClientData(n, data);
162 m_clientDataItemsType = wxClientData_Void;
163}
164
165void *wxItemContainer::GetClientData(int n) const
166{
167 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
168 wxT("this window doesn't have void client data") );
169
170 return DoGetItemClientData(n);
171}
172
173wxControlWithItems::~wxControlWithItems()
174{
175 // this destructor is required for Darwin
176}
177
178#endif // wxUSE_CONTROLS