]>
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) wxWindows 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()
47 wxListBoxBase::~wxListBoxBase()
49 // this destructor is required for Darwin
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 void wxListBoxBase::InsertItems(int nItems
, const wxString
*items
, int pos
)
59 for ( int n
= 0; n
< nItems
; n
++ )
64 DoInsertItems(aItems
, pos
);
68 void wxListBoxBase::Set(int nItems
, const wxString
* items
, void **clientData
)
71 for ( int n
= 0; n
< nItems
; n
++ )
76 DoSetItems(aItems
, clientData
);
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 bool wxListBoxBase::SetStringSelection(const wxString
& s
, bool select
)
85 int sel
= FindString(s
);
86 wxCHECK_MSG( sel
!= -1, FALSE
,
87 wxT("invalid string in SetStringSelection") );
89 SetSelection(sel
, select
);
94 void wxListBoxBase::DeselectAll(int itemToLeaveSelected
)
96 if ( HasMultipleSelection() )
98 wxArrayInt selections
;
99 GetSelections(selections
);
101 size_t count
= selections
.GetCount();
102 for ( size_t n
= 0; n
< count
; n
++ )
104 int item
= selections
[n
];
105 if ( item
!= itemToLeaveSelected
)
109 else // single selection
111 int sel
= GetSelection();
112 if ( sel
!= -1 && sel
!= itemToLeaveSelected
)
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 void wxListBoxBase::Command(wxCommandEvent
& event
)
125 SetSelection(event
.m_commandInt
, event
.m_extraLong
!= 0);
126 (void)ProcessEvent(event
);
129 // ----------------------------------------------------------------------------
130 // SetFirstItem() and such
131 // ----------------------------------------------------------------------------
133 void wxListBoxBase::SetFirstItem(const wxString
& s
)
135 int n
= FindString(s
);
137 wxCHECK_RET( n
!= -1, wxT("invalid string in wxListBox::SetFirstItem") );
142 void wxListBoxBase::AppendAndEnsureVisible(const wxString
& s
)
145 EnsureVisible(GetCount() - 1);
148 void wxListBoxBase::EnsureVisible(int WXUNUSED(n
))
150 // the base class version does nothing (the only alternative would be to
151 // call SetFirstItem() but this is probably even more stupid)
154 #endif // wxUSE_LISTBOX