]> git.saurik.com Git - wxWidgets.git/blame - src/common/lboxcmn.cpp
avoiding nesting dcs on the same window concurrently
[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// adding items
47// ----------------------------------------------------------------------------
48
aa61d352 49void wxListBoxBase::InsertItems(unsigned int nItems, const wxString *items, unsigned int pos)
2ee3ee1b
VZ
50{
51 wxArrayString aItems;
aa61d352 52 for ( unsigned int n = 0; n < nItems; n++ )
2ee3ee1b
VZ
53 {
54 aItems.Add(items[n]);
55 }
56
57 DoInsertItems(aItems, pos);
58}
59
60
61void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
62{
63 wxArrayString aItems;
64 for ( int n = 0; n < nItems; n++ )
65 {
66 aItems.Add(items[n]);
67 }
68
69 DoSetItems(aItems, clientData);
70}
71
72// ----------------------------------------------------------------------------
73// selection
74// ----------------------------------------------------------------------------
75
2ee3ee1b
VZ
76bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
77{
95668975
VZ
78 const int sel = FindString(s);
79 if ( sel == wxNOT_FOUND )
80 return false;
2ee3ee1b
VZ
81
82 SetSelection(sel, select);
83
f644b28c 84 return true;
2ee3ee1b
VZ
85}
86
1e6feb95
VZ
87void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
88{
89 if ( HasMultipleSelection() )
90 {
91 wxArrayInt selections;
92 GetSelections(selections);
93
94 size_t count = selections.GetCount();
95 for ( size_t n = 0; n < count; n++ )
96 {
97 int item = selections[n];
98 if ( item != itemToLeaveSelected )
99 Deselect(item);
100 }
101 }
102 else // single selection
103 {
104 int sel = GetSelection();
f644b28c 105 if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected )
1e6feb95
VZ
106 {
107 Deselect(sel);
108 }
109 }
110}
111
2ee3ee1b 112// ----------------------------------------------------------------------------
6c8a980f 113// misc
2ee3ee1b
VZ
114// ----------------------------------------------------------------------------
115
6c8a980f 116void wxListBoxBase::Command(wxCommandEvent& event)
2ee3ee1b 117{
687706f5 118 SetSelection(event.GetInt(), event.GetExtraLong() != 0);
6c8a980f 119 (void)ProcessEvent(event);
2ee3ee1b
VZ
120}
121
1e6feb95
VZ
122// ----------------------------------------------------------------------------
123// SetFirstItem() and such
124// ----------------------------------------------------------------------------
125
2ee3ee1b
VZ
126void wxListBoxBase::SetFirstItem(const wxString& s)
127{
128 int n = FindString(s);
129
f644b28c 130 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
2ee3ee1b
VZ
131
132 DoSetFirstItem(n);
133}
1e6feb95
VZ
134
135void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
136{
137 Append(s);
138 EnsureVisible(GetCount() - 1);
139}
140
141void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
142{
143 // the base class version does nothing (the only alternative would be to
144 // call SetFirstItem() but this is probably even more stupid)
145}
146
147#endif // wxUSE_LISTBOX