wxChoice and wxListBox GTK+ changes (wxChoice works, wxListBox still doesn't)
[wxWidgets.git] / src / common / lboxcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/lboxcmn.cpp
3 // Purpose: wxListBox class methods common to all platforms
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 "listboxbase.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 #ifndef WX_PRECOMP
32 #include "wx/listbox.h"
33 #endif
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 // ----------------------------------------------------------------------------
40 // adding items
41 // ----------------------------------------------------------------------------
42
43 void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
44 {
45 wxArrayString aItems;
46 for ( int n = 0; n < nItems; n++ )
47 {
48 aItems.Add(items[n]);
49 }
50
51 DoInsertItems(aItems, pos);
52 }
53
54
55 void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
56 {
57 wxArrayString aItems;
58 for ( int n = 0; n < nItems; n++ )
59 {
60 aItems.Add(items[n]);
61 }
62
63 DoSetItems(aItems, clientData);
64 }
65
66 // ----------------------------------------------------------------------------
67 // selection
68 // ----------------------------------------------------------------------------
69
70 wxString wxListBoxBase::GetStringSelection () const
71 {
72 wxString s;
73 int sel = GetSelection();
74 if ( sel != -1 )
75 s = GetString(sel);
76
77 return s;
78 }
79
80 bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
81 {
82 int sel = FindString(s);
83 wxCHECK_MSG( sel != -1, FALSE,
84 wxT("invalid string in wxListBox::SetStringSelection") );
85
86 SetSelection(sel, select);
87
88 return TRUE;
89 }
90
91 // ----------------------------------------------------------------------------
92 // client data
93 // ----------------------------------------------------------------------------
94
95 void wxListBoxBase::SetClientObject(int n, wxClientData *data)
96 {
97 wxASSERT_MSG( m_clientDataItemsType != ClientData_Void,
98 wxT("can't have both object and void client data") );
99
100 wxClientData *clientDataOld = DoGetClientObject(n);
101 if ( clientDataOld )
102 delete clientDataOld;
103
104 DoSetClientObject(n, data);
105 m_clientDataItemsType = ClientData_Object;
106 }
107
108 wxClientData *wxListBoxBase::GetClientObject(int n) const
109 {
110 wxASSERT_MSG( m_clientDataItemsType == ClientData_Object,
111 wxT("this window doesn't have object client data") );
112
113 return DoGetClientObject(n);
114 }
115
116 void wxListBoxBase::SetClientData(int n, void *data)
117 {
118 wxASSERT_MSG( m_clientDataItemsType != ClientData_Object,
119 wxT("can't have both object and void client data") );
120
121 DoSetClientData(n, data);
122 m_clientDataItemsType = ClientData_Void;
123 }
124
125 void *wxListBoxBase::GetClientData(int n) const
126 {
127 wxASSERT_MSG( m_clientDataItemsType == ClientData_Void,
128 wxT("this window doesn't have void client data") );
129
130 return DoGetClientData(n);
131 }
132
133 // ----------------------------------------------------------------------------
134 // misc
135 // ----------------------------------------------------------------------------
136
137 void wxListBoxBase::SetFirstItem(const wxString& s)
138 {
139 int n = FindString(s);
140
141 wxCHECK_RET( n != -1, wxT("invalid string in wxListBox::SetFirstItem") );
142
143 DoSetFirstItem(n);
144 }
145
146 void wxListBoxBase::Command(wxCommandEvent & event)
147 {
148 SetSelection(event.m_commandInt, event.m_extraLong);
149 (void)ProcessEvent(event);
150 }
151