]> git.saurik.com Git - wxWidgets.git/blame - src/common/lboxcmn.cpp
Added some standard further identifiers to help with WinCE toolbars
[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$
8// Copyright: (c) wxWindows team
6c8a980f 9// Licence: wxWindows licence
2ee3ee1b
VZ
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
1e6feb95
VZ
31#if wxUSE_LISTBOX
32
2ee3ee1b
VZ
33#ifndef WX_PRECOMP
34 #include "wx/listbox.h"
ed39ff57 35 #include "wx/dynarray.h"
2ee3ee1b
VZ
36#endif
37
38// ============================================================================
39// implementation
40// ============================================================================
41
799ea011
GD
42wxListBoxBase::~wxListBoxBase()
43{
44 // this destructor is required for Darwin
45}
46
2ee3ee1b
VZ
47// ----------------------------------------------------------------------------
48// adding items
49// ----------------------------------------------------------------------------
50
51void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
52{
53 wxArrayString aItems;
54 for ( int n = 0; n < nItems; n++ )
55 {
56 aItems.Add(items[n]);
57 }
58
59 DoInsertItems(aItems, pos);
60}
61
62
63void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
64{
65 wxArrayString aItems;
66 for ( int n = 0; n < nItems; n++ )
67 {
68 aItems.Add(items[n]);
69 }
70
71 DoSetItems(aItems, clientData);
72}
73
74// ----------------------------------------------------------------------------
75// selection
76// ----------------------------------------------------------------------------
77
2ee3ee1b
VZ
78bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
79{
80 int sel = FindString(s);
81 wxCHECK_MSG( sel != -1, FALSE,
6c8a980f 82 wxT("invalid string in SetStringSelection") );
2ee3ee1b
VZ
83
84 SetSelection(sel, select);
85
86 return TRUE;
87}
88
1e6feb95
VZ
89void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
90{
91 if ( HasMultipleSelection() )
92 {
93 wxArrayInt selections;
94 GetSelections(selections);
95
96 size_t count = selections.GetCount();
97 for ( size_t n = 0; n < count; n++ )
98 {
99 int item = selections[n];
100 if ( item != itemToLeaveSelected )
101 Deselect(item);
102 }
103 }
104 else // single selection
105 {
106 int sel = GetSelection();
107 if ( sel != -1 && sel != itemToLeaveSelected )
108 {
109 Deselect(sel);
110 }
111 }
112}
113
2ee3ee1b 114// ----------------------------------------------------------------------------
6c8a980f 115// misc
2ee3ee1b
VZ
116// ----------------------------------------------------------------------------
117
6c8a980f 118void wxListBoxBase::Command(wxCommandEvent& event)
2ee3ee1b 119{
8ee9d618 120 SetSelection(event.m_commandInt, event.m_extraLong != 0);
6c8a980f 121 (void)ProcessEvent(event);
2ee3ee1b
VZ
122}
123
1e6feb95
VZ
124// ----------------------------------------------------------------------------
125// SetFirstItem() and such
126// ----------------------------------------------------------------------------
127
2ee3ee1b
VZ
128void wxListBoxBase::SetFirstItem(const wxString& s)
129{
130 int n = FindString(s);
131
132 wxCHECK_RET( n != -1, wxT("invalid string in wxListBox::SetFirstItem") );
133
134 DoSetFirstItem(n);
135}
1e6feb95
VZ
136
137void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
138{
139 Append(s);
140 EnsureVisible(GetCount() - 1);
141}
142
143void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
144{
145 // the base class version does nothing (the only alternative would be to
146 // call SetFirstItem() but this is probably even more stupid)
147}
148
149#endif // wxUSE_LISTBOX