1 ///////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "listbox.h"
16 #include "wx/listbox.h"
18 #include "wx/dynarray.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
25 // ============================================================================
26 // list box control implementation
27 // ============================================================================
30 wxListBox::wxListBox()
36 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
39 int n
, const wxString choices
[],
41 const wxValidator
& validator
,
48 SetValidator(validator
);
50 if (parent
) parent
->AddChild(this);
52 wxSystemSettings settings
;
53 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
55 m_windowId
= ( id
== -1 ) ? (int)NewControlId() : id
;
57 // TODO create listbox
62 wxListBox::~wxListBox()
66 void wxListBox::SetupColours()
68 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
71 void wxListBox::SetFirstItem(int N
)
76 void wxListBox::SetFirstItem(const wxString
& s
)
81 void wxListBox::Delete(int N
)
87 void wxListBox::Append(const wxString
& item
)
94 void wxListBox::Append(const wxString
& item
, char *Client_data
)
101 void wxListBox::Set(int n
, const wxString
*choices
, char** clientData
)
108 int wxListBox::FindString(const wxString
& s
) const
114 void wxListBox::Clear()
120 void wxListBox::SetSelection(int N
, bool select
)
125 bool wxListBox::Selected(int N
) const
131 void wxListBox::Deselect(int N
)
136 char *wxListBox::GetClientData(int N
) const
142 void wxListBox::SetClientData(int N
, char *Client_data
)
147 // Return number of selections and an array of selected integers
148 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
153 if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
156 for ( int n = 0; n < no_sel; n++ )
161 else // single-selection listbox
171 // Get single selection, for single choice list items
172 int wxListBox::GetSelection() const
178 // Find string for position
179 wxString
wxListBox::GetString(int N
) const
185 void wxListBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
190 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
197 void wxListBox::SetString(int N
, const wxString
& s
)
202 int wxListBox::Number () const
207 // For single selection items only
208 wxString
wxListBox::GetStringSelection () const
210 int sel
= GetSelection ();
212 return this->GetString (sel
);
217 bool wxListBox::SetStringSelection (const wxString
& s
, bool flag
)
219 int sel
= FindString (s
);
222 SetSelection (sel
, flag
);
229 void wxListBox::Command (wxCommandEvent
& event
)
231 if (event
.m_extraLong
)
232 SetSelection (event
.m_commandInt
);
235 Deselect (event
.m_commandInt
);
238 ProcessCommand (event
);