1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
29 #include "mondrian.xpm"
31 #include "bitmaps/toolbrai.xpm"
32 #include "bitmaps/toolchar.xpm"
33 #include "bitmaps/tooldata.xpm"
34 #include "bitmaps/toolnote.xpm"
35 #include "bitmaps/tooltodo.xpm"
36 #include "bitmaps/toolchec.xpm"
37 #include "bitmaps/toolgame.xpm"
38 #include "bitmaps/tooltime.xpm"
39 #include "bitmaps/toolword.xpm"
40 #include "bitmaps/small1.xpm"
43 #include "wx/imaglist.h"
44 #include "wx/listctrl.h"
45 #include "wx/timer.h" // for wxStopWatch
46 #include "wx/colordlg.h" // for wxGetColourFromUser
50 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
51 EVT_SIZE(MyFrame::OnSize
)
53 EVT_MENU(LIST_QUIT
, MyFrame::OnQuit
)
54 EVT_MENU(LIST_ABOUT
, MyFrame::OnAbout
)
55 EVT_MENU(LIST_LIST_VIEW
, MyFrame::OnListView
)
56 EVT_MENU(LIST_REPORT_VIEW
, MyFrame::OnReportView
)
57 EVT_MENU(LIST_ICON_VIEW
, MyFrame::OnIconView
)
58 EVT_MENU(LIST_ICON_TEXT_VIEW
, MyFrame::OnIconTextView
)
59 EVT_MENU(LIST_SMALL_ICON_VIEW
, MyFrame::OnSmallIconView
)
60 EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW
, MyFrame::OnSmallIconTextView
)
61 EVT_MENU(LIST_VIRTUAL_VIEW
, MyFrame::OnVirtualView
)
63 EVT_MENU(LIST_TOGGLE_FIRST
, MyFrame::OnToggleFirstSel
)
64 EVT_MENU(LIST_DESELECT_ALL
, MyFrame::OnDeselectAll
)
65 EVT_MENU(LIST_SELECT_ALL
, MyFrame::OnSelectAll
)
66 EVT_MENU(LIST_DELETE
, MyFrame::OnDelete
)
67 EVT_MENU(LIST_ADD
, MyFrame::OnAdd
)
68 EVT_MENU(LIST_DELETE_ALL
, MyFrame::OnDeleteAll
)
69 EVT_MENU(LIST_SORT
, MyFrame::OnSort
)
70 EVT_MENU(LIST_SET_FG_COL
, MyFrame::OnSetFgColour
)
71 EVT_MENU(LIST_SET_BG_COL
, MyFrame::OnSetBgColour
)
72 EVT_MENU(LIST_TOGGLE_MULTI_SEL
, MyFrame::OnToggleMultiSel
)
73 EVT_MENU(LIST_SHOW_COL_INFO
, MyFrame::OnShowColInfo
)
74 EVT_MENU(LIST_SHOW_SEL_INFO
, MyFrame::OnShowSelInfo
)
76 EVT_UPDATE_UI(LIST_SHOW_COL_INFO
, MyFrame::OnUpdateShowColInfo
)
79 BEGIN_EVENT_TABLE(MyListCtrl
, wxListCtrl
)
80 EVT_LIST_BEGIN_DRAG(LIST_CTRL
, MyListCtrl::OnBeginDrag
)
81 EVT_LIST_BEGIN_RDRAG(LIST_CTRL
, MyListCtrl::OnBeginRDrag
)
82 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL
, MyListCtrl::OnBeginLabelEdit
)
83 EVT_LIST_END_LABEL_EDIT(LIST_CTRL
, MyListCtrl::OnEndLabelEdit
)
84 EVT_LIST_DELETE_ITEM(LIST_CTRL
, MyListCtrl::OnDeleteItem
)
85 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL
, MyListCtrl::OnDeleteAllItems
)
86 EVT_LIST_GET_INFO(LIST_CTRL
, MyListCtrl::OnGetInfo
)
87 EVT_LIST_SET_INFO(LIST_CTRL
, MyListCtrl::OnSetInfo
)
88 EVT_LIST_ITEM_SELECTED(LIST_CTRL
, MyListCtrl::OnSelected
)
89 EVT_LIST_ITEM_DESELECTED(LIST_CTRL
, MyListCtrl::OnDeselected
)
90 EVT_LIST_KEY_DOWN(LIST_CTRL
, MyListCtrl::OnListKeyDown
)
91 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL
, MyListCtrl::OnActivated
)
92 EVT_LIST_COL_CLICK(LIST_CTRL
, MyListCtrl::OnColClick
)
94 EVT_CHAR(MyListCtrl::OnChar
)
99 // number of items in list/report view
100 static const int NUM_ITEMS
= 30;
102 // number of items in icon/small icon view
103 static const int NUM_ICONS
= 9;
105 int wxCALLBACK
MyCompareFunction(long item1
, long item2
, long sortData
)
108 return item1
< item2
;
111 // `Main program' equivalent, creating windows and returning main app frame
114 // Create the main frame window
115 MyFrame
*frame
= new MyFrame("wxListCtrl Test", 50, 50, 450, 340);
125 // My frame constructor
126 MyFrame::MyFrame(const wxChar
*title
, int x
, int y
, int w
, int h
)
127 : wxFrame((wxFrame
*)NULL
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
129 m_listCtrl
= (MyListCtrl
*) NULL
;
130 m_logWindow
= (wxTextCtrl
*) NULL
;
133 SetIcon( wxICON(mondrian
) );
135 // Make an image list containing large icons
136 m_imageListNormal
= new wxImageList(32, 32, TRUE
);
137 m_imageListSmall
= new wxImageList(16, 16, TRUE
);
140 m_imageListNormal
->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE
) );
141 m_imageListNormal
->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE
) );
142 m_imageListNormal
->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE
) );
143 m_imageListNormal
->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE
) );
144 m_imageListNormal
->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE
) );
145 m_imageListNormal
->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE
) );
146 m_imageListNormal
->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE
) );
147 m_imageListNormal
->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE
) );
148 m_imageListNormal
->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE
) );
150 m_imageListSmall
->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE
) );
153 m_imageListNormal
->Add( wxIcon( toolbrai_xpm
) );
154 m_imageListNormal
->Add( wxIcon( toolchar_xpm
) );
155 m_imageListNormal
->Add( wxIcon( tooldata_xpm
) );
156 m_imageListNormal
->Add( wxIcon( toolnote_xpm
) );
157 m_imageListNormal
->Add( wxIcon( tooltodo_xpm
) );
158 m_imageListNormal
->Add( wxIcon( toolchec_xpm
) );
159 m_imageListNormal
->Add( wxIcon( toolgame_xpm
) );
160 m_imageListNormal
->Add( wxIcon( tooltime_xpm
) );
161 m_imageListNormal
->Add( wxIcon( toolword_xpm
) );
163 m_imageListSmall
->Add( wxIcon( small1_xpm
) );
167 wxMenu
*menuFile
= new wxMenu
;
168 menuFile
->Append(LIST_ABOUT
, _T("&About"));
169 menuFile
->AppendSeparator();
170 menuFile
->Append(LIST_QUIT
, _T("E&xit\tAlt-X"));
172 wxMenu
*menuView
= new wxMenu
;
173 menuView
->Append(LIST_LIST_VIEW
, _T("&List view\tF1"));
174 menuView
->Append(LIST_REPORT_VIEW
, _T("&Report view\tF2"));
175 menuView
->Append(LIST_ICON_VIEW
, _T("&Icon view\tF3"));
176 menuView
->Append(LIST_ICON_TEXT_VIEW
, _T("Icon view with &text\tF4"));
177 menuView
->Append(LIST_SMALL_ICON_VIEW
, _T("&Small icon view\tF5"));
178 menuView
->Append(LIST_SMALL_ICON_TEXT_VIEW
, _T("Small icon &view with text\tF6"));
179 menuView
->Append(LIST_VIRTUAL_VIEW
, _T("Virtual view\tF7"));
181 wxMenu
*menuList
= new wxMenu
;
182 menuList
->Append(LIST_TOGGLE_FIRST
, _T("&Toggle first item\tCtrl-T"));
183 menuList
->Append(LIST_DESELECT_ALL
, _T("&Deselect All\tCtrl-D"));
184 menuList
->Append(LIST_SELECT_ALL
, _T("S&elect All\tCtrl-A"));
185 menuList
->AppendSeparator();
186 menuList
->Append(LIST_SHOW_COL_INFO
, _T("Show &column info\tCtrl-C"));
187 menuList
->Append(LIST_SHOW_SEL_INFO
, _T("Show &selected items\tCtrl-S"));
188 menuList
->AppendSeparator();
189 menuList
->Append(LIST_SORT
, _T("&Sort\tCtrl-S"));
190 menuList
->AppendSeparator();
191 menuList
->Append(LIST_ADD
, _T("&Append an item\tCtrl-P"));
192 menuList
->Append(LIST_DELETE
, _T("&Delete first item\tCtrl-X"));
193 menuList
->Append(LIST_DELETE_ALL
, _T("Delete &all items"));
194 menuList
->AppendSeparator();
195 menuList
->Append(LIST_TOGGLE_MULTI_SEL
, _T("&Multiple selection\tCtrl-M"),
196 _T("Toggle multiple selection"), TRUE
);
198 wxMenu
*menuCol
= new wxMenu
;
199 menuCol
->Append(LIST_SET_FG_COL
, _T("&Foreground colour..."));
200 menuCol
->Append(LIST_SET_BG_COL
, _T("&Background colour..."));
202 wxMenuBar
*menubar
= new wxMenuBar
;
203 menubar
->Append(menuFile
, _T("&File"));
204 menubar
->Append(menuView
, _T("&View"));
205 menubar
->Append(menuList
, _T("&List"));
206 menubar
->Append(menuCol
, _T("&Colour"));
209 m_logWindow
= new wxTextCtrl(this, -1, wxEmptyString
,
210 wxDefaultPosition
, wxDefaultSize
,
211 wxTE_MULTILINE
| wxSUNKEN_BORDER
);
213 m_logOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow
));
215 RecreateList(wxLC_REPORT
| wxLC_SINGLE_SEL
);
222 delete wxLog::SetActiveTarget(m_logOld
);
224 delete m_imageListNormal
;
225 delete m_imageListSmall
;
228 void MyFrame::OnSize(wxSizeEvent
& event
)
233 wxSize size
= GetClientSize();
234 wxCoord y
= (2*size
.y
)/3;
235 m_listCtrl
->SetSize(0, 0, size
.x
, y
);
236 m_logWindow
->SetSize(0, y
+ 1, size
.x
, size
.y
- y
);
241 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
246 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
248 wxMessageDialog
dialog(this, "List test sample\nJulian Smart (c) 1997",
249 "About list test", wxOK
|wxCANCEL
);
254 void MyFrame::OnToggleFirstSel(wxCommandEvent
& WXUNUSED(event
))
256 m_listCtrl
->SetItemState(0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
259 void MyFrame::OnDeselectAll(wxCommandEvent
& WXUNUSED(event
))
261 int n
= m_listCtrl
->GetItemCount();
262 for (int i
= 0; i
< n
; i
++)
263 m_listCtrl
->SetItemState(i
,0,wxLIST_STATE_SELECTED
);
266 void MyFrame::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
268 int n
= m_listCtrl
->GetItemCount();
269 for (int i
= 0; i
< n
; i
++)
270 m_listCtrl
->SetItemState(i
,wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
273 // ----------------------------------------------------------------------------
274 // changing listctrl modes
275 // ----------------------------------------------------------------------------
277 void MyFrame::RecreateList(long flags
, bool withText
)
279 // we could avoid recreating it if we don't set/clear the wxLC_VIRTUAL
280 // style, but it is more trouble to do it than not
282 if ( !m_listCtrl
|| ((flags
& wxLC_VIRTUAL
) !=
283 (m_listCtrl
->GetWindowStyleFlag() & wxLC_VIRTUAL
)) )
288 m_listCtrl
= new MyListCtrl(this, LIST_CTRL
,
289 wxDefaultPosition
, wxDefaultSize
,
293 switch ( flags
& wxLC_MASK_TYPE
)
300 InitWithIconItems(withText
);
303 case wxLC_SMALL_ICON
:
304 InitWithIconItems(withText
, TRUE
);
308 if ( flags
& wxLC_VIRTUAL
)
309 InitWithVirtualItems();
311 InitWithReportItems();
315 wxFAIL_MSG( _T("unknown listctrl mode") );
323 m_logWindow
->Clear();
326 void MyFrame::OnListView(wxCommandEvent
& WXUNUSED(event
))
328 RecreateList(wxLC_LIST
);
331 void MyFrame::InitWithListItems()
333 for ( int i
= 0; i
< NUM_ITEMS
; i
++ )
335 m_listCtrl
->InsertItem(i
, wxString::Format(_T("Item %d"), i
));
339 void MyFrame::OnReportView(wxCommandEvent
& WXUNUSED(event
))
341 RecreateList(wxLC_REPORT
);
344 void MyFrame::InitWithReportItems()
346 m_listCtrl
->SetImageList(m_imageListSmall
, wxIMAGE_LIST_SMALL
);
348 m_listCtrl
->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
349 m_listCtrl
->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
350 m_listCtrl
->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
352 // to speed up inserting we hide the control temporarily
357 for ( int i
= 0; i
< NUM_ITEMS
; i
++ )
359 m_listCtrl
->InsertItemInReportView(i
);
362 m_logWindow
->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
363 NUM_ITEMS
, sw
.Time()));
366 // we leave all mask fields to 0 and only change the colour
369 item
.SetTextColour(*wxRED
);
370 m_listCtrl
->SetItem( item
);
373 item
.SetTextColour(*wxGREEN
);
374 m_listCtrl
->SetItem( item
);
376 item
.SetTextColour(*wxLIGHT_GREY
);
377 item
.SetFont(*wxITALIC_FONT
);
378 item
.SetBackgroundColour(*wxRED
);
379 m_listCtrl
->SetItem( item
);
381 m_listCtrl
->SetTextColour(*wxBLUE
);
382 m_listCtrl
->SetBackgroundColour(*wxLIGHT_GREY
);
384 m_listCtrl
->SetColumnWidth( 0, wxLIST_AUTOSIZE
);
385 m_listCtrl
->SetColumnWidth( 1, wxLIST_AUTOSIZE
);
386 m_listCtrl
->SetColumnWidth( 2, wxLIST_AUTOSIZE
);
389 void MyFrame::InitWithIconItems(bool withText
, bool sameIcon
)
391 m_listCtrl
->SetImageList(m_imageListNormal
, wxIMAGE_LIST_NORMAL
);
392 m_listCtrl
->SetImageList(m_imageListSmall
, wxIMAGE_LIST_SMALL
);
394 for ( int i
= 0; i
< NUM_ICONS
; i
++ )
396 int image
= sameIcon
? 0 : i
;
400 m_listCtrl
->InsertItem(i
, wxString::Format(_T("Label %d"), i
),
405 m_listCtrl
->InsertItem(i
, image
);
410 void MyFrame::OnIconView(wxCommandEvent
& WXUNUSED(event
))
412 RecreateList(wxLC_ICON
, FALSE
);
415 void MyFrame::OnIconTextView(wxCommandEvent
& WXUNUSED(event
))
417 RecreateList(wxLC_ICON
);
420 void MyFrame::OnSmallIconView(wxCommandEvent
& WXUNUSED(event
))
422 RecreateList(wxLC_SMALL_ICON
, FALSE
);
425 void MyFrame::OnSmallIconTextView(wxCommandEvent
& WXUNUSED(event
))
427 RecreateList(wxLC_SMALL_ICON
);
430 void MyFrame::OnVirtualView(wxCommandEvent
& WXUNUSED(event
))
432 RecreateList(wxLC_REPORT
| wxLC_VIRTUAL
);
435 void MyFrame::InitWithVirtualItems()
437 m_listCtrl
->InsertColumn(0, "First Column");
438 m_listCtrl
->InsertColumn(1, "Second Column");
439 m_listCtrl
->SetColumnWidth(0, 150);
440 m_listCtrl
->SetColumnWidth(1, 150);
442 m_listCtrl
->SetItemCount(1000000);
445 void MyFrame::OnSort(wxCommandEvent
& WXUNUSED(event
))
449 m_listCtrl
->SortItems(MyCompareFunction
, 0);
451 m_logWindow
->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
452 m_listCtrl
->GetItemCount(),
456 void MyFrame::OnShowSelInfo(wxCommandEvent
& event
)
458 int selCount
= m_listCtrl
->GetSelectedItemCount();
459 wxLogMessage(_T("%d items selected:"), selCount
);
461 // don't show too many items
462 size_t shownCount
= 0;
464 long item
= m_listCtrl
->GetNextItem(-1, wxLIST_NEXT_ALL
,
465 wxLIST_STATE_SELECTED
);
468 wxLogMessage(_T("\t%ld (%s)"),
469 item
, m_listCtrl
->GetItemText(item
).c_str());
471 if ( ++shownCount
> 10 )
473 wxLogMessage(_T("\t... more selected items snipped..."));
477 item
= m_listCtrl
->GetNextItem(item
, wxLIST_NEXT_ALL
,
478 wxLIST_STATE_SELECTED
);
482 void MyFrame::OnShowColInfo(wxCommandEvent
& event
)
484 int count
= m_listCtrl
->GetColumnCount();
485 wxLogMessage("%d columns:", count
);
486 for ( int c
= 0; c
< count
; c
++ )
488 wxLogMessage("\tcolumn %d has width %d", c
,
489 m_listCtrl
->GetColumnWidth(c
));
493 void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent
& event
)
495 event
.Enable( (m_listCtrl
->GetWindowStyleFlag() & wxLC_REPORT
) != 0 );
498 void MyFrame::OnToggleMultiSel(wxCommandEvent
& WXUNUSED(event
))
500 long flags
= m_listCtrl
->GetWindowStyleFlag();
501 if ( flags
& wxLC_SINGLE_SEL
)
502 flags
&= ~wxLC_SINGLE_SEL
;
504 flags
|= wxLC_SINGLE_SEL
;
506 m_logWindow
->WriteText(wxString::Format("Current selection mode: %sle\n",
507 (flags
& wxLC_SINGLE_SEL
) ? "sing" : "multip"));
512 void MyFrame::OnSetFgColour(wxCommandEvent
& WXUNUSED(event
))
514 m_listCtrl
->SetForegroundColour(wxGetColourFromUser(this));
515 m_listCtrl
->Refresh();
518 void MyFrame::OnSetBgColour(wxCommandEvent
& WXUNUSED(event
))
520 m_listCtrl
->SetBackgroundColour(wxGetColourFromUser(this));
521 m_listCtrl
->Refresh();
524 void MyFrame::OnAdd(wxCommandEvent
& WXUNUSED(event
))
526 m_listCtrl
->InsertItem(m_listCtrl
->GetItemCount(), _T("Appended item"));
529 void MyFrame::OnDelete(wxCommandEvent
& WXUNUSED(event
))
531 if ( m_listCtrl
->GetItemCount() )
533 m_listCtrl
->DeleteItem(0);
537 m_logWindow
->WriteText("Nothing to delete");
541 void MyFrame::OnDeleteAll(wxCommandEvent
& WXUNUSED(event
))
545 m_listCtrl
->DeleteAllItems();
547 m_logWindow
->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
548 m_listCtrl
->GetItemCount(),
554 void MyListCtrl::OnColClick(wxListEvent
& event
)
556 wxLogMessage( "OnColumnClick at %d.", event
.GetColumn() );
559 void MyListCtrl::OnBeginDrag(wxListEvent
& event
)
561 wxLogMessage( "OnBeginDrag at %d,%d.",
562 event
.m_pointDrag
.x
, event
.m_pointDrag
.y
);
565 void MyListCtrl::OnBeginRDrag(wxListEvent
& event
)
567 wxLogMessage( "OnBeginRDrag at %d,%d.",
568 event
.m_pointDrag
.x
, event
.m_pointDrag
.y
);
571 void MyListCtrl::OnBeginLabelEdit(wxListEvent
& event
)
573 wxLogMessage("OnBeginLabelEdit: %s", event
.m_item
.m_text
.c_str());
576 void MyListCtrl::OnEndLabelEdit(wxListEvent
& event
)
578 wxLogMessage("OnEndLabelEdit: %s", event
.m_item
.m_text
.c_str());
581 void MyListCtrl::OnDeleteItem(wxListEvent
& event
)
583 LogEvent(event
, _T("OnDeleteItem"));
586 void MyListCtrl::OnDeleteAllItems(wxListEvent
& event
)
588 LogEvent(event
, _T("OnDeleteAllItems"));
591 void MyListCtrl::OnGetInfo(wxListEvent
& event
)
595 msg
<< "OnGetInfo (" << event
.m_item
.m_itemId
<< ", " << event
.m_item
.m_col
<< ")";
596 if ( event
.m_item
.m_mask
& wxLIST_MASK_STATE
)
597 msg
<< " wxLIST_MASK_STATE";
598 if ( event
.m_item
.m_mask
& wxLIST_MASK_TEXT
)
599 msg
<< " wxLIST_MASK_TEXT";
600 if ( event
.m_item
.m_mask
& wxLIST_MASK_IMAGE
)
601 msg
<< " wxLIST_MASK_IMAGE";
602 if ( event
.m_item
.m_mask
& wxLIST_MASK_DATA
)
603 msg
<< " wxLIST_MASK_DATA";
604 if ( event
.m_item
.m_mask
& wxLIST_SET_ITEM
)
605 msg
<< " wxLIST_SET_ITEM";
606 if ( event
.m_item
.m_mask
& wxLIST_MASK_WIDTH
)
607 msg
<< " wxLIST_MASK_WIDTH";
608 if ( event
.m_item
.m_mask
& wxLIST_MASK_FORMAT
)
609 msg
<< " wxLIST_MASK_WIDTH";
611 if ( event
.m_item
.m_mask
& wxLIST_MASK_TEXT
)
613 event
.m_item
.m_text
= "My callback text";
619 void MyListCtrl::OnSetInfo(wxListEvent
& event
)
621 LogEvent(event
, _T("OnSetInfo"));
624 void MyListCtrl::OnSelected(wxListEvent
& event
)
626 LogEvent(event
, _T("OnSelected"));
628 if ( GetWindowStyle() & wxLC_REPORT
)
631 info
.m_itemId
= event
.m_itemIndex
;
633 info
.m_mask
= wxLIST_MASK_TEXT
;
636 wxLogMessage("Value of the 2nd field of the selected item: %s",
637 info
.m_text
.c_str());
641 wxFAIL_MSG("wxListCtrl::GetItem() failed");
646 void MyListCtrl::OnDeselected(wxListEvent
& event
)
648 LogEvent(event
, _T("OnDeselected"));
651 void MyListCtrl::OnActivated(wxListEvent
& event
)
653 LogEvent(event
, _T("OnActivated"));
656 void MyListCtrl::OnListKeyDown(wxListEvent
& event
)
658 switch ( event
.GetCode() )
661 DeleteItem(event
.GetIndex());
663 wxLogMessage(_T("Item %d deleted"), event
.GetIndex());
667 if ( GetWindowStyle() & wxLC_REPORT
)
669 if ( GetWindowStyle() & wxLC_VIRTUAL
)
671 SetItemCount(GetItemCount() + 1);
675 InsertItemInReportView(event
.GetIndex());
681 LogEvent(event
, _T("OnListKeyDown"));
687 void MyListCtrl::OnChar(wxKeyEvent
& event
)
689 wxLogMessage(_T("Got char event."));
694 void MyListCtrl::LogEvent(const wxListEvent
& event
, const wxChar
*eventName
)
696 wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
697 event
.GetIndex(), eventName
,
698 event
.GetText().c_str(), event
.GetData());
701 wxString
MyListCtrl::OnGetItemText(long item
, long column
) const
703 return wxString::Format(_T("Column %ld of item %ld"), column
, item
);
706 int MyListCtrl::OnGetItemImage(long item
) const
711 void MyListCtrl::InsertItemInReportView(int i
)
714 buf
.Printf(_T("This is item %d"), i
);
715 long tmp
= InsertItem(i
, buf
, 0);
718 buf
.Printf(_T("Col 1, item %d"), i
);
721 buf
.Printf(_T("Item %d in column 2"), i
);