1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl sample
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // not all ports have support for EVT_CONTEXT_MENU yet, don't define
12 // USE_CONTEXT_MENU for those which don't
13 #if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__)
14 #define USE_CONTEXT_MENU 0
16 #define USE_CONTEXT_MENU 1
19 // Define a new application type
20 class MyApp
: public wxApp
25 virtual bool OnInit();
28 wxDECLARE_NO_COPY_CLASS(MyApp
);
31 class MyListCtrl
: public wxListCtrl
34 MyListCtrl(wxWindow
*parent
,
39 : wxListCtrl(parent
, id
, pos
, size
, style
)
48 // add one item to the listctrl in report mode
49 void InsertItemInReportView(int i
);
51 void OnColClick(wxListEvent
& event
);
52 void OnColRightClick(wxListEvent
& event
);
53 void OnColBeginDrag(wxListEvent
& event
);
54 void OnColDragging(wxListEvent
& event
);
55 void OnColEndDrag(wxListEvent
& event
);
56 void OnBeginDrag(wxListEvent
& event
);
57 void OnBeginRDrag(wxListEvent
& event
);
58 void OnBeginLabelEdit(wxListEvent
& event
);
59 void OnEndLabelEdit(wxListEvent
& event
);
60 void OnDeleteItem(wxListEvent
& event
);
61 void OnDeleteAllItems(wxListEvent
& event
);
62 void OnSelected(wxListEvent
& event
);
63 void OnDeselected(wxListEvent
& event
);
64 void OnListKeyDown(wxListEvent
& event
);
65 void OnActivated(wxListEvent
& event
);
66 void OnFocused(wxListEvent
& event
);
67 void OnCacheHint(wxListEvent
& event
);
69 void OnChar(wxKeyEvent
& event
);
72 void OnContextMenu(wxContextMenuEvent
& event
);
75 void OnRightClick(wxMouseEvent
& event
);
78 void ShowContextMenu(const wxPoint
& pos
);
80 void SetColumnImage(int col
, int image
);
82 void LogEvent(const wxListEvent
& event
, const wxChar
*eventName
);
83 void LogColEvent(const wxListEvent
& event
, const wxChar
*eventName
);
85 virtual wxString
OnGetItemText(long item
, long column
) const;
86 virtual int OnGetItemColumnImage(long item
, long column
) const;
87 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
92 wxDECLARE_NO_COPY_CLASS(MyListCtrl
);
96 // Define a new frame type
97 class MyFrame
: public wxFrame
100 MyFrame(const wxChar
*title
);
106 void OnSize(wxSizeEvent
& event
);
108 void OnQuit(wxCommandEvent
& event
);
109 void OnAbout(wxCommandEvent
& event
);
110 void OnListView(wxCommandEvent
& event
);
111 void OnReportView(wxCommandEvent
& event
);
112 void OnIconView(wxCommandEvent
& event
);
113 void OnIconTextView(wxCommandEvent
& event
);
114 void OnSmallIconView(wxCommandEvent
& event
);
115 void OnSmallIconTextView(wxCommandEvent
& event
);
116 void OnVirtualView(wxCommandEvent
& event
);
117 void OnSmallVirtualView(wxCommandEvent
& event
);
119 void OnSetItemsCount(wxCommandEvent
& event
);
122 void OnGoTo(wxCommandEvent
& event
);
123 void OnFocusLast(wxCommandEvent
& event
);
124 void OnToggleFirstSel(wxCommandEvent
& event
);
125 void OnDeselectAll(wxCommandEvent
& event
);
126 void OnSelectAll(wxCommandEvent
& event
);
127 void OnAdd(wxCommandEvent
& event
);
128 void OnEdit(wxCommandEvent
& event
);
129 void OnDelete(wxCommandEvent
& event
);
130 void OnDeleteAll(wxCommandEvent
& event
);
131 void OnSort(wxCommandEvent
& event
);
132 void OnSetFgColour(wxCommandEvent
& event
);
133 void OnSetBgColour(wxCommandEvent
& event
);
134 void OnSetRowLines(wxCommandEvent
& event
);
135 void OnToggleMultiSel(wxCommandEvent
& event
);
136 void OnShowColInfo(wxCommandEvent
& event
);
137 void OnShowSelInfo(wxCommandEvent
& event
);
138 void OnShowViewRect(wxCommandEvent
& event
);
139 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
140 void OnSetColOrder(wxCommandEvent
& event
);
141 void OnGetColOrder(wxCommandEvent
& event
);
142 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
143 void OnFreeze(wxCommandEvent
& event
);
144 void OnThaw(wxCommandEvent
& event
);
145 void OnToggleLines(wxCommandEvent
& event
);
146 void OnToggleHeader(wxCommandEvent
& event
);
147 void OnToggleBell(wxCommandEvent
& event
);
149 void OnToggleMacUseGeneric(wxCommandEvent
& event
);
151 void OnFind(wxCommandEvent
& event
);
153 void OnUpdateUIEnableInReport(wxUpdateUIEvent
& event
);
154 void OnUpdateToggleMultiSel(wxUpdateUIEvent
& event
);
155 void OnUpdateToggleHeader(wxUpdateUIEvent
& event
);
156 void OnUpdateRowLines(wxUpdateUIEvent
& event
);
158 wxImageList
*m_imageListNormal
;
159 wxImageList
*m_imageListSmall
;
162 MyListCtrl
*m_listCtrl
;
163 wxTextCtrl
*m_logWindow
;
166 // recreate the list control with the new flags
167 void RecreateList(long flags
, bool withText
= true);
169 // fill the control with items depending on the view
170 void InitWithListItems();
171 void InitWithReportItems();
172 void InitWithIconItems(bool withText
, bool sameIcon
= false);
173 void InitWithVirtualItems();
175 // return true if the control is not in virtual view, give an error message
176 // and return false if it is
177 bool CheckNonVirtual() const;
184 // number of items to initialize list/report view with
188 wxDECLARE_NO_COPY_CLASS(MyFrame
);
189 DECLARE_EVENT_TABLE()
193 // IDs for the menu commands
196 LIST_ABOUT
= wxID_ABOUT
,
197 LIST_QUIT
= wxID_EXIT
,
199 LIST_LIST_VIEW
= wxID_HIGHEST
,
202 LIST_SMALL_ICON_VIEW
,
203 LIST_SMALL_ICON_TEXT_VIEW
,
206 LIST_SMALL_VIRTUAL_VIEW
,
207 LIST_SET_ITEMS_COUNT
,
220 LIST_TOGGLE_MULTI_SEL
,
227 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
230 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
237 LIST_MAC_USE_GENERIC
,