]>
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 // ============================================================================
40 // ============================================================================
42 wxItemContainer::~wxItemContainer()
44 // this destructor is required for Darwin
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxString
wxItemContainer::GetStringSelection() const
54 int sel
= GetSelection();
61 bool wxItemContainer::SetStringSelection(const wxString
& s
)
63 const int sel
= FindString(s
);
64 if ( sel
== wxNOT_FOUND
)
72 wxArrayString
wxItemContainer::GetStrings() const
74 wxArrayString result
;
75 size_t count
= GetCount() ;
76 for ( size_t n
= 0 ; n
< count
; n
++ )
77 result
.Add(GetString(n
));
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 void wxItemContainer::Append(const wxArrayString
& strings
)
87 size_t count
= strings
.GetCount();
88 for ( size_t n
= 0; n
< count
; n
++ )
94 int wxItemContainer::Insert(const wxString
& item
, int pos
, void *clientData
)
96 int n
= DoInsert(item
, pos
);
97 if ( n
!= wxNOT_FOUND
)
98 SetClientData(n
, clientData
);
104 wxItemContainer::Insert(const wxString
& item
, int pos
, wxClientData
*clientData
)
106 int n
= DoInsert(item
, pos
);
107 if ( n
!= wxNOT_FOUND
)
108 SetClientObject(n
, clientData
);
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 void wxItemContainer::SetClientObject(int n
, wxClientData
*data
)
119 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Void
,
120 wxT("can't have both object and void client data") );
122 // when we call SetClientObject() for the first time, m_clientDataItemsType
123 // is still wxClientData_None and so calling DoGetItemClientObject() would
124 // fail (in addition to being useless) - don't do it
125 if ( m_clientDataItemsType
== wxClientData_Object
)
127 wxClientData
*clientDataOld
= DoGetItemClientObject(n
);
129 delete clientDataOld
;
131 else // m_clientDataItemsType == wxClientData_None
133 // now we have object client data
134 m_clientDataItemsType
= wxClientData_Object
;
137 DoSetItemClientObject(n
, data
);
140 wxClientData
*wxItemContainer::GetClientObject(int n
) const
142 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Object
,
143 wxT("this window doesn't have object client data") );
145 return DoGetItemClientObject(n
);
148 void wxItemContainer::SetClientData(int n
, void *data
)
150 wxASSERT_MSG( m_clientDataItemsType
!= wxClientData_Object
,
151 wxT("can't have both object and void client data") );
153 DoSetItemClientData(n
, data
);
154 m_clientDataItemsType
= wxClientData_Void
;
157 void *wxItemContainer::GetClientData(int n
) const
159 wxASSERT_MSG( m_clientDataItemsType
== wxClientData_Void
,
160 wxT("this window doesn't have void client data") );
162 return DoGetItemClientData(n
);
165 wxControlWithItems::~wxControlWithItems()
167 // this destructor is required for Darwin
170 #if WXWIN_COMPATIBILITY_2_2
172 int wxItemContainer::Number() const
177 #endif // WXWIN_COMPATIBILITY_2_2
179 #endif // wxUSE_CONTROLS