+void MyFrame::OnSetMargins(wxCommandEvent& WXUNUSED(event))
+{
+ 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& WXUNUSED(event))
+{
+ m_hlbox->SelectAll();
+}
+
+void MyFrame::OnUpdateUISelectAll(wxUpdateUIEvent& event)
+{
+ event.Enable( m_hlbox && m_hlbox->HasMultipleSelection() );
+}
+
+void MyFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
+{
+ wxColour col = wxGetColourFromUser(this, m_hlbox->GetBackgroundColour());
+ if ( col.Ok() )
+ {
+ m_hlbox->SetBackgroundColour(col);
+ m_hlbox->Refresh();
+
+ SetStatusText(_T("Background colour changed."));
+ }
+}
+
+void MyFrame::OnSetSelBgCol(wxCommandEvent& WXUNUSED(event))
+{
+ wxColour col = wxGetColourFromUser(this, m_hlbox->GetSelectionBackground());
+ if ( col.Ok() )
+ {
+ m_hlbox->SetSelectionBackground(col);
+ m_hlbox->Refresh();
+
+ SetStatusText(_T("Selection background colour changed."));
+ }
+}
+
+void MyFrame::OnSetSelFgCol(wxCommandEvent& event)
+{
+ m_hlbox->SetChangeSelFg(!event.IsChecked());
+ m_hlbox->Refresh();
+}
+
+// ----------------------------------------------------------------------------
+// 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
+// ============================================================================
+
+MyHtmlListBox::MyHtmlListBox(wxWindow *parent, bool multi)
+ : wxHtmlListBox(parent, -1, wxDefaultPosition, wxDefaultSize,
+ multi ? wxLB_MULTIPLE : 0)
+{
+ m_change = true;
+
+ SetMargins(5, 5);
+
+#ifdef USE_HTML_FILE
+ if ( !m_file.Open("results") )
+ {
+ wxLogError("Failed to open results file");
+ }
+ else
+ {
+ SetItemCount(m_file.GetLineCount());
+ }
+#else
+ SetItemCount(1000);
+#endif
+
+ SetSelection(3);
+}
+
+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());
+ }
+}
+
+wxString MyHtmlListBox::OnGetItem(size_t n) const
+{
+#ifdef USE_HTML_FILE
+ wxString s;
+ if ( m_file.IsOpened() )
+ s = m_file[n];
+
+ return s;
+#else
+ int level = n % 6 + 1;
+ return wxString::Format(_T("<h%d><font color=#%2x%2x%2x>")
+ _T("Item</font> <b>%lu</b>")
+ _T("</h%d>"),
+ level,
+ abs(n - 192) % 256,
+ abs(n - 256) % 256,
+ abs(n - 128) % 256,
+ (unsigned long)n, level);
+#endif
+}
+
+wxColour MyHtmlListBox::GetSelectedTextColour(const wxColour& colFg) const
+{
+ return m_change ? wxHtmlListBox::GetSelectedTextColour(colFg) : colFg;
+}
+