+
+ // Make a menubar
+ wxMenu *menuFile = new wxMenu;
+ menuFile->Append(LIST_ABOUT, _T("&About"));
+ menuFile->AppendSeparator();
+ menuFile->Append(LIST_QUIT, _T("E&xit\tAlt-X"));
+
+ wxMenu *menuView = new wxMenu;
+ menuView->Append(LIST_LIST_VIEW, _T("&List view\tF1"));
+ menuView->Append(LIST_REPORT_VIEW, _T("&Report view\tF2"));
+ menuView->Append(LIST_ICON_VIEW, _T("&Icon view\tF3"));
+ menuView->Append(LIST_ICON_TEXT_VIEW, _T("Icon view with &text\tF4"));
+ menuView->Append(LIST_SMALL_ICON_VIEW, _T("&Small icon view\tF5"));
+ menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, _T("Small icon &view with text\tF6"));
+ menuView->Append(LIST_VIRTUAL_VIEW, _T("&Virtual view\tF7"));
+ menuView->Append(LIST_SMALL_VIRTUAL_VIEW, _T("Small virtual vie&w\tF8"));
+
+ wxMenu *menuList = new wxMenu;
+ menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L"));
+ menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G"));
+ menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D"));
+ menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A"));
+ menuList->AppendSeparator();
+ menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C"));
+ menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S"));
+ menuList->AppendSeparator();
+ menuList->Append(LIST_SORT, _T("&Sort\tCtrl-S"));
+ menuList->AppendSeparator();
+ menuList->Append(LIST_ADD, _T("&Append an item\tCtrl-P"));
+ menuList->Append(LIST_EDIT, _T("&Edit the item\tCtrl-E"));
+ menuList->Append(LIST_DELETE, _T("&Delete first item\tCtrl-X"));
+ menuList->Append(LIST_DELETE_ALL, _T("Delete &all items"));
+ menuList->AppendSeparator();
+ menuList->Append(LIST_FREEZE, _T("Free&ze\tCtrl-Z"));
+ menuList->Append(LIST_THAW, _T("Tha&w\tCtrl-W"));
+ menuList->AppendSeparator();
+ menuList->AppendCheckItem(LIST_TOGGLE_LINES, _T("Toggle &lines\tCtrl-I"));
+ menuList->Append(LIST_TOGGLE_MULTI_SEL, _T("&Multiple selection\tCtrl-M"),
+ _T("Toggle multiple selection"), true);
+
+ wxMenu *menuCol = new wxMenu;
+ menuCol->Append(LIST_SET_FG_COL, _T("&Foreground colour..."));
+ menuCol->Append(LIST_SET_BG_COL, _T("&Background colour..."));
+
+ wxMenuBar *menubar = new wxMenuBar;
+ menubar->Append(menuFile, _T("&File"));
+ menubar->Append(menuView, _T("&View"));
+ menubar->Append(menuList, _T("&List"));
+ menubar->Append(menuCol, _T("&Colour"));
+ SetMenuBar(menubar);
+
+ m_panel = new wxPanel(this, wxID_ANY);
+ m_logWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE | wxSUNKEN_BORDER);
+
+ m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
+
+ RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL);
+
+#if wxUSE_STATUSBAR
+ CreateStatusBar(3);
+#endif // wxUSE_STATUSBAR
+}
+
+MyFrame::~MyFrame()
+{
+ delete wxLog::SetActiveTarget(m_logOld);
+
+ delete m_imageListNormal;
+ delete m_imageListSmall;
+}
+
+void MyFrame::OnSize(wxSizeEvent& event)
+{
+ DoSize();
+
+ event.Skip();
+}
+
+void MyFrame::DoSize()
+{
+ if ( !m_logWindow )
+ return;
+
+ wxSize size = GetClientSize();
+ wxCoord y = (2*size.y)/3;
+ m_listCtrl->SetSize(0, 0, size.x, y);
+ m_logWindow->SetSize(0, y + 1, size.x, size.y - y);
+}
+
+bool MyFrame::CheckNonVirtual() const
+{
+ if ( !m_listCtrl->HasFlag(wxLC_VIRTUAL) )
+ return true;
+
+ // "this" == whatever
+ wxLogWarning(_T("Can't do this in virtual view, sorry."));
+
+ return false;
+}
+
+void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
+{
+ Close(true);
+}
+
+void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
+{
+ wxMessageDialog dialog(this, _T("List test sample\nJulian Smart (c) 1997"),
+ _T("About list test"), wxOK|wxCANCEL);
+
+ dialog.ShowModal();
+}
+
+void MyFrame::OnFreeze(wxCommandEvent& WXUNUSED(event))
+{
+ wxLogMessage(_T("Freezing the control"));
+
+ m_listCtrl->Freeze();
+}
+
+void MyFrame::OnThaw(wxCommandEvent& WXUNUSED(event))
+{
+ wxLogMessage(_T("Thawing the control"));
+
+ m_listCtrl->Thaw();
+}
+
+void MyFrame::OnToggleLines(wxCommandEvent& event)
+{
+ m_listCtrl->SetSingleStyle(wxLC_HRULES | wxLC_VRULES, event.IsChecked());
+}
+
+void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event))
+{
+ long index = m_listCtrl->GetItemCount() - 1;
+ if ( index == -1 )
+ {
+ return;
+ }
+
+ m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+ m_listCtrl->EnsureVisible(index);
+}
+
+void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+}
+
+void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !CheckNonVirtual() )
+ return;
+
+ int n = m_listCtrl->GetItemCount();
+ for (int i = 0; i < n; i++)
+ m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
+}
+
+void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !CheckNonVirtual() )
+ return;
+
+ int n = m_listCtrl->GetItemCount();
+ for (int i = 0; i < n; i++)
+ m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+}
+
+// ----------------------------------------------------------------------------
+// changing listctrl modes
+// ----------------------------------------------------------------------------
+
+void MyFrame::RecreateList(long flags, bool withText)
+{
+ // we could avoid recreating it if we don't set/clear the wxLC_VIRTUAL
+ // style, but it is more trouble to do it than not
+#if 0
+ if ( !m_listCtrl || ((flags & wxLC_VIRTUAL) !=
+ (m_listCtrl->GetWindowStyleFlag() & wxLC_VIRTUAL)) )