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