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
66 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
68 return new wxOSXTimerImpl(timer
);
71 int gs_wxBusyCursorCount
= 0;
72 extern wxCursor gMacCurrentCursor
;
73 wxCursor gMacStoredActiveCursor
;
75 // Set the cursor to the busy cursor for all windows
76 void wxBeginBusyCursor(const wxCursor
*cursor
)
78 if (gs_wxBusyCursorCount
++ == 0)
80 gMacStoredActiveCursor
= gMacCurrentCursor
;
85 //else: nothing to do, already set
88 // Restore cursor to normal
89 void wxEndBusyCursor()
91 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
92 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
94 if (--gs_wxBusyCursorCount
== 0)
96 gMacStoredActiveCursor
.MacInstall();
97 gMacStoredActiveCursor
= wxNullCursor
;
99 wxSetCursor(wxNullCursor
);
103 // true if we're between the above two calls
106 return (gs_wxBusyCursorCount
> 0);
113 wxString
wxMacFindFolderNoSeparator( short vol
,
115 Boolean createFolder
)
120 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
122 strDir
= wxMacFSRefToPath( &fsRef
);
128 wxString
wxMacFindFolder( short vol
,
130 Boolean createFolder
)
132 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
138 // ============================================================================
139 // GUI-only functions from now on
140 // ============================================================================
144 // ----------------------------------------------------------------------------
145 // Miscellaneous functions
146 // ----------------------------------------------------------------------------
148 void wxGetMousePosition( int* x
, int* y
)
158 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
160 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
162 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
165 *x
= bounds
.origin
.x
;
167 *y
= bounds
.origin
.y
;
169 *width
= bounds
.size
.width
;
171 *height
= bounds
.size
.height
;
174 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
180 *width
= r
.right
- r
.left
;
182 *height
= r
.bottom
- r
.top
;
190 // ----------------------------------------------------------------------------
191 // Native Struct Conversions
192 // ----------------------------------------------------------------------------
194 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
198 n
->right
= wx
->x
+ wx
->width
;
199 n
->bottom
= wx
->y
+ wx
->height
;
202 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
206 wx
->width
= n
->right
- n
->left
;
207 wx
->height
= n
->bottom
- n
->top
;
210 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
216 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
222 // ----------------------------------------------------------------------------
223 // Carbon Event Support
224 // ----------------------------------------------------------------------------
226 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
228 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
231 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
233 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
236 // ----------------------------------------------------------------------------
237 // Control Access Support
238 // ----------------------------------------------------------------------------
241 // ============================================================================
242 // DataBrowser Wrapper
243 // ============================================================================
245 // basing on DataBrowserItemIDs
248 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
250 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
252 DataBrowserItemID itemID
,
253 DataBrowserItemNotification message
,
254 DataBrowserItemDataRef itemData
)
256 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
259 ctl
->ItemNotification(itemID
, message
, itemData
);
263 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
265 DataBrowserItemID itemID
,
266 DataBrowserPropertyID property
,
267 DataBrowserItemDataRef itemData
,
268 Boolean changeValue
)
270 OSStatus err
= errDataBrowserPropertyNotSupported
;
271 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
274 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
279 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
281 DataBrowserItemID itemOneID
,
282 DataBrowserItemID itemTwoID
,
283 DataBrowserPropertyID sortProperty
)
285 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
288 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
293 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
294 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
295 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
297 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
,
300 long WXUNUSED(style
))
301 : wxMacControl( peer
)
303 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
304 OSStatus err
= ::CreateDataBrowserControl(
305 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
306 &bounds
, kDataBrowserListView
, &m_controlRef
);
307 SetReferenceInNativeControl();
309 if ( gDataBrowserItemCompareUPP
== NULL
)
310 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
311 if ( gDataBrowserItemDataUPP
== NULL
)
312 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
313 if ( gDataBrowserItemNotificationUPP
== NULL
)
315 gDataBrowserItemNotificationUPP
=
316 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
319 DataBrowserCallbacks callbacks
;
320 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
322 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
323 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
324 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
325 SetCallbacks( &callbacks
);
329 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
331 DataBrowserItemState state
,
332 ItemCount
*numItems
) const
334 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
337 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
339 DataBrowserItemState state
,
342 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
345 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
347 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
350 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
351 DataBrowserTableViewColumnIndex position
)
353 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
356 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
)
358 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
361 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
363 DataBrowserTableViewColumnID id
;
364 GetColumnIDFromIndex( position
, &id
);
365 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
368 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
370 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
373 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
375 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
378 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
380 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
383 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
385 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
388 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
390 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
393 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
395 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
398 OSStatus
wxMacDataBrowserControl::UpdateItems(
399 DataBrowserItemID container
,
401 const DataBrowserItemID
*items
,
402 DataBrowserPropertyID preSortProperty
,
403 DataBrowserPropertyID propertyID
) const
405 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
408 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
410 return IsDataBrowserItemSelected( m_controlRef
, item
);
413 OSStatus
wxMacDataBrowserControl::AddItems(
414 DataBrowserItemID container
,
416 const DataBrowserItemID
*items
,
417 DataBrowserPropertyID preSortProperty
)
419 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
422 OSStatus
wxMacDataBrowserControl::RemoveItems(
423 DataBrowserItemID container
,
425 const DataBrowserItemID
*items
,
426 DataBrowserPropertyID preSortProperty
)
428 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
431 OSStatus
wxMacDataBrowserControl::RevealItem(
432 DataBrowserItemID item
,
433 DataBrowserPropertyID propertyID
,
434 DataBrowserRevealOptions options
) const
436 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
439 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
441 const DataBrowserItemID
*items
,
442 DataBrowserSetOption operation
)
444 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
447 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
449 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
452 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
454 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
457 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
459 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
462 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
464 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
467 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
469 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
472 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
474 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
477 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
479 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
482 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
484 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
487 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
489 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
492 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
494 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
497 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
499 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
502 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
504 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
507 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
508 DataBrowserTableViewColumnIndex
*position
) const
510 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
513 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
515 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
518 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
520 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
523 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
525 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
528 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
530 return GetDataBrowserSortProperty( m_controlRef
, column
);
533 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
535 return SetDataBrowserSortProperty( m_controlRef
, column
);
538 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
540 return GetDataBrowserSortOrder( m_controlRef
, order
);
543 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
545 return SetDataBrowserSortOrder( m_controlRef
, order
);
548 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
549 DataBrowserPropertyFlags
*flags
) const
551 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
554 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
555 DataBrowserPropertyFlags flags
)
557 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
560 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
561 DataBrowserListViewHeaderDesc
*desc
) const
563 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
566 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
567 DataBrowserListViewHeaderDesc
*desc
)
569 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
572 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
573 Boolean expandableRows
)
575 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
578 OSStatus
wxMacDataBrowserControl::GetItemPartBounds( DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
)
580 return GetDataBrowserItemPartBounds( m_controlRef
, item
, property
, part
, bounds
);
583 // ============================================================================
584 // Higher-level Databrowser
585 // ============================================================================
587 // basing on data item objects
590 wxMacDataItem::wxMacDataItem()
595 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
598 wxMacDataItem::~wxMacDataItem()
602 void wxMacDataItem::SetOrder( SInt32 order
)
607 SInt32
wxMacDataItem::GetOrder() const
612 void wxMacDataItem::SetData( void* data)
617 void* wxMacDataItem::GetData() const
622 short wxMacDataItem::GetColumn()
627 void wxMacDataItem::SetColumn( short col )
632 void wxMacDataItem::SetLabel( const wxString& str)
635 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
638 const wxString& wxMacDataItem::GetLabel() const
644 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
645 const wxMacDataItem
* rhs
,
646 DataBrowserPropertyID sortProperty
) const
650 if ( sortProperty
== kNumericOrderColumnId
)
651 retval
= m_order
< rhs
->m_order
;
656 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
657 DataBrowserPropertyID property
,
658 DataBrowserItemDataRef itemData
,
661 OSStatus err
= errDataBrowserPropertyNotSupported
;
664 if ( property
== kNumericOrderColumnId
)
666 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
674 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*WXUNUSED(owner
) ,
675 DataBrowserItemNotification
WXUNUSED(message
),
676 DataBrowserItemDataRef
WXUNUSED(itemData
) ) const
680 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
682 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
683 wxMacDataBrowserControl( peer
, pos
, size
, style
)
685 m_suppressSelection
= false;
686 m_sortOrder
= SortOrder_None
;
687 m_clientDataItemsType
= wxClientData_None
;
690 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
692 m_former
= browser
->SuppressSelection(true);
696 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
698 m_browser
->SuppressSelection(m_former
);
701 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
703 bool former
= m_suppressSelection
;
704 m_suppressSelection
= suppress
;
709 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
710 DataBrowserItemID itemTwoID
,
711 DataBrowserPropertyID sortProperty
)
713 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
714 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
716 Boolean retval
= false;
717 if ( itemOne
!= NULL
)
718 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
722 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
723 DataBrowserItemID itemID
,
724 DataBrowserPropertyID property
,
725 DataBrowserItemDataRef itemData
,
726 Boolean changeValue
)
728 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
729 OSStatus err
= errDataBrowserPropertyNotSupported
;
732 case kDataBrowserContainerIsClosableProperty
:
733 case kDataBrowserContainerIsSortableProperty
:
734 case kDataBrowserContainerIsOpenableProperty
:
735 // right now default behaviour on these
740 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
748 void wxMacDataItemBrowserControl::ItemNotification(
749 DataBrowserItemID itemID
,
750 DataBrowserItemNotification message
,
751 DataBrowserItemDataRef itemData
)
753 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
755 item
->Notification( this, message
, itemData
);
758 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
759 bool recurse
, DataBrowserItemState state
) const
761 ItemCount numItems
= 0;
762 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
763 recurse
, state
, &numItems
) );
767 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
770 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
774 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
775 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
777 Handle handle
= NewHandle(0);
778 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
779 recurse
, state
, handle
) );
781 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
783 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
784 for ( int i
= 0; i
< itemCount
; ++i
)
786 items
.Add(itemsArray
[i
]);
789 DisposeHandle( handle
);
792 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
794 DataBrowserTableViewRowIndex row
;
795 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
796 wxCHECK( err
== noErr
, (unsigned)-1 );
800 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
802 DataBrowserItemID id
;
803 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
804 wxCHECK( err
== noErr
, NULL
);
805 return (wxMacDataItem
*) id
;
808 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
809 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
811 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
812 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
815 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
816 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
818 unsigned int noItems
= itemArray
.GetCount();
819 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
820 for ( unsigned int i
= 0; i
< noItems
; ++i
)
821 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
823 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
824 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
828 static int column_id_counter
= 0;
830 void wxMacDataItemBrowserControl::InsertColumn(int col
, DataBrowserPropertyType colType
,
831 const wxString
& title
, SInt16 just
, int defaultWidth
)
833 DataBrowserListViewColumnDesc columnDesc
;
834 columnDesc
.headerBtnDesc
.titleOffset
= 0;
835 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
837 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
838 kControlUseFontMask
| kControlUseJustMask
;
840 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
841 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
842 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
843 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
845 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
846 // defined for other modes?
849 enc
= m_font
.GetEncoding();
851 enc
= wxLocale::GetSystemEncoding();
852 wxCFStringRef
cfTitle( title
, enc
);
853 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
855 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
856 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
858 DataBrowserPropertyID id
= kMinColumnId
+ column_id_counter
;
861 columnDesc
.propertyDesc
.propertyID
= id
;
862 columnDesc
.propertyDesc
.propertyType
= colType
;
863 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
864 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
865 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
867 verify_noerr( AddColumn( &columnDesc
, col
) );
869 if (defaultWidth
> 0){
870 SetColumnWidth(col
, defaultWidth
);
874 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
876 DataBrowserPropertyID id
;
877 GetColumnIDFromIndex(colId
, &id
);
878 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
881 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
883 DataBrowserPropertyID id
;
884 GetColumnIDFromIndex(colId
, &id
);
886 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
890 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
892 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
893 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
896 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
898 unsigned int noItems
= itemArray
.GetCount();
899 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
900 for ( unsigned int i
= 0; i
< noItems
; ++i
)
901 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
903 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
904 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
908 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
910 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
911 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
915 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
917 unsigned int noItems
= itemArray
.GetCount();
918 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
919 for ( unsigned int i
= 0; i
< noItems
; ++i
)
920 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
922 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
923 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
928 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
930 SetScrollPosition(0, 0);
931 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
935 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
937 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
940 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
942 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
945 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
947 unsigned int noItems
= itemArray
.GetCount();
948 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
949 for ( unsigned int i
= 0; i
< noItems
; ++i
)
950 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
952 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
956 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
958 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
961 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
963 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
966 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
968 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
971 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
973 return m_clientDataItemsType
;
975 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
977 m_clientDataItemsType
= clientDataItemsType
;
980 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
982 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
983 RemoveItem( wxMacDataBrowserRootContainer
, item
);
986 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, wxMacDataItem
* item
)
988 if ( m_sortOrder
== SortOrder_None
)
991 // increase the order of the lines to be shifted
992 unsigned int lines
= MacGetCount();
993 for ( unsigned int i
= n
; i
< lines
; ++i
)
995 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
996 iter
->SetOrder( iter
->GetOrder() + 1 );
1000 // I don't understand what this code is supposed to do, RR.
1001 SInt32 frontLineOrder
= 0;
1004 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
1005 frontLineOrder
= iter
->GetOrder()+1;
1008 item
->SetOrder( n
);
1012 AddItem( wxMacDataBrowserRootContainer
, item
);
1015 void wxMacDataItemBrowserControl::MacClear()
1017 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
1018 RemoveAllItems(wxMacDataBrowserRootContainer
);
1021 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1023 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);