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