]>
git.saurik.com Git - wxWidgets.git/blob - src/common/lboxcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "listboxbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/listbox.h"
35 #include "wx/dynarray.h"
36 #include "wx/arrstr.h"
39 // ============================================================================
41 // ============================================================================
43 wxListBoxBase::~wxListBoxBase()
45 // this destructor is required for Darwin
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 void wxListBoxBase::InsertItems(int nItems
, const wxString
*items
, int pos
)
55 for ( int n
= 0; n
< nItems
; n
++ )
60 DoInsertItems(aItems
, pos
);
64 void wxListBoxBase::Set(int nItems
, const wxString
* items
, void **clientData
)
67 for ( int n
= 0; n
< nItems
; n
++ )
72 DoSetItems(aItems
, clientData
);
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 bool wxListBoxBase::SetStringSelection(const wxString
& s
, bool select
)
81 int sel
= FindString(s
);
82 wxCHECK_MSG( sel
!= wxNOT_FOUND
, false,
83 wxT("invalid string in SetStringSelection") );
85 SetSelection(sel
, select
);
90 void wxListBoxBase::DeselectAll(int itemToLeaveSelected
)
92 if ( HasMultipleSelection() )
94 wxArrayInt selections
;
95 GetSelections(selections
);
97 size_t count
= selections
.GetCount();
98 for ( size_t n
= 0; n
< count
; n
++ )
100 int item
= selections
[n
];
101 if ( item
!= itemToLeaveSelected
)
105 else // single selection
107 int sel
= GetSelection();
108 if ( sel
!= wxNOT_FOUND
&& sel
!= itemToLeaveSelected
)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 void wxListBoxBase::Command(wxCommandEvent
& event
)
121 SetSelection(event
.m_commandInt
, event
.m_extraLong
!= 0);
122 (void)ProcessEvent(event
);
125 // ----------------------------------------------------------------------------
126 // SetFirstItem() and such
127 // ----------------------------------------------------------------------------
129 void wxListBoxBase::SetFirstItem(const wxString
& s
)
131 int n
= FindString(s
);
133 wxCHECK_RET( n
!= wxNOT_FOUND
, wxT("invalid string in wxListBox::SetFirstItem") );
138 void wxListBoxBase::AppendAndEnsureVisible(const wxString
& s
)
141 EnsureVisible(GetCount() - 1);
144 void wxListBoxBase::EnsureVisible(int WXUNUSED(n
))
146 // the base class version does nothing (the only alternative would be to
147 // call SetFirstItem() but this is probably even more stupid)
150 #endif // wxUSE_LISTBOX