]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
applied patch 939076: __SMARTPHONE__ define
[wxWidgets.git] / src / common / ctrlsub.cpp
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) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
31 #if wxUSE_CONTROLS
32
33 #ifndef WX_PRECOMP
34 #include "wx/ctrlsub.h"
35 #include "wx/arrstr.h"
36 #endif
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 wxItemContainer::~wxItemContainer()
43 {
44 // this destructor is required for Darwin
45 }
46
47 // ----------------------------------------------------------------------------
48 // selection
49 // ----------------------------------------------------------------------------
50
51 wxString wxItemContainer::GetStringSelection() const
52 {
53 wxString s;
54 int sel = GetSelection();
55 if ( sel != -1 )
56 s = GetString(sel);
57
58 return s;
59 }
60
61 wxArrayString wxItemContainer::GetStrings() const
62 {
63 wxArrayString result ;
64 size_t count = GetCount() ;
65 for ( size_t n = 0 ; n < count ; n++ )
66 result.Add(GetString(n));
67 return result ;
68 }
69
70 // ----------------------------------------------------------------------------
71 // appending items
72 // ----------------------------------------------------------------------------
73
74 void wxItemContainer::Append(const wxArrayString& strings)
75 {
76 size_t count = strings.GetCount();
77 for ( size_t n = 0; n < count; n++ )
78 {
79 Append(strings[n]);
80 }
81 }
82
83 int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
84 {
85 int n = DoInsert(item, pos);
86 if ( n != wxNOT_FOUND )
87 SetClientData(n, clientData);
88
89 return n;
90 }
91
92 int
93 wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
94 {
95 int n = DoInsert(item, pos);
96 if ( n != wxNOT_FOUND )
97 SetClientObject(n, clientData);
98
99 return n;
100 }
101
102 // ----------------------------------------------------------------------------
103 // client data
104 // ----------------------------------------------------------------------------
105
106 void wxItemContainer::SetClientObject(int n, wxClientData *data)
107 {
108 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
109 wxT("can't have both object and void client data") );
110
111 // when we call SetClientObject() for the first time, m_clientDataItemsType
112 // is still wxClientData_None and so calling DoGetItemClientObject() would
113 // fail (in addition to being useless) - don't do it
114 if ( m_clientDataItemsType == wxClientData_Object )
115 {
116 wxClientData *clientDataOld = DoGetItemClientObject(n);
117 if ( clientDataOld )
118 delete clientDataOld;
119 }
120 else // m_clientDataItemsType == wxClientData_None
121 {
122 // now we have object client data
123 m_clientDataItemsType = wxClientData_Object;
124 }
125
126 DoSetItemClientObject(n, data);
127 }
128
129 wxClientData *wxItemContainer::GetClientObject(int n) const
130 {
131 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
132 wxT("this window doesn't have object client data") );
133
134 return DoGetItemClientObject(n);
135 }
136
137 void wxItemContainer::SetClientData(int n, void *data)
138 {
139 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
140 wxT("can't have both object and void client data") );
141
142 DoSetItemClientData(n, data);
143 m_clientDataItemsType = wxClientData_Void;
144 }
145
146 void *wxItemContainer::GetClientData(int n) const
147 {
148 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
149 wxT("this window doesn't have void client data") );
150
151 return DoGetItemClientData(n);
152 }
153
154 wxControlWithItems::~wxControlWithItems()
155 {
156 // this destructor is required for Darwin
157 }
158
159 #endif // wxUSE_CONTROLS