1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // not all ports have support for EVT_CONTEXT_MENU yet, don't define
13 // USE_CONTEXT_MENU for those which don't
14 #if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__) || defined(__WXMGL__)
15 #define USE_CONTEXT_MENU 0
17 #define USE_CONTEXT_MENU 1
20 // Define a new application type
21 class MyApp
: public wxApp
26 virtual bool OnInit();
29 wxDECLARE_NO_COPY_CLASS(MyApp
);
32 class MyListCtrl
: public wxListCtrl
35 MyListCtrl(wxWindow
*parent
,
40 : wxListCtrl(parent
, id
, pos
, size
, style
),
41 m_attr(*wxBLUE
, *wxLIGHT_GREY
, wxNullFont
)
50 // add one item to the listctrl in report mode
51 void InsertItemInReportView(int i
);
53 void OnColClick(wxListEvent
& event
);
54 void OnColRightClick(wxListEvent
& event
);
55 void OnColBeginDrag(wxListEvent
& event
);
56 void OnColDragging(wxListEvent
& event
);
57 void OnColEndDrag(wxListEvent
& event
);
58 void OnBeginDrag(wxListEvent
& event
);
59 void OnBeginRDrag(wxListEvent
& event
);
60 void OnBeginLabelEdit(wxListEvent
& event
);
61 void OnEndLabelEdit(wxListEvent
& event
);
62 void OnDeleteItem(wxListEvent
& event
);
63 void OnDeleteAllItems(wxListEvent
& event
);
64 void OnSelected(wxListEvent
& event
);
65 void OnDeselected(wxListEvent
& event
);
66 void OnListKeyDown(wxListEvent
& event
);
67 void OnActivated(wxListEvent
& event
);
68 void OnFocused(wxListEvent
& event
);
69 void OnCacheHint(wxListEvent
& event
);
71 void OnChar(wxKeyEvent
& event
);
74 void OnContextMenu(wxContextMenuEvent
& event
);
77 void OnRightClick(wxMouseEvent
& event
);
80 void ShowContextMenu(const wxPoint
& pos
);
82 void SetColumnImage(int col
, int image
);
84 void LogEvent(const wxListEvent
& event
, const wxChar
*eventName
);
85 void LogColEvent(const wxListEvent
& event
, const wxChar
*eventName
);
87 virtual wxString
OnGetItemText(long item
, long column
) const;
88 virtual int OnGetItemColumnImage(long item
, long column
) const;
89 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
91 wxListItemAttr m_attr
;
96 wxDECLARE_NO_COPY_CLASS(MyListCtrl
);
100 // Define a new frame type
101 class MyFrame
: public wxFrame
104 MyFrame(const wxChar
*title
);
110 void OnSize(wxSizeEvent
& event
);
112 void OnQuit(wxCommandEvent
& event
);
113 void OnAbout(wxCommandEvent
& event
);
114 void OnListView(wxCommandEvent
& event
);
115 void OnReportView(wxCommandEvent
& event
);
116 void OnIconView(wxCommandEvent
& event
);
117 void OnIconTextView(wxCommandEvent
& event
);
118 void OnSmallIconView(wxCommandEvent
& event
);
119 void OnSmallIconTextView(wxCommandEvent
& event
);
120 void OnVirtualView(wxCommandEvent
& event
);
121 void OnSmallVirtualView(wxCommandEvent
& event
);
123 void OnGoTo(wxCommandEvent
& event
);
124 void OnFocusLast(wxCommandEvent
& event
);
125 void OnToggleFirstSel(wxCommandEvent
& event
);
126 void OnDeselectAll(wxCommandEvent
& event
);
127 void OnSelectAll(wxCommandEvent
& event
);
128 void OnAdd(wxCommandEvent
& event
);
129 void OnEdit(wxCommandEvent
& event
);
130 void OnDelete(wxCommandEvent
& event
);
131 void OnDeleteAll(wxCommandEvent
& event
);
132 void OnSort(wxCommandEvent
& event
);
133 void OnSetFgColour(wxCommandEvent
& event
);
134 void OnSetBgColour(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 OnToggleMacUseGeneric(wxCommandEvent
& event
);
148 void OnUpdateShowColInfo(wxUpdateUIEvent
& event
);
149 void OnUpdateToggleMultiSel(wxUpdateUIEvent
& event
);
151 wxImageList
*m_imageListNormal
;
152 wxImageList
*m_imageListSmall
;
155 MyListCtrl
*m_listCtrl
;
156 wxListCtrl
*m_simpleListCtrl
;
157 wxTextCtrl
*m_logWindow
;
160 // recreate the list control with the new flags
161 void RecreateList(long flags
, bool withText
= true);
163 // fill the control with items depending on the view
164 void InitWithListItems();
165 void InitWithReportItems();
166 void InitWithIconItems(bool withText
, bool sameIcon
= false);
167 void InitWithVirtualItems();
169 // return true if the control is not in virtual view, give an error message
170 // and return false if it is
171 bool CheckNonVirtual() const;
178 wxDECLARE_NO_COPY_CLASS(MyFrame
);
179 DECLARE_EVENT_TABLE()
183 // IDs for the menu commands
186 LIST_ABOUT
= wxID_ABOUT
,
187 LIST_QUIT
= wxID_EXIT
,
189 LIST_LIST_VIEW
= wxID_HIGHEST
,
192 LIST_SMALL_ICON_VIEW
,
193 LIST_SMALL_ICON_TEXT_VIEW
,
196 LIST_SMALL_VIRTUAL_VIEW
,
207 LIST_TOGGLE_MULTI_SEL
,
212 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
215 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
221 LIST_MAC_USE_GENERIC
,