1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
34 // #include "MoreFilesX.h"
36 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
37 #include <AudioToolbox/AudioServices.h>
40 #include "wx/osx/private.h"
42 #include "wx/osx/private/timer.h"
45 #include "wx/evtloop.h"
52 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
53 if ( AudioServicesPlayAlertSound
!= NULL
)
54 AudioServicesPlayAlertSound(kUserPreferredAlert
);
57 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
65 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
67 return new wxOSXTimerImpl(timer
);
70 int gs_wxBusyCursorCount
= 0;
71 extern wxCursor gMacCurrentCursor
;
72 wxCursor gMacStoredActiveCursor
;
74 // Set the cursor to the busy cursor for all windows
75 void wxBeginBusyCursor(const wxCursor
*cursor
)
77 if (gs_wxBusyCursorCount
++ == 0)
79 gMacStoredActiveCursor
= gMacCurrentCursor
;
84 //else: nothing to do, already set
87 // Restore cursor to normal
88 void wxEndBusyCursor()
90 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
91 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
93 if (--gs_wxBusyCursorCount
== 0)
95 gMacStoredActiveCursor
.MacInstall();
96 gMacStoredActiveCursor
= wxNullCursor
;
98 wxSetCursor(wxNullCursor
);
102 // true if we're between the above two calls
105 return (gs_wxBusyCursorCount
> 0);
112 wxString
wxMacFindFolderNoSeparator( short vol
,
114 Boolean createFolder
)
119 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
121 strDir
= wxMacFSRefToPath( &fsRef
);
127 wxString
wxMacFindFolder( short vol
,
129 Boolean createFolder
)
131 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
137 // ============================================================================
138 // GUI-only functions from now on
139 // ============================================================================
143 // ----------------------------------------------------------------------------
144 // Miscellaneous functions
145 // ----------------------------------------------------------------------------
147 void wxGetMousePosition( int* x
, int* y
)
157 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
159 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
161 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
164 *x
= bounds
.origin
.x
;
166 *y
= bounds
.origin
.y
;
168 *width
= bounds
.size
.width
;
170 *height
= bounds
.size
.height
;
173 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
179 *width
= r
.right
- r
.left
;
181 *height
= r
.bottom
- r
.top
;
189 // ----------------------------------------------------------------------------
190 // Native Struct Conversions
191 // ----------------------------------------------------------------------------
193 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
197 n
->right
= wx
->x
+ wx
->width
;
198 n
->bottom
= wx
->y
+ wx
->height
;
201 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
205 wx
->width
= n
->right
- n
->left
;
206 wx
->height
= n
->bottom
- n
->top
;
209 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
215 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
221 // ----------------------------------------------------------------------------
222 // Carbon Event Support
223 // ----------------------------------------------------------------------------
225 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
227 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
230 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
232 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
235 // ----------------------------------------------------------------------------
236 // Control Access Support
237 // ----------------------------------------------------------------------------
240 // ============================================================================
241 // DataBrowser Wrapper
242 // ============================================================================
244 // basing on DataBrowserItemIDs
247 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
249 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
251 DataBrowserItemID itemID
,
252 DataBrowserItemNotification message
,
253 DataBrowserItemDataRef itemData
)
255 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
258 ctl
->ItemNotification(itemID
, message
, itemData
);
262 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
264 DataBrowserItemID itemID
,
265 DataBrowserPropertyID property
,
266 DataBrowserItemDataRef itemData
,
267 Boolean changeValue
)
269 OSStatus err
= errDataBrowserPropertyNotSupported
;
270 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
273 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
278 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
280 DataBrowserItemID itemOneID
,
281 DataBrowserItemID itemTwoID
,
282 DataBrowserPropertyID sortProperty
)
284 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
287 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
292 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
293 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
294 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
296 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
299 long WXUNUSED(style
))
300 : wxMacControl( peer
)
302 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
303 OSStatus err
= ::CreateDataBrowserControl(
304 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
305 &bounds
, kDataBrowserListView
, &m_controlRef
);
306 SetReferenceInNativeControl();
308 if ( gDataBrowserItemCompareUPP
== NULL
)
309 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
310 if ( gDataBrowserItemDataUPP
== NULL
)
311 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
312 if ( gDataBrowserItemNotificationUPP
== NULL
)
314 gDataBrowserItemNotificationUPP
=
315 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
318 DataBrowserCallbacks callbacks
;
319 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
321 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
322 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
323 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
324 SetCallbacks( &callbacks
);
328 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
330 DataBrowserItemState state
,
331 ItemCount
*numItems
) const
333 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
336 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
338 DataBrowserItemState state
,
341 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
344 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
346 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
349 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
350 DataBrowserTableViewColumnIndex position
)
352 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
355 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
)
357 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
360 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
362 DataBrowserTableViewColumnID id
;
363 GetColumnIDFromIndex( position
, &id
);
364 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
367 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
369 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
372 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
374 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
377 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
379 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
382 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
384 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
387 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
389 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
392 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
394 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
397 OSStatus
wxMacDataBrowserControl::UpdateItems(
398 DataBrowserItemID container
,
400 const DataBrowserItemID
*items
,
401 DataBrowserPropertyID preSortProperty
,
402 DataBrowserPropertyID propertyID
) const
404 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
407 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
409 return IsDataBrowserItemSelected( m_controlRef
, item
);
412 OSStatus
wxMacDataBrowserControl::AddItems(
413 DataBrowserItemID container
,
415 const DataBrowserItemID
*items
,
416 DataBrowserPropertyID preSortProperty
)
418 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
421 OSStatus
wxMacDataBrowserControl::RemoveItems(
422 DataBrowserItemID container
,
424 const DataBrowserItemID
*items
,
425 DataBrowserPropertyID preSortProperty
)
427 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
430 OSStatus
wxMacDataBrowserControl::RevealItem(
431 DataBrowserItemID item
,
432 DataBrowserPropertyID propertyID
,
433 DataBrowserRevealOptions options
) const
435 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
438 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
440 const DataBrowserItemID
*items
,
441 DataBrowserSetOption operation
)
443 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
446 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
448 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
451 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
453 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
456 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
458 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
461 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
463 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
466 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
468 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
471 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
473 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
476 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
478 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
481 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
483 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
486 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
488 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
491 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
493 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
496 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
498 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
501 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
503 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
506 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
507 DataBrowserTableViewColumnIndex
*position
) const
509 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
512 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
514 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
517 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
519 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
522 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
524 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
527 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
529 return GetDataBrowserSortProperty( m_controlRef
, column
);
532 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
534 return SetDataBrowserSortProperty( m_controlRef
, column
);
537 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
539 return GetDataBrowserSortOrder( m_controlRef
, order
);
542 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
544 return SetDataBrowserSortOrder( m_controlRef
, order
);
547 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
548 DataBrowserPropertyFlags
*flags
) const
550 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
553 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
554 DataBrowserPropertyFlags flags
)
556 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
559 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
560 DataBrowserListViewHeaderDesc
*desc
) const
562 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
565 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
566 DataBrowserListViewHeaderDesc
*desc
)
568 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
571 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
572 Boolean expandableRows
)
574 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
577 OSStatus
wxMacDataBrowserControl::GetItemPartBounds( DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
)
579 return GetDataBrowserItemPartBounds( m_controlRef
, item
, property
, part
, bounds
);
582 // ============================================================================
583 // Higher-level Databrowser
584 // ============================================================================
586 // basing on data item objects
589 wxMacDataItem::wxMacDataItem()
594 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
597 wxMacDataItem::~wxMacDataItem()
601 void wxMacDataItem::SetOrder( SInt32 order
)
606 SInt32
wxMacDataItem::GetOrder() const
611 void wxMacDataItem::SetData( void* data)
616 void* wxMacDataItem::GetData() const
621 short wxMacDataItem::GetColumn()
626 void wxMacDataItem::SetColumn( short col )
631 void wxMacDataItem::SetLabel( const wxString& str)
634 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
637 const wxString& wxMacDataItem::GetLabel() const
643 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
644 const wxMacDataItem
* rhs
,
645 DataBrowserPropertyID sortProperty
) const
649 if ( sortProperty
== kNumericOrderColumnId
)
650 retval
= m_order
< rhs
->m_order
;
655 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
656 DataBrowserPropertyID property
,
657 DataBrowserItemDataRef itemData
,
660 OSStatus err
= errDataBrowserPropertyNotSupported
;
663 if ( property
== kNumericOrderColumnId
)
665 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
673 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
674 DataBrowserItemNotification
WXUNUSED(message
),
675 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
679 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
681 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
682 wxMacDataBrowserControl( peer
, pos
, size
, style
)
684 m_suppressSelection
= false;
685 m_sortOrder
= SortOrder_None
;
686 m_clientDataItemsType
= wxClientData_None
;
689 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
691 m_former
= browser
->SuppressSelection(true);
695 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
697 m_browser
->SuppressSelection(m_former
);
700 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
702 bool former
= m_suppressSelection
;
703 m_suppressSelection
= suppress
;
708 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
709 DataBrowserItemID itemTwoID
,
710 DataBrowserPropertyID sortProperty
)
712 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
713 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
715 Boolean retval
= false;
716 if ( itemOne
!= NULL
)
717 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
721 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
722 DataBrowserItemID itemID
,
723 DataBrowserPropertyID property
,
724 DataBrowserItemDataRef itemData
,
725 Boolean changeValue
)
727 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
728 OSStatus err
= errDataBrowserPropertyNotSupported
;
731 case kDataBrowserContainerIsClosableProperty
:
732 case kDataBrowserContainerIsSortableProperty
:
733 case kDataBrowserContainerIsOpenableProperty
:
734 // right now default behaviour on these
739 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
747 void wxMacDataItemBrowserControl::ItemNotification(
748 DataBrowserItemID itemID
,
749 DataBrowserItemNotification message
,
750 DataBrowserItemDataRef itemData
)
752 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
754 item
->Notification( this, message
, itemData
);
757 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
758 bool recurse
, DataBrowserItemState state
) const
760 ItemCount numItems
= 0;
761 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
762 recurse
, state
, &numItems
) );
766 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
769 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
773 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
774 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
776 Handle handle
= NewHandle(0);
777 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
778 recurse
, state
, handle
) );
780 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
782 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
783 for ( int i
= 0; i
< itemCount
; ++i
)
785 items
.Add(itemsArray
[i
]);
788 DisposeHandle( handle
);
791 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
793 DataBrowserTableViewRowIndex row
;
794 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
795 wxCHECK( err
== noErr
, (unsigned)-1 );
799 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
801 DataBrowserItemID id
;
802 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
803 wxCHECK( err
== noErr
, NULL
);
804 return (wxMacDataItem
*) id
;
807 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
808 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
810 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
811 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
814 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
815 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
817 unsigned int noItems
= itemArray
.GetCount();
818 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
819 for ( unsigned int i
= 0; i
< noItems
; ++i
)
820 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
822 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
823 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
827 static int column_id_counter
= 0;
829 void wxMacDataItemBrowserControl::InsertColumn(int col
, DataBrowserPropertyType colType
,
830 const wxString
& title
, SInt16 just
, int defaultWidth
)
832 DataBrowserListViewColumnDesc columnDesc
;
833 columnDesc
.headerBtnDesc
.titleOffset
= 0;
834 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
836 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
837 kControlUseFontMask
| kControlUseJustMask
;
839 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
840 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
841 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
842 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
844 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
845 // defined for other modes?
848 enc
= m_font
.GetEncoding();
850 enc
= wxLocale::GetSystemEncoding();
851 wxCFStringRef
cfTitle( title
, enc
);
852 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
854 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
855 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
857 DataBrowserPropertyID id
= kMinColumnId
+ column_id_counter
;
860 columnDesc
.propertyDesc
.propertyID
= id
;
861 columnDesc
.propertyDesc
.propertyType
= colType
;
862 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
863 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
864 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
866 verify_noerr( AddColumn( &columnDesc
, col
) );
868 if (defaultWidth
> 0){
869 SetColumnWidth(col
, defaultWidth
);
873 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
875 DataBrowserPropertyID id
;
876 GetColumnIDFromIndex(colId
, &id
);
877 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
880 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
882 DataBrowserPropertyID id
;
883 GetColumnIDFromIndex(colId
, &id
);
885 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
889 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
891 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
892 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
895 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
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::AddItems( (DataBrowserItemID
)container
, noItems
,
903 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
907 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
909 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
910 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
914 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
916 unsigned int noItems
= itemArray
.GetCount();
917 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
918 for ( unsigned int i
= 0; i
< noItems
; ++i
)
919 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
921 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
922 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
927 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
929 SetScrollPosition(0, 0);
930 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
934 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
936 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
939 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
941 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
944 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
946 unsigned int noItems
= itemArray
.GetCount();
947 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
948 for ( unsigned int i
= 0; i
< noItems
; ++i
)
949 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
951 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
955 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
957 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
960 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
962 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
965 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
967 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
970 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
972 return m_clientDataItemsType
;
974 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
976 m_clientDataItemsType
= clientDataItemsType
;
979 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
981 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
982 RemoveItem( wxMacDataBrowserRootContainer
, item
);
985 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
987 if ( m_sortOrder
== SortOrder_None
)
990 // increase the order of the lines to be shifted
991 unsigned int lines
= MacGetCount();
992 for ( unsigned int i
= n
; i
< lines
; ++i
)
994 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
995 iter
->SetOrder( iter
->GetOrder() + 1 );
999 // I don't understand what this code is supposed to do, RR.
1000 SInt32 frontLineOrder
= 0;
1003 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1004 frontLineOrder
= iter
->GetOrder()+1;
1007 item
->SetOrder( n
);
1011 AddItem( wxMacDataBrowserRootContainer
, item
);
1014 void wxMacDataItemBrowserControl::MacClear()
1016 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1017 RemoveAllItems(wxMacDataBrowserRootContainer
);
1020 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1022 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);