]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/listctrl_mac.cpp
af509328045803cefd4f75a689087dea6bc402d4
[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 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1576 le.SetEventObject( this );
1577 le.m_itemIndex = item;
1578 le.m_col = 0;
1579 GetItem( le.m_item );
1580
1581 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
1582 {
1583 // vetoed by user code
1584 return NULL;
1585 }
1586
1587 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
1588 m_textctrlWrapper = new wxListCtrlTextCtrlWrapper(this, text, item);
1589 return m_textctrlWrapper->GetText();
1590 }
1591 return NULL;
1592 }
1593
1594 // End label editing, optionally cancelling the edit
1595 bool wxListCtrl::EndEditLabel(bool cancel)
1596 {
1597 // TODO: generic impl. doesn't have this method - is it needed for us?
1598 if (m_genericImpl)
1599 return true; // m_genericImpl->EndEditLabel(cancel);
1600
1601 if (m_dbImpl)
1602 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) );
1603 return true;
1604 }
1605
1606 // Ensures this item is visible
1607 bool wxListCtrl::EnsureVisible(long item)
1608 {
1609 if (m_genericImpl)
1610 return m_genericImpl->EnsureVisible(item);
1611
1612 if (m_dbImpl)
1613 {
1614 wxMacDataItem* dataItem = m_dbImpl->GetItemFromLine(item);
1615 m_dbImpl->RevealItem(dataItem, kDataBrowserRevealWithoutSelecting);
1616 }
1617
1618 return true;
1619 }
1620
1621 // Find an item whose label matches this string, starting from the item after 'start'
1622 // or the beginning if 'start' is -1.
1623 long wxListCtrl::FindItem(long start, const wxString& str, bool partial)
1624 {
1625 if (m_genericImpl)
1626 return m_genericImpl->FindItem(start, str, partial);
1627
1628 return -1;
1629 }
1630
1631 // Find an item whose data matches this data, starting from the item after 'start'
1632 // or the beginning if 'start' is -1.
1633 long wxListCtrl::FindItem(long start, long data)
1634 {
1635 if (m_genericImpl)
1636 return m_genericImpl->FindItem(start, data);
1637
1638 long idx = start + 1;
1639 long count = GetItemCount();
1640
1641 while (idx < count)
1642 {
1643 if (GetItemData(idx) == data)
1644 return idx;
1645 idx++;
1646 };
1647
1648 return -1;
1649 }
1650
1651 // Find an item nearest this position in the specified direction, starting from
1652 // the item after 'start' or the beginning if 'start' is -1.
1653 long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction)
1654 {
1655 if (m_genericImpl)
1656 return m_genericImpl->FindItem(start, pt, direction);
1657 return -1;
1658 }
1659
1660 // Determines which item (if any) is at the specified point,
1661 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1662 long
1663 wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
1664 {
1665 if (m_genericImpl)
1666 return m_genericImpl->HitTest(point, flags, ptrSubItem);
1667
1668 flags = wxLIST_HITTEST_NOWHERE;
1669 if (m_dbImpl)
1670 {
1671 int colHeaderHeight = 22; // TODO: Find a way to get this value from the db control?
1672 UInt16 rowHeight = 0;
1673 m_dbImpl->GetDefaultRowHeight(&rowHeight);
1674
1675 int y = point.y;
1676 // get the actual row by taking scroll position into account
1677 UInt32 offsetX, offsetY;
1678 m_dbImpl->GetScrollPosition( &offsetY, &offsetX );
1679 y += offsetY;
1680
1681 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER) )
1682 y -= colHeaderHeight;
1683
1684 int row = y / rowHeight;
1685 DataBrowserItemID id;
1686 m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id );
1687
1688 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1689 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
1690 {
1691 wxMacListCtrlItem* lcItem;
1692 lcItem = (wxMacListCtrlItem*) id;
1693 if (lcItem)
1694 {
1695 flags = wxLIST_HITTEST_ONITEM;
1696 return row;
1697 }
1698 }
1699 else
1700 {
1701 if (row < GetItemCount() )
1702 {
1703 flags = wxLIST_HITTEST_ONITEM;
1704 return row;
1705 }
1706 }
1707
1708 }
1709 return -1;
1710 }
1711
1712
1713 // Inserts an item, returning the index of the new item if successful,
1714 // -1 otherwise.
1715 long wxListCtrl::InsertItem(wxListItem& info)
1716 {
1717 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1718
1719 if (m_genericImpl)
1720 return m_genericImpl->InsertItem(info);
1721
1722 if (m_dbImpl)
1723 {
1724 int count = GetItemCount();
1725
1726 if (info.m_itemId > count)
1727 info.m_itemId = count;
1728
1729 m_dbImpl->MacInsertItem(info.m_itemId, &info );
1730 wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() );
1731 event.SetEventObject( this );
1732 event.m_itemIndex = info.m_itemId;
1733 GetEventHandler()->ProcessEvent( event );
1734 }
1735
1736 return info.m_itemId;
1737 }
1738
1739 long wxListCtrl::InsertItem(long index, const wxString& label)
1740 {
1741 if (m_genericImpl)
1742 return m_genericImpl->InsertItem(index, label);
1743
1744 wxListItem info;
1745 info.m_text = label;
1746 info.m_mask = wxLIST_MASK_TEXT;
1747 info.m_itemId = index;
1748 return InsertItem(info);
1749 }
1750
1751 // Inserts an image item
1752 long wxListCtrl::InsertItem(long index, int imageIndex)
1753 {
1754 if (m_genericImpl)
1755 return m_genericImpl->InsertItem(index, imageIndex);
1756
1757 wxListItem info;
1758 info.m_image = imageIndex;
1759 info.m_mask = wxLIST_MASK_IMAGE;
1760 info.m_itemId = index;
1761 return InsertItem(info);
1762 }
1763
1764 // Inserts an image/string item
1765 long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex)
1766 {
1767 if (m_genericImpl)
1768 return m_genericImpl->InsertItem(index, label, imageIndex);
1769
1770 wxListItem info;
1771 info.m_image = imageIndex;
1772 info.m_text = label;
1773 info.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT;
1774 info.m_itemId = index;
1775 return InsertItem(info);
1776 }
1777
1778 // For list view mode (only), inserts a column.
1779 long wxListCtrl::InsertColumn(long col, wxListItem& item)
1780 {
1781 if (m_genericImpl)
1782 return m_genericImpl->InsertColumn(col, item);
1783
1784 if (m_dbImpl)
1785 {
1786 int width = item.GetWidth();
1787 if ( !(item.GetMask() & wxLIST_MASK_WIDTH) )
1788 width = 150;
1789
1790 DataBrowserPropertyType type = kDataBrowserCustomType; //kDataBrowserTextType;
1791 wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
1792 if (imageList && imageList->GetImageCount() > 0)
1793 {
1794 wxBitmap bmp = imageList->GetBitmap(0);
1795 //if (bmp.Ok())
1796 // type = kDataBrowserIconAndTextType;
1797 }
1798
1799 SInt16 just = teFlushDefault;
1800 if (item.GetMask() & wxLIST_MASK_FORMAT)
1801 {
1802 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
1803 just = teFlushLeft;
1804 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
1805 just = teCenter;
1806 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
1807 just = teFlushRight;
1808 }
1809 m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
1810 SetColumn(col, item);
1811
1812 // set/remove options based on the wxListCtrl type.
1813 DataBrowserTableViewColumnID id;
1814 m_dbImpl->GetColumnIDFromIndex(col, &id);
1815 DataBrowserPropertyFlags flags;
1816 verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags));
1817 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS)
1818 flags |= kDataBrowserPropertyIsEditable;
1819
1820 if (GetWindowStyleFlag() & wxLC_VIRTUAL){
1821 flags &= ~kDataBrowserListViewSortableColumn;
1822 }
1823 verify_noerr(m_dbImpl->SetPropertyFlags(id, flags));
1824 }
1825
1826 return col;
1827 }
1828
1829 long wxListCtrl::InsertColumn(long col,
1830 const wxString& heading,
1831 int format,
1832 int width)
1833 {
1834 if (m_genericImpl)
1835 return m_genericImpl->InsertColumn(col, heading, format, width);
1836
1837 wxListItem item;
1838 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
1839 item.m_text = heading;
1840 if ( width > -1 )
1841 {
1842 item.m_mask |= wxLIST_MASK_WIDTH;
1843 item.m_width = width;
1844 }
1845 item.m_format = format;
1846
1847 return InsertColumn(col, item);
1848 }
1849
1850 // scroll the control by the given number of pixels (exception: in list view,
1851 // dx is interpreted as number of columns)
1852 bool wxListCtrl::ScrollList(int dx, int dy)
1853 {
1854 if (m_genericImpl)
1855 return m_genericImpl->ScrollList(dx, dy);
1856
1857 if (m_dbImpl)
1858 {
1859 m_dbImpl->SetScrollPosition(dx, dy);
1860 }
1861 return true;
1862 }
1863
1864
1865 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
1866 {
1867 if (m_genericImpl)
1868 return m_genericImpl->SortItems(fn, data);
1869
1870 if (m_dbImpl)
1871 {
1872 m_compareFunc = fn;
1873 m_compareFuncData = data;
1874 }
1875
1876 return true;
1877 }
1878
1879 void wxListCtrl::OnRenameTimer()
1880 {
1881 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
1882
1883 EditLabel( m_current );
1884 }
1885
1886 bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value)
1887 {
1888 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() );
1889 le.SetEventObject( this );
1890 le.m_itemIndex = itemEdit;
1891
1892 GetItem( le.m_item );
1893 le.m_item.m_text = value;
1894 return !GetEventHandler()->ProcessEvent( le ) ||
1895 le.IsAllowed();
1896 }
1897
1898 void wxListCtrl::OnRenameCancelled(long itemEdit)
1899 {
1900 // let owner know that the edit was cancelled
1901 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1902
1903 le.SetEditCanceled(true);
1904
1905 le.SetEventObject( this );
1906 le.m_itemIndex = itemEdit;
1907
1908 GetItem( le.m_item );
1909 GetEventHandler()->ProcessEvent( le );
1910 }
1911
1912 // ----------------------------------------------------------------------------
1913 // virtual list controls
1914 // ----------------------------------------------------------------------------
1915
1916 wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
1917 {
1918 // this is a pure virtual function, in fact - which is not really pure
1919 // because the controls which are not virtual don't need to implement it
1920 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1921
1922 return wxEmptyString;
1923 }
1924
1925 int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
1926 {
1927 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
1928 -1,
1929 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1930 return -1;
1931 }
1932
1933 int wxListCtrl::OnGetItemColumnImage(long item, long column) const
1934 {
1935 if (!column)
1936 return OnGetItemImage(item);
1937
1938 return -1;
1939 }
1940
1941 wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
1942 {
1943 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
1944 _T("invalid item index in OnGetItemAttr()") );
1945
1946 // no attributes by default
1947 return NULL;
1948 }
1949
1950 void wxListCtrl::SetItemCount(long count)
1951 {
1952 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1953
1954 if (m_genericImpl)
1955 {
1956 m_genericImpl->SetItemCount(count);
1957 return;
1958 }
1959
1960 if (m_dbImpl)
1961 {
1962 // we need to temporarily disable the new item creation notification
1963 // procedure to speed things up
1964 // FIXME: Even this doesn't seem to help much...
1965 DataBrowserCallbacks callbacks;
1966 DataBrowserItemNotificationUPP itemUPP;
1967 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
1968 itemUPP = callbacks.u.v1.itemNotificationCallback;
1969 callbacks.u.v1.itemNotificationCallback = 0;
1970 m_dbImpl->SetCallbacks(&callbacks);
1971 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
1972 count, NULL, kDataBrowserItemNoProperty);
1973 callbacks.u.v1.itemNotificationCallback = itemUPP;
1974 m_dbImpl->SetCallbacks(&callbacks);
1975 }
1976 m_count = count;
1977 }
1978
1979 void wxListCtrl::RefreshItem(long item)
1980 {
1981 if (m_genericImpl)
1982 {
1983 m_genericImpl->RefreshItem(item);
1984 return;
1985 }
1986
1987 wxRect rect;
1988 GetItemRect(item, rect);
1989 RefreshRect(rect);
1990 }
1991
1992 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
1993 {
1994 if (m_genericImpl)
1995 {
1996 m_genericImpl->RefreshItems(itemFrom, itemTo);
1997 return;
1998 }
1999
2000 wxRect rect1, rect2;
2001 GetItemRect(itemFrom, rect1);
2002 GetItemRect(itemTo, rect2);
2003
2004 wxRect rect = rect1;
2005 rect.height = rect2.GetBottom() - rect1.GetTop();
2006
2007 RefreshRect(rect);
2008 }
2009
2010
2011 // wxMac internal data structures
2012
2013 wxMacListCtrlItem::~wxMacListCtrlItem()
2014 {
2015 }
2016
2017 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
2018 DataBrowserItemNotification message,
2019 DataBrowserItemDataRef itemData ) const
2020 {
2021
2022 wxMacDataBrowserListCtrlControl *lb = dynamic_cast<wxMacDataBrowserListCtrlControl*>(owner);
2023
2024 // we want to depend on as little as possible to make sure tear-down of controls is safe
2025 if ( message == kDataBrowserItemRemoved)
2026 {
2027 if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object )
2028 {
2029 delete (wxClientData*) (m_data);
2030 }
2031
2032 delete this;
2033 return;
2034 }
2035 else if ( message == kDataBrowserItemAdded )
2036 {
2037 // we don't issue events on adding, the item is not really stored in the list yet, so we
2038 // avoid asserts by gettting out now
2039 return ;
2040 }
2041
2042 wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl );
2043 if ( list )
2044 {
2045 bool trigger = false;
2046
2047 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2048 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2049
2050 event.SetEventObject( list );
2051 event.m_itemIndex = owner->GetLineFromItem( this ) ;
2052 if ( !list->IsVirtual() )
2053 {
2054 lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2055 }
2056
2057 switch (message)
2058 {
2059 case kDataBrowserItemDeselected:
2060 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2061 if ( !isSingle )
2062 trigger = !lb->IsSelectionSuppressed();
2063 break;
2064
2065 case kDataBrowserItemSelected:
2066 trigger = !lb->IsSelectionSuppressed();
2067 break;
2068
2069 case kDataBrowserItemDoubleClicked:
2070 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2071 trigger = true;
2072 break;
2073
2074 case kDataBrowserEditStarted :
2075 // TODO : how to veto ?
2076 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2077 trigger = true ;
2078 break ;
2079
2080 case kDataBrowserEditStopped :
2081 // TODO probably trigger only upon the value store callback, because
2082 // here IIRC we cannot veto
2083 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2084 trigger = true ;
2085 break ;
2086
2087 default:
2088 break;
2089 }
2090
2091 if ( trigger )
2092 {
2093 // direct notification is not always having the listbox GetSelection() having in synch with event
2094 wxPostEvent( list->GetEventHandler(), event );
2095 }
2096 }
2097
2098 }
2099
2100 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
2101 : wxMacDataItemBrowserControl( peer, pos, size, style )
2102 {
2103 OSStatus err = noErr;
2104 m_clientDataItemsType = wxClientData_None;
2105 m_isVirtual = false;
2106
2107 if ( style & wxLC_VIRTUAL )
2108 m_isVirtual = true;
2109
2110 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
2111 if ( style & wxLC_SINGLE_SEL )
2112 {
2113 options |= kDataBrowserSelectOnlyOne;
2114 }
2115 else
2116 {
2117 options |= kDataBrowserCmdTogglesSelection;
2118 }
2119
2120 err = SetSelectionFlags( options );
2121 verify_noerr( err );
2122
2123 DataBrowserCustomCallbacks callbacks;
2124 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
2125
2126 if ( gDataBrowserDrawItemUPP == NULL )
2127 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
2128
2129 // if ( gDataBrowserEditItemUPP == NULL )
2130 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
2131
2132 if ( gDataBrowserHitTestUPP == NULL )
2133 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
2134
2135 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
2136 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
2137 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
2138
2139 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
2140
2141 if ( style & wxLC_LIST )
2142 {
2143 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
2144 verify_noerr( AutoSizeColumns() );
2145 }
2146
2147 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
2148 verify_noerr( SetHeaderButtonHeight( 0 ) );
2149
2150 if ( m_isVirtual )
2151 SetSortProperty( kMinColumnId - 1 );
2152 else
2153 SetSortProperty( kMinColumnId );
2154 if ( style & wxLC_SORT_ASCENDING )
2155 {
2156 m_sortOrder = SortOrder_Text_Ascending;
2157 SetSortOrder( kDataBrowserOrderIncreasing );
2158 }
2159 else if ( style & wxLC_SORT_DESCENDING )
2160 {
2161 m_sortOrder = SortOrder_Text_Descending;
2162 SetSortOrder( kDataBrowserOrderDecreasing );
2163 }
2164 else
2165 {
2166 m_sortOrder = SortOrder_None;
2167 }
2168
2169 if ( style & wxLC_VRULES )
2170 {
2171 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2172 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
2173 #endif
2174 }
2175
2176 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
2177 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
2178 }
2179
2180 pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2181 ControlRef browser,
2182 DataBrowserItemID itemID,
2183 DataBrowserPropertyID property,
2184 CFStringRef theString,
2185 Rect *maxEditTextRect,
2186 Boolean *shrinkToFit)
2187 {
2188 Boolean result = false;
2189 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2190 if ( ctl != 0 )
2191 {
2192 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
2193 theString = CFSTR("Hello!");
2194 }
2195 return result;
2196 }
2197
2198 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2199 DataBrowserItemID itemID,
2200 DataBrowserPropertyID property,
2201 CFStringRef theString,
2202 Rect *maxEditTextRect,
2203 Boolean *shrinkToFit)
2204 {
2205 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2206 return false;
2207 }
2208
2209 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2210 ControlRef browser,
2211 DataBrowserItemID itemID,
2212 DataBrowserPropertyID property,
2213 DataBrowserItemState itemState,
2214 const Rect *itemRect,
2215 SInt16 gdDepth,
2216 Boolean colorDevice)
2217 {
2218 wxMacDataBrowserListCtrlControl* ctl = dynamic_cast<wxMacDataBrowserListCtrlControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
2219 if ( ctl != 0 )
2220 {
2221 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
2222 }
2223 }
2224
2225 // routines needed for DrawItem
2226 enum
2227 {
2228 kIconWidth = 16,
2229 kIconHeight = 16,
2230 kTextBoxHeight = 14,
2231 kIconTextSpacingV = 2,
2232 kItemPadding = 4,
2233 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
2234 };
2235
2236 static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
2237 {
2238 float textBottom;
2239 float iconH, iconW = 0;
2240 float padding = kItemPadding;
2241 if (hasIcon)
2242 {
2243 iconH = kIconHeight;
2244 iconW = kIconWidth;
2245 padding = padding*2;
2246 }
2247
2248 textBottom = inItemRect.origin.y;
2249
2250 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
2251 textBottom + kIconTextSpacingV, kIconWidth,
2252 kIconHeight);
2253
2254 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
2255 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
2256 inItemRect.size.height - kIconTextSpacingV);
2257 }
2258
2259 void wxMacDataBrowserListCtrlControl::DrawItem(
2260 DataBrowserItemID itemID,
2261 DataBrowserPropertyID property,
2262 DataBrowserItemState itemState,
2263 const Rect *itemRect,
2264 SInt16 gdDepth,
2265 Boolean colorDevice)
2266 {
2267 wxString text;
2268 wxFont font = wxNullFont;
2269 int imgIndex = -1;
2270 short listColumn = property - kMinColumnId;
2271
2272 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2273 wxMacListCtrlItem* lcItem;
2274 wxColour color = *wxBLACK;
2275 wxColour bgColor = wxNullColour;
2276
2277 if (listColumn >= 0)
2278 {
2279 if (!m_isVirtual)
2280 {
2281 lcItem = (wxMacListCtrlItem*) itemID;
2282 if (lcItem->HasColumnInfo(listColumn)){
2283 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2284
2285 // we always use the 0 column to get font and text/background colors.
2286 if (lcItem->HasColumnInfo(0))
2287 {
2288 wxListItem* firstItem = lcItem->GetColumnInfo(0);
2289 color = firstItem->GetTextColour();
2290 bgColor = firstItem->GetBackgroundColour();
2291 font = firstItem->GetFont();
2292 }
2293
2294 if (item->GetMask() & wxLIST_MASK_TEXT)
2295 text = item->GetText();
2296 if (item->GetMask() & wxLIST_MASK_IMAGE)
2297 imgIndex = item->GetImage();
2298 }
2299
2300 }
2301 else
2302 {
2303 text = list->OnGetItemText( (long)itemID-1, listColumn );
2304 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2305 wxListItemAttr* attrs = list->OnGetItemAttr( (long)itemID-1 );
2306 if (attrs)
2307 {
2308 if (attrs->HasBackgroundColour())
2309 bgColor = attrs->GetBackgroundColour();
2310 if (attrs->HasTextColour())
2311 color = attrs->GetTextColour();
2312 if (attrs->HasFont())
2313 font = attrs->GetFont();
2314 }
2315 }
2316 }
2317
2318 wxColour listBgColor = list->GetBackgroundColour();
2319 if (bgColor == wxNullColour)
2320 bgColor = listBgColor;
2321
2322 wxFont listFont = list->GetFont();
2323 if (font == wxNullFont)
2324 font = listFont;
2325
2326 wxMacCFStringHolder cfString;
2327 cfString.Assign( text, wxLocale::GetSystemEncoding() );
2328
2329 Rect enclosingRect;
2330 CGRect enclosingCGRect, iconCGRect, textCGRect;
2331 Boolean active;
2332 ThemeDrawingState savedState = NULL;
2333 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
2334 RGBColor labelColor;
2335
2336 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
2337 &enclosingRect);
2338
2339 enclosingCGRect = CGRectMake(enclosingRect.left,
2340 enclosingRect.top,
2341 enclosingRect.right - enclosingRect.left,
2342 enclosingRect.bottom - enclosingRect.top);
2343
2344 active = IsControlActive(GetControlRef());
2345
2346 if (itemState == kDataBrowserItemIsSelected)
2347 {
2348 RGBColor foregroundColor;
2349
2350 GetThemeDrawingState(&savedState);
2351
2352 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &foregroundColor);
2353 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
2354
2355 CGContextSaveGState(context);
2356
2357 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2358 (float)foregroundColor.green / (float)USHRT_MAX,
2359 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2360 CGContextFillRect(context, enclosingCGRect);
2361
2362 CGContextRestoreGState(context);
2363 }
2364 else
2365 {
2366
2367 if (color.Ok())
2368 labelColor = MAC_WXCOLORREF( color.GetPixel() );
2369 else if (list->GetTextColour().Ok())
2370 labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
2371 else
2372 {
2373 labelColor.red = 0;
2374 labelColor.green = 0;
2375 labelColor.blue = 0;
2376 }
2377
2378 if (bgColor.Ok())
2379 {
2380 RGBColor foregroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
2381 CGContextSaveGState(context);
2382
2383 CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX,
2384 (float)foregroundColor.green / (float)USHRT_MAX,
2385 (float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
2386 CGContextFillRect(context, enclosingCGRect);
2387
2388 CGContextRestoreGState(context);
2389 }
2390 }
2391
2392 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2393
2394 if (imgIndex != -1)
2395 {
2396 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2397 if (imageList && imageList->GetImageCount() > 0){
2398 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2399 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2400
2401 RGBColor iconLabel;
2402 iconLabel.red = 0;
2403 iconLabel.green = 0;
2404 iconLabel.blue = 0;
2405
2406 CGContextSaveGState(context);
2407 CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
2408 CGContextScaleCTM(context,1.0f,-1.0f);
2409 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2410 active ? kTransformNone : kTransformDisabled, &iconLabel,
2411 kPlotIconRefNormalFlags, icon);
2412
2413 CGContextRestoreGState(context);
2414 }
2415 }
2416
2417 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2418 UInt16 fontID = kThemeViewsFont;
2419
2420 if (font.Ok())
2421 {
2422 if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
2423 fontID = font.MacGetThemeFontID();
2424
2425 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2426 #ifndef __LP64__
2427 ::TextSize( (short)(font.MacGetFontSize()) ) ;
2428 ::TextFace( font.MacGetFontStyle() ) ;
2429 #endif
2430 }
2431
2432 wxListItem item;
2433 list->GetColumn(listColumn, item);
2434 if (item.GetMask() & wxLIST_MASK_FORMAT)
2435 {
2436 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
2437 hFlush = kHIThemeTextHorizontalFlushLeft;
2438 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
2439 hFlush = kHIThemeTextHorizontalFlushCenter;
2440 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
2441 {
2442 hFlush = kHIThemeTextHorizontalFlushRight;
2443 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
2444 }
2445 }
2446
2447 HIThemeTextInfo info;
2448 info.version = kHIThemeTextInfoVersionZero;
2449 info.state = active ? kThemeStateActive : kThemeStateInactive;
2450 info.fontID = fontID;
2451 info.horizontalFlushness = hFlush;
2452 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
2453 info.options = kHIThemeTextBoxOptionNone;
2454 info.truncationPosition = kHIThemeTextTruncationEnd;
2455 info.truncationMaxLines = 1;
2456
2457 CGContextSaveGState(context);
2458 CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
2459 (float)labelColor.green / (float)USHRT_MAX,
2460 (float)labelColor.blue / (float)USHRT_MAX, 1.0);
2461
2462 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
2463
2464 CGContextRestoreGState(context);
2465
2466 if (savedState != NULL)
2467 SetThemeDrawingState(savedState, true);
2468 }
2469
2470 OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
2471 DataBrowserPropertyID property,
2472 DataBrowserItemDataRef itemData,
2473 Boolean changeValue )
2474 {
2475 wxString text;
2476 int imgIndex = -1;
2477 short listColumn = property - kMinColumnId;
2478
2479 OSStatus err = errDataBrowserPropertyNotSupported;
2480 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2481 wxMacListCtrlItem* lcItem;
2482
2483 if (listColumn >= 0)
2484 {
2485 if (!m_isVirtual)
2486 {
2487 lcItem = (wxMacListCtrlItem*) itemID;
2488 if (lcItem->HasColumnInfo(listColumn)){
2489 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2490 if (item->GetMask() & wxLIST_MASK_TEXT)
2491 text = item->GetText();
2492 if (item->GetMask() & wxLIST_MASK_IMAGE)
2493 imgIndex = item->GetImage();
2494 }
2495 }
2496 else
2497 {
2498 text = list->OnGetItemText( (long)itemID-1, listColumn );
2499 imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
2500 }
2501 }
2502
2503 if ( !changeValue )
2504 {
2505 switch (property)
2506 {
2507 case kDataBrowserItemIsEditableProperty :
2508 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
2509 {
2510 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
2511 err = noErr ;
2512 }
2513 break ;
2514 default :
2515 if ( property >= kMinColumnId )
2516 {
2517 wxMacCFStringHolder cfStr;
2518
2519 if (text){
2520 cfStr.Assign( text, wxLocale::GetSystemEncoding() );
2521 err = ::SetDataBrowserItemDataText( itemData, cfStr );
2522 err = noErr;
2523 }
2524
2525
2526
2527 if ( imgIndex != -1 )
2528 {
2529 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
2530 if (imageList && imageList->GetImageCount() > 0){
2531 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2532 IconRef icon = bmp.GetBitmapData()->GetIconRef();
2533 ::SetDataBrowserItemDataIcon(itemData, icon);
2534 }
2535 }
2536
2537 }
2538 break ;
2539 }
2540
2541 }
2542 else
2543 {
2544 switch (property)
2545 {
2546 default:
2547 if ( property >= kMinColumnId )
2548 {
2549 short listColumn = property - kMinColumnId;
2550
2551 // TODO probably send the 'end edit' from here, as we
2552 // can then deal with the veto
2553 CFStringRef sr ;
2554 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
2555 wxMacCFStringHolder cfStr(sr) ;;
2556 if (m_isVirtual)
2557 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
2558 else
2559 {
2560 if (lcItem)
2561 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
2562 }
2563 err = noErr ;
2564 }
2565 break;
2566 }
2567 }
2568 return err;
2569 }
2570
2571 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
2572 DataBrowserItemNotification message,
2573 DataBrowserItemDataRef itemData )
2574 {
2575 // we want to depend on as little as possible to make sure tear-down of controls is safe
2576 if ( message == kDataBrowserItemRemoved)
2577 {
2578 // make sure MacDelete does the proper teardown.
2579 return;
2580 }
2581 else if ( message == kDataBrowserItemAdded )
2582 {
2583 // we don't issue events on adding, the item is not really stored in the list yet, so we
2584 // avoid asserts by getting out now
2585 return ;
2586 }
2587
2588 wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
2589 if ( list )
2590 {
2591 bool trigger = false;
2592
2593 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2594 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2595
2596 event.SetEventObject( list );
2597 if ( !list->IsVirtual() )
2598 {
2599 DataBrowserTableViewRowIndex result = 0;
2600 verify_noerr( GetItemRow( itemID, &result ) ) ;
2601 event.m_itemIndex = result;
2602
2603 if (event.m_itemIndex >= 0)
2604 MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
2605 }
2606 else
2607 {
2608 event.m_itemIndex = (long)itemID;
2609 }
2610
2611 switch (message)
2612 {
2613 case kDataBrowserItemDeselected:
2614 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2615 if ( !isSingle )
2616 trigger = !IsSelectionSuppressed();
2617 break;
2618
2619 case kDataBrowserItemSelected:
2620 trigger = !IsSelectionSuppressed();
2621
2622 break;
2623
2624 case kDataBrowserItemDoubleClicked:
2625 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2626 trigger = true;
2627 break;
2628
2629 case kDataBrowserEditStarted :
2630 // TODO : how to veto ?
2631 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2632 trigger = true ;
2633 break ;
2634
2635 case kDataBrowserEditStopped :
2636 // TODO probably trigger only upon the value store callback, because
2637 // here IIRC we cannot veto
2638 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2639 trigger = true ;
2640 break ;
2641
2642 default:
2643 break;
2644 }
2645
2646 if ( trigger )
2647 {
2648 // direct notification is not always having the listbox GetSelection() having in synch with event
2649 wxPostEvent( list->GetEventHandler(), event );
2650 }
2651 }
2652 }
2653
2654 Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
2655 DataBrowserItemID itemTwoID,
2656 DataBrowserPropertyID sortProperty)
2657 {
2658
2659 bool retval = false;
2660 wxString itemText;
2661 wxString otherItemText;
2662 int colId = sortProperty - kMinColumnId;
2663 long itemNum = 0;
2664 long otherItemNum = 0;
2665
2666 wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
2667
2668 // means we need to
2669 if (colId >= 0)
2670 {
2671 if (!m_isVirtual)
2672 {
2673 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
2674 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
2675 wxListCtrlCompare func = list->GetCompareFunc();
2676 if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
2677 return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
2678
2679 itemNum = item->GetOrder();
2680 otherItemNum = otherItem->GetOrder();
2681 if (item->HasColumnInfo(colId))
2682 itemText = item->GetColumnInfo(colId)->GetText();
2683 if (otherItem->HasColumnInfo(colId))
2684 otherItemText = otherItem->GetColumnInfo(colId)->GetText();
2685 }
2686 else
2687 {
2688 itemNum = (long)itemOneID;
2689 otherItemNum = (long)itemTwoID;
2690 itemText = list->OnGetItemText( itemNum-1, colId );
2691 otherItemText = list->OnGetItemText( otherItemNum-1, colId );
2692
2693 }
2694
2695 DataBrowserSortOrder sort;
2696 verify_noerr(GetSortOrder(&sort));
2697
2698 if ( sort == kDataBrowserOrderIncreasing )
2699 {
2700 retval = itemText.CmpNoCase( otherItemText ) > 0;
2701 }
2702 else if ( sort == kDataBrowserOrderDecreasing )
2703 {
2704 retval = itemText.CmpNoCase( otherItemText ) < 0;
2705 }
2706 }
2707 else{
2708 // fallback for undefined cases
2709 retval = itemOneID < itemTwoID;
2710 }
2711
2712 return retval;
2713 }
2714
2715 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2716 {
2717 }
2718
2719 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
2720 {
2721 wxMacDataItem* dataItem = GetItemFromLine(row);
2722 if (item)
2723 {
2724 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2725 listItem->SetColumnInfo( column, item );
2726 UpdateState(dataItem, item);
2727 }
2728 }
2729
2730 // apply changes that need to happen immediately, rather than when the
2731 // databrowser control fires a callback.
2732 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
2733 {
2734 bool isSelected = IsItemSelected( dataItem );
2735 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
2736
2737 // toggle the selection state if wxListInfo state and actual state don't match.
2738 if ( isSelected != isSelectedState )
2739 {
2740 DataBrowserSetOption options = kDataBrowserItemsAdd;
2741 if (!isSelectedState)
2742 options = kDataBrowserItemsRemove;
2743 SetSelectedItem(dataItem, options);
2744 }
2745 // TODO: Set column width if item width > than current column width
2746 }
2747
2748 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
2749 {
2750 wxMacDataItem* dataItem = GetItemFromLine(row);
2751 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2752 //if (item)
2753 {
2754 wxMacListCtrlItem* listItem = dynamic_cast<wxMacListCtrlItem*>(dataItem);
2755 wxListItem* oldItem = listItem->GetColumnInfo( column );
2756
2757 long mask = item.GetMask();
2758 if ( !mask )
2759 // by default, get everything for backwards compatibility
2760 mask = -1;
2761
2762 if ( mask & wxLIST_MASK_TEXT )
2763 item.SetText(oldItem->GetText());
2764 if ( mask & wxLIST_MASK_IMAGE )
2765 item.SetImage(oldItem->GetImage());
2766 if ( mask & wxLIST_MASK_DATA )
2767 item.SetData(oldItem->GetData());
2768 if ( mask & wxLIST_MASK_STATE )
2769 item.SetState(oldItem->GetState());
2770 if ( mask & wxLIST_MASK_WIDTH )
2771 item.SetWidth(oldItem->GetWidth());
2772 if ( mask & wxLIST_MASK_FORMAT )
2773 item.SetAlign(oldItem->GetAlign());
2774
2775 item.SetTextColour(oldItem->GetTextColour());
2776 item.SetBackgroundColour(oldItem->GetBackgroundColour());
2777 item.SetFont(oldItem->GetFont());
2778 }
2779 }
2780
2781 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
2782 {
2783 wxMacDataItemBrowserControl::MacInsert(n, item->GetText());
2784 MacSetColumnInfo(n, 0, item);
2785 }
2786
2787 wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem()
2788 {
2789 return new wxMacListCtrlItem();
2790 }
2791
2792 wxMacListCtrlItem::wxMacListCtrlItem()
2793 {
2794 m_rowItems = wxListItemList();
2795 }
2796
2797 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
2798 {
2799 return GetColumnInfo(column)->GetImage();
2800 }
2801
2802 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
2803 {
2804 GetColumnInfo(column)->SetImage(imageIndex);
2805 }
2806
2807 const wxString& wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
2808 {
2809 if ( column == 0 )
2810 return GetLabel();
2811
2812 return GetColumnInfo(column)->GetText();
2813 }
2814
2815 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
2816 {
2817 GetColumnInfo(column)->SetText(text);
2818
2819 // for compatibility with superclass APIs
2820 if ( column == 0 )
2821 SetLabel(text);
2822 }
2823
2824 wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
2825 {
2826 wxListItemList::compatibility_iterator node = m_rowItems.Item( column );
2827 wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") );
2828
2829 return node->GetData();
2830 }
2831
2832 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
2833 {
2834 return m_rowItems.GetCount() > column;
2835 }
2836
2837 void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
2838 {
2839
2840 if ( column >= m_rowItems.GetCount() )
2841 {
2842 wxListItem* listItem = new wxListItem(*item);
2843 m_rowItems.Append( listItem );
2844 }
2845 else
2846 {
2847 wxListItem* listItem = GetColumnInfo( column );
2848 long mask = item->GetMask();
2849 if (mask & wxLIST_MASK_TEXT)
2850 listItem->SetText(item->GetText());
2851 if (mask & wxLIST_MASK_DATA)
2852 listItem->SetData(item->GetData());
2853 if (mask & wxLIST_MASK_IMAGE)
2854 listItem->SetImage(item->GetImage());
2855 if (mask & wxLIST_MASK_STATE)
2856 listItem->SetState(item->GetState());
2857 if (mask & wxLIST_MASK_FORMAT)
2858 listItem->SetAlign(item->GetAlign());
2859 if (mask & wxLIST_MASK_WIDTH)
2860 listItem->SetWidth(item->GetWidth());
2861
2862 listItem->SetTextColour(item->GetTextColour());
2863 listItem->SetBackgroundColour(item->GetBackgroundColour());
2864 listItem->SetFont(item->GetFont());
2865 }
2866 }
2867
2868 #endif // wxUSE_LISTCTRL