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
)
407 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
410 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
412 DataBrowserTableViewColumnID id
;
413 GetColumnIDFromIndex( position
, &id
);
414 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
417 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
419 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
422 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
424 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
427 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
429 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
432 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
434 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
437 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
439 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
442 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
444 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
447 OSStatus
wxMacDataBrowserControl::UpdateItems(
448 DataBrowserItemID container
,
450 const DataBrowserItemID
*items
,
451 DataBrowserPropertyID preSortProperty
,
452 DataBrowserPropertyID propertyID
) const
454 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
457 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
459 return IsDataBrowserItemSelected( m_controlRef
, item
);
462 OSStatus
wxMacDataBrowserControl::AddItems(
463 DataBrowserItemID container
,
465 const DataBrowserItemID
*items
,
466 DataBrowserPropertyID preSortProperty
)
468 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
471 OSStatus
wxMacDataBrowserControl::RemoveItems(
472 DataBrowserItemID container
,
474 const DataBrowserItemID
*items
,
475 DataBrowserPropertyID preSortProperty
)
477 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
480 OSStatus
wxMacDataBrowserControl::RevealItem(
481 DataBrowserItemID item
,
482 DataBrowserPropertyID propertyID
,
483 DataBrowserRevealOptions options
) const
485 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
488 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
490 const DataBrowserItemID
*items
,
491 DataBrowserSetOption operation
)
493 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
496 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
498 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
501 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
503 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
506 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
508 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
511 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
513 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
516 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
518 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
521 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
523 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
526 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
528 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
531 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
533 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
536 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
538 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
541 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
543 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
546 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
548 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
551 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
553 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
556 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
557 DataBrowserTableViewColumnIndex
*position
) const
559 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
562 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
564 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
567 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
569 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
572 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
574 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
577 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
579 return GetDataBrowserSortProperty( m_controlRef
, column
);
582 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
584 return SetDataBrowserSortProperty( m_controlRef
, column
);
587 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
589 return GetDataBrowserSortOrder( m_controlRef
, order
);
592 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
594 return SetDataBrowserSortOrder( m_controlRef
, order
);
597 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
598 DataBrowserPropertyFlags
*flags
) const
600 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
603 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
604 DataBrowserPropertyFlags flags
)
606 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
609 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
610 DataBrowserListViewHeaderDesc
*desc
) const
612 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
615 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
616 DataBrowserListViewHeaderDesc
*desc
)
618 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
621 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
622 Boolean expandableRows
)
624 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
627 // ============================================================================
628 // Higher-level Databrowser
629 // ============================================================================
631 // basing on data item objects
634 wxMacDataItem::wxMacDataItem()
639 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
642 wxMacDataItem::~wxMacDataItem()
646 void wxMacDataItem::SetOrder( SInt32 order
)
651 SInt32
wxMacDataItem::GetOrder() const
656 void wxMacDataItem::SetData( void* data)
661 void* wxMacDataItem::GetData() const
666 short wxMacDataItem::GetColumn()
671 void wxMacDataItem::SetColumn( short col )
676 void wxMacDataItem::SetLabel( const wxString& str)
679 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
682 const wxString& wxMacDataItem::GetLabel() const
688 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
689 const wxMacDataItem
* rhs
,
690 DataBrowserPropertyID sortProperty
) const
694 if ( sortProperty
== kNumericOrderColumnId
)
695 retval
= m_order
< rhs
->m_order
;
700 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
701 DataBrowserPropertyID property
,
702 DataBrowserItemDataRef itemData
,
705 OSStatus err
= errDataBrowserPropertyNotSupported
;
708 if ( property
== kNumericOrderColumnId
)
710 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
718 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
719 DataBrowserItemNotification
WXUNUSED(message
),
720 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
724 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
726 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
727 wxMacDataBrowserControl( peer
, pos
, size
, style
)
729 m_suppressSelection
= false;
730 m_sortOrder
= SortOrder_None
;
731 m_clientDataItemsType
= wxClientData_None
;
734 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
736 m_former
= browser
->SuppressSelection(true);
740 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
742 m_browser
->SuppressSelection(m_former
);
745 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
747 bool former
= m_suppressSelection
;
748 m_suppressSelection
= suppress
;
753 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
754 DataBrowserItemID itemTwoID
,
755 DataBrowserPropertyID sortProperty
)
757 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
758 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
760 Boolean retval
= false;
761 if ( itemOne
!= NULL
)
762 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
766 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
767 DataBrowserItemID itemID
,
768 DataBrowserPropertyID property
,
769 DataBrowserItemDataRef itemData
,
770 Boolean changeValue
)
772 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
773 OSStatus err
= errDataBrowserPropertyNotSupported
;
776 case kDataBrowserContainerIsClosableProperty
:
777 case kDataBrowserContainerIsSortableProperty
:
778 case kDataBrowserContainerIsOpenableProperty
:
779 // right now default behaviour on these
784 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
792 void wxMacDataItemBrowserControl::ItemNotification(
793 DataBrowserItemID itemID
,
794 DataBrowserItemNotification message
,
795 DataBrowserItemDataRef itemData
)
797 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
799 item
->Notification( this, message
, itemData
);
802 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
803 bool recurse
, DataBrowserItemState state
) const
805 ItemCount numItems
= 0;
806 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
807 recurse
, state
, &numItems
) );
811 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
814 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
818 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
819 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
821 Handle handle
= NewHandle(0);
822 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
823 recurse
, state
, handle
) );
825 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
827 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
828 for ( int i
= 0; i
< itemCount
; ++i
)
830 items
.Add(itemsArray
[i
]);
833 DisposeHandle( handle
);
836 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
838 DataBrowserTableViewRowIndex row
;
839 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
840 wxCHECK( err
== noErr
, (unsigned)-1 );
844 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
846 DataBrowserItemID id
;
847 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
848 wxCHECK( err
== noErr
, NULL
);
849 return (wxMacDataItem
*) id
;
852 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
853 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
855 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
856 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
859 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
860 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
862 unsigned int noItems
= itemArray
.GetCount();
863 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
864 for ( unsigned int i
= 0; i
< noItems
; ++i
)
865 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
867 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
868 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
872 static int column_id_counter
= 0;
874 void wxMacDataItemBrowserControl::InsertColumn(int col
, DataBrowserPropertyType colType
,
875 const wxString
& title
, SInt16 just
, int defaultWidth
)
877 DataBrowserListViewColumnDesc columnDesc
;
878 columnDesc
.headerBtnDesc
.titleOffset
= 0;
879 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
881 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
882 kControlUseFontMask
| kControlUseJustMask
;
884 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
885 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
886 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
887 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
889 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
890 // defined for other modes?
893 enc
= m_font
.GetEncoding();
895 enc
= wxLocale::GetSystemEncoding();
896 wxCFStringRef
cfTitle( title
, enc
);
897 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
899 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
900 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
902 DataBrowserPropertyID id
= kMinColumnId
+ column_id_counter
;
905 columnDesc
.propertyDesc
.propertyID
= id
;
906 columnDesc
.propertyDesc
.propertyType
= colType
;
907 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
908 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
909 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
911 verify_noerr( AddColumn( &columnDesc
, col
) );
913 if (defaultWidth
> 0){
914 SetColumnWidth(col
, defaultWidth
);
918 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
920 DataBrowserPropertyID id
;
921 GetColumnIDFromIndex(colId
, &id
);
922 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
925 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
927 DataBrowserPropertyID id
;
928 GetColumnIDFromIndex(colId
, &id
);
930 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
934 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
936 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
937 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
940 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
942 unsigned int noItems
= itemArray
.GetCount();
943 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
944 for ( unsigned int i
= 0; i
< noItems
; ++i
)
945 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
947 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
948 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
952 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
954 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
955 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
959 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
961 unsigned int noItems
= itemArray
.GetCount();
962 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
963 for ( unsigned int i
= 0; i
< noItems
; ++i
)
964 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
966 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
967 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
972 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
974 SetScrollPosition(0, 0);
975 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
979 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
981 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
984 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
986 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
989 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
991 unsigned int noItems
= itemArray
.GetCount();
992 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
993 for ( unsigned int i
= 0; i
< noItems
; ++i
)
994 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
996 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1000 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1002 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1005 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1007 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1010 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
1012 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
1015 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
1017 return m_clientDataItemsType
;
1019 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
1021 m_clientDataItemsType
= clientDataItemsType
;
1024 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
1026 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
1027 RemoveItem( wxMacDataBrowserRootContainer
, item
);
1030 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
1032 if ( m_sortOrder
== SortOrder_None
)
1035 // increase the order of the lines to be shifted
1036 unsigned int lines
= MacGetCount();
1037 for ( unsigned int i
= n
; i
< lines
; ++i
)
1039 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1040 iter
->SetOrder( iter
->GetOrder() + 1 );
1044 // I don't understand what this code is supposed to do, RR.
1045 SInt32 frontLineOrder
= 0;
1048 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1049 frontLineOrder
= iter
->GetOrder()+1;
1052 item
->SetOrder( n
);
1056 AddItem( wxMacDataBrowserRootContainer
, item
);
1059 void wxMacDataItemBrowserControl::MacClear()
1061 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1062 RemoveAllItems(wxMacDataBrowserRootContainer
);
1065 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1067 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);