]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlsub.cpp
Applied patch [ 1204548 ] Add Get and SetVolume to wxMediaCtrl and fix bug 1200182
[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
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
6c8a980f
VZ
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
1e6feb95
VZ
31#if wxUSE_CONTROLS
32
6c8a980f
VZ
33#ifndef WX_PRECOMP
34 #include "wx/ctrlsub.h"
a9711a4d 35 #include "wx/arrstr.h"
6c8a980f
VZ
36#endif
37
38// ============================================================================
8ba7c771 39// wxItemContainerImmutable implementation
6c8a980f
VZ
40// ============================================================================
41
8ba7c771 42wxItemContainerImmutable::~wxItemContainerImmutable()
799ea011
GD
43{
44 // this destructor is required for Darwin
45}
46
6c8a980f
VZ
47// ----------------------------------------------------------------------------
48// selection
49// ----------------------------------------------------------------------------
50
8ba7c771 51wxString wxItemContainerImmutable::GetStringSelection() const
6c8a980f
VZ
52{
53 wxString s;
54 int sel = GetSelection();
55 if ( sel != -1 )
56 s = GetString(sel);
57
58 return s;
59}
60
8ba7c771 61bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
64fa6f16
VZ
62{
63 const int sel = FindString(s);
64 if ( sel == wxNOT_FOUND )
65 return false;
66
c6179a84 67 SetSelection(sel);
64fa6f16
VZ
68
69 return true;
70}
71
8ba7c771 72wxArrayString wxItemContainerImmutable::GetStrings() const
b8d5be01 73{
8ba7c771
VZ
74 wxArrayString result;
75
76 const size_t count = GetCount();
77 result.Alloc(count);
78 for ( size_t n = 0; n < count; n++ )
b8d5be01 79 result.Add(GetString(n));
8ba7c771
VZ
80
81 return result;
82}
83
84// ============================================================================
85// wxItemContainer implementation
86// ============================================================================
87
88wxItemContainer::~wxItemContainer()
89{
90 // this destructor is required for Darwin
b8d5be01
SC
91}
92
0e0bc921
VZ
93// ----------------------------------------------------------------------------
94// appending items
95// ----------------------------------------------------------------------------
96
97void 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
243dbf1a
VZ
106int 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
115int
116wxItemContainer::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
6c8a980f
VZ
125// ----------------------------------------------------------------------------
126// client data
127// ----------------------------------------------------------------------------
128
1e6feb95 129void wxItemContainer::SetClientObject(int n, wxClientData *data)
6c8a980f 130{
1e6feb95 131 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
6c8a980f
VZ
132 wxT("can't have both object and void client data") );
133
da6069e2
VZ
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 }
6c8a980f
VZ
148
149 DoSetItemClientObject(n, data);
6c8a980f
VZ
150}
151
1e6feb95 152wxClientData *wxItemContainer::GetClientObject(int n) const
6c8a980f 153{
1e6feb95 154 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
6c8a980f
VZ
155 wxT("this window doesn't have object client data") );
156
157 return DoGetItemClientObject(n);
158}
159
1e6feb95 160void wxItemContainer::SetClientData(int n, void *data)
6c8a980f 161{
1e6feb95 162 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
6c8a980f
VZ
163 wxT("can't have both object and void client data") );
164
165 DoSetItemClientData(n, data);
1e6feb95 166 m_clientDataItemsType = wxClientData_Void;
6c8a980f
VZ
167}
168
1e6feb95 169void *wxItemContainer::GetClientData(int n) const
6c8a980f 170{
1e6feb95 171 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
6c8a980f
VZ
172 wxT("this window doesn't have void client data") );
173
174 return DoGetItemClientData(n);
175}
176
7c720ce6
GD
177wxControlWithItems::~wxControlWithItems()
178{
179 // this destructor is required for Darwin
180}
181
1e6feb95 182#endif // wxUSE_CONTROLS