]>
Commit | Line | Data |
---|---|---|
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 | #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 | ||
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 | // this destructor is required for Darwin | |
45 | } | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // selection | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | wxString wxItemContainer::GetStringSelection() const | |
52 | { | |
53 | wxString s; | |
54 | int sel = GetSelection(); | |
55 | if ( sel != -1 ) | |
56 | s = GetString(sel); | |
57 | ||
58 | return s; | |
59 | } | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // appending items | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | void 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 | ||
74 | int 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 | ||
83 | int | |
84 | wxItemContainer::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 | ||
93 | // ---------------------------------------------------------------------------- | |
94 | // client data | |
95 | // ---------------------------------------------------------------------------- | |
96 | ||
97 | void wxItemContainer::SetClientObject(int n, wxClientData *data) | |
98 | { | |
99 | wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void, | |
100 | wxT("can't have both object and void client data") ); | |
101 | ||
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 | } | |
116 | ||
117 | DoSetItemClientObject(n, data); | |
118 | } | |
119 | ||
120 | wxClientData *wxItemContainer::GetClientObject(int n) const | |
121 | { | |
122 | wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object, | |
123 | wxT("this window doesn't have object client data") ); | |
124 | ||
125 | return DoGetItemClientObject(n); | |
126 | } | |
127 | ||
128 | void wxItemContainer::SetClientData(int n, void *data) | |
129 | { | |
130 | wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object, | |
131 | wxT("can't have both object and void client data") ); | |
132 | ||
133 | DoSetItemClientData(n, data); | |
134 | m_clientDataItemsType = wxClientData_Void; | |
135 | } | |
136 | ||
137 | void *wxItemContainer::GetClientData(int n) const | |
138 | { | |
139 | wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void, | |
140 | wxT("this window doesn't have void client data") ); | |
141 | ||
142 | return DoGetItemClientData(n); | |
143 | } | |
144 | ||
145 | wxControlWithItems::~wxControlWithItems() | |
146 | { | |
147 | // this destructor is required for Darwin | |
148 | } | |
149 | ||
150 | #endif // wxUSE_CONTROLS |