]>
Commit | Line | Data |
---|---|---|
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 | DECLARE_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 | #ifdef __POCKETPC__ | |
44 | EnableContextMenu(); | |
45 | #endif | |
46 | } | |
47 | ||
48 | // add one item to the listctrl in report mode | |
49 | void InsertItemInReportView(int i); | |
50 | ||
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); | |
65 | #endif | |
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); | |
72 | ||
73 | void OnChar(wxKeyEvent& event); | |
74 | ||
75 | #if USE_CONTEXT_MENU | |
76 | void OnContextMenu(wxContextMenuEvent& event); | |
77 | #endif | |
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 | DECLARE_NO_COPY_CLASS(MyListCtrl) | |
94 | DECLARE_EVENT_TABLE() | |
95 | }; | |
96 | ||
97 | // Define a new frame type | |
98 | class MyFrame: public wxFrame | |
99 | { | |
100 | public: | |
101 | MyFrame(const wxChar *title); | |
102 | virtual ~MyFrame(); | |
103 | ||
104 | void DoSize(); | |
105 | ||
106 | protected: | |
107 | void OnSize(wxSizeEvent& event); | |
108 | ||
109 | void OnQuit(wxCommandEvent& event); | |
110 | void OnAbout(wxCommandEvent& event); | |
111 | void OnListView(wxCommandEvent& event); | |
112 | void OnReportView(wxCommandEvent& event); | |
113 | void OnIconView(wxCommandEvent& event); | |
114 | void OnIconTextView(wxCommandEvent& event); | |
115 | void OnSmallIconView(wxCommandEvent& event); | |
116 | void OnSmallIconTextView(wxCommandEvent& event); | |
117 | void OnVirtualView(wxCommandEvent& event); | |
118 | void OnSmallVirtualView(wxCommandEvent& event); | |
119 | ||
120 | void OnFocusLast(wxCommandEvent& event); | |
121 | void OnToggleFirstSel(wxCommandEvent& event); | |
122 | void OnDeselectAll(wxCommandEvent& event); | |
123 | void OnSelectAll(wxCommandEvent& event); | |
124 | void OnAdd(wxCommandEvent& event); | |
125 | void OnEdit(wxCommandEvent& event); | |
126 | void OnDelete(wxCommandEvent& event); | |
127 | void OnDeleteAll(wxCommandEvent& event); | |
128 | void OnSort(wxCommandEvent& event); | |
129 | void OnSetFgColour(wxCommandEvent& event); | |
130 | void OnSetBgColour(wxCommandEvent& event); | |
131 | void OnToggleMultiSel(wxCommandEvent& event); | |
132 | void OnShowColInfo(wxCommandEvent& event); | |
133 | void OnShowSelInfo(wxCommandEvent& event); | |
134 | void OnFreeze(wxCommandEvent& event); | |
135 | void OnThaw(wxCommandEvent& event); | |
136 | void OnToggleLines(wxCommandEvent& event); | |
137 | ||
138 | void OnUpdateShowColInfo(wxUpdateUIEvent& event); | |
139 | void OnUpdateToggleMultiSel(wxUpdateUIEvent& event); | |
140 | ||
141 | wxImageList *m_imageListNormal; | |
142 | wxImageList *m_imageListSmall; | |
143 | ||
144 | wxPanel *m_panel; | |
145 | MyListCtrl *m_listCtrl; | |
146 | wxTextCtrl *m_logWindow; | |
147 | ||
148 | private: | |
149 | // recreate the list control with the new flags | |
150 | void RecreateList(long flags, bool withText = true); | |
151 | ||
152 | // fill the control with items depending on the view | |
153 | void InitWithListItems(); | |
154 | void InitWithReportItems(); | |
155 | void InitWithIconItems(bool withText, bool sameIcon = false); | |
156 | void InitWithVirtualItems(); | |
157 | ||
158 | // return true if the control is not in virtual view, give an error message | |
159 | // and return false if it is | |
160 | bool CheckNonVirtual() const; | |
161 | ||
162 | ||
163 | wxLog *m_logOld; | |
164 | ||
165 | bool m_smallVirtual; | |
166 | ||
167 | DECLARE_NO_COPY_CLASS(MyFrame) | |
168 | DECLARE_EVENT_TABLE() | |
169 | }; | |
170 | ||
171 | ||
172 | // IDs for the menu commands | |
173 | enum | |
174 | { | |
175 | LIST_ABOUT = wxID_ABOUT, | |
176 | LIST_QUIT = wxID_EXIT, | |
177 | ||
178 | LIST_LIST_VIEW = wxID_HIGHEST, | |
179 | LIST_ICON_VIEW, | |
180 | LIST_ICON_TEXT_VIEW, | |
181 | LIST_SMALL_ICON_VIEW, | |
182 | LIST_SMALL_ICON_TEXT_VIEW, | |
183 | LIST_REPORT_VIEW, | |
184 | LIST_VIRTUAL_VIEW, | |
185 | LIST_SMALL_VIRTUAL_VIEW, | |
186 | ||
187 | LIST_DESELECT_ALL, | |
188 | LIST_SELECT_ALL, | |
189 | LIST_DELETE_ALL, | |
190 | LIST_DELETE, | |
191 | LIST_ADD, | |
192 | LIST_EDIT, | |
193 | LIST_SORT, | |
194 | LIST_SET_FG_COL, | |
195 | LIST_SET_BG_COL, | |
196 | LIST_TOGGLE_MULTI_SEL, | |
197 | LIST_TOGGLE_FIRST, | |
198 | LIST_SHOW_COL_INFO, | |
199 | LIST_SHOW_SEL_INFO, | |
200 | LIST_FOCUS_LAST, | |
201 | LIST_FREEZE, | |
202 | LIST_THAW, | |
203 | LIST_TOGGLE_LINES, | |
204 | ||
205 | LIST_CTRL = 1000 | |
206 | }; |