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