]> git.saurik.com Git - wxWidgets.git/blob - src/common/ctrlsub.cpp
clicking on a panel without children should give it the focus (closes 215436)
[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 #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 #endif
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 wxItemContainer::~wxItemContainer()
42 {
43 // this destructor is required for Darwin
44 }
45
46 // ----------------------------------------------------------------------------
47 // selection
48 // ----------------------------------------------------------------------------
49
50 wxString wxItemContainer::GetStringSelection() const
51 {
52 wxString s;
53 int sel = GetSelection();
54 if ( sel != -1 )
55 s = GetString(sel);
56
57 return s;
58 }
59
60 // ----------------------------------------------------------------------------
61 // appending items
62 // ----------------------------------------------------------------------------
63
64 void wxItemContainer::Append(const wxArrayString& strings)
65 {
66 size_t count = strings.GetCount();
67 for ( size_t n = 0; n < count; n++ )
68 {
69 Append(strings[n]);
70 }
71 }
72
73 int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
74 {
75 int n = DoInsert(item, pos);
76 if ( n != wxNOT_FOUND )
77 SetClientData(n, clientData);
78
79 return n;
80 }
81
82 int
83 wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
84 {
85 int n = DoInsert(item, pos);
86 if ( n != wxNOT_FOUND )
87 SetClientObject(n, clientData);
88
89 return n;
90 }
91
92 // ----------------------------------------------------------------------------
93 // client data
94 // ----------------------------------------------------------------------------
95
96 void wxItemContainer::SetClientObject(int n, wxClientData *data)
97 {
98 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
99 wxT("can't have both object and void client data") );
100
101 // when we call SetClientObject() for the first time, m_clientDataItemsType
102 // is still wxClientData_None and so calling DoGetItemClientObject() would
103 // fail (in addition to being useless) - don't do it
104 if ( m_clientDataItemsType == wxClientData_Object )
105 {
106 wxClientData *clientDataOld = DoGetItemClientObject(n);
107 if ( clientDataOld )
108 delete clientDataOld;
109 }
110 else // m_clientDataItemsType == wxClientData_None
111 {
112 // now we have object client data
113 m_clientDataItemsType = wxClientData_Object;
114 }
115
116 DoSetItemClientObject(n, data);
117 }
118
119 wxClientData *wxItemContainer::GetClientObject(int n) const
120 {
121 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
122 wxT("this window doesn't have object client data") );
123
124 return DoGetItemClientObject(n);
125 }
126
127 void wxItemContainer::SetClientData(int n, void *data)
128 {
129 wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
130 wxT("can't have both object and void client data") );
131
132 DoSetItemClientData(n, data);
133 m_clientDataItemsType = wxClientData_Void;
134 }
135
136 void *wxItemContainer::GetClientData(int n) const
137 {
138 wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
139 wxT("this window doesn't have void client data") );
140
141 return DoGetItemClientData(n);
142 }
143
144 wxControlWithItems::~wxControlWithItems()
145 {
146 // this destructor is required for Darwin
147 }
148
149 #endif // wxUSE_CONTROLS