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
684 if ( sortProperty
== kNumericOrderColumnId
)
685 retval
= m_order
< rhs
->m_order
;
690 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
691 DataBrowserPropertyID property
,
692 DataBrowserItemDataRef itemData
,
695 OSStatus err
= errDataBrowserPropertyNotSupported
;
698 if ( property
== kNumericOrderColumnId
)
700 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
708 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
709 DataBrowserItemNotification
WXUNUSED(message
),
710 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
714 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
716 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
717 wxMacDataBrowserControl( peer
, pos
, size
, style
)
719 m_suppressSelection
= false;
720 m_sortOrder
= SortOrder_None
;
721 m_clientDataItemsType
= wxClientData_None
;
724 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
726 m_former
= browser
->SuppressSelection(true);
730 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
732 m_browser
->SuppressSelection(m_former
);
735 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
737 bool former
= m_suppressSelection
;
738 m_suppressSelection
= suppress
;
743 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
744 DataBrowserItemID itemTwoID
,
745 DataBrowserPropertyID sortProperty
)
747 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
748 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
749 return CompareItems( itemOne
, itemTwo
, sortProperty
);
752 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
753 const wxMacDataItem
* itemTwo
,
754 DataBrowserPropertyID sortProperty
)
756 Boolean retval
= false;
757 if ( itemOne
!= NULL
)
758 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
762 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
763 DataBrowserItemID itemID
,
764 DataBrowserPropertyID property
,
765 DataBrowserItemDataRef itemData
,
766 Boolean changeValue
)
768 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
769 return GetSetItemData(item
, property
, itemData
, changeValue
);
772 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
774 DataBrowserPropertyID property
,
775 DataBrowserItemDataRef itemData
,
776 Boolean changeValue
)
778 OSStatus err
= errDataBrowserPropertyNotSupported
;
781 case kDataBrowserContainerIsClosableProperty
:
782 case kDataBrowserContainerIsSortableProperty
:
783 case kDataBrowserContainerIsOpenableProperty
:
784 // right now default behaviour on these
789 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
797 void wxMacDataItemBrowserControl::ItemNotification(
798 DataBrowserItemID itemID
,
799 DataBrowserItemNotification message
,
800 DataBrowserItemDataRef itemData
)
802 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
803 ItemNotification( item
, message
, itemData
);
806 void wxMacDataItemBrowserControl::ItemNotification(
807 const wxMacDataItem
* item
,
808 DataBrowserItemNotification message
,
809 DataBrowserItemDataRef itemData
)
812 item
->Notification( this, message
, itemData
);
815 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
816 bool recurse
, DataBrowserItemState state
) const
818 ItemCount numItems
= 0;
819 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
820 recurse
, state
, &numItems
) );
824 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
827 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
831 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
832 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
834 Handle handle
= NewHandle(0);
835 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
836 recurse
, state
, handle
) );
838 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
840 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
841 for ( int i
= 0; i
< itemCount
; ++i
)
843 items
.Add(itemsArray
[i
]);
846 DisposeHandle( handle
);
849 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
851 DataBrowserTableViewRowIndex row
;
852 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
853 wxCHECK( err
== noErr
, (unsigned)-1 );
857 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
859 DataBrowserItemID id
;
860 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
861 wxCHECK( err
== noErr
, NULL
);
862 return (wxMacDataItem
*) id
;
865 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
866 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
868 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
869 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
872 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
873 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
875 unsigned int noItems
= itemArray
.GetCount();
876 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
877 for ( unsigned int i
= 0; i
< noItems
; ++i
)
878 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
880 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
881 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
885 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
886 const wxString
& title
, SInt16 just
, int defaultWidth
)
888 DataBrowserListViewColumnDesc columnDesc
;
889 columnDesc
.headerBtnDesc
.titleOffset
= 0;
890 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
892 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
893 kControlUseFontMask
| kControlUseJustMask
;
895 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
896 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
897 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
898 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
900 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
901 // defined for other modes?
904 enc
= m_font
.GetEncoding();
906 enc
= wxLocale::GetSystemEncoding();
907 wxCFStringRef
cfTitle( title
, enc
);
908 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
910 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
911 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
913 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
914 columnDesc
.propertyDesc
.propertyType
= colType
;
915 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
916 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
917 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
919 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
921 if (defaultWidth
> 0){
922 SetColumnWidth(colId
, defaultWidth
);
927 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
929 DataBrowserPropertyID id
;
930 GetColumnIDFromIndex(colId
, &id
);
931 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
934 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
936 DataBrowserPropertyID id
;
937 GetColumnIDFromIndex(colId
, &id
);
939 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
943 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
945 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
946 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
949 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
951 unsigned int noItems
= itemArray
.GetCount();
952 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
953 for ( unsigned int i
= 0; i
< noItems
; ++i
)
954 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
956 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
957 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
961 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
963 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
964 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
968 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
970 unsigned int noItems
= itemArray
.GetCount();
971 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
972 for ( unsigned int i
= 0; i
< noItems
; ++i
)
973 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
975 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
976 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
981 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
983 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
987 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
989 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
992 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
994 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
997 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
999 unsigned int noItems
= itemArray
.GetCount();
1000 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1001 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1002 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1004 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1008 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1010 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1013 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1015 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1018 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1020 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1023 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1025 return m_clientDataItemsType
;
1027 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1029 m_clientDataItemsType
= clientDataItemsType
;
1032 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1034 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1035 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1038 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
1040 if ( m_sortOrder
== SortOrder_None
)
1043 // increase the order of the lines to be shifted
1044 unsigned int lines
= MacGetCount();
1045 for ( unsigned int i
= n
; i
< lines
; ++i
)
1047 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1048 iter
->SetOrder( iter
->GetOrder() + 1 );
1052 // I don't understand what this code is supposed to do, RR.
1053 SInt32 frontLineOrder
= 0;
1056 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1057 frontLineOrder
= iter
->GetOrder()+1;
1060 item
->SetOrder( n
);
1064 AddItem( wxMacDataBrowserRootContainer
, item
);
1067 void wxMacDataItemBrowserControl::MacClear()
1069 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1070 RemoveAllItems(wxMacDataBrowserRootContainer
);
1073 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1075 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);