]>
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"
29 #include "wx/listbox.h"
32 #include "wx/dynarray.h"
33 #include "wx/arrstr.h"
36 // ============================================================================
38 // ============================================================================
40 wxListBoxBase::~wxListBoxBase()
42 // this destructor is required for Darwin
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 void wxListBoxBase::InsertItems(unsigned int nItems
, const wxString
*items
, unsigned int pos
)
52 for ( unsigned int n
= 0; n
< nItems
; n
++ )
57 DoInsertItems(aItems
, pos
);
61 void wxListBoxBase::Set(int nItems
, const wxString
* items
, void **clientData
)
64 for ( int n
= 0; n
< nItems
; n
++ )
69 DoSetItems(aItems
, clientData
);
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 bool wxListBoxBase::SetStringSelection(const wxString
& s
, bool select
)
78 int sel
= FindString(s
);
79 wxCHECK_MSG( sel
!= wxNOT_FOUND
, false,
80 wxT("invalid string in SetStringSelection") );
82 SetSelection(sel
, select
);
87 void wxListBoxBase::DeselectAll(int itemToLeaveSelected
)
89 if ( HasMultipleSelection() )
91 wxArrayInt selections
;
92 GetSelections(selections
);
94 size_t count
= selections
.GetCount();
95 for ( size_t n
= 0; n
< count
; n
++ )
97 int item
= selections
[n
];
98 if ( item
!= itemToLeaveSelected
)
102 else // single selection
104 int sel
= GetSelection();
105 if ( sel
!= wxNOT_FOUND
&& sel
!= itemToLeaveSelected
)
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 void wxListBoxBase::Command(wxCommandEvent
& event
)
118 SetSelection(event
.GetInt(), event
.GetExtraLong() != 0);
119 (void)ProcessEvent(event
);
122 // ----------------------------------------------------------------------------
123 // SetFirstItem() and such
124 // ----------------------------------------------------------------------------
126 void wxListBoxBase::SetFirstItem(const wxString
& s
)
128 int n
= FindString(s
);
130 wxCHECK_RET( n
!= wxNOT_FOUND
, wxT("invalid string in wxListBox::SetFirstItem") );
135 void wxListBoxBase::AppendAndEnsureVisible(const wxString
& s
)
138 EnsureVisible(GetCount() - 1);
141 void wxListBoxBase::EnsureVisible(int WXUNUSED(n
))
143 // the base class version does nothing (the only alternative would be to
144 // call SetFirstItem() but this is probably even more stupid)
147 #endif // wxUSE_LISTBOX