1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/wxprec.h"
21 #include "wx/toplevel.h"
26 #include "wx/apptrait.h"
35 // #include "MoreFilesX.h"
37 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
38 #include <AudioToolbox/AudioServices.h>
41 #include "wx/osx/private.h"
43 #include "wx/osx/private/timer.h"
46 #include "wx/evtloop.h"
48 #if defined(__MWERKS__) && wxUSE_UNICODE
49 #if __MWERKS__ < 0x4100
59 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
60 if ( AudioServicesPlayAlertSound
!= NULL
)
61 AudioServicesPlayAlertSound(kUserPreferredAlert
);
64 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
76 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
78 return new wxOSXTimerImpl(timer
);
81 int gs_wxBusyCursorCount
= 0;
82 extern wxCursor gMacCurrentCursor
;
83 wxCursor gMacStoredActiveCursor
;
85 // Set the cursor to the busy cursor for all windows
86 void wxBeginBusyCursor(const wxCursor
*cursor
)
88 if (gs_wxBusyCursorCount
++ == 0)
90 gMacStoredActiveCursor
= gMacCurrentCursor
;
95 //else: nothing to do, already set
98 // Restore cursor to normal
99 void wxEndBusyCursor()
101 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
102 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
104 if (--gs_wxBusyCursorCount
== 0)
106 gMacStoredActiveCursor
.MacInstall();
107 gMacStoredActiveCursor
= wxNullCursor
;
109 wxSetCursor(wxNullCursor
);
113 // true if we're between the above two calls
116 return (gs_wxBusyCursorCount
> 0);
123 wxString
wxMacFindFolderNoSeparator( short vol
,
125 Boolean createFolder
)
130 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
132 strDir
= wxMacFSRefToPath( &fsRef
);
138 wxString
wxMacFindFolder( short vol
,
140 Boolean createFolder
)
142 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
149 void wxGetMousePosition( int* x
, int* y
)
159 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
161 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
163 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
166 *x
= bounds
.origin
.x
;
168 *y
= bounds
.origin
.y
;
170 *width
= bounds
.size
.width
;
172 *height
= bounds
.size
.height
;
175 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
181 *width
= r
.right
- r
.left
;
183 *height
= r
.bottom
- r
.top
;
190 // ----------------------------------------------------------------------------
191 // Common Event Support
192 // ----------------------------------------------------------------------------
196 OSStatus err
= noErr
;
200 // lead sometimes to race conditions, although all calls used should be thread safe ...
201 static wxMacCarbonEvent s_wakeupEvent
;
202 if ( !s_wakeupEvent
.IsValid() )
204 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
205 kEventAttributeNone
);
210 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
212 s_wakeupEvent
.SetCurrentTime();
213 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
214 kEventPriorityHigh
);
217 wxMacCarbonEvent wakeupEvent
;
218 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
219 kEventAttributeNone
);
220 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
221 kEventPriorityHigh
);
230 // ----------------------------------------------------------------------------
231 // Native Struct Conversions
232 // ----------------------------------------------------------------------------
234 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
238 n
->right
= wx
->x
+ wx
->width
;
239 n
->bottom
= wx
->y
+ wx
->height
;
242 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
246 wx
->width
= n
->right
- n
->left
;
247 wx
->height
= n
->bottom
- n
->top
;
250 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
256 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
262 // ----------------------------------------------------------------------------
263 // Carbon Event Support
264 // ----------------------------------------------------------------------------
266 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
268 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
271 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
273 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
276 // ----------------------------------------------------------------------------
277 // Control Access Support
278 // ----------------------------------------------------------------------------
281 // ============================================================================
282 // DataBrowser Wrapper
283 // ============================================================================
285 // basing on DataBrowserItemIDs
288 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
290 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
292 DataBrowserItemID itemID
,
293 DataBrowserItemNotification message
,
294 DataBrowserItemDataRef itemData
)
296 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
299 ctl
->ItemNotification(itemID
, message
, itemData
);
303 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
305 DataBrowserItemID itemID
,
306 DataBrowserPropertyID property
,
307 DataBrowserItemDataRef itemData
,
308 Boolean changeValue
)
310 OSStatus err
= errDataBrowserPropertyNotSupported
;
311 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
314 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
319 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
321 DataBrowserItemID itemOneID
,
322 DataBrowserItemID itemTwoID
,
323 DataBrowserPropertyID sortProperty
)
325 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
328 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
333 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
334 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
335 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
337 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
340 long WXUNUSED(style
))
341 : wxMacControl( peer
)
343 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
344 OSStatus err
= ::CreateDataBrowserControl(
345 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
346 &bounds
, kDataBrowserListView
, &m_controlRef
);
347 SetReferenceInNativeControl();
349 if ( gDataBrowserItemCompareUPP
== NULL
)
350 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
351 if ( gDataBrowserItemDataUPP
== NULL
)
352 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
353 if ( gDataBrowserItemNotificationUPP
== NULL
)
355 gDataBrowserItemNotificationUPP
=
356 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
359 DataBrowserCallbacks callbacks
;
360 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
362 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
363 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
364 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
365 SetCallbacks( &callbacks
);
369 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
371 DataBrowserItemState state
,
372 ItemCount
*numItems
) const
374 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
377 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
379 DataBrowserItemState state
,
382 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
385 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
387 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
390 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
391 DataBrowserTableViewColumnIndex position
)
393 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
396 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
397 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
400 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
402 DataBrowserTableViewColumnID id
;
403 GetColumnIDFromIndex( position
, &id
);
404 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
407 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
409 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
412 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
414 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
417 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
419 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
422 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
424 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
427 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
429 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
432 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
434 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
437 OSStatus
wxMacDataBrowserControl::UpdateItems(
438 DataBrowserItemID container
,
440 const DataBrowserItemID
*items
,
441 DataBrowserPropertyID preSortProperty
,
442 DataBrowserPropertyID propertyID
) const
444 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
447 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
449 return IsDataBrowserItemSelected( m_controlRef
, item
);
452 OSStatus
wxMacDataBrowserControl::AddItems(
453 DataBrowserItemID container
,
455 const DataBrowserItemID
*items
,
456 DataBrowserPropertyID preSortProperty
)
458 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
461 OSStatus
wxMacDataBrowserControl::RemoveItems(
462 DataBrowserItemID container
,
464 const DataBrowserItemID
*items
,
465 DataBrowserPropertyID preSortProperty
)
467 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
470 OSStatus
wxMacDataBrowserControl::RevealItem(
471 DataBrowserItemID item
,
472 DataBrowserPropertyID propertyID
,
473 DataBrowserRevealOptions options
) const
475 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
478 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
480 const DataBrowserItemID
*items
,
481 DataBrowserSetOption operation
)
483 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
486 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
488 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
491 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
493 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
496 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
498 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
501 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
503 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
506 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
508 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
511 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
513 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
516 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
518 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
521 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
523 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
526 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
528 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
531 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
533 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
536 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
538 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
541 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
543 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
546 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
547 DataBrowserTableViewColumnIndex
*position
) const
549 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
552 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
554 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
557 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
559 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
562 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
564 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
567 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
569 return GetDataBrowserSortProperty( m_controlRef
, column
);
572 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
574 return SetDataBrowserSortProperty( m_controlRef
, column
);
577 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
579 return GetDataBrowserSortOrder( m_controlRef
, order
);
582 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
584 return SetDataBrowserSortOrder( m_controlRef
, order
);
587 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
588 DataBrowserPropertyFlags
*flags
) const
590 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
593 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
594 DataBrowserPropertyFlags flags
)
596 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
599 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
600 DataBrowserListViewHeaderDesc
*desc
) const
602 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
605 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
606 DataBrowserListViewHeaderDesc
*desc
)
608 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
611 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
612 Boolean expandableRows
)
614 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
617 // ============================================================================
618 // Higher-level Databrowser
619 // ============================================================================
621 // basing on data item objects
624 wxMacDataItem::wxMacDataItem()
629 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
632 wxMacDataItem::~wxMacDataItem()
636 void wxMacDataItem::SetOrder( SInt32 order
)
641 SInt32
wxMacDataItem::GetOrder() const
646 void wxMacDataItem::SetData( void* data)
651 void* wxMacDataItem::GetData() const
656 short wxMacDataItem::GetColumn()
661 void wxMacDataItem::SetColumn( short col )
666 void wxMacDataItem::SetLabel( const wxString& str)
669 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
672 const wxString& wxMacDataItem::GetLabel() const
678 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
679 const wxMacDataItem
* rhs
,
680 DataBrowserPropertyID sortProperty
) const
682 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
685 if ( sortProperty
== kNumericOrderColumnId
)
686 retval
= m_order
< otherItem
->m_order
;
691 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
692 DataBrowserPropertyID property
,
693 DataBrowserItemDataRef itemData
,
696 OSStatus err
= errDataBrowserPropertyNotSupported
;
699 if ( property
== kNumericOrderColumnId
)
701 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
709 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
710 DataBrowserItemNotification
WXUNUSED(message
),
711 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
715 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
717 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
718 wxMacDataBrowserControl( peer
, pos
, size
, style
)
720 m_suppressSelection
= false;
721 m_sortOrder
= SortOrder_None
;
722 m_clientDataItemsType
= wxClientData_None
;
725 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
727 m_former
= browser
->SuppressSelection(true);
731 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
733 m_browser
->SuppressSelection(m_former
);
736 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
738 bool former
= m_suppressSelection
;
739 m_suppressSelection
= suppress
;
744 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
745 DataBrowserItemID itemTwoID
,
746 DataBrowserPropertyID sortProperty
)
748 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
749 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
750 return CompareItems( itemOne
, itemTwo
, sortProperty
);
753 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
754 const wxMacDataItem
* itemTwo
,
755 DataBrowserPropertyID sortProperty
)
757 Boolean retval
= false;
758 if ( itemOne
!= NULL
)
759 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
763 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
764 DataBrowserItemID itemID
,
765 DataBrowserPropertyID property
,
766 DataBrowserItemDataRef itemData
,
767 Boolean changeValue
)
769 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
770 return GetSetItemData(item
, property
, itemData
, changeValue
);
773 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
775 DataBrowserPropertyID property
,
776 DataBrowserItemDataRef itemData
,
777 Boolean changeValue
)
779 OSStatus err
= errDataBrowserPropertyNotSupported
;
782 case kDataBrowserContainerIsClosableProperty
:
783 case kDataBrowserContainerIsSortableProperty
:
784 case kDataBrowserContainerIsOpenableProperty
:
785 // right now default behaviour on these
790 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
798 void wxMacDataItemBrowserControl::ItemNotification(
799 DataBrowserItemID itemID
,
800 DataBrowserItemNotification message
,
801 DataBrowserItemDataRef itemData
)
803 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
804 ItemNotification( item
, message
, itemData
);
807 void wxMacDataItemBrowserControl::ItemNotification(
808 const wxMacDataItem
* item
,
809 DataBrowserItemNotification message
,
810 DataBrowserItemDataRef itemData
)
813 item
->Notification( this, message
, itemData
);
816 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
817 bool recurse
, DataBrowserItemState state
) const
819 ItemCount numItems
= 0;
820 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
821 recurse
, state
, &numItems
) );
825 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
828 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
832 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
833 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
835 Handle handle
= NewHandle(0);
836 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
837 recurse
, state
, handle
) );
839 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
841 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
842 for ( int i
= 0; i
< itemCount
; ++i
)
844 items
.Add(itemsArray
[i
]);
847 DisposeHandle( handle
);
850 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
852 DataBrowserTableViewRowIndex row
;
853 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
854 wxCHECK( err
== noErr
, (unsigned)-1 );
858 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
860 DataBrowserItemID id
;
861 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
862 wxCHECK( err
== noErr
, NULL
);
863 return (wxMacDataItem
*) id
;
866 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
867 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
869 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
870 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
873 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
874 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
876 unsigned int noItems
= itemArray
.GetCount();
877 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
878 for ( unsigned int i
= 0; i
< noItems
; ++i
)
879 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
881 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
882 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
886 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
887 const wxString
& title
, SInt16 just
, int defaultWidth
)
889 DataBrowserListViewColumnDesc columnDesc
;
890 columnDesc
.headerBtnDesc
.titleOffset
= 0;
891 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
893 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
894 kControlUseFontMask
| kControlUseJustMask
;
896 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
897 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
898 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
899 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
901 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
902 // defined for other modes?
905 enc
= m_font
.GetEncoding();
907 enc
= wxLocale::GetSystemEncoding();
908 wxCFStringRef
cfTitle( title
, enc
);
909 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
911 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
912 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
914 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
915 columnDesc
.propertyDesc
.propertyType
= colType
;
916 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
917 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
918 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
920 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
922 if (defaultWidth
> 0){
923 SetColumnWidth(colId
, defaultWidth
);
928 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
930 DataBrowserPropertyID id
;
931 GetColumnIDFromIndex(colId
, &id
);
932 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
935 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
937 DataBrowserPropertyID id
;
938 GetColumnIDFromIndex(colId
, &id
);
940 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
944 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
946 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
947 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
950 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
952 unsigned int noItems
= itemArray
.GetCount();
953 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
954 for ( unsigned int i
= 0; i
< noItems
; ++i
)
955 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
957 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
958 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
962 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
964 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
965 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
969 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
971 unsigned int noItems
= itemArray
.GetCount();
972 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
973 for ( unsigned int i
= 0; i
< noItems
; ++i
)
974 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
976 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
977 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
982 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
984 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
988 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
990 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
993 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
995 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
998 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1000 unsigned int noItems
= itemArray
.GetCount();
1001 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1002 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1003 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1005 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1009 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1011 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1014 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1016 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1019 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1021 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1024 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1026 return m_clientDataItemsType
;
1028 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1030 m_clientDataItemsType
= clientDataItemsType
;
1033 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1035 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1036 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1039 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
1041 if ( m_sortOrder
== SortOrder_None
)
1044 // increase the order of the lines to be shifted
1045 unsigned int lines
= MacGetCount();
1046 for ( unsigned int i
= n
; i
< lines
; ++i
)
1048 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1049 iter
->SetOrder( iter
->GetOrder() + 1 );
1053 // I don't understand what this code is supposed to do, RR.
1054 SInt32 frontLineOrder
= 0;
1057 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1058 frontLineOrder
= iter
->GetOrder()+1;
1061 item
->SetOrder( n
);
1065 AddItem( wxMacDataBrowserRootContainer
, item
);
1068 void wxMacDataItemBrowserControl::MacClear()
1070 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1071 RemoveAllItems(wxMacDataBrowserRootContainer
);
1074 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1076 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);