]>
Commit | Line | Data |
---|---|---|
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 | ||
2ee3ee1b | 29 | #ifndef WX_PRECOMP |
ed39ff57 | 30 | #include "wx/dynarray.h" |
ad9835c9 | 31 | #include "wx/listbox.h" |
a9711a4d | 32 | #include "wx/arrstr.h" |
2ee3ee1b VZ |
33 | #endif |
34 | ||
35 | // ============================================================================ | |
36 | // implementation | |
37 | // ============================================================================ | |
38 | ||
799ea011 GD |
39 | wxListBoxBase::~wxListBoxBase() |
40 | { | |
41 | // this destructor is required for Darwin | |
42 | } | |
43 | ||
2ee3ee1b VZ |
44 | // ---------------------------------------------------------------------------- |
45 | // adding items | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
aa61d352 | 48 | void wxListBoxBase::InsertItems(unsigned int nItems, const wxString *items, unsigned int pos) |
2ee3ee1b VZ |
49 | { |
50 | wxArrayString aItems; | |
aa61d352 | 51 | for ( unsigned int n = 0; n < nItems; n++ ) |
2ee3ee1b VZ |
52 | { |
53 | aItems.Add(items[n]); | |
54 | } | |
55 | ||
56 | DoInsertItems(aItems, pos); | |
57 | } | |
58 | ||
59 | ||
60 | void 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 |
75 | bool 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 |
86 | void 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 | 115 | void 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 |
125 | void 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 | |
134 | void wxListBoxBase::AppendAndEnsureVisible(const wxString& s) | |
135 | { | |
136 | Append(s); | |
137 | EnsureVisible(GetCount() - 1); | |
138 | } | |
139 | ||
140 | void 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 |