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