]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlsub.cpp
Don't delete model in views destructor as several
[wxWidgets.git] / src / common / ctrlsub.cpp
CommitLineData
6c8a980f
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: 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;
52 int sel = GetSelection();
53 if ( sel != -1 )
54 s = GetString(sel);
55
56 return s;
57}
58
8ba7c771 59bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
64fa6f16
VZ
60{
61 const int sel = FindString(s);
62 if ( sel == wxNOT_FOUND )
63 return false;
64
c6179a84 65 SetSelection(sel);
64fa6f16
VZ
66
67 return true;
68}
69
8ba7c771 70wxArrayString wxItemContainerImmutable::GetStrings() const
b8d5be01 71{
8ba7c771
VZ
72 wxArrayString result;
73
74 const size_t count = GetCount();
75 result.Alloc(count);
76 for ( size_t n = 0; n < count; n++ )
b8d5be01 77 result.Add(GetString(n));
8ba7c771
VZ
78
79 return result;
80}
81
82// ============================================================================
83// wxItemContainer implementation
84// ============================================================================
85
86wxItemContainer::~wxItemContainer()
87{
88 // this destructor is required for Darwin
b8d5be01
SC
89}
90
0e0bc921
VZ
91// ----------------------------------------------------------------------------
92// appending items
93// ----------------------------------------------------------------------------
94
95void wxItemContainer::Append(const wxArrayString& strings)
96{
97 size_t count = strings.GetCount();
98 for ( size_t n = 0; n < count; n++ )
99 {
100 Append(strings[n]);
101 }
102}
103
243dbf1a
VZ
104int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
105{
106 int n = DoInsert(item, pos);
107 if ( n != wxNOT_FOUND )
108 SetClientData(n, clientData);
109
110 return n;
111}
112
113int
114wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
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
1e6feb95 127void wxItemContainer::SetClientObject(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
1e6feb95 150wxClientData *wxItemContainer::GetClientObject(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
1e6feb95 158void wxItemContainer::SetClientData(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
1e6feb95 167void *wxItemContainer::GetClientData(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
7c720ce6
GD
175wxControlWithItems::~wxControlWithItems()
176{
177 // this destructor is required for Darwin
178}
179
1e6feb95 180#endif // wxUSE_CONTROLS