]> git.saurik.com Git - wxWidgets.git/blob - src/common/lboxcmn.cpp
remove -lfoo.dll hack, it appears to be unnecessary after all.. don't ask.
[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 #ifdef __GNUG__
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 #endif
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 // ----------------------------------------------------------------------------
42 // adding items
43 // ----------------------------------------------------------------------------
44
45 void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
46 {
47 wxArrayString aItems;
48 for ( int n = 0; n < nItems; n++ )
49 {
50 aItems.Add(items[n]);
51 }
52
53 DoInsertItems(aItems, pos);
54 }
55
56
57 void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
58 {
59 wxArrayString aItems;
60 for ( int n = 0; n < nItems; n++ )
61 {
62 aItems.Add(items[n]);
63 }
64
65 DoSetItems(aItems, clientData);
66 }
67
68 // ----------------------------------------------------------------------------
69 // selection
70 // ----------------------------------------------------------------------------
71
72 bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
73 {
74 int sel = FindString(s);
75 wxCHECK_MSG( sel != -1, FALSE,
76 wxT("invalid string in SetStringSelection") );
77
78 SetSelection(sel, select);
79
80 return TRUE;
81 }
82
83 void wxListBoxBase::DeselectAll(int itemToLeaveSelected)
84 {
85 if ( HasMultipleSelection() )
86 {
87 wxArrayInt selections;
88 GetSelections(selections);
89
90 size_t count = selections.GetCount();
91 for ( size_t n = 0; n < count; n++ )
92 {
93 int item = selections[n];
94 if ( item != itemToLeaveSelected )
95 Deselect(item);
96 }
97 }
98 else // single selection
99 {
100 int sel = GetSelection();
101 if ( sel != -1 && sel != itemToLeaveSelected )
102 {
103 Deselect(sel);
104 }
105 }
106 }
107
108 // ----------------------------------------------------------------------------
109 // misc
110 // ----------------------------------------------------------------------------
111
112 void wxListBoxBase::Command(wxCommandEvent& event)
113 {
114 SetSelection(event.m_commandInt, event.m_extraLong != 0);
115 (void)ProcessEvent(event);
116 }
117
118 // ----------------------------------------------------------------------------
119 // SetFirstItem() and such
120 // ----------------------------------------------------------------------------
121
122 void wxListBoxBase::SetFirstItem(const wxString& s)
123 {
124 int n = FindString(s);
125
126 wxCHECK_RET( n != -1, wxT("invalid string in wxListBox::SetFirstItem") );
127
128 DoSetFirstItem(n);
129 }
130
131 void wxListBoxBase::AppendAndEnsureVisible(const wxString& s)
132 {
133 Append(s);
134 EnsureVisible(GetCount() - 1);
135 }
136
137 void wxListBoxBase::EnsureVisible(int WXUNUSED(n))
138 {
139 // the base class version does nothing (the only alternative would be to
140 // call SetFirstItem() but this is probably even more stupid)
141 }
142
143 #endif // wxUSE_LISTBOX