]> git.saurik.com Git - wxWidgets.git/blame - src/common/lboxcmn.cpp
Source cleaning. wxMotif/OS2 adjustements.
[wxWidgets.git] / src / common / lboxcmn.cpp
CommitLineData
2ee3ee1b
VZ
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$
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
2ee3ee1b
VZ
29#ifndef WX_PRECOMP
30 #include "wx/listbox.h"
ed39ff57 31 #include "wx/dynarray.h"
a9711a4d 32 #include "wx/arrstr.h"
2ee3ee1b
VZ
33#endif
34
35// ============================================================================
36// implementation
37// ============================================================================
38
799ea011
GD
39wxListBoxBase::~wxListBoxBase()
40{
41 // this destructor is required for Darwin
42}
43
2ee3ee1b
VZ
44// ----------------------------------------------------------------------------
45// adding items
46// ----------------------------------------------------------------------------
47
48void 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
60void 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
2ee3ee1b
VZ
75bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
76{
77 int sel = FindString(s);
f644b28c 78 wxCHECK_MSG( sel != wxNOT_FOUND, false,
6c8a980f 79 wxT("invalid string in SetStringSelection") );
2ee3ee1b
VZ
80
81 SetSelection(sel, select);
82
f644b28c 83 return true;
2ee3ee1b
VZ
84}
85
1e6feb95
VZ
86void 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();
f644b28c 104 if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected )
1e6feb95
VZ
105 {
106 Deselect(sel);
107 }
108 }
109}
110
2ee3ee1b 111// ----------------------------------------------------------------------------
6c8a980f 112// misc
2ee3ee1b
VZ
113// ----------------------------------------------------------------------------
114
6c8a980f 115void wxListBoxBase::Command(wxCommandEvent& event)
2ee3ee1b 116{
687706f5 117 SetSelection(event.GetInt(), event.GetExtraLong() != 0);
6c8a980f 118 (void)ProcessEvent(event);
2ee3ee1b
VZ
119}
120
1e6feb95
VZ
121// ----------------------------------------------------------------------------
122// SetFirstItem() and such
123// ----------------------------------------------------------------------------
124
2ee3ee1b
VZ
125void wxListBoxBase::SetFirstItem(const wxString& s)
126{
127 int n = FindString(s);
128
f644b28c 129 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
2ee3ee1b
VZ
130
131 DoSetFirstItem(n);
132}
1e6feb95
VZ
133
134void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
135{
136 Append(s);
137 EnsureVisible(GetCount() - 1);
138}
139
140void 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