added virtual view mode with small number of items for testing search in virtual list control

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34272 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-05-22 21:31:42 +00:00
parent 9705fbe904
commit b0401bea78
2 changed files with 55 additions and 11 deletions

View File

@@ -47,6 +47,21 @@
#include "listtest.h" #include "listtest.h"
const wxChar *SMALL_VIRTUAL_VIEW_ITEMS[][2] =
{
{ _T("Cat"), _T("meow") },
{ _T("Cow"), _T("moo") },
{ _T("Crow"), _T("caw") },
{ _T("Dog"), _T("woof") },
{ _T("Duck"), _T("quack") },
{ _T("Mouse"), _T("squeak") },
{ _T("Owl"), _T("hoo") },
{ _T("Pig"), _T("oink") },
{ _T("Pigeon"), _T("coo") },
{ _T("Sheep"), _T("baaah") },
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_SIZE(MyFrame::OnSize) EVT_SIZE(MyFrame::OnSize)
@@ -59,6 +74,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView) EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast) EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
@@ -145,10 +161,11 @@ bool MyApp::OnInit()
// My frame constructor // My frame constructor
MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h)
: wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{ {
m_listCtrl = (MyListCtrl *) NULL; m_listCtrl = NULL;
m_logWindow = (wxTextCtrl *) NULL; m_logWindow = NULL;
m_smallVirtual = false;
// Give it an icon // Give it an icon
SetIcon( wxICON(mondrian) ); SetIcon( wxICON(mondrian) );
@@ -197,7 +214,8 @@ MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h)
menuView->Append(LIST_ICON_TEXT_VIEW, _T("Icon view with &text\tF4")); 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_VIEW, _T("&Small icon view\tF5"));
menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, _T("Small icon &view with text\tF6")); 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_VIRTUAL_VIEW, _T("&Virtual view\tF7"));
menuView->Append(LIST_SMALL_VIRTUAL_VIEW, _T("Small virtual vie&w\tF8"));
wxMenu *menuList = new wxMenu; wxMenu *menuList = new wxMenu;
menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L")); menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L"));
@@ -521,6 +539,13 @@ void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event))
{ {
m_smallVirtual = false;
RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
}
void MyFrame::OnSmallVirtualView(wxCommandEvent& WXUNUSED(event))
{
m_smallVirtual = true;
RecreateList(wxLC_REPORT | wxLC_VIRTUAL); RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
} }
@@ -528,13 +553,21 @@ void MyFrame::InitWithVirtualItems()
{ {
m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
if ( m_smallVirtual )
{
m_listCtrl->InsertColumn(0, _T("Animal"));
m_listCtrl->InsertColumn(1, _T("Sound"));
m_listCtrl->SetItemCount(WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS));
}
else
{
m_listCtrl->InsertColumn(0, _T("First Column")); m_listCtrl->InsertColumn(0, _T("First Column"));
m_listCtrl->InsertColumn(1, _T("Second Column")); m_listCtrl->InsertColumn(1, _T("Second Column"));
m_listCtrl->SetColumnWidth(0, 150); m_listCtrl->SetColumnWidth(0, 150);
m_listCtrl->SetColumnWidth(1, 150); m_listCtrl->SetColumnWidth(1, 150);
m_listCtrl->SetItemCount(1000000); m_listCtrl->SetItemCount(1000000);
} }
}
void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
{ {
@@ -953,9 +986,16 @@ void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName)
} }
wxString MyListCtrl::OnGetItemText(long item, long column) const wxString MyListCtrl::OnGetItemText(long item, long column) const
{
if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
{
return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
}
else
{ {
return wxString::Format(_T("Column %ld of item %ld"), column, item); return wxString::Format(_T("Column %ld of item %ld"), column, item);
} }
}
int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const
{ {

View File

@@ -98,6 +98,7 @@ protected:
void OnSmallIconView(wxCommandEvent& event); void OnSmallIconView(wxCommandEvent& event);
void OnSmallIconTextView(wxCommandEvent& event); void OnSmallIconTextView(wxCommandEvent& event);
void OnVirtualView(wxCommandEvent& event); void OnVirtualView(wxCommandEvent& event);
void OnSmallVirtualView(wxCommandEvent& event);
void OnFocusLast(wxCommandEvent& event); void OnFocusLast(wxCommandEvent& event);
void OnToggleFirstSel(wxCommandEvent& event); void OnToggleFirstSel(wxCommandEvent& event);
@@ -144,6 +145,8 @@ private:
wxLog *m_logOld; wxLog *m_logOld;
bool m_smallVirtual;
DECLARE_NO_COPY_CLASS(MyFrame) DECLARE_NO_COPY_CLASS(MyFrame)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@@ -162,6 +165,7 @@ enum
LIST_SMALL_ICON_TEXT_VIEW, LIST_SMALL_ICON_TEXT_VIEW,
LIST_REPORT_VIEW, LIST_REPORT_VIEW,
LIST_VIRTUAL_VIEW, LIST_VIRTUAL_VIEW,
LIST_SMALL_VIRTUAL_VIEW,
LIST_DESELECT_ALL, LIST_DESELECT_ALL,
LIST_SELECT_ALL, LIST_SELECT_ALL,