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