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 DECLARE_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
)
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 #if WXWIN_COMPATIBILITY_2_4
63 void OnGetInfo(wxListEvent
& event
);
64 void OnSetInfo(wxListEvent
& event
);
66 void OnSelected(wxListEvent
& event
);
67 void OnDeselected(wxListEvent
& event
);
68 void OnListKeyDown(wxListEvent
& event
);
69 void OnActivated(wxListEvent
& event
);
70 void OnFocused(wxListEvent
& event
);
71 void OnCacheHint(wxListEvent
& event
);
73 void OnChar(wxKeyEvent
& event
);
76 void OnContextMenu(wxContextMenuEvent
& event
);
79 void OnRightClick(wxMouseEvent
& event
);
82 void ShowContextMenu(const wxPoint
& pos
);
84 void SetColumnImage(int col
, int image
);
86 void LogEvent(const wxListEvent
& event
, const wxChar
*eventName
);
87 void LogColEvent(const wxListEvent
& event
, const wxChar
*eventName
);
89 virtual wxString
OnGetItemText(long item
, long column
) const;
90 virtual int OnGetItemColumnImage(long item
, long column
) const;
91 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
93 wxListItemAttr m_attr
;
95 DECLARE_NO_COPY_CLASS(MyListCtrl
)
99 // Define a new frame type
100 class MyFrame
: public wxFrame
103 MyFrame(const wxChar
*title
);
109 void OnSize(wxSizeEvent
& event
);
111 void OnQuit(wxCommandEvent
& event
);
112 void OnAbout(wxCommandEvent
& event
);
113 void OnListView(wxCommandEvent
& event
);
114 void OnReportView(wxCommandEvent
& event
);
115 void OnIconView(wxCommandEvent
& event
);
116 void OnIconTextView(wxCommandEvent
& event
);
117 void OnSmallIconView(wxCommandEvent
& event
);
118 void OnSmallIconTextView(wxCommandEvent
& event
);
119 void OnVirtualView(wxCommandEvent
& event
);
120 void OnSmallVirtualView(wxCommandEvent
& event
);
122 void OnFocusLast(wxCommandEvent
& event
);
123 void OnToggleFirstSel(wxCommandEvent
& event
);
124 void OnDeselectAll(wxCommandEvent
& event
);
125 void OnSelectAll(wxCommandEvent
& event
);
126 void OnAdd(wxCommandEvent
& event
);
127 void OnEdit(wxCommandEvent
& event
);
128 void OnDelete(wxCommandEvent
& event
);
129 void OnDeleteAll(wxCommandEvent
& event
);
130 void OnSort(wxCommandEvent
& event
);
131 void OnSetFgColour(wxCommandEvent
& event
);
132 void OnSetBgColour(wxCommandEvent
& event
);
133 void OnToggleMultiSel(wxCommandEvent
& event
);
134 void OnShowColInfo(wxCommandEvent
& event
);
135 void OnShowSelInfo(wxCommandEvent
& event
);
136 void OnFreeze(wxCommandEvent
& event
);
137 void OnThaw(wxCommandEvent
& event
);
138 void OnToggleLines(wxCommandEvent
& event
);
140 void OnUpdateShowColInfo(wxUpdateUIEvent
& event
);
141 void OnUpdateToggleMultiSel(wxUpdateUIEvent
& event
);
143 wxImageList
*m_imageListNormal
;
144 wxImageList
*m_imageListSmall
;
147 MyListCtrl
*m_listCtrl
;
148 wxTextCtrl
*m_logWindow
;
151 // recreate the list control with the new flags
152 void RecreateList(long flags
, bool withText
= true);
154 // fill the control with items depending on the view
155 void InitWithListItems();
156 void InitWithReportItems();
157 void InitWithIconItems(bool withText
, bool sameIcon
= false);
158 void InitWithVirtualItems();
160 // return true if the control is not in virtual view, give an error message
161 // and return false if it is
162 bool CheckNonVirtual() const;
169 DECLARE_NO_COPY_CLASS(MyFrame
)
170 DECLARE_EVENT_TABLE()
174 // IDs for the menu commands
177 LIST_ABOUT
= wxID_ABOUT
,
178 LIST_QUIT
= wxID_EXIT
,
180 LIST_LIST_VIEW
= wxID_HIGHEST
,
183 LIST_SMALL_ICON_VIEW
,
184 LIST_SMALL_ICON_TEXT_VIEW
,
187 LIST_SMALL_VIRTUAL_VIEW
,
198 LIST_TOGGLE_MULTI_SEL
,