Applied patch [ 832096 ] Final separation for GUI and console for Open Watcom
[wxWidgets.git] / src / common / ctrlsub.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/ctrlsub.cpp
3 // Purpose: wxItemContainer implementation
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
31 #if wxUSE_CONTROLS
32
33 #ifndef WX_PRECOMP
34 #include "wx/ctrlsub.h"
35 #include "wx/arrstr.h"
36 #endif
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 wxItemContainer::wxItemContainer()
43 {
44 m_clientDataItemsType = wxClientData_None;
45 }
46
47 wxItemContainer::~wxItemContainer()
48 {
49 // this destructor is required for Darwin
50 }
51
52 // ----------------------------------------------------------------------------
53 // selection
54 // ----------------------------------------------------------------------------
55
56 wxString wxItemContainer::GetStringSelection() const
57 {
58 wxString s;
59 int sel = GetSelection();
60 if ( sel != -1 )
61 s = GetString(sel);
62
63 return s;
64 }
65
66 wxArrayString wxItemContainer::GetStrings() const
67 {
68 wxArrayString result ;
69 size_t count = GetCount() ;
70 for ( size_t n = 0 ; n < count ; n++ )
71 result.Add(GetString(n));
72 return result ;
73 }
74
75 // ----------------------------------------------------------------------------
76 // appending items
77 // ----------------------------------------------------------------------------
78
79 void wxItemContainer::Append(const wxArrayString& strings)
80 {
81 size_t count = strings.GetCount();
82 for ( size_t n = 0; n < count; n++ )
83 {
84 Append(strings[n]);
85 }
86 }
87
88 int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
89 {
90 int n = DoInsert(item, pos);
91 if ( n != wxNOT_FOUND )
92 SetClientData(n, clientData);
93
94 return n;
95 }
96
97 int
98 wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
99 {
100 int n = DoInsert(item, pos);
101 if ( n != wxNOT_FOUND )
102 SetClientObject(n, clientData);
103
104 return n;
105 }
106
107 // ----------------------------------------------------------------------------
108 // client data
109 // ----------------------------------------------------------------------------
110
111 void wxItemContainer::SetClientObject(int n, wxClientData *data)
112 {
113 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
114 wxT("can't have both object and void client data") );
115
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 )
120 {
121 wxClientData *clientDataOld = DoGetItemClientObject(n);
122 if ( clientDataOld )
123 delete clientDataOld;
124 }
125 else // m_clientDataItemsType == wxClientData_None
126 {
127 // now we have object client data
128 m_clientDataItemsType = wxClientData_Object;
129 }
130
131 DoSetItemClientObject(n, data);
132 }
133
134 wxClientData *wxItemContainer::GetClientObject(int n) const
135 {
136 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
137 wxT("this window doesn't have object client data") );
138
139 return DoGetItemClientObject(n);
140 }
141
142 void wxItemContainer::SetClientData(int n, void *data)
143 {
144 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
145 wxT("can't have both object and void client data") );
146
147 DoSetItemClientData(n, data);
148 m_clientDataItemsType = wxClientData_Void;
149 }
150
151 void *wxItemContainer::GetClientData(int n) const
152 {
153 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
154 wxT("this window doesn't have void client data") );
155
156 return DoGetItemClientData(n);
157 }
158
159 wxControlWithItems::wxControlWithItems()
160 {
161 }
162
163 wxControlWithItems::~wxControlWithItems()
164 {
165 // this destructor is required for Darwin
166 }
167
168 #endif // wxUSE_CONTROLS