]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
further encapsulation of graphics context, wxdc becoming 'generic'
[wxWidgets.git] / src / mac / carbon / listctrl_mac.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
3 // Purpose: wxListCtrl
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_LISTCTRL
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/intl.h"
32 #include "wx/log.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
35 #include "wx/textctrl.h"
36 #endif
37
38 #include "wx/mac/uma.h"
39
40 #include "wx/imaglist.h"
41 #include "wx/listctrl.h"
42 #include "wx/sysopt.h"
43
44 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
45
46 #if wxUSE_EXTENDED_RTTI
47 WX_DEFINE_FLAGS( wxListCtrlStyle )
48
49 wxBEGIN_FLAGS( wxListCtrlStyle )
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
55 wxFLAGS_MEMBER(wxBORDER_RAISED)
56 wxFLAGS_MEMBER(wxBORDER_STATIC)
57 wxFLAGS_MEMBER(wxBORDER_NONE)
58
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
63 wxFLAGS_MEMBER(wxRAISED_BORDER)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER)
65 wxFLAGS_MEMBER(wxBORDER)
66
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
71 wxFLAGS_MEMBER(wxWANTS_CHARS)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
74 wxFLAGS_MEMBER(wxVSCROLL)
75 wxFLAGS_MEMBER(wxHSCROLL)
76
77 wxFLAGS_MEMBER(wxLC_LIST)
78 wxFLAGS_MEMBER(wxLC_REPORT)
79 wxFLAGS_MEMBER(wxLC_ICON)
80 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
81 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
82 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
83 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
84 wxFLAGS_MEMBER(wxLC_USER_TEXT)
85 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
86 wxFLAGS_MEMBER(wxLC_NO_HEADER)
87 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
88 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
89 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
90 wxFLAGS_MEMBER(wxLC_VIRTUAL)
91
92 wxEND_FLAGS( wxListCtrlStyle )
93
94 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
95
96 wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
97 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
98
99 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
100 wxEND_PROPERTIES_TABLE()
101
102 wxBEGIN_HANDLERS_TABLE(wxListCtrl)
103 wxEND_HANDLERS_TABLE()
104
105 wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
106
107 /*
108 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
109 */
110 #else
111 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
112 #endif
113
114 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
115 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
116
117 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
118
119 WX_DECLARE_EXPORTED_LIST(wxListItem, wxListItemList);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxListItemList)
122
123 class wxMacListCtrlItem : public wxMacListBoxItem
124 {
125 public:
126 wxMacListCtrlItem();
127
128 virtual void Notification(wxMacDataItemBrowserControl *owner ,
129 DataBrowserItemNotification message,
130 DataBrowserItemDataRef itemData ) const;
131
132 virtual void SetColumnInfo( unsigned int column, wxListItem* item );
133 virtual wxListItem* GetColumnInfo( unsigned int column );
134 virtual bool HasColumnInfo( unsigned int column );
135
136 virtual void SetColumnTextValue( unsigned int column, const wxString& text );
137 virtual const wxString& GetColumnTextValue( unsigned int column );
138
139 virtual int GetColumnImageValue( unsigned int column );
140 virtual void SetColumnImageValue( unsigned int column, int imageIndex );
141
142 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
143 DataBrowserPropertyID property,
144 DataBrowserItemDataRef itemData,
145 bool changeValue );
146
147
148 virtual ~wxMacListCtrlItem();
149 protected:
150 wxListItemList m_rowItems;
151 };
152
153 // TODO: Make a better name!!
154 class wxMacDataBrowserListCtrlControl : public wxMacDataItemBrowserControl
155 {
156 public:
157 wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style );
158 virtual ~wxMacDataBrowserListCtrlControl();
159
160 // create a list item (can be a subclass of wxMacListBoxItem)
161
162 virtual wxMacListCtrlItem* CreateItem();
163
164 virtual void MacInsertItem( unsigned int n, wxListItem* item );
165 virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item );
166 virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item );
167 virtual void UpdateState(wxMacDataItem* dataItem, wxListItem* item);
168
169 protected:
170 wxClientDataType m_clientDataItemsType;
171
172 };
173
174 // TODO: This gives errors, find out why.
175 //BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
176 // EVT_PAINT(wxListCtrl::OnPaint)
177 //END_EVENT_TABLE()
178
179 // ============================================================================
180 // implementation
181 // ============================================================================
182
183 wxMacListControl* wxListCtrl::GetPeer() const
184 {
185 return dynamic_cast<wxMacListControl*>(m_peer);
186 }
187
188 // ----------------------------------------------------------------------------
189 // wxListCtrl construction
190 // ----------------------------------------------------------------------------
191
192 void wxListCtrl::Init()
193 {
194 m_imageListNormal = NULL;
195 m_imageListSmall = NULL;
196 m_imageListState = NULL;
197
198 // keep track of if we created our own image lists, or if they were assigned
199 // to us.
200 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = false;
201 m_colCount = 0;
202 m_count = 0;
203 m_textCtrl = NULL;
204 m_genericImpl = NULL;
205 m_dbImpl = NULL;
206 }
207
208 bool wxListCtrl::Create(wxWindow *parent,
209 wxWindowID id,
210 const wxPoint& pos,
211 const wxSize& size,
212 long style,
213 const wxValidator& validator,
214 const wxString& name)
215 {
216
217 // for now, we'll always use the generic list control for ICON and LIST views,
218 // because they dynamically change the number of columns on resize.
219 // Also, allow the user to set it to use the list ctrl as well.
220 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL )
221 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) ||
222 (style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST))
223 {
224 m_macIsUserPane = true;
225
226 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
227 return false;
228 m_genericImpl = new wxGenericListCtrl(this, id, pos, size, style, validator, name);
229 return true;
230 }
231
232 else
233 {
234 m_macIsUserPane = false;
235
236 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
237 return false;
238 m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style );
239 m_peer = m_dbImpl;
240
241 MacPostControlCreate( pos, size );
242 }
243
244 return true;
245 }
246
247 wxListCtrl::~wxListCtrl()
248 {
249 if (m_ownsImageListNormal)
250 delete m_imageListNormal;
251 if (m_ownsImageListSmall)
252 delete m_imageListSmall;
253 if (m_ownsImageListState)
254 delete m_imageListState;
255 }
256
257 // ----------------------------------------------------------------------------
258 // set/get/change style
259 // ----------------------------------------------------------------------------
260
261 // Add or remove a single window style
262 void wxListCtrl::SetSingleStyle(long style, bool add)
263 {
264 long flag = GetWindowStyleFlag();
265
266 // Get rid of conflicting styles
267 if ( add )
268 {
269 if ( style & wxLC_MASK_TYPE)
270 flag = flag & ~wxLC_MASK_TYPE;
271 if ( style & wxLC_MASK_ALIGN )
272 flag = flag & ~wxLC_MASK_ALIGN;
273 if ( style & wxLC_MASK_SORT )
274 flag = flag & ~wxLC_MASK_SORT;
275 }
276
277 if ( add )
278 flag |= style;
279 else
280 flag &= ~style;
281
282 SetWindowStyleFlag(flag);
283 }
284
285 // Set the whole window style
286 void wxListCtrl::SetWindowStyleFlag(long flag)
287 {
288 if ( flag != m_windowStyle )
289 {
290 m_windowStyle = flag;
291
292 if (m_genericImpl){
293 m_genericImpl->SetWindowStyleFlag(flag);
294 }
295
296 Refresh();
297 }
298 }
299
300 void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags ){
301 wxControl::DoSetSize(x, y, width, height, sizeFlags);
302
303 if (m_genericImpl)
304 m_genericImpl->SetSize(x, y, width, height, sizeFlags);
305 }
306
307 // ----------------------------------------------------------------------------
308 // accessors
309 // ----------------------------------------------------------------------------
310
311 // Gets information about this column
312 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
313 {
314 if (m_genericImpl)
315 return m_genericImpl->GetColumn(col, item);
316
317 bool success = true;
318
319 if ( item.m_mask & wxLIST_MASK_TEXT )
320 {
321 }
322
323 if ( item.m_mask & wxLIST_MASK_FORMAT )
324 {
325 }
326
327 if ( item.m_mask & wxLIST_MASK_IMAGE )
328 {
329 }
330
331 if ( (item.m_mask & wxLIST_MASK_TEXT) )
332 {
333 }
334
335
336 return success;
337 }
338
339 // Sets information about this column
340 bool wxListCtrl::SetColumn(int col, wxListItem& item)
341 {
342 if (m_genericImpl)
343 return m_genericImpl->SetColumn(col, item);
344
345 return false;
346 }
347
348 int wxListCtrl::GetColumnCount() const
349 {
350 if (m_genericImpl)
351 return m_genericImpl->GetColumnCount();
352
353 if (m_dbImpl){
354 UInt32 count;
355 m_dbImpl->GetColumnCount(&count);
356 return count;
357 }
358
359 return m_colCount;
360 }
361
362 // Gets the column width
363 int wxListCtrl::GetColumnWidth(int col) const
364 {
365 if (m_genericImpl)
366 return m_genericImpl->GetColumnWidth(col);
367
368 if (m_dbImpl){
369 return m_dbImpl->GetColumnWidth(col);
370 }
371
372 return 0;
373 }
374
375 // Sets the column width
376 bool wxListCtrl::SetColumnWidth(int col, int width)
377 {
378 if (m_genericImpl)
379 return m_genericImpl->SetColumnWidth(col, width);
380
381 // TODO: This is setting the width of the first column
382 // to the entire window width; investigate why
383 // this is.
384
385 //if (m_dbImpl){
386 // m_dbImpl->SetColumnWidth(col+1, width);
387 // return true;
388 //}
389
390 return false;
391 }
392
393 // Gets the number of items that can fit vertically in the
394 // visible area of the list control (list or report view)
395 // or the total number of items in the list control (icon
396 // or small icon view)
397 int wxListCtrl::GetCountPerPage() const
398 {
399 if (m_genericImpl)
400 return m_genericImpl->GetCountPerPage();
401
402 if (m_dbImpl){
403 }
404
405 return 1;
406 }
407
408 // Gets the edit control for editing labels.
409 wxTextCtrl* wxListCtrl::GetEditControl() const
410 {
411 if (m_genericImpl)
412 return m_genericImpl->GetEditControl();
413
414 return NULL;
415 }
416
417 // Gets information about the item
418 bool wxListCtrl::GetItem(wxListItem& info) const
419 {
420 if (m_genericImpl)
421 return m_genericImpl->GetItem(info);
422
423 if (m_dbImpl)
424 m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info);
425 bool success = true;
426 return success;
427 }
428
429 // Sets information about the item
430 bool wxListCtrl::SetItem(wxListItem& info)
431 {
432 if (m_genericImpl)
433 return m_genericImpl->SetItem(info);
434
435 if (m_dbImpl)
436 m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info );
437
438 return true;
439 }
440
441 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
442 {
443 if (m_genericImpl)
444 return m_genericImpl->SetItem(index, col, label, imageId);
445
446 wxListItem info;
447 info.m_text = label;
448 info.m_mask = wxLIST_MASK_TEXT;
449 info.m_itemId = index;
450 info.m_col = col;
451 if ( imageId > -1 )
452 {
453 info.m_image = imageId;
454 info.m_mask |= wxLIST_MASK_IMAGE;
455 }
456 return SetItem(info);
457 }
458
459
460 // Gets the item state
461 int wxListCtrl::GetItemState(long item, long stateMask) const
462 {
463 if (m_genericImpl)
464 return m_genericImpl->GetItemState(item, stateMask);
465
466 wxListItem info;
467
468 info.m_mask = wxLIST_MASK_STATE;
469 info.m_stateMask = stateMask;
470 info.m_itemId = item;
471
472 if (!GetItem(info))
473 return 0;
474
475 return info.m_state;
476 }
477
478 // Sets the item state
479 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
480 {
481 if (m_genericImpl)
482 return m_genericImpl->SetItemState(item, state, stateMask);
483
484 wxListItem info;
485 info.m_mask = wxLIST_MASK_STATE;
486 info.m_stateMask = stateMask;
487 info.m_state = state;
488 info.m_itemId = item;
489 return SetItem(info);
490 }
491
492 // Sets the item image
493 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
494 {
495 return SetItemColumnImage(item, 0, image);
496 }
497
498 // Sets the item image
499 bool wxListCtrl::SetItemColumnImage(long item, long column, int image)
500 {
501 if (m_genericImpl)
502 return m_genericImpl->SetItemColumnImage(item, column, image);
503
504 wxListItem info;
505
506 info.m_mask = wxLIST_MASK_IMAGE;
507 info.m_image = image;
508 info.m_itemId = item;
509 info.m_col = column;
510
511 return SetItem(info);
512 }
513
514 // Gets the item text
515 wxString wxListCtrl::GetItemText(long item) const
516 {
517 if (m_genericImpl)
518 return m_genericImpl->GetItemText(item);
519
520 wxListItem info;
521
522 info.m_mask = wxLIST_MASK_TEXT;
523 info.m_itemId = item;
524
525 if (!GetItem(info))
526 return wxEmptyString;
527 return info.m_text;
528 }
529
530 // Sets the item text
531 void wxListCtrl::SetItemText(long item, const wxString& str)
532 {
533 if (m_genericImpl)
534 return m_genericImpl->SetItemText(item, str);
535
536 wxListItem info;
537
538 info.m_mask = wxLIST_MASK_TEXT;
539 info.m_itemId = item;
540 info.m_text = str;
541
542 SetItem(info);
543 }
544
545 // Gets the item data
546 long wxListCtrl::GetItemData(long item) const
547 {
548 if (m_genericImpl)
549 return m_genericImpl->GetItemData(item);
550
551 wxListItem info;
552
553 info.m_mask = wxLIST_MASK_DATA;
554 info.m_itemId = item;
555
556 if (!GetItem(info))
557 return 0;
558 return info.m_data;
559 }
560
561 // Sets the item data
562 bool wxListCtrl::SetItemData(long item, long data)
563 {
564 if (m_genericImpl)
565 return m_genericImpl->SetItemData(item, data);
566
567 wxListItem info;
568
569 info.m_mask = wxLIST_MASK_DATA;
570 info.m_itemId = item;
571 info.m_data = data;
572
573 return SetItem(info);
574 }
575
576 wxRect wxListCtrl::GetViewRect() const
577 {
578 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
579 _T("wxListCtrl::GetViewRect() only works in icon mode") );
580
581 if (m_genericImpl)
582 return m_genericImpl->GetViewRect();
583
584 wxRect rect;
585 return rect;
586 }
587
588 // Gets the item rectangle
589 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
590 {
591 if (m_genericImpl)
592 return m_genericImpl->GetItemRect(item, rect, code);
593
594 return true;
595 }
596
597 // Gets the item position
598 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
599 {
600 if (m_genericImpl)
601 return m_genericImpl->GetItemPosition(item, pos);
602
603 bool success = false;
604
605 return success;
606 }
607
608 // Sets the item position.
609 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
610 {
611 if (m_genericImpl)
612 return m_genericImpl->SetItemPosition(item, pos);
613
614 return false;
615 }
616
617 // Gets the number of items in the list control
618 int wxListCtrl::GetItemCount() const
619 {
620 if (m_genericImpl)
621 return m_genericImpl->GetItemCount();
622
623 if (m_dbImpl)
624 return m_dbImpl->MacGetCount();
625
626 return m_count;
627 }
628
629 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
630 {
631 if (m_genericImpl)
632 m_genericImpl->SetItemSpacing(spacing, isSmall);
633 }
634
635 wxSize wxListCtrl::GetItemSpacing() const
636 {
637 if (m_genericImpl)
638 return m_genericImpl->GetItemSpacing();
639
640 return wxSize(0, 0);
641 }
642
643 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
644 {
645 if (m_genericImpl){
646 m_genericImpl->SetItemTextColour(item, col);
647 }
648
649 wxListItem info;
650 info.m_itemId = item;
651 info.SetTextColour( col );
652 SetItem( info );
653 }
654
655 wxColour wxListCtrl::GetItemTextColour( long item ) const
656 {
657 if (m_genericImpl)
658 return m_genericImpl->GetItemTextColour(item);
659
660 if (m_dbImpl){
661 wxListItem info;
662 if (GetItem(info))
663 return info.GetTextColour();
664 }
665 return wxNullColour;
666 }
667
668 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
669 {
670 if (m_genericImpl){
671 m_genericImpl->SetItemBackgroundColour(item, col);
672 return;
673 }
674
675 wxListItem info;
676 info.m_itemId = item;
677 info.SetBackgroundColour( col );
678 SetItem( info );
679 }
680
681 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
682 {
683 if (m_genericImpl)
684 return m_genericImpl->GetItemBackgroundColour(item);
685
686 if (m_dbImpl){
687 wxListItem info;
688 if (GetItem(info))
689 return info.GetBackgroundColour();
690 }
691 return wxNullColour;
692 }
693
694 void wxListCtrl::SetItemFont( long item, const wxFont &f )
695 {
696 if (m_genericImpl){
697 m_genericImpl->SetItemFont(item, f);
698 return;
699 }
700
701 wxListItem info;
702 info.m_itemId = item;
703 info.SetFont( f );
704 SetItem( info );
705 }
706
707 wxFont wxListCtrl::GetItemFont( long item ) const
708 {
709 if (m_genericImpl)
710 return m_genericImpl->GetItemFont(item);
711
712 if (m_dbImpl){
713 wxListItem info;
714 if (GetItem(info))
715 return info.GetFont();
716 }
717
718 return wxNullFont;
719 }
720
721 // Gets the number of selected items in the list control
722 int wxListCtrl::GetSelectedItemCount() const
723 {
724 if (m_genericImpl)
725 return m_genericImpl->GetSelectedItemCount();
726
727 if (m_dbImpl)
728 return m_dbImpl->GetSelectedItemCount(NULL, true);
729
730 return 0;
731 }
732
733 // Gets the text colour of the listview
734 wxColour wxListCtrl::GetTextColour() const
735 {
736 if (m_genericImpl)
737 return m_genericImpl->GetTextColour();
738
739 // TODO: we need owner drawn list items to customize text color.
740 if (m_dbImpl)
741 return *wxBLACK;
742 }
743
744 // Sets the text colour of the listview
745 void wxListCtrl::SetTextColour(const wxColour& col)
746 {
747 if (m_genericImpl){
748 m_genericImpl->SetTextColour(col);
749 return;
750 }
751
752 // TODO: if we add owner-drawn item support for DataBrowser,
753 // consider supporting this property
754 }
755
756 // Gets the index of the topmost visible item when in
757 // list or report view
758 long wxListCtrl::GetTopItem() const
759 {
760 if (m_genericImpl)
761 return m_genericImpl->GetTopItem();
762
763 return 0;
764 }
765
766 // Searches for an item, starting from 'item'.
767 // 'geometry' is one of
768 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
769 // 'state' is a state bit flag, one or more of
770 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
771 // item can be -1 to find the first item that matches the
772 // specified flags.
773 // Returns the item or -1 if unsuccessful.
774 long wxListCtrl::GetNextItem(long item, int geom, int state) const
775 {
776 if (m_genericImpl)
777 return m_genericImpl->GetNextItem(item, geom, state);
778
779 return 0;
780 }
781
782
783 wxImageList *wxListCtrl::GetImageList(int which) const
784 {
785 if (m_genericImpl)
786 return m_genericImpl->GetImageList(which);
787
788 if ( which == wxIMAGE_LIST_NORMAL )
789 {
790 return m_imageListNormal;
791 }
792 else if ( which == wxIMAGE_LIST_SMALL )
793 {
794 return m_imageListSmall;
795 }
796 else if ( which == wxIMAGE_LIST_STATE )
797 {
798 return m_imageListState;
799 }
800 return NULL;
801 }
802
803 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
804 {
805 if (m_genericImpl){
806 m_genericImpl->SetImageList(imageList, which);
807 return;
808 }
809
810 int flags = 0;
811 if ( which == wxIMAGE_LIST_NORMAL )
812 {
813 if (m_ownsImageListNormal) delete m_imageListNormal;
814 m_imageListNormal = imageList;
815 m_ownsImageListNormal = false;
816 }
817 else if ( which == wxIMAGE_LIST_SMALL )
818 {
819 if (m_ownsImageListSmall) delete m_imageListSmall;
820 m_imageListSmall = imageList;
821 m_ownsImageListSmall = false;
822 }
823 else if ( which == wxIMAGE_LIST_STATE )
824 {
825 if (m_ownsImageListState) delete m_imageListState;
826 m_imageListState = imageList;
827 m_ownsImageListState = false;
828 }
829 }
830
831 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
832 {
833 if (m_genericImpl){
834 m_genericImpl->AssignImageList(imageList, which);
835 return;
836 }
837
838 SetImageList(imageList, which);
839 if ( which == wxIMAGE_LIST_NORMAL )
840 m_ownsImageListNormal = true;
841 else if ( which == wxIMAGE_LIST_SMALL )
842 m_ownsImageListSmall = true;
843 else if ( which == wxIMAGE_LIST_STATE )
844 m_ownsImageListState = true;
845 }
846
847 // ----------------------------------------------------------------------------
848 // Operations
849 // ----------------------------------------------------------------------------
850
851 // Arranges the items
852 bool wxListCtrl::Arrange(int flag)
853 {
854 if (m_genericImpl)
855 return m_genericImpl->Arrange(flag);
856 return false;
857 }
858
859 // Deletes an item
860 bool wxListCtrl::DeleteItem(long item)
861 {
862 if (m_genericImpl)
863 return m_genericImpl->DeleteItem(item);
864
865 if (m_dbImpl){
866 m_dbImpl->MacDelete(item);
867 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
868 event.SetEventObject( this );
869 event.m_itemIndex = item;
870 GetEventHandler()->ProcessEvent( event );
871
872 }
873 return true;
874 }
875
876 // Deletes all items
877 bool wxListCtrl::DeleteAllItems()
878 {
879 if (m_genericImpl)
880 return m_genericImpl->DeleteAllItems();
881
882 if (m_dbImpl){
883 m_dbImpl->MacClear();
884 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
885 event.SetEventObject( this );
886 GetEventHandler()->ProcessEvent( event );
887 }
888 return true;
889 }
890
891 // Deletes all items
892 bool wxListCtrl::DeleteAllColumns()
893 {
894 if (m_genericImpl)
895 return m_genericImpl->DeleteAllColumns();
896
897 if (m_dbImpl){
898 UInt32 cols;
899 m_dbImpl->GetColumnCount(&cols);
900 for (UInt32 col = 0; col < cols; col++){
901 DeleteColumn(col);
902 }
903 }
904
905 return true;
906 }
907
908 // Deletes a column
909 bool wxListCtrl::DeleteColumn(int col)
910 {
911 if (m_genericImpl)
912 return m_genericImpl->DeleteColumn(col);
913
914 if (m_dbImpl){
915 OSStatus err = m_dbImpl->RemoveColumn(col);
916 return err == noErr;
917 }
918
919 return true;
920 }
921
922 // Clears items, and columns if there are any.
923 void wxListCtrl::ClearAll()
924 {
925 if (m_genericImpl){
926 m_genericImpl->ClearAll();
927 return;
928 }
929
930 DeleteAllItems();
931 if ( m_colCount > 0 )
932 DeleteAllColumns();
933 }
934
935 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
936 {
937 if (m_genericImpl)
938 return m_genericImpl->EditLabel(item, textControlClass);
939
940 return NULL;
941 }
942
943 // End label editing, optionally cancelling the edit
944 bool wxListCtrl::EndEditLabel(bool cancel)
945 {
946 // TODO: generic impl. doesn't have this method - is it needed for us?
947 if (m_genericImpl)
948 return false; // m_genericImpl->EndEditLabel(cancel);
949
950 bool b = true;
951 return b;
952 }
953
954 // Ensures this item is visible
955 bool wxListCtrl::EnsureVisible(long item)
956 {
957 if (m_genericImpl)
958 return m_genericImpl->EnsureVisible(item);
959
960 if (m_dbImpl){
961 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
962 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
963 }
964 }
965
966 // Find an item whose label matches this string, starting from the item after 'start'
967 // or the beginning if 'start' is -1.
968 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
969 {
970 if (m_genericImpl)
971 return m_genericImpl->FindItem(start, str, partial);
972
973 return -1;
974 }
975
976 // Find an item whose data matches this data, starting from the item after 'start'
977 // or the beginning if 'start' is -1.
978 long wxListCtrl::FindItem(long start, long data)
979 {
980 if (m_genericImpl)
981 return m_genericImpl->FindItem(start, data);
982
983 long idx = start + 1;
984 long count = GetItemCount();
985
986 while (idx < count)
987 {
988 if (GetItemData(idx) == data)
989 return idx;
990 idx++;
991 };
992
993 return -1;
994 }
995
996 // Find an item nearest this position in the specified direction, starting from
997 // the item after 'start' or the beginning if 'start' is -1.
998 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
999 {
1000 if (m_genericImpl)
1001 return m_genericImpl->FindItem(start, pt, direction);
1002 return -1;
1003 }
1004
1005 // Determines which item (if any) is at the specified point,
1006 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1007 long
1008 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1009 {
1010 if (m_genericImpl)
1011 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1012
1013 return -1;
1014 }
1015
1016
1017 // Inserts an item, returning the index of the new item if successful,
1018 // -1 otherwise.
1019 long wxListCtrl::InsertItem(wxListItem& info)
1020 {
1021 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1022
1023 if (m_genericImpl)
1024 return m_genericImpl->InsertItem(info);
1025
1026 if (m_dbImpl){
1027 int count = GetItemCount();
1028
1029 if (info.m_itemId > count)
1030 info.m_itemId = count;
1031
1032 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1033 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1034 event.SetEventObject( this );
1035 event.m_itemIndex = info.m_itemId;
1036 GetEventHandler()->ProcessEvent( event );
1037 }
1038
1039 return info.m_itemId;
1040 }
1041
1042 long wxListCtrl::InsertItem(long index, const wxString& label)
1043 {
1044 if (m_genericImpl)
1045 return m_genericImpl->InsertItem(index, label);
1046
1047 wxListItem info;
1048 info.m_text = label;
1049 info.m_mask = wxLIST_MASK_TEXT;
1050 info.m_itemId = index;
1051 return InsertItem(info);
1052 }
1053
1054 // Inserts an image item
1055 long wxListCtrl::InsertItem(long index, int imageIndex)
1056 {
1057 if (m_genericImpl)
1058 return m_genericImpl->InsertItem(index, imageIndex);
1059
1060 wxListItem info;
1061 info.m_image = imageIndex;
1062 info.m_mask = wxLIST_MASK_IMAGE;
1063 info.m_itemId = index;
1064 return InsertItem(info);
1065 }
1066
1067 // Inserts an image/string item
1068 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1069 {
1070 if (m_genericImpl)
1071 return m_genericImpl->InsertItem(index, label, imageIndex);
1072
1073 wxListItem info;
1074 info.m_image = imageIndex;
1075 info.m_text = label;
1076 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1077 info.m_itemId = index;
1078 return InsertItem(info);
1079 }
1080
1081 // For list view mode (only), inserts a column.
1082 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1083 {
1084 if (m_genericImpl)
1085 return m_genericImpl->InsertColumn(col, item);
1086
1087 if (m_dbImpl){
1088 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1089 item.SetWidth(150);
1090
1091 DataBrowserPropertyType type = kDataBrowserTextType;
1092 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1093 if (imageList && imageList->GetImageCount() > 0){
1094 wxBitmap bmp = imageList->GetBitmap(0);
1095 if (bmp.Ok())
1096 type = kDataBrowserIconAndTextType;
1097 }
1098
1099 fprintf(stderr, "Flush is %d\n", item.GetAlign());
1100 SInt16 just = teFlushDefault;
1101 if (item.GetMask() & wxLIST_MASK_FORMAT){
1102 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1103 just = teFlushLeft;
1104 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1105 just = teCenter;
1106 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1107 just = teFlushRight;
1108 }
1109 m_dbImpl->InsertColumn(col, type, item.GetText(), just, item.GetWidth());
1110
1111 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1112 {
1113 DataBrowserTableViewColumnID id;
1114 m_dbImpl->GetColumnIDFromIndex(col, &id);
1115 DataBrowserPropertyFlags flags;
1116 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1117 flags |= kDataBrowserPropertyIsEditable;
1118 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1119 }
1120 }
1121
1122 return col;
1123 }
1124
1125 long wxListCtrl::InsertColumn(long col,
1126 const wxString& heading,
1127 int format,
1128 int width)
1129 {
1130 if (m_genericImpl)
1131 return m_genericImpl->InsertColumn(col, heading, format, width);
1132
1133 wxListItem item;
1134 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1135 item.m_text = heading;
1136 if ( width > -1 )
1137 {
1138 item.m_mask |= wxLIST_MASK_WIDTH;
1139 item.m_width = width;
1140 }
1141 item.m_format = format;
1142
1143 return InsertColumn(col, item);
1144 }
1145
1146 // scroll the control by the given number of pixels (exception: in list view,
1147 // dx is interpreted as number of columns)
1148 bool wxListCtrl::ScrollList(int dx, int dy)
1149 {
1150 if (m_genericImpl)
1151 return m_genericImpl->ScrollList(dx, dy);
1152
1153 if (m_dbImpl){
1154 m_dbImpl->SetScrollPosition(dx, dy);
1155 }
1156 return true;
1157 }
1158
1159
1160 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1161 {
1162 if (m_genericImpl)
1163 return m_genericImpl->SortItems(fn, data);
1164
1165 return true;
1166 }
1167
1168 // ----------------------------------------------------------------------------
1169 // virtual list controls
1170 // ----------------------------------------------------------------------------
1171
1172 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1173 {
1174 // this is a pure virtual function, in fact - which is not really pure
1175 // because the controls which are not virtual don't need to implement it
1176 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1177
1178 return wxEmptyString;
1179 }
1180
1181 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1182 {
1183 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1184 -1,
1185 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1186 return -1;
1187 }
1188
1189 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1190 {
1191 if (!column)
1192 return OnGetItemImage(item);
1193
1194 return -1;
1195 }
1196
1197 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1198 {
1199 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1200 _T("invalid item index in OnGetItemAttr()") );
1201
1202 // no attributes by default
1203 return NULL;
1204 }
1205
1206 void wxListCtrl::SetItemCount(long count)
1207 {
1208 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1209
1210 if (m_genericImpl){
1211 m_genericImpl->SetItemCount(count);
1212 return;
1213 }
1214
1215 m_count = count;
1216 }
1217
1218 void wxListCtrl::RefreshItem(long item)
1219 {
1220 if (m_genericImpl){
1221 m_genericImpl->RefreshItem(item);
1222 return;
1223 }
1224
1225 wxRect rect;
1226 GetItemRect(item, rect);
1227 RefreshRect(rect);
1228 }
1229
1230 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1231 {
1232 if (m_genericImpl){
1233 m_genericImpl->RefreshItems(itemFrom, itemTo);
1234 return;
1235 }
1236
1237 wxRect rect1, rect2;
1238 GetItemRect(itemFrom, rect1);
1239 GetItemRect(itemTo, rect2);
1240
1241 wxRect rect = rect1;
1242 rect.height = rect2.GetBottom() - rect1.GetTop();
1243
1244 RefreshRect(rect);
1245 }
1246
1247
1248 // wxMac internal data structures
1249
1250 wxMacListCtrlItem::~wxMacListCtrlItem()
1251 {
1252 }
1253
1254 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
1255 DataBrowserItemNotification message,
1256 DataBrowserItemDataRef itemData ) const
1257 {
1258
1259 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
1260
1261 // we want to depend on as little as possible to make sure tear-down of controls is safe
1262 if ( message == kDataBrowserItemRemoved)
1263 {
1264 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
1265 {
1266 delete (wxClientData*) (m_data);
1267 }
1268
1269 delete this;
1270 return;
1271 }
1272 else if ( message == kDataBrowserItemAdded )
1273 {
1274 // we don't issue events on adding, the item is not really stored in the list yet, so we
1275 // avoid asserts by gettting out now
1276 return ;
1277 }
1278
1279 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1280 if ( list ){
1281 bool trigger = false;
1282
1283 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
1284 bool isSingle = list->GetWindowStyle() | wxLC_SINGLE_SEL;
1285 event.SetEventObject( list );
1286 event.m_itemIndex = owner->GetLineFromItem( this ) ;
1287 if ( !list->IsVirtual() )
1288 {
1289 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
1290 }
1291
1292 switch (message)
1293 {
1294 case kDataBrowserItemDeselected:
1295 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
1296 if ( !isSingle )
1297 trigger = !lb->IsSelectionSuppressed();
1298 break;
1299
1300 case kDataBrowserItemSelected:
1301 trigger = !lb->IsSelectionSuppressed();
1302 break;
1303
1304 case kDataBrowserItemDoubleClicked:
1305 event.SetEventType( wxEVT_LEFT_DCLICK );
1306 trigger = true;
1307 break;
1308
1309 case kDataBrowserEditStarted :
1310 // TODO : how to veto ?
1311 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
1312 trigger = true ;
1313 break ;
1314
1315 case kDataBrowserEditStopped :
1316 // TODO probably trigger only upon the value store callback, because
1317 // here IIRC we cannot veto
1318 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
1319 trigger = true ;
1320 break ;
1321
1322 default:
1323 break;
1324 }
1325
1326 if ( trigger )
1327 {
1328 // direct notification is not always having the listbox GetSelection() having in synch with event
1329 wxPostEvent( list->GetEventHandler(), event );
1330 }
1331 }
1332
1333 }
1334
1335 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
1336 : wxMacDataItemBrowserControl( peer, pos, size, style )
1337 {
1338 OSStatus err = noErr;
1339 m_clientDataItemsType = wxClientData_None;
1340
1341 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
1342 if ( style & wxLC_SINGLE_SEL )
1343 {
1344 options |= kDataBrowserSelectOnlyOne;
1345 }
1346 else
1347 {
1348 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
1349 }
1350
1351 err = SetSelectionFlags( options );
1352 verify_noerr( err );
1353
1354 if ( style & wxLC_LIST ){
1355 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
1356 verify_noerr( AutoSizeColumns() );
1357 verify_noerr( SetHeaderButtonHeight( 0 ) );
1358 }
1359
1360 SetDataBrowserSortProperty( m_controlRef , kMinColumnId );
1361 if ( style & wxLC_SORT_ASCENDING )
1362 {
1363 m_sortOrder = SortOrder_Text_Ascending;
1364 SetDataBrowserSortProperty( m_controlRef , kMinColumnId );
1365 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
1366 }
1367 else if ( style & wxLC_SORT_DESCENDING )
1368 {
1369 m_sortOrder = SortOrder_Text_Descending;
1370 SetDataBrowserSortProperty( m_controlRef , kMinColumnId );
1371 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderDecreasing);
1372 }
1373 else
1374 {
1375 m_sortOrder = SortOrder_None;
1376 SetDataBrowserSortProperty( m_controlRef , kMinColumnId);
1377 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
1378 }
1379
1380 verify_noerr( AutoSizeColumns() );
1381 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
1382 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
1383 }
1384
1385 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1386 {
1387 }
1388
1389 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
1390 {
1391 wxMacDataItem* dataItem = GetItemFromLine(row);
1392 if (item){
1393 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
1394 listItem->SetColumnInfo( column, item );
1395 UpdateState(dataItem, item);
1396 }
1397 }
1398
1399 // apply changes that need to happen immediately, rather than when the
1400 // databrowser control fires a callback.
1401 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
1402 {
1403 bool isSelected = IsItemSelected( dataItem );
1404 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
1405
1406 // toggle the selection state if wxListInfo state and actual state don't match.
1407 if ( isSelected != isSelectedState ){
1408 DataBrowserSetOption options = kDataBrowserItemsAdd;
1409 if (!isSelectedState)
1410 options = kDataBrowserItemsRemove;
1411 fprintf(stderr, "state = %d, db options = %d\n", isSelectedState, options);
1412 SetSelectedItem(dataItem, options);
1413 }
1414 // TODO: Set column width if item width > than current column width
1415 }
1416
1417 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
1418 {
1419 wxMacDataItem* dataItem = GetItemFromLine(row);
1420 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1421 //if (item)
1422 {
1423 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
1424 wxListItem* oldItem = listItem->GetColumnInfo( column );
1425
1426 long mask = item.GetMask();
1427 if ( !mask )
1428 // by default, get everything for backwards compatibility
1429 mask = -1;
1430
1431 if ( mask & wxLIST_MASK_TEXT )
1432 item.SetText(oldItem->GetText());
1433 if ( mask & wxLIST_MASK_IMAGE )
1434 item.SetImage(oldItem->GetImage());
1435 if ( mask & wxLIST_MASK_DATA )
1436 item.SetData(oldItem->GetData());
1437 if ( mask & wxLIST_MASK_STATE )
1438 item.SetState(oldItem->GetState());
1439 if ( mask & wxLIST_MASK_WIDTH )
1440 item.SetWidth(oldItem->GetWidth());
1441 if ( mask & wxLIST_MASK_FORMAT )
1442 item.SetAlign(oldItem->GetAlign());
1443
1444 item.SetTextColour(oldItem->GetTextColour());
1445 item.SetBackgroundColour(oldItem->GetBackgroundColour());
1446 item.SetFont(oldItem->GetFont());
1447 }
1448 }
1449
1450 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
1451 {
1452 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
1453 MacSetColumnInfo(n, 0, item);
1454 }
1455
1456 wxMacListCtrlItem* wxMacDataBrowserListCtrlControl::CreateItem()
1457 {
1458 return new wxMacListCtrlItem();
1459 }
1460
1461 wxMacListCtrlItem::wxMacListCtrlItem()
1462 {
1463 m_rowItems = wxListItemList();
1464 }
1465
1466 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
1467 {
1468 return GetColumnInfo(column)->GetImage();
1469 }
1470
1471 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
1472 {
1473 GetColumnInfo(column)->SetImage(imageIndex);
1474 }
1475
1476 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
1477 {
1478 if ( column == 0 )
1479 return GetLabel();
1480
1481 return GetColumnInfo(column)->GetText();
1482 }
1483
1484 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
1485 {
1486 GetColumnInfo(column)->SetText(text);
1487
1488 // for compatibility with superclass APIs
1489 if ( column == 0 )
1490 SetLabel(text);
1491 }
1492
1493 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
1494 {
1495 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
1496 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
1497
1498 return node->GetData();
1499 }
1500
1501 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
1502 {
1503 return m_rowItems.GetCount() > column;
1504 }
1505
1506 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
1507 {
1508
1509 if ( column >= m_rowItems.GetCount() ){
1510 wxListItem* listItem = new wxListItem(*item);
1511 //listItem->SetAlign(item->GetAlign());
1512 //listItem->SetBackgroundColour(item->GetBackgroundColour());
1513 //listItem->SetColumn(item->GetColumn());
1514 //listItem->SetData(item->GetData());
1515 //listItem->SetFont(item->GetFont());
1516 //listItem->SetId(GetOrder());
1517 //listItem->SetImage(item->GetImage());
1518 //listItem->SetMask(item->GetMask());
1519
1520 //listItem->SetText(item->GetText());
1521 m_rowItems.Append( listItem );
1522 }
1523 else{
1524 wxListItem* listItem = GetColumnInfo( column );
1525 long mask = item->GetMask();
1526 if (mask & wxLIST_MASK_TEXT)
1527 listItem->SetText(item->GetText());
1528 if (mask & wxLIST_MASK_DATA)
1529 listItem->SetData(item->GetData());
1530 if (mask & wxLIST_MASK_IMAGE)
1531 listItem->SetImage(item->GetImage());
1532 if (mask & wxLIST_MASK_STATE)
1533 listItem->SetState(item->GetState());
1534 if (mask & wxLIST_MASK_FORMAT)
1535 listItem->SetAlign(item->GetAlign());
1536 if (mask & wxLIST_MASK_WIDTH)
1537 listItem->SetWidth(item->GetWidth());
1538 }
1539 }
1540
1541 OSStatus wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl *owner ,
1542 DataBrowserPropertyID property,
1543 DataBrowserItemDataRef itemData,
1544 bool changeValue )
1545 {
1546
1547 OSStatus err = errDataBrowserPropertyNotSupported;
1548 wxListCtrl* list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1549 if ( !changeValue )
1550 {
1551 switch (property)
1552 {
1553 case kDataBrowserItemIsEditableProperty :
1554 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
1555 {
1556 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
1557 err = noErr ;
1558 }
1559 break ;
1560 default :
1561 if ( property >= kMinColumnId ){
1562 short listColumn = property - kMinColumnId;
1563
1564 if (HasColumnInfo(listColumn)){
1565 wxListItem* item = GetColumnInfo(listColumn);
1566 wxMacCFStringHolder cfStr;
1567
1568 if (item->GetText()){
1569 cfStr.Assign( item->GetText(), wxLocale::GetSystemEncoding() );
1570 err = ::SetDataBrowserItemDataText( itemData, cfStr );
1571 err = noErr;
1572 }
1573
1574 int imgIndex = item->GetImage();
1575 if ( (item->GetMask() & wxLIST_MASK_IMAGE) ){
1576 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
1577 if (imageList && imageList->GetImageCount() > 0){
1578 wxBitmap bmp = imageList->GetBitmap(imgIndex);
1579 IconRef icon = bmp.GetBitmapData()->GetIconRef();
1580 ::SetDataBrowserItemDataIcon(itemData, icon);
1581 }
1582 }
1583
1584 }
1585 }
1586 break ;
1587 }
1588 }
1589 else
1590 {
1591 switch (property)
1592 {
1593 default:
1594 if ( property >= kMinColumnId ){
1595 short listColumn = property - kMinColumnId;
1596
1597 if (HasColumnInfo(listColumn)){
1598 // TODO probably send the 'end edit' from here, as we
1599 // can then deal with the veto
1600 CFStringRef sr ;
1601 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
1602 wxMacCFStringHolder cfStr(sr) ;;
1603 list->SetItem( owner->GetLineFromItem(this) , listColumn, cfStr.AsString() ) ;
1604 err = noErr ;
1605 }
1606 }
1607 break;
1608 }
1609 }
1610
1611 // don't duplicate the numeric order column handling
1612 if (err == errDataBrowserPropertyNotSupported)
1613 err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue);
1614
1615 return err;
1616 }
1617
1618 #endif // wxUSE_LISTCTRL