]>
git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/ctrlsub.h"
31 #include "wx/arrstr.h"
34 IMPLEMENT_ABSTRACT_CLASS(wxControlWithItems
, wxControl
)
36 // ============================================================================
37 // wxItemContainerImmutable implementation
38 // ============================================================================
40 wxItemContainerImmutable::~wxItemContainerImmutable()
42 // this destructor is required for Darwin
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 wxString
wxItemContainerImmutable::GetStringSelection() const
53 int sel
= GetSelection();
54 if ( sel
!= wxNOT_FOUND
)
55 s
= GetString((unsigned int)sel
);
60 bool wxItemContainerImmutable::SetStringSelection(const wxString
& s
)
62 const int sel
= FindString(s
);
63 if ( sel
== wxNOT_FOUND
)
71 wxArrayString
wxItemContainerImmutable::GetStrings() const
75 const unsigned int count
= GetCount();
77 for ( unsigned int n
= 0; n
< count
; n
++ )
78 result
.Add(GetString(n
));
83 // ============================================================================
84 // wxItemContainer implementation
85 // ============================================================================
87 wxItemContainer::~wxItemContainer()
89 // this destructor is required for Darwin
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 void wxItemContainer::Append(const wxArrayString
& strings
)
98 const size_t count
= strings
.GetCount();
99 for ( size_t n
= 0; n
< count
; n
++ )
105 int wxItemContainer::Insert(const wxString
& item
, unsigned int pos
, void *clientData
)
107 int n
= DoInsert(item
, pos
);
108 if ( n
!= wxNOT_FOUND
)
109 SetClientData(n
, clientData
);
114 int wxItemContainer::Insert(const wxString
& item
, unsigned int pos
, wxClientData
*clientData
)
116 int n
= DoInsert(item
, pos
);
117 if ( n
!= wxNOT_FOUND
)
118 SetClientObject(n
, clientData
);
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 void wxItemContainer::SetClientObject(unsigned int n
, wxClientData
*data
)
129 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Void
,
130 wxT("can't have both object and void client data") );
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
)
137 wxClientData
*clientDataOld
= DoGetItemClientObject(n
);
139 delete clientDataOld
;
141 else // m_clientDataItemsType == wxClientData_None
143 // now we have object client data
144 m_clientDataItemsType
= wxClientData_Object
;
147 DoSetItemClientObject(n
, data
);
150 wxClientData
*wxItemContainer::GetClientObject(unsigned int n
) const
152 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Object
,
153 wxT("this window doesn't have object client data") );
155 return DoGetItemClientObject(n
);
158 void wxItemContainer::SetClientData(unsigned int n
, void *data
)
160 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Object
,
161 wxT("can't have both object and void client data") );
163 DoSetItemClientData(n
, data
);
164 m_clientDataItemsType
= wxClientData_Void
;
167 void *wxItemContainer::GetClientData(unsigned int n
) const
169 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Void
,
170 wxT("this window doesn't have void client data") );
172 return DoGetItemClientData(n
);
175 wxControlWithItems::~wxControlWithItems()
177 // this destructor is required for Darwin
180 #endif // wxUSE_CONTROLS