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