1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: listctrl.cpp
|
|
|
|
// Purpose: wxListCtrl sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1999-07-23 23:41:45 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
1998-12-07 08:27:06 +00:00
|
|
|
#ifndef __WXMSW__
|
2000-02-24 23:40:42 +00:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
|
|
|
|
#include "bitmaps/toolbrai.xpm"
|
|
|
|
#include "bitmaps/toolchar.xpm"
|
|
|
|
#include "bitmaps/tooldata.xpm"
|
|
|
|
#include "bitmaps/toolnote.xpm"
|
|
|
|
#include "bitmaps/tooltodo.xpm"
|
|
|
|
#include "bitmaps/toolchec.xpm"
|
|
|
|
#include "bitmaps/toolgame.xpm"
|
|
|
|
#include "bitmaps/tooltime.xpm"
|
|
|
|
#include "bitmaps/toolword.xpm"
|
|
|
|
#include "bitmaps/small1.xpm"
|
1998-12-07 08:27:06 +00:00
|
|
|
#endif
|
|
|
|
|
2000-03-17 23:02:03 +00:00
|
|
|
#include "wx/imaglist.h"
|
1998-05-22 19:57:05 +00:00
|
|
|
#include "wx/listctrl.h"
|
2000-02-06 01:30:21 +00:00
|
|
|
#include "wx/timer.h" // for wxStopWatch
|
2000-02-08 01:07:48 +00:00
|
|
|
#include "wx/colordlg.h" // for wxGetColourFromUser
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
#include "listtest.h"
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2001-07-05 01:27:38 +00:00
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
|
|
|
|
1999-07-23 23:41:45 +00:00
|
|
|
EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
|
|
|
|
EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
|
|
|
|
EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
|
|
|
|
EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
|
|
|
|
EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
|
|
|
|
EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
|
2001-07-05 01:27:38 +00:00
|
|
|
EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
|
|
|
|
|
2000-03-13 17:20:39 +00:00
|
|
|
EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
|
1999-07-23 23:41:45 +00:00
|
|
|
EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
|
|
|
|
EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
|
2001-06-23 22:24:33 +00:00
|
|
|
EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
|
2001-07-06 21:18:15 +00:00
|
|
|
EVT_MENU(LIST_ADD, MyFrame::OnAdd)
|
1999-07-23 23:41:45 +00:00
|
|
|
EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
|
1999-12-01 22:07:25 +00:00
|
|
|
EVT_MENU(LIST_SORT, MyFrame::OnSort)
|
2000-02-08 01:07:48 +00:00
|
|
|
EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
|
|
|
|
EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
|
2000-02-10 18:12:44 +00:00
|
|
|
EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
|
2000-07-15 19:51:35 +00:00
|
|
|
EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
|
2001-07-07 22:42:35 +00:00
|
|
|
EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
|
2001-07-05 01:27:38 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
|
1998-05-22 19:57:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
|
1999-07-23 23:41:45 +00:00
|
|
|
EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
|
|
|
|
EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
|
|
|
|
EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
|
|
|
|
EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
|
|
|
|
EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
|
2000-02-06 13:51:01 +00:00
|
|
|
EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
|
1999-07-23 23:41:45 +00:00
|
|
|
EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
|
|
|
|
EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
|
|
|
|
EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
|
|
|
|
EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
|
|
|
|
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
|
|
|
|
EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
|
1999-08-24 20:26:06 +00:00
|
|
|
EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
|
2001-07-20 00:25:09 +00:00
|
|
|
EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
EVT_CHAR(MyListCtrl::OnChar)
|
1998-05-22 19:57:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
// number of items in list/report view
|
|
|
|
static const int NUM_ITEMS = 30;
|
|
|
|
|
|
|
|
// number of items in icon/small icon view
|
|
|
|
static const int NUM_ICONS = 9;
|
|
|
|
|
1999-12-01 22:07:25 +00:00
|
|
|
int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
|
|
|
|
{
|
|
|
|
// inverse the order
|
|
|
|
return item1 < item2;
|
|
|
|
}
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
2000-02-08 01:07:48 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
|
|
|
// Create the main frame window
|
2001-08-02 18:59:50 +00:00
|
|
|
MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"), 50, 50, 450, 340);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
// Show the frame
|
|
|
|
frame->Show(TRUE);
|
1999-07-23 23:41:45 +00:00
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
2000-02-24 23:40:42 +00:00
|
|
|
MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h)
|
|
|
|
: wxFrame((wxFrame *)NULL, -1, title, wxPoint(x, y), wxSize(w, h))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-07-23 23:41:45 +00:00
|
|
|
m_listCtrl = (MyListCtrl *) NULL;
|
|
|
|
m_logWindow = (wxTextCtrl *) NULL;
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
SetIcon( wxICON(mondrian) );
|
|
|
|
|
|
|
|
// Make an image list containing large icons
|
|
|
|
m_imageListNormal = new wxImageList(32, 32, TRUE);
|
|
|
|
m_imageListSmall = new wxImageList(16, 16, TRUE);
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
|
|
|
|
m_imageListSmall->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE) );
|
|
|
|
|
|
|
|
#else
|
|
|
|
m_imageListNormal->Add( wxIcon( toolbrai_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( toolchar_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( tooldata_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( toolnote_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( tooltodo_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( toolchec_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( toolgame_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( tooltime_xpm ) );
|
|
|
|
m_imageListNormal->Add( wxIcon( toolword_xpm ) );
|
|
|
|
|
|
|
|
m_imageListSmall->Add( wxIcon( small1_xpm) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
2001-07-05 01:27:38 +00:00
|
|
|
menuFile->Append(LIST_ABOUT, _T("&About"));
|
2000-02-24 23:40:42 +00:00
|
|
|
menuFile->AppendSeparator();
|
2001-07-05 01:27:38 +00:00
|
|
|
menuFile->Append(LIST_QUIT, _T("E&xit\tAlt-X"));
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
wxMenu *menuView = new wxMenu;
|
2001-07-05 01:27:38 +00:00
|
|
|
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"));
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
wxMenu *menuList = new wxMenu;
|
2001-07-05 01:27:38 +00:00
|
|
|
menuList->Append(LIST_TOGGLE_FIRST, _T("&Toggle first item\tCtrl-T"));
|
|
|
|
menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D"));
|
|
|
|
menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A"));
|
2001-07-07 22:42:35 +00:00
|
|
|
menuList->AppendSeparator();
|
2001-07-05 01:27:38 +00:00
|
|
|
menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C"));
|
2001-07-07 22:42:35 +00:00
|
|
|
menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S"));
|
2000-02-24 23:40:42 +00:00
|
|
|
menuList->AppendSeparator();
|
2001-07-05 01:27:38 +00:00
|
|
|
menuList->Append(LIST_SORT, _T("&Sort\tCtrl-S"));
|
2000-02-24 23:40:42 +00:00
|
|
|
menuList->AppendSeparator();
|
2001-07-06 21:18:15 +00:00
|
|
|
menuList->Append(LIST_ADD, _T("&Append an item\tCtrl-P"));
|
|
|
|
menuList->Append(LIST_DELETE, _T("&Delete first item\tCtrl-X"));
|
2001-07-05 01:27:38 +00:00
|
|
|
menuList->Append(LIST_DELETE_ALL, _T("Delete &all items"));
|
2000-02-24 23:40:42 +00:00
|
|
|
menuList->AppendSeparator();
|
2001-07-05 01:27:38 +00:00
|
|
|
menuList->Append(LIST_TOGGLE_MULTI_SEL, _T("&Multiple selection\tCtrl-M"),
|
|
|
|
_T("Toggle multiple selection"), TRUE);
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
wxMenu *menuCol = new wxMenu;
|
2001-07-05 01:27:38 +00:00
|
|
|
menuCol->Append(LIST_SET_FG_COL, _T("&Foreground colour..."));
|
|
|
|
menuCol->Append(LIST_SET_BG_COL, _T("&Background colour..."));
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
wxMenuBar *menubar = new wxMenuBar;
|
2001-07-05 01:27:38 +00:00
|
|
|
menubar->Append(menuFile, _T("&File"));
|
|
|
|
menubar->Append(menuView, _T("&View"));
|
|
|
|
menubar->Append(menuList, _T("&List"));
|
|
|
|
menubar->Append(menuCol, _T("&Colour"));
|
2000-02-24 23:40:42 +00:00
|
|
|
SetMenuBar(menubar);
|
|
|
|
|
|
|
|
m_logWindow = new wxTextCtrl(this, -1, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
|
|
|
|
|
|
|
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
|
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL);
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
CreateStatusBar(3);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-08 01:07:48 +00:00
|
|
|
MyFrame::~MyFrame()
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
delete wxLog::SetActiveTarget(m_logOld);
|
|
|
|
|
|
|
|
delete m_imageListNormal;
|
|
|
|
delete m_imageListSmall;
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 01:27:38 +00:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-05 01:27:38 +00:00
|
|
|
if ( !m_logWindow )
|
|
|
|
return;
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-07-05 01:27:38 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
event.Skip();
|
1999-07-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 01:27:38 +00:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1999-07-02 15:30:00 +00:00
|
|
|
{
|
2001-07-05 01:27:38 +00:00
|
|
|
Close(TRUE);
|
1999-07-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
|
1998-08-17 15:48:25 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-07-23 23:41:45 +00:00
|
|
|
wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997",
|
|
|
|
"About list test", wxOK|wxCANCEL);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-07-23 23:41:45 +00:00
|
|
|
dialog.ShowModal();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-03-13 17:20:39 +00:00
|
|
|
void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
|
|
|
}
|
|
|
|
|
1998-08-23 20:06:24 +00:00
|
|
|
void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-07-23 23:41:45 +00:00
|
|
|
int n = m_listCtrl->GetItemCount();
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
|
1998-08-23 20:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-07-23 23:41:45 +00:00
|
|
|
int n = m_listCtrl->GetItemCount();
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
1998-08-23 20:06:24 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// changing listctrl modes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MyFrame::RecreateList(long flags, bool withText)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
// 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)) )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
delete m_listCtrl;
|
|
|
|
|
|
|
|
m_listCtrl = new MyListCtrl(this, LIST_CTRL,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
flags |
|
|
|
|
wxSUNKEN_BORDER);
|
|
|
|
|
|
|
|
switch ( flags & wxLC_MASK_TYPE )
|
|
|
|
{
|
|
|
|
case wxLC_LIST:
|
|
|
|
InitWithListItems();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxLC_ICON:
|
|
|
|
InitWithIconItems(withText);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxLC_SMALL_ICON:
|
|
|
|
InitWithIconItems(withText, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxLC_REPORT:
|
|
|
|
if ( flags & wxLC_VIRTUAL )
|
|
|
|
InitWithVirtualItems();
|
|
|
|
else
|
|
|
|
InitWithReportItems();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( _T("unknown listctrl mode") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
SendSizeEvent();
|
|
|
|
#endif
|
|
|
|
|
1999-06-11 17:27:57 +00:00
|
|
|
m_logWindow->Clear();
|
2001-07-07 16:52:27 +00:00
|
|
|
}
|
2000-02-06 20:36:00 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
RecreateList(wxLC_LIST);
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::InitWithListItems()
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < NUM_ITEMS; i++ )
|
1999-06-11 17:27:57 +00:00
|
|
|
{
|
2001-07-05 01:27:38 +00:00
|
|
|
m_listCtrl->InsertItem(i, wxString::Format(_T("Item %d"), i));
|
1999-06-11 17:27:57 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-08-17 15:48:25 +00:00
|
|
|
void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_REPORT);
|
|
|
|
}
|
1999-07-23 23:41:45 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::InitWithReportItems()
|
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-06-11 17:27:57 +00:00
|
|
|
m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
|
|
|
|
m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
|
|
|
|
m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
|
|
|
|
|
2000-02-06 01:30:21 +00:00
|
|
|
// to speed up inserting we hide the control temporarily
|
|
|
|
m_listCtrl->Hide();
|
|
|
|
|
|
|
|
wxStopWatch sw;
|
|
|
|
|
|
|
|
for ( int i = 0; i < NUM_ITEMS; i++ )
|
1999-06-11 17:27:57 +00:00
|
|
|
{
|
2001-07-09 15:58:24 +00:00
|
|
|
m_listCtrl->InsertItemInReportView(i);
|
1999-06-11 17:27:57 +00:00
|
|
|
}
|
1999-12-04 22:34:54 +00:00
|
|
|
|
2000-02-06 01:30:21 +00:00
|
|
|
m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
|
|
|
|
NUM_ITEMS, sw.Time()));
|
|
|
|
m_listCtrl->Show();
|
|
|
|
|
1999-12-04 11:56:28 +00:00
|
|
|
// we leave all mask fields to 0 and only change the colour
|
1999-12-04 22:34:54 +00:00
|
|
|
wxListItem item;
|
|
|
|
item.m_itemId = 0;
|
1999-12-06 10:43:35 +00:00
|
|
|
item.SetTextColour(*wxRED);
|
1999-12-04 22:34:54 +00:00
|
|
|
m_listCtrl->SetItem( item );
|
|
|
|
|
|
|
|
item.m_itemId = 2;
|
1999-12-05 00:20:58 +00:00
|
|
|
item.SetTextColour(*wxGREEN);
|
1999-12-04 22:34:54 +00:00
|
|
|
m_listCtrl->SetItem( item );
|
1999-12-05 00:20:58 +00:00
|
|
|
item.m_itemId = 4;
|
1999-12-04 22:34:54 +00:00
|
|
|
item.SetTextColour(*wxLIGHT_GREY);
|
1999-12-05 00:20:58 +00:00
|
|
|
item.SetFont(*wxITALIC_FONT);
|
|
|
|
item.SetBackgroundColour(*wxRED);
|
1999-12-04 22:34:54 +00:00
|
|
|
m_listCtrl->SetItem( item );
|
1999-07-23 23:41:45 +00:00
|
|
|
|
1999-12-05 00:20:58 +00:00
|
|
|
m_listCtrl->SetTextColour(*wxBLUE);
|
|
|
|
m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY);
|
|
|
|
|
1999-06-11 17:27:57 +00:00
|
|
|
m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
|
|
|
|
m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
|
|
|
|
m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::InitWithIconItems(bool withText, bool sameIcon)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
|
|
|
|
m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
for ( int i = 0; i < NUM_ICONS; i++ )
|
1999-07-23 23:41:45 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
int image = sameIcon ? 0 : i;
|
|
|
|
|
|
|
|
if ( withText )
|
|
|
|
{
|
|
|
|
m_listCtrl->InsertItem(i, wxString::Format(_T("Label %d"), i),
|
|
|
|
image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_listCtrl->InsertItem(i, image);
|
|
|
|
}
|
1999-07-23 23:41:45 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_ICON, FALSE);
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
RecreateList(wxLC_ICON);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-08-17 15:48:25 +00:00
|
|
|
void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_SMALL_ICON, FALSE);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-08-17 15:48:25 +00:00
|
|
|
void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_SMALL_ICON);
|
1999-07-23 23:41:45 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 01:27:38 +00:00
|
|
|
void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
|
|
|
|
}
|
2001-07-05 01:27:38 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
void MyFrame::InitWithVirtualItems()
|
|
|
|
{
|
2001-07-05 01:27:38 +00:00
|
|
|
m_listCtrl->InsertColumn(0, "First Column");
|
|
|
|
m_listCtrl->InsertColumn(1, "Second Column");
|
|
|
|
m_listCtrl->SetColumnWidth(0, 150);
|
|
|
|
m_listCtrl->SetColumnWidth(1, 150);
|
|
|
|
|
|
|
|
m_listCtrl->SetItemCount(1000000);
|
|
|
|
}
|
|
|
|
|
1999-12-01 22:07:25 +00:00
|
|
|
void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2000-02-06 01:30:21 +00:00
|
|
|
wxStopWatch sw;
|
|
|
|
|
1999-12-01 22:07:25 +00:00
|
|
|
m_listCtrl->SortItems(MyCompareFunction, 0);
|
2000-02-06 01:30:21 +00:00
|
|
|
|
|
|
|
m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
|
|
|
|
m_listCtrl->GetItemCount(),
|
|
|
|
sw.Time()));
|
1999-12-01 22:07:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 22:42:35 +00:00
|
|
|
void MyFrame::OnShowSelInfo(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int selCount = m_listCtrl->GetSelectedItemCount();
|
|
|
|
wxLogMessage(_T("%d items selected:"), selCount);
|
|
|
|
|
|
|
|
// don't show too many items
|
|
|
|
size_t shownCount = 0;
|
|
|
|
|
|
|
|
long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
|
|
|
|
wxLIST_STATE_SELECTED);
|
|
|
|
while ( item != -1 )
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("\t%ld (%s)"),
|
|
|
|
item, m_listCtrl->GetItemText(item).c_str());
|
|
|
|
|
|
|
|
if ( ++shownCount > 10 )
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("\t... more selected items snipped..."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
|
|
|
|
wxLIST_STATE_SELECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
void MyFrame::OnShowColInfo(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int count = m_listCtrl->GetColumnCount();
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage(wxT("%d columns:"), count);
|
2000-07-15 19:51:35 +00:00
|
|
|
for ( int c = 0; c < count; c++ )
|
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage(wxT("\tcolumn %d has width %d"), c,
|
2000-07-15 19:51:35 +00:00
|
|
|
m_listCtrl->GetColumnWidth(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 );
|
|
|
|
}
|
|
|
|
|
2000-02-10 18:12:44 +00:00
|
|
|
void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
long flags = m_listCtrl->GetWindowStyleFlag();
|
|
|
|
if ( flags & wxLC_SINGLE_SEL )
|
2001-07-07 16:52:27 +00:00
|
|
|
flags &= ~wxLC_SINGLE_SEL;
|
2000-02-10 18:12:44 +00:00
|
|
|
else
|
2001-07-07 16:52:27 +00:00
|
|
|
flags |= wxLC_SINGLE_SEL;
|
|
|
|
|
2001-08-02 18:59:50 +00:00
|
|
|
m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"),
|
2001-07-07 16:52:27 +00:00
|
|
|
(flags & wxLC_SINGLE_SEL) ? "sing" : "multip"));
|
2000-02-10 18:12:44 +00:00
|
|
|
|
2001-07-07 16:52:27 +00:00
|
|
|
RecreateList(flags);
|
2000-02-10 18:12:44 +00:00
|
|
|
}
|
|
|
|
|
2000-02-08 01:07:48 +00:00
|
|
|
void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
|
|
|
|
m_listCtrl->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this));
|
|
|
|
m_listCtrl->Refresh();
|
|
|
|
}
|
|
|
|
|
2001-07-06 21:18:15 +00:00
|
|
|
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), _T("Appended item"));
|
|
|
|
}
|
|
|
|
|
2001-06-23 22:24:33 +00:00
|
|
|
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
if ( m_listCtrl->GetItemCount() )
|
|
|
|
{
|
|
|
|
m_listCtrl->DeleteItem(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_logWindow->WriteText("Nothing to delete");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-23 23:41:45 +00:00
|
|
|
void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2000-02-06 01:30:21 +00:00
|
|
|
wxStopWatch sw;
|
1999-07-23 23:41:45 +00:00
|
|
|
|
|
|
|
m_listCtrl->DeleteAllItems();
|
|
|
|
|
2000-02-06 01:30:21 +00:00
|
|
|
m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
|
|
|
|
m_listCtrl->GetItemCount(),
|
|
|
|
sw.Time()));
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MyListCtrl
|
|
|
|
|
2001-07-20 00:25:09 +00:00
|
|
|
void MyListCtrl::OnCacheHint(wxListEvent& event)
|
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
|
2001-07-20 00:25:09 +00:00
|
|
|
event.GetCacheFrom(), event.GetCacheTo() );
|
|
|
|
}
|
|
|
|
|
1999-08-24 20:26:06 +00:00
|
|
|
void MyListCtrl::OnColClick(wxListEvent& event)
|
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnColumnClick at %d."), event.GetColumn() );
|
1999-08-24 20:26:06 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
void MyListCtrl::OnBeginDrag(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnBeginDrag at %d,%d."),
|
2000-02-24 23:40:42 +00:00
|
|
|
event.m_pointDrag.x, event.m_pointDrag.y );
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
void MyListCtrl::OnBeginRDrag(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
|
2000-02-24 23:40:42 +00:00
|
|
|
event.m_pointDrag.x, event.m_pointDrag.y );
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage( wxT("OnEndLabelEdit: %s"), event.m_item.m_text.c_str());
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-22 15:22:21 +00:00
|
|
|
void MyListCtrl::OnDeleteItem(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnDeleteItem"));
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-24 23:40:42 +00:00
|
|
|
void MyListCtrl::OnDeleteAllItems(wxListEvent& event)
|
2000-02-06 13:51:01 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnDeleteAllItems"));
|
2000-02-06 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
void MyListCtrl::OnGetInfo(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
wxString msg;
|
1999-07-23 23:41:45 +00:00
|
|
|
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_STATE )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_STATE";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_TEXT";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_IMAGE";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_DATA )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_DATA";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_SET_ITEM )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_SET_ITEM";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_WIDTH";
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
|
2000-02-24 23:40:42 +00:00
|
|
|
msg << " wxLIST_MASK_WIDTH";
|
1999-07-23 23:41:45 +00:00
|
|
|
|
|
|
|
if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
|
|
|
|
{
|
|
|
|
event.m_item.m_text = "My callback text";
|
|
|
|
}
|
2000-02-24 23:40:42 +00:00
|
|
|
|
|
|
|
wxLogMessage(msg);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-22 15:22:21 +00:00
|
|
|
void MyListCtrl::OnSetInfo(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnSetInfo"));
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-29 22:47:56 +00:00
|
|
|
void MyListCtrl::OnSelected(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnSelected"));
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-11-16 16:59:10 +00:00
|
|
|
if ( GetWindowStyle() & wxLC_REPORT )
|
1999-09-29 22:47:56 +00:00
|
|
|
{
|
1999-11-16 16:59:10 +00:00
|
|
|
wxListItem info;
|
|
|
|
info.m_itemId = event.m_itemIndex;
|
|
|
|
info.m_col = 1;
|
|
|
|
info.m_mask = wxLIST_MASK_TEXT;
|
|
|
|
if ( GetItem(info) )
|
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"),
|
2000-02-24 23:40:42 +00:00
|
|
|
info.m_text.c_str());
|
1999-11-16 16:59:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-02 18:59:50 +00:00
|
|
|
wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
|
1999-11-16 16:59:10 +00:00
|
|
|
}
|
1999-09-29 22:47:56 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-22 15:22:21 +00:00
|
|
|
void MyListCtrl::OnDeselected(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnDeselected"));
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-22 15:22:21 +00:00
|
|
|
void MyListCtrl::OnActivated(wxListEvent& event)
|
1998-12-16 08:06:02 +00:00
|
|
|
{
|
2000-02-24 23:40:42 +00:00
|
|
|
LogEvent(event, _T("OnActivated"));
|
1998-12-16 08:06:02 +00:00
|
|
|
}
|
|
|
|
|
1999-05-14 14:44:03 +00:00
|
|
|
void MyListCtrl::OnListKeyDown(wxListEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-07-09 15:58:24 +00:00
|
|
|
switch ( event.GetCode() )
|
|
|
|
{
|
2001-07-11 16:22:12 +00:00
|
|
|
case 'c':
|
|
|
|
{
|
|
|
|
wxListItem info;
|
|
|
|
info.m_itemId = event.GetIndex();
|
|
|
|
GetItem(info);
|
|
|
|
|
|
|
|
wxListItemAttr *attr = info.GetAttributes();
|
|
|
|
if ( !attr || !attr->HasTextColour() )
|
|
|
|
{
|
|
|
|
info.SetTextColour(*wxCYAN);
|
|
|
|
|
|
|
|
SetItem(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-09 15:58:24 +00:00
|
|
|
case WXK_DELETE:
|
2001-07-23 14:57:01 +00:00
|
|
|
{
|
|
|
|
long item = GetNextItem(-1,
|
|
|
|
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
|
|
while ( item != -1 )
|
|
|
|
{
|
|
|
|
DeleteItem(item);
|
|
|
|
|
|
|
|
wxLogMessage(_T("Item %ld deleted"), item);
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2001-07-23 14:57:01 +00:00
|
|
|
// -1 because the indices were shifted by DeleteItem()
|
|
|
|
item = GetNextItem(item - 1,
|
|
|
|
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
|
|
}
|
|
|
|
}
|
2001-07-09 15:58:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_INSERT:
|
|
|
|
if ( GetWindowStyle() & wxLC_REPORT )
|
|
|
|
{
|
|
|
|
if ( GetWindowStyle() & wxLC_VIRTUAL )
|
|
|
|
{
|
|
|
|
SetItemCount(GetItemCount() + 1);
|
|
|
|
}
|
|
|
|
else // !virtual
|
|
|
|
{
|
|
|
|
InsertItemInReportView(event.GetIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//else: fall through
|
|
|
|
|
|
|
|
default:
|
|
|
|
LogEvent(event, _T("OnListKeyDown"));
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
2000-07-15 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyListCtrl::OnChar(wxKeyEvent& event)
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("Got char event."));
|
|
|
|
|
|
|
|
event.Skip();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-24 23:40:42 +00:00
|
|
|
void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName)
|
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
|
|
|
|
event.GetIndex(), eventName,
|
|
|
|
event.GetText().c_str(), event.GetData());
|
2000-02-24 23:40:42 +00:00
|
|
|
}
|
1998-12-16 08:06:02 +00:00
|
|
|
|
2001-07-05 01:27:38 +00:00
|
|
|
wxString MyListCtrl::OnGetItemText(long item, long column) const
|
|
|
|
{
|
|
|
|
return wxString::Format(_T("Column %ld of item %ld"), column, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MyListCtrl::OnGetItemImage(long item) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 16:22:12 +00:00
|
|
|
wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
|
|
|
|
{
|
|
|
|
return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
|
|
|
|
}
|
|
|
|
|
2001-07-09 15:58:24 +00:00
|
|
|
void MyListCtrl::InsertItemInReportView(int i)
|
|
|
|
{
|
|
|
|
wxString buf;
|
|
|
|
buf.Printf(_T("This is item %d"), i);
|
|
|
|
long tmp = InsertItem(i, buf, 0);
|
|
|
|
SetItemData(tmp, i);
|
|
|
|
|
|
|
|
buf.Printf(_T("Col 1, item %d"), i);
|
|
|
|
SetItem(i, 1, buf);
|
|
|
|
|
|
|
|
buf.Printf(_T("Item %d in column 2"), i);
|
|
|
|
SetItem(i, 2, buf);
|
|
|
|
}
|
|
|
|
|