]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
use wxLocaltime_r() instead of localtime(): this is safer and localtime() isn't avail...
[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
633 // since the generic control is a child, make sure we position it at 0, 0
634 m_genericImpl = new wxGenericListCtrlHook(this, id, wxPoint(0, 0), size, style, validator, name);
635 m_genericImpl->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
636 return true;
637 }
638
639 else
640 {
641 m_macIsUserPane = false;
642
643 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
644 return false;
645 m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style );
646 m_peer = m_dbImpl;
647
648 MacPostControlCreate( pos, size );
649
650 InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
651 GetEventTypeCount(eventList), eventList, this,
652 (EventHandlerRef *)&m_macListCtrlEventHandler);
653 }
654
655 return true;
656 }
657
658 wxListCtrl::~wxListCtrl()
659 {
660 if (m_genericImpl)
661 {
662 m_genericImpl->PopEventHandler(/* deleteHandler = */ true);
663 }
664
665 if (m_ownsImageListNormal)
666 delete m_imageListNormal;
667 if (m_ownsImageListSmall)
668 delete m_imageListSmall;
669 if (m_ownsImageListState)
670 delete m_imageListState;
671
672 delete m_renameTimer;
673 }
674
675 // ----------------------------------------------------------------------------
676 // set/get/change style
677 // ----------------------------------------------------------------------------
678
679 // Add or remove a single window style
680 void wxListCtrl::SetSingleStyle(long style, bool add)
681 {
682 long flag = GetWindowStyleFlag();
683
684 // Get rid of conflicting styles
685 if ( add )
686 {
687 if ( style & wxLC_MASK_TYPE)
688 flag = flag & ~wxLC_MASK_TYPE;
689 if ( style & wxLC_MASK_ALIGN )
690 flag = flag & ~wxLC_MASK_ALIGN;
691 if ( style & wxLC_MASK_SORT )
692 flag = flag & ~wxLC_MASK_SORT;
693 }
694
695 if ( add )
696 flag |= style;
697 else
698 flag &= ~style;
699
700 SetWindowStyleFlag(flag);
701 }
702
703 // Set the whole window style
704 void wxListCtrl::SetWindowStyleFlag(long flag)
705 {
706 if ( flag != m_windowStyle )
707 {
708 m_windowStyle = flag;
709
710 if (m_genericImpl)
711 {
712 m_genericImpl->SetWindowStyleFlag(flag);
713 }
714
715 Refresh();
716 }
717 }
718
719 void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags )
720 {
721 wxControl::DoSetSize(x, y, width, height, sizeFlags);
722
723 if (m_genericImpl)
724 m_genericImpl->SetSize(0, 0, width, height, sizeFlags);
725 }
726
727 wxSize wxListCtrl::DoGetBestSize() const
728 {
729 return wxWindow::DoGetBestSize();
730 }
731
732 bool wxListCtrl::SetFont(const wxFont& font)
733 {
734 bool rv = true;
735 rv = wxControl::SetFont(font);
736 if (m_genericImpl)
737 rv = m_genericImpl->SetFont(font);
738 return rv;
739 }
740
741 bool wxListCtrl::SetForegroundColour(const wxColour& colour)
742 {
743 bool rv = true;
744 if (m_genericImpl)
745 rv = m_genericImpl->SetForegroundColour(colour);
746 if (m_dbImpl)
747 SetTextColour(colour);
748 return rv;
749 }
750
751 bool wxListCtrl::SetBackgroundColour(const wxColour& colour)
752 {
753 bool rv = true;
754 if (m_genericImpl)
755 rv = m_genericImpl->SetBackgroundColour(colour);
756 if (m_dbImpl)
757 m_bgColor = colour;
758 return rv;
759 }
760
761 wxColour wxListCtrl::GetBackgroundColour()
762 {
763 if (m_genericImpl)
764 return m_genericImpl->GetBackgroundColour();
765 if (m_dbImpl)
766 return m_bgColor;
767
768 return wxNullColour;
769 }
770
771 // ----------------------------------------------------------------------------
772 // accessors
773 // ----------------------------------------------------------------------------
774
775 // Gets information about this column
776 bool wxListCtrl::GetColumn(int col, wxListItem& item) const
777 {
778 if (m_genericImpl)
779 return m_genericImpl->GetColumn(col, item);
780
781 bool success = true;
782
783 if (m_dbImpl)
784 {
785
786 wxColumnList::compatibility_iterator node = m_colsInfo.Item( col );
787 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
788 wxListItem* column = node->GetData();
789
790 long mask = column->GetMask();
791 if (mask & wxLIST_MASK_TEXT)
792 item.SetText(column->GetText());
793 if (mask & wxLIST_MASK_DATA)
794 item.SetData(column->GetData());
795 if (mask & wxLIST_MASK_IMAGE)
796 item.SetImage(column->GetImage());
797 if (mask & wxLIST_MASK_STATE)
798 item.SetState(column->GetState());
799 if (mask & wxLIST_MASK_FORMAT)
800 item.SetAlign(column->GetAlign());
801 if (mask & wxLIST_MASK_WIDTH)
802 item.SetWidth(column->GetWidth());
803 }
804
805 return success;
806 }
807
808 // Sets information about this column
809 bool wxListCtrl::SetColumn(int col, wxListItem& item)
810 {
811 if (m_genericImpl)
812 return m_genericImpl->SetColumn(col, item);
813
814 if (m_dbImpl)
815 {
816 if ( col >= (int)m_colsInfo.GetCount() )
817 {
818 wxListItem* listItem = new wxListItem(item);
819 m_colsInfo.Append( listItem );
820 }
821 else
822 {
823 wxListItem listItem;
824 GetColumn( col, listItem );
825 long mask = item.GetMask();
826 if (mask & wxLIST_MASK_TEXT)
827 listItem.SetText(item.GetText());
828 if (mask & wxLIST_MASK_DATA)
829 listItem.SetData(item.GetData());
830 if (mask & wxLIST_MASK_IMAGE)
831 listItem.SetImage(item.GetImage());
832 if (mask & wxLIST_MASK_STATE)
833 listItem.SetState(item.GetState());
834 if (mask & wxLIST_MASK_FORMAT)
835 listItem.SetAlign(item.GetAlign());
836 if (mask & wxLIST_MASK_WIDTH)
837 listItem.SetWidth(item.GetWidth());
838 }
839
840 // change the appearance in the databrowser.
841 DataBrowserListViewHeaderDesc columnDesc;
842 columnDesc.version=kDataBrowserListViewLatestHeaderDesc;
843 verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) );
844
845 /*
846 if (item.GetMask() & wxLIST_MASK_TEXT)
847 {
848 wxFontEncoding enc;
849 if ( m_font.Ok() )
850 enc = m_font.GetEncoding();
851 else
852 enc = wxLocale::GetSystemEncoding();
853 wxMacCFStringHolder cfTitle;
854 cfTitle.Assign( item.GetText() , enc );
855 if(columnDesc.titleString)
856 CFRelease(columnDesc.titleString);
857 columnDesc.titleString = cfTitle;
858 }
859 */
860
861 if (item.GetMask() & wxLIST_MASK_IMAGE && item.GetImage() != -1 )
862 {
863 columnDesc.btnContentInfo.contentType = kControlContentIconRef;
864 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
865 if (imageList && imageList->GetImageCount() > 0 )
866 {
867 wxBitmap bmp = imageList->GetBitmap( item.GetImage() );
868 IconRef icon = bmp.GetBitmapData()->GetIconRef();
869 columnDesc.btnContentInfo.u.iconRef = icon;
870 }
871 }
872
873 verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) );
874
875 }
876 return true;
877 }
878
879 int wxListCtrl::GetColumnCount() const
880 {
881 if (m_genericImpl)
882 return m_genericImpl->GetColumnCount();
883
884 if (m_dbImpl)
885 {
886 UInt32 count;
887 m_dbImpl->GetColumnCount(&count);
888 return count;
889 }
890
891 return m_colCount;
892 }
893
894 // Gets the column width
895 int wxListCtrl::GetColumnWidth(int col) const
896 {
897 if (m_genericImpl)
898 return m_genericImpl->GetColumnWidth(col);
899
900 if (m_dbImpl)
901 {
902 return m_dbImpl->GetColumnWidth(col);
903 }
904
905 return 0;
906 }
907
908 // Sets the column width
909 bool wxListCtrl::SetColumnWidth(int col, int width)
910 {
911 if (m_genericImpl)
912 return m_genericImpl->SetColumnWidth(col, width);
913
914 if (m_dbImpl)
915 {
916 int mywidth = width;
917 if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER)
918 mywidth = 150;
919
920 if (col == -1)
921 {
922 for (int column = 0; column < GetColumnCount(); column++)
923 {
924 m_dbImpl->SetColumnWidth(col, mywidth);
925 }
926 }
927 else{
928 m_dbImpl->SetColumnWidth(col, mywidth);
929 }
930 return true;
931 }
932
933 return false;
934 }
935
936 // Gets the number of items that can fit vertically in the
937 // visible area of the list control (list or report view)
938 // or the total number of items in the list control (icon
939 // or small icon view)
940 int wxListCtrl::GetCountPerPage() const
941 {
942 if (m_genericImpl)
943 return m_genericImpl->GetCountPerPage();
944
945 if (m_dbImpl)
946 {
947 }
948
949 return 1;
950 }
951
952 // Gets the edit control for editing labels.
953 wxTextCtrl* wxListCtrl::GetEditControl() const
954 {
955 if (m_genericImpl)
956 return m_genericImpl->GetEditControl();
957
958 return NULL;
959 }
960
961 // Gets information about the item
962 bool wxListCtrl::GetItem(wxListItem& info) const
963 {
964 if (m_genericImpl)
965 return m_genericImpl->GetItem(info);
966
967 if (m_dbImpl)
968 {
969 if (!IsVirtual())
970 m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info);
971 else
972 {
973 info.SetText( OnGetItemText(info.m_itemId, info.m_col) );
974 info.SetImage( OnGetItemColumnImage(info.m_itemId, info.m_col) );
975 wxListItemAttr* attrs = OnGetItemAttr( info.m_itemId );
976 if (attrs)
977 {
978 info.SetFont( attrs->GetFont() );
979 info.SetBackgroundColour( attrs->GetBackgroundColour() );
980 info.SetTextColour( attrs->GetTextColour() );
981 }
982 }
983 }
984 bool success = true;
985 return success;
986 }
987
988 // Sets information about the item
989 bool wxListCtrl::SetItem(wxListItem& info)
990 {
991 if (m_genericImpl)
992 return m_genericImpl->SetItem(info);
993
994 if (m_dbImpl)
995 m_dbImpl->MacSetColumnInfo( info.m_itemId, info.m_col, &info );
996
997 return true;
998 }
999
1000 long wxListCtrl::SetItem(long index, int col, const wxString& label, int imageId)
1001 {
1002 if (m_genericImpl)
1003 return m_genericImpl->SetItem(index, col, label, imageId);
1004
1005 wxListItem info;
1006 info.m_text = label;
1007 info.m_mask = wxLIST_MASK_TEXT;
1008 info.m_itemId = index;
1009 info.m_col = col;
1010 if ( imageId > -1 )
1011 {
1012 info.m_image = imageId;
1013 info.m_mask |= wxLIST_MASK_IMAGE;
1014 }
1015 return SetItem(info);
1016 }
1017
1018
1019 // Gets the item state
1020 int wxListCtrl::GetItemState(long item, long stateMask) const
1021 {
1022 if (m_genericImpl)
1023 return m_genericImpl->GetItemState(item, stateMask);
1024
1025 wxListItem info;
1026
1027 info.m_mask = wxLIST_MASK_STATE;
1028 info.m_stateMask = stateMask;
1029 info.m_itemId = item;
1030
1031 if (!GetItem(info))
1032 return 0;
1033
1034 return info.m_state;
1035 }
1036
1037 // Sets the item state
1038 bool wxListCtrl::SetItemState(long item, long state, long stateMask)
1039 {
1040 if (m_genericImpl)
1041 return m_genericImpl->SetItemState(item, state, stateMask);
1042
1043 wxListItem info;
1044 info.m_mask = wxLIST_MASK_STATE;
1045 info.m_stateMask = stateMask;
1046 info.m_state = state;
1047 info.m_itemId = item;
1048 return SetItem(info);
1049 }
1050
1051 // Sets the item image
1052 bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
1053 {
1054 return SetItemColumnImage(item, 0, image);
1055 }
1056
1057 // Sets the item image
1058 bool wxListCtrl::SetItemColumnImage(long item, long column, int image)
1059 {
1060 if (m_genericImpl)
1061 return m_genericImpl->SetItemColumnImage(item, column, image);
1062
1063 wxListItem info;
1064
1065 info.m_mask = wxLIST_MASK_IMAGE;
1066 info.m_image = image;
1067 info.m_itemId = item;
1068 info.m_col = column;
1069
1070 return SetItem(info);
1071 }
1072
1073 // Gets the item text
1074 wxString wxListCtrl::GetItemText(long item) const
1075 {
1076 if (m_genericImpl)
1077 return m_genericImpl->GetItemText(item);
1078
1079 wxListItem info;
1080
1081 info.m_mask = wxLIST_MASK_TEXT;
1082 info.m_itemId = item;
1083
1084 if (!GetItem(info))
1085 return wxEmptyString;
1086 return info.m_text;
1087 }
1088
1089 // Sets the item text
1090 void wxListCtrl::SetItemText(long item, const wxString& str)
1091 {
1092 if (m_genericImpl)
1093 return m_genericImpl->SetItemText(item, str);
1094
1095 wxListItem info;
1096
1097 info.m_mask = wxLIST_MASK_TEXT;
1098 info.m_itemId = item;
1099 info.m_text = str;
1100
1101 SetItem(info);
1102 }
1103
1104 // Gets the item data
1105 long wxListCtrl::GetItemData(long item) const
1106 {
1107 if (m_genericImpl)
1108 return m_genericImpl->GetItemData(item);
1109
1110 wxListItem info;
1111
1112 info.m_mask = wxLIST_MASK_DATA;
1113 info.m_itemId = item;
1114
1115 if (!GetItem(info))
1116 return 0;
1117 return info.m_data;
1118 }
1119
1120 // Sets the item data
1121 bool wxListCtrl::SetItemData(long item, long data)
1122 {
1123 if (m_genericImpl)
1124 return m_genericImpl->SetItemData(item, data);
1125
1126 wxListItem info;
1127
1128 info.m_mask = wxLIST_MASK_DATA;
1129 info.m_itemId = item;
1130 info.m_data = data;
1131
1132 return SetItem(info);
1133 }
1134
1135 wxRect wxListCtrl::GetViewRect() const
1136 {
1137 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
1138 _T("wxListCtrl::GetViewRect() only works in icon mode") );
1139
1140 if (m_genericImpl)
1141 return m_genericImpl->GetViewRect();
1142
1143 wxRect rect;
1144 return rect;
1145 }
1146
1147 // Gets the item rectangle
1148 bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const
1149 {
1150 if (m_genericImpl)
1151 return m_genericImpl->GetItemRect(item, rect, code);
1152
1153
1154 if (m_dbImpl)
1155 {
1156 DataBrowserItemID id;
1157 DataBrowserPropertyID col = kMinColumnId;
1158 Rect bounds;
1159 DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart;
1160 if ( code == wxLIST_RECT_LABEL )
1161 part = kDataBrowserPropertyTextPart;
1162 else if ( code == wxLIST_RECT_ICON )
1163 part = kDataBrowserPropertyIconPart;
1164
1165 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL) )
1166 {
1167 wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item);
1168 id = (DataBrowserItemID) thisItem;
1169 }
1170 else
1171 id = item;
1172
1173 GetDataBrowserItemPartBounds( m_dbImpl->GetControlRef(), id, col, part, &bounds );
1174
1175 rect.x = bounds.left;
1176 rect.y = bounds.top;
1177 rect.width = bounds.right - bounds.left; //GetClientSize().x; // we need the width of the whole row, not just the item.
1178 rect.height = bounds.bottom - bounds.top;
1179 //fprintf("id = %d, bounds = %d, %d, %d, %d\n", id, rect.x, rect.y, rect.width, rect.height);
1180 }
1181 return true;
1182 }
1183
1184 // Gets the item position
1185 bool wxListCtrl::GetItemPosition(long item, wxPoint& pos) const
1186 {
1187 if (m_genericImpl)
1188 return m_genericImpl->GetItemPosition(item, pos);
1189
1190 bool success = false;
1191
1192 if (m_dbImpl)
1193 {
1194 wxRect itemRect;
1195 GetItemRect(item, itemRect);
1196 pos = itemRect.GetPosition();
1197 success = true;
1198 }
1199
1200 return success;
1201 }
1202
1203 // Sets the item position.
1204 bool wxListCtrl::SetItemPosition(long item, const wxPoint& pos)
1205 {
1206 if (m_genericImpl)
1207 return m_genericImpl->SetItemPosition(item, pos);
1208
1209 return false;
1210 }
1211
1212 // Gets the number of items in the list control
1213 int wxListCtrl::GetItemCount() const
1214 {
1215 if (m_genericImpl)
1216 return m_genericImpl->GetItemCount();
1217
1218 if (m_dbImpl)
1219 return m_dbImpl->MacGetCount();
1220
1221 return m_count;
1222 }
1223
1224 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
1225 {
1226 if (m_genericImpl)
1227 m_genericImpl->SetItemSpacing(spacing, isSmall);
1228 }
1229
1230 wxSize wxListCtrl::GetItemSpacing() const
1231 {
1232 if (m_genericImpl)
1233 return m_genericImpl->GetItemSpacing();
1234
1235 return wxSize(0, 0);
1236 }
1237
1238 void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
1239 {
1240 if (m_genericImpl)
1241 {
1242 m_genericImpl->SetItemTextColour(item, col);
1243 return;
1244 }
1245
1246 wxListItem info;
1247 info.m_itemId = item;
1248 info.SetTextColour( col );
1249 SetItem( info );
1250 }
1251
1252 wxColour wxListCtrl::GetItemTextColour( long item ) const
1253 {
1254 if (m_genericImpl)
1255 return m_genericImpl->GetItemTextColour(item);
1256
1257 if (m_dbImpl)
1258 {
1259 wxListItem info;
1260 if (GetItem(info))
1261 return info.GetTextColour();
1262 }
1263 return wxNullColour;
1264 }
1265
1266 void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
1267 {
1268 if (m_genericImpl)
1269 {
1270 m_genericImpl->SetItemBackgroundColour(item, col);
1271 return;
1272 }
1273
1274 wxListItem info;
1275 info.m_itemId = item;
1276 info.SetBackgroundColour( col );
1277 SetItem( info );
1278 }
1279
1280 wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
1281 {
1282 if (m_genericImpl)
1283 return m_genericImpl->GetItemBackgroundColour(item);
1284
1285 if (m_dbImpl)
1286 {
1287 wxListItem info;
1288 if (GetItem(info))
1289 return info.GetBackgroundColour();
1290 }
1291 return wxNullColour;
1292 }
1293
1294 void wxListCtrl::SetItemFont( long item, const wxFont &f )
1295 {
1296 if (m_genericImpl)
1297 {
1298 m_genericImpl->SetItemFont(item, f);
1299 return;
1300 }
1301
1302 wxListItem info;
1303 info.m_itemId = item;
1304 info.SetFont( f );
1305 SetItem( info );
1306 }
1307
1308 wxFont wxListCtrl::GetItemFont( long item ) const
1309 {
1310 if (m_genericImpl)
1311 return m_genericImpl->GetItemFont(item);
1312
1313 if (m_dbImpl)
1314 {
1315 wxListItem info;
1316 if (GetItem(info))
1317 return info.GetFont();
1318 }
1319
1320 return wxNullFont;
1321 }
1322
1323 // Gets the number of selected items in the list control
1324 int wxListCtrl::GetSelectedItemCount() const
1325 {
1326 if (m_genericImpl)
1327 return m_genericImpl->GetSelectedItemCount();
1328
1329 if (m_dbImpl)
1330 return m_dbImpl->GetSelectedItemCount(NULL, true);
1331
1332 return 0;
1333 }
1334
1335 // Gets the text colour of the listview
1336 wxColour wxListCtrl::GetTextColour() const
1337 {
1338 if (m_genericImpl)
1339 return m_genericImpl->GetTextColour();
1340
1341 // TODO: we need owner drawn list items to customize text color.
1342 if (m_dbImpl)
1343 return m_textColor;
1344
1345 return wxNullColour;
1346 }
1347
1348 // Sets the text colour of the listview
1349 void wxListCtrl::SetTextColour(const wxColour& col)
1350 {
1351 if (m_genericImpl)
1352 {
1353 m_genericImpl->SetTextColour(col);
1354 return;
1355 }
1356
1357 if (m_dbImpl)
1358 m_textColor = col;
1359 }
1360
1361 // Gets the index of the topmost visible item when in
1362 // list or report view
1363 long wxListCtrl::GetTopItem() const
1364 {
1365 if (m_genericImpl)
1366 return m_genericImpl->GetTopItem();
1367
1368 return 0;
1369 }
1370
1371 // Searches for an item, starting from 'item'.
1372 // 'geometry' is one of
1373 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1374 // 'state' is a state bit flag, one or more of
1375 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1376 // item can be -1 to find the first item that matches the
1377 // specified flags.
1378 // Returns the item or -1 if unsuccessful.
1379 long wxListCtrl::GetNextItem(long item, int geom, int state) const
1380 {
1381 if (m_genericImpl)
1382 return m_genericImpl->GetNextItem(item, geom, state);
1383
1384 if (m_dbImpl && geom == wxLIST_NEXT_ALL && state == wxLIST_STATE_SELECTED )
1385 {
1386 long count = m_dbImpl->MacGetCount() ;
1387 for ( long line = item + 1 ; line < count; line++ )
1388 {
1389 wxMacDataItem* id = m_dbImpl->GetItemFromLine(line);
1390 if ( m_dbImpl->IsItemSelected(id ) )
1391 return line;
1392 }
1393 return -1;
1394 }
1395
1396 return 0;
1397 }
1398
1399
1400 wxImageList *wxListCtrl::GetImageList(int which) const
1401 {
1402 if (m_genericImpl)
1403 return m_genericImpl->GetImageList(which);
1404
1405 if ( which == wxIMAGE_LIST_NORMAL )
1406 {
1407 return m_imageListNormal;
1408 }
1409 else if ( which == wxIMAGE_LIST_SMALL )
1410 {
1411 return m_imageListSmall;
1412 }
1413 else if ( which == wxIMAGE_LIST_STATE )
1414 {
1415 return m_imageListState;
1416 }
1417 return NULL;
1418 }
1419
1420 void wxListCtrl::SetImageList(wxImageList *imageList, int which)
1421 {
1422 if (m_genericImpl)
1423 {
1424 m_genericImpl->SetImageList(imageList, which);
1425 return;
1426 }
1427
1428 if ( which == wxIMAGE_LIST_NORMAL )
1429 {
1430 if (m_ownsImageListNormal) delete m_imageListNormal;
1431 m_imageListNormal = imageList;
1432 m_ownsImageListNormal = false;
1433 }
1434 else if ( which == wxIMAGE_LIST_SMALL )
1435 {
1436 if (m_ownsImageListSmall) delete m_imageListSmall;
1437 m_imageListSmall = imageList;
1438 m_ownsImageListSmall = false;
1439 }
1440 else if ( which == wxIMAGE_LIST_STATE )
1441 {
1442 if (m_ownsImageListState) delete m_imageListState;
1443 m_imageListState = imageList;
1444 m_ownsImageListState = false;
1445 }
1446 }
1447
1448 void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
1449 {
1450 if (m_genericImpl)
1451 {
1452 m_genericImpl->AssignImageList(imageList, which);
1453 return;
1454 }
1455
1456 SetImageList(imageList, which);
1457 if ( which == wxIMAGE_LIST_NORMAL )
1458 m_ownsImageListNormal = true;
1459 else if ( which == wxIMAGE_LIST_SMALL )
1460 m_ownsImageListSmall = true;
1461 else if ( which == wxIMAGE_LIST_STATE )
1462 m_ownsImageListState = true;
1463 }
1464
1465 // ----------------------------------------------------------------------------
1466 // Operations
1467 // ----------------------------------------------------------------------------
1468
1469 // Arranges the items
1470 bool wxListCtrl::Arrange(int flag)
1471 {
1472 if (m_genericImpl)
1473 return m_genericImpl->Arrange(flag);
1474 return false;
1475 }
1476
1477 // Deletes an item
1478 bool wxListCtrl::DeleteItem(long item)
1479 {
1480 if (m_genericImpl)
1481 return m_genericImpl->DeleteItem(item);
1482
1483 if (m_dbImpl)
1484 {
1485 m_dbImpl->MacDelete(item);
1486 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() );
1487 event.SetEventObject( this );
1488 event.m_itemIndex = item;
1489 GetEventHandler()->ProcessEvent( event );
1490
1491 }
1492 return true;
1493 }
1494
1495 // Deletes all items
1496 bool wxListCtrl::DeleteAllItems()
1497 {
1498 if (m_genericImpl)
1499 return m_genericImpl->DeleteAllItems();
1500
1501 if (m_dbImpl)
1502 {
1503 m_dbImpl->MacClear();
1504 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() );
1505 event.SetEventObject( this );
1506 GetEventHandler()->ProcessEvent( event );
1507 }
1508 return true;
1509 }
1510
1511 // Deletes all items
1512 bool wxListCtrl::DeleteAllColumns()
1513 {
1514 if (m_genericImpl)
1515 return m_genericImpl->DeleteAllColumns();
1516
1517 if (m_dbImpl)
1518 {
1519 UInt32 cols;
1520 m_dbImpl->GetColumnCount(&cols);
1521 for (UInt32 col = 0; col < cols; col++)
1522 {
1523 DeleteColumn(col);
1524 }
1525 }
1526
1527 return true;
1528 }
1529
1530 // Deletes a column
1531 bool wxListCtrl::DeleteColumn(int col)
1532 {
1533 if (m_genericImpl)
1534 return m_genericImpl->DeleteColumn(col);
1535
1536 if (m_dbImpl)
1537 {
1538 OSStatus err = m_dbImpl->RemoveColumn(col);
1539 return err == noErr;
1540 }
1541
1542 return true;
1543 }
1544
1545 // Clears items, and columns if there are any.
1546 void wxListCtrl::ClearAll()
1547 {
1548 if (m_genericImpl)
1549 {
1550 m_genericImpl->ClearAll();
1551 return;
1552 }
1553
1554 if (m_dbImpl)
1555 {
1556 DeleteAllItems();
1557 DeleteAllColumns();
1558 }
1559 }
1560
1561 wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass)
1562 {
1563 if (m_genericImpl)
1564 return m_genericImpl->EditLabel(item, textControlClass);
1565
1566 if (m_dbImpl)
1567 {
1568 wxCHECK_MSG( (item >= 0) && ((long)item < GetItemCount()), NULL,
1569 wxT("wrong index in wxListCtrl::EditLabel()") );
1570
1571 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
1572 wxT("EditLabel() needs a text control") );
1573
1574 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1575 le.SetEventObject( this );
1576 le.m_itemIndex = item;
1577 le.m_col = 0;
1578 GetItem( le.m_item );
1579
1580 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
1581 {
1582 // vetoed by user code
1583 return NULL;
1584 }
1585
1586 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
1587 m_textctrlWrapper = new wxListCtrlTextCtrlWrapper(this, text, item);
1588 return m_textctrlWrapper->GetText();
1589 }
1590 return NULL;
1591 }
1592
1593 // End label editing, optionally cancelling the edit
1594 bool wxListCtrl::EndEditLabel(bool cancel)
1595 {
1596 // TODO: generic impl. doesn't have this method - is it needed for us?
1597 if (m_genericImpl)
1598 return true; // m_genericImpl->EndEditLabel(cancel);
1599
1600 if (m_dbImpl)
1601 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) );
1602 return true;
1603 }
1604
1605 // Ensures this item is visible
1606 bool wxListCtrl::EnsureVisible(long item)
1607 {
1608 if (m_genericImpl)
1609 return m_genericImpl->EnsureVisible(item);
1610
1611 if (m_dbImpl)
1612 {
1613 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
1614 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
1615 }
1616
1617 return true;
1618 }
1619
1620 // Find an item whose label matches this string, starting from the item after 'start'
1621 // or the beginning if 'start' is -1.
1622 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1623 {
1624 if (m_genericImpl)
1625 return m_genericImpl->FindItem(start, str, partial);
1626
1627 return -1;
1628 }
1629
1630 // Find an item whose data matches this data, starting from the item after 'start'
1631 // or the beginning if 'start' is -1.
1632 long wxListCtrl::FindItem(long start, long data)
1633 {
1634 if (m_genericImpl)
1635 return m_genericImpl->FindItem(start, data);
1636
1637 long idx = start + 1;
1638 long count = GetItemCount();
1639
1640 while (idx < count)
1641 {
1642 if (GetItemData(idx) == data)
1643 return idx;
1644 idx++;
1645 };
1646
1647 return -1;
1648 }
1649
1650 // Find an item nearest this position in the specified direction, starting from
1651 // the item after 'start' or the beginning if 'start' is -1.
1652 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1653 {
1654 if (m_genericImpl)
1655 return m_genericImpl->FindItem(start, pt, direction);
1656 return -1;
1657 }
1658
1659 // Determines which item (if any) is at the specified point,
1660 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1661 long
1662 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1663 {
1664 if (m_genericImpl)
1665 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1666
1667 flags = wxLIST_HITTEST_NOWHERE;
1668 if (m_dbImpl)
1669 {
1670 int colHeaderHeight = 22; // TODO: Find a way to get this value from the db control?
1671 UInt16 rowHeight = 0;
1672 m_dbImpl->GetDefaultRowHeight(&rowHeight);
1673
1674 int y = point.y;
1675 // get the actual row by taking scroll position into account
1676 UInt32 offsetX, offsetY;
1677 m_dbImpl->GetScrollPosition( &offsetY, &offsetX );
1678 y += offsetY;
1679
1680 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER) )
1681 y -= colHeaderHeight;
1682
1683 int row = y / rowHeight;
1684 DataBrowserItemID id;
1685 m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id );
1686
1687 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1688 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
1689 {
1690 wxMacListCtrlItem* lcItem;
1691 lcItem = (wxMacListCtrlItem*) id;
1692 if (lcItem)
1693 {
1694 flags = wxLIST_HITTEST_ONITEM;
1695 return row;
1696 }
1697 }
1698 else
1699 {
1700 if (row < GetItemCount() )
1701 {
1702 flags = wxLIST_HITTEST_ONITEM;
1703 return row;
1704 }
1705 }
1706
1707 }
1708 return -1;
1709 }
1710
1711
1712 // Inserts an item, returning the index of the new item if successful,
1713 // -1 otherwise.
1714 long wxListCtrl::InsertItem(wxListItem& info)
1715 {
1716 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1717
1718 if (m_genericImpl)
1719 return m_genericImpl->InsertItem(info);
1720
1721 if (m_dbImpl)
1722 {
1723 int count = GetItemCount();
1724
1725 if (info.m_itemId > count)
1726 info.m_itemId = count;
1727
1728 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1729 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1730 event.SetEventObject( this );
1731 event.m_itemIndex = info.m_itemId;
1732 GetEventHandler()->ProcessEvent( event );
1733 }
1734
1735 return info.m_itemId;
1736 }
1737
1738 long wxListCtrl::InsertItem(long index, const wxString& label)
1739 {
1740 if (m_genericImpl)
1741 return m_genericImpl->InsertItem(index, label);
1742
1743 wxListItem info;
1744 info.m_text = label;
1745 info.m_mask = wxLIST_MASK_TEXT;
1746 info.m_itemId = index;
1747 return InsertItem(info);
1748 }
1749
1750 // Inserts an image item
1751 long wxListCtrl::InsertItem(long index, int imageIndex)
1752 {
1753 if (m_genericImpl)
1754 return m_genericImpl->InsertItem(index, imageIndex);
1755
1756 wxListItem info;
1757 info.m_image = imageIndex;
1758 info.m_mask = wxLIST_MASK_IMAGE;
1759 info.m_itemId = index;
1760 return InsertItem(info);
1761 }
1762
1763 // Inserts an image/string item
1764 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1765 {
1766 if (m_genericImpl)
1767 return m_genericImpl->InsertItem(index, label, imageIndex);
1768
1769 wxListItem info;
1770 info.m_image = imageIndex;
1771 info.m_text = label;
1772 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1773 info.m_itemId = index;
1774 return InsertItem(info);
1775 }
1776
1777 // For list view mode (only), inserts a column.
1778 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1779 {
1780 if (m_genericImpl)
1781 return m_genericImpl->InsertColumn(col, item);
1782
1783 if (m_dbImpl)
1784 {
1785 int width = item.GetWidth();
1786 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1787 width = 150;
1788
1789 DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType;
1790 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1791 if (imageList && imageList->GetImageCount() > 0)
1792 {
1793 wxBitmap bmp = imageList->GetBitmap(0);
1794 //if (bmp.Ok())
1795 // type = kDataBrowserIconAndTextType;
1796 }
1797
1798 SInt16 just = teFlushDefault;
1799 if (item.GetMask() & wxLIST_MASK_FORMAT)
1800 {
1801 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1802 just = teFlushLeft;
1803 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1804 just = teCenter;
1805 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1806 just = teFlushRight;
1807 }
1808 m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
1809 SetColumn(col, item);
1810
1811 // set/remove options based on the wxListCtrl type.
1812 DataBrowserTableViewColumnID id;
1813 m_dbImpl->GetColumnIDFromIndex(col, &id);
1814 DataBrowserPropertyFlags flags;
1815 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1816 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1817 flags |= kDataBrowserPropertyIsEditable;
1818
1819 if (GetWindowStyleFlag() & wxLC_VIRTUAL){
1820 flags &= ~kDataBrowserListViewSortableColumn;
1821 }
1822 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1823 }
1824
1825 return col;
1826 }
1827
1828 long wxListCtrl::InsertColumn(long col,
1829 const wxString& heading,
1830 int format,
1831 int width)
1832 {
1833 if (m_genericImpl)
1834 return m_genericImpl->InsertColumn(col, heading, format, width);
1835
1836 wxListItem item;
1837 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1838 item.m_text = heading;
1839 if ( width > -1 )
1840 {
1841 item.m_mask |= wxLIST_MASK_WIDTH;
1842 item.m_width = width;
1843 }
1844 item.m_format = format;
1845
1846 return InsertColumn(col, item);
1847 }
1848
1849 // scroll the control by the given number of pixels (exception: in list view,
1850 // dx is interpreted as number of columns)
1851 bool wxListCtrl::ScrollList(int dx, int dy)
1852 {
1853 if (m_genericImpl)
1854 return m_genericImpl->ScrollList(dx, dy);
1855
1856 if (m_dbImpl)
1857 {
1858 m_dbImpl->SetScrollPosition(dx, dy);
1859 }
1860 return true;
1861 }
1862
1863
1864 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1865 {
1866 if (m_genericImpl)
1867 return m_genericImpl->SortItems(fn, data);
1868
1869 if (m_dbImpl)
1870 {
1871 m_compareFunc = fn;
1872 m_compareFuncData = data;
1873 }
1874
1875 return true;
1876 }
1877
1878 void wxListCtrl::OnRenameTimer()
1879 {
1880 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1881
1882 EditLabel( m_current );
1883 }
1884
1885 bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value)
1886 {
1887 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() );
1888 le.SetEventObject( this );
1889 le.m_itemIndex = itemEdit;
1890
1891 GetItem( le.m_item );
1892 le.m_item.m_text = value;
1893 return !GetEventHandler()->ProcessEvent( le ) ||
1894 le.IsAllowed();
1895 }
1896
1897 void wxListCtrl::OnRenameCancelled(long itemEdit)
1898 {
1899 // let owner know that the edit was cancelled
1900 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1901
1902 le.SetEditCanceled(true);
1903
1904 le.SetEventObject( this );
1905 le.m_itemIndex = itemEdit;
1906
1907 GetItem( le.m_item );
1908 GetEventHandler()->ProcessEvent( le );
1909 }
1910
1911 // ----------------------------------------------------------------------------
1912 // virtual list controls
1913 // ----------------------------------------------------------------------------
1914
1915 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1916 {
1917 // this is a pure virtual function, in fact - which is not really pure
1918 // because the controls which are not virtual don't need to implement it
1919 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1920
1921 return wxEmptyString;
1922 }
1923
1924 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1925 {
1926 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1927 -1,
1928 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1929 return -1;
1930 }
1931
1932 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1933 {
1934 if (!column)
1935 return OnGetItemImage(item);
1936
1937 return -1;
1938 }
1939
1940 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1941 {
1942 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1943 _T("invalid item index in OnGetItemAttr()") );
1944
1945 // no attributes by default
1946 return NULL;
1947 }
1948
1949 void wxListCtrl::SetItemCount(long count)
1950 {
1951 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1952
1953 if (m_genericImpl)
1954 {
1955 m_genericImpl->SetItemCount(count);
1956 return;
1957 }
1958
1959 if (m_dbImpl)
1960 {
1961 // we need to temporarily disable the new item creation notification
1962 // procedure to speed things up
1963 // FIXME: Even this doesn't seem to help much...
1964 DataBrowserCallbacks callbacks;
1965 DataBrowserItemNotificationUPP itemUPP;
1966 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
1967 itemUPP = callbacks.u.v1.itemNotificationCallback;
1968 callbacks.u.v1.itemNotificationCallback = 0;
1969 m_dbImpl->SetCallbacks(&callbacks);
1970 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
1971 count, NULL, kDataBrowserItemNoProperty);
1972 callbacks.u.v1.itemNotificationCallback = itemUPP;
1973 m_dbImpl->SetCallbacks(&callbacks);
1974 }
1975 m_count = count;
1976 }
1977
1978 void wxListCtrl::RefreshItem(long item)
1979 {
1980 if (m_genericImpl)
1981 {
1982 m_genericImpl->RefreshItem(item);
1983 return;
1984 }
1985
1986 wxRect rect;
1987 GetItemRect(item, rect);
1988 RefreshRect(rect);
1989 }
1990
1991 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1992 {
1993 if (m_genericImpl)
1994 {
1995 m_genericImpl->RefreshItems(itemFrom, itemTo);
1996 return;
1997 }
1998
1999 wxRect rect1, rect2;
2000 GetItemRect(itemFrom, rect1);
2001 GetItemRect(itemTo, rect2);
2002
2003 wxRect rect = rect1;
2004 rect.height = rect2.GetBottom() - rect1.GetTop();
2005
2006 RefreshRect(rect);
2007 }
2008
2009
2010 // wxMac internal data structures
2011
2012 wxMacListCtrlItem::~wxMacListCtrlItem()
2013 {
2014 }
2015
2016 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
2017 DataBrowserItemNotification message,
2018 DataBrowserItemDataRef itemData ) const
2019 {
2020
2021 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
2022
2023 // we want to depend on as little as possible to make sure tear-down of controls is safe
2024 if ( message == kDataBrowserItemRemoved)
2025 {
2026 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
2027 {
2028 delete (wxClientData*) (m_data);
2029 }
2030
2031 delete this;
2032 return;
2033 }
2034 else if ( message == kDataBrowserItemAdded )
2035 {
2036 // we don't issue events on adding, the item is not really stored in the list yet, so we
2037 // avoid asserts by gettting out now
2038 return ;
2039 }
2040
2041 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
2042 if ( list )
2043 {
2044 bool trigger = false;
2045
2046 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2047 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2048
2049 event.SetEventObject( list );
2050 event.m_itemIndex = owner->GetLineFromItem( this ) ;
2051 if ( !list->IsVirtual() )
2052 {
2053 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2054 }
2055
2056 switch (message)
2057 {
2058 case kDataBrowserItemDeselected:
2059 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2060 if ( !isSingle )
2061 trigger = !lb->IsSelectionSuppressed();
2062 break;
2063
2064 case kDataBrowserItemSelected:
2065 trigger = !lb->IsSelectionSuppressed();
2066 break;
2067
2068 case kDataBrowserItemDoubleClicked:
2069 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2070 trigger = true;
2071 break;
2072
2073 case kDataBrowserEditStarted :
2074 // TODO : how to veto ?
2075 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2076 trigger = true ;
2077 break ;
2078
2079 case kDataBrowserEditStopped :
2080 // TODO probably trigger only upon the value store callback, because
2081 // here IIRC we cannot veto
2082 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2083 trigger = true ;
2084 break ;
2085
2086 default:
2087 break;
2088 }
2089
2090 if ( trigger )
2091 {
2092 // direct notification is not always having the listbox GetSelection() having in synch with event
2093 wxPostEvent( list->GetEventHandler(), event );
2094 }
2095 }
2096
2097 }
2098
2099 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
2100 : wxMacDataItemBrowserControl( peer, pos, size, style )
2101 {
2102 OSStatus err = noErr;
2103 m_clientDataItemsType = wxClientData_None;
2104 m_isVirtual = false;
2105
2106 if ( style & wxLC_VIRTUAL )
2107 m_isVirtual = true;
2108
2109 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
2110 if ( style & wxLC_SINGLE_SEL )
2111 {
2112 options |= kDataBrowserSelectOnlyOne;
2113 }
2114 else
2115 {
2116 options |= kDataBrowserCmdTogglesSelection;
2117 }
2118
2119 err = SetSelectionFlags( options );
2120 verify_noerr( err );
2121
2122 DataBrowserCustomCallbacks callbacks;
2123 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
2124
2125 if ( gDataBrowserDrawItemUPP == NULL )
2126 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
2127
2128 // if ( gDataBrowserEditItemUPP == NULL )
2129 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2130
2131 if ( gDataBrowserHitTestUPP == NULL )
2132 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
2133
2134 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
2135 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2136 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
2137
2138 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
2139
2140 if ( style & wxLC_LIST )
2141 {
2142 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
2143 verify_noerr( AutoSizeColumns() );
2144 }
2145
2146 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
2147 verify_noerr( SetHeaderButtonHeight( 0 ) );
2148
2149 if ( m_isVirtual )
2150 SetSortProperty( kMinColumnId - 1 );
2151 else
2152 SetSortProperty( kMinColumnId );
2153 if ( style & wxLC_SORT_ASCENDING )
2154 {
2155 m_sortOrder = SortOrder_Text_Ascending;
2156 SetSortOrder( kDataBrowserOrderIncreasing );
2157 }
2158 else if ( style & wxLC_SORT_DESCENDING )
2159 {
2160 m_sortOrder = SortOrder_Text_Descending;
2161 SetSortOrder( kDataBrowserOrderDecreasing );
2162 }
2163 else
2164 {
2165 m_sortOrder = SortOrder_None;
2166 }
2167
2168 if ( style & wxLC_VRULES )
2169 {
2170 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2171 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
2172 #endif
2173 }
2174
2175 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
2176 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
2177 }
2178
2179 pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2180 ControlRef browser,
2181 DataBrowserItemID itemID,
2182 DataBrowserPropertyID property,
2183 CFStringRef theString,
2184 Rect *maxEditTextRect,
2185 Boolean *shrinkToFit)
2186 {
2187 Boolean result = false;
2188 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2189 if ( ctl != 0 )
2190 {
2191 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
2192 theString = CFSTR("Hello!");
2193 }
2194 return result;
2195 }
2196
2197 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2198 DataBrowserItemID itemID,
2199 DataBrowserPropertyID property,
2200 CFStringRef theString,
2201 Rect *maxEditTextRect,
2202 Boolean *shrinkToFit)
2203 {
2204 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2205 return false;
2206 }
2207
2208 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2209 ControlRef browser,
2210 DataBrowserItemID itemID,
2211 DataBrowserPropertyID property,
2212 DataBrowserItemState itemState,
2213 const Rect *itemRect,
2214 SInt16 gdDepth,
2215 Boolean colorDevice)
2216 {
2217 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2218 if ( ctl != 0 )
2219 {
2220 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
2221 }
2222 }
2223
2224 // routines needed for DrawItem
2225 enum
2226 {
2227 kIconWidth = 16,
2228 kIconHeight = 16,
2229 kTextBoxHeight = 14,
2230 kIconTextSpacingV = 2,
2231 kItemPadding = 4,
2232 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
2233 };
2234
2235 static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
2236 {
2237 float textBottom;
2238 float iconH, iconW = 0;
2239 float padding = kItemPadding;
2240 if (hasIcon)
2241 {
2242 iconH = kIconHeight;
2243 iconW = kIconWidth;
2244 padding = padding*2;
2245 }
2246
2247 textBottom = inItemRect.origin.y;
2248
2249 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
2250 textBottom + kIconTextSpacingV, kIconWidth,
2251 kIconHeight);
2252
2253 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
2254 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
2255 inItemRect.size.height - kIconTextSpacingV);
2256 }
2257
2258 void wxMacDataBrowserListCtrlControl::DrawItem(
2259 DataBrowserItemID itemID,
2260 DataBrowserPropertyID property,
2261 DataBrowserItemState itemState,
2262 const Rect *itemRect,
2263 SInt16 gdDepth,
2264 Boolean colorDevice)
2265 {
2266 wxString text;
2267 wxFont font = wxNullFont;
2268 int imgIndex = -1;
2269 short listColumn = property - kMinColumnId;
2270
2271 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2272 wxMacListCtrlItem* lcItem;
2273 wxColour color = *wxBLACK;
2274 wxColour bgColor = wxNullColour;
2275
2276 if (listColumn >= 0)
2277 {
2278 if (!m_isVirtual)
2279 {
2280 lcItem = (wxMacListCtrlItem*) itemID;
2281 if (lcItem->HasColumnInfo(listColumn)){
2282 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2283
2284 // we always use the 0 column to get font and text/background colors.
2285 if (lcItem->HasColumnInfo(0))
2286 {
2287 wxListItem* firstItem = lcItem->GetColumnInfo(0);
2288 color = firstItem->GetTextColour();
2289 bgColor = firstItem->GetBackgroundColour();
2290 font = firstItem->GetFont();
2291 }
2292
2293 if (item->GetMask() & wxLIST_MASK_TEXT)
2294 text = item->GetText();
2295 if (item->GetMask() & wxLIST_MASK_IMAGE)
2296 imgIndex = item->GetImage();
2297 }
2298
2299 }
2300 else
2301 {
2302 text = list->OnGetItemText( (long)itemID-1, listColumn );
2303 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2304 wxListItemAttr* attrs = list->OnGetItemAttr( (long)itemID-1 );
2305 if (attrs)
2306 {
2307 if (attrs->HasBackgroundColour())
2308 bgColor = attrs->GetBackgroundColour();
2309 if (attrs->HasTextColour())
2310 color = attrs->GetTextColour();
2311 if (attrs->HasFont())
2312 font = attrs->GetFont();
2313 }
2314 }
2315 }
2316
2317 wxColour listBgColor = list->GetBackgroundColour();
2318 if (bgColor == wxNullColour)
2319 bgColor = listBgColor;
2320
2321 wxFont listFont = list->GetFont();
2322 if (font == wxNullFont)
2323 font = listFont;
2324
2325 wxMacCFStringHolder cfString;
2326 cfString.Assign( text, wxLocale::GetSystemEncoding() );
2327
2328 Rect enclosingRect;
2329 CGRect enclosingCGRect, iconCGRect, textCGRect;
2330 Boolean active;
2331 ThemeDrawingState savedState = NULL;
2332 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
2333 RGBColor labelColor;
2334
2335 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
2336 &enclosingRect);
2337
2338 enclosingCGRect = CGRectMake(enclosingRect.left,
2339 enclosingRect.top,
2340 enclosingRect.right - enclosingRect.left,
2341 enclosingRect.bottom - enclosingRect.top);
2342
2343 active = IsControlActive(GetControlRef());
2344
2345 if (itemState == kDataBrowserItemIsSelected)
2346 {
2347 RGBColor foregroundColor;
2348
2349 GetThemeDrawingState(&savedState);
2350
2351 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &foregroundColor);
2352 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
2353
2354 CGContextSaveGState(context);
2355
2356 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2357 (float)foregroundColor.green / (float)USHRT_MAX,
2358 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2359 CGContextFillRect(context, enclosingCGRect);
2360
2361 CGContextRestoreGState(context);
2362 }
2363 else
2364 {
2365
2366 if (color.Ok())
2367 labelColor = MAC_WXCOLORREF( color.GetPixel() );
2368 else if (list->GetTextColour().Ok())
2369 labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
2370 else
2371 {
2372 labelColor.red = 0;
2373 labelColor.green = 0;
2374 labelColor.blue = 0;
2375 }
2376
2377 if (bgColor.Ok())
2378 {
2379 RGBColor foregroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
2380 CGContextSaveGState(context);
2381
2382 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2383 (float)foregroundColor.green / (float)USHRT_MAX,
2384 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2385 CGContextFillRect(context, enclosingCGRect);
2386
2387 CGContextRestoreGState(context);
2388 }
2389 }
2390
2391 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2392
2393 if (imgIndex != -1)
2394 {
2395 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2396 if (imageList && imageList->GetImageCount() > 0){
2397 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2398 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2399
2400 RGBColor iconLabel;
2401 iconLabel.red = 0;
2402 iconLabel.green = 0;
2403 iconLabel.blue = 0;
2404
2405 CGContextSaveGState(context);
2406 CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
2407 CGContextScaleCTM(context,1.0f,-1.0f);
2408 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2409 active ? kTransformNone : kTransformDisabled, &iconLabel,
2410 kPlotIconRefNormalFlags, icon);
2411
2412 CGContextRestoreGState(context);
2413 }
2414 }
2415
2416 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2417 UInt16 fontID = kThemeViewsFont;
2418
2419 if (font.Ok())
2420 {
2421 if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
2422 fontID = font.MacGetThemeFontID();
2423
2424 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2425 #ifndef __LP64__
2426 ::TextSize( (short)(font.MacGetFontSize()) ) ;
2427 ::TextFace( font.MacGetFontStyle() ) ;
2428 #endif
2429 }
2430
2431 wxListItem item;
2432 list->GetColumn(listColumn, item);
2433 if (item.GetMask() & wxLIST_MASK_FORMAT)
2434 {
2435 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
2436 hFlush = kHIThemeTextHorizontalFlushLeft;
2437 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
2438 hFlush = kHIThemeTextHorizontalFlushCenter;
2439 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
2440 {
2441 hFlush = kHIThemeTextHorizontalFlushRight;
2442 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
2443 }
2444 }
2445
2446 HIThemeTextInfo info;
2447 info.version = kHIThemeTextInfoVersionZero;
2448 info.state = active ? kThemeStateActive : kThemeStateInactive;
2449 info.fontID = fontID;
2450 info.horizontalFlushness = hFlush;
2451 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
2452 info.options = kHIThemeTextBoxOptionNone;
2453 info.truncationPosition = kHIThemeTextTruncationEnd;
2454 info.truncationMaxLines = 1;
2455
2456 CGContextSaveGState(context);
2457 CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
2458 (float)labelColor.green / (float)USHRT_MAX,
2459 (float)labelColor.blue / (float)USHRT_MAX, 1.0);
2460
2461 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
2462
2463 CGContextRestoreGState(context);
2464
2465 if (savedState != NULL)
2466 SetThemeDrawingState(savedState, true);
2467 }
2468
2469 OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
2470 DataBrowserPropertyID property,
2471 DataBrowserItemDataRef itemData,
2472 Boolean changeValue )
2473 {
2474 wxString text;
2475 int imgIndex = -1;
2476 short listColumn = property - kMinColumnId;
2477
2478 OSStatus err = errDataBrowserPropertyNotSupported;
2479 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2480 wxMacListCtrlItem* lcItem;
2481
2482 if (listColumn >= 0)
2483 {
2484 if (!m_isVirtual)
2485 {
2486 lcItem = (wxMacListCtrlItem*) itemID;
2487 if (lcItem->HasColumnInfo(listColumn)){
2488 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2489 if (item->GetMask() & wxLIST_MASK_TEXT)
2490 text = item->GetText();
2491 if (item->GetMask() & wxLIST_MASK_IMAGE)
2492 imgIndex = item->GetImage();
2493 }
2494 }
2495 else
2496 {
2497 text = list->OnGetItemText( (long)itemID-1, listColumn );
2498 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2499 }
2500 }
2501
2502 if ( !changeValue )
2503 {
2504 switch (property)
2505 {
2506 case kDataBrowserItemIsEditableProperty :
2507 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
2508 {
2509 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
2510 err = noErr ;
2511 }
2512 break ;
2513 default :
2514 if ( property >= kMinColumnId )
2515 {
2516 wxMacCFStringHolder cfStr;
2517
2518 if (text){
2519 cfStr.Assign( text, wxLocale::GetSystemEncoding() );
2520 err = ::SetDataBrowserItemDataText( itemData, cfStr );
2521 err = noErr;
2522 }
2523
2524
2525
2526 if ( imgIndex != -1 )
2527 {
2528 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2529 if (imageList && imageList->GetImageCount() > 0){
2530 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2531 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2532 ::SetDataBrowserItemDataIcon(itemData, icon);
2533 }
2534 }
2535
2536 }
2537 break ;
2538 }
2539
2540 }
2541 else
2542 {
2543 switch (property)
2544 {
2545 default:
2546 if ( property >= kMinColumnId )
2547 {
2548 short listColumn = property - kMinColumnId;
2549
2550 // TODO probably send the 'end edit' from here, as we
2551 // can then deal with the veto
2552 CFStringRef sr ;
2553 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
2554 wxMacCFStringHolder cfStr(sr) ;;
2555 if (m_isVirtual)
2556 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
2557 else
2558 {
2559 if (lcItem)
2560 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
2561 }
2562 err = noErr ;
2563 }
2564 break;
2565 }
2566 }
2567 return err;
2568 }
2569
2570 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
2571 DataBrowserItemNotification message,
2572 DataBrowserItemDataRef itemData )
2573 {
2574 // we want to depend on as little as possible to make sure tear-down of controls is safe
2575 if ( message == kDataBrowserItemRemoved)
2576 {
2577 // make sure MacDelete does the proper teardown.
2578 return;
2579 }
2580 else if ( message == kDataBrowserItemAdded )
2581 {
2582 // we don't issue events on adding, the item is not really stored in the list yet, so we
2583 // avoid asserts by getting out now
2584 return ;
2585 }
2586
2587 wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
2588 if ( list )
2589 {
2590 bool trigger = false;
2591
2592 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2593 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2594
2595 event.SetEventObject( list );
2596 if ( !list->IsVirtual() )
2597 {
2598 DataBrowserTableViewRowIndex result = 0;
2599 verify_noerr( GetItemRow( itemID, &result ) ) ;
2600 event.m_itemIndex = result;
2601
2602 if (event.m_itemIndex >= 0)
2603 MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2604 }
2605 else
2606 {
2607 event.m_itemIndex = (long)itemID;
2608 }
2609
2610 switch (message)
2611 {
2612 case kDataBrowserItemDeselected:
2613 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2614 if ( !isSingle )
2615 trigger = !IsSelectionSuppressed();
2616 break;
2617
2618 case kDataBrowserItemSelected:
2619 trigger = !IsSelectionSuppressed();
2620
2621 break;
2622
2623 case kDataBrowserItemDoubleClicked:
2624 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2625 trigger = true;
2626 break;
2627
2628 case kDataBrowserEditStarted :
2629 // TODO : how to veto ?
2630 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2631 trigger = true ;
2632 break ;
2633
2634 case kDataBrowserEditStopped :
2635 // TODO probably trigger only upon the value store callback, because
2636 // here IIRC we cannot veto
2637 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2638 trigger = true ;
2639 break ;
2640
2641 default:
2642 break;
2643 }
2644
2645 if ( trigger )
2646 {
2647 // direct notification is not always having the listbox GetSelection() having in synch with event
2648 wxPostEvent( list->GetEventHandler(), event );
2649 }
2650 }
2651 }
2652
2653 Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
2654 DataBrowserItemID itemTwoID,
2655 DataBrowserPropertyID sortProperty)
2656 {
2657
2658 bool retval = false;
2659 wxString itemText;
2660 wxString otherItemText;
2661 int colId = sortProperty - kMinColumnId;
2662 long itemNum = 0;
2663 long otherItemNum = 0;
2664
2665 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2666
2667 // means we need to
2668 if (colId >= 0)
2669 {
2670 if (!m_isVirtual)
2671 {
2672 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
2673 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
2674 wxListCtrlCompare func = list->GetCompareFunc();
2675 if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
2676 return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
2677
2678 itemNum = item->GetOrder();
2679 otherItemNum = otherItem->GetOrder();
2680 if (item->HasColumnInfo(colId))
2681 itemText = item->GetColumnInfo(colId)->GetText();
2682 if (otherItem->HasColumnInfo(colId))
2683 otherItemText = otherItem->GetColumnInfo(colId)->GetText();
2684 }
2685 else
2686 {
2687 itemNum = (long)itemOneID;
2688 otherItemNum = (long)itemTwoID;
2689 itemText = list->OnGetItemText( itemNum-1, colId );
2690 otherItemText = list->OnGetItemText( otherItemNum-1, colId );
2691
2692 }
2693
2694 DataBrowserSortOrder sort;
2695 verify_noerr(GetSortOrder(&sort));
2696
2697 if ( sort == kDataBrowserOrderIncreasing )
2698 {
2699 retval = itemText.CmpNoCase( otherItemText ) > 0;
2700 }
2701 else if ( sort == kDataBrowserOrderDecreasing )
2702 {
2703 retval = itemText.CmpNoCase( otherItemText ) < 0;
2704 }
2705 }
2706 else{
2707 // fallback for undefined cases
2708 retval = itemOneID < itemTwoID;
2709 }
2710
2711 return retval;
2712 }
2713
2714 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2715 {
2716 }
2717
2718 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
2719 {
2720 wxMacDataItem* dataItem = GetItemFromLine(row);
2721 if (item)
2722 {
2723 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2724 listItem->SetColumnInfo( column, item );
2725 UpdateState(dataItem, item);
2726 }
2727 }
2728
2729 // apply changes that need to happen immediately, rather than when the
2730 // databrowser control fires a callback.
2731 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
2732 {
2733 bool isSelected = IsItemSelected( dataItem );
2734 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
2735
2736 // toggle the selection state if wxListInfo state and actual state don't match.
2737 if ( isSelected != isSelectedState )
2738 {
2739 DataBrowserSetOption options = kDataBrowserItemsAdd;
2740 if (!isSelectedState)
2741 options = kDataBrowserItemsRemove;
2742 SetSelectedItem(dataItem, options);
2743 }
2744 // TODO: Set column width if item width > than current column width
2745 }
2746
2747 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
2748 {
2749 wxMacDataItem* dataItem = GetItemFromLine(row);
2750 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2751 //if (item)
2752 {
2753 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2754 wxListItem* oldItem = listItem->GetColumnInfo( column );
2755
2756 long mask = item.GetMask();
2757 if ( !mask )
2758 // by default, get everything for backwards compatibility
2759 mask = -1;
2760
2761 if ( mask & wxLIST_MASK_TEXT )
2762 item.SetText(oldItem->GetText());
2763 if ( mask & wxLIST_MASK_IMAGE )
2764 item.SetImage(oldItem->GetImage());
2765 if ( mask & wxLIST_MASK_DATA )
2766 item.SetData(oldItem->GetData());
2767 if ( mask & wxLIST_MASK_STATE )
2768 item.SetState(oldItem->GetState());
2769 if ( mask & wxLIST_MASK_WIDTH )
2770 item.SetWidth(oldItem->GetWidth());
2771 if ( mask & wxLIST_MASK_FORMAT )
2772 item.SetAlign(oldItem->GetAlign());
2773
2774 item.SetTextColour(oldItem->GetTextColour());
2775 item.SetBackgroundColour(oldItem->GetBackgroundColour());
2776 item.SetFont(oldItem->GetFont());
2777 }
2778 }
2779
2780 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
2781 {
2782 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
2783 MacSetColumnInfo(n, 0, item);
2784 }
2785
2786 wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem()
2787 {
2788 return new wxMacListCtrlItem();
2789 }
2790
2791 wxMacListCtrlItem::wxMacListCtrlItem()
2792 {
2793 m_rowItems = wxListItemList();
2794 }
2795
2796 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
2797 {
2798 return GetColumnInfo(column)->GetImage();
2799 }
2800
2801 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
2802 {
2803 GetColumnInfo(column)->SetImage(imageIndex);
2804 }
2805
2806 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
2807 {
2808 if ( column == 0 )
2809 return GetLabel();
2810
2811 return GetColumnInfo(column)->GetText();
2812 }
2813
2814 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
2815 {
2816 GetColumnInfo(column)->SetText(text);
2817
2818 // for compatibility with superclass APIs
2819 if ( column == 0 )
2820 SetLabel(text);
2821 }
2822
2823 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
2824 {
2825 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
2826 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
2827
2828 return node->GetData();
2829 }
2830
2831 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
2832 {
2833 return m_rowItems.GetCount() > column;
2834 }
2835
2836 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
2837 {
2838
2839 if ( column >= m_rowItems.GetCount() )
2840 {
2841 wxListItem* listItem = new wxListItem(*item);
2842 m_rowItems.Append( listItem );
2843 }
2844 else
2845 {
2846 wxListItem* listItem = GetColumnInfo( column );
2847 long mask = item->GetMask();
2848 if (mask & wxLIST_MASK_TEXT)
2849 listItem->SetText(item->GetText());
2850 if (mask & wxLIST_MASK_DATA)
2851 listItem->SetData(item->GetData());
2852 if (mask & wxLIST_MASK_IMAGE)
2853 listItem->SetImage(item->GetImage());
2854 if (mask & wxLIST_MASK_STATE)
2855 listItem->SetState(item->GetState());
2856 if (mask & wxLIST_MASK_FORMAT)
2857 listItem->SetAlign(item->GetAlign());
2858 if (mask & wxLIST_MASK_WIDTH)
2859 listItem->SetWidth(item->GetWidth());
2860
2861 listItem->SetTextColour(item->GetTextColour());
2862 listItem->SetBackgroundColour(item->GetBackgroundColour());
2863 listItem->SetFont(item->GetFont());
2864 }
2865 }
2866
2867 #endif // wxUSE_LISTCTRL