]> git.saurik.com Git - wxWidgets.git/blob - samples/listctrl/listtest.h
Added check to allow multiple selection by dragging only if property under mouse...
[wxWidgets.git] / samples / listctrl / listtest.h
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$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
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
16 #else
17 #define USE_CONTEXT_MENU 1
18 #endif
19
20 // Define a new application type
21 class MyApp: public wxApp
22 {
23 public:
24 MyApp() { }
25
26 virtual bool OnInit();
27
28 private:
29 wxDECLARE_NO_COPY_CLASS(MyApp);
30 };
31
32 class MyListCtrl: public wxListCtrl
33 {
34 public:
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),
41 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
42 {
43 m_updated = -1;
44
45 #ifdef __POCKETPC__
46 EnableContextMenu();
47 #endif
48 }
49
50 // add one item to the listctrl in report mode
51 void InsertItemInReportView(int i);
52
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);
70
71 void OnChar(wxKeyEvent& event);
72
73 #if USE_CONTEXT_MENU
74 void OnContextMenu(wxContextMenuEvent& event);
75 #endif
76
77 void OnRightClick(wxMouseEvent& event);
78
79 private:
80 void ShowContextMenu(const wxPoint& pos);
81 wxLog *m_logOld;
82 void SetColumnImage(int col, int image);
83
84 void LogEvent(const wxListEvent& event, const wxChar *eventName);
85 void LogColEvent(const wxListEvent& event, const wxChar *eventName);
86
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;
90
91 wxListItemAttr m_attr;
92
93 long m_updated;
94
95
96 wxDECLARE_NO_COPY_CLASS(MyListCtrl);
97 DECLARE_EVENT_TABLE()
98 };
99
100 // Define a new frame type
101 class MyFrame: public wxFrame
102 {
103 public:
104 MyFrame(const wxChar *title);
105 virtual ~MyFrame();
106
107 void DoSize();
108
109 protected:
110 void OnSize(wxSizeEvent& event);
111
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);
122
123 void OnSetItemsCount(wxCommandEvent& event);
124
125
126 void OnGoTo(wxCommandEvent& event);
127 void OnFocusLast(wxCommandEvent& event);
128 void OnToggleFirstSel(wxCommandEvent& event);
129 void OnDeselectAll(wxCommandEvent& event);
130 void OnSelectAll(wxCommandEvent& event);
131 void OnAdd(wxCommandEvent& event);
132 void OnEdit(wxCommandEvent& event);
133 void OnDelete(wxCommandEvent& event);
134 void OnDeleteAll(wxCommandEvent& event);
135 void OnSort(wxCommandEvent& event);
136 void OnSetFgColour(wxCommandEvent& event);
137 void OnSetBgColour(wxCommandEvent& event);
138 void OnToggleMultiSel(wxCommandEvent& event);
139 void OnShowColInfo(wxCommandEvent& event);
140 void OnShowSelInfo(wxCommandEvent& event);
141 void OnShowViewRect(wxCommandEvent& event);
142 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
143 void OnSetColOrder(wxCommandEvent& event);
144 void OnGetColOrder(wxCommandEvent& event);
145 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
146 void OnFreeze(wxCommandEvent& event);
147 void OnThaw(wxCommandEvent& event);
148 void OnToggleLines(wxCommandEvent& event);
149 #ifdef __WXOSX__
150 void OnToggleMacUseGeneric(wxCommandEvent& event);
151 #endif // __WXOSX__
152 void OnFind(wxCommandEvent& event);
153
154 void OnUpdateShowColInfo(wxUpdateUIEvent& event);
155 void OnUpdateToggleMultiSel(wxUpdateUIEvent& event);
156
157 wxImageList *m_imageListNormal;
158 wxImageList *m_imageListSmall;
159
160 wxPanel *m_panel;
161 MyListCtrl *m_listCtrl;
162 wxTextCtrl *m_logWindow;
163
164 private:
165 // recreate the list control with the new flags
166 void RecreateList(long flags, bool withText = true);
167
168 // fill the control with items depending on the view
169 void InitWithListItems();
170 void InitWithReportItems();
171 void InitWithIconItems(bool withText, bool sameIcon = false);
172 void InitWithVirtualItems();
173
174 // return true if the control is not in virtual view, give an error message
175 // and return false if it is
176 bool CheckNonVirtual() const;
177
178
179 wxLog *m_logOld;
180
181 bool m_smallVirtual;
182
183 // number of items to initialize list/report view with
184 int m_numListItems;
185
186
187 wxDECLARE_NO_COPY_CLASS(MyFrame);
188 DECLARE_EVENT_TABLE()
189 };
190
191
192 // IDs for the menu commands
193 enum
194 {
195 LIST_ABOUT = wxID_ABOUT,
196 LIST_QUIT = wxID_EXIT,
197
198 LIST_LIST_VIEW = wxID_HIGHEST,
199 LIST_ICON_VIEW,
200 LIST_ICON_TEXT_VIEW,
201 LIST_SMALL_ICON_VIEW,
202 LIST_SMALL_ICON_TEXT_VIEW,
203 LIST_REPORT_VIEW,
204 LIST_VIRTUAL_VIEW,
205 LIST_SMALL_VIRTUAL_VIEW,
206 LIST_SET_ITEMS_COUNT,
207
208 LIST_DESELECT_ALL,
209 LIST_SELECT_ALL,
210 LIST_DELETE_ALL,
211 LIST_DELETE,
212 LIST_ADD,
213 LIST_EDIT,
214 LIST_SORT,
215 LIST_FIND,
216 LIST_SET_FG_COL,
217 LIST_SET_BG_COL,
218 LIST_TOGGLE_MULTI_SEL,
219 LIST_TOGGLE_FIRST,
220 LIST_SHOW_COL_INFO,
221 LIST_SHOW_SEL_INFO,
222 LIST_SHOW_VIEW_RECT,
223 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
224 LIST_SET_COL_ORDER,
225 LIST_GET_COL_ORDER,
226 #endif // wxHAS_LISTCTRL_COLUMN_ORDER
227 LIST_GOTO,
228 LIST_FOCUS_LAST,
229 LIST_FREEZE,
230 LIST_THAW,
231 LIST_TOGGLE_LINES,
232 #ifdef __WXOSX__
233 LIST_MAC_USE_GENERIC,
234 #endif
235
236 LIST_CTRL = 1000
237 };