]>
Commit | Line | Data |
---|---|---|
93cf77c0 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: wxListCtrl. See also Robert's generic wxListCtrl | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "listctrl.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/listctrl.h" | |
17 | ||
18 | #if !USE_SHARED_LIBRARY | |
19 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
20 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
21 | ||
22 | #endif | |
23 | ||
24 | wxListCtrl::wxListCtrl() | |
25 | { | |
26 | m_imageListNormal = NULL; | |
27 | m_imageListSmall = NULL; | |
28 | m_imageListState = NULL; | |
29 | m_baseStyle = 0; | |
30 | m_colCount = 0; | |
31 | } | |
32 | ||
33 | bool wxListCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
34 | long style, const wxValidator& validator, const wxString& name) | |
35 | { | |
36 | m_imageListNormal = NULL; | |
37 | m_imageListSmall = NULL; | |
38 | m_imageListState = NULL; | |
39 | m_colCount = 0; | |
40 | ||
41 | SetValidator(validator); | |
42 | SetName(name); | |
43 | ||
44 | m_windowStyle = style; | |
45 | ||
46 | SetParent(parent); | |
47 | ||
48 | m_windowId = (id == -1) ? NewControlId() : id; | |
49 | ||
50 | if (parent) parent->AddChild(this); | |
51 | ||
52 | // TODO create list control | |
53 | return TRUE; | |
54 | } | |
55 | ||
56 | wxListCtrl::~wxListCtrl() | |
57 | { | |
58 | } | |
59 | ||
60 | // Add or remove a single window style | |
61 | void wxListCtrl::SetSingleStyle(long style, bool add) | |
62 | { | |
63 | long flag = GetWindowStyleFlag(); | |
64 | ||
65 | // Get rid of conflicting styles | |
66 | if ( add ) | |
67 | { | |
68 | if ( style & wxLC_MASK_TYPE) | |
69 | flag = flag & ~wxLC_MASK_TYPE ; | |
70 | if ( style & wxLC_MASK_ALIGN ) | |
71 | flag = flag & ~wxLC_MASK_ALIGN ; | |
72 | if ( style & wxLC_MASK_SORT ) | |
73 | flag = flag & ~wxLC_MASK_SORT ; | |
74 | } | |
75 | ||
76 | if ( flag & style ) | |
77 | { | |
78 | if ( !add ) | |
79 | flag -= style; | |
80 | } | |
81 | else | |
82 | { | |
83 | if ( add ) | |
84 | { | |
85 | flag |= style; | |
86 | } | |
87 | } | |
88 | ||
89 | m_windowStyle = flag; | |
90 | ||
91 | /* TODO RecreateWindow(); */ | |
92 | } | |
93 | ||
94 | // Set the whole window style | |
95 | void wxListCtrl::SetWindowStyleFlag(long flag) | |
96 | { | |
97 | m_windowStyle = flag; | |
98 | ||
99 | /* TODO RecreateWindow(); */ | |
100 | } | |
101 | ||
102 | ||
103 | // Gets information about this column | |
104 | bool wxListCtrl::GetColumn(int col, wxListItem& item) const | |
105 | { | |
106 | // TODO | |
107 | return FALSE; | |
108 | } | |
109 | ||
110 | // Sets information about this column | |
111 | bool wxListCtrl::SetColumn(int col, wxListItem& item) | |
112 | { | |
113 | // TODO | |
114 | return FALSE; | |
115 | } | |
116 | ||
117 | // Gets the column width | |
118 | int wxListCtrl::GetColumnWidth(int col) const | |
119 | { | |
120 | // TODO | |
121 | return 0; | |
122 | } | |
123 | ||
124 | // Sets the column width | |
125 | bool wxListCtrl::SetColumnWidth(int col, int width) | |
126 | { | |
127 | // TODO | |
128 | return FALSE; | |
129 | } | |
130 | ||
131 | // Gets the number of items that can fit vertically in the | |
132 | // visible area of the list control (list or report view) | |
133 | // or the total number of items in the list control (icon | |
134 | // or small icon view) | |
135 | int wxListCtrl::GetCountPerPage() const | |
136 | { | |
137 | // TODO | |
138 | return 0; | |
139 | } | |
140 | ||
141 | // Gets the edit control for editing labels. | |
142 | wxTextCtrl* wxListCtrl::GetEditControl() const | |
143 | { | |
144 | return m_textCtrl; | |
145 | } | |
146 | ||
147 | // Gets information about the item | |
148 | bool wxListCtrl::GetItem(wxListItem& info) const | |
149 | { | |
150 | // TODO | |
151 | return FALSE; | |
152 | } | |
153 | ||
154 | // Sets information about the item | |
155 | bool wxListCtrl::SetItem(wxListItem& info) | |
156 | { | |
157 | // TODO | |
158 | return FALSE; | |
159 | } | |
160 | ||
161 | long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId) | |
162 | { | |
163 | wxListItem info; | |
164 | info.m_text = label; | |
165 | info.m_mask = wxLIST_MASK_TEXT; | |
166 | info.m_itemId = index; | |
167 | info.m_col = col; | |
168 | if ( imageId > -1 ) | |
169 | { | |
170 | info.m_image = imageId; | |
171 | info.m_mask |= wxLIST_MASK_IMAGE; | |
172 | } | |
173 | return SetItem(info); | |
174 | } | |
175 | ||
176 | ||
177 | // Gets the item state | |
178 | int wxListCtrl::GetItemState(long item, long stateMask) const | |
179 | { | |
180 | wxListItem info; | |
181 | ||
182 | info.m_mask = wxLIST_MASK_STATE ; | |
183 | info.m_stateMask = stateMask; | |
184 | info.m_itemId = item; | |
185 | ||
186 | if (!GetItem(info)) | |
187 | return 0; | |
188 | ||
189 | return info.m_state; | |
190 | } | |
191 | ||
192 | // Sets the item state | |
193 | bool wxListCtrl::SetItemState(long item, long state, long stateMask) | |
194 | { | |
195 | wxListItem info; | |
196 | ||
197 | info.m_mask = wxLIST_MASK_STATE ; | |
198 | info.m_state = state; | |
199 | info.m_stateMask = stateMask; | |
200 | info.m_itemId = item; | |
201 | ||
202 | return SetItem(info); | |
203 | } | |
204 | ||
205 | // Sets the item image | |
206 | bool wxListCtrl::SetItemImage(long item, int image, int selImage) | |
207 | { | |
208 | wxListItem info; | |
209 | ||
210 | info.m_mask = wxLIST_MASK_IMAGE ; | |
211 | info.m_image = image; | |
212 | info.m_itemId = item; | |
213 | ||
214 | return SetItem(info); | |
215 | } | |
216 | ||
217 | // Gets the item text | |
218 | wxString wxListCtrl::GetItemText(long item) const | |
219 | { | |
220 | wxListItem info; | |
221 | ||
222 | info.m_mask = wxLIST_MASK_TEXT ; | |
223 | info.m_itemId = item; | |
224 | ||
225 | if (!GetItem(info)) | |
226 | return wxString(""); | |
227 | return info.m_text; | |
228 | } | |
229 | ||
230 | // Sets the item text | |
231 | void wxListCtrl::SetItemText(long item, const wxString& str) | |
232 | { | |
233 | wxListItem info; | |
234 | ||
235 | info.m_mask = wxLIST_MASK_TEXT ; | |
236 | info.m_itemId = item; | |
237 | info.m_text = str; | |
238 | ||
239 | SetItem(info); | |
240 | } | |
241 | ||
242 | // Gets the item data | |
243 | long wxListCtrl::GetItemData(long item) const | |
244 | { | |
245 | wxListItem info; | |
246 | ||
247 | info.m_mask = wxLIST_MASK_DATA ; | |
248 | info.m_itemId = item; | |
249 | ||
250 | if (!GetItem(info)) | |
251 | return 0; | |
252 | return info.m_data; | |
253 | } | |
254 | ||
255 | // Sets the item data | |
256 | bool wxListCtrl::SetItemData(long item, long data) | |
257 | { | |
258 | wxListItem info; | |
259 | ||
260 | info.m_mask = wxLIST_MASK_DATA ; | |
261 | info.m_itemId = item; | |
262 | info.m_data = data; | |
263 | ||
264 | return SetItem(info); | |
265 | } | |
266 | ||
267 | // Gets the item rectangle | |
268 | bool wxListCtrl::GetItemRect(long item, wxRectangle& rect, int code) const | |
269 | { | |
270 | // TODO | |
271 | return FALSE; | |
272 | } | |
273 | ||
274 | // Gets the item position | |
275 | bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const | |
276 | { | |
277 | // TODO | |
278 | return FALSE; | |
279 | } | |
280 | ||
281 | // Sets the item position. | |
282 | bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos) | |
283 | { | |
284 | // TODO | |
285 | return FALSE; | |
286 | } | |
287 | ||
288 | // Gets the number of items in the list control | |
289 | int wxListCtrl::GetItemCount() const | |
290 | { | |
291 | // TODO | |
292 | return FALSE; | |
293 | } | |
294 | ||
295 | // Retrieves the spacing between icons in pixels. | |
296 | // If small is TRUE, gets the spacing for the small icon | |
297 | // view, otherwise the large icon view. | |
298 | int wxListCtrl::GetItemSpacing(bool isSmall) const | |
299 | { | |
300 | // TODO | |
301 | return FALSE; | |
302 | } | |
303 | ||
304 | // Gets the number of selected items in the list control | |
305 | int wxListCtrl::GetSelectedItemCount() const | |
306 | { | |
307 | // TODO | |
308 | return FALSE; | |
309 | } | |
310 | ||
311 | // Gets the text colour of the listview | |
312 | wxColour wxListCtrl::GetTextColour() const | |
313 | { | |
314 | // TODO | |
315 | return wxColour(); | |
316 | } | |
317 | ||
318 | // Sets the text colour of the listview | |
319 | void wxListCtrl::SetTextColour(const wxColour& col) | |
320 | { | |
321 | // TODO | |
322 | } | |
323 | ||
324 | // Gets the index of the topmost visible item when in | |
325 | // list or report view | |
326 | long wxListCtrl::GetTopItem() const | |
327 | { | |
328 | // TODO | |
329 | return 0; | |
330 | } | |
331 | ||
332 | // Searches for an item, starting from 'item'. | |
333 | // 'geometry' is one of | |
334 | // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. | |
335 | // 'state' is a state bit flag, one or more of | |
336 | // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. | |
337 | // item can be -1 to find the first item that matches the | |
338 | // specified flags. | |
339 | // Returns the item or -1 if unsuccessful. | |
340 | long wxListCtrl::GetNextItem(long item, int geom, int state) const | |
341 | { | |
342 | // TODO | |
343 | return 0; | |
344 | } | |
345 | ||
346 | wxImageList *wxListCtrl::GetImageList(int which) const | |
347 | { | |
348 | if ( which == wxIMAGE_LIST_NORMAL ) | |
349 | { | |
350 | return m_imageListNormal; | |
351 | } | |
352 | else if ( which == wxIMAGE_LIST_SMALL ) | |
353 | { | |
354 | return m_imageListSmall; | |
355 | } | |
356 | else if ( which == wxIMAGE_LIST_STATE ) | |
357 | { | |
358 | return m_imageListState; | |
359 | } | |
360 | return NULL; | |
361 | } | |
362 | ||
363 | void wxListCtrl::SetImageList(wxImageList *imageList, int which) | |
364 | { | |
365 | int flags = 0; | |
366 | if ( which == wxIMAGE_LIST_NORMAL ) | |
367 | { | |
368 | flags = LVSIL_NORMAL; | |
369 | m_imageListNormal = imageList; | |
370 | } | |
371 | else if ( which == wxIMAGE_LIST_SMALL ) | |
372 | { | |
373 | flags = LVSIL_SMALL; | |
374 | m_imageListSmall = imageList; | |
375 | } | |
376 | else if ( which == wxIMAGE_LIST_STATE ) | |
377 | { | |
378 | flags = LVSIL_STATE; | |
379 | m_imageListState = imageList; | |
380 | } | |
381 | // TODO set image list | |
382 | } | |
383 | ||
384 | // Operations | |
385 | //////////////////////////////////////////////////////////////////////////// | |
386 | ||
387 | // Arranges the items | |
388 | bool wxListCtrl::Arrange(int flag) | |
389 | { | |
390 | // TODO | |
391 | return FALSE; | |
392 | } | |
393 | ||
394 | // Deletes an item | |
395 | bool wxListCtrl::DeleteItem(long item) | |
396 | { | |
397 | // TODO | |
398 | return FALSE; | |
399 | } | |
400 | ||
401 | // Deletes all items | |
402 | bool wxListCtrl::DeleteAllItems() | |
403 | { | |
404 | // TODO | |
405 | return FALSE; | |
406 | } | |
407 | ||
408 | // Deletes all items | |
409 | bool wxListCtrl::DeleteAllColumns() | |
410 | { | |
411 | // TODO | |
412 | return FALSE; | |
413 | } | |
414 | ||
415 | // Deletes a column | |
416 | bool wxListCtrl::DeleteColumn(int col) | |
417 | { | |
418 | // TODO | |
419 | return FALSE; | |
420 | } | |
421 | ||
422 | // Clears items, and columns if there are any. | |
423 | void wxListCtrl::ClearAll() | |
424 | { | |
425 | DeleteAllItems(); | |
426 | if ( m_colCount > 0 ) | |
427 | DeleteAllColumns(); | |
428 | } | |
429 | ||
430 | // Edit the label | |
431 | wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) | |
432 | { | |
433 | // TODO | |
434 | return NULL; | |
435 | } | |
436 | ||
437 | // End label editing, optionally cancelling the edit | |
438 | bool wxListCtrl::EndEditLabel(bool cancel) | |
439 | { | |
440 | // TODO | |
441 | return FALSE; | |
442 | } | |
443 | ||
444 | // Ensures this item is visible | |
445 | bool wxListCtrl::EnsureVisible(long item) | |
446 | { | |
447 | // TODO | |
448 | return FALSE; | |
449 | } | |
450 | ||
451 | // Find an item whose label matches this string, starting from the item after 'start' | |
452 | // or the beginning if 'start' is -1. | |
453 | long wxListCtrl::FindItem(long start, const wxString& str, bool partial) | |
454 | { | |
455 | // TODO | |
456 | return FALSE; | |
457 | } | |
458 | ||
459 | // Find an item whose data matches this data, starting from the item after 'start' | |
460 | // or the beginning if 'start' is -1. | |
461 | long wxListCtrl::FindItem(long start, long data) | |
462 | { | |
463 | // TODO | |
464 | return 0; | |
465 | } | |
466 | ||
467 | // Find an item nearest this position in the specified direction, starting from | |
468 | // the item after 'start' or the beginning if 'start' is -1. | |
469 | long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) | |
470 | { | |
471 | // TODO | |
472 | return 0; | |
473 | } | |
474 | ||
475 | // Determines which item (if any) is at the specified point, | |
476 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
477 | long wxListCtrl::HitTest(const wxPoint& point, int& flags) | |
478 | { | |
479 | // TODO | |
480 | return 0; | |
481 | } | |
482 | ||
483 | // Inserts an item, returning the index of the new item if successful, | |
484 | // -1 otherwise. | |
485 | long wxListCtrl::InsertItem(wxListItem& info) | |
486 | { | |
487 | // TODO | |
488 | return 0; | |
489 | } | |
490 | ||
491 | long wxListCtrl::InsertItem(long index, const wxString& label) | |
492 | { | |
493 | wxListItem info; | |
494 | info.m_text = label; | |
495 | info.m_mask = wxLIST_MASK_TEXT; | |
496 | info.m_itemId = index; | |
497 | return InsertItem(info); | |
498 | } | |
499 | ||
500 | // Inserts an image item | |
501 | long wxListCtrl::InsertItem(long index, int imageIndex) | |
502 | { | |
503 | wxListItem info; | |
504 | info.m_image = imageIndex; | |
505 | info.m_mask = wxLIST_MASK_IMAGE; | |
506 | info.m_itemId = index; | |
507 | return InsertItem(info); | |
508 | } | |
509 | ||
510 | // Inserts an image/string item | |
511 | long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) | |
512 | { | |
513 | wxListItem info; | |
514 | info.m_image = imageIndex; | |
515 | info.m_text = label; | |
516 | info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT; | |
517 | info.m_itemId = index; | |
518 | return InsertItem(info); | |
519 | } | |
520 | ||
521 | // For list view mode (only), inserts a column. | |
522 | long wxListCtrl::InsertColumn(long col, wxListItem& item) | |
523 | { | |
524 | // TODO | |
525 | return 0; | |
526 | } | |
527 | ||
528 | long wxListCtrl::InsertColumn(long col, const wxString& heading, int format, | |
529 | int width) | |
530 | { | |
531 | wxListItem item; | |
532 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
533 | item.m_text = heading; | |
534 | if ( width > -1 ) | |
535 | { | |
536 | item.m_mask |= wxLIST_MASK_WIDTH; | |
537 | item.m_width = width; | |
538 | } | |
539 | item.m_format = format; | |
540 | ||
541 | return InsertColumn(col, item); | |
542 | } | |
543 | ||
544 | // Scrolls the list control. If in icon, small icon or report view mode, | |
545 | // x specifies the number of pixels to scroll. If in list view mode, x | |
546 | // specifies the number of columns to scroll. | |
547 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
548 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
549 | bool wxListCtrl::ScrollList(int dx, int dy) | |
550 | { | |
551 | // TODO | |
552 | return FALSE; | |
553 | } | |
554 | ||
555 | // Sort items. | |
556 | ||
557 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
558 | // item1 is the long data associated with a first item (NOT the index). | |
559 | // item2 is the long data associated with a second item (NOT the index). | |
560 | // data is the same value as passed to SortItems. | |
561 | // The return value is a negative number if the first item should precede the second | |
562 | // item, a positive number of the second item should precede the first, | |
563 | // or zero if the two items are equivalent. | |
564 | ||
565 | // data is arbitrary data to be passed to the sort function. | |
566 | bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) | |
567 | { | |
568 | // TODO | |
569 | return FALSE; | |
570 | } | |
571 | ||
572 | // List item structure | |
573 | wxListItem::wxListItem() | |
574 | { | |
575 | m_mask = 0; | |
576 | m_itemId = 0; | |
577 | m_col = 0; | |
578 | m_state = 0; | |
579 | m_stateMask = 0; | |
580 | m_image = 0; | |
581 | m_data = 0; | |
582 | ||
583 | m_format = wxLIST_FORMAT_CENTRE; | |
584 | m_width = 0; | |
585 | } | |
586 | ||
587 | // List event | |
588 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxCommandEvent) | |
589 | ||
590 | wxListEvent::wxListEvent(wxEventType commandType, int id): | |
591 | wxCommandEvent(commandType, id) | |
592 | { | |
593 | m_code = 0; | |
594 | m_itemIndex = 0; | |
595 | m_col = 0; | |
596 | m_cancelled = FALSE; | |
597 | } | |
598 |