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
;
148 // ============================================================================
149 // GUI-only functions from now on
150 // ============================================================================
154 // ----------------------------------------------------------------------------
155 // Miscellaneous functions
156 // ----------------------------------------------------------------------------
158 void wxGetMousePosition( int* x
, int* y
)
168 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
170 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
172 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
175 *x
= bounds
.origin
.x
;
177 *y
= bounds
.origin
.y
;
179 *width
= bounds
.size
.width
;
181 *height
= bounds
.size
.height
;
184 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
190 *width
= r
.right
- r
.left
;
192 *height
= r
.bottom
- r
.top
;
199 // ----------------------------------------------------------------------------
200 // Common Event Support
201 // ----------------------------------------------------------------------------
205 OSStatus err
= noErr
;
209 // lead sometimes to race conditions, although all calls used should be thread safe ...
210 static wxMacCarbonEvent s_wakeupEvent
;
211 if ( !s_wakeupEvent
.IsValid() )
213 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
214 kEventAttributeNone
);
219 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
221 s_wakeupEvent
.SetCurrentTime();
222 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
223 kEventPriorityHigh
);
226 wxMacCarbonEvent wakeupEvent
;
227 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
228 kEventAttributeNone
);
229 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
230 kEventPriorityHigh
);
239 // ----------------------------------------------------------------------------
240 // Native Struct Conversions
241 // ----------------------------------------------------------------------------
243 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
247 n
->right
= wx
->x
+ wx
->width
;
248 n
->bottom
= wx
->y
+ wx
->height
;
251 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
255 wx
->width
= n
->right
- n
->left
;
256 wx
->height
= n
->bottom
- n
->top
;
259 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
265 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
271 // ----------------------------------------------------------------------------
272 // Carbon Event Support
273 // ----------------------------------------------------------------------------
275 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
277 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
280 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
282 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
285 // ----------------------------------------------------------------------------
286 // Control Access Support
287 // ----------------------------------------------------------------------------
290 // ============================================================================
291 // DataBrowser Wrapper
292 // ============================================================================
294 // basing on DataBrowserItemIDs
297 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
299 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
301 DataBrowserItemID itemID
,
302 DataBrowserItemNotification message
,
303 DataBrowserItemDataRef itemData
)
305 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
308 ctl
->ItemNotification(itemID
, message
, itemData
);
312 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
314 DataBrowserItemID itemID
,
315 DataBrowserPropertyID property
,
316 DataBrowserItemDataRef itemData
,
317 Boolean changeValue
)
319 OSStatus err
= errDataBrowserPropertyNotSupported
;
320 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
323 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
328 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
330 DataBrowserItemID itemOneID
,
331 DataBrowserItemID itemTwoID
,
332 DataBrowserPropertyID sortProperty
)
334 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
337 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
342 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
343 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
344 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
346 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
349 long WXUNUSED(style
))
350 : wxMacControl( peer
)
352 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
353 OSStatus err
= ::CreateDataBrowserControl(
354 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
355 &bounds
, kDataBrowserListView
, &m_controlRef
);
356 SetReferenceInNativeControl();
358 if ( gDataBrowserItemCompareUPP
== NULL
)
359 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
360 if ( gDataBrowserItemDataUPP
== NULL
)
361 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
362 if ( gDataBrowserItemNotificationUPP
== NULL
)
364 gDataBrowserItemNotificationUPP
=
365 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
368 DataBrowserCallbacks callbacks
;
369 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
371 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
372 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
373 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
374 SetCallbacks( &callbacks
);
378 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
380 DataBrowserItemState state
,
381 ItemCount
*numItems
) const
383 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
386 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
388 DataBrowserItemState state
,
391 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
394 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
396 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
399 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
400 DataBrowserTableViewColumnIndex position
)
402 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
405 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
406 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
409 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
411 DataBrowserTableViewColumnID id
;
412 GetColumnIDFromIndex( position
, &id
);
413 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
416 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
418 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
421 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
423 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
426 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
428 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
431 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
433 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
436 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
438 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
441 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
443 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
446 OSStatus
wxMacDataBrowserControl::UpdateItems(
447 DataBrowserItemID container
,
449 const DataBrowserItemID
*items
,
450 DataBrowserPropertyID preSortProperty
,
451 DataBrowserPropertyID propertyID
) const
453 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
456 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
458 return IsDataBrowserItemSelected( m_controlRef
, item
);
461 OSStatus
wxMacDataBrowserControl::AddItems(
462 DataBrowserItemID container
,
464 const DataBrowserItemID
*items
,
465 DataBrowserPropertyID preSortProperty
)
467 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
470 OSStatus
wxMacDataBrowserControl::RemoveItems(
471 DataBrowserItemID container
,
473 const DataBrowserItemID
*items
,
474 DataBrowserPropertyID preSortProperty
)
476 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
479 OSStatus
wxMacDataBrowserControl::RevealItem(
480 DataBrowserItemID item
,
481 DataBrowserPropertyID propertyID
,
482 DataBrowserRevealOptions options
) const
484 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
487 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
489 const DataBrowserItemID
*items
,
490 DataBrowserSetOption operation
)
492 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
495 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
497 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
500 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
502 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
505 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
507 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
510 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
512 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
515 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
517 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
520 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
522 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
525 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
527 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
530 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
532 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
535 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
537 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
540 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
542 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
545 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
547 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
550 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
552 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
555 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
556 DataBrowserTableViewColumnIndex
*position
) const
558 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
561 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
563 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
566 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
568 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
571 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
573 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
576 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
578 return GetDataBrowserSortProperty( m_controlRef
, column
);
581 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
583 return SetDataBrowserSortProperty( m_controlRef
, column
);
586 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
588 return GetDataBrowserSortOrder( m_controlRef
, order
);
591 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
593 return SetDataBrowserSortOrder( m_controlRef
, order
);
596 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
597 DataBrowserPropertyFlags
*flags
) const
599 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
602 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
603 DataBrowserPropertyFlags flags
)
605 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
608 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
609 DataBrowserListViewHeaderDesc
*desc
) const
611 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
614 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
615 DataBrowserListViewHeaderDesc
*desc
)
617 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
620 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
621 Boolean expandableRows
)
623 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
626 // ============================================================================
627 // Higher-level Databrowser
628 // ============================================================================
630 // basing on data item objects
633 wxMacDataItem::wxMacDataItem()
638 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
641 wxMacDataItem::~wxMacDataItem()
645 void wxMacDataItem::SetOrder( SInt32 order
)
650 SInt32
wxMacDataItem::GetOrder() const
655 void wxMacDataItem::SetData( void* data)
660 void* wxMacDataItem::GetData() const
665 short wxMacDataItem::GetColumn()
670 void wxMacDataItem::SetColumn( short col )
675 void wxMacDataItem::SetLabel( const wxString& str)
678 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
681 const wxString& wxMacDataItem::GetLabel() const
687 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
688 const wxMacDataItem
* rhs
,
689 DataBrowserPropertyID sortProperty
) const
693 if ( sortProperty
== kNumericOrderColumnId
)
694 retval
= m_order
< rhs
->m_order
;
699 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
700 DataBrowserPropertyID property
,
701 DataBrowserItemDataRef itemData
,
704 OSStatus err
= errDataBrowserPropertyNotSupported
;
707 if ( property
== kNumericOrderColumnId
)
709 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
717 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
718 DataBrowserItemNotification
WXUNUSED(message
),
719 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
723 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
725 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
726 wxMacDataBrowserControl( peer
, pos
, size
, style
)
728 m_suppressSelection
= false;
729 m_sortOrder
= SortOrder_None
;
730 m_clientDataItemsType
= wxClientData_None
;
733 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
735 m_former
= browser
->SuppressSelection(true);
739 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
741 m_browser
->SuppressSelection(m_former
);
744 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
746 bool former
= m_suppressSelection
;
747 m_suppressSelection
= suppress
;
752 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
753 DataBrowserItemID itemTwoID
,
754 DataBrowserPropertyID sortProperty
)
756 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
757 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
758 return CompareItems( itemOne
, itemTwo
, sortProperty
);
761 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
762 const wxMacDataItem
* itemTwo
,
763 DataBrowserPropertyID sortProperty
)
765 Boolean retval
= false;
766 if ( itemOne
!= NULL
)
767 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
771 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
772 DataBrowserItemID itemID
,
773 DataBrowserPropertyID property
,
774 DataBrowserItemDataRef itemData
,
775 Boolean changeValue
)
777 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
778 return GetSetItemData(item
, property
, itemData
, changeValue
);
781 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
783 DataBrowserPropertyID property
,
784 DataBrowserItemDataRef itemData
,
785 Boolean changeValue
)
787 OSStatus err
= errDataBrowserPropertyNotSupported
;
790 case kDataBrowserContainerIsClosableProperty
:
791 case kDataBrowserContainerIsSortableProperty
:
792 case kDataBrowserContainerIsOpenableProperty
:
793 // right now default behaviour on these
798 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
806 void wxMacDataItemBrowserControl::ItemNotification(
807 DataBrowserItemID itemID
,
808 DataBrowserItemNotification message
,
809 DataBrowserItemDataRef itemData
)
811 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
812 ItemNotification( item
, message
, itemData
);
815 void wxMacDataItemBrowserControl::ItemNotification(
816 const wxMacDataItem
* item
,
817 DataBrowserItemNotification message
,
818 DataBrowserItemDataRef itemData
)
821 item
->Notification( this, message
, itemData
);
824 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
825 bool recurse
, DataBrowserItemState state
) const
827 ItemCount numItems
= 0;
828 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
829 recurse
, state
, &numItems
) );
833 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
836 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
840 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
841 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
843 Handle handle
= NewHandle(0);
844 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
845 recurse
, state
, handle
) );
847 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
849 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
850 for ( int i
= 0; i
< itemCount
; ++i
)
852 items
.Add(itemsArray
[i
]);
855 DisposeHandle( handle
);
858 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
860 DataBrowserTableViewRowIndex row
;
861 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
862 wxCHECK( err
== noErr
, (unsigned)-1 );
866 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
868 DataBrowserItemID id
;
869 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
870 wxCHECK( err
== noErr
, NULL
);
871 return (wxMacDataItem
*) id
;
874 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
875 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
877 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
878 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
881 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
882 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
884 unsigned int noItems
= itemArray
.GetCount();
885 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
886 for ( unsigned int i
= 0; i
< noItems
; ++i
)
887 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
889 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
890 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
894 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
895 const wxString
& title
, SInt16 just
, int defaultWidth
)
897 DataBrowserListViewColumnDesc columnDesc
;
898 columnDesc
.headerBtnDesc
.titleOffset
= 0;
899 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
901 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
902 kControlUseFontMask
| kControlUseJustMask
;
904 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
905 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
906 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
907 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
909 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
910 // defined for other modes?
913 enc
= m_font
.GetEncoding();
915 enc
= wxLocale::GetSystemEncoding();
916 wxCFStringRef
cfTitle( title
, enc
);
917 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
919 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
920 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
922 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
923 columnDesc
.propertyDesc
.propertyType
= colType
;
924 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
925 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
926 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
928 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
930 if (defaultWidth
> 0){
931 SetColumnWidth(colId
, defaultWidth
);
936 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
938 DataBrowserPropertyID id
;
939 GetColumnIDFromIndex(colId
, &id
);
940 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
943 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
945 DataBrowserPropertyID id
;
946 GetColumnIDFromIndex(colId
, &id
);
948 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
952 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
954 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
955 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
958 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
960 unsigned int noItems
= itemArray
.GetCount();
961 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
962 for ( unsigned int i
= 0; i
< noItems
; ++i
)
963 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
965 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
966 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
970 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
972 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
973 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
977 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
979 unsigned int noItems
= itemArray
.GetCount();
980 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
981 for ( unsigned int i
= 0; i
< noItems
; ++i
)
982 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
984 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
985 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
990 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
992 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
996 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
998 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1001 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1003 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1006 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1008 unsigned int noItems
= itemArray
.GetCount();
1009 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1010 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1011 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1013 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1017 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1019 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1022 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1024 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1027 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1029 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1032 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1034 return m_clientDataItemsType
;
1036 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1038 m_clientDataItemsType
= clientDataItemsType
;
1041 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1043 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1044 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1047 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
1049 if ( m_sortOrder
== SortOrder_None
)
1052 // increase the order of the lines to be shifted
1053 unsigned int lines
= MacGetCount();
1054 for ( unsigned int i
= n
; i
< lines
; ++i
)
1056 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1057 iter
->SetOrder( iter
->GetOrder() + 1 );
1061 // I don't understand what this code is supposed to do, RR.
1062 SInt32 frontLineOrder
= 0;
1065 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1066 frontLineOrder
= iter
->GetOrder()+1;
1069 item
->SetOrder( n
);
1073 AddItem( wxMacDataBrowserRootContainer
, item
);
1076 void wxMacDataItemBrowserControl::MacClear()
1078 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1079 RemoveAllItems(wxMacDataBrowserRootContainer
);
1082 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1084 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);