]>
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) wxWindows 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 // ============================================================================
40 // ============================================================================
42 wxItemContainer::wxItemContainer()
44 m_clientDataItemsType
= wxClientData_None
;
47 wxItemContainer::~wxItemContainer()
49 // this destructor is required for Darwin
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 wxString
wxItemContainer::GetStringSelection() const
59 int sel
= GetSelection();
66 wxArrayString
wxItemContainer::GetStrings() const
68 wxArrayString result
;
69 size_t count
= GetCount() ;
70 for ( size_t n
= 0 ; n
< count
; n
++ )
71 result
.Add(GetString(n
));
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 void wxItemContainer::Append(const wxArrayString
& strings
)
81 size_t count
= strings
.GetCount();
82 for ( size_t n
= 0; n
< count
; n
++ )
88 int wxItemContainer::Insert(const wxString
& item
, int pos
, void *clientData
)
90 int n
= DoInsert(item
, pos
);
91 if ( n
!= wxNOT_FOUND
)
92 SetClientData(n
, clientData
);
98 wxItemContainer::Insert(const wxString
& item
, int pos
, wxClientData
*clientData
)
100 int n
= DoInsert(item
, pos
);
101 if ( n
!= wxNOT_FOUND
)
102 SetClientObject(n
, clientData
);
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 void wxItemContainer::SetClientObject(int n
, wxClientData
*data
)
113 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Void
,
114 wxT("can't have both object and void client data") );
116 // when we call SetClientObject() for the first time, m_clientDataItemsType
117 // is still wxClientData_None and so calling DoGetItemClientObject() would
118 // fail (in addition to being useless) - don't do it
119 if ( m_clientDataItemsType
== wxClientData_Object
)
121 wxClientData
*clientDataOld
= DoGetItemClientObject(n
);
123 delete clientDataOld
;
125 else // m_clientDataItemsType == wxClientData_None
127 // now we have object client data
128 m_clientDataItemsType
= wxClientData_Object
;
131 DoSetItemClientObject(n
, data
);
134 wxClientData
*wxItemContainer::GetClientObject(int n
) const
136 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Object
,
137 wxT("this window doesn't have object client data") );
139 return DoGetItemClientObject(n
);
142 void wxItemContainer::SetClientData(int n
, void *data
)
144 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Object
,
145 wxT("can't have both object and void client data") );
147 DoSetItemClientData(n
, data
);
148 m_clientDataItemsType
= wxClientData_Void
;
151 void *wxItemContainer::GetClientData(int n
) const
153 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Void
,
154 wxT("this window doesn't have void client data") );
156 return DoGetItemClientData(n
);
159 wxControlWithItems::wxControlWithItems()
163 wxControlWithItems::~wxControlWithItems()
165 // this destructor is required for Darwin
168 #endif // wxUSE_CONTROLS