]>
git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/ctrlsub.cpp
3 // Purpose: wxItemContainer implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "controlwithitems.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/ctrlsub.h"
35 #include "wx/arrstr.h"
38 // ============================================================================
39 // wxItemContainerImmutable implementation
40 // ============================================================================
42 wxItemContainerImmutable::~wxItemContainerImmutable()
44 // this destructor is required for Darwin
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxString
wxItemContainerImmutable::GetStringSelection() const
54 int sel
= GetSelection();
61 bool wxItemContainerImmutable::SetStringSelection(const wxString
& s
)
63 const int sel
= FindString(s
);
64 if ( sel
== wxNOT_FOUND
)
72 wxArrayString
wxItemContainerImmutable::GetStrings() const
76 const size_t count
= GetCount();
78 for ( size_t n
= 0; n
< count
; n
++ )
79 result
.Add(GetString(n
));
84 // ============================================================================
85 // wxItemContainer implementation
86 // ============================================================================
88 wxItemContainer::~wxItemContainer()
90 // this destructor is required for Darwin
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 void wxItemContainer::Append(const wxArrayString
& strings
)
99 size_t count
= strings
.GetCount();
100 for ( size_t n
= 0; n
< count
; n
++ )
106 int wxItemContainer::Insert(const wxString
& item
, int pos
, void *clientData
)
108 int n
= DoInsert(item
, pos
);
109 if ( n
!= wxNOT_FOUND
)
110 SetClientData(n
, clientData
);
116 wxItemContainer::Insert(const wxString
& item
, int pos
, wxClientData
*clientData
)
118 int n
= DoInsert(item
, pos
);
119 if ( n
!= wxNOT_FOUND
)
120 SetClientObject(n
, clientData
);
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 void wxItemContainer::SetClientObject(int n
, wxClientData
*data
)
131 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Void
,
132 wxT("can't have both object and void client data") );
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
)
139 wxClientData
*clientDataOld
= DoGetItemClientObject(n
);
141 delete clientDataOld
;
143 else // m_clientDataItemsType == wxClientData_None
145 // now we have object client data
146 m_clientDataItemsType
= wxClientData_Object
;
149 DoSetItemClientObject(n
, data
);
152 wxClientData
*wxItemContainer::GetClientObject(int n
) const
154 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Object
,
155 wxT("this window doesn't have object client data") );
157 return DoGetItemClientObject(n
);
160 void wxItemContainer::SetClientData(int n
, void *data
)
162 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Object
,
163 wxT("can't have both object and void client data") );
165 DoSetItemClientData(n
, data
);
166 m_clientDataItemsType
= wxClientData_Void
;
169 void *wxItemContainer::GetClientData(int n
) const
171 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Void
,
172 wxT("this window doesn't have void client data") );
174 return DoGetItemClientData(n
);
177 wxControlWithItems::~wxControlWithItems()
179 // this destructor is required for Darwin
182 #endif // wxUSE_CONTROLS