]>
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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/ctrlsub.h"
31 #include "wx/arrstr.h"
34 // ============================================================================
35 // wxItemContainerImmutable implementation
36 // ============================================================================
38 wxItemContainerImmutable::~wxItemContainerImmutable()
40 // this destructor is required for Darwin
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxString
wxItemContainerImmutable::GetStringSelection() const
50 int sel
= GetSelection();
57 bool wxItemContainerImmutable::SetStringSelection(const wxString
& s
)
59 const int sel
= FindString(s
);
60 if ( sel
== wxNOT_FOUND
)
68 wxArrayString
wxItemContainerImmutable::GetStrings() const
72 const size_t count
= GetCount();
74 for ( size_t n
= 0; n
< count
; n
++ )
75 result
.Add(GetString(n
));
80 // ============================================================================
81 // wxItemContainer implementation
82 // ============================================================================
84 wxItemContainer::~wxItemContainer()
86 // this destructor is required for Darwin
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 void wxItemContainer::Append(const wxArrayString
& strings
)
95 size_t count
= strings
.GetCount();
96 for ( size_t n
= 0; n
< count
; n
++ )
102 int wxItemContainer::Insert(const wxString
& item
, int pos
, void *clientData
)
104 int n
= DoInsert(item
, pos
);
105 if ( n
!= wxNOT_FOUND
)
106 SetClientData(n
, clientData
);
112 wxItemContainer::Insert(const wxString
& item
, int pos
, wxClientData
*clientData
)
114 int n
= DoInsert(item
, pos
);
115 if ( n
!= wxNOT_FOUND
)
116 SetClientObject(n
, clientData
);
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 void wxItemContainer::SetClientObject(int n
, wxClientData
*data
)
127 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Void
,
128 wxT("can't have both object and void client data") );
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
)
135 wxClientData
*clientDataOld
= DoGetItemClientObject(n
);
137 delete clientDataOld
;
139 else // m_clientDataItemsType == wxClientData_None
141 // now we have object client data
142 m_clientDataItemsType
= wxClientData_Object
;
145 DoSetItemClientObject(n
, data
);
148 wxClientData
*wxItemContainer::GetClientObject(int n
) const
150 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Object
,
151 wxT("this window doesn't have object client data") );
153 return DoGetItemClientObject(n
);
156 void wxItemContainer::SetClientData(int n
, void *data
)
158 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Object
,
159 wxT("can't have both object and void client data") );
161 DoSetItemClientData(n
, data
);
162 m_clientDataItemsType
= wxClientData_Void
;
165 void *wxItemContainer::GetClientData(int n
) const
167 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Void
,
168 wxT("this window doesn't have void client data") );
170 return DoGetItemClientData(n
);
173 wxControlWithItems::~wxControlWithItems()
175 // this destructor is required for Darwin
178 #endif // wxUSE_CONTROLS