]> git.saurik.com Git - wxWidgets.git/blob - src/common/lboxcmn.cpp
set error to GSOCK_TIMEOUT if the socket timed out (modified and extended patch 1303554)
[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) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_LISTBOX
28
29 #ifndef WX_PRECOMP
30 #include "wx/listbox.h"
31 #include "wx/dynarray.h"
32 #include "wx/arrstr.h"
33 #endif
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 wxListBoxBase::~wxListBoxBase()
40 {
41 // this destructor is required for Darwin
42 }
43
44 // ----------------------------------------------------------------------------
45 // adding items
46 // ----------------------------------------------------------------------------
47
48 void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
49 {
50 wxArrayString aItems;
51 for ( int n = 0; n < nItems; n++ )
52 {
53 aItems.Add(items[n]);
54 }
55
56 DoInsertItems(aItems, pos);
57 }
58
59
60 void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
61 {
62 wxArrayString aItems;
63 for ( int n = 0; n < nItems; n++ )
64 {
65 aItems.Add(items[n]);
66 }
67
68 DoSetItems(aItems, clientData);
69 }
70
71 // ----------------------------------------------------------------------------
72 // selection
73 // ----------------------------------------------------------------------------
74
75 bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
76 {
77 int sel = FindString(s);
78 wxCHECK_MSG( sel != wxNOT_FOUND, false,
79 wxT("invalid string in SetStringSelection") );
80
81 SetSelection(sel, select);
82
83 return true;
84 }
85
86 void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
87 {
88 if ( HasMultipleSelection() )
89 {
90 wxArrayInt selections;
91 GetSelections(selections);
92
93 size_t count = selections.GetCount();
94 for ( size_t n = 0; n < count; n++ )
95 {
96 int item = selections[n];
97 if ( item != itemToLeaveSelected )
98 Deselect(item);
99 }
100 }
101 else // single selection
102 {
103 int sel = GetSelection();
104 if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected )
105 {
106 Deselect(sel);
107 }
108 }
109 }
110
111 // ----------------------------------------------------------------------------
112 // misc
113 // ----------------------------------------------------------------------------
114
115 void wxListBoxBase::Command(wxCommandEvent& event)
116 {
117 SetSelection(event.GetInt(), event.GetExtraLong() != 0);
118 (void)ProcessEvent(event);
119 }
120
121 // ----------------------------------------------------------------------------
122 // SetFirstItem() and such
123 // ----------------------------------------------------------------------------
124
125 void wxListBoxBase::SetFirstItem(const wxString& s)
126 {
127 int n = FindString(s);
128
129 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
130
131 DoSetFirstItem(n);
132 }
133
134 void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
135 {
136 Append(s);
137 EnsureVisible(GetCount() - 1);
138 }
139
140 void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
141 {
142 // the base class version does nothing (the only alternative would be to
143 // call SetFirstItem() but this is probably even more stupid)
144 }
145
146 #endif // wxUSE_LISTBOX