]>
git.saurik.com Git - wxWidgets.git/blob - src/common/lboxcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/lboxcmn.cpp
3 // Purpose: wxListBox class methods common to all platforms
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/dynarray.h"
31 #include "wx/listbox.h"
32 #include "wx/arrstr.h"
35 // ============================================================================
37 // ============================================================================
39 wxListBoxBase::~wxListBoxBase()
41 // this destructor is required for Darwin
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 void wxListBoxBase::InsertItems(unsigned int nItems
, const wxString
*items
, unsigned int pos
)
51 for ( unsigned int n
= 0; n
< nItems
; n
++ )
56 DoInsertItems(aItems
, pos
);
60 void wxListBoxBase::Set(int nItems
, const wxString
* items
, void **clientData
)
63 for ( int n
= 0; n
< nItems
; n
++ )
68 DoSetItems(aItems
, clientData
);
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 bool wxListBoxBase::SetStringSelection(const wxString
& s
, bool select
)
77 int sel
= FindString(s
);
78 wxCHECK_MSG( sel
!= wxNOT_FOUND
, false,
79 wxT("invalid string in SetStringSelection") );
81 SetSelection(sel
, select
);
86 void wxListBoxBase::DeselectAll(int itemToLeaveSelected
)
88 if ( HasMultipleSelection() )
90 wxArrayInt selections
;
91 GetSelections(selections
);
93 size_t count
= selections
.GetCount();
94 for ( size_t n
= 0; n
< count
; n
++ )
96 int item
= selections
[n
];
97 if ( item
!= itemToLeaveSelected
)
101 else // single selection
103 int sel
= GetSelection();
104 if ( sel
!= wxNOT_FOUND
&& sel
!= itemToLeaveSelected
)
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 void wxListBoxBase::Command(wxCommandEvent
& event
)
117 SetSelection(event
.GetInt(), event
.GetExtraLong() != 0);
118 (void)ProcessEvent(event
);
121 // ----------------------------------------------------------------------------
122 // SetFirstItem() and such
123 // ----------------------------------------------------------------------------
125 void wxListBoxBase::SetFirstItem(const wxString
& s
)
127 int n
= FindString(s
);
129 wxCHECK_RET( n
!= wxNOT_FOUND
, wxT("invalid string in wxListBox::SetFirstItem") );
134 void wxListBoxBase::AppendAndEnsureVisible(const wxString
& s
)
137 EnsureVisible(GetCount() - 1);
140 void wxListBoxBase::EnsureVisible(int WXUNUSED(n
))
142 // the base class version does nothing (the only alternative would be to
143 // call SetFirstItem() but this is probably even more stupid)
146 #endif // wxUSE_LISTBOX