]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
Accidently checked for invalid image index rather than using the mask.
[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 wxSize wxListCtrl::GetItemSpacing() const
630 {
631 if (m_genericImpl)
632 return m_genericImpl->GetItemSpacing();
633
634 return wxSize(0, 0);
635 }
636
637 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
638 {
639 if (m_genericImpl){
640 m_genericImpl->SetItemTextColour(item, col);
641 }
642
643 wxListItem info;
644 info.m_itemId = item;
645 info.SetTextColour( col );
646 SetItem( info );
647 }
648
649 wxColour wxListCtrl::GetItemTextColour( long item ) const
650 {
651 if (m_genericImpl)
652 return m_genericImpl->GetItemTextColour(item);
653
654 if (m_dbImpl){
655 wxListItem info;
656 if (GetItem(info))
657 return info.GetTextColour();
658 }
659 return wxNullColour;
660 }
661
662 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
663 {
664 if (m_genericImpl){
665 m_genericImpl->SetItemBackgroundColour(item, col);
666 return;
667 }
668
669 wxListItem info;
670 info.m_itemId = item;
671 info.SetBackgroundColour( col );
672 SetItem( info );
673 }
674
675 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
676 {
677 if (m_genericImpl)
678 return m_genericImpl->GetItemBackgroundColour(item);
679
680 if (m_dbImpl){
681 wxListItem info;
682 if (GetItem(info))
683 return info.GetBackgroundColour();
684 }
685 return wxNullColour;
686 }
687
688 void wxListCtrl::SetItemFont( long item, const wxFont &f )
689 {
690 if (m_genericImpl){
691 m_genericImpl->SetItemFont(item, f);
692 return;
693 }
694
695 wxListItem info;
696 info.m_itemId = item;
697 info.SetFont( f );
698 SetItem( info );
699 }
700
701 wxFont wxListCtrl::GetItemFont( long item ) const
702 {
703 if (m_genericImpl)
704 return m_genericImpl->GetItemFont(item);
705
706 if (m_dbImpl){
707 wxListItem info;
708 if (GetItem(info))
709 return info.GetFont();
710 }
711
712 return wxNullFont;
713 }
714
715 // Gets the number of selected items in the list control
716 int wxListCtrl::GetSelectedItemCount() const
717 {
718 if (m_genericImpl)
719 return m_genericImpl->GetSelectedItemCount();
720
721 if (m_dbImpl)
722 return m_dbImpl->GetSelectedItemCount(NULL, true);
723
724 return 0;
725 }
726
727 // Gets the text colour of the listview
728 wxColour wxListCtrl::GetTextColour() const
729 {
730 if (m_genericImpl)
731 return m_genericImpl->GetTextColour();
732
733 // TODO: we need owner drawn list items to customize text color.
734 if (m_dbImpl)
735 return *wxBLACK;
736 }
737
738 // Sets the text colour of the listview
739 void wxListCtrl::SetTextColour(const wxColour& col)
740 {
741 if (m_genericImpl){
742 m_genericImpl->SetTextColour(col);
743 return;
744 }
745
746 // TODO: if we add owner-drawn item support for DataBrowser,
747 // consider supporting this property
748 }
749
750 // Gets the index of the topmost visible item when in
751 // list or report view
752 long wxListCtrl::GetTopItem() const
753 {
754 if (m_genericImpl)
755 return m_genericImpl->GetTopItem();
756
757 return 0;
758 }
759
760 // Searches for an item, starting from 'item'.
761 // 'geometry' is one of
762 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
763 // 'state' is a state bit flag, one or more of
764 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
765 // item can be -1 to find the first item that matches the
766 // specified flags.
767 // Returns the item or -1 if unsuccessful.
768 long wxListCtrl::GetNextItem(long item, int geom, int state) const
769 {
770 if (m_genericImpl)
771 return m_genericImpl->GetNextItem(item, geom, state);
772
773 return 0;
774 }
775
776
777 wxImageList *wxListCtrl::GetImageList(int which) const
778 {
779 if (m_genericImpl)
780 return m_genericImpl->GetImageList(which);
781
782 if ( which == wxIMAGE_LIST_NORMAL )
783 {
784 return m_imageListNormal;
785 }
786 else if ( which == wxIMAGE_LIST_SMALL )
787 {
788 return m_imageListSmall;
789 }
790 else if ( which == wxIMAGE_LIST_STATE )
791 {
792 return m_imageListState;
793 }
794 return NULL;
795 }
796
797 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
798 {
799 if (m_genericImpl){
800 m_genericImpl->SetImageList(imageList, which);
801 return;
802 }
803
804 int flags = 0;
805 if ( which == wxIMAGE_LIST_NORMAL )
806 {
807 if (m_ownsImageListNormal) delete m_imageListNormal;
808 m_imageListNormal = imageList;
809 m_ownsImageListNormal = false;
810 }
811 else if ( which == wxIMAGE_LIST_SMALL )
812 {
813 if (m_ownsImageListSmall) delete m_imageListSmall;
814 m_imageListSmall = imageList;
815 m_ownsImageListSmall = false;
816 }
817 else if ( which == wxIMAGE_LIST_STATE )
818 {
819 if (m_ownsImageListState) delete m_imageListState;
820 m_imageListState = imageList;
821 m_ownsImageListState = false;
822 }
823 }
824
825 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
826 {
827 if (m_genericImpl){
828 m_genericImpl->AssignImageList(imageList, which);
829 return;
830 }
831
832 SetImageList(imageList, which);
833 if ( which == wxIMAGE_LIST_NORMAL )
834 m_ownsImageListNormal = true;
835 else if ( which == wxIMAGE_LIST_SMALL )
836 m_ownsImageListSmall = true;
837 else if ( which == wxIMAGE_LIST_STATE )
838 m_ownsImageListState = true;
839 }
840
841 // ----------------------------------------------------------------------------
842 // Operations
843 // ----------------------------------------------------------------------------
844
845 // Arranges the items
846 bool wxListCtrl::Arrange(int flag)
847 {
848 if (m_genericImpl)
849 return m_genericImpl->Arrange(flag);
850 return false;
851 }
852
853 // Deletes an item
854 bool wxListCtrl::DeleteItem(long item)
855 {
856 if (m_genericImpl)
857 return m_genericImpl->DeleteItem(item);
858
859 if (m_dbImpl){
860 m_dbImpl->MacDelete(item);
861 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
862 event.SetEventObject( this );
863 event.m_itemIndex = item;
864 GetEventHandler()->ProcessEvent( event );
865
866 }
867 return true;
868 }
869
870 // Deletes all items
871 bool wxListCtrl::DeleteAllItems()
872 {
873 if (m_genericImpl)
874 return m_genericImpl->DeleteAllItems();
875
876 if (m_dbImpl){
877 m_dbImpl->MacClear();
878 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
879 event.SetEventObject( this );
880 GetEventHandler()->ProcessEvent( event );
881 }
882 return true;
883 }
884
885 // Deletes all items
886 bool wxListCtrl::DeleteAllColumns()
887 {
888 if (m_genericImpl)
889 return m_genericImpl->DeleteAllColumns();
890
891 if (m_dbImpl){
892 UInt32 cols;
893 m_dbImpl->GetColumnCount(&cols);
894 for (UInt32 col = 0; col < cols; col++){
895 DeleteColumn(col);
896 }
897 }
898
899 return true;
900 }
901
902 // Deletes a column
903 bool wxListCtrl::DeleteColumn(int col)
904 {
905 if (m_genericImpl)
906 return m_genericImpl->DeleteColumn(col);
907
908 if (m_dbImpl){
909 OSStatus err = m_dbImpl->RemoveColumn(col);
910 return err == noErr;
911 }
912
913 return true;
914 }
915
916 // Clears items, and columns if there are any.
917 void wxListCtrl::ClearAll()
918 {
919 if (m_genericImpl){
920 m_genericImpl->ClearAll();
921 return;
922 }
923
924 DeleteAllItems();
925 if ( m_colCount > 0 )
926 DeleteAllColumns();
927 }
928
929 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
930 {
931 if (m_genericImpl)
932 return m_genericImpl->EditLabel(item, textControlClass);
933
934 return NULL;
935 }
936
937 // End label editing, optionally cancelling the edit
938 bool wxListCtrl::EndEditLabel(bool cancel)
939 {
940 // TODO: generic impl. doesn't have this method - is it needed for us?
941 if (m_genericImpl)
942 return false; // m_genericImpl->EndEditLabel(cancel);
943
944 bool b = true;
945 return b;
946 }
947
948 // Ensures this item is visible
949 bool wxListCtrl::EnsureVisible(long item)
950 {
951 if (m_genericImpl)
952 return m_genericImpl->EnsureVisible(item);
953
954 if (m_dbImpl){
955 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
956 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
957 }
958 }
959
960 // Find an item whose label matches this string, starting from the item after 'start'
961 // or the beginning if 'start' is -1.
962 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
963 {
964 if (m_genericImpl)
965 return m_genericImpl->FindItem(start, str, partial);
966
967 return -1;
968 }
969
970 // Find an item whose data matches this data, starting from the item after 'start'
971 // or the beginning if 'start' is -1.
972 long wxListCtrl::FindItem(long start, long data)
973 {
974 if (m_genericImpl)
975 return m_genericImpl->FindItem(start, data);
976
977 long idx = start + 1;
978 long count = GetItemCount();
979
980 while (idx < count)
981 {
982 if (GetItemData(idx) == data)
983 return idx;
984 idx++;
985 };
986
987 return -1;
988 }
989
990 // Find an item nearest this position in the specified direction, starting from
991 // the item after 'start' or the beginning if 'start' is -1.
992 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
993 {
994 if (m_genericImpl)
995 return m_genericImpl->FindItem(start, pt, direction);
996 return -1;
997 }
998
999 // Determines which item (if any) is at the specified point,
1000 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1001 long
1002 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1003 {
1004 if (m_genericImpl)
1005 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1006
1007 return -1;
1008 }
1009
1010
1011 // Inserts an item, returning the index of the new item if successful,
1012 // -1 otherwise.
1013 long wxListCtrl::InsertItem(wxListItem& info)
1014 {
1015 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1016
1017 if (m_genericImpl)
1018 return m_genericImpl->InsertItem(info);
1019
1020 if (m_dbImpl){
1021 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1022 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1023 event.SetEventObject( this );
1024 event.m_itemIndex = info.m_itemId;
1025 GetEventHandler()->ProcessEvent( event );
1026 }
1027
1028 return info.m_itemId;
1029 }
1030
1031 long wxListCtrl::InsertItem(long index, const wxString& label)
1032 {
1033 if (m_genericImpl)
1034 return m_genericImpl->InsertItem(index, label);
1035
1036 wxListItem info;
1037 info.m_text = label;
1038 info.m_mask = wxLIST_MASK_TEXT;
1039 info.m_itemId = index;
1040 return InsertItem(info);
1041 }
1042
1043 // Inserts an image item
1044 long wxListCtrl::InsertItem(long index, int imageIndex)
1045 {
1046 if (m_genericImpl)
1047 return m_genericImpl->InsertItem(index, imageIndex);
1048
1049 wxListItem info;
1050 info.m_image = imageIndex;
1051 info.m_mask = wxLIST_MASK_IMAGE;
1052 info.m_itemId = index;
1053 return InsertItem(info);
1054 }
1055
1056 // Inserts an image/string item
1057 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1058 {
1059 if (m_genericImpl)
1060 return m_genericImpl->InsertItem(index, label, imageIndex);
1061
1062 wxListItem info;
1063 info.m_image = imageIndex;
1064 info.m_text = label;
1065 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1066 info.m_itemId = index;
1067 return InsertItem(info);
1068 }
1069
1070 // For list view mode (only), inserts a column.
1071 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1072 {
1073 if (m_genericImpl)
1074 return m_genericImpl->InsertColumn(col, item);
1075
1076 if (m_dbImpl){
1077 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) ) //item.GetWidth() == 0)
1078 item.SetWidth(300);
1079 DataBrowserPropertyType type = kDataBrowserTextType;
1080 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1081 if (imageList && imageList->GetImageCount() > 0){
1082 wxBitmap bmp = imageList->GetBitmap(0);
1083 if (bmp.Ok())
1084 type = kDataBrowserIconAndTextType;
1085 }
1086
1087 fprintf(stderr, "Flush is %d\n", item.GetAlign());
1088 SInt16 just = teFlushDefault;
1089 if (item.GetMask() & wxLIST_MASK_FORMAT){
1090 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1091 just = teFlushLeft;
1092 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1093 just = teCenter;
1094 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1095 just = teFlushRight;
1096 }
1097 m_dbImpl->InsertColumn(col, type, item.GetText(), just, -1, item.GetWidth());
1098 }
1099
1100 return col;
1101 }
1102
1103 long wxListCtrl::InsertColumn(long col,
1104 const wxString& heading,
1105 int format,
1106 int width)
1107 {
1108 if (m_genericImpl)
1109 return m_genericImpl->InsertColumn(col, heading, format, width);
1110
1111 wxListItem item;
1112 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1113 item.m_text = heading;
1114 if ( width > -1 )
1115 {
1116 item.m_mask |= wxLIST_MASK_WIDTH;
1117 item.m_width = width;
1118 }
1119 item.m_format = format;
1120
1121 return InsertColumn(col, item);
1122 }
1123
1124 // scroll the control by the given number of pixels (exception: in list view,
1125 // dx is interpreted as number of columns)
1126 bool wxListCtrl::ScrollList(int dx, int dy)
1127 {
1128 if (m_genericImpl)
1129 return m_genericImpl->ScrollList(dx, dy);
1130
1131 if (m_dbImpl){
1132 m_dbImpl->SetScrollPosition(dx, dy);
1133 }
1134 return true;
1135 }
1136
1137
1138 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1139 {
1140 if (m_genericImpl)
1141 return m_genericImpl->SortItems(fn, data);
1142
1143 return true;
1144 }
1145
1146 // ----------------------------------------------------------------------------
1147 // virtual list controls
1148 // ----------------------------------------------------------------------------
1149
1150 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1151 {
1152 // this is a pure virtual function, in fact - which is not really pure
1153 // because the controls which are not virtual don't need to implement it
1154 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1155
1156 return wxEmptyString;
1157 }
1158
1159 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1160 {
1161 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1162 -1,
1163 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1164 return -1;
1165 }
1166
1167 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1168 {
1169 if (!column)
1170 return OnGetItemImage(item);
1171
1172 return -1;
1173 }
1174
1175 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1176 {
1177 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1178 _T("invalid item index in OnGetItemAttr()") );
1179
1180 // no attributes by default
1181 return NULL;
1182 }
1183
1184 void wxListCtrl::SetItemCount(long count)
1185 {
1186 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1187
1188 if (m_genericImpl){
1189 m_genericImpl->SetItemCount(count);
1190 return;
1191 }
1192
1193 m_count = count;
1194 }
1195
1196 void wxListCtrl::RefreshItem(long item)
1197 {
1198 if (m_genericImpl){
1199 m_genericImpl->RefreshItem(item);
1200 return;
1201 }
1202
1203 wxRect rect;
1204 GetItemRect(item, rect);
1205 RefreshRect(rect);
1206 }
1207
1208 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1209 {
1210 if (m_genericImpl){
1211 m_genericImpl->RefreshItems(itemFrom, itemTo);
1212 return;
1213 }
1214
1215 wxRect rect1, rect2;
1216 GetItemRect(itemFrom, rect1);
1217 GetItemRect(itemTo, rect2);
1218
1219 wxRect rect = rect1;
1220 rect.height = rect2.GetBottom() - rect1.GetTop();
1221
1222 RefreshRect(rect);
1223 }
1224
1225
1226 // wxMac internal data structures
1227
1228 wxMacListCtrlItem::~wxMacListCtrlItem()
1229 {
1230 }
1231
1232 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
1233 DataBrowserItemNotification message,
1234 DataBrowserItemDataRef itemData ) const
1235 {
1236
1237 wxMacDataBrowserListControl *lb = dynamic_cast<wxMacDataBrowserListControl*>(owner);
1238
1239 // we want to depend on as little as possible to make sure tear-down of controls is safe
1240 if ( message == kDataBrowserItemRemoved)
1241 {
1242 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
1243 {
1244 delete (wxClientData*) (m_data);
1245 }
1246
1247 delete this;
1248 return;
1249 }
1250
1251 // TO STEFAN: I'm getting a couple different problems here and I'd appreciate
1252 // if you could take a look at them.
1253 // 1) wxDynamicCast fails during shutdown. This doesn't suprise me, but
1254 // you have similar listbox code, so I'm wondering why this case is different.
1255 // 2) owner->GetLineFromItem( this ) always asserts.
1256 // 3) the !lb->IsSelectionSuppressed code also fails with EXC_BAD_ACCESS
1257
1258 // To be honest, I think there are casting issues here, but I don't work enough
1259 // in C++ that these things are clear to me, so I'm hoping another pair of eyes
1260 // would help. ;-)
1261 // In any case, I set trigger to false so that these events are not sent.
1262
1263 // during shutdown, this may fail.
1264 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1265 if ( list ){
1266 bool trigger = false;
1267
1268 wxCommandEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
1269 bool isSingle = list->GetWindowStyle() | wxLC_SINGLE_SEL;
1270 switch (message)
1271 {
1272 case kDataBrowserItemDeselected:
1273 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
1274 //if ( !isSingle )
1275 // trigger = !lb->IsSelectionSuppressed();
1276 break;
1277
1278 case kDataBrowserItemSelected:
1279 //trigger = !lb->IsSelectionSuppressed();
1280 break;
1281
1282 case kDataBrowserItemDoubleClicked:
1283 event.SetEventType( wxEVT_LEFT_DCLICK );
1284 trigger = true;
1285 break;
1286
1287 default:
1288 break;
1289 }
1290
1291 if ( trigger )
1292 {
1293 event.SetEventObject( list );
1294 //if ( list->HasClientObjectData() )
1295 // event.SetClientObject( (wxClientData*) m_data );
1296 //else if ( list->HasClientUntypedData() )
1297 // event.SetClientData( m_data );
1298 event.SetString( m_label );
1299 event.SetInt( owner->GetLineFromItem( this ) );
1300 event.SetExtraLong( !isSingle ? message == kDataBrowserItemSelected : true );
1301 wxPostEvent( list->GetEventHandler(), event );
1302
1303 // direct notification is not always having the listbox GetSelection() having in synch with event
1304 // list->GetEventHandler()->ProcessEvent(event);
1305 }
1306 }
1307
1308 }
1309
1310 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
1311 : wxMacDataItemBrowserControl( peer, pos, size, style )
1312 {
1313 OSStatus err = noErr;
1314 m_clientDataItemsType = wxClientData_None;
1315
1316 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
1317 if ( style & wxLC_SINGLE_SEL )
1318 {
1319 options |= kDataBrowserSelectOnlyOne;
1320 }
1321 else
1322 {
1323 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
1324 }
1325
1326 err = SetSelectionFlags( options );
1327 verify_noerr( err );
1328
1329 // create the numeric order column
1330 DataBrowserListViewColumnDesc columnDesc;
1331 columnDesc.headerBtnDesc.titleOffset = 0;
1332 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
1333
1334 columnDesc.headerBtnDesc.btnFontStyle.flags =
1335 kControlUseFontMask | kControlUseJustMask;
1336
1337 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
1338 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
1339 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
1340 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
1341 columnDesc.headerBtnDesc.titleString = NULL;
1342
1343 columnDesc.headerBtnDesc.minimumWidth = 0;
1344 columnDesc.headerBtnDesc.maximumWidth = 0;
1345 columnDesc.propertyDesc.propertyID = kNumericOrderColumnId;
1346 columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart;
1347 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
1348 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1349 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
1350 #endif
1351
1352 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
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 , kNumericOrderColumnId);
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 if (item){
1421 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
1422 wxListItem* oldItem = listItem->GetColumnInfo( column );
1423
1424 long mask = item.GetMask();
1425 if ( !mask )
1426 // by default, get everything for backwards compatibility
1427 mask = -1;
1428
1429 if ( mask & wxLIST_MASK_TEXT )
1430 item.SetText(oldItem->GetText());
1431 if ( mask & wxLIST_MASK_IMAGE )
1432 item.SetImage(oldItem->GetImage());
1433 if ( mask & wxLIST_MASK_DATA )
1434 item.SetData(oldItem->GetData());
1435 if ( mask & wxLIST_MASK_STATE )
1436 item.SetState(oldItem->GetState());
1437 if ( mask & wxLIST_MASK_WIDTH )
1438 item.SetWidth(oldItem->GetWidth());
1439 if ( mask & wxLIST_MASK_FORMAT )
1440 item.SetAlign(oldItem->GetAlign());
1441
1442 item.SetTextColour(oldItem->GetTextColour());
1443 item.SetBackgroundColour(oldItem->GetBackgroundColour());
1444 item.SetFont(oldItem->GetFont());
1445 }
1446 }
1447
1448 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
1449 {
1450 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
1451 MacSetColumnInfo(n, 0, item);
1452 }
1453
1454 wxMacListCtrlItem* wxMacDataBrowserListCtrlControl::CreateItem()
1455 {
1456 return new wxMacListCtrlItem();
1457 }
1458
1459 wxMacListCtrlItem::wxMacListCtrlItem()
1460 {
1461 m_rowItems = wxListItemList();
1462 }
1463
1464 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
1465 {
1466 return GetColumnInfo(column)->GetImage();
1467 }
1468
1469 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
1470 {
1471 GetColumnInfo(column)->SetImage(imageIndex);
1472 }
1473
1474 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
1475 {
1476 if ( column == 0 )
1477 return GetLabel();
1478
1479 return GetColumnInfo(column)->GetText();
1480 }
1481
1482 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
1483 {
1484 GetColumnInfo(column)->SetText(text);
1485
1486 // for compatibility with superclass APIs
1487 if ( column == 0 )
1488 SetLabel(text);
1489 }
1490
1491 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
1492 {
1493 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
1494 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
1495
1496 return node->GetData();
1497 }
1498
1499 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
1500 {
1501 return m_rowItems.GetCount() > column;
1502 }
1503
1504 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
1505 {
1506
1507 if ( column >= m_rowItems.GetCount() ){
1508 wxListItem* listItem = new wxListItem(*item);
1509 //listItem->SetAlign(item->GetAlign());
1510 //listItem->SetBackgroundColour(item->GetBackgroundColour());
1511 //listItem->SetColumn(item->GetColumn());
1512 //listItem->SetData(item->GetData());
1513 //listItem->SetFont(item->GetFont());
1514 //listItem->SetId(GetOrder());
1515 //listItem->SetImage(item->GetImage());
1516 //listItem->SetMask(item->GetMask());
1517
1518 //listItem->SetText(item->GetText());
1519 m_rowItems.Append( listItem );
1520 }
1521 else{
1522 wxListItem* listItem = GetColumnInfo( column );
1523 long mask = item->GetMask();
1524 if (mask & wxLIST_MASK_TEXT)
1525 listItem->SetText(item->GetText());
1526 if (mask & wxLIST_MASK_DATA)
1527 listItem->SetData(item->GetData());
1528 if (mask & wxLIST_MASK_IMAGE)
1529 listItem->SetImage(item->GetImage());
1530 if (mask & wxLIST_MASK_STATE)
1531 listItem->SetState(item->GetState());
1532 if (mask & wxLIST_MASK_FORMAT)
1533 listItem->SetAlign(item->GetAlign());
1534 if (mask & wxLIST_MASK_WIDTH)
1535 listItem->SetWidth(item->GetWidth());
1536 }
1537 }
1538
1539 OSStatus wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl *owner ,
1540 DataBrowserPropertyID property,
1541 DataBrowserItemDataRef itemData,
1542 bool changeValue )
1543 {
1544 OSStatus err = errDataBrowserPropertyNotSupported;
1545 if ( !changeValue )
1546 {
1547 if ( property >= kMinColumnId ){
1548 short listColumn = property - kMinColumnId;
1549
1550 if (HasColumnInfo(listColumn)){
1551 wxListItem* item = GetColumnInfo(listColumn);
1552 wxMacCFStringHolder cfStr;
1553
1554 if (item->GetText()){
1555 cfStr.Assign( item->GetText(), wxLocale::GetSystemEncoding() );
1556 err = ::SetDataBrowserItemDataText( itemData, cfStr );
1557 err = noErr;
1558 }
1559
1560 int imgIndex = item->GetImage();
1561 if ( (item->GetMask() & wxLIST_MASK_IMAGE) ){
1562 wxListCtrl* list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
1563 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
1564 if (imageList && imageList->GetImageCount() > 0){
1565 wxBitmap bmp = imageList->GetBitmap(imgIndex);
1566 IconRef icon = bmp.GetBitmapData()->GetIconRef();
1567 ::SetDataBrowserItemDataIcon(itemData, icon);
1568 }
1569 }
1570
1571 }
1572 }
1573 }
1574 else
1575 {
1576 switch (property)
1577 {
1578 // no editable props here
1579 default:
1580 break;
1581 }
1582 }
1583
1584 // don't duplicate the numeric order column handling
1585 if (err == errDataBrowserPropertyNotSupported)
1586 err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue);
1587
1588 return err;
1589 }
1590
1591 #endif // wxUSE_LISTCTRL