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"
53 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
54 if ( AudioServicesPlayAlertSound
!= NULL
)
55 AudioServicesPlayAlertSound(kUserPreferredAlert
);
58 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
70 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
72 return new wxOSXTimerImpl(timer
);
75 int gs_wxBusyCursorCount
= 0;
76 extern wxCursor gMacCurrentCursor
;
77 wxCursor gMacStoredActiveCursor
;
79 // Set the cursor to the busy cursor for all windows
80 void wxBeginBusyCursor(const wxCursor
*cursor
)
82 if (gs_wxBusyCursorCount
++ == 0)
84 gMacStoredActiveCursor
= gMacCurrentCursor
;
89 //else: nothing to do, already set
92 // Restore cursor to normal
93 void wxEndBusyCursor()
95 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
96 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
98 if (--gs_wxBusyCursorCount
== 0)
100 gMacStoredActiveCursor
.MacInstall();
101 gMacStoredActiveCursor
= wxNullCursor
;
103 wxSetCursor(wxNullCursor
);
107 // true if we're between the above two calls
110 return (gs_wxBusyCursorCount
> 0);
117 wxString
wxMacFindFolderNoSeparator( short vol
,
119 Boolean createFolder
)
124 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
126 strDir
= wxMacFSRefToPath( &fsRef
);
132 wxString
wxMacFindFolder( short vol
,
134 Boolean createFolder
)
136 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
142 // ============================================================================
143 // GUI-only functions from now on
144 // ============================================================================
148 // ----------------------------------------------------------------------------
149 // Miscellaneous functions
150 // ----------------------------------------------------------------------------
152 void wxGetMousePosition( int* x
, int* y
)
162 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
164 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
166 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
169 *x
= bounds
.origin
.x
;
171 *y
= bounds
.origin
.y
;
173 *width
= bounds
.size
.width
;
175 *height
= bounds
.size
.height
;
178 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
184 *width
= r
.right
- r
.left
;
186 *height
= r
.bottom
- r
.top
;
194 // ----------------------------------------------------------------------------
195 // Native Struct Conversions
196 // ----------------------------------------------------------------------------
198 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
202 n
->right
= wx
->x
+ wx
->width
;
203 n
->bottom
= wx
->y
+ wx
->height
;
206 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
210 wx
->width
= n
->right
- n
->left
;
211 wx
->height
= n
->bottom
- n
->top
;
214 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
220 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
226 // ----------------------------------------------------------------------------
227 // Carbon Event Support
228 // ----------------------------------------------------------------------------
230 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
232 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
235 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
237 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
240 // ----------------------------------------------------------------------------
241 // Control Access Support
242 // ----------------------------------------------------------------------------
245 // ============================================================================
246 // DataBrowser Wrapper
247 // ============================================================================
249 // basing on DataBrowserItemIDs
252 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
254 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
256 DataBrowserItemID itemID
,
257 DataBrowserItemNotification message
,
258 DataBrowserItemDataRef itemData
)
260 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
263 ctl
->ItemNotification(itemID
, message
, itemData
);
267 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
269 DataBrowserItemID itemID
,
270 DataBrowserPropertyID property
,
271 DataBrowserItemDataRef itemData
,
272 Boolean changeValue
)
274 OSStatus err
= errDataBrowserPropertyNotSupported
;
275 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
278 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
283 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
285 DataBrowserItemID itemOneID
,
286 DataBrowserItemID itemTwoID
,
287 DataBrowserPropertyID sortProperty
)
289 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
292 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
297 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
298 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
299 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
301 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
304 long WXUNUSED(style
))
305 : wxMacControl( peer
)
307 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
308 OSStatus err
= ::CreateDataBrowserControl(
309 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
310 &bounds
, kDataBrowserListView
, &m_controlRef
);
311 SetReferenceInNativeControl();
313 if ( gDataBrowserItemCompareUPP
== NULL
)
314 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
315 if ( gDataBrowserItemDataUPP
== NULL
)
316 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
317 if ( gDataBrowserItemNotificationUPP
== NULL
)
319 gDataBrowserItemNotificationUPP
=
320 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
323 DataBrowserCallbacks callbacks
;
324 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
326 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
327 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
328 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
329 SetCallbacks( &callbacks
);
333 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
335 DataBrowserItemState state
,
336 ItemCount
*numItems
) const
338 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
341 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
343 DataBrowserItemState state
,
346 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
349 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
351 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
354 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
355 DataBrowserTableViewColumnIndex position
)
357 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
360 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
)
362 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
365 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
367 DataBrowserTableViewColumnID id
;
368 GetColumnIDFromIndex( position
, &id
);
369 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
372 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
374 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
377 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
379 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
382 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
384 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
387 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
389 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
392 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
394 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
397 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
399 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
402 OSStatus
wxMacDataBrowserControl::UpdateItems(
403 DataBrowserItemID container
,
405 const DataBrowserItemID
*items
,
406 DataBrowserPropertyID preSortProperty
,
407 DataBrowserPropertyID propertyID
) const
409 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
412 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
414 return IsDataBrowserItemSelected( m_controlRef
, item
);
417 OSStatus
wxMacDataBrowserControl::AddItems(
418 DataBrowserItemID container
,
420 const DataBrowserItemID
*items
,
421 DataBrowserPropertyID preSortProperty
)
423 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
426 OSStatus
wxMacDataBrowserControl::RemoveItems(
427 DataBrowserItemID container
,
429 const DataBrowserItemID
*items
,
430 DataBrowserPropertyID preSortProperty
)
432 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
435 OSStatus
wxMacDataBrowserControl::RevealItem(
436 DataBrowserItemID item
,
437 DataBrowserPropertyID propertyID
,
438 DataBrowserRevealOptions options
) const
440 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
443 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
445 const DataBrowserItemID
*items
,
446 DataBrowserSetOption operation
)
448 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
451 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
453 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
456 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
458 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
461 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
463 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
466 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
468 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
471 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
473 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
476 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
478 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
481 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
483 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
486 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
488 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
491 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
493 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
496 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
498 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
501 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
503 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
506 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
508 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
511 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
512 DataBrowserTableViewColumnIndex
*position
) const
514 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
517 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
519 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
522 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
524 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
527 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
529 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
532 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
534 return GetDataBrowserSortProperty( m_controlRef
, column
);
537 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
539 return SetDataBrowserSortProperty( m_controlRef
, column
);
542 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
544 return GetDataBrowserSortOrder( m_controlRef
, order
);
547 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
549 return SetDataBrowserSortOrder( m_controlRef
, order
);
552 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
553 DataBrowserPropertyFlags
*flags
) const
555 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
558 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
559 DataBrowserPropertyFlags flags
)
561 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
564 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
565 DataBrowserListViewHeaderDesc
*desc
) const
567 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
570 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
571 DataBrowserListViewHeaderDesc
*desc
)
573 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
576 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
577 Boolean expandableRows
)
579 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
582 OSStatus
wxMacDataBrowserControl::GetItemPartBounds( DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
)
584 return GetDataBrowserItemPartBounds( m_controlRef
, item
, property
, part
, bounds
);
587 // ============================================================================
588 // Higher-level Databrowser
589 // ============================================================================
591 // basing on data item objects
594 wxMacDataItem::wxMacDataItem()
599 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
602 wxMacDataItem::~wxMacDataItem()
606 void wxMacDataItem::SetOrder( SInt32 order
)
611 SInt32
wxMacDataItem::GetOrder() const
616 void wxMacDataItem::SetData( void* data)
621 void* wxMacDataItem::GetData() const
626 short wxMacDataItem::GetColumn()
631 void wxMacDataItem::SetColumn( short col )
636 void wxMacDataItem::SetLabel( const wxString& str)
639 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
642 const wxString& wxMacDataItem::GetLabel() const
648 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
649 const wxMacDataItem
* rhs
,
650 DataBrowserPropertyID sortProperty
) const
654 if ( sortProperty
== kNumericOrderColumnId
)
655 retval
= m_order
< rhs
->m_order
;
660 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
661 DataBrowserPropertyID property
,
662 DataBrowserItemDataRef itemData
,
665 OSStatus err
= errDataBrowserPropertyNotSupported
;
668 if ( property
== kNumericOrderColumnId
)
670 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
678 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
679 DataBrowserItemNotification
WXUNUSED(message
),
680 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
684 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
686 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
687 wxMacDataBrowserControl( peer
, pos
, size
, style
)
689 m_suppressSelection
= false;
690 m_sortOrder
= SortOrder_None
;
691 m_clientDataItemsType
= wxClientData_None
;
694 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
696 m_former
= browser
->SuppressSelection(true);
700 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
702 m_browser
->SuppressSelection(m_former
);
705 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
707 bool former
= m_suppressSelection
;
708 m_suppressSelection
= suppress
;
713 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
714 DataBrowserItemID itemTwoID
,
715 DataBrowserPropertyID sortProperty
)
717 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
718 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
720 Boolean retval
= false;
721 if ( itemOne
!= NULL
)
722 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
726 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
727 DataBrowserItemID itemID
,
728 DataBrowserPropertyID property
,
729 DataBrowserItemDataRef itemData
,
730 Boolean changeValue
)
732 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
733 OSStatus err
= errDataBrowserPropertyNotSupported
;
736 case kDataBrowserContainerIsClosableProperty
:
737 case kDataBrowserContainerIsSortableProperty
:
738 case kDataBrowserContainerIsOpenableProperty
:
739 // right now default behaviour on these
744 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
752 void wxMacDataItemBrowserControl::ItemNotification(
753 DataBrowserItemID itemID
,
754 DataBrowserItemNotification message
,
755 DataBrowserItemDataRef itemData
)
757 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
759 item
->Notification( this, message
, itemData
);
762 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
763 bool recurse
, DataBrowserItemState state
) const
765 ItemCount numItems
= 0;
766 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
767 recurse
, state
, &numItems
) );
771 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
774 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
778 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
779 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
781 Handle handle
= NewHandle(0);
782 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
783 recurse
, state
, handle
) );
785 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
787 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
788 for ( int i
= 0; i
< itemCount
; ++i
)
790 items
.Add(itemsArray
[i
]);
793 DisposeHandle( handle
);
796 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
798 DataBrowserTableViewRowIndex row
;
799 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
800 wxCHECK( err
== noErr
, (unsigned)-1 );
804 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
806 DataBrowserItemID id
;
807 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
808 wxCHECK( err
== noErr
, NULL
);
809 return (wxMacDataItem
*) id
;
812 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
813 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
815 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
816 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
819 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
820 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
822 unsigned int noItems
= itemArray
.GetCount();
823 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
824 for ( unsigned int i
= 0; i
< noItems
; ++i
)
825 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
827 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
828 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
832 static int column_id_counter
= 0;
834 void wxMacDataItemBrowserControl::InsertColumn(int col
, DataBrowserPropertyType colType
,
835 const wxString
& title
, SInt16 just
, int defaultWidth
)
837 DataBrowserListViewColumnDesc columnDesc
;
838 columnDesc
.headerBtnDesc
.titleOffset
= 0;
839 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
841 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
842 kControlUseFontMask
| kControlUseJustMask
;
844 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
845 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
846 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
847 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
849 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
850 // defined for other modes?
853 enc
= m_font
.GetEncoding();
855 enc
= wxLocale::GetSystemEncoding();
856 wxCFStringRef
cfTitle( title
, enc
);
857 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
859 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
860 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
862 DataBrowserPropertyID id
= kMinColumnId
+ column_id_counter
;
865 columnDesc
.propertyDesc
.propertyID
= id
;
866 columnDesc
.propertyDesc
.propertyType
= colType
;
867 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
868 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
869 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
871 verify_noerr( AddColumn( &columnDesc
, col
) );
873 if (defaultWidth
> 0){
874 SetColumnWidth(col
, defaultWidth
);
878 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
880 DataBrowserPropertyID id
;
881 GetColumnIDFromIndex(colId
, &id
);
882 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
885 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
887 DataBrowserPropertyID id
;
888 GetColumnIDFromIndex(colId
, &id
);
890 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
894 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
896 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
897 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
900 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
902 unsigned int noItems
= itemArray
.GetCount();
903 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
904 for ( unsigned int i
= 0; i
< noItems
; ++i
)
905 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
907 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
908 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
912 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
914 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
915 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
919 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
921 unsigned int noItems
= itemArray
.GetCount();
922 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
923 for ( unsigned int i
= 0; i
< noItems
; ++i
)
924 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
926 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
927 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
932 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
934 SetScrollPosition(0, 0);
935 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
939 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
941 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
944 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
946 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
949 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
951 unsigned int noItems
= itemArray
.GetCount();
952 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
953 for ( unsigned int i
= 0; i
< noItems
; ++i
)
954 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
956 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
960 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
962 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
965 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
967 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
970 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
972 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
975 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
977 return m_clientDataItemsType
;
979 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
981 m_clientDataItemsType
= clientDataItemsType
;
984 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
986 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
987 RemoveItem( wxMacDataBrowserRootContainer
, item
);
990 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
992 if ( m_sortOrder
== SortOrder_None
)
995 // increase the order of the lines to be shifted
996 unsigned int lines
= MacGetCount();
997 for ( unsigned int i
= n
; i
< lines
; ++i
)
999 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
1000 iter
->SetOrder( iter
->GetOrder() + 1 );
1004 // I don't understand what this code is supposed to do, RR.
1005 SInt32 frontLineOrder
= 0;
1008 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1009 frontLineOrder
= iter
->GetOrder()+1;
1012 item
->SetOrder( n
);
1016 AddItem( wxMacDataBrowserRootContainer
, item
);
1019 void wxMacDataItemBrowserControl::MacClear()
1021 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1022 RemoveAllItems(wxMacDataBrowserRootContainer
);
1025 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1027 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);