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
;
200 // ----------------------------------------------------------------------------
201 // Native Struct Conversions
202 // ----------------------------------------------------------------------------
204 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
208 n
->right
= wx
->x
+ wx
->width
;
209 n
->bottom
= wx
->y
+ wx
->height
;
212 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
216 wx
->width
= n
->right
- n
->left
;
217 wx
->height
= n
->bottom
- n
->top
;
220 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
226 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
232 // ----------------------------------------------------------------------------
233 // Carbon Event Support
234 // ----------------------------------------------------------------------------
236 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
238 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
241 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
243 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
246 // ----------------------------------------------------------------------------
247 // Control Access Support
248 // ----------------------------------------------------------------------------
251 // ============================================================================
252 // DataBrowser Wrapper
253 // ============================================================================
255 // basing on DataBrowserItemIDs
258 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
260 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
262 DataBrowserItemID itemID
,
263 DataBrowserItemNotification message
,
264 DataBrowserItemDataRef itemData
)
266 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
269 ctl
->ItemNotification(itemID
, message
, itemData
);
273 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
275 DataBrowserItemID itemID
,
276 DataBrowserPropertyID property
,
277 DataBrowserItemDataRef itemData
,
278 Boolean changeValue
)
280 OSStatus err
= errDataBrowserPropertyNotSupported
;
281 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
284 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
289 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
291 DataBrowserItemID itemOneID
,
292 DataBrowserItemID itemTwoID
,
293 DataBrowserPropertyID sortProperty
)
295 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
298 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
303 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
304 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
305 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
307 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
310 long WXUNUSED(style
))
311 : wxMacControl( peer
)
313 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
314 OSStatus err
= ::CreateDataBrowserControl(
315 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
316 &bounds
, kDataBrowserListView
, &m_controlRef
);
317 SetReferenceInNativeControl();
319 if ( gDataBrowserItemCompareUPP
== NULL
)
320 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
321 if ( gDataBrowserItemDataUPP
== NULL
)
322 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
323 if ( gDataBrowserItemNotificationUPP
== NULL
)
325 gDataBrowserItemNotificationUPP
=
326 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
329 DataBrowserCallbacks callbacks
;
330 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
332 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
333 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
334 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
335 SetCallbacks( &callbacks
);
339 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
341 DataBrowserItemState state
,
342 ItemCount
*numItems
) const
344 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
347 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
349 DataBrowserItemState state
,
352 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
355 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
357 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
360 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
361 DataBrowserTableViewColumnIndex position
)
363 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
366 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
)
368 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
371 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
373 DataBrowserTableViewColumnID id
;
374 GetColumnIDFromIndex( position
, &id
);
375 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
378 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
380 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
383 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
385 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
388 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
390 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
393 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
395 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
398 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
400 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
403 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
405 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
408 OSStatus
wxMacDataBrowserControl::UpdateItems(
409 DataBrowserItemID container
,
411 const DataBrowserItemID
*items
,
412 DataBrowserPropertyID preSortProperty
,
413 DataBrowserPropertyID propertyID
) const
415 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
418 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
420 return IsDataBrowserItemSelected( m_controlRef
, item
);
423 OSStatus
wxMacDataBrowserControl::AddItems(
424 DataBrowserItemID container
,
426 const DataBrowserItemID
*items
,
427 DataBrowserPropertyID preSortProperty
)
429 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
432 OSStatus
wxMacDataBrowserControl::RemoveItems(
433 DataBrowserItemID container
,
435 const DataBrowserItemID
*items
,
436 DataBrowserPropertyID preSortProperty
)
438 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
441 OSStatus
wxMacDataBrowserControl::RevealItem(
442 DataBrowserItemID item
,
443 DataBrowserPropertyID propertyID
,
444 DataBrowserRevealOptions options
) const
446 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
449 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
451 const DataBrowserItemID
*items
,
452 DataBrowserSetOption operation
)
454 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
457 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
459 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
462 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
464 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
467 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
469 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
472 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
474 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
477 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
479 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
482 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
484 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
487 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
489 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
492 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
494 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
497 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
499 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
502 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
504 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
507 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
509 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
512 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
514 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
517 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
518 DataBrowserTableViewColumnIndex
*position
) const
520 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
523 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
525 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
528 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
530 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
533 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
535 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
538 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
540 return GetDataBrowserSortProperty( m_controlRef
, column
);
543 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
545 return SetDataBrowserSortProperty( m_controlRef
, column
);
548 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
550 return GetDataBrowserSortOrder( m_controlRef
, order
);
553 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
555 return SetDataBrowserSortOrder( m_controlRef
, order
);
558 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
559 DataBrowserPropertyFlags
*flags
) const
561 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
564 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
565 DataBrowserPropertyFlags flags
)
567 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
570 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
571 DataBrowserListViewHeaderDesc
*desc
) const
573 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
576 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
577 DataBrowserListViewHeaderDesc
*desc
)
579 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
582 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
583 Boolean expandableRows
)
585 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
588 OSStatus
wxMacDataBrowserControl::GetItemPartBounds( DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
)
590 return GetDataBrowserItemPartBounds( m_controlRef
, item
, property
, part
, bounds
);
593 // ============================================================================
594 // Higher-level Databrowser
595 // ============================================================================
597 // basing on data item objects
600 wxMacDataItem::wxMacDataItem()
605 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
608 wxMacDataItem::~wxMacDataItem()
612 void wxMacDataItem::SetOrder( SInt32 order
)
617 SInt32
wxMacDataItem::GetOrder() const
622 void wxMacDataItem::SetData( void* data)
627 void* wxMacDataItem::GetData() const
632 short wxMacDataItem::GetColumn()
637 void wxMacDataItem::SetColumn( short col )
642 void wxMacDataItem::SetLabel( const wxString& str)
645 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
648 const wxString& wxMacDataItem::GetLabel() const
654 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
655 const wxMacDataItem
* rhs
,
656 DataBrowserPropertyID sortProperty
) const
660 if ( sortProperty
== kNumericOrderColumnId
)
661 retval
= m_order
< rhs
->m_order
;
666 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
667 DataBrowserPropertyID property
,
668 DataBrowserItemDataRef itemData
,
671 OSStatus err
= errDataBrowserPropertyNotSupported
;
674 if ( property
== kNumericOrderColumnId
)
676 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
684 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
685 DataBrowserItemNotification
WXUNUSED(message
),
686 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
690 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
692 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
693 wxMacDataBrowserControl( peer
, pos
, size
, style
)
695 m_suppressSelection
= false;
696 m_sortOrder
= SortOrder_None
;
697 m_clientDataItemsType
= wxClientData_None
;
700 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
702 m_former
= browser
->SuppressSelection(true);
706 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
708 m_browser
->SuppressSelection(m_former
);
711 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
713 bool former
= m_suppressSelection
;
714 m_suppressSelection
= suppress
;
719 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
720 DataBrowserItemID itemTwoID
,
721 DataBrowserPropertyID sortProperty
)
723 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
724 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
726 Boolean retval
= false;
727 if ( itemOne
!= NULL
)
728 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
732 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
733 DataBrowserItemID itemID
,
734 DataBrowserPropertyID property
,
735 DataBrowserItemDataRef itemData
,
736 Boolean changeValue
)
738 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
739 OSStatus err
= errDataBrowserPropertyNotSupported
;
742 case kDataBrowserContainerIsClosableProperty
:
743 case kDataBrowserContainerIsSortableProperty
:
744 case kDataBrowserContainerIsOpenableProperty
:
745 // right now default behaviour on these
750 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
758 void wxMacDataItemBrowserControl::ItemNotification(
759 DataBrowserItemID itemID
,
760 DataBrowserItemNotification message
,
761 DataBrowserItemDataRef itemData
)
763 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
765 item
->Notification( this, message
, itemData
);
768 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
769 bool recurse
, DataBrowserItemState state
) const
771 ItemCount numItems
= 0;
772 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
773 recurse
, state
, &numItems
) );
777 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
780 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
784 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
785 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
787 Handle handle
= NewHandle(0);
788 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
789 recurse
, state
, handle
) );
791 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
793 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
794 for ( int i
= 0; i
< itemCount
; ++i
)
796 items
.Add(itemsArray
[i
]);
799 DisposeHandle( handle
);
802 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
804 DataBrowserTableViewRowIndex row
;
805 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
806 wxCHECK( err
== noErr
, (unsigned)-1 );
810 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
812 DataBrowserItemID id
;
813 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
814 wxCHECK( err
== noErr
, NULL
);
815 return (wxMacDataItem
*) id
;
818 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
819 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
821 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
822 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
825 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
826 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
828 unsigned int noItems
= itemArray
.GetCount();
829 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
830 for ( unsigned int i
= 0; i
< noItems
; ++i
)
831 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
833 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
834 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
838 static int column_id_counter
= 0;
840 void wxMacDataItemBrowserControl::InsertColumn(int col
, DataBrowserPropertyType colType
,
841 const wxString
& title
, SInt16 just
, int defaultWidth
)
843 DataBrowserListViewColumnDesc columnDesc
;
844 columnDesc
.headerBtnDesc
.titleOffset
= 0;
845 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
847 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
848 kControlUseFontMask
| kControlUseJustMask
;
850 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
851 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
852 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
853 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
855 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
856 // defined for other modes?
859 enc
= m_font
.GetEncoding();
861 enc
= wxLocale::GetSystemEncoding();
862 wxCFStringRef
cfTitle( title
, enc
);
863 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
865 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
866 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
868 DataBrowserPropertyID id
= kMinColumnId
+ column_id_counter
;
871 columnDesc
.propertyDesc
.propertyID
= id
;
872 columnDesc
.propertyDesc
.propertyType
= colType
;
873 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
874 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
875 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
877 verify_noerr( AddColumn( &columnDesc
, col
) );
879 if (defaultWidth
> 0){
880 SetColumnWidth(col
, defaultWidth
);
884 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
886 DataBrowserPropertyID id
;
887 GetColumnIDFromIndex(colId
, &id
);
888 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
891 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
893 DataBrowserPropertyID id
;
894 GetColumnIDFromIndex(colId
, &id
);
896 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
900 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
902 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
903 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
906 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
908 unsigned int noItems
= itemArray
.GetCount();
909 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
910 for ( unsigned int i
= 0; i
< noItems
; ++i
)
911 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
913 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
914 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
918 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
920 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
921 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
925 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
927 unsigned int noItems
= itemArray
.GetCount();
928 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
929 for ( unsigned int i
= 0; i
< noItems
; ++i
)
930 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
932 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
933 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
938 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
940 SetScrollPosition(0, 0);
941 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
945 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
947 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
950 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
952 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
955 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
957 unsigned int noItems
= itemArray
.GetCount();
958 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
959 for ( unsigned int i
= 0; i
< noItems
; ++i
)
960 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
962 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
966 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
968 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
971 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
973 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
976 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
978 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
981 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
983 return m_clientDataItemsType
;
985 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
987 m_clientDataItemsType
= clientDataItemsType
;
990 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
992 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
993 RemoveItem( wxMacDataBrowserRootContainer
, item
);
996 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
998 if ( m_sortOrder
== SortOrder_None
)
1001 // increase the order of the lines to be shifted
1002 unsigned int lines
= MacGetCount();
1003 for ( unsigned int i
= n
; i
< lines
; ++i
)
1005 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1006 iter
->SetOrder( iter
->GetOrder() + 1 );
1010 // I don't understand what this code is supposed to do, RR.
1011 SInt32 frontLineOrder
= 0;
1014 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1015 frontLineOrder
= iter
->GetOrder()+1;
1018 item
->SetOrder( n
);
1022 AddItem( wxMacDataBrowserRootContainer
, item
);
1025 void wxMacDataItemBrowserControl::MacClear()
1027 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1028 RemoveAllItems(wxMacDataBrowserRootContainer
);
1031 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1033 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);