many wxItemContainer-related changes:
[wxWidgets.git] / src / common / lboxcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 #include "wx/listbox.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/dynarray.h"
33 #include "wx/arrstr.h"
34 #endif
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 wxListBoxBase::~wxListBoxBase()
41 {
42 // this destructor is required for Darwin
43 }
44
45 // ----------------------------------------------------------------------------
46 // selection
47 // ----------------------------------------------------------------------------
48
49 bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
50 {
51 const int sel = FindString(s);
52 if ( sel == wxNOT_FOUND )
53 return false;
54
55 SetSelection(sel, select);
56
57 return true;
58 }
59
60 void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
61 {
62 if ( HasMultipleSelection() )
63 {
64 wxArrayInt selections;
65 GetSelections(selections);
66
67 size_t count = selections.GetCount();
68 for ( size_t n = 0; n < count; n++ )
69 {
70 int item = selections[n];
71 if ( item != itemToLeaveSelected )
72 Deselect(item);
73 }
74 }
75 else // single selection
76 {
77 int sel = GetSelection();
78 if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected )
79 {
80 Deselect(sel);
81 }
82 }
83 }
84
85 // ----------------------------------------------------------------------------
86 // misc
87 // ----------------------------------------------------------------------------
88
89 void wxListBoxBase::Command(wxCommandEvent& event)
90 {
91 SetSelection(event.GetInt(), event.GetExtraLong() != 0);
92 (void)ProcessEvent(event);
93 }
94
95 // ----------------------------------------------------------------------------
96 // SetFirstItem() and such
97 // ----------------------------------------------------------------------------
98
99 void wxListBoxBase::SetFirstItem(const wxString& s)
100 {
101 int n = FindString(s);
102
103 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
104
105 DoSetFirstItem(n);
106 }
107
108 void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
109 {
110 Append(s);
111 EnsureVisible(GetCount() - 1);
112 }
113
114 void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
115 {
116 // the base class version does nothing (the only alternative would be to
117 // call SetFirstItem() but this is probably even more stupid)
118 }
119
120 #endif // wxUSE_LISTBOX