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