]> git.saurik.com Git - wxWidgets.git/blob - src/common/lboxcmn.cpp
cocoa doesn't need system framework - string conversion for cocoa - focus for cocoa...
[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) wxWidgets 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 // this destructor is required for Darwin
46 }
47
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
79 bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
80 {
81 int sel = FindString(s);
82 wxCHECK_MSG( sel != wxNOT_FOUND, false,
83 wxT("invalid string in SetStringSelection") );
84
85 SetSelection(sel, select);
86
87 return true;
88 }
89
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 != wxNOT_FOUND && sel != itemToLeaveSelected )
109 {
110 Deselect(sel);
111 }
112 }
113 }
114
115 // ----------------------------------------------------------------------------
116 // misc
117 // ----------------------------------------------------------------------------
118
119 void wxListBoxBase::Command(wxCommandEvent& event)
120 {
121 SetSelection(event.m_commandInt, event.m_extraLong != 0);
122 (void)ProcessEvent(event);
123 }
124
125 // ----------------------------------------------------------------------------
126 // SetFirstItem() and such
127 // ----------------------------------------------------------------------------
128
129 void wxListBoxBase::SetFirstItem(const wxString& s)
130 {
131 int n = FindString(s);
132
133 wxCHECK_RET( n != wxNOT_FOUND, wxT("invalid string in wxListBox::SetFirstItem") );
134
135 DoSetFirstItem(n);
136 }
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