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