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 // wxMac Specific string utility functions
264 //---------------------------------------------------------------------------
266 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
268 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
269 int len
= strlen(buf
);
274 memcpy( (char*) &to
[1] , buf
, len
);
277 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
279 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
283 // ----------------------------------------------------------------------------
284 // Carbon Event Support
285 // ----------------------------------------------------------------------------
287 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
289 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
292 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
294 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
297 // ----------------------------------------------------------------------------
298 // Control Access Support
299 // ----------------------------------------------------------------------------
302 // ============================================================================
303 // DataBrowser Wrapper
304 // ============================================================================
306 // basing on DataBrowserItemIDs
309 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
311 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
313 DataBrowserItemID itemID
,
314 DataBrowserItemNotification message
,
315 DataBrowserItemDataRef itemData
)
317 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
320 ctl
->ItemNotification(itemID
, message
, itemData
);
324 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
326 DataBrowserItemID itemID
,
327 DataBrowserPropertyID property
,
328 DataBrowserItemDataRef itemData
,
329 Boolean changeValue
)
331 OSStatus err
= errDataBrowserPropertyNotSupported
;
332 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
335 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
340 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
342 DataBrowserItemID itemOneID
,
343 DataBrowserItemID itemTwoID
,
344 DataBrowserPropertyID sortProperty
)
346 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
349 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
354 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
355 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
356 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
358 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
361 long WXUNUSED(style
))
362 : wxMacControl( peer
)
364 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
365 OSStatus err
= ::CreateDataBrowserControl(
366 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
367 &bounds
, kDataBrowserListView
, &m_controlRef
);
368 SetReferenceInNativeControl();
370 if ( gDataBrowserItemCompareUPP
== NULL
)
371 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
372 if ( gDataBrowserItemDataUPP
== NULL
)
373 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
374 if ( gDataBrowserItemNotificationUPP
== NULL
)
376 gDataBrowserItemNotificationUPP
=
377 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
380 DataBrowserCallbacks callbacks
;
381 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
383 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
384 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
385 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
386 SetCallbacks( &callbacks
);
390 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
392 DataBrowserItemState state
,
393 ItemCount
*numItems
) const
395 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
398 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
400 DataBrowserItemState state
,
403 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
406 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
408 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
411 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
412 DataBrowserTableViewColumnIndex position
)
414 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
417 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
418 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
421 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
423 DataBrowserTableViewColumnID id
;
424 GetColumnIDFromIndex( position
, &id
);
425 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
428 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
430 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
433 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
435 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
438 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
440 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
443 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
445 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
448 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
450 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
453 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
455 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
458 OSStatus
wxMacDataBrowserControl::UpdateItems(
459 DataBrowserItemID container
,
461 const DataBrowserItemID
*items
,
462 DataBrowserPropertyID preSortProperty
,
463 DataBrowserPropertyID propertyID
) const
465 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
468 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
470 return IsDataBrowserItemSelected( m_controlRef
, item
);
473 OSStatus
wxMacDataBrowserControl::AddItems(
474 DataBrowserItemID container
,
476 const DataBrowserItemID
*items
,
477 DataBrowserPropertyID preSortProperty
)
479 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
482 OSStatus
wxMacDataBrowserControl::RemoveItems(
483 DataBrowserItemID container
,
485 const DataBrowserItemID
*items
,
486 DataBrowserPropertyID preSortProperty
)
488 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
491 OSStatus
wxMacDataBrowserControl::RevealItem(
492 DataBrowserItemID item
,
493 DataBrowserPropertyID propertyID
,
494 DataBrowserRevealOptions options
) const
496 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
499 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
501 const DataBrowserItemID
*items
,
502 DataBrowserSetOption operation
)
504 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
507 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
509 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
512 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
514 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
517 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
519 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
522 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
524 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
527 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
529 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
532 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
534 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
537 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
539 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
542 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
544 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
547 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
549 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
552 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
554 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
557 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
559 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
562 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
564 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
567 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
568 DataBrowserTableViewColumnIndex
*position
) const
570 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
573 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
575 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
578 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
580 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
583 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
585 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
588 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
590 return GetDataBrowserSortProperty( m_controlRef
, column
);
593 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
595 return SetDataBrowserSortProperty( m_controlRef
, column
);
598 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
600 return GetDataBrowserSortOrder( m_controlRef
, order
);
603 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
605 return SetDataBrowserSortOrder( m_controlRef
, order
);
608 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
609 DataBrowserPropertyFlags
*flags
) const
611 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
614 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
615 DataBrowserPropertyFlags flags
)
617 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
620 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
621 DataBrowserListViewHeaderDesc
*desc
) const
623 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
626 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
627 DataBrowserListViewHeaderDesc
*desc
)
629 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
632 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
633 Boolean expandableRows
)
635 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
638 // ============================================================================
639 // Higher-level Databrowser
640 // ============================================================================
642 // basing on data item objects
645 wxMacDataItem::wxMacDataItem()
650 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
653 wxMacDataItem::~wxMacDataItem()
657 void wxMacDataItem::SetOrder( SInt32 order
)
662 SInt32
wxMacDataItem::GetOrder() const
667 void wxMacDataItem::SetData( void* data)
672 void* wxMacDataItem::GetData() const
677 short wxMacDataItem::GetColumn()
682 void wxMacDataItem::SetColumn( short col )
687 void wxMacDataItem::SetLabel( const wxString& str)
690 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
693 const wxString& wxMacDataItem::GetLabel() const
699 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
700 const wxMacDataItem
* rhs
,
701 DataBrowserPropertyID sortProperty
) const
703 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
706 if ( sortProperty
== kNumericOrderColumnId
)
707 retval
= m_order
< otherItem
->m_order
;
712 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
713 DataBrowserPropertyID property
,
714 DataBrowserItemDataRef itemData
,
717 OSStatus err
= errDataBrowserPropertyNotSupported
;
720 if ( property
== kNumericOrderColumnId
)
722 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
730 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
731 DataBrowserItemNotification
WXUNUSED(message
),
732 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
736 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
738 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
739 wxMacDataBrowserControl( peer
, pos
, size
, style
)
741 m_suppressSelection
= false;
742 m_sortOrder
= SortOrder_None
;
743 m_clientDataItemsType
= wxClientData_None
;
746 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
748 m_former
= browser
->SuppressSelection(true);
752 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
754 m_browser
->SuppressSelection(m_former
);
757 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
759 bool former
= m_suppressSelection
;
760 m_suppressSelection
= suppress
;
765 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
766 DataBrowserItemID itemTwoID
,
767 DataBrowserPropertyID sortProperty
)
769 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
770 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
771 return CompareItems( itemOne
, itemTwo
, sortProperty
);
774 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
775 const wxMacDataItem
* itemTwo
,
776 DataBrowserPropertyID sortProperty
)
778 Boolean retval
= false;
779 if ( itemOne
!= NULL
)
780 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
784 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
785 DataBrowserItemID itemID
,
786 DataBrowserPropertyID property
,
787 DataBrowserItemDataRef itemData
,
788 Boolean changeValue
)
790 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
791 return GetSetItemData(item
, property
, itemData
, changeValue
);
794 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
796 DataBrowserPropertyID property
,
797 DataBrowserItemDataRef itemData
,
798 Boolean changeValue
)
800 OSStatus err
= errDataBrowserPropertyNotSupported
;
803 case kDataBrowserContainerIsClosableProperty
:
804 case kDataBrowserContainerIsSortableProperty
:
805 case kDataBrowserContainerIsOpenableProperty
:
806 // right now default behaviour on these
811 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
819 void wxMacDataItemBrowserControl::ItemNotification(
820 DataBrowserItemID itemID
,
821 DataBrowserItemNotification message
,
822 DataBrowserItemDataRef itemData
)
824 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
825 ItemNotification( item
, message
, itemData
);
828 void wxMacDataItemBrowserControl::ItemNotification(
829 const wxMacDataItem
* item
,
830 DataBrowserItemNotification message
,
831 DataBrowserItemDataRef itemData
)
834 item
->Notification( this, message
, itemData
);
837 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
838 bool recurse
, DataBrowserItemState state
) const
840 ItemCount numItems
= 0;
841 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
842 recurse
, state
, &numItems
) );
846 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
849 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
853 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
854 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
856 Handle handle
= NewHandle(0);
857 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
858 recurse
, state
, handle
) );
860 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
862 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
863 for ( int i
= 0; i
< itemCount
; ++i
)
865 items
.Add(itemsArray
[i
]);
868 DisposeHandle( handle
);
871 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
873 DataBrowserTableViewRowIndex row
;
874 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
875 wxCHECK( err
== noErr
, (unsigned)-1 );
879 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
881 DataBrowserItemID id
;
882 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
883 wxCHECK( err
== noErr
, NULL
);
884 return (wxMacDataItem
*) id
;
887 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
888 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
890 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
891 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
894 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
895 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
897 unsigned int noItems
= itemArray
.GetCount();
898 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
899 for ( unsigned int i
= 0; i
< noItems
; ++i
)
900 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
902 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
903 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
907 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
908 const wxString
& title
, SInt16 just
, int defaultWidth
)
910 DataBrowserListViewColumnDesc columnDesc
;
911 columnDesc
.headerBtnDesc
.titleOffset
= 0;
912 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
914 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
915 kControlUseFontMask
| kControlUseJustMask
;
917 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
918 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
919 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
920 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
922 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
923 // defined for other modes?
926 enc
= m_font
.GetEncoding();
928 enc
= wxLocale::GetSystemEncoding();
929 wxCFStringRef
cfTitle( title
, enc
);
930 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
932 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
933 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
935 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
936 columnDesc
.propertyDesc
.propertyType
= colType
;
937 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
938 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
939 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
941 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
943 if (defaultWidth
> 0){
944 SetColumnWidth(colId
, defaultWidth
);
949 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
951 DataBrowserPropertyID id
;
952 GetColumnIDFromIndex(colId
, &id
);
953 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
956 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
958 DataBrowserPropertyID id
;
959 GetColumnIDFromIndex(colId
, &id
);
961 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
965 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
967 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
968 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
971 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
973 unsigned int noItems
= itemArray
.GetCount();
974 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
975 for ( unsigned int i
= 0; i
< noItems
; ++i
)
976 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
978 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
979 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
983 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
985 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
986 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
990 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
992 unsigned int noItems
= itemArray
.GetCount();
993 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
994 for ( unsigned int i
= 0; i
< noItems
; ++i
)
995 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
997 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
998 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1003 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1005 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1006 verify_noerr( err
);
1009 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1011 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1014 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1016 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1019 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1021 unsigned int noItems
= itemArray
.GetCount();
1022 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1023 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1024 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1026 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1030 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1032 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1035 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1037 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1040 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1042 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1045 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1047 return m_clientDataItemsType
;
1049 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1051 m_clientDataItemsType
= clientDataItemsType
;
1054 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1056 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1057 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1060 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
1062 SInt32 frontLineOrder
= 0;
1064 if ( m_sortOrder
== SortOrder_None
)
1066 // increase the order of the lines to be shifted
1067 unsigned int lines
= MacGetCount();
1068 for ( unsigned int i
= n
; i
< lines
; ++i
)
1070 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1071 iter
->SetOrder( iter
->GetOrder() + 1 );
1075 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1076 frontLineOrder
= iter
->GetOrder();
1080 wxArrayMacDataItemPtr ids
;
1083 if ( m_sortOrder
== SortOrder_None
)
1084 item
->SetOrder( frontLineOrder
+ 1 );
1088 AddItems( wxMacDataBrowserRootContainer
, ids
);
1091 void wxMacDataItemBrowserControl::MacClear()
1093 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1094 RemoveAllItems(wxMacDataBrowserRootContainer
);
1097 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1099 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);