]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
recognize CP866 (bug 1497808)
[wxWidgets.git] / src / mac / carbon / listctrl_mac.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.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 #include "wx/listctrl.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/intl.h"
33 #endif
34
35 #include "wx/mac/uma.h"
36
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
39 #include "wx/timer.h"
40
41 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
42
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListCtrlStyle )
45
46 wxBEGIN_FLAGS( wxListCtrlStyle )
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
52 wxFLAGS_MEMBER(wxBORDER_RAISED)
53 wxFLAGS_MEMBER(wxBORDER_STATIC)
54 wxFLAGS_MEMBER(wxBORDER_NONE)
55
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
60 wxFLAGS_MEMBER(wxRAISED_BORDER)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER)
62 wxFLAGS_MEMBER(wxBORDER)
63
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
68 wxFLAGS_MEMBER(wxWANTS_CHARS)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
71 wxFLAGS_MEMBER(wxVSCROLL)
72 wxFLAGS_MEMBER(wxHSCROLL)
73
74 wxFLAGS_MEMBER(wxLC_LIST)
75 wxFLAGS_MEMBER(wxLC_REPORT)
76 wxFLAGS_MEMBER(wxLC_ICON)
77 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
78 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
79 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
80 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
81 wxFLAGS_MEMBER(wxLC_USER_TEXT)
82 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
83 wxFLAGS_MEMBER(wxLC_NO_HEADER)
84 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
85 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
86 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
87 wxFLAGS_MEMBER(wxLC_VIRTUAL)
88
89 wxEND_FLAGS( wxListCtrlStyle )
90
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
92
93 wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
94 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
95
96 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
98
99 wxBEGIN_HANDLERS_TABLE(wxListCtrl)
100 wxEND_HANDLERS_TABLE()
101
102 wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
103
104 /*
105 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
106 */
107 #else
108 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
109 #endif
110
111 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
112 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
113
114 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
115
116 WX_DECLARE_EXPORTED_LIST(wxListItem, wxListItemList);
117 #include "wx/listimpl.cpp"
118 WX_DEFINE_LIST(wxListItemList)
119 WX_DEFINE_LIST(wxColumnList)
120
121 // so we can check for column clicks
122 static const EventTypeSpec eventList[] =
123 {
124 { kEventClassControl, kEventControlHit },
125 { kEventClassControl, kEventControlDraw }
126 };
127
128 static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
129 {
130 OSStatus result = eventNotHandledErr ;
131
132 wxMacCarbonEvent cEvent( event ) ;
133
134 ControlRef controlRef ;
135 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
136
137 wxListCtrl *window = (wxListCtrl*) data ;
138 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, window->GetId() );
139 le.SetEventObject( window );
140
141 switch ( GetEventKind( event ) )
142 {
143 // check if the column was clicked on and fire an event if so
144 case kEventControlHit :
145 {
146 ControlPartCode result = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) ;
147 if (result == kControlButtonPart){
148 DataBrowserPropertyID col;
149 GetDataBrowserSortProperty(controlRef, &col);
150 int column = col - kMinColumnId;
151 le.m_col = column;
152 window->GetEventHandler()->ProcessEvent( le );
153 }
154 result = CallNextEventHandler(handler, event);
155 break;
156 }
157 case kEventControlDraw:
158 {
159 CGContextRef context = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, typeCGContextRef) ;
160 window->MacSetDrawingContext(context);
161 result = CallNextEventHandler(handler, event);
162 window->MacSetDrawingContext(NULL);
163 break;
164 }
165 default :
166 break ;
167 }
168
169
170 return result ;
171 }
172
173 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler )
174
175 class wxMacListCtrlItem : public wxMacListBoxItem
176 {
177 public:
178 wxMacListCtrlItem();
179
180 virtual void Notification(wxMacDataItemBrowserControl *owner ,
181 DataBrowserItemNotification message,
182 DataBrowserItemDataRef itemData ) const;
183
184 virtual void SetColumnInfo( unsigned int column, wxListItem* item );
185 virtual wxListItem* GetColumnInfo( unsigned int column );
186 virtual bool HasColumnInfo( unsigned int column );
187
188 virtual void SetColumnTextValue( unsigned int column, const wxString& text );
189 virtual const wxString& GetColumnTextValue( unsigned int column );
190
191 virtual int GetColumnImageValue( unsigned int column );
192 virtual void SetColumnImageValue( unsigned int column, int imageIndex );
193
194 virtual ~wxMacListCtrlItem();
195 protected:
196 wxListItemList m_rowItems;
197 };
198
199 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP = NULL;
200 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
201 DataBrowserHitTestUPP gDataBrowserHitTestUPP = NULL;
202
203 // TODO: Make a better name!!
204 class wxMacDataBrowserListCtrlControl : public wxMacDataItemBrowserControl
205 {
206 public:
207 wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style );
208 virtual ~wxMacDataBrowserListCtrlControl();
209
210 // create a list item (can be a subclass of wxMacListBoxItem)
211
212 virtual wxMacDataItem* CreateItem();
213
214 virtual void MacInsertItem( unsigned int n, wxListItem* item );
215 virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item );
216 virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item );
217 virtual void UpdateState(wxMacDataItem* dataItem, wxListItem* item);
218
219 protected:
220 // we need to override to provide specialized handling for virtual wxListCtrls
221 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
222 DataBrowserPropertyID property,
223 DataBrowserItemDataRef itemData,
224 Boolean changeValue );
225
226 virtual void ItemNotification(
227 DataBrowserItemID itemID,
228 DataBrowserItemNotification message,
229 DataBrowserItemDataRef itemData);
230
231 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
232 DataBrowserItemID itemTwoID,
233 DataBrowserPropertyID sortProperty);
234
235 static pascal void DataBrowserDrawItemProc(ControlRef browser,
236 DataBrowserItemID item,
237 DataBrowserPropertyID property,
238 DataBrowserItemState itemState,
239 const Rect *theRect,
240 SInt16 gdDepth,
241 Boolean colorDevice);
242
243 virtual void DrawItem(DataBrowserItemID itemID,
244 DataBrowserPropertyID property,
245 DataBrowserItemState itemState,
246 const Rect *itemRect,
247 SInt16 gdDepth,
248 Boolean colorDevice);
249
250 static pascal Boolean DataBrowserEditTextProc(ControlRef browser,
251 DataBrowserItemID item,
252 DataBrowserPropertyID property,
253 CFStringRef theString,
254 Rect *maxEditTextRect,
255 Boolean *shrinkToFit);
256
257 static pascal Boolean DataBrowserHitTestProc(ControlRef browser,
258 DataBrowserItemID itemID,
259 DataBrowserPropertyID property,
260 const Rect *theRect,
261 const Rect *mouseRect) { return true; }
262
263 virtual bool ConfirmEditText(DataBrowserItemID item,
264 DataBrowserPropertyID property,
265 CFStringRef theString,
266 Rect *maxEditTextRect,
267 Boolean *shrinkToFit);
268
269
270
271 wxClientDataType m_clientDataItemsType;
272 bool m_isVirtual;
273
274 };
275
276 class wxMacListCtrlEventDelegate : public wxEvtHandler
277 {
278 public:
279 wxMacListCtrlEventDelegate( wxListCtrl* list, int id );
280 virtual bool ProcessEvent( wxEvent& event );
281
282 private:
283 wxListCtrl* m_list;
284 int m_id;
285 };
286
287 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl* list, int id )
288 {
289 m_list = list;
290 m_id = id;
291 }
292
293 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event )
294 {
295 // even though we use a generic list ctrl underneath, make sure
296 // we present ourselves as wxListCtrl.
297 event.SetEventObject( m_list );
298 event.SetId( m_id );
299
300 if ( !event.IsKindOf( CLASSINFO( wxCommandEvent ) ) )
301 {
302 if (m_list->GetEventHandler()->ProcessEvent( event ))
303 return true;
304 }
305 return wxEvtHandler::ProcessEvent(event);
306 }
307
308 //-----------------------------------------------------------------------------
309 // wxListCtrlRenameTimer (internal)
310 //-----------------------------------------------------------------------------
311
312 class wxListCtrlRenameTimer: public wxTimer
313 {
314 private:
315 wxListCtrl *m_owner;
316
317 public:
318 wxListCtrlRenameTimer( wxListCtrl *owner );
319 void Notify();
320 };
321
322 //-----------------------------------------------------------------------------
323 // wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
324 //-----------------------------------------------------------------------------
325
326 class wxListCtrlTextCtrlWrapper : public wxEvtHandler
327 {
328 public:
329 // NB: text must be a valid object but not Create()d yet
330 wxListCtrlTextCtrlWrapper(wxListCtrl *owner,
331 wxTextCtrl *text,
332 long itemEdit);
333
334 wxTextCtrl *GetText() const { return m_text; }
335
336 void AcceptChangesAndFinish();
337
338 protected:
339 void OnChar( wxKeyEvent &event );
340 void OnKeyUp( wxKeyEvent &event );
341 void OnKillFocus( wxFocusEvent &event );
342
343 bool AcceptChanges();
344 void Finish();
345
346 private:
347 wxListCtrl *m_owner;
348 wxTextCtrl *m_text;
349 wxString m_startValue;
350 long m_itemEdited;
351 bool m_finished;
352 bool m_aboutToFinish;
353
354 DECLARE_EVENT_TABLE()
355 };
356
357 //-----------------------------------------------------------------------------
358 // wxListCtrlRenameTimer (internal)
359 //-----------------------------------------------------------------------------
360
361 wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl *owner )
362 {
363 m_owner = owner;
364 }
365
366 void wxListCtrlRenameTimer::Notify()
367 {
368 m_owner->OnRenameTimer();
369 }
370
371 //-----------------------------------------------------------------------------
372 // wxListCtrlTextCtrlWrapper (internal)
373 //-----------------------------------------------------------------------------
374
375 BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper, wxEvtHandler)
376 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar)
377 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp)
378 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus)
379 END_EVENT_TABLE()
380
381 wxListCtrlTextCtrlWrapper::wxListCtrlTextCtrlWrapper(wxListCtrl *owner,
382 wxTextCtrl *text,
383 long itemEdit)
384 : m_startValue(owner->GetItemText(itemEdit)),
385 m_itemEdited(itemEdit)
386 {
387 m_owner = owner;
388 m_text = text;
389 m_finished = false;
390 m_aboutToFinish = false;
391
392 wxRect rectLabel;
393 owner->GetItemRect(itemEdit, rectLabel);
394
395 m_text->Create(owner, wxID_ANY, m_startValue,
396 wxPoint(rectLabel.x+8,rectLabel.y),
397 wxSize(rectLabel.width,rectLabel.height));
398 m_text->SetFocus();
399
400 m_text->PushEventHandler(this);
401 }
402
403 void wxListCtrlTextCtrlWrapper::Finish()
404 {
405 if ( !m_finished )
406 {
407 m_finished = true;
408
409 m_text->RemoveEventHandler(this);
410 m_owner->FinishEditing(m_text);
411
412 wxPendingDelete.Append( this );
413 }
414 }
415
416 bool wxListCtrlTextCtrlWrapper::AcceptChanges()
417 {
418 const wxString value = m_text->GetValue();
419
420 if ( value == m_startValue )
421 // nothing changed, always accept
422 return true;
423
424 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
425 // vetoed by the user
426 return false;
427
428 // accepted, do rename the item
429 m_owner->SetItemText(m_itemEdited, value);
430
431 return true;
432 }
433
434 void wxListCtrlTextCtrlWrapper::AcceptChangesAndFinish()
435 {
436 m_aboutToFinish = true;
437
438 // Notify the owner about the changes
439 AcceptChanges();
440
441 // Even if vetoed, close the control (consistent with MSW)
442 Finish();
443 }
444
445 void wxListCtrlTextCtrlWrapper::OnChar( wxKeyEvent &event )
446 {
447 switch ( event.m_keyCode )
448 {
449 case WXK_RETURN:
450 AcceptChangesAndFinish();
451 break;
452
453 case WXK_ESCAPE:
454 m_owner->OnRenameCancelled( m_itemEdited );
455 Finish();
456 break;
457
458 default:
459 event.Skip();
460 }
461 }
462
463 void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
464 {
465 if (m_finished)
466 {
467 event.Skip();
468 return;
469 }
470
471 // auto-grow the textctrl:
472 wxSize parentSize = m_owner->GetSize();
473 wxPoint myPos = m_text->GetPosition();
474 wxSize mySize = m_text->GetSize();
475 int sx, sy;
476 m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy);
477 if (myPos.x + sx > parentSize.x)
478 sx = parentSize.x - myPos.x;
479 if (mySize.x > sx)
480 sx = mySize.x;
481 m_text->SetSize(sx, wxDefaultCoord);
482
483 event.Skip();
484 }
485
486 void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
487 {
488 if ( !m_finished && !m_aboutToFinish )
489 {
490 if ( !AcceptChanges() )
491 m_owner->OnRenameCancelled( m_itemEdited );
492
493 Finish();
494 }
495
496 // We must let the native text control handle focus
497 event.Skip();
498 }
499
500 BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
501 EVT_LEFT_DOWN(wxListCtrl::OnLeftDown)
502 EVT_LEFT_DCLICK(wxListCtrl::OnDblClick)
503 END_EVENT_TABLE()
504
505 // ============================================================================
506 // implementation
507 // ============================================================================
508
509 wxMacListControl* wxListCtrl::GetPeer() const
510 {
511 return dynamic_cast<wxMacListControl*>(m_peer);
512 }
513
514 // ----------------------------------------------------------------------------
515 // wxListCtrl construction
516 // ----------------------------------------------------------------------------
517
518 void wxListCtrl::Init()
519 {
520 m_imageListNormal = NULL;
521 m_imageListSmall = NULL;
522 m_imageListState = NULL;
523
524 // keep track of if we created our own image lists, or if they were assigned
525 // to us.
526 m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = false;
527 m_colCount = 0;
528 m_count = 0;
529 m_textCtrl = NULL;
530 m_genericImpl = NULL;
531 m_dbImpl = NULL;
532 m_compareFunc = NULL;
533 m_compareFuncData = 0;
534 m_colsInfo = wxColumnList();
535 m_textColor = wxNullColour;
536 m_bgColor = wxNullColour;
537 m_textctrlWrapper = NULL;
538 m_current = -1;
539 m_renameTimer = new wxListCtrlRenameTimer( this );
540 }
541
542 class wxGenericListCtrlHook : public wxGenericListCtrl
543 {
544 public:
545 wxGenericListCtrlHook(wxListCtrl* parent,
546 wxWindowID id,
547 const wxPoint& pos,
548 const wxSize& size,
549 long style,
550 const wxValidator& validator,
551 const wxString& name)
552 : wxGenericListCtrl(parent, id, pos, size, style, validator, name),
553 m_nativeListCtrl(parent)
554 {
555 }
556
557 protected:
558 virtual wxListItemAttr * OnGetItemAttr(long item) const
559 {
560 return m_nativeListCtrl->OnGetItemAttr(item);
561 }
562
563 virtual int OnGetItemImage(long item) const
564 {
565 return m_nativeListCtrl->OnGetItemImage(item);
566 }
567
568 virtual int OnGetItemColumnImage(long item, long column) const
569 {
570 return m_nativeListCtrl->OnGetItemColumnImage(item, column);
571 }
572
573 virtual wxString OnGetItemText(long item, long column) const
574 {
575 return m_nativeListCtrl->OnGetItemText(item, column);
576 }
577
578 wxListCtrl* m_nativeListCtrl;
579
580 };
581
582 void wxListCtrl::OnLeftDown(wxMouseEvent& event)
583 {
584 if ( m_textctrlWrapper )
585 {
586 m_current = -1;
587 m_textctrlWrapper->AcceptChangesAndFinish();
588 }
589
590 int hitResult;
591 long current = HitTest(event.GetPosition(), hitResult);
592 if ((current == m_current) &&
593 (hitResult == wxLIST_HITTEST_ONITEM) &&
594 HasFlag(wxLC_EDIT_LABELS) )
595 {
596 m_renameTimer->Start( 100, true );
597 }
598 else
599 {
600 m_current = current;
601 }
602 event.Skip();
603 }
604
605 void wxListCtrl::OnDblClick(wxMouseEvent& event)
606 {
607 m_current = -1;
608 event.Skip();
609 }
610
611 bool wxListCtrl::Create(wxWindow *parent,
612 wxWindowID id,
613 const wxPoint& pos,
614 const wxSize& size,
615 long style,
616 const wxValidator& validator,
617 const wxString& name)
618 {
619
620 // for now, we'll always use the generic list control for ICON and LIST views,
621 // because they dynamically change the number of columns on resize.
622 // Also, allow the user to set it to use the list ctrl as well.
623 // Also, use generic list control in VIRTUAL mode.
624 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL )
625 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) ||
626 (style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST) )
627 {
628 m_macIsUserPane = true;
629
630 if ( !wxWindow::Create(parent, id, pos, size, style & wxNO_BORDER, name) )
631 return false;
632 m_genericImpl = new wxGenericListCtrlHook(this, id, pos, size, style, validator, name);
633 m_genericImpl->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
634 return true;
635 }
636
637 else
638 {
639 m_macIsUserPane = false;
640
641 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
642 return false;
643 m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style );
644 m_peer = m_dbImpl;
645
646 MacPostControlCreate( pos, size );
647
648 InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
649 GetEventTypeCount(eventList), eventList, this,
650 (EventHandlerRef *)&m_macListCtrlEventHandler);
651 }
652
653 return true;
654 }
655
656 wxListCtrl::~wxListCtrl()
657 {
658 if (m_genericImpl)
659 {
660 m_genericImpl->PopEventHandler(/* deleteHandler = */ true);
661 }
662
663 if (m_ownsImageListNormal)
664 delete m_imageListNormal;
665 if (m_ownsImageListSmall)
666 delete m_imageListSmall;
667 if (m_ownsImageListState)
668 delete m_imageListState;
669
670 delete m_renameTimer;
671 }
672
673 // ----------------------------------------------------------------------------
674 // set/get/change style
675 // ----------------------------------------------------------------------------
676
677 // Add or remove a single window style
678 void wxListCtrl::SetSingleStyle(long style, bool add)
679 {
680 long flag = GetWindowStyleFlag();
681
682 // Get rid of conflicting styles
683 if ( add )
684 {
685 if ( style & wxLC_MASK_TYPE)
686 flag = flag & ~wxLC_MASK_TYPE;
687 if ( style & wxLC_MASK_ALIGN )
688 flag = flag & ~wxLC_MASK_ALIGN;
689 if ( style & wxLC_MASK_SORT )
690 flag = flag & ~wxLC_MASK_SORT;
691 }
692
693 if ( add )
694 flag |= style;
695 else
696 flag &= ~style;
697
698 SetWindowStyleFlag(flag);
699 }
700
701 // Set the whole window style
702 void wxListCtrl::SetWindowStyleFlag(long flag)
703 {
704 if ( flag != m_windowStyle )
705 {
706 m_windowStyle = flag;
707
708 if (m_genericImpl)
709 {
710 m_genericImpl->SetWindowStyleFlag(flag);
711 }
712
713 Refresh();
714 }
715 }
716
717 void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags )
718 {
719 wxControl::DoSetSize(x, y, width, height, sizeFlags);
720
721 if (m_genericImpl)
722 m_genericImpl->SetSize(x, y, width, height, sizeFlags);
723 }
724
725 wxSize wxListCtrl::DoGetBestSize() const
726 {
727 if (m_genericImpl)
728 return m_genericImpl->GetBestSize();
729
730 return wxWindow::DoGetBestSize();
731 }
732
733 bool wxListCtrl::SetFont(const wxFont& font)
734 {
735 bool rv = true;
736 rv = wxControl::SetFont(font);
737 if (m_genericImpl)
738 rv = m_genericImpl->SetFont(font);
739 return rv;
740 }
741
742 bool wxListCtrl::SetForegroundColour(const wxColour& colour)
743 {
744 bool rv = true;
745 if (m_genericImpl)
746 rv = m_genericImpl->SetForegroundColour(colour);
747 if (m_dbImpl)
748 SetTextColour(colour);
749 return rv;
750 }
751
752 bool wxListCtrl::SetBackgroundColour(const wxColour& colour)
753 {
754 bool rv = true;
755 if (m_genericImpl)
756 rv = m_genericImpl->SetBackgroundColour(colour);
757 if (m_dbImpl)
758 m_bgColor = colour;
759 return rv;
760 }
761
762 wxColour wxListCtrl::GetBackgroundColour()
763 {
764 if (m_genericImpl)
765 return m_genericImpl->GetBackgroundColour();
766 if (m_dbImpl)
767 return m_bgColor;
768
769 return wxNullColour;
770 }
771
772 // ----------------------------------------------------------------------------
773 // accessors
774 // ----------------------------------------------------------------------------
775
776 // Gets information about this column
777 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
778 {
779 if (m_genericImpl)
780 return m_genericImpl->GetColumn(col, item);
781
782 bool success = true;
783
784 if (m_dbImpl)
785 {
786
787 wxColumnList::compatibility_iterator node = m_colsInfo.Item( col );
788 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
789 wxListItem* column = node->GetData();
790
791 long mask = column->GetMask();
792 if (mask & wxLIST_MASK_TEXT)
793 item.SetText(column->GetText());
794 if (mask & wxLIST_MASK_DATA)
795 item.SetData(column->GetData());
796 if (mask & wxLIST_MASK_IMAGE)
797 item.SetImage(column->GetImage());
798 if (mask & wxLIST_MASK_STATE)
799 item.SetState(column->GetState());
800 if (mask & wxLIST_MASK_FORMAT)
801 item.SetAlign(column->GetAlign());
802 if (mask & wxLIST_MASK_WIDTH)
803 item.SetWidth(column->GetWidth());
804 }
805
806 return success;
807 }
808
809 // Sets information about this column
810 bool wxListCtrl::SetColumn(int col, wxListItem& item)
811 {
812 if (m_genericImpl)
813 return m_genericImpl->SetColumn(col, item);
814
815 if (m_dbImpl)
816 {
817 if ( col >= (int)m_colsInfo.GetCount() )
818 {
819 wxListItem* listItem = new wxListItem(item);
820 m_colsInfo.Append( listItem );
821 }
822 else
823 {
824 wxListItem listItem;
825 GetColumn( col, listItem );
826 long mask = item.GetMask();
827 if (mask & wxLIST_MASK_TEXT)
828 listItem.SetText(item.GetText());
829 if (mask & wxLIST_MASK_DATA)
830 listItem.SetData(item.GetData());
831 if (mask & wxLIST_MASK_IMAGE)
832 listItem.SetImage(item.GetImage());
833 if (mask & wxLIST_MASK_STATE)
834 listItem.SetState(item.GetState());
835 if (mask & wxLIST_MASK_FORMAT)
836 listItem.SetAlign(item.GetAlign());
837 if (mask & wxLIST_MASK_WIDTH)
838 listItem.SetWidth(item.GetWidth());
839 }
840
841 // change the appearance in the databrowser.
842 DataBrowserListViewHeaderDesc columnDesc;
843 columnDesc.version=kDataBrowserListViewLatestHeaderDesc;
844 verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) );
845
846 /*
847 if (item.GetMask() & wxLIST_MASK_TEXT)
848 {
849 wxFontEncoding enc;
850 if ( m_font.Ok() )
851 enc = m_font.GetEncoding();
852 else
853 enc = wxLocale::GetSystemEncoding();
854 wxMacCFStringHolder cfTitle;
855 cfTitle.Assign( item.GetText() , enc );
856 if(columnDesc.titleString)
857 CFRelease(columnDesc.titleString);
858 columnDesc.titleString = cfTitle;
859 }
860 */
861
862 if (item.GetMask() & wxLIST_MASK_IMAGE && item.GetImage() != -1 )
863 {
864 columnDesc.btnContentInfo.contentType = kControlContentIconRef;
865 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
866 if (imageList && imageList->GetImageCount() > 0 )
867 {
868 wxBitmap bmp = imageList->GetBitmap( item.GetImage() );
869 IconRef icon = bmp.GetBitmapData()->GetIconRef();
870 columnDesc.btnContentInfo.u.iconRef = icon;
871 }
872 }
873
874 verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) );
875
876 }
877 return true;
878 }
879
880 int wxListCtrl::GetColumnCount() const
881 {
882 if (m_genericImpl)
883 return m_genericImpl->GetColumnCount();
884
885 if (m_dbImpl)
886 {
887 UInt32 count;
888 m_dbImpl->GetColumnCount(&count);
889 return count;
890 }
891
892 return m_colCount;
893 }
894
895 // Gets the column width
896 int wxListCtrl::GetColumnWidth(int col) const
897 {
898 if (m_genericImpl)
899 return m_genericImpl->GetColumnWidth(col);
900
901 if (m_dbImpl)
902 {
903 return m_dbImpl->GetColumnWidth(col);
904 }
905
906 return 0;
907 }
908
909 // Sets the column width
910 bool wxListCtrl::SetColumnWidth(int col, int width)
911 {
912 if (m_genericImpl)
913 return m_genericImpl->SetColumnWidth(col, width);
914
915 if (m_dbImpl)
916 {
917 int mywidth = width;
918 if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER)
919 mywidth = 150;
920
921 if (col == -1)
922 {
923 for (int column = 0; column < GetColumnCount(); column++)
924 {
925 m_dbImpl->SetColumnWidth(col, mywidth);
926 }
927 }
928 else{
929 m_dbImpl->SetColumnWidth(col, mywidth);
930 }
931 return true;
932 }
933
934 return false;
935 }
936
937 // Gets the number of items that can fit vertically in the
938 // visible area of the list control (list or report view)
939 // or the total number of items in the list control (icon
940 // or small icon view)
941 int wxListCtrl::GetCountPerPage() const
942 {
943 if (m_genericImpl)
944 return m_genericImpl->GetCountPerPage();
945
946 if (m_dbImpl)
947 {
948 }
949
950 return 1;
951 }
952
953 // Gets the edit control for editing labels.
954 wxTextCtrl* wxListCtrl::GetEditControl() const
955 {
956 if (m_genericImpl)
957 return m_genericImpl->GetEditControl();
958
959 return NULL;
960 }
961
962 // Gets information about the item
963 bool wxListCtrl::GetItem(wxListItem& info) const
964 {
965 if (m_genericImpl)
966 return m_genericImpl->GetItem(info);
967
968 if (m_dbImpl)
969 {
970 if (!IsVirtual())
971 m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info);
972 else
973 {
974 info.SetText( OnGetItemText(info.m_itemId, info.m_col) );
975 info.SetImage( OnGetItemColumnImage(info.m_itemId, info.m_col) );
976 wxListItemAttr* attrs = OnGetItemAttr( info.m_itemId );
977 if (attrs)
978 {
979 info.SetFont( attrs->GetFont() );
980 info.SetBackgroundColour( attrs->GetBackgroundColour() );
981 info.SetTextColour( attrs->GetTextColour() );
982 }
983 }
984 }
985 bool success = true;
986 return success;
987 }
988
989 // Sets information about the item
990 bool wxListCtrl::SetItem(wxListItem& info)
991 {
992 if (m_genericImpl)
993 return m_genericImpl->SetItem(info);
994
995 if (m_dbImpl)
996 m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info );
997
998 return true;
999 }
1000
1001 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
1002 {
1003 if (m_genericImpl)
1004 return m_genericImpl->SetItem(index, col, label, imageId);
1005
1006 wxListItem info;
1007 info.m_text = label;
1008 info.m_mask = wxLIST_MASK_TEXT;
1009 info.m_itemId = index;
1010 info.m_col = col;
1011 if ( imageId > -1 )
1012 {
1013 info.m_image = imageId;
1014 info.m_mask |= wxLIST_MASK_IMAGE;
1015 }
1016 return SetItem(info);
1017 }
1018
1019
1020 // Gets the item state
1021 int wxListCtrl::GetItemState(long item, long stateMask) const
1022 {
1023 if (m_genericImpl)
1024 return m_genericImpl->GetItemState(item, stateMask);
1025
1026 wxListItem info;
1027
1028 info.m_mask = wxLIST_MASK_STATE;
1029 info.m_stateMask = stateMask;
1030 info.m_itemId = item;
1031
1032 if (!GetItem(info))
1033 return 0;
1034
1035 return info.m_state;
1036 }
1037
1038 // Sets the item state
1039 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
1040 {
1041 if (m_genericImpl)
1042 return m_genericImpl->SetItemState(item, state, stateMask);
1043
1044 wxListItem info;
1045 info.m_mask = wxLIST_MASK_STATE;
1046 info.m_stateMask = stateMask;
1047 info.m_state = state;
1048 info.m_itemId = item;
1049 return SetItem(info);
1050 }
1051
1052 // Sets the item image
1053 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
1054 {
1055 return SetItemColumnImage(item, 0, image);
1056 }
1057
1058 // Sets the item image
1059 bool wxListCtrl::SetItemColumnImage(long item, long column, int image)
1060 {
1061 if (m_genericImpl)
1062 return m_genericImpl->SetItemColumnImage(item, column, image);
1063
1064 wxListItem info;
1065
1066 info.m_mask = wxLIST_MASK_IMAGE;
1067 info.m_image = image;
1068 info.m_itemId = item;
1069 info.m_col = column;
1070
1071 return SetItem(info);
1072 }
1073
1074 // Gets the item text
1075 wxString wxListCtrl::GetItemText(long item) const
1076 {
1077 if (m_genericImpl)
1078 return m_genericImpl->GetItemText(item);
1079
1080 wxListItem info;
1081
1082 info.m_mask = wxLIST_MASK_TEXT;
1083 info.m_itemId = item;
1084
1085 if (!GetItem(info))
1086 return wxEmptyString;
1087 return info.m_text;
1088 }
1089
1090 // Sets the item text
1091 void wxListCtrl::SetItemText(long item, const wxString& str)
1092 {
1093 if (m_genericImpl)
1094 return m_genericImpl->SetItemText(item, str);
1095
1096 wxListItem info;
1097
1098 info.m_mask = wxLIST_MASK_TEXT;
1099 info.m_itemId = item;
1100 info.m_text = str;
1101
1102 SetItem(info);
1103 }
1104
1105 // Gets the item data
1106 long wxListCtrl::GetItemData(long item) const
1107 {
1108 if (m_genericImpl)
1109 return m_genericImpl->GetItemData(item);
1110
1111 wxListItem info;
1112
1113 info.m_mask = wxLIST_MASK_DATA;
1114 info.m_itemId = item;
1115
1116 if (!GetItem(info))
1117 return 0;
1118 return info.m_data;
1119 }
1120
1121 // Sets the item data
1122 bool wxListCtrl::SetItemData(long item, long data)
1123 {
1124 if (m_genericImpl)
1125 return m_genericImpl->SetItemData(item, data);
1126
1127 wxListItem info;
1128
1129 info.m_mask = wxLIST_MASK_DATA;
1130 info.m_itemId = item;
1131 info.m_data = data;
1132
1133 return SetItem(info);
1134 }
1135
1136 wxRect wxListCtrl::GetViewRect() const
1137 {
1138 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
1139 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1140
1141 if (m_genericImpl)
1142 return m_genericImpl->GetViewRect();
1143
1144 wxRect rect;
1145 return rect;
1146 }
1147
1148 // Gets the item rectangle
1149 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
1150 {
1151 if (m_genericImpl)
1152 return m_genericImpl->GetItemRect(item, rect, code);
1153
1154
1155 if (m_dbImpl)
1156 {
1157 DataBrowserItemID id;
1158 DataBrowserPropertyID col = kMinColumnId;
1159 Rect bounds;
1160 DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart;
1161 if ( code == wxLIST_RECT_LABEL )
1162 part = kDataBrowserPropertyTextPart;
1163 else if ( code == wxLIST_RECT_ICON )
1164 part = kDataBrowserPropertyIconPart;
1165
1166 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL) )
1167 {
1168 wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item);
1169 id = (DataBrowserItemID) thisItem;
1170 }
1171 else
1172 id = item;
1173
1174 GetDataBrowserItemPartBounds( m_dbImpl->GetControlRef(), id, col, part, &bounds );
1175
1176 rect.x = bounds.left;
1177 rect.y = bounds.top;
1178 rect.width = bounds.right - bounds.left; //GetClientSize().x; // we need the width of the whole row, not just the item.
1179 rect.height = bounds.bottom - bounds.top;
1180 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1181 }
1182 return true;
1183 }
1184
1185 // Gets the item position
1186 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
1187 {
1188 if (m_genericImpl)
1189 return m_genericImpl->GetItemPosition(item, pos);
1190
1191 bool success = false;
1192
1193 if (m_dbImpl)
1194 {
1195 wxRect itemRect;
1196 GetItemRect(item, itemRect);
1197 pos = itemRect.GetPosition();
1198 success = true;
1199 }
1200
1201 return success;
1202 }
1203
1204 // Sets the item position.
1205 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
1206 {
1207 if (m_genericImpl)
1208 return m_genericImpl->SetItemPosition(item, pos);
1209
1210 return false;
1211 }
1212
1213 // Gets the number of items in the list control
1214 int wxListCtrl::GetItemCount() const
1215 {
1216 if (m_genericImpl)
1217 return m_genericImpl->GetItemCount();
1218
1219 if (m_dbImpl)
1220 return m_dbImpl->MacGetCount();
1221
1222 return m_count;
1223 }
1224
1225 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
1226 {
1227 if (m_genericImpl)
1228 m_genericImpl->SetItemSpacing(spacing, isSmall);
1229 }
1230
1231 wxSize wxListCtrl::GetItemSpacing() const
1232 {
1233 if (m_genericImpl)
1234 return m_genericImpl->GetItemSpacing();
1235
1236 return wxSize(0, 0);
1237 }
1238
1239 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
1240 {
1241 if (m_genericImpl)
1242 {
1243 m_genericImpl->SetItemTextColour(item, col);
1244 return;
1245 }
1246
1247 wxListItem info;
1248 info.m_itemId = item;
1249 info.SetTextColour( col );
1250 SetItem( info );
1251 }
1252
1253 wxColour wxListCtrl::GetItemTextColour( long item ) const
1254 {
1255 if (m_genericImpl)
1256 return m_genericImpl->GetItemTextColour(item);
1257
1258 if (m_dbImpl)
1259 {
1260 wxListItem info;
1261 if (GetItem(info))
1262 return info.GetTextColour();
1263 }
1264 return wxNullColour;
1265 }
1266
1267 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
1268 {
1269 if (m_genericImpl)
1270 {
1271 m_genericImpl->SetItemBackgroundColour(item, col);
1272 return;
1273 }
1274
1275 wxListItem info;
1276 info.m_itemId = item;
1277 info.SetBackgroundColour( col );
1278 SetItem( info );
1279 }
1280
1281 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
1282 {
1283 if (m_genericImpl)
1284 return m_genericImpl->GetItemBackgroundColour(item);
1285
1286 if (m_dbImpl)
1287 {
1288 wxListItem info;
1289 if (GetItem(info))
1290 return info.GetBackgroundColour();
1291 }
1292 return wxNullColour;
1293 }
1294
1295 void wxListCtrl::SetItemFont( long item, const wxFont &f )
1296 {
1297 if (m_genericImpl)
1298 {
1299 m_genericImpl->SetItemFont(item, f);
1300 return;
1301 }
1302
1303 wxListItem info;
1304 info.m_itemId = item;
1305 info.SetFont( f );
1306 SetItem( info );
1307 }
1308
1309 wxFont wxListCtrl::GetItemFont( long item ) const
1310 {
1311 if (m_genericImpl)
1312 return m_genericImpl->GetItemFont(item);
1313
1314 if (m_dbImpl)
1315 {
1316 wxListItem info;
1317 if (GetItem(info))
1318 return info.GetFont();
1319 }
1320
1321 return wxNullFont;
1322 }
1323
1324 // Gets the number of selected items in the list control
1325 int wxListCtrl::GetSelectedItemCount() const
1326 {
1327 if (m_genericImpl)
1328 return m_genericImpl->GetSelectedItemCount();
1329
1330 if (m_dbImpl)
1331 return m_dbImpl->GetSelectedItemCount(NULL, true);
1332
1333 return 0;
1334 }
1335
1336 // Gets the text colour of the listview
1337 wxColour wxListCtrl::GetTextColour() const
1338 {
1339 if (m_genericImpl)
1340 return m_genericImpl->GetTextColour();
1341
1342 // TODO: we need owner drawn list items to customize text color.
1343 if (m_dbImpl)
1344 return m_textColor;
1345
1346 return wxNullColour;
1347 }
1348
1349 // Sets the text colour of the listview
1350 void wxListCtrl::SetTextColour(const wxColour& col)
1351 {
1352 if (m_genericImpl)
1353 {
1354 m_genericImpl->SetTextColour(col);
1355 return;
1356 }
1357
1358 if (m_dbImpl)
1359 m_textColor = col;
1360 }
1361
1362 // Gets the index of the topmost visible item when in
1363 // list or report view
1364 long wxListCtrl::GetTopItem() const
1365 {
1366 if (m_genericImpl)
1367 return m_genericImpl->GetTopItem();
1368
1369 return 0;
1370 }
1371
1372 // Searches for an item, starting from 'item'.
1373 // 'geometry' is one of
1374 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1375 // 'state' is a state bit flag, one or more of
1376 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1377 // item can be -1 to find the first item that matches the
1378 // specified flags.
1379 // Returns the item or -1 if unsuccessful.
1380 long wxListCtrl::GetNextItem(long item, int geom, int state) const
1381 {
1382 if (m_genericImpl)
1383 return m_genericImpl->GetNextItem(item, geom, state);
1384
1385 if (m_dbImpl && geom == wxLIST_NEXT_ALL && state == wxLIST_STATE_SELECTED )
1386 {
1387 long count = m_dbImpl->MacGetCount() ;
1388 for ( long line = item + 1 ; line < count; line++ )
1389 {
1390 wxMacDataItem* id = m_dbImpl->GetItemFromLine(line);
1391 if ( m_dbImpl->IsItemSelected(id ) )
1392 return line;
1393 }
1394 return -1;
1395 }
1396
1397 return 0;
1398 }
1399
1400
1401 wxImageList *wxListCtrl::GetImageList(int which) const
1402 {
1403 if (m_genericImpl)
1404 return m_genericImpl->GetImageList(which);
1405
1406 if ( which == wxIMAGE_LIST_NORMAL )
1407 {
1408 return m_imageListNormal;
1409 }
1410 else if ( which == wxIMAGE_LIST_SMALL )
1411 {
1412 return m_imageListSmall;
1413 }
1414 else if ( which == wxIMAGE_LIST_STATE )
1415 {
1416 return m_imageListState;
1417 }
1418 return NULL;
1419 }
1420
1421 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
1422 {
1423 if (m_genericImpl)
1424 {
1425 m_genericImpl->SetImageList(imageList, which);
1426 return;
1427 }
1428
1429 if ( which == wxIMAGE_LIST_NORMAL )
1430 {
1431 if (m_ownsImageListNormal) delete m_imageListNormal;
1432 m_imageListNormal = imageList;
1433 m_ownsImageListNormal = false;
1434 }
1435 else if ( which == wxIMAGE_LIST_SMALL )
1436 {
1437 if (m_ownsImageListSmall) delete m_imageListSmall;
1438 m_imageListSmall = imageList;
1439 m_ownsImageListSmall = false;
1440 }
1441 else if ( which == wxIMAGE_LIST_STATE )
1442 {
1443 if (m_ownsImageListState) delete m_imageListState;
1444 m_imageListState = imageList;
1445 m_ownsImageListState = false;
1446 }
1447 }
1448
1449 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1450 {
1451 if (m_genericImpl)
1452 {
1453 m_genericImpl->AssignImageList(imageList, which);
1454 return;
1455 }
1456
1457 SetImageList(imageList, which);
1458 if ( which == wxIMAGE_LIST_NORMAL )
1459 m_ownsImageListNormal = true;
1460 else if ( which == wxIMAGE_LIST_SMALL )
1461 m_ownsImageListSmall = true;
1462 else if ( which == wxIMAGE_LIST_STATE )
1463 m_ownsImageListState = true;
1464 }
1465
1466 // ----------------------------------------------------------------------------
1467 // Operations
1468 // ----------------------------------------------------------------------------
1469
1470 // Arranges the items
1471 bool wxListCtrl::Arrange(int flag)
1472 {
1473 if (m_genericImpl)
1474 return m_genericImpl->Arrange(flag);
1475 return false;
1476 }
1477
1478 // Deletes an item
1479 bool wxListCtrl::DeleteItem(long item)
1480 {
1481 if (m_genericImpl)
1482 return m_genericImpl->DeleteItem(item);
1483
1484 if (m_dbImpl)
1485 {
1486 m_dbImpl->MacDelete(item);
1487 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
1488 event.SetEventObject( this );
1489 event.m_itemIndex = item;
1490 GetEventHandler()->ProcessEvent( event );
1491
1492 }
1493 return true;
1494 }
1495
1496 // Deletes all items
1497 bool wxListCtrl::DeleteAllItems()
1498 {
1499 if (m_genericImpl)
1500 return m_genericImpl->DeleteAllItems();
1501
1502 if (m_dbImpl)
1503 {
1504 m_dbImpl->MacClear();
1505 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
1506 event.SetEventObject( this );
1507 GetEventHandler()->ProcessEvent( event );
1508 }
1509 return true;
1510 }
1511
1512 // Deletes all items
1513 bool wxListCtrl::DeleteAllColumns()
1514 {
1515 if (m_genericImpl)
1516 return m_genericImpl->DeleteAllColumns();
1517
1518 if (m_dbImpl)
1519 {
1520 UInt32 cols;
1521 m_dbImpl->GetColumnCount(&cols);
1522 for (UInt32 col = 0; col < cols; col++)
1523 {
1524 DeleteColumn(col);
1525 }
1526 }
1527
1528 return true;
1529 }
1530
1531 // Deletes a column
1532 bool wxListCtrl::DeleteColumn(int col)
1533 {
1534 if (m_genericImpl)
1535 return m_genericImpl->DeleteColumn(col);
1536
1537 if (m_dbImpl)
1538 {
1539 OSStatus err = m_dbImpl->RemoveColumn(col);
1540 return err == noErr;
1541 }
1542
1543 return true;
1544 }
1545
1546 // Clears items, and columns if there are any.
1547 void wxListCtrl::ClearAll()
1548 {
1549 if (m_genericImpl)
1550 {
1551 m_genericImpl->ClearAll();
1552 return;
1553 }
1554
1555 if (m_dbImpl)
1556 {
1557 DeleteAllItems();
1558 DeleteAllColumns();
1559 }
1560 }
1561
1562 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1563 {
1564 if (m_genericImpl)
1565 return m_genericImpl->EditLabel(item, textControlClass);
1566
1567 if (m_dbImpl)
1568 {
1569 wxCHECK_MSG( (item >= 0) && ((long)item < GetItemCount()), NULL,
1570 wxT("wrong index in wxListCtrl::EditLabel()") );
1571
1572 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
1573 wxT("EditLabel() needs a text control") );
1574
1575 long itemEdit = (long)item;
1576
1577 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1578 le.SetEventObject( this );
1579 le.m_itemIndex = item;
1580 le.m_col = 0;
1581 GetItem( le.m_item );
1582
1583 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
1584 {
1585 // vetoed by user code
1586 return NULL;
1587 }
1588
1589 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
1590 m_textctrlWrapper = new wxListCtrlTextCtrlWrapper(this, text, item);
1591 return m_textctrlWrapper->GetText();
1592 }
1593 return NULL;
1594 }
1595
1596 // End label editing, optionally cancelling the edit
1597 bool wxListCtrl::EndEditLabel(bool cancel)
1598 {
1599 // TODO: generic impl. doesn't have this method - is it needed for us?
1600 if (m_genericImpl)
1601 return true; // m_genericImpl->EndEditLabel(cancel);
1602
1603 if (m_dbImpl)
1604 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) );
1605 return true;
1606 }
1607
1608 // Ensures this item is visible
1609 bool wxListCtrl::EnsureVisible(long item)
1610 {
1611 if (m_genericImpl)
1612 return m_genericImpl->EnsureVisible(item);
1613
1614 if (m_dbImpl)
1615 {
1616 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
1617 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
1618 }
1619
1620 return true;
1621 }
1622
1623 // Find an item whose label matches this string, starting from the item after 'start'
1624 // or the beginning if 'start' is -1.
1625 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1626 {
1627 if (m_genericImpl)
1628 return m_genericImpl->FindItem(start, str, partial);
1629
1630 return -1;
1631 }
1632
1633 // Find an item whose data matches this data, starting from the item after 'start'
1634 // or the beginning if 'start' is -1.
1635 long wxListCtrl::FindItem(long start, long data)
1636 {
1637 if (m_genericImpl)
1638 return m_genericImpl->FindItem(start, data);
1639
1640 long idx = start + 1;
1641 long count = GetItemCount();
1642
1643 while (idx < count)
1644 {
1645 if (GetItemData(idx) == data)
1646 return idx;
1647 idx++;
1648 };
1649
1650 return -1;
1651 }
1652
1653 // Find an item nearest this position in the specified direction, starting from
1654 // the item after 'start' or the beginning if 'start' is -1.
1655 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1656 {
1657 if (m_genericImpl)
1658 return m_genericImpl->FindItem(start, pt, direction);
1659 return -1;
1660 }
1661
1662 // Determines which item (if any) is at the specified point,
1663 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1664 long
1665 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1666 {
1667 if (m_genericImpl)
1668 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1669
1670 flags = wxLIST_HITTEST_NOWHERE;
1671 if (m_dbImpl)
1672 {
1673 int colHeaderHeight = 22; // TODO: Find a way to get this value from the db control?
1674 UInt16 rowHeight = 0;
1675 m_dbImpl->GetDefaultRowHeight(&rowHeight);
1676
1677 int y = point.y;
1678 // get the actual row by taking scroll position into account
1679 UInt32 offsetX, offsetY;
1680 m_dbImpl->GetScrollPosition( &offsetY, &offsetX );
1681 y += offsetY;
1682
1683 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER) )
1684 y -= colHeaderHeight;
1685
1686 int row = y / rowHeight;
1687 DataBrowserItemID id;
1688 m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id );
1689
1690 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1691 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
1692 {
1693 wxMacListCtrlItem* lcItem;
1694 lcItem = (wxMacListCtrlItem*) id;
1695 if (lcItem)
1696 {
1697 flags = wxLIST_HITTEST_ONITEM;
1698 return row;
1699 }
1700 }
1701 else
1702 {
1703 if (row < GetItemCount() )
1704 {
1705 flags = wxLIST_HITTEST_ONITEM;
1706 return row;
1707 }
1708 }
1709
1710 }
1711 return -1;
1712 }
1713
1714
1715 // Inserts an item, returning the index of the new item if successful,
1716 // -1 otherwise.
1717 long wxListCtrl::InsertItem(wxListItem& info)
1718 {
1719 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1720
1721 if (m_genericImpl)
1722 return m_genericImpl->InsertItem(info);
1723
1724 if (m_dbImpl)
1725 {
1726 int count = GetItemCount();
1727
1728 if (info.m_itemId > count)
1729 info.m_itemId = count;
1730
1731 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1732 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1733 event.SetEventObject( this );
1734 event.m_itemIndex = info.m_itemId;
1735 GetEventHandler()->ProcessEvent( event );
1736 }
1737
1738 return info.m_itemId;
1739 }
1740
1741 long wxListCtrl::InsertItem(long index, const wxString& label)
1742 {
1743 if (m_genericImpl)
1744 return m_genericImpl->InsertItem(index, label);
1745
1746 wxListItem info;
1747 info.m_text = label;
1748 info.m_mask = wxLIST_MASK_TEXT;
1749 info.m_itemId = index;
1750 return InsertItem(info);
1751 }
1752
1753 // Inserts an image item
1754 long wxListCtrl::InsertItem(long index, int imageIndex)
1755 {
1756 if (m_genericImpl)
1757 return m_genericImpl->InsertItem(index, imageIndex);
1758
1759 wxListItem info;
1760 info.m_image = imageIndex;
1761 info.m_mask = wxLIST_MASK_IMAGE;
1762 info.m_itemId = index;
1763 return InsertItem(info);
1764 }
1765
1766 // Inserts an image/string item
1767 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1768 {
1769 if (m_genericImpl)
1770 return m_genericImpl->InsertItem(index, label, imageIndex);
1771
1772 wxListItem info;
1773 info.m_image = imageIndex;
1774 info.m_text = label;
1775 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1776 info.m_itemId = index;
1777 return InsertItem(info);
1778 }
1779
1780 // For list view mode (only), inserts a column.
1781 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1782 {
1783 if (m_genericImpl)
1784 return m_genericImpl->InsertColumn(col, item);
1785
1786 if (m_dbImpl)
1787 {
1788 int width = item.GetWidth();
1789 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1790 width = 150;
1791
1792 DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType;
1793 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1794 if (imageList && imageList->GetImageCount() > 0)
1795 {
1796 wxBitmap bmp = imageList->GetBitmap(0);
1797 //if (bmp.Ok())
1798 // type = kDataBrowserIconAndTextType;
1799 }
1800
1801 SInt16 just = teFlushDefault;
1802 if (item.GetMask() & wxLIST_MASK_FORMAT)
1803 {
1804 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1805 just = teFlushLeft;
1806 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1807 just = teCenter;
1808 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1809 just = teFlushRight;
1810 }
1811 m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
1812 SetColumn(col, item);
1813
1814 // set/remove options based on the wxListCtrl type.
1815 DataBrowserTableViewColumnID id;
1816 m_dbImpl->GetColumnIDFromIndex(col, &id);
1817 DataBrowserPropertyFlags flags;
1818 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1819 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1820 flags |= kDataBrowserPropertyIsEditable;
1821
1822 if (GetWindowStyleFlag() & wxLC_VIRTUAL){
1823 flags &= ~kDataBrowserListViewSortableColumn;
1824 }
1825 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1826 }
1827
1828 return col;
1829 }
1830
1831 long wxListCtrl::InsertColumn(long col,
1832 const wxString& heading,
1833 int format,
1834 int width)
1835 {
1836 if (m_genericImpl)
1837 return m_genericImpl->InsertColumn(col, heading, format, width);
1838
1839 wxListItem item;
1840 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1841 item.m_text = heading;
1842 if ( width > -1 )
1843 {
1844 item.m_mask |= wxLIST_MASK_WIDTH;
1845 item.m_width = width;
1846 }
1847 item.m_format = format;
1848
1849 return InsertColumn(col, item);
1850 }
1851
1852 // scroll the control by the given number of pixels (exception: in list view,
1853 // dx is interpreted as number of columns)
1854 bool wxListCtrl::ScrollList(int dx, int dy)
1855 {
1856 if (m_genericImpl)
1857 return m_genericImpl->ScrollList(dx, dy);
1858
1859 if (m_dbImpl)
1860 {
1861 m_dbImpl->SetScrollPosition(dx, dy);
1862 }
1863 return true;
1864 }
1865
1866
1867 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1868 {
1869 if (m_genericImpl)
1870 return m_genericImpl->SortItems(fn, data);
1871
1872 if (m_dbImpl)
1873 {
1874 m_compareFunc = fn;
1875 m_compareFuncData = data;
1876 }
1877
1878 return true;
1879 }
1880
1881 void wxListCtrl::OnRenameTimer()
1882 {
1883 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1884
1885 EditLabel( m_current );
1886 }
1887
1888 bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value)
1889 {
1890 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() );
1891 le.SetEventObject( this );
1892 le.m_itemIndex = itemEdit;
1893
1894 GetItem( le.m_item );
1895 le.m_item.m_text = value;
1896 return !GetEventHandler()->ProcessEvent( le ) ||
1897 le.IsAllowed();
1898 }
1899
1900 void wxListCtrl::OnRenameCancelled(long itemEdit)
1901 {
1902 // let owner know that the edit was cancelled
1903 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1904
1905 le.SetEditCanceled(true);
1906
1907 le.SetEventObject( this );
1908 le.m_itemIndex = itemEdit;
1909
1910 GetItem( le.m_item );
1911 GetEventHandler()->ProcessEvent( le );
1912 }
1913
1914 // ----------------------------------------------------------------------------
1915 // virtual list controls
1916 // ----------------------------------------------------------------------------
1917
1918 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1919 {
1920 // this is a pure virtual function, in fact - which is not really pure
1921 // because the controls which are not virtual don't need to implement it
1922 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1923
1924 return wxEmptyString;
1925 }
1926
1927 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1928 {
1929 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1930 -1,
1931 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1932 return -1;
1933 }
1934
1935 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1936 {
1937 if (!column)
1938 return OnGetItemImage(item);
1939
1940 return -1;
1941 }
1942
1943 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1944 {
1945 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1946 _T("invalid item index in OnGetItemAttr()") );
1947
1948 // no attributes by default
1949 return NULL;
1950 }
1951
1952 void wxListCtrl::SetItemCount(long count)
1953 {
1954 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1955
1956 if (m_genericImpl)
1957 {
1958 m_genericImpl->SetItemCount(count);
1959 return;
1960 }
1961
1962 if (m_dbImpl)
1963 {
1964 // we need to temporarily disable the new item creation notification
1965 // procedure to speed things up
1966 // FIXME: Even this doesn't seem to help much...
1967 DataBrowserCallbacks callbacks;
1968 DataBrowserItemNotificationUPP itemUPP;
1969 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
1970 itemUPP = callbacks.u.v1.itemNotificationCallback;
1971 callbacks.u.v1.itemNotificationCallback = 0;
1972 m_dbImpl->SetCallbacks(&callbacks);
1973 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
1974 count, NULL, kDataBrowserItemNoProperty);
1975 callbacks.u.v1.itemNotificationCallback = itemUPP;
1976 m_dbImpl->SetCallbacks(&callbacks);
1977 }
1978 m_count = count;
1979 }
1980
1981 void wxListCtrl::RefreshItem(long item)
1982 {
1983 if (m_genericImpl)
1984 {
1985 m_genericImpl->RefreshItem(item);
1986 return;
1987 }
1988
1989 wxRect rect;
1990 GetItemRect(item, rect);
1991 RefreshRect(rect);
1992 }
1993
1994 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1995 {
1996 if (m_genericImpl)
1997 {
1998 m_genericImpl->RefreshItems(itemFrom, itemTo);
1999 return;
2000 }
2001
2002 wxRect rect1, rect2;
2003 GetItemRect(itemFrom, rect1);
2004 GetItemRect(itemTo, rect2);
2005
2006 wxRect rect = rect1;
2007 rect.height = rect2.GetBottom() - rect1.GetTop();
2008
2009 RefreshRect(rect);
2010 }
2011
2012
2013 // wxMac internal data structures
2014
2015 wxMacListCtrlItem::~wxMacListCtrlItem()
2016 {
2017 }
2018
2019 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
2020 DataBrowserItemNotification message,
2021 DataBrowserItemDataRef itemData ) const
2022 {
2023
2024 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
2025
2026 // we want to depend on as little as possible to make sure tear-down of controls is safe
2027 if ( message == kDataBrowserItemRemoved)
2028 {
2029 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
2030 {
2031 delete (wxClientData*) (m_data);
2032 }
2033
2034 delete this;
2035 return;
2036 }
2037 else if ( message == kDataBrowserItemAdded )
2038 {
2039 // we don't issue events on adding, the item is not really stored in the list yet, so we
2040 // avoid asserts by gettting out now
2041 return ;
2042 }
2043
2044 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
2045 if ( list )
2046 {
2047 bool trigger = false;
2048
2049 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2050 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2051
2052 event.SetEventObject( list );
2053 event.m_itemIndex = owner->GetLineFromItem( this ) ;
2054 if ( !list->IsVirtual() )
2055 {
2056 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2057 }
2058
2059 switch (message)
2060 {
2061 case kDataBrowserItemDeselected:
2062 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2063 if ( !isSingle )
2064 trigger = !lb->IsSelectionSuppressed();
2065 break;
2066
2067 case kDataBrowserItemSelected:
2068 trigger = !lb->IsSelectionSuppressed();
2069 break;
2070
2071 case kDataBrowserItemDoubleClicked:
2072 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2073 trigger = true;
2074 break;
2075
2076 case kDataBrowserEditStarted :
2077 // TODO : how to veto ?
2078 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2079 trigger = true ;
2080 break ;
2081
2082 case kDataBrowserEditStopped :
2083 // TODO probably trigger only upon the value store callback, because
2084 // here IIRC we cannot veto
2085 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2086 trigger = true ;
2087 break ;
2088
2089 default:
2090 break;
2091 }
2092
2093 if ( trigger )
2094 {
2095 // direct notification is not always having the listbox GetSelection() having in synch with event
2096 wxPostEvent( list->GetEventHandler(), event );
2097 }
2098 }
2099
2100 }
2101
2102 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
2103 : wxMacDataItemBrowserControl( peer, pos, size, style )
2104 {
2105 OSStatus err = noErr;
2106 m_clientDataItemsType = wxClientData_None;
2107 m_isVirtual = false;
2108
2109 if ( style & wxLC_VIRTUAL )
2110 m_isVirtual = true;
2111
2112 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
2113 if ( style & wxLC_SINGLE_SEL )
2114 {
2115 options |= kDataBrowserSelectOnlyOne;
2116 }
2117 else
2118 {
2119 options |= kDataBrowserCmdTogglesSelection;
2120 }
2121
2122 err = SetSelectionFlags( options );
2123 verify_noerr( err );
2124
2125 DataBrowserCustomCallbacks callbacks;
2126 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
2127
2128 if ( gDataBrowserDrawItemUPP == NULL )
2129 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
2130
2131 // if ( gDataBrowserEditItemUPP == NULL )
2132 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2133
2134 if ( gDataBrowserHitTestUPP == NULL )
2135 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
2136
2137 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
2138 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2139 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
2140
2141 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
2142
2143 if ( style & wxLC_LIST )
2144 {
2145 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
2146 verify_noerr( AutoSizeColumns() );
2147 }
2148
2149 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
2150 verify_noerr( SetHeaderButtonHeight( 0 ) );
2151
2152 if ( m_isVirtual )
2153 SetSortProperty( kMinColumnId - 1 );
2154 else
2155 SetSortProperty( kMinColumnId );
2156 if ( style & wxLC_SORT_ASCENDING )
2157 {
2158 m_sortOrder = SortOrder_Text_Ascending;
2159 SetSortOrder( kDataBrowserOrderIncreasing );
2160 }
2161 else if ( style & wxLC_SORT_DESCENDING )
2162 {
2163 m_sortOrder = SortOrder_Text_Descending;
2164 SetSortOrder( kDataBrowserOrderDecreasing );
2165 }
2166 else
2167 {
2168 m_sortOrder = SortOrder_None;
2169 }
2170
2171 if ( style & wxLC_VRULES )
2172 {
2173 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2174 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
2175 #endif
2176 }
2177
2178 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
2179 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
2180 }
2181
2182 pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2183 ControlRef browser,
2184 DataBrowserItemID itemID,
2185 DataBrowserPropertyID property,
2186 CFStringRef theString,
2187 Rect *maxEditTextRect,
2188 Boolean *shrinkToFit)
2189 {
2190 Boolean result = false;
2191 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2192 if ( ctl != 0 )
2193 {
2194 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
2195 theString = CFSTR("Hello!");
2196 }
2197 return result;
2198 }
2199
2200 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2201 DataBrowserItemID itemID,
2202 DataBrowserPropertyID property,
2203 CFStringRef theString,
2204 Rect *maxEditTextRect,
2205 Boolean *shrinkToFit)
2206 {
2207 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2208 return false;
2209 }
2210
2211 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2212 ControlRef browser,
2213 DataBrowserItemID itemID,
2214 DataBrowserPropertyID property,
2215 DataBrowserItemState itemState,
2216 const Rect *itemRect,
2217 SInt16 gdDepth,
2218 Boolean colorDevice)
2219 {
2220 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2221 if ( ctl != 0 )
2222 {
2223 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
2224 }
2225 }
2226
2227 // routines needed for DrawItem
2228 enum
2229 {
2230 kIconWidth = 16,
2231 kIconHeight = 16,
2232 kTextBoxHeight = 14,
2233 kIconTextSpacingV = 2,
2234 kItemPadding = 4,
2235 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
2236 };
2237
2238 static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
2239 {
2240 float textBottom;
2241 float iconH, iconW = 0;
2242 float padding = kItemPadding;
2243 if (hasIcon)
2244 {
2245 iconH = kIconHeight;
2246 iconW = kIconWidth;
2247 padding = padding*2;
2248 }
2249
2250 textBottom = inItemRect.origin.y;
2251
2252 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
2253 textBottom + kIconTextSpacingV, kIconWidth,
2254 kIconHeight);
2255
2256 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
2257 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
2258 inItemRect.size.height - kIconTextSpacingV);
2259 }
2260
2261 void wxMacDataBrowserListCtrlControl::DrawItem(
2262 DataBrowserItemID itemID,
2263 DataBrowserPropertyID property,
2264 DataBrowserItemState itemState,
2265 const Rect *itemRect,
2266 SInt16 gdDepth,
2267 Boolean colorDevice)
2268 {
2269 wxString text;
2270 wxFont font = wxNullFont;
2271 int imgIndex = -1;
2272 short listColumn = property - kMinColumnId;
2273
2274 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2275 wxMacListCtrlItem* lcItem;
2276 wxColour color = *wxBLACK;
2277 wxColour bgColor = wxNullColour;
2278
2279 if (listColumn >= 0)
2280 {
2281 if (!m_isVirtual)
2282 {
2283 lcItem = (wxMacListCtrlItem*) itemID;
2284 if (lcItem->HasColumnInfo(listColumn)){
2285 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2286
2287 // we always use the 0 column to get font and text/background colors.
2288 if (lcItem->HasColumnInfo(0))
2289 {
2290 wxListItem* firstItem = lcItem->GetColumnInfo(0);
2291 color = firstItem->GetTextColour();
2292 bgColor = firstItem->GetBackgroundColour();
2293 font = firstItem->GetFont();
2294 }
2295
2296 if (item->GetMask() & wxLIST_MASK_TEXT)
2297 text = item->GetText();
2298 if (item->GetMask() & wxLIST_MASK_IMAGE)
2299 imgIndex = item->GetImage();
2300 }
2301
2302 }
2303 else
2304 {
2305 text = list->OnGetItemText( (long)itemID-1, listColumn );
2306 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2307 wxListItemAttr* attrs = list->OnGetItemAttr( (long)itemID-1 );
2308 if (attrs)
2309 {
2310 if (attrs->HasBackgroundColour())
2311 bgColor = attrs->GetBackgroundColour();
2312 if (attrs->HasTextColour())
2313 color = attrs->GetTextColour();
2314 if (attrs->HasFont())
2315 font = attrs->GetFont();
2316 }
2317 }
2318 }
2319
2320 wxColour listBgColor = list->GetBackgroundColour();
2321 if (bgColor == wxNullColour)
2322 bgColor = listBgColor;
2323
2324 wxFont listFont = list->GetFont();
2325 if (font == wxNullFont)
2326 font = listFont;
2327
2328 wxMacCFStringHolder cfString;
2329 cfString.Assign( text, wxLocale::GetSystemEncoding() );
2330
2331 Rect enclosingRect;
2332 CGRect enclosingCGRect, iconCGRect, textCGRect;
2333 Boolean active;
2334 ThemeDrawingState savedState = NULL;
2335 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
2336 RGBColor labelColor;
2337
2338 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
2339 &enclosingRect);
2340
2341 enclosingCGRect = CGRectMake(enclosingRect.left,
2342 enclosingRect.top,
2343 enclosingRect.right - enclosingRect.left,
2344 enclosingRect.bottom - enclosingRect.top);
2345
2346 active = IsControlActive(GetControlRef());
2347
2348 if (itemState == kDataBrowserItemIsSelected)
2349 {
2350 RGBColor foregroundColor;
2351
2352 GetThemeDrawingState(&savedState);
2353
2354 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &foregroundColor);
2355 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
2356
2357 CGContextSaveGState(context);
2358
2359 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2360 (float)foregroundColor.green / (float)USHRT_MAX,
2361 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2362 CGContextFillRect(context, enclosingCGRect);
2363
2364 CGContextRestoreGState(context);
2365 }
2366 else
2367 {
2368
2369 if (color.Ok())
2370 labelColor = MAC_WXCOLORREF( color.GetPixel() );
2371 else if (list->GetTextColour().Ok())
2372 labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
2373 else
2374 {
2375 labelColor.red = 0;
2376 labelColor.green = 0;
2377 labelColor.blue = 0;
2378 }
2379
2380 if (bgColor.Ok())
2381 {
2382 RGBColor foregroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
2383 CGContextSaveGState(context);
2384
2385 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2386 (float)foregroundColor.green / (float)USHRT_MAX,
2387 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2388 CGContextFillRect(context, enclosingCGRect);
2389
2390 CGContextRestoreGState(context);
2391 }
2392 }
2393
2394 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2395
2396 if (imgIndex != -1)
2397 {
2398 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2399 if (imageList && imageList->GetImageCount() > 0){
2400 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2401 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2402
2403 RGBColor iconLabel;
2404 iconLabel.red = 0;
2405 iconLabel.green = 0;
2406 iconLabel.blue = 0;
2407
2408 CGContextSaveGState(context);
2409 CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
2410 CGContextScaleCTM(context,1.0f,-1.0f);
2411 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2412 active ? kTransformNone : kTransformDisabled, &iconLabel,
2413 kPlotIconRefNormalFlags, icon);
2414
2415 CGContextRestoreGState(context);
2416 }
2417 }
2418
2419 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2420 UInt16 fontID = kThemeViewsFont;
2421
2422 if (font.Ok())
2423 {
2424 if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
2425 fontID = font.MacGetThemeFontID();
2426
2427 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2428 #ifndef __LP64__
2429 ::TextSize( (short)(font.MacGetFontSize()) ) ;
2430 ::TextFace( font.MacGetFontStyle() ) ;
2431 #endif
2432 }
2433
2434 wxListItem item;
2435 list->GetColumn(listColumn, item);
2436 if (item.GetMask() & wxLIST_MASK_FORMAT)
2437 {
2438 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
2439 hFlush = kHIThemeTextHorizontalFlushLeft;
2440 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
2441 hFlush = kHIThemeTextHorizontalFlushCenter;
2442 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
2443 {
2444 hFlush = kHIThemeTextHorizontalFlushRight;
2445 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
2446 }
2447 }
2448
2449 HIThemeTextInfo info;
2450 info.version = kHIThemeTextInfoVersionZero;
2451 info.state = active ? kThemeStateActive : kThemeStateInactive;
2452 info.fontID = fontID;
2453 info.horizontalFlushness = hFlush;
2454 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
2455 info.options = kHIThemeTextBoxOptionNone;
2456 info.truncationPosition = kHIThemeTextTruncationEnd;
2457 info.truncationMaxLines = 1;
2458
2459 CGContextSaveGState(context);
2460 CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
2461 (float)labelColor.green / (float)USHRT_MAX,
2462 (float)labelColor.blue / (float)USHRT_MAX, 1.0);
2463
2464 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
2465
2466 CGContextRestoreGState(context);
2467
2468 if (savedState != NULL)
2469 SetThemeDrawingState(savedState, true);
2470 }
2471
2472 OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
2473 DataBrowserPropertyID property,
2474 DataBrowserItemDataRef itemData,
2475 Boolean changeValue )
2476 {
2477 wxString text;
2478 int imgIndex = -1;
2479 short listColumn = property - kMinColumnId;
2480
2481 OSStatus err = errDataBrowserPropertyNotSupported;
2482 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2483 wxMacListCtrlItem* lcItem;
2484
2485 if (listColumn >= 0)
2486 {
2487 if (!m_isVirtual)
2488 {
2489 lcItem = (wxMacListCtrlItem*) itemID;
2490 if (lcItem->HasColumnInfo(listColumn)){
2491 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2492 if (item->GetMask() & wxLIST_MASK_TEXT)
2493 text = item->GetText();
2494 if (item->GetMask() & wxLIST_MASK_IMAGE)
2495 imgIndex = item->GetImage();
2496 }
2497 }
2498 else
2499 {
2500 text = list->OnGetItemText( (long)itemID-1, listColumn );
2501 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2502 }
2503 }
2504
2505 if ( !changeValue )
2506 {
2507 switch (property)
2508 {
2509 case kDataBrowserItemIsEditableProperty :
2510 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
2511 {
2512 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
2513 err = noErr ;
2514 }
2515 break ;
2516 default :
2517 if ( property >= kMinColumnId )
2518 {
2519 wxMacCFStringHolder cfStr;
2520
2521 if (text){
2522 cfStr.Assign( text, wxLocale::GetSystemEncoding() );
2523 err = ::SetDataBrowserItemDataText( itemData, cfStr );
2524 err = noErr;
2525 }
2526
2527
2528
2529 if ( imgIndex != -1 )
2530 {
2531 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2532 if (imageList && imageList->GetImageCount() > 0){
2533 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2534 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2535 ::SetDataBrowserItemDataIcon(itemData, icon);
2536 }
2537 }
2538
2539 }
2540 break ;
2541 }
2542
2543 }
2544 else
2545 {
2546 switch (property)
2547 {
2548 default:
2549 if ( property >= kMinColumnId )
2550 {
2551 short listColumn = property - kMinColumnId;
2552
2553 // TODO probably send the 'end edit' from here, as we
2554 // can then deal with the veto
2555 CFStringRef sr ;
2556 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
2557 wxMacCFStringHolder cfStr(sr) ;;
2558 if (m_isVirtual)
2559 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
2560 else
2561 {
2562 if (lcItem)
2563 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
2564 }
2565 err = noErr ;
2566 }
2567 break;
2568 }
2569 }
2570 return err;
2571 }
2572
2573 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
2574 DataBrowserItemNotification message,
2575 DataBrowserItemDataRef itemData )
2576 {
2577 // we want to depend on as little as possible to make sure tear-down of controls is safe
2578 if ( message == kDataBrowserItemRemoved)
2579 {
2580 // make sure MacDelete does the proper teardown.
2581 return;
2582 }
2583 else if ( message == kDataBrowserItemAdded )
2584 {
2585 // we don't issue events on adding, the item is not really stored in the list yet, so we
2586 // avoid asserts by getting out now
2587 return ;
2588 }
2589
2590 wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
2591 if ( list )
2592 {
2593 bool trigger = false;
2594
2595 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2596 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2597
2598 event.SetEventObject( list );
2599 if ( !list->IsVirtual() )
2600 {
2601 DataBrowserTableViewRowIndex result = 0;
2602 verify_noerr( GetItemRow( itemID, &result ) ) ;
2603 event.m_itemIndex = result;
2604
2605 if (event.m_itemIndex >= 0)
2606 MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2607 }
2608 else
2609 {
2610 event.m_itemIndex = (long)itemID;
2611 }
2612
2613 switch (message)
2614 {
2615 case kDataBrowserItemDeselected:
2616 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2617 if ( !isSingle )
2618 trigger = !IsSelectionSuppressed();
2619 break;
2620
2621 case kDataBrowserItemSelected:
2622 trigger = !IsSelectionSuppressed();
2623
2624 break;
2625
2626 case kDataBrowserItemDoubleClicked:
2627 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2628 trigger = true;
2629 break;
2630
2631 case kDataBrowserEditStarted :
2632 // TODO : how to veto ?
2633 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2634 trigger = true ;
2635 break ;
2636
2637 case kDataBrowserEditStopped :
2638 // TODO probably trigger only upon the value store callback, because
2639 // here IIRC we cannot veto
2640 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2641 trigger = true ;
2642 break ;
2643
2644 default:
2645 break;
2646 }
2647
2648 if ( trigger )
2649 {
2650 // direct notification is not always having the listbox GetSelection() having in synch with event
2651 wxPostEvent( list->GetEventHandler(), event );
2652 }
2653 }
2654 }
2655
2656 Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
2657 DataBrowserItemID itemTwoID,
2658 DataBrowserPropertyID sortProperty)
2659 {
2660
2661 bool retval = false;
2662 wxString itemText;
2663 wxString otherItemText;
2664 int colId = sortProperty - kMinColumnId;
2665 long itemNum = 0;
2666 long otherItemNum = 0;
2667
2668 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2669
2670 // means we need to
2671 if (colId >= 0)
2672 {
2673 if (!m_isVirtual)
2674 {
2675 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
2676 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
2677 wxListCtrlCompare func = list->GetCompareFunc();
2678 if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
2679 return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
2680
2681 itemNum = item->GetOrder();
2682 otherItemNum = otherItem->GetOrder();
2683 if (item->HasColumnInfo(colId))
2684 itemText = item->GetColumnInfo(colId)->GetText();
2685 if (otherItem->HasColumnInfo(colId))
2686 otherItemText = otherItem->GetColumnInfo(colId)->GetText();
2687 }
2688 else
2689 {
2690 itemNum = (long)itemOneID;
2691 otherItemNum = (long)itemTwoID;
2692 itemText = list->OnGetItemText( itemNum-1, colId );
2693 otherItemText = list->OnGetItemText( otherItemNum-1, colId );
2694
2695 }
2696
2697 DataBrowserSortOrder sort;
2698 verify_noerr(GetSortOrder(&sort));
2699
2700 if ( sort == kDataBrowserOrderIncreasing )
2701 {
2702 retval = itemText.CmpNoCase( otherItemText ) > 0;
2703 }
2704 else if ( sort == kDataBrowserOrderDecreasing )
2705 {
2706 retval = itemText.CmpNoCase( otherItemText ) < 0;
2707 }
2708 }
2709 else{
2710 // fallback for undefined cases
2711 retval = itemOneID < itemTwoID;
2712 }
2713
2714 return retval;
2715 }
2716
2717 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2718 {
2719 }
2720
2721 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
2722 {
2723 wxMacDataItem* dataItem = GetItemFromLine(row);
2724 if (item)
2725 {
2726 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2727 listItem->SetColumnInfo( column, item );
2728 UpdateState(dataItem, item);
2729 }
2730 }
2731
2732 // apply changes that need to happen immediately, rather than when the
2733 // databrowser control fires a callback.
2734 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
2735 {
2736 bool isSelected = IsItemSelected( dataItem );
2737 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
2738
2739 // toggle the selection state if wxListInfo state and actual state don't match.
2740 if ( isSelected != isSelectedState )
2741 {
2742 DataBrowserSetOption options = kDataBrowserItemsAdd;
2743 if (!isSelectedState)
2744 options = kDataBrowserItemsRemove;
2745 SetSelectedItem(dataItem, options);
2746 }
2747 // TODO: Set column width if item width > than current column width
2748 }
2749
2750 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
2751 {
2752 wxMacDataItem* dataItem = GetItemFromLine(row);
2753 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2754 //if (item)
2755 {
2756 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2757 wxListItem* oldItem = listItem->GetColumnInfo( column );
2758
2759 long mask = item.GetMask();
2760 if ( !mask )
2761 // by default, get everything for backwards compatibility
2762 mask = -1;
2763
2764 if ( mask & wxLIST_MASK_TEXT )
2765 item.SetText(oldItem->GetText());
2766 if ( mask & wxLIST_MASK_IMAGE )
2767 item.SetImage(oldItem->GetImage());
2768 if ( mask & wxLIST_MASK_DATA )
2769 item.SetData(oldItem->GetData());
2770 if ( mask & wxLIST_MASK_STATE )
2771 item.SetState(oldItem->GetState());
2772 if ( mask & wxLIST_MASK_WIDTH )
2773 item.SetWidth(oldItem->GetWidth());
2774 if ( mask & wxLIST_MASK_FORMAT )
2775 item.SetAlign(oldItem->GetAlign());
2776
2777 item.SetTextColour(oldItem->GetTextColour());
2778 item.SetBackgroundColour(oldItem->GetBackgroundColour());
2779 item.SetFont(oldItem->GetFont());
2780 }
2781 }
2782
2783 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
2784 {
2785 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
2786 MacSetColumnInfo(n, 0, item);
2787 }
2788
2789 wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem()
2790 {
2791 return new wxMacListCtrlItem();
2792 }
2793
2794 wxMacListCtrlItem::wxMacListCtrlItem()
2795 {
2796 m_rowItems = wxListItemList();
2797 }
2798
2799 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
2800 {
2801 return GetColumnInfo(column)->GetImage();
2802 }
2803
2804 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
2805 {
2806 GetColumnInfo(column)->SetImage(imageIndex);
2807 }
2808
2809 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
2810 {
2811 if ( column == 0 )
2812 return GetLabel();
2813
2814 return GetColumnInfo(column)->GetText();
2815 }
2816
2817 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
2818 {
2819 GetColumnInfo(column)->SetText(text);
2820
2821 // for compatibility with superclass APIs
2822 if ( column == 0 )
2823 SetLabel(text);
2824 }
2825
2826 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
2827 {
2828 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
2829 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
2830
2831 return node->GetData();
2832 }
2833
2834 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
2835 {
2836 return m_rowItems.GetCount() > column;
2837 }
2838
2839 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
2840 {
2841
2842 if ( column >= m_rowItems.GetCount() )
2843 {
2844 wxListItem* listItem = new wxListItem(*item);
2845 m_rowItems.Append( listItem );
2846 }
2847 else
2848 {
2849 wxListItem* listItem = GetColumnInfo( column );
2850 long mask = item->GetMask();
2851 if (mask & wxLIST_MASK_TEXT)
2852 listItem->SetText(item->GetText());
2853 if (mask & wxLIST_MASK_DATA)
2854 listItem->SetData(item->GetData());
2855 if (mask & wxLIST_MASK_IMAGE)
2856 listItem->SetImage(item->GetImage());
2857 if (mask & wxLIST_MASK_STATE)
2858 listItem->SetState(item->GetState());
2859 if (mask & wxLIST_MASK_FORMAT)
2860 listItem->SetAlign(item->GetAlign());
2861 if (mask & wxLIST_MASK_WIDTH)
2862 listItem->SetWidth(item->GetWidth());
2863
2864 listItem->SetTextColour(item->GetTextColour());
2865 listItem->SetBackgroundColour(item->GetBackgroundColour());
2866 listItem->SetFont(item->GetFont());
2867 }
2868 }
2869
2870 #endif // wxUSE_LISTCTRL