]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.h | |
3 | // Purpose: wxListCtrl sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
526954c5 | 9 | // Licence: wxWindows licence |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
107ff668 JS |
12 | // not all ports have support for EVT_CONTEXT_MENU yet, don't define |
13 | // USE_CONTEXT_MENU for those which don't | |
f2012fa6 | 14 | #if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__) |
107ff668 JS |
15 | #define USE_CONTEXT_MENU 0 |
16 | #else | |
17 | #define USE_CONTEXT_MENU 1 | |
18 | #endif | |
19 | ||
457814b5 JS |
20 | // Define a new application type |
21 | class MyApp: public wxApp | |
fa5f6926 VZ |
22 | { |
23 | public: | |
c71963cd VZ |
24 | MyApp() { } |
25 | ||
fa5f6926 | 26 | virtual bool OnInit(); |
c71963cd VZ |
27 | |
28 | private: | |
c0c133e1 | 29 | wxDECLARE_NO_COPY_CLASS(MyApp); |
457814b5 JS |
30 | }; |
31 | ||
32 | class MyListCtrl: public wxListCtrl | |
33 | { | |
34 | public: | |
6c02c329 VZ |
35 | MyListCtrl(wxWindow *parent, |
36 | const wxWindowID id, | |
37 | const wxPoint& pos, | |
38 | const wxSize& size, | |
39 | long style) | |
40 | : wxListCtrl(parent, id, pos, size, style), | |
a92b0cfd | 41 | m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont) |
5ea47806 | 42 | { |
ebc9b89d VZ |
43 | m_updated = -1; |
44 | ||
107ff668 JS |
45 | #ifdef __POCKETPC__ |
46 | EnableContextMenu(); | |
47 | #endif | |
5ea47806 | 48 | } |
fa5f6926 | 49 | |
5cd89174 VZ |
50 | // add one item to the listctrl in report mode |
51 | void InsertItemInReportView(int i); | |
52 | ||
8636aed8 | 53 | void OnColClick(wxListEvent& event); |
11358d39 VZ |
54 | void OnColRightClick(wxListEvent& event); |
55 | void OnColBeginDrag(wxListEvent& event); | |
56 | void OnColDragging(wxListEvent& event); | |
57 | void OnColEndDrag(wxListEvent& event); | |
5ea47806 VZ |
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); | |
12c1b46a | 63 | void OnDeleteAllItems(wxListEvent& event); |
5ea47806 VZ |
64 | void OnSelected(wxListEvent& event); |
65 | void OnDeselected(wxListEvent& event); | |
66 | void OnListKeyDown(wxListEvent& event); | |
67 | void OnActivated(wxListEvent& event); | |
0ddefeb0 | 68 | void OnFocused(wxListEvent& event); |
614391dc | 69 | void OnCacheHint(wxListEvent& event); |
457814b5 | 70 | |
88ac883a | 71 | void OnChar(wxKeyEvent& event); |
cfb66763 | 72 | |
107ff668 JS |
73 | #if USE_CONTEXT_MENU |
74 | void OnContextMenu(wxContextMenuEvent& event); | |
75 | #endif | |
88ac883a | 76 | |
164a7972 VZ |
77 | void OnRightClick(wxMouseEvent& event); |
78 | ||
c41ea66a | 79 | private: |
cfb66763 WS |
80 | void ShowContextMenu(const wxPoint& pos); |
81 | wxLog *m_logOld; | |
6f806543 VZ |
82 | void SetColumnImage(int col, int image); |
83 | ||
c41ea66a | 84 | void LogEvent(const wxListEvent& event, const wxChar *eventName); |
2b5f62a0 | 85 | void LogColEvent(const wxListEvent& event, const wxChar *eventName); |
c41ea66a | 86 | |
98ec9dbe | 87 | virtual wxString OnGetItemText(long item, long column) const; |
06db67bc | 88 | virtual int OnGetItemColumnImage(long item, long column) const; |
6c02c329 VZ |
89 | virtual wxListItemAttr *OnGetItemAttr(long item) const; |
90 | ||
91 | wxListItemAttr m_attr; | |
98ec9dbe | 92 | |
ebc9b89d VZ |
93 | long m_updated; |
94 | ||
95 | ||
c0c133e1 | 96 | wxDECLARE_NO_COPY_CLASS(MyListCtrl); |
5ea47806 | 97 | DECLARE_EVENT_TABLE() |
457814b5 JS |
98 | }; |
99 | ||
100 | // Define a new frame type | |
101 | class MyFrame: public wxFrame | |
5ea47806 VZ |
102 | { |
103 | public: | |
107ff668 | 104 | MyFrame(const wxChar *title); |
07bf769e VZ |
105 | virtual ~MyFrame(); |
106 | ||
107 | void DoSize(); | |
5ea47806 | 108 | |
2b5f62a0 | 109 | protected: |
98ec9dbe VZ |
110 | void OnSize(wxSizeEvent& event); |
111 | ||
457814b5 JS |
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); | |
98ec9dbe | 120 | void OnVirtualView(wxCommandEvent& event); |
b0401bea | 121 | void OnSmallVirtualView(wxCommandEvent& event); |
98ec9dbe | 122 | |
beb9e8f2 VZ |
123 | void OnSetItemsCount(wxCommandEvent& event); |
124 | ||
125 | ||
6ef2b230 | 126 | void OnGoTo(wxCommandEvent& event); |
88b792af | 127 | void OnFocusLast(wxCommandEvent& event); |
58b3bdc9 | 128 | void OnToggleFirstSel(wxCommandEvent& event); |
c4771147 KB |
129 | void OnDeselectAll(wxCommandEvent& event); |
130 | void OnSelectAll(wxCommandEvent& event); | |
cf1dfa6b | 131 | void OnAdd(wxCommandEvent& event); |
efe23391 | 132 | void OnEdit(wxCommandEvent& event); |
bec0a261 | 133 | void OnDelete(wxCommandEvent& event); |
5ea47806 | 134 | void OnDeleteAll(wxCommandEvent& event); |
fa5f6926 | 135 | void OnSort(wxCommandEvent& event); |
11f26ea0 VZ |
136 | void OnSetFgColour(wxCommandEvent& event); |
137 | void OnSetBgColour(wxCommandEvent& event); | |
7b848b0d | 138 | void OnToggleMultiSel(wxCommandEvent& event); |
f6bcfd97 | 139 | void OnShowColInfo(wxCommandEvent& event); |
b54e41c5 | 140 | void OnShowSelInfo(wxCommandEvent& event); |
929b7901 | 141 | void OnShowViewRect(wxCommandEvent& event); |
80cc5fc7 VZ |
142 | #ifdef wxHAS_LISTCTRL_COLUMN_ORDER |
143 | void OnSetColOrder(wxCommandEvent& event); | |
144 | void OnGetColOrder(wxCommandEvent& event); | |
145 | #endif // wxHAS_LISTCTRL_COLUMN_ORDER | |
c5c528fc VZ |
146 | void OnFreeze(wxCommandEvent& event); |
147 | void OnThaw(wxCommandEvent& event); | |
494ab5de | 148 | void OnToggleLines(wxCommandEvent& event); |
1bab3627 | 149 | void OnToggleHeader(wxCommandEvent& event); |
8a3f03ff | 150 | #ifdef __WXOSX__ |
2458daa7 | 151 | void OnToggleMacUseGeneric(wxCommandEvent& event); |
8a3f03ff | 152 | #endif // __WXOSX__ |
beb9e8f2 | 153 | void OnFind(wxCommandEvent& event); |
5ea47806 | 154 | |
1bab3627 | 155 | void OnUpdateUIEnableInReport(wxUpdateUIEvent& event); |
ae403b11 | 156 | void OnUpdateToggleMultiSel(wxUpdateUIEvent& event); |
1bab3627 | 157 | void OnUpdateToggleHeader(wxUpdateUIEvent& event); |
5ea47806 | 158 | |
c41ea66a VZ |
159 | wxImageList *m_imageListNormal; |
160 | wxImageList *m_imageListSmall; | |
161 | ||
2b5f62a0 VZ |
162 | wxPanel *m_panel; |
163 | MyListCtrl *m_listCtrl; | |
164 | wxTextCtrl *m_logWindow; | |
165 | ||
c41ea66a | 166 | private: |
776a33cf | 167 | // recreate the list control with the new flags |
1550e402 | 168 | void RecreateList(long flags, bool withText = true); |
776a33cf VZ |
169 | |
170 | // fill the control with items depending on the view | |
171 | void InitWithListItems(); | |
172 | void InitWithReportItems(); | |
1550e402 | 173 | void InitWithIconItems(bool withText, bool sameIcon = false); |
776a33cf VZ |
174 | void InitWithVirtualItems(); |
175 | ||
68457180 VZ |
176 | // return true if the control is not in virtual view, give an error message |
177 | // and return false if it is | |
178 | bool CheckNonVirtual() const; | |
179 | ||
180 | ||
c41ea66a VZ |
181 | wxLog *m_logOld; |
182 | ||
b0401bea VZ |
183 | bool m_smallVirtual; |
184 | ||
beb9e8f2 VZ |
185 | // number of items to initialize list/report view with |
186 | int m_numListItems; | |
187 | ||
188 | ||
c0c133e1 | 189 | wxDECLARE_NO_COPY_CLASS(MyFrame); |
5ea47806 | 190 | DECLARE_EVENT_TABLE() |
457814b5 JS |
191 | }; |
192 | ||
193 | ||
98ec9dbe | 194 | // IDs for the menu commands |
fa5f6926 VZ |
195 | enum |
196 | { | |
658070d1 JS |
197 | LIST_ABOUT = wxID_ABOUT, |
198 | LIST_QUIT = wxID_EXIT, | |
cf1dfa6b | 199 | |
658070d1 | 200 | LIST_LIST_VIEW = wxID_HIGHEST, |
98ec9dbe VZ |
201 | LIST_ICON_VIEW, |
202 | LIST_ICON_TEXT_VIEW, | |
203 | LIST_SMALL_ICON_VIEW, | |
204 | LIST_SMALL_ICON_TEXT_VIEW, | |
cf1dfa6b | 205 | LIST_REPORT_VIEW, |
98ec9dbe | 206 | LIST_VIRTUAL_VIEW, |
b0401bea | 207 | LIST_SMALL_VIRTUAL_VIEW, |
beb9e8f2 | 208 | LIST_SET_ITEMS_COUNT, |
98ec9dbe | 209 | |
98ec9dbe VZ |
210 | LIST_DESELECT_ALL, |
211 | LIST_SELECT_ALL, | |
98ec9dbe | 212 | LIST_DELETE_ALL, |
bec0a261 | 213 | LIST_DELETE, |
cf1dfa6b | 214 | LIST_ADD, |
efe23391 | 215 | LIST_EDIT, |
fa5f6926 | 216 | LIST_SORT, |
beb9e8f2 | 217 | LIST_FIND, |
11f26ea0 VZ |
218 | LIST_SET_FG_COL, |
219 | LIST_SET_BG_COL, | |
7b848b0d | 220 | LIST_TOGGLE_MULTI_SEL, |
1bab3627 | 221 | LIST_TOGGLE_HEADER, |
58b3bdc9 | 222 | LIST_TOGGLE_FIRST, |
f6bcfd97 | 223 | LIST_SHOW_COL_INFO, |
b54e41c5 | 224 | LIST_SHOW_SEL_INFO, |
929b7901 | 225 | LIST_SHOW_VIEW_RECT, |
80cc5fc7 VZ |
226 | #ifdef wxHAS_LISTCTRL_COLUMN_ORDER |
227 | LIST_SET_COL_ORDER, | |
228 | LIST_GET_COL_ORDER, | |
229 | #endif // wxHAS_LISTCTRL_COLUMN_ORDER | |
6ef2b230 | 230 | LIST_GOTO, |
88b792af | 231 | LIST_FOCUS_LAST, |
c5c528fc VZ |
232 | LIST_FREEZE, |
233 | LIST_THAW, | |
494ab5de | 234 | LIST_TOGGLE_LINES, |
8a3f03ff | 235 | #ifdef __WXOSX__ |
2458daa7 | 236 | LIST_MAC_USE_GENERIC, |
8a3f03ff | 237 | #endif |
457814b5 | 238 | |
fa5f6926 VZ |
239 | LIST_CTRL = 1000 |
240 | }; |