]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/listctrl_mac.cpp
Don't use deprecated NSTableView selectRow:byExtendingSelection: method.
[wxWidgets.git] / src / osx / carbon / listctrl_mac.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/listctrl_mac.cpp
489468fe
SC
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
1f0c8f31 36#include "wx/osx/uma.h"
489468fe
SC
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
45WX_DEFINE_FLAGS( wxListCtrlStyle )
46
47wxBEGIN_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
90wxEND_FLAGS( wxListCtrlStyle )
91
92IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
93
94wxBEGIN_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
98wxEND_PROPERTIES_TABLE()
99
100wxBEGIN_HANDLERS_TABLE(wxListCtrl)
101wxEND_HANDLERS_TABLE()
102
103wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
104
105/*
51c72a7b 106 TODO : Expose more information of a list's layout etc. via appropriate objects (a la NotebookPageInfo)
489468fe
SC
107*/
108#else
109IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
110#endif
111
112IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
113IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
114
115IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
116
117WX_DECLARE_HASH_MAP( int, wxListItem*, wxIntegerHash, wxIntegerEqual, wxListItemList );
118
119#include "wx/listimpl.cpp"
120WX_DEFINE_LIST(wxColumnList)
121
122// so we can check for column clicks
123static const EventTypeSpec eventList[] =
124{
125 { kEventClassControl, kEventControlHit },
126 { kEventClassControl, kEventControlDraw }
127};
128
129static 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);
03647350 151
89c33c48
RR
152 DataBrowserTableViewColumnIndex column = 0;
153 verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef, col, &column ) );
03647350 154
489468fe
SC
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
180DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler )
181
524c47aa 182class wxMacListCtrlItem : public wxMacDataItem
489468fe
SC
183{
184public:
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();
202protected:
203 wxListItemList m_rowItems;
204};
205
206DataBrowserDrawItemUPP gDataBrowserDrawItemUPP = NULL;
207//DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
208DataBrowserHitTestUPP gDataBrowserHitTestUPP = NULL;
209
210// TODO: Make a better name!!
211class wxMacDataBrowserListCtrlControl : public wxMacDataItemBrowserControl
212{
213public:
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
489468fe
SC
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
226protected:
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
284class wxMacListCtrlEventDelegate : public wxEvtHandler
285{
286public:
287 wxMacListCtrlEventDelegate( wxListCtrl* list, int id );
288 virtual bool ProcessEvent( wxEvent& event );
289
290private:
291 wxListCtrl* m_list;
292 int m_id;
293};
294
295wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl* list, int id )
296{
297 m_list = list;
298 m_id = id;
299}
300
301bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event )
302{
1cdb63aa
JS
303 int id = event.GetId();
304 wxObject* obj = event.GetEventObject();
03647350 305
489468fe
SC
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 {
1cdb63aa
JS
313 if (m_list->GetEventHandler()->ProcessEvent( event ))
314 {
315 event.SetId(id);
316 event.SetEventObject(obj);
489468fe 317 return true;
1cdb63aa 318 }
489468fe 319 }
1cdb63aa
JS
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;
489468fe
SC
327}
328
329//-----------------------------------------------------------------------------
330// wxListCtrlRenameTimer (internal)
331//-----------------------------------------------------------------------------
332
333class wxListCtrlRenameTimer: public wxTimer
334{
335private:
336 wxListCtrl *m_owner;
337
338public:
339 wxListCtrlRenameTimer( wxListCtrl *owner );
340 void Notify();
341};
342
343//-----------------------------------------------------------------------------
344// wxListCtrlTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
345//-----------------------------------------------------------------------------
346
347class wxListCtrlTextCtrlWrapper : public wxEvtHandler
348{
349public:
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
359protected:
360 void OnChar( wxKeyEvent &event );
361 void OnKeyUp( wxKeyEvent &event );
362 void OnKillFocus( wxFocusEvent &event );
363
364 bool AcceptChanges();
365 void Finish();
366
367private:
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
382wxListCtrlRenameTimer::wxListCtrlRenameTimer( wxListCtrl *owner )
383{
384 m_owner = owner;
385}
386
387void wxListCtrlRenameTimer::Notify()
388{
389 m_owner->OnRenameTimer();
390}
391
392//-----------------------------------------------------------------------------
393// wxListCtrlTextCtrlWrapper (internal)
394//-----------------------------------------------------------------------------
395
396BEGIN_EVENT_TABLE(wxListCtrlTextCtrlWrapper, wxEvtHandler)
397 EVT_CHAR (wxListCtrlTextCtrlWrapper::OnChar)
398 EVT_KEY_UP (wxListCtrlTextCtrlWrapper::OnKeyUp)
399 EVT_KILL_FOCUS (wxListCtrlTextCtrlWrapper::OnKillFocus)
400END_EVENT_TABLE()
401
402wxListCtrlTextCtrlWrapper::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
425void 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
438bool 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
456void 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
467void 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
485void 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;
9a83f860 498 m_text->GetTextExtent(m_text->GetValue() + wxT("MM"), &sx, &sy);
489468fe
SC
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
508void 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
489468fe
SC
522// ============================================================================
523// implementation
524// ============================================================================
525
524c47aa 526wxMacDataBrowserListCtrlControl* wxListCtrl::GetListPeer() const
489468fe 527{
524c47aa 528 return dynamic_cast<wxMacDataBrowserListCtrlControl*> ( GetPeer() );
489468fe
SC
529}
530
531// ----------------------------------------------------------------------------
532// wxListCtrl construction
533// ----------------------------------------------------------------------------
534
535void 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;
864186dd 556 m_renameTimer = NULL;
489468fe
SC
557}
558
559class wxGenericListCtrlHook : public wxGenericListCtrl
560{
561public:
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
574protected:
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
599void 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) &&
51c72a7b 610 (hitResult & wxLIST_HITTEST_ONITEMLABEL) &&
489468fe
SC
611 HasFlag(wxLC_EDIT_LABELS) )
612 {
864186dd
TK
613 if ( m_renameTimer )
614 m_renameTimer->Start( 250, true );
489468fe
SC
615 }
616 else
617 {
618 m_current = current;
619 }
620 event.Skip();
621}
622
623void wxListCtrl::OnDblClick(wxMouseEvent& event)
624{
864186dd 625 if ( m_renameTimer && m_renameTimer->IsRunning() )
88b497c1 626 m_renameTimer->Stop();
489468fe
SC
627 event.Skip();
628}
629
630#if wxABI_VERSION >= 20801
631void wxListCtrl::OnRightDown(wxMouseEvent& event)
632{
633 if (m_dbImpl)
634 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition());
635 event.Skip();
636}
637
638void wxListCtrl::OnMiddleDown(wxMouseEvent& event)
639{
640 if (m_dbImpl)
641 FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, event.GetPosition());
642 event.Skip();
643}
644
645void 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
663void wxListCtrl::OnChar(wxKeyEvent& event)
664{
665
03647350 666
489468fe
SC
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;
03647350 673
489468fe
SC
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 }
03647350 680
489468fe
SC
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;
03647350 691
489468fe
SC
692 break;
693
694 case WXK_DOWN:
695 if ( m_current < GetItemCount() - 1 )
696 m_current += 1;
697 else
698 m_current = GetItemCount() - 1;
03647350 699
489468fe
SC
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
715bool 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 {
864186dd 750 m_macIsUserPane = false;
489468fe
SC
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);
864186dd
TK
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 );
489468fe
SC
769 }
770
771 return true;
772}
773
774wxListCtrl::~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;
03647350 789
489468fe
SC
790 WX_CLEAR_LIST(wxColumnList, m_colsInfo);
791}
792
793/*static*/
794wxVisualAttributes
795wxListCtrl::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 );
7eb8aeb8
SC
801 static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS);
802 attr.font = font;
489468fe
SC
803
804 return attr;
805}
806
807// ----------------------------------------------------------------------------
808// set/get/change style
809// ----------------------------------------------------------------------------
810
811// Add or remove a single window style
812void 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
836void 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
851void 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
879wxSize wxListCtrl::DoGetBestSize() const
880{
881 return wxWindow::DoGetBestSize();
882}
883
884bool 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
893bool 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
903bool 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
0b134cd0 913wxColour wxListCtrl::GetBackgroundColour() const
489468fe
SC
914{
915 if (m_genericImpl)
916 return m_genericImpl->GetBackgroundColour();
917 if (m_dbImpl)
918 return m_bgColor;
919
920 return wxNullColour;
921}
922
a74d082e
JS
923void wxListCtrl::Freeze ()
924{
925 if (m_genericImpl)
926 m_genericImpl->Freeze();
927 wxControl::Freeze();
928}
929
930void wxListCtrl::Thaw ()
931{
932 if (m_genericImpl)
933 m_genericImpl->Thaw();
934 wxControl::Thaw();
935}
936
937void wxListCtrl::Update ()
938{
939 if (m_genericImpl)
940 m_genericImpl->Update();
941 wxControl::Update();
942}
943
489468fe
SC
944// ----------------------------------------------------------------------------
945// accessors
946// ----------------------------------------------------------------------------
947
948// Gets information about this column
949bool 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 );
9a83f860 959 wxASSERT_MSG( node, wxT("invalid column index in wxMacListCtrlItem") );
489468fe
SC
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
981bool wxListCtrl::SetColumn(int col, wxListItem& item)
982{
983 if (m_genericImpl)
984 return m_genericImpl->SetColumn(col, item);
985
986 if (m_dbImpl)
987 {
9a83f860 988 wxASSERT_MSG( col < (int)m_colsInfo.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
03647350 989
489468fe 990 long mask = item.GetMask();
489468fe
SC
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;
89c33c48
RR
1012
1013 DataBrowserTableViewColumnID id = 0;
1014 verify_noerr( m_dbImpl->GetColumnIDFromIndex( col, &id ) );
1015 verify_noerr( m_dbImpl->GetHeaderDesc( id, &columnDesc ) );
489468fe
SC
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
89c33c48 1045 verify_noerr( m_dbImpl->SetHeaderDesc( id, &columnDesc ) );
489468fe
SC
1046
1047 }
1048 return true;
1049}
1050
1051int 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
1067int 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
1081bool 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)
1130int 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.
1147wxTextCtrl* 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
1156bool 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);
1398e483
JS
1168 // MacGetColumnInfo returns erroneous information in the state field, so zero it.
1169 info.SetState(0);
489468fe
SC
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
1205bool 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
1216long 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
1236int 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
1272bool 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
1332bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage))
1333{
1334 return SetItemColumnImage(item, 0, image);
1335}
1336
1337// Sets the item image
1338bool 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
dfdad1f9 1354wxString wxListCtrl::GetItemText(long item, int column) const
489468fe
SC
1355{
1356 if (m_genericImpl)
dfdad1f9 1357 return m_genericImpl->GetItemText(item, column);
489468fe
SC
1358
1359 wxListItem info;
1360
1361 info.m_mask = wxLIST_MASK_TEXT;
1362 info.m_itemId = item;
dfdad1f9 1363 info.m_col = column;
489468fe
SC
1364
1365 if (!GetItem(info))
1366 return wxEmptyString;
1367 return info.m_text;
1368}
1369
1370// Sets the item text
1371void 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
1386long 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
1402bool 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
1416wxRect wxListCtrl::GetViewRect() const
1417{
1418 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
9a83f860 1419 wxT("wxListCtrl::GetViewRect() only works in icon mode") );
489468fe
SC
1420
1421 if (m_genericImpl)
1422 return m_genericImpl->GetViewRect();
1423
1424 wxRect rect;
1425 return rect;
1426}
1427
f63c36c3 1428bool wxListCtrl::GetSubItemRect( long item, long subItem, wxRect& rect, int code ) const
9e5754be
RR
1429{
1430 if (m_genericImpl)
f63c36c3 1431 return m_genericImpl->GetSubItemRect(item, subItem, rect, code);
9e5754be 1432
03647350 1433 // TODO: implement for DataBrowser implementation
9e5754be
RR
1434 return false;
1435}
1436
489468fe
SC
1437// Gets the item rectangle
1438bool 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;
89c33c48
RR
1447
1448 DataBrowserTableViewColumnID col = 0;
1449 verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &col ) );
03647350 1450
489468fe
SC
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
1478bool 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.
1497bool 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
1506int 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
1517void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
1518{
1519 if (m_genericImpl)
1520 m_genericImpl->SetItemSpacing(spacing, isSmall);
1521}
1522
1523wxSize wxListCtrl::GetItemSpacing() const
1524{
1525 if (m_genericImpl)
1526 return m_genericImpl->GetItemSpacing();
1527
1528 return wxSize(0, 0);
1529}
1530
1531void 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
1545wxColour 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
1559void 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
1573wxColour 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
1587void 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
1601wxFont 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
1617int 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
1629wxColour 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
1642void 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
1656long 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.
1680long 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
03647350 1697 if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
88b497c1
KO
1698 return line;
1699
489468fe
SC
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
03647350 1720 if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
88b497c1
KO
1721 return line;
1722
489468fe
SC
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
1736wxImageList *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
1756void 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
1784void 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
1806bool wxListCtrl::Arrange(int flag)
1807{
1808 if (m_genericImpl)
1809 return m_genericImpl->Arrange(flag);
1810 return false;
1811}
1812
1813// Deletes an item
1814bool 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
1832bool wxListCtrl::DeleteAllItems()
1833{
88b497c1 1834 m_current = -1;
489468fe
SC
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
1849bool 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
1868bool 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.
1883void 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
1898wxTextCtrl* 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
1931bool 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)
89c33c48
RR
1938 {
1939 DataBrowserTableViewColumnID id = 0;
1940 verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &id ) );
1941 verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, id ) );
1942 }
489468fe
SC
1943 return true;
1944}
1945
1946// Ensures this item is visible
1947bool 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.
1963long 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.
1997long 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.
2019long 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
51c72a7b
JS
2026static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon);
2027
489468fe
SC
2028// Determines which item (if any) is at the specified point,
2029// giving details in 'flags' (see wxLIST_HITTEST_... flags above)
2030long
2031wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
2032{
51c72a7b
JS
2033 if (ptrSubItem)
2034 *ptrSubItem = -1;
2035
489468fe
SC
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
51c72a7b
JS
2062 CGPoint click_point = CGPointMake( point.x, point.y );
2063 if (row < GetItemCount() )
489468fe 2064 {
51c72a7b
JS
2065 short column;
2066 for( column = 0; column < GetColumnCount(); column++ )
489468fe 2067 {
51c72a7b
JS
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 );
ce00f59b 2075
51c72a7b
JS
2076 enclosingCGRect = CGRectMake(enclosingRect.left,
2077 enclosingRect.top,
2078 enclosingRect.right - enclosingRect.left,
2079 enclosingRect.bottom - enclosingRect.top);
ce00f59b 2080
51c72a7b
JS
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);
ce00f59b 2089
51c72a7b
JS
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 }
ce00f59b 2105
51c72a7b 2106 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
ce00f59b 2107
51c72a7b
JS
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 }
489468fe 2149 }
51c72a7b 2150
489468fe
SC
2151 return -1;
2152}
2153
2154int 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.
2174long wxListCtrl::InsertItem(wxListItem& info)
2175{
9a83f860 2176 wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") );
489468fe
SC
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
2199long 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
2212long 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
2225long 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.
2239long 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);
03647350 2270
89c33c48
RR
2271 wxListItem* listItem = new wxListItem(item);
2272 m_colsInfo.Insert( col, listItem );
489468fe
SC
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
2292long 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)
2315bool wxListCtrl::ScrollList(int dx, int dy)
2316{
2317 if (m_genericImpl)
2318 return m_genericImpl->ScrollList(dx, dy);
2319
2320 if (m_dbImpl)
2321 {
c9c4274a
VZ
2322 // Notice that the parameter order is correct here: first argument is
2323 // the "top" displacement, second one is the "left" one.
2324 m_dbImpl->SetScrollPosition(dy, dx);
489468fe
SC
2325 }
2326 return true;
2327}
2328
2329
b18e2046 2330bool wxListCtrl::SortItems(wxListCtrlCompare fn, wxIntPtr data)
489468fe
SC
2331{
2332 if (m_genericImpl)
2333 return m_genericImpl->SortItems(fn, data);
2334
2335 if (m_dbImpl)
2336 {
2337 m_compareFunc = fn;
2338 m_compareFuncData = data;
2339 SortDataBrowserContainer( m_dbImpl->GetControlRef(), kDataBrowserNoItem, true);
2340
2341 // we need to do this after each call, else we get a crash from wxPython when
2342 // SortItems is called the second time.
2343 m_compareFunc = NULL;
2344 m_compareFuncData = 0;
2345 }
2346
2347 return true;
2348}
2349
2350void wxListCtrl::OnRenameTimer()
2351{
2352 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
2353
2354 EditLabel( m_current );
2355}
2356
2357bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value)
2358{
2359 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() );
2360 le.SetEventObject( this );
2361 le.m_itemIndex = itemEdit;
2362
2363 GetItem( le.m_item );
2364 le.m_item.m_text = value;
2365 return !HandleWindowEvent( le ) ||
2366 le.IsAllowed();
2367}
2368
2369void wxListCtrl::OnRenameCancelled(long itemEdit)
2370{
2371 // let owner know that the edit was cancelled
2372 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2373
2374 le.SetEditCanceled(true);
2375
2376 le.SetEventObject( this );
2377 le.m_itemIndex = itemEdit;
2378
2379 GetItem( le.m_item );
2380 HandleWindowEvent( le );
2381}
2382
2383// ----------------------------------------------------------------------------
2384// virtual list controls
2385// ----------------------------------------------------------------------------
2386
2387wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2388{
2389 // this is a pure virtual function, in fact - which is not really pure
2390 // because the controls which are not virtual don't need to implement it
9a83f860 2391 wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") );
489468fe
SC
2392
2393 return wxEmptyString;
2394}
2395
2396int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2397{
2398 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
2399 -1,
2400 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2401 return -1;
2402}
2403
2404int wxListCtrl::OnGetItemColumnImage(long item, long column) const
2405{
2406 if (!column)
2407 return OnGetItemImage(item);
2408
2409 return -1;
2410}
2411
2412wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
2413{
2414 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
9a83f860 2415 wxT("invalid item index in OnGetItemAttr()") );
489468fe
SC
2416
2417 // no attributes by default
2418 return NULL;
2419}
2420
2421void wxListCtrl::SetItemCount(long count)
2422{
9a83f860 2423 wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") );
489468fe
SC
2424
2425 if (m_genericImpl)
2426 {
2427 m_genericImpl->SetItemCount(count);
2428 return;
2429 }
2430
2431 if (m_dbImpl)
2432 {
2433 // we need to temporarily disable the new item creation notification
2434 // procedure to speed things up
2435 // FIXME: Even this doesn't seem to help much...
2436
2437 // FIXME: Find a more efficient way to do this.
2438 m_dbImpl->MacClear();
2439
2440 DataBrowserCallbacks callbacks;
2441 DataBrowserItemNotificationUPP itemUPP;
2442 GetDataBrowserCallbacks(m_dbImpl->GetControlRef(), &callbacks);
2443 itemUPP = callbacks.u.v1.itemNotificationCallback;
2444 callbacks.u.v1.itemNotificationCallback = 0;
2445 m_dbImpl->SetCallbacks(&callbacks);
2446 ::AddDataBrowserItems(m_dbImpl->GetControlRef(), kDataBrowserNoItem,
2447 count, NULL, kDataBrowserItemNoProperty);
2448 callbacks.u.v1.itemNotificationCallback = itemUPP;
2449 m_dbImpl->SetCallbacks(&callbacks);
2450 }
2451 m_count = count;
2452}
2453
2454void wxListCtrl::RefreshItem(long item)
2455{
2456 if (m_genericImpl)
2457 {
2458 m_genericImpl->RefreshItem(item);
2459 return;
2460 }
2461
2462 if (m_dbImpl)
2463 {
2464 DataBrowserItemID id;
2465
2466 if ( !IsVirtual() )
2467 {
2468 wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item);
2469 id = (DataBrowserItemID) thisItem;
2470 }
2471 else
2472 id = item+1;
2473
2474 m_dbImpl->wxMacDataBrowserControl::UpdateItems
2475 (
2476 kDataBrowserNoItem,
2477 1, &id,
2478 kDataBrowserItemNoProperty, // preSortProperty
2479 kDataBrowserNoItem // update all columns
2480 );
2481 }
2482}
2483
2484void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
2485{
2486 if (m_genericImpl)
2487 {
2488 m_genericImpl->RefreshItems(itemFrom, itemTo);
2489 return;
2490 }
2491
2492 if (m_dbImpl)
2493 {
2494 const long count = itemTo - itemFrom + 1;
2495 DataBrowserItemID *ids = new DataBrowserItemID[count];
2496
2497 if ( !IsVirtual() )
2498 {
2499 for ( long i = 0; i < count; i++ )
2500 {
2501 wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(itemFrom+i);
2502 ids[i] = (DataBrowserItemID) thisItem;
2503 }
2504 }
2505 else
2506 {
2507 for ( long i = 0; i < count; i++ )
2508 ids[i] = itemFrom+i+1;
2509 }
2510
2511 m_dbImpl->wxMacDataBrowserControl::UpdateItems
2512 (
2513 kDataBrowserNoItem,
2514 count, ids,
2515 kDataBrowserItemNoProperty, // preSortProperty
2516 kDataBrowserNoItem // update all columns
2517 );
2518
2519 delete[] ids;
2520 }
2521}
2522
2523void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget )
2524{
2525#if wxUSE_DRAG_AND_DROP
2526 if (m_genericImpl)
2527 m_genericImpl->SetDropTarget( dropTarget );
2528
2529 if (m_dbImpl)
2530 wxWindow::SetDropTarget( dropTarget );
2531#endif
2532}
2533
2534wxDropTarget *wxListCtrl::GetDropTarget() const
2535{
2536#if wxUSE_DRAG_AND_DROP
2537 if (m_genericImpl)
2538 return m_genericImpl->GetDropTarget();
2539
2540 if (m_dbImpl)
2541 return wxWindow::GetDropTarget();
2542#endif
2543 return NULL;
2544}
2545
2546#if wxABI_VERSION >= 20801
2547void wxListCtrl::SetFocus()
2548{
2549 if (m_genericImpl)
2550 {
2551 m_genericImpl->SetFocus();
2552 return;
2553 }
2554
2555 wxWindow::SetFocus();
2556}
2557#endif
2558
2559// wxMac internal data structures
2560
2561wxMacListCtrlItem::~wxMacListCtrlItem()
2562{
2563 WX_CLEAR_HASH_MAP( wxListItemList, m_rowItems );
2564}
2565
2566void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
2567 DataBrowserItemNotification message,
2568 DataBrowserItemDataRef WXUNUSED(itemData) ) const
2569{
2570
2571 wxMacDataBrowserListCtrlControl *lb = wxDynamicCast(owner, wxMacDataBrowserListCtrlControl);
2572
2573 // we want to depend on as little as possible to make sure tear-down of controls is safe
2574 if ( message == kDataBrowserItemRemoved)
2575 {
489468fe
SC
2576 delete this;
2577 return;
2578 }
2579 else if ( message == kDataBrowserItemAdded )
2580 {
2581 // we don't issue events on adding, the item is not really stored in the list yet, so we
2582 // avoid asserts by gettting out now
2583 return ;
2584 }
2585
b2680ced 2586 wxListCtrl *list = wxDynamicCast( owner->GetWXPeer() , wxListCtrl );
489468fe
SC
2587 if ( list && lb )
2588 {
2589 bool trigger = false;
2590
2591 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
2592 bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
2593
2594 event.SetEventObject( list );
2595 event.m_itemIndex = owner->GetLineFromItem( this ) ;
2596 event.m_item.m_itemId = event.m_itemIndex;
2597 list->GetItem(event.m_item);
2598
2599 switch (message)
2600 {
2601 case kDataBrowserItemDeselected:
2602 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
2603 if ( !isSingle )
2604 trigger = !lb->IsSelectionSuppressed();
2605 break;
2606
2607 case kDataBrowserItemSelected:
2608 trigger = !lb->IsSelectionSuppressed();
2609 break;
2610
2611 case kDataBrowserItemDoubleClicked:
2612 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
2613 trigger = true;
2614 break;
2615
2616 case kDataBrowserEditStarted :
2617 // TODO : how to veto ?
2618 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
2619 trigger = true ;
2620 break ;
2621
2622 case kDataBrowserEditStopped :
2623 // TODO probably trigger only upon the value store callback, because
2624 // here IIRC we cannot veto
2625 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
2626 trigger = true ;
2627 break ;
2628
2629 default:
2630 break;
2631 }
2632
2633 if ( trigger )
2634 {
2635 // direct notification is not always having the listbox GetSelection() having in synch with event
2636 wxPostEvent( list->GetEventHandler(), event );
2637 }
2638 }
2639
2640}
2641
2642IMPLEMENT_DYNAMIC_CLASS(wxMacDataBrowserListCtrlControl, wxMacDataItemBrowserControl )
2643
2644wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
2645 : wxMacDataItemBrowserControl( peer, pos, size, style )
2646{
2647 OSStatus err = noErr;
2648 m_clientDataItemsType = wxClientData_None;
2649 m_isVirtual = false;
2650 m_flags = 0;
2651
2652 if ( style & wxLC_VIRTUAL )
2653 m_isVirtual = true;
2654
2655 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
2656 if ( style & wxLC_SINGLE_SEL )
2657 {
2658 options |= kDataBrowserSelectOnlyOne;
2659 }
2660 else
2661 {
2662 options |= kDataBrowserCmdTogglesSelection;
2663 }
2664
2665 err = SetSelectionFlags( options );
2666 verify_noerr( err );
2667
2668 DataBrowserCustomCallbacks callbacks;
2669 InitializeDataBrowserCustomCallbacks( &callbacks, kDataBrowserLatestCustomCallbacks );
2670
2671 if ( gDataBrowserDrawItemUPP == NULL )
2672 gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc);
2673
2674 if ( gDataBrowserHitTestUPP == NULL )
2675 gDataBrowserHitTestUPP = NewDataBrowserHitTestUPP(DataBrowserHitTestProc);
2676
2677 callbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP;
2678 callbacks.u.v1.hitTestCallback = gDataBrowserHitTestUPP;
2679
2680 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks );
2681
2682 if ( style & wxLC_LIST )
2683 {
2684 InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1);
2685 verify_noerr( AutoSizeColumns() );
2686 }
2687
2688 if ( style & wxLC_LIST || style & wxLC_NO_HEADER )
2689 verify_noerr( SetHeaderButtonHeight( 0 ) );
2690
2691 if ( m_isVirtual )
2692 SetSortProperty( kMinColumnId - 1 );
2693 else
2694 SetSortProperty( kMinColumnId );
2695
2696 m_sortOrder = SortOrder_None;
2697
2698 if ( style & wxLC_SORT_DESCENDING )
2699 {
2700 SetSortOrder( kDataBrowserOrderDecreasing );
2701 }
2702 else if ( style & wxLC_SORT_ASCENDING )
2703 {
2704 SetSortOrder( kDataBrowserOrderIncreasing );
2705 }
2706
2707 if ( style & wxLC_VRULES )
2708 {
2709 verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
2710 }
2711
2712 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
2713 verify_noerr( SetHasScrollBars( (style & wxHSCROLL) != 0 , true ) );
2714}
2715
2716pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
2717 ControlRef browser,
2718 DataBrowserItemID itemID,
2719 DataBrowserPropertyID property,
2720 CFStringRef theString,
2721 Rect *maxEditTextRect,
2722 Boolean *shrinkToFit)
2723{
2724 Boolean result = false;
2725 wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl);
2726 if ( ctl != 0 )
2727 {
2728 result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
2729 theString = CFSTR("Hello!");
2730 }
2731 return result;
2732}
2733
2734bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
2735 DataBrowserItemID WXUNUSED(itemID),
2736 DataBrowserPropertyID WXUNUSED(property),
2737 CFStringRef WXUNUSED(theString),
2738 Rect *WXUNUSED(maxEditTextRect),
2739 Boolean *WXUNUSED(shrinkToFit))
2740{
2741 return false;
2742}
2743
2744pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
2745 ControlRef browser,
2746 DataBrowserItemID itemID,
2747 DataBrowserPropertyID property,
2748 DataBrowserItemState itemState,
2749 const Rect *itemRect,
2750 SInt16 gdDepth,
2751 Boolean colorDevice)
2752{
2753 wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl);
2754 if ( ctl != 0 )
2755 {
2756 ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
2757 }
2758}
2759
2760// routines needed for DrawItem
2761enum
2762{
2763 kIconWidth = 16,
2764 kIconHeight = 16,
2765 kTextBoxHeight = 14,
2766 kIconTextSpacingV = 2,
2767 kItemPadding = 4,
2768 kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
2769};
2770
2771static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
2772{
2773 float textBottom;
2774 float iconH, iconW = 0;
2775 float padding = kItemPadding;
2776 if (hasIcon)
2777 {
2778 iconH = kIconHeight;
2779 iconW = kIconWidth;
2780 padding = padding*2;
2781 }
2782
2783 textBottom = inItemRect.origin.y;
2784
2785 *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
2786 textBottom + kIconTextSpacingV, kIconWidth,
2787 kIconHeight);
2788
2789 *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
2790 textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
2791 inItemRect.size.height - kIconTextSpacingV);
2792}
2793
2794void wxMacDataBrowserListCtrlControl::DrawItem(
2795 DataBrowserItemID itemID,
2796 DataBrowserPropertyID property,
2797 DataBrowserItemState itemState,
2798 const Rect *WXUNUSED(itemRect),
2799 SInt16 gdDepth,
2800 Boolean colorDevice)
2801{
2802 wxString text;
2803 wxFont font = wxNullFont;
2804 int imgIndex = -1;
03647350 2805
89c33c48 2806 DataBrowserTableViewColumnIndex listColumn = 0;
0698ed3c 2807 GetColumnPosition( property, &listColumn );
03647350 2808
b2680ced 2809 wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl );
489468fe
SC
2810 wxMacListCtrlItem* lcItem;
2811 wxColour color = *wxBLACK;
2812 wxColour bgColor = wxNullColour;
2813
2814 if (listColumn >= 0)
2815 {
2816 if (!m_isVirtual)
2817 {
2818 lcItem = (wxMacListCtrlItem*) itemID;
89c33c48
RR
2819 if (lcItem->HasColumnInfo(listColumn))
2820 {
489468fe
SC
2821 wxListItem* item = lcItem->GetColumnInfo(listColumn);
2822
2823 // we always use the 0 column to get font and text/background colors.
2824 if (lcItem->HasColumnInfo(0))
2825 {
2826 wxListItem* firstItem = lcItem->GetColumnInfo(0);
2827 color = firstItem->GetTextColour();
2828 bgColor = firstItem->GetBackgroundColour();
2829 font = firstItem->GetFont();
2830 }
2831
2832 if (item->GetMask() & wxLIST_MASK_TEXT)
2833 text = item->GetText();
2834 if (item->GetMask() & wxLIST_MASK_IMAGE)
2835 imgIndex = item->GetImage();
2836 }
2837
2838 }
2839 else
2840 {
2841 long itemNum = (long)itemID-1;
2842 if (itemNum >= 0 && itemNum < list->GetItemCount())
2843 {
2844 text = list->OnGetItemText( itemNum, listColumn );
2845 imgIndex = list->OnGetItemColumnImage( itemNum, listColumn );
2846 wxListItemAttr* attrs = list->OnGetItemAttr( itemNum );
2847 if (attrs)
2848 {
2849 if (attrs->HasBackgroundColour())
2850 bgColor = attrs->GetBackgroundColour();
2851 if (attrs->HasTextColour())
2852 color = attrs->GetTextColour();
2853 if (attrs->HasFont())
2854 font = attrs->GetFont();
2855 }
2856 }
2857 }
2858 }
2859
2860 wxColour listBgColor = list->GetBackgroundColour();
2861 if (bgColor == wxNullColour)
2862 bgColor = listBgColor;
2863
2864 if (!font.Ok())
2865 font = list->GetFont();
2866
2867 wxCFStringRef cfString( text, wxLocale::GetSystemEncoding() );
2868
2869 Rect enclosingRect;
2870 CGRect enclosingCGRect, iconCGRect, textCGRect;
2871 Boolean active;
2872 ThemeDrawingState savedState = NULL;
2873 CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
51c72a7b
JS
2874 wxMacCGContextStateSaver top_saver_cg( context );
2875
489468fe
SC
2876 RGBColor labelColor;
2877 labelColor.red = 0;
2878 labelColor.green = 0;
2879 labelColor.blue = 0;
2880
2881 RGBColor backgroundColor;
2882 backgroundColor.red = 255;
2883 backgroundColor.green = 255;
2884 backgroundColor.blue = 255;
2885
2886 GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
2887 &enclosingRect);
2888
2889 enclosingCGRect = CGRectMake(enclosingRect.left,
2890 enclosingRect.top,
2891 enclosingRect.right - enclosingRect.left,
2892 enclosingRect.bottom - enclosingRect.top);
2893
2894 bool hasFocus = (wxWindow::FindFocus() == list);
2895 active = IsControlActive(GetControlRef());
2896
2897 // don't paint the background over the vertical rule line
2898 if ( list->GetWindowStyleFlag() & wxLC_VRULES )
2899 {
2900 enclosingCGRect.origin.x += 1;
2901 enclosingCGRect.size.width -= 1;
2902 }
2903 if (itemState == kDataBrowserItemIsSelected)
2904 {
2905
2906 GetThemeDrawingState(&savedState);
2907
2908 if (active && hasFocus)
2909 {
2910 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &backgroundColor);
2911 GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
2912 }
2913 else
2914 {
2915 GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &backgroundColor);
2916 GetThemeTextColor(kThemeTextColorBlack, gdDepth, colorDevice, &labelColor);
2917 }
51c72a7b 2918 wxMacCGContextStateSaver cg( context );
489468fe
SC
2919
2920 CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX,
2921 (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX,
2922 (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0);
2923 CGContextFillRect(context, enclosingCGRect);
489468fe
SC
2924 }
2925 else
2926 {
2927
2928 if (color.Ok())
2929 color.GetRGBColor(&labelColor);
2930 else if (list->GetTextColour().Ok())
2931 list->GetTextColour().GetRGBColor(&labelColor);
2932
2933 if (bgColor.Ok())
2934 {
2935 bgColor.GetRGBColor(&backgroundColor);
2936 CGContextSaveGState(context);
2937
2938 CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX,
2939 (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX,
2940 (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0);
2941 CGContextFillRect(context, enclosingCGRect);
2942
2943 CGContextRestoreGState(context);
2944 }
2945 }
2946
2947 calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
2948
2949 if (imgIndex != -1)
2950 {
2951 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
51c72a7b
JS
2952 if (imageList && imageList->GetImageCount() > 0)
2953 {
489468fe
SC
2954 wxBitmap bmp = imageList->GetBitmap(imgIndex);
2955 IconRef icon = bmp.GetIconRef();
2956
51c72a7b
JS
2957 wxMacCGContextStateSaver cg( context );
2958
489468fe
SC
2959 CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
2960 CGContextScaleCTM(context,1.0f,-1.0f);
2961 PlotIconRefInContext(context, &iconCGRect, kAlignNone,
2962 active ? kTransformNone : kTransformDisabled, NULL,
2963 kPlotIconRefNormalFlags, icon);
489468fe
SC
2964 }
2965 }
2966
2967 HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
2968 HIThemeTextInfo info;
2969 bool setup = false;
292e5e1f 2970#if wxOSX_USE_CORE_TEXT
489468fe
SC
2971 if ( UMAGetSystemVersion() >= 0x1050 )
2972 {
2973 info.version = kHIThemeTextInfoVersionOne;
2974 info.fontID = kThemeViewsFont;
2975 if (font.Ok())
2976 {
2977 info.fontID = kThemeSpecifiedFont;
aa6208d9 2978 info.font = (CTFontRef) font.OSXGetCTFont();
489468fe
SC
2979 setup = true;
2980 }
2981 }
2982#endif
292e5e1f 2983#if wxOSX_USE_ATSU_TEXT
489468fe
SC
2984 if ( !setup )
2985 {
2986 info.version = kHIThemeTextInfoVersionZero;
2987 info.fontID = kThemeViewsFont;
2988
2989 if (font.Ok())
2990 {
2991 info.fontID = font.MacGetThemeFontID();
2992
f1c40652 2993 ::TextSize( (short)(font.GetPointSize()) ) ;
489468fe
SC
2994 ::TextFace( font.MacGetFontStyle() ) ;
2995 }
2996 }
2997#endif
2998
2999 wxListItem item;
3000 list->GetColumn(listColumn, item);
3001 if (item.GetMask() & wxLIST_MASK_FORMAT)
3002 {
3003 if (item.GetAlign() == wxLIST_FORMAT_LEFT)
3004 hFlush = kHIThemeTextHorizontalFlushLeft;
3005 else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
3006 hFlush = kHIThemeTextHorizontalFlushCenter;
3007 else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
3008 {
3009 hFlush = kHIThemeTextHorizontalFlushRight;
3010 textCGRect.origin.x -= kItemPadding; // give a little extra paddding
3011 }
3012 }
3013
3014 info.state = active ? kThemeStateActive : kThemeStateInactive;
3015 info.horizontalFlushness = hFlush;
3016 info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
3017 info.options = kHIThemeTextBoxOptionNone;
3018 info.truncationPosition = kHIThemeTextTruncationEnd;
3019 info.truncationMaxLines = 1;
3020
51c72a7b
JS
3021 {
3022 wxMacCGContextStateSaver cg( context );
3023 CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX,
489468fe
SC
3024 (CGFloat)labelColor.green / (CGFloat)USHRT_MAX,
3025 (CGFloat)labelColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0);
3026
51c72a7b
JS
3027 HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
3028 }
489468fe
SC
3029
3030#ifndef __LP64__
3031 if (savedState != NULL)
3032 SetThemeDrawingState(savedState, true);
3033#endif
3034}
3035
3036OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
3037 DataBrowserPropertyID property,
3038 DataBrowserItemDataRef itemData,
3039 Boolean changeValue )
3040{
3041 wxString text;
3042 int imgIndex = -1;
89c33c48
RR
3043
3044 DataBrowserTableViewColumnIndex listColumn = 0;
3045 verify_noerr( GetColumnPosition( property, &listColumn ) );
489468fe
SC
3046
3047 OSStatus err = errDataBrowserPropertyNotSupported;
b2680ced 3048 wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl );
489468fe
SC
3049 wxMacListCtrlItem* lcItem = NULL;
3050
3051 if (listColumn >= 0)
3052 {
3053 if (!m_isVirtual)
3054 {
3055 lcItem = (wxMacListCtrlItem*) itemID;
3056 if (lcItem && lcItem->HasColumnInfo(listColumn)){
3057 wxListItem* item = lcItem->GetColumnInfo(listColumn);
3058 if (item->GetMask() & wxLIST_MASK_TEXT)
3059 text = item->GetText();
3060 if (item->GetMask() & wxLIST_MASK_IMAGE)
3061 imgIndex = item->GetImage();
3062 }
3063 }
3064 else
3065 {
3066 long itemNum = (long)itemID-1;
3067 if (itemNum >= 0 && itemNum < list->GetItemCount())
3068 {
3069 text = list->OnGetItemText( itemNum, listColumn );
3070 imgIndex = list->OnGetItemColumnImage( itemNum, listColumn );
3071 }
3072 }
3073 }
3074
3075 if ( !changeValue )
3076 {
3077 switch (property)
3078 {
3079 case kDataBrowserItemIsEditableProperty :
3080 if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
3081 {
3082 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
3083 err = noErr ;
3084 }
3085 break ;
3086 default :
3087 if ( property >= kMinColumnId )
3088 {
3089 if (!text.IsEmpty()){
3090 wxCFStringRef cfStr( text, wxLocale::GetSystemEncoding() );
3091 err = ::SetDataBrowserItemDataText( itemData, cfStr );
3092 err = noErr;
3093 }
3094
3095
3096
3097 if ( imgIndex != -1 )
3098 {
3099 wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
3100 if (imageList && imageList->GetImageCount() > 0){
3101 wxBitmap bmp = imageList->GetBitmap(imgIndex);
3102 IconRef icon = bmp.GetIconRef();
3103 ::SetDataBrowserItemDataIcon(itemData, icon);
3104 }
3105 }
3106
3107 }
3108 break ;
3109 }
3110
3111 }
3112 else
3113 {
3114 switch (property)
3115 {
3116 default:
3117 if ( property >= kMinColumnId )
3118 {
89c33c48
RR
3119 DataBrowserTableViewColumnIndex listColumn = 0;
3120 verify_noerr( GetColumnPosition( property, &listColumn ) );
489468fe
SC
3121
3122 // TODO probably send the 'end edit' from here, as we
3123 // can then deal with the veto
3124 CFStringRef sr ;
3125 verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
3126 wxCFStringRef cfStr(sr) ;;
3127 if (m_isVirtual)
3128 list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
3129 else
3130 {
3131 if (lcItem)
3132 lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
3133 }
3134 err = noErr ;
3135 }
3136 break;
3137 }
3138 }
3139 return err;
3140}
3141
3142void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
3143 DataBrowserItemNotification message,
3144 DataBrowserItemDataRef itemData )
3145{
3146 wxMacListCtrlItem *item = NULL;
3147 if ( !m_isVirtual )
3148 {
3149 item = (wxMacListCtrlItem *) itemID;
3150 }
03647350 3151
489468fe
SC
3152 // we want to depend on as little as possible to make sure tear-down of controls is safe
3153 if ( message == kDataBrowserItemRemoved )
3154 {
3155 if ( item )
3156 item->Notification(this, message, itemData);
3157 return;
3158 }
3159 else if ( message == kDataBrowserItemAdded )
3160 {
3161 // we don't issue events on adding, the item is not really stored in the list yet, so we
3162 // avoid asserts by getting out now
3163 if ( item )
3164 item->Notification(this, message, itemData);
3165 return ;
3166 }
3167
b2680ced 3168 wxListCtrl *list = wxDynamicCast( GetWXPeer() , wxListCtrl );
489468fe
SC
3169 if ( list )
3170 {
3171 bool trigger = false;
3172
3173 wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
3174
3175 event.SetEventObject( list );
3176 if ( !list->IsVirtual() )
3177 {
3178 DataBrowserTableViewRowIndex result = 0;
3179 verify_noerr( GetItemRow( itemID, &result ) ) ;
3180 event.m_itemIndex = result;
3181 }
3182 else
3183 {
3184 event.m_itemIndex = (long)itemID-1;
3185 }
3186 event.m_item.m_itemId = event.m_itemIndex;
3187 list->GetItem(event.m_item);
3188
3189 switch (message)
3190 {
3191 case kDataBrowserItemDeselected:
3192 event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
3193 // as the generic implementation is also triggering this
3194 // event for single selection, we do the same (different than listbox)
3195 trigger = !IsSelectionSuppressed();
3196 break;
3197
3198 case kDataBrowserItemSelected:
3199 trigger = !IsSelectionSuppressed();
3200
3201 break;
3202
3203 case kDataBrowserItemDoubleClicked:
3204 event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
3205 trigger = true;
3206 break;
3207
3208 case kDataBrowserEditStarted :
3209 // TODO : how to veto ?
3210 event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
3211 trigger = true ;
3212 break ;
3213
3214 case kDataBrowserEditStopped :
3215 // TODO probably trigger only upon the value store callback, because
3216 // here IIRC we cannot veto
3217 event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
3218 trigger = true ;
3219 break ;
3220
3221 default:
3222 break;
3223 }
3224
3225 if ( trigger )
3226 {
3227 // direct notification is not always having the listbox GetSelection() having in synch with event
3228 wxPostEvent( list->GetEventHandler(), event );
3229 }
3230 }
3231}
3232
3233Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
3234 DataBrowserItemID itemTwoID,
3235 DataBrowserPropertyID sortProperty)
3236{
3237
3238 bool retval = false;
3239 wxString itemText;
3240 wxString otherItemText;
3241 long itemOrder;
3242 long otherItemOrder;
3243
89c33c48
RR
3244 DataBrowserTableViewColumnIndex colId = 0;
3245 verify_noerr( GetColumnPosition( sortProperty, &colId ) );
489468fe 3246
b2680ced 3247 wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl );
489468fe
SC
3248
3249 DataBrowserSortOrder sort;
3250 verify_noerr(GetSortOrder(&sort));
3251
3252 if (colId >= 0)
3253 {
3254 if (!m_isVirtual)
3255 {
3256 wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
3257 wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
3258
3259 itemOrder = item->GetOrder();
4ee5edc7 3260 otherItemOrder = otherItem->GetOrder();
489468fe
SC
3261
3262 wxListCtrlCompare func = list->GetCompareFunc();
3263 if (func != NULL)
3264 {
4ee5edc7 3265
489468fe
SC
3266 long item1 = -1;
3267 long item2 = -1;
3268 if (item && item->HasColumnInfo(0))
3269 item1 = item->GetColumnInfo(0)->GetData();
3270 if (otherItem && otherItem->HasColumnInfo(0))
3271 item2 = otherItem->GetColumnInfo(0)->GetData();
3272
3273 if (item1 > -1 && item2 > -1)
3274 {
3275 int result = func(item1, item2, list->GetCompareFuncData());
3276 if (sort == kDataBrowserOrderIncreasing)
3277 return result >= 0;
3278 else
3279 return result < 0;
3280 }
3281 }
3282
3283 // we can't use the native control's sorting abilities, so just
3284 // sort by item id.
3285 return itemOrder < otherItemOrder;
3286 }
3287 else
3288 {
3289
3290 long itemNum = (long)itemOneID;
3291 long otherItemNum = (long)itemTwoID;
3292
3293 // virtual listctrls don't support sorting
3294 return itemNum < otherItemNum;
3295 }
3296 }
3297 else{
3298 // fallback for undefined cases
3299 retval = itemOneID < itemTwoID;
3300 }
3301
3302 return retval;
3303}
3304
3305wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
3306{
3307}
3308
3309void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item )
3310{
3311 wxMacDataItem* dataItem = GetItemFromLine(row);
9a83f860 3312 wxASSERT_MSG( dataItem, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") );
489468fe
SC
3313 if (item)
3314 {
5c33522f 3315 wxMacListCtrlItem* listItem = static_cast<wxMacListCtrlItem *>(dataItem);
489468fe
SC
3316 bool hasInfo = listItem->HasColumnInfo( column );
3317 listItem->SetColumnInfo( column, item );
3318 listItem->SetOrder(row);
3319 UpdateState(dataItem, item);
3320
b2680ced 3321 wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl );
489468fe
SC
3322
3323 // NB: When this call was made before a control was completely shown, it would
3324 // update the item prematurely (i.e. no text would be listed) and, on show,
3325 // only the sorted column would be refreshed, meaning only first column text labels
3326 // would be shown. Making sure not to update items until the control is visible
3327 // seems to fix this issue.
3328 if (hasInfo && list->IsShown())
89c33c48
RR
3329 {
3330 DataBrowserTableViewColumnID id = 0;
3331 verify_noerr( GetColumnIDFromIndex( column, &id ) );
3332 UpdateItem( wxMacDataBrowserRootContainer, listItem , id );
3333 }
489468fe
SC
3334 }
3335}
3336
3337// apply changes that need to happen immediately, rather than when the
3338// databrowser control fires a callback.
3339void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxListItem* listItem)
3340{
3341 bool isSelected = IsItemSelected( dataItem );
3342 bool isSelectedState = (listItem->GetState() == wxLIST_STATE_SELECTED);
3343
3344 // toggle the selection state if wxListInfo state and actual state don't match.
3345 if ( listItem->GetMask() & wxLIST_MASK_STATE && isSelected != isSelectedState )
3346 {
3347 DataBrowserSetOption options = kDataBrowserItemsAdd;
3348 if (!isSelectedState)
3349 options = kDataBrowserItemsRemove;
3350 SetSelectedItem(dataItem, options);
3351 }
3352 // TODO: Set column width if item width > than current column width
3353}
3354
3355void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item )
3356{
3357 wxMacDataItem* dataItem = GetItemFromLine(row);
9a83f860 3358 wxASSERT_MSG( dataItem, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") );
489468fe
SC
3359 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
3360 //if (item)
3361 {
5c33522f 3362 wxMacListCtrlItem* listItem = static_cast<wxMacListCtrlItem *>(dataItem);
489468fe
SC
3363
3364 if (!listItem->HasColumnInfo( column ))
3365 return;
3366
3367 wxListItem* oldItem = listItem->GetColumnInfo( column );
3368
3369 if (oldItem)
3370 {
3371 long mask = item.GetMask();
3372 if ( !mask )
3373 // by default, get everything for backwards compatibility
3374 mask = -1;
3375
3376 if ( mask & wxLIST_MASK_TEXT )
3377 item.SetText(oldItem->GetText());
3378 if ( mask & wxLIST_MASK_IMAGE )
3379 item.SetImage(oldItem->GetImage());
3380 if ( mask & wxLIST_MASK_DATA )
3381 item.SetData(oldItem->GetData());
3382 if ( mask & wxLIST_MASK_STATE )
3383 item.SetState(oldItem->GetState());
3384 if ( mask & wxLIST_MASK_WIDTH )
3385 item.SetWidth(oldItem->GetWidth());
3386 if ( mask & wxLIST_MASK_FORMAT )
3387 item.SetAlign(oldItem->GetAlign());
3388
3389 item.SetTextColour(oldItem->GetTextColour());
3390 item.SetBackgroundColour(oldItem->GetBackgroundColour());
3391 item.SetFont(oldItem->GetFont());
3392 }
3393 }
3394}
03647350 3395
489468fe
SC
3396void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
3397{
03647350 3398
524c47aa 3399 wxMacDataItemBrowserControl::MacInsert(n, new wxMacListCtrlItem() );
489468fe
SC
3400 MacSetColumnInfo(n, 0, item);
3401}
3402
489468fe
SC
3403wxMacListCtrlItem::wxMacListCtrlItem()
3404{
3405 m_rowItems = wxListItemList();
3406}
3407
3408int wxMacListCtrlItem::GetColumnImageValue( unsigned int column )
3409{
3410 if ( HasColumnInfo(column) )
3411 return GetColumnInfo(column)->GetImage();
3412
3413 return -1;
3414}
3415
3416void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex )
3417{
3418 if ( HasColumnInfo(column) )
3419 GetColumnInfo(column)->SetImage(imageIndex);
3420}
3421
3422wxString wxMacListCtrlItem::GetColumnTextValue( unsigned int column )
3423{
524c47aa 3424/* TODO CHECK REMOVE
489468fe
SC
3425 if ( column == 0 )
3426 return GetLabel();
524c47aa 3427*/
489468fe
SC
3428 if ( HasColumnInfo(column) )
3429 return GetColumnInfo(column)->GetText();
3430
3431 return wxEmptyString;
3432}
3433
3434void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& text )
3435{
3436 if ( HasColumnInfo(column) )
3437 GetColumnInfo(column)->SetText(text);
3438
524c47aa 3439/* TODO CHECK REMOVE
489468fe
SC
3440 // for compatibility with superclass APIs
3441 if ( column == 0 )
3442 SetLabel(text);
524c47aa 3443*/
489468fe
SC
3444}
3445
3446wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )
3447{
9a83f860 3448 wxASSERT_MSG( HasColumnInfo(column), wxT("invalid column index in wxMacListCtrlItem") );
489468fe
SC
3449 return m_rowItems[column];
3450}
3451
3452bool wxMacListCtrlItem::HasColumnInfo( unsigned int column )
3453{
3454 return !(m_rowItems.find( column ) == m_rowItems.end());
3455}
3456
3457void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
3458{
3459
3460 if ( !HasColumnInfo(column) )
3461 {
3462 wxListItem* listItem = new wxListItem(*item);
3463 m_rowItems[column] = listItem;
3464 }
3465 else
3466 {
3467 wxListItem* listItem = GetColumnInfo( column );
3468 long mask = item->GetMask();
3469 if (mask & wxLIST_MASK_TEXT)
3470 listItem->SetText(item->GetText());
3471 if (mask & wxLIST_MASK_DATA)
3472 listItem->SetData(item->GetData());
3473 if (mask & wxLIST_MASK_IMAGE)
3474 listItem->SetImage(item->GetImage());
3475 if (mask & wxLIST_MASK_STATE)
3476 listItem->SetState(item->GetState());
3477 if (mask & wxLIST_MASK_FORMAT)
3478 listItem->SetAlign(item->GetAlign());
3479 if (mask & wxLIST_MASK_WIDTH)
3480 listItem->SetWidth(item->GetWidth());
3481
3482 if ( item->HasAttributes() )
3483 {
3484 if ( listItem->HasAttributes() )
3485 listItem->GetAttributes()->AssignFrom(*item->GetAttributes());
3486 else
3487 {
3488 listItem->SetTextColour(item->GetTextColour());
3489 listItem->SetBackgroundColour(item->GetBackgroundColour());
3490 listItem->SetFont(item->GetFont());
3491 }
3492 }
3493 }
3494}
3495
3496int wxListCtrl::CalcColumnAutoWidth(int col) const
3497{
3498 int width = 0;
3499
3500 for ( int i = 0; i < GetItemCount(); i++ )
3501 {
3502 wxListItem info;
3503 info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE);
3504 info.SetId(i);
3505 info.SetColumn(col);
3506 GetItem(info);
3507
3508 const wxFont font = info.GetFont();
3509
3510 int w = 0;
3511 if ( font.IsOk() )
3512 GetTextExtent(info.GetText(), &w, NULL, NULL, NULL, &font);
3513 else
3514 GetTextExtent(info.GetText(), &w, NULL);
3515
3516 w += 2 * kItemPadding;
3517
3518 if ( info.GetImage() != -1 )
3519 w += kIconWidth;
3520
3521 width = wxMax(width, w);
3522 }
3523
3524 return width;
3525}
3526
3527#endif // wxUSE_LISTCTRL
3528