]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlsub.cpp
correcting CGImage handling to be always correctly initialized and freed on OSX build...
[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
34// ============================================================================
8ba7c771 35// wxItemContainerImmutable implementation
6c8a980f
VZ
36// ============================================================================
37
8ba7c771 38wxItemContainerImmutable::~wxItemContainerImmutable()
799ea011
GD
39{
40 // this destructor is required for Darwin
41}
42
6c8a980f
VZ
43// ----------------------------------------------------------------------------
44// selection
45// ----------------------------------------------------------------------------
46
8ba7c771 47wxString wxItemContainerImmutable::GetStringSelection() const
6c8a980f
VZ
48{
49 wxString s;
50 int sel = GetSelection();
51 if ( sel != -1 )
52 s = GetString(sel);
53
54 return s;
55}
56
8ba7c771 57bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
64fa6f16
VZ
58{
59 const int sel = FindString(s);
60 if ( sel == wxNOT_FOUND )
61 return false;
62
c6179a84 63 SetSelection(sel);
64fa6f16
VZ
64
65 return true;
66}
67
8ba7c771 68wxArrayString wxItemContainerImmutable::GetStrings() const
b8d5be01 69{
8ba7c771
VZ
70 wxArrayString result;
71
72 const size_t count = GetCount();
73 result.Alloc(count);
74 for ( size_t n = 0; n < count; n++ )
b8d5be01 75 result.Add(GetString(n));
8ba7c771
VZ
76
77 return result;
78}
79
80// ============================================================================
81// wxItemContainer implementation
82// ============================================================================
83
84wxItemContainer::~wxItemContainer()
85{
86 // this destructor is required for Darwin
b8d5be01
SC
87}
88
0e0bc921
VZ
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
243dbf1a
VZ
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
6c8a980f
VZ
121// ----------------------------------------------------------------------------
122// client data
123// ----------------------------------------------------------------------------
124
1e6feb95 125void wxItemContainer::SetClientObject(int n, wxClientData *data)
6c8a980f 126{
1e6feb95 127 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
6c8a980f
VZ
128 wxT("can't have both object and void client data") );
129
da6069e2
VZ
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 }
6c8a980f
VZ
144
145 DoSetItemClientObject(n, data);
6c8a980f
VZ
146}
147
1e6feb95 148wxClientData *wxItemContainer::GetClientObject(int n) const
6c8a980f 149{
1e6feb95 150 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
6c8a980f
VZ
151 wxT("this window doesn't have object client data") );
152
153 return DoGetItemClientObject(n);
154}
155
1e6feb95 156void wxItemContainer::SetClientData(int n, void *data)
6c8a980f 157{
1e6feb95 158 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
6c8a980f
VZ
159 wxT("can't have both object and void client data") );
160
161 DoSetItemClientData(n, data);
1e6feb95 162 m_clientDataItemsType = wxClientData_Void;
6c8a980f
VZ
163}
164
1e6feb95 165void *wxItemContainer::GetClientData(int n) const
6c8a980f 166{
1e6feb95 167 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
6c8a980f
VZ
168 wxT("this window doesn't have void client data") );
169
170 return DoGetItemClientData(n);
171}
172
7c720ce6
GD
173wxControlWithItems::~wxControlWithItems()
174{
175 // this destructor is required for Darwin
176}
177
1e6feb95 178#endif // wxUSE_CONTROLS