]> git.saurik.com Git - wxWidgets.git/blame - src/common/ctrlsub.cpp
xti extensions
[wxWidgets.git] / src / common / ctrlsub.cpp
CommitLineData
6c8a980f
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/ctrlsub.cpp
1e6feb95 3// Purpose: wxItemContainer implementation
6c8a980f
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 22.10.99
7// RCS-ID: $Id$
8// Copyright: (c) wxWindows team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "controlwithitems.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
1e6feb95
VZ
31#if wxUSE_CONTROLS
32
6c8a980f
VZ
33#ifndef WX_PRECOMP
34 #include "wx/ctrlsub.h"
a9711a4d 35 #include "wx/arrstr.h"
6c8a980f
VZ
36#endif
37
38// ============================================================================
39// implementation
40// ============================================================================
41
799ea011
GD
42wxItemContainer::~wxItemContainer()
43{
44 // this destructor is required for Darwin
45}
46
6c8a980f
VZ
47// ----------------------------------------------------------------------------
48// selection
49// ----------------------------------------------------------------------------
50
1e6feb95 51wxString wxItemContainer::GetStringSelection() const
6c8a980f
VZ
52{
53 wxString s;
54 int sel = GetSelection();
55 if ( sel != -1 )
56 s = GetString(sel);
57
58 return s;
59}
60
0e0bc921
VZ
61// ----------------------------------------------------------------------------
62// appending items
63// ----------------------------------------------------------------------------
64
65void wxItemContainer::Append(const wxArrayString& strings)
66{
67 size_t count = strings.GetCount();
68 for ( size_t n = 0; n < count; n++ )
69 {
70 Append(strings[n]);
71 }
72}
73
243dbf1a
VZ
74int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
75{
76 int n = DoInsert(item, pos);
77 if ( n != wxNOT_FOUND )
78 SetClientData(n, clientData);
79
80 return n;
81}
82
83int
84wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
85{
86 int n = DoInsert(item, pos);
87 if ( n != wxNOT_FOUND )
88 SetClientObject(n, clientData);
89
90 return n;
91}
92
6c8a980f
VZ
93// ----------------------------------------------------------------------------
94// client data
95// ----------------------------------------------------------------------------
96
1e6feb95 97void wxItemContainer::SetClientObject(int n, wxClientData *data)
6c8a980f 98{
1e6feb95 99 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
6c8a980f
VZ
100 wxT("can't have both object and void client data") );
101
da6069e2
VZ
102 // when we call SetClientObject() for the first time, m_clientDataItemsType
103 // is still wxClientData_None and so calling DoGetItemClientObject() would
104 // fail (in addition to being useless) - don't do it
105 if ( m_clientDataItemsType == wxClientData_Object )
106 {
107 wxClientData *clientDataOld = DoGetItemClientObject(n);
108 if ( clientDataOld )
109 delete clientDataOld;
110 }
111 else // m_clientDataItemsType == wxClientData_None
112 {
113 // now we have object client data
114 m_clientDataItemsType = wxClientData_Object;
115 }
6c8a980f
VZ
116
117 DoSetItemClientObject(n, data);
6c8a980f
VZ
118}
119
1e6feb95 120wxClientData *wxItemContainer::GetClientObject(int n) const
6c8a980f 121{
1e6feb95 122 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
6c8a980f
VZ
123 wxT("this window doesn't have object client data") );
124
125 return DoGetItemClientObject(n);
126}
127
1e6feb95 128void wxItemContainer::SetClientData(int n, void *data)
6c8a980f 129{
1e6feb95 130 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
6c8a980f
VZ
131 wxT("can't have both object and void client data") );
132
133 DoSetItemClientData(n, data);
1e6feb95 134 m_clientDataItemsType = wxClientData_Void;
6c8a980f
VZ
135}
136
1e6feb95 137void *wxItemContainer::GetClientData(int n) const
6c8a980f 138{
1e6feb95 139 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
6c8a980f
VZ
140 wxT("this window doesn't have void client data") );
141
142 return DoGetItemClientData(n);
143}
144
7c720ce6
GD
145wxControlWithItems::~wxControlWithItems()
146{
147 // this destructor is required for Darwin
148}
149
1e6feb95 150#endif // wxUSE_CONTROLS