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