+void MyFrame::OnSetMargins(wxCommandEvent&)
+{
+ long margin = wxGetNumberFromUser
+ (
+ _T("Enter the margins to use for the listbox items."),
+ _T("Margin: "),
+ _T("HtmlLbox: Set the margins"),
+ 0, 0, 20,
+ this
+ );
+
+ if ( margin != -1 )
+ {
+ m_hlbox->SetMargins(margin, margin);
+ m_hlbox->RefreshAll();
+ }
+}
+
+void MyFrame::OnToggleMulti(wxCommandEvent& event)
+{
+ // we need to recreate the listbox
+ wxSizer *sizer = GetSizer();
+ sizer->Detach(m_hlbox);
+ delete m_hlbox;
+
+ m_hlbox = new MyHtmlListBox(this, event.IsChecked());
+ sizer->Prepend(m_hlbox, 1, wxGROW);
+
+ sizer->Layout();
+}
+
+void MyFrame::OnSelectAll(wxCommandEvent& event)
+{
+ m_hlbox->SelectRange(0, m_hlbox->GetItemCount() - 1);
+}
+
+void MyFrame::OnUpdateUISelectAll(wxUpdateUIEvent& event)
+{
+ event.Enable( m_hlbox && m_hlbox->HasMultipleSelection() );
+}
+
+// ----------------------------------------------------------------------------
+// listbox event handlers
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnLboxSelect(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Listbox selection is now %ld."), event.GetInt());
+
+ if ( m_hlbox->HasMultipleSelection() )
+ {
+ wxString s;
+
+ bool first = true;
+ unsigned long cookie;
+ for ( int item = m_hlbox->GetFirstSelected(cookie);
+ item != wxNOT_FOUND;
+ item = m_hlbox->GetNextSelected(cookie) )
+ {
+ if ( first )
+ first = false;
+ else
+ s << _T(", ");
+
+ s << item;
+ }
+
+ if ( !s.empty() )
+ wxLogMessage(_T("Selected items: %s"), s.c_str());
+ }
+
+ SetStatusText(wxString::Format(
+ _T("# items selected = %lu"),
+ (unsigned long)m_hlbox->GetSelectedCount()
+ ));
+}
+
+// ============================================================================
+// MyHtmlListBox
+// ============================================================================
+
+void MyHtmlListBox::OnDrawSeparator(wxDC& dc, wxRect& rect, size_t) const
+{
+ if ( ((MyFrame *)GetParent())->
+ GetMenuBar()->IsChecked(HtmlLbox_DrawSeparator) )
+ {
+ dc.SetPen(*wxBLACK_DASHED_PEN);
+ dc.DrawLine(rect.x, rect.y, rect.GetRight(), rect.y);
+ dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight(), rect.GetBottom());
+ }
+}
+