]> git.saurik.com Git - wxWidgets.git/blame - src/common/lboxcmn.cpp
wxError, wxFatalError, wxDebugMsg are not only deprecated, they don't exist anymore...
[wxWidgets.git] / src / common / lboxcmn.cpp
CommitLineData
2ee3ee1b 1///////////////////////////////////////////////////////////////////////////////
aa61d352 2// Name: src/common/lboxcmn.cpp
2ee3ee1b
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
2ee3ee1b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2ee3ee1b
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
1e6feb95
VZ
27#if wxUSE_LISTBOX
28
2a673eb1
WS
29#include "wx/listbox.h"
30
2ee3ee1b 31#ifndef WX_PRECOMP
ed39ff57 32 #include "wx/dynarray.h"
a9711a4d 33 #include "wx/arrstr.h"
2ee3ee1b
VZ
34#endif
35
36// ============================================================================
37// implementation
38// ============================================================================
39
799ea011
GD
40wxListBoxBase::~wxListBoxBase()
41{
42 // this destructor is required for Darwin
43}
44
2ee3ee1b
VZ
45// ----------------------------------------------------------------------------
46// selection
47// ----------------------------------------------------------------------------
48
2ee3ee1b
VZ
49bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
50{
95668975
VZ
51 const int sel = FindString(s);
52 if ( sel == wxNOT_FOUND )
53 return false;
2ee3ee1b
VZ
54
55 SetSelection(sel, select);
56
f644b28c 57 return true;
2ee3ee1b
VZ
58}
59
1e6feb95
VZ
60void 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();
f644b28c 78 if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected )
1e6feb95
VZ
79 {
80 Deselect(sel);
81 }
82 }
83}
84
2ee3ee1b 85// ----------------------------------------------------------------------------
6c8a980f 86// misc
2ee3ee1b
VZ
87// ----------------------------------------------------------------------------
88
6c8a980f 89void wxListBoxBase::Command(wxCommandEvent& event)
2ee3ee1b 90{
687706f5 91 SetSelection(event.GetInt(), event.GetExtraLong() != 0);
6c8a980f 92 (void)ProcessEvent(event);
2ee3ee1b
VZ
93}
94
1e6feb95
VZ
95// ----------------------------------------------------------------------------
96// SetFirstItem() and such
97// ----------------------------------------------------------------------------
98
2ee3ee1b
VZ
99void wxListBoxBase::SetFirstItem(const wxString& s)
100{
101 int n = FindString(s);
102
f644b28c 103 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
2ee3ee1b
VZ
104
105 DoSetFirstItem(n);
106}
1e6feb95
VZ
107
108void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
109{
110 Append(s);
111 EnsureVisible(GetCount() - 1);
112}
113
114void 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