1 |
william |
31 |
/////////////////////////////////////////////////////////////////////////////// |
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: lboxcmn.cpp 39964 2006-07-04 00:31:52Z VZ $ |
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 |
|
|
// adding items |
47 |
|
|
// ---------------------------------------------------------------------------- |
48 |
|
|
|
49 |
|
|
void wxListBoxBase::InsertItems(unsigned int nItems, const wxString *items, unsigned int pos) |
50 |
|
|
{ |
51 |
|
|
wxArrayString aItems; |
52 |
|
|
for ( unsigned int n = 0; n < nItems; n++ ) |
53 |
|
|
{ |
54 |
|
|
aItems.Add(items[n]); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
DoInsertItems(aItems, pos); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
void 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 |
|
|
|
76 |
|
|
bool wxListBoxBase::SetStringSelection(const wxString& s, bool select) |
77 |
|
|
{ |
78 |
|
|
const int sel = FindString(s); |
79 |
|
|
if ( sel == wxNOT_FOUND ) |
80 |
|
|
return false; |
81 |
|
|
|
82 |
|
|
SetSelection(sel, select); |
83 |
|
|
|
84 |
|
|
return true; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
void 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(); |
105 |
|
|
if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected ) |
106 |
|
|
{ |
107 |
|
|
Deselect(sel); |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
// ---------------------------------------------------------------------------- |
113 |
|
|
// misc |
114 |
|
|
// ---------------------------------------------------------------------------- |
115 |
|
|
|
116 |
|
|
void wxListBoxBase::Command(wxCommandEvent& event) |
117 |
|
|
{ |
118 |
|
|
SetSelection(event.GetInt(), event.GetExtraLong() != 0); |
119 |
|
|
(void)ProcessEvent(event); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
// ---------------------------------------------------------------------------- |
123 |
|
|
// SetFirstItem() and such |
124 |
|
|
// ---------------------------------------------------------------------------- |
125 |
|
|
|
126 |
|
|
void wxListBoxBase::SetFirstItem(const wxString& s) |
127 |
|
|
{ |
128 |
|
|
int n = FindString(s); |
129 |
|
|
|
130 |
|
|
wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") ); |
131 |
|
|
|
132 |
|
|
DoSetFirstItem(n); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
void wxListBoxBase::AppendAndEnsureVisible(const wxString& s) |
136 |
|
|
{ |
137 |
|
|
Append(s); |
138 |
|
|
EnsureVisible(GetCount() - 1); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
void 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 |