X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c0a66d92372d38600f2b993a541f5788064fba2d..6cef0db28018fd2644ee4e38af715872e5242459:/src/mac/carbon/databrow.cpp diff --git a/src/mac/carbon/databrow.cpp b/src/mac/carbon/databrow.cpp index 8f18448a6e..a4485f8bc5 100644 --- a/src/mac/carbon/databrow.cpp +++ b/src/mac/carbon/databrow.cpp @@ -9,58 +9,42 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef wxUSE_GENERICDATAVIEWCTRL - -#include - -#include -#include -#include -#include - #include "wx/wxprec.h" -#include "wx/utils.h" +#if wxUSE_DATAVIEWCTRL +#ifndef wxUSE_GENERICDATAVIEWCTRL #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/toplevel.h" #include "wx/font.h" + #include "wx/settings.h" + #include "wx/utils.h" #endif -#include "wx/apptrait.h" - -#include "wx/mac/uma.h" - - -#ifdef __DARWIN__ - #include -#else - #include - #include - #include -#endif - +#include "wx/dataview.h" +#include "wx/mac/carbon/databrow.h" #include "wx/mac/private.h" - -#if defined(__MWERKS__) && wxUSE_UNICODE -#if __MWERKS__ < 0x4100 || !defined(__DARWIN__) - #include -#endif -#endif +#include "wx/mac/uma.h" #include -#include "wx/mac/carbon/databrow.h" +// ============================================================================ +// Variables used globally in databrow.cpp +// ============================================================================ +DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP = NULL; +DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL; +DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL; +DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL; -#include "wx/dataview.h" +DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL; +DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP = NULL; +DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP = NULL; +DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP = NULL; // ============================================================================ -// DataBrowser Wrapper +// wxMacDataBrowserTableViewControl // ============================================================================ -// -// basing on DataBrowserItemIDs -// pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser, DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty) { @@ -73,22 +57,22 @@ pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlR return errDataBrowserPropertyNotSupported; } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */ -pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice) +pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser, MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* selection) { wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); if (ControlPtr != NULL) - ControlPtr->DataBrowserDrawItemProc(itemID,property,state,rectangle,bitDepth,colorDevice); -} /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */ + ControlPtr->DataBrowserGetContextualMenuProc(menu,helpType,helpItemString,selection); +} /* wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef, MenuRef*, UInt32*, CFStringRef*, AEDesc*) */ -pascal OSStatus wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean getValue) +pascal OSStatus wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue) { wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); if (ControlPtr != NULL) - return ControlPtr->DataBrowserGetSetItemDataProc(itemID,property,itemData,getValue); + return ControlPtr->DataBrowserGetSetItemDataProc(itemID,propertyID,itemData,getValue); else return errDataBrowserPropertyNotSupported; } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */ @@ -102,10 +86,41 @@ pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(Co ControlPtr->DataBrowserItemNotificationProc(itemID,message,itemData); } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */ -DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL; -DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL; -DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL; -DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL; +pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice) +{ + wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); + + + if (ControlPtr != NULL) + ControlPtr->DataBrowserDrawItemProc(itemID,propertyID,state,rectangle,bitDepth,colorDevice); +} /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */ + +pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit) +{ + wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); + + + return ((ControlPtr != NULL) && ControlPtr->DataBrowserEditItemProc(itemID,propertyID,theString,maxEditTextRect,shrinkToFit)); +} /* wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */ + +pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Rect const* mouseRect) +{ + wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); + + + return ((ControlPtr != NULL) && ControlPtr->DataBrowserHitTestProc(itemID,propertyID,theRect,mouseRect)); +} /* wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */ + +pascal DataBrowserTrackingResult wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point startPt, EventModifiers modifiers) +{ + wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast(wxMacControl::GetReferenceFromNativeControl(browser))); + + + if (ControlPtr != NULL) + return ControlPtr->DataBrowserTrackingProc(itemID,propertyID,theRect,startPt,modifiers); + else + return kDataBrowserNothingHit; +} /* wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style) :wxMacControl(peer) @@ -116,9 +131,10 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee SetReferenceInNativeControl(); verify_noerr(err); - if (gDataBrowserTableViewDrawItemUPP == NULL) gDataBrowserTableViewDrawItemUPP = NewDataBrowserDrawItemUPP (DataBrowserDrawItemProc); - if (gDataBrowserTableViewItemCompareUPP == NULL) gDataBrowserTableViewItemCompareUPP = NewDataBrowserItemCompareUPP(wxMacDataBrowserTableViewControl::DataBrowserCompareProc); - if (gDataBrowserTableViewItemDataUPP == NULL) gDataBrowserTableViewItemDataUPP = NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc); + // setup standard callbacks: + if (gDataBrowserTableViewGetContextualMenuUPP == NULL) gDataBrowserTableViewGetContextualMenuUPP = NewDataBrowserGetContextualMenuUPP(wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc); + if (gDataBrowserTableViewItemCompareUPP == NULL) gDataBrowserTableViewItemCompareUPP = NewDataBrowserItemCompareUPP (wxMacDataBrowserTableViewControl::DataBrowserCompareProc); + if (gDataBrowserTableViewItemDataUPP == NULL) gDataBrowserTableViewItemDataUPP = NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc); if (gDataBrowserTableViewItemNotificationUPP == NULL) { gDataBrowserTableViewItemNotificationUPP = @@ -128,19 +144,28 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc); #endif } + DataBrowserCallbacks callbacks; // variable definition - DataBrowserCallbacks callbacks; - DataBrowserCustomCallbacks customCallbacks; + InitializeDataBrowserCallbacks(&callbacks,kDataBrowserLatestCallbacks); + callbacks.u.v1.getContextualMenuCallback = gDataBrowserTableViewGetContextualMenuUPP; + callbacks.u.v1.itemDataCallback = gDataBrowserTableViewItemDataUPP; + callbacks.u.v1.itemCompareCallback = gDataBrowserTableViewItemCompareUPP; + callbacks.u.v1.itemNotificationCallback = gDataBrowserTableViewItemNotificationUPP; + this->SetCallbacks(&callbacks); - InitializeDataBrowserCallbacks (&callbacks, kDataBrowserLatestCallbacks); - InitializeDataBrowserCustomCallbacks(&customCallbacks,kDataBrowserLatestCallbacks); + // setup callbacks for customized items: + if (gDataBrowserTableViewDrawItemUPP == NULL) gDataBrowserTableViewDrawItemUPP = NewDataBrowserDrawItemUPP(wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc); + if (gDataBrowserTableViewEditItemUPP == NULL) gDataBrowserTableViewEditItemUPP = NewDataBrowserEditItemUPP(wxMacDataBrowserTableViewControl::DataBrowserEditItemProc); + if (gDataBrowserTableViewHitTestUPP == NULL) gDataBrowserTableViewHitTestUPP = NewDataBrowserHitTestUPP (wxMacDataBrowserTableViewControl::DataBrowserHitTestProc); + if (gDataBrowserTableViewTrackingUPP == NULL) gDataBrowserTableViewTrackingUPP = NewDataBrowserTrackingUPP(wxMacDataBrowserTableViewControl::DataBrowserTrackingProc); - callbacks.u.v1.itemDataCallback = gDataBrowserTableViewItemDataUPP; - callbacks.u.v1.itemCompareCallback = gDataBrowserTableViewItemCompareUPP; - callbacks.u.v1.itemNotificationCallback = gDataBrowserTableViewItemNotificationUPP; - this->SetCallbacks(&callbacks); + DataBrowserCustomCallbacks customCallbacks; // variable definition + InitializeDataBrowserCustomCallbacks(&customCallbacks,kDataBrowserLatestCallbacks); customCallbacks.u.v1.drawItemCallback = gDataBrowserTableViewDrawItemUPP; + customCallbacks.u.v1.editTextCallback = gDataBrowserTableViewEditItemUPP; + customCallbacks.u.v1.hitTestCallback = gDataBrowserTableViewHitTestUPP; + customCallbacks.u.v1.trackingCallback = gDataBrowserTableViewTrackingUPP; this->SetCustomCallbacks(&customCallbacks); // style setting: @@ -156,7 +181,7 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee flags |= kDataBrowserSelectOnlyOne; (void) this->SetSelectionFlags(flags); } /* if */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + OptionBits attributes; // variable definition if (this->GetAttributes(&attributes) == noErr) // get default settings @@ -165,9 +190,13 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee attributes |= kDataBrowserAttributeListViewDrawColumnDividers; else attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers; + if ((style & wxDV_ROW_LINES) != 0) + attributes |= kDataBrowserAttributeListViewAlternatingRowColors; + else + attributes &= ~kDataBrowserAttributeListViewAlternatingRowColors; (void) this->SetAttributes(attributes); } /* if */ -#endif + if ((style & wxDV_NO_HEADER) != 0) this->SetHeaderButtonHeight(0); } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */ @@ -188,15 +217,15 @@ OSStatus wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomC // // header handling // -OSStatus wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc) const +OSStatus wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc) const { desc->version = kDataBrowserListViewLatestHeaderDesc; // if this statement is missing the next call will fail (NOT DOCUMENTED!!) - return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef,property,desc); + return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef,propertyID,desc); } -OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc) +OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc) { - return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef,property,desc); + return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef,propertyID,desc); } // @@ -212,79 +241,85 @@ OSStatus wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enabl return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth,enableHeight); } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes) { return ::DataBrowserGetAttributes(this->GetControlRef(),attributes); } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */ -#endif -OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const +OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const +{ + return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width); +} + +OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const { - return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); + return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width ); } -OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight( UInt16 * height ) const +OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const { - return GetDataBrowserTableViewRowHeight( m_controlRef, height ); + return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height); } OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height) { - return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); + return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height); } -OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const +OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserPropertyPart part, Rect* bounds) { - return GetDataBrowserTableViewColumnWidth( m_controlRef , width ); -} + return ::GetDataBrowserItemPartBounds(this->m_controlRef,item,propertyID,part,bounds); +} /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */ -OSStatus wxMacDataBrowserTableViewControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const +OSStatus wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item, UInt16* height) const { - return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height); -} + return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height); +} /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */ OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const { - return GetDataBrowserScrollPosition( m_controlRef , top , left ); + return GetDataBrowserScrollPosition(this->m_controlRef, top , left ); } -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes) { return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes,~attributes); } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */ -#endif -OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width ) +OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width) { - return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); + return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width); } -OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth( UInt16 width ) +OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width) { - return SetDataBrowserTableViewColumnWidth( m_controlRef , width ); + return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef,width); } -OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight( UInt16 height ) +OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height) { - return SetDataBrowserTableViewRowHeight( m_controlRef , height ); + return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height); } -OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars( bool horiz, bool vert ) +OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert) { - return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert ); -} + return ::SetDataBrowserHasScrollBars(this->m_controlRef,horiz,vert); +} /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */ OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height) { - return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); -} + return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height); +} /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */ -OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) +OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle) { - return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle ); -} + return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef,hiliteStyle); +} /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */ + +OSStatus wxMacDataBrowserTableViewControl::SetIndent(float Indent) +{ + return ::DataBrowserSetMetric(this->m_controlRef,kDataBrowserMetricDisclosureColumnPerDepthGap,true,Indent); +} /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */ OSStatus wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item, UInt16 height) { @@ -301,31 +336,36 @@ OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32 // OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const { - return GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns); + return ::GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns); } -OSStatus wxMacDataBrowserTableViewControl::GetColumnID(DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id) +OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const { - return GetDataBrowserTableViewColumnProperty(this->m_controlRef,position,id); -} /* wxMacDataBrowserTableViewControl::GetColumnID(DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id) */ + return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index); +} /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */ -OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* id) const +OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const { - for (*id=kMinPropertyID; *id::max(); ++(*id)) - if (this->IsUsedPropertyID(*id) == errDataBrowserPropertyNotFound) + for (*propertyID=kMinPropertyID; *propertyID::max(); ++(*propertyID)) + if (this->IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound) return noErr; return errDataBrowserPropertyNotSupported; } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */ -OSStatus wxMacDataBrowserTableViewControl::GetPropertyColumn(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* column) const +OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const { - return GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,column); -} /* wxMacDataBrowserTableViewControl::GetPropertyColumn(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */ + return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags); +} -OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID property, DataBrowserPropertyFlags *flags) const +OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID) { - return GetDataBrowserPropertyFlags( m_controlRef , property , flags ); -} + return ::GetDataBrowserItemDataProperty(itemData,propertyID); +} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */ + +OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID) +{ + return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID); +} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */ OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID) const { @@ -337,28 +377,35 @@ OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyI return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index); } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */ -OSStatus wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex position) +OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID) { - DataBrowserTableViewColumnID id; - GetColumnID( position, &id ); - return RemoveDataBrowserTableViewColumn( m_controlRef, id ); -} + return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID); +} /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */ -OSStatus wxMacDataBrowserTableViewControl::SetColumnPosition(DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position) +OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index) { - return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,column,position); -} + DataBrowserTableViewColumnID propertyID; + -OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID property, DataBrowserPropertyFlags flags) + this->GetPropertyID(index,&propertyID); + return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID); +} /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */ + +OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index) { - return ::SetDataBrowserPropertyFlags(this->m_controlRef,property,flags); -} /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */ + return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index); +} /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */ -OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID property, Boolean expandableRows) +OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows) { - return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows); + return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef,propertyID,expandableRows); } +OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags) +{ + return ::SetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags); +} /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */ + // // item handling // @@ -370,9 +417,12 @@ OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const { ItemCount NoOfItems; + + OSStatus status; - verify_noerr(this->GetItemCount(&NoOfItems)); + status = this->GetItemCount(&NoOfItems); + wxCHECK_MSG(status == noErr,status,_("Could not retrieve number of items")); if (NoOfItems == 0) { *id = 1; @@ -467,10 +517,10 @@ size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserIt return NoOfItems; } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/ -OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const +OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const { - return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); -} + return ::GetDataBrowserSelectionAnchor(this->m_controlRef,first,last); +} /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */ OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const { @@ -489,35 +539,52 @@ OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectio OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation) { - return ::SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation ); + return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation ); } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */ -OSStatus wxMacDataBrowserTableViewControl::GetSortProperty( DataBrowserPropertyID *column ) const +OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const { - return GetDataBrowserSortProperty( m_controlRef , column ); + return ::GetDataBrowserSortOrder(this->m_controlRef,order); } -OSStatus wxMacDataBrowserTableViewControl::SetSortProperty( DataBrowserPropertyID column ) +OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const { - return SetDataBrowserSortProperty( m_controlRef , column ); + return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID); } -OSStatus wxMacDataBrowserTableViewControl::GetSortOrder( DataBrowserSortOrder *order ) const +OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren) +{ + return ::SortDataBrowserContainer(this->m_controlRef,container,sortChildren); +} /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */ + +OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order) { - return GetDataBrowserSortOrder( m_controlRef , order ); + return ::SetDataBrowserSortOrder(this->m_controlRef,order); } -OSStatus wxMacDataBrowserTableViewControl::SetSortOrder( DataBrowserSortOrder order ) +OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID) { - return SetDataBrowserSortOrder( m_controlRef , order ); + return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID); } +// +// container handling +// +OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID) +{ + return ::CloseDataBrowserContainer(this->m_controlRef,containerID); +} /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */ + +OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID) +{ + return ::OpenDataBrowserContainer(this->m_controlRef,containerID); +} /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */ + IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl) // ============================================================================ -// Databrowser class for the list view control +// wxMacDataBrowserListViewControl // ============================================================================ -// #pragma mark - // // column handling @@ -528,9 +595,8 @@ OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDes } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */ // ============================================================================ -// Databrowser class for the data view control +// wxMacDataViewDataBrowserListViewControl // ============================================================================ -// #pragma mark - // // constructors / destructor @@ -541,109 +607,382 @@ wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl } /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */ // -// item ID and model matching +// callback functions (inherited from wxMacDataBrowserTableViewControl) // -void wxMacDataViewDataBrowserListViewControl::ClearItemIDRowPairs(void) +Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty) { - this->m_itemIDRowNumberMap.clear(); -} /* wxMacDataViewDataBrowserListViewControl::ClearItemIDRowPairs(void) */ + DataBrowserSortOrder sortOrder; -bool wxMacDataViewDataBrowserListViewControl::DeleteItemIDRowPair(DataBrowserItemID itemID) -{ - return (this->m_itemIDRowNumberMap.erase(itemID) == 1); -} /* wxMacDataViewDataBrowserListViewControl::DeleteItemIDRowPair(DataBrowseritemID) */ - -bool wxMacDataViewDataBrowserListViewControl::GetRowIndex(unsigned long& rowIndex, DataBrowserItemID itemID) const -{ - ItemIDRowNumberHashMap::const_iterator iteratorHashMap(this->m_itemIDRowNumberMap.find(itemID)); + DataBrowserTableViewColumnIndex modelColumnIndex; + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - if (iteratorHashMap == this->m_itemIDRowNumberMap.end()) - return false; - else + + wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly.")); + wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly.")); + if (sortProperty >= kMinPropertyID) { - rowIndex = iteratorHashMap->second; - return true; + // variable definition and initialization: + wxDataViewColumn* ColumnPtr(dataViewCtrlPtr->GetColumnPtr(sortProperty)); + + wxCHECK_MSG(ColumnPtr != NULL,false,_("Could not determine column index.")); + modelColumnIndex = ColumnPtr->GetModelColumn(); } /* if */ -} /* wxMacDataViewDataBrowserListViewControl::GetRowIndex(unsigned int& rowIndex, DataBrowserItemID itemID) const */ + else + modelColumnIndex = 0; + this->GetSortOrder(&sortOrder); + return static_cast(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast(itemOneID)),wxDataViewItem(reinterpret_cast(itemTwoID)), + modelColumnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0); +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */ -bool wxMacDataViewDataBrowserListViewControl::InsertItemIDRowPair(DataBrowserItemID itemID, unsigned long rowIndex) +void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* WXUNUSED(selection)) + // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU. { - return this->m_itemIDRowNumberMap.insert(ItemIDRowNumberHashMap::value_type(itemID,rowIndex)).second; -} /* wxMacDataViewDataBrowserListViewControl::InsertItemIDRowPair(DataBrowserItemID, unsigned long) */ + wxArrayDataBrowserItemID itemIDs; -void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndices(unsigned int* newIndices) -{ - ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin()); - - - while (hashMapIterator != this->m_itemIDRowNumberMap.end()) - { - hashMapIterator->second = newIndices[hashMapIterator->second]; - ++hashMapIterator; - } /* while */ -} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndices(unsigned int*) */ + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); -void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesDeletion (unsigned long decreaseFromIndex) -{ - ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin()); - - - while (hashMapIterator != this->m_itemIDRowNumberMap.end()) - { - if (hashMapIterator->second >= decreaseFromIndex) - --(hashMapIterator->second); - ++hashMapIterator; - } /* while */ -} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesDeletion (unsigned int) */ -void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesInsertion(unsigned long increaseFromIndex) -{ - ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin()); - + wxCHECK_RET(dataViewCtrlPtr != NULL,_("wxWidget control pointer is not a data view pointer")); + // initialize parameters so that no context menu will be displayed automatically by the native data browser: + *menu = NULL; + *helpType = kCMHelpItemNoHelp; + *helpItemString = NULL; + // create information for a context menu event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId()); - while (hashMapIterator != this->m_itemIDRowNumberMap.end()) - { - if (hashMapIterator->second >= increaseFromIndex) - ++(hashMapIterator->second); - ++hashMapIterator; - } /* while */ -} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesInsertion(unsigned int) */ + dataViewEvent.SetModel(dataViewCtrlPtr->GetModel()); + // get the item information; + // theoretically more than one ID can be returned but the event can only handle one item, therefore all item related data is using the data of the first item in the array: + if (this->GetSelectedItemIDs(itemIDs) > 0) + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemIDs[0]))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */ -void wxMacDataViewDataBrowserListViewControl::ReverseRowIndexNumbering(void) +OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue) { - if (this->m_itemIDRowNumberMap.size() > 0) + if (getValue) { - size_t const maxIndex = this->m_itemIDRowNumberMap.size()-1; - - ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin()); - + // variable definitions: + wxDataViewCtrl* dataViewCtrlPtr; - while (hashMapIterator != this->m_itemIDRowNumberMap.end()) + dataViewCtrlPtr = dynamic_cast(this->GetPeer()); + wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); + if (dataViewCtrlPtr->IsDeleting()) + return noErr; // if a delete process is running the data of editable fields cannot be saved because the associated model variable may already have been deleted + else + { + // variable definitions: + OSStatus errorStatus; + wxDataViewColumn* dataViewColumnPtr; + + wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly.")); + dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID); + wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index.")); + switch (dataViewColumnPtr->GetRenderer()->GetPropertyType()) + { + case kDataBrowserCheckboxType: + { + // variable definition: + ThemeButtonValue buttonValue; + + errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue); + if (errorStatus == noErr) + { + if (buttonValue == kThemeButtonOn) + { + // variable definition and initialization: + wxVariant modifiedData(true); + + return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),dataViewColumnPtr->GetModelColumn()) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured)); + } /* if */ + else if (buttonValue == kThemeButtonOff) + { + // variable definition and initialization: + wxVariant modifiedData(false); + + return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),dataViewColumnPtr->GetModelColumn()) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured)); + } /* if */ + else + return errDataBrowserInvalidPropertyData; + } /* if */ + else + return errorStatus; + } /* block */ + case kDataBrowserTextType: + { + // variable definitions: + CFStringRef stringReference; + + errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference); + if (errorStatus == noErr) + { + // variable definitions and initializations: +#if wxCHECK_VERSION(2,9,0) + wxCFStringRef modifiedString(stringReference); +#else + wxMacCFStringHolder modifiedString(stringReference); +#endif + wxVariant modifiedData(modifiedString.AsString()); + + if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),dataViewColumnPtr->GetModelColumn())) + return noErr; + else + return errDataBrowserNotConfigured; + } /* if */ + else + return errorStatus; + } /* block */ + default: + return errDataBrowserPropertyNotSupported; + } /* switch */ + } /* if */ + } /* if */ + else + { + if (propertyID >= kMinPropertyID) // in case data columns set the data + { + // variable definitions: + wxVariant variant; + wxDataViewColumn* dataViewColumnPtr; + wxDataViewCtrl* dataViewCtrlPtr; + + dataViewCtrlPtr = dynamic_cast(this->GetPeer()); + wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); + wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly.")); + dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID); + wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing.")); + wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column.")); + dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast(itemID)),dataViewColumnPtr->GetModelColumn()); + if (!(variant.IsNull())) + { + dataViewColumnPtr->GetRenderer()->SetDataReference(itemData); + dataViewColumnPtr->GetRenderer()->SetValue(variant); + wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed.")); + } /* if */ + return noErr; + } /* if */ + else // react on special system requests { - hashMapIterator->second = maxIndex-hashMapIterator->second; - ++hashMapIterator; - } /* while */ + switch (propertyID) + { + case kDataBrowserContainerIsClosableProperty: + { + // variable definitions: + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + + wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast(itemID))); + dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + // opening the container is allowed if not vetoed: + return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed()); + } /* block */ + case kDataBrowserContainerIsOpenableProperty: + { + // variable definitions: + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + + wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast(itemID))); + dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + // opening the container is allowed if not vetoed: + return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed()); + } /* block */ + case kDataBrowserItemIsContainerProperty: + { + // variable definition: + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + + wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); + wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly.")); + return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast(itemID)))); + } /* block */ + case kDataBrowserItemIsEditableProperty: + return ::SetDataBrowserItemDataBooleanValue(itemData,true); + } /* switch */ + } /* if */ } /* if */ -} /* wxMacDataViewDataBrowserListViewControl::ReverseRowIndexNumbering(void) */ + return errDataBrowserPropertyNotSupported; +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */ -// -// callback functions (inherited from wxMacDataBrowserTableViewControl) -// -Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID WXUNUSED(sortProperty)) +void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData) { - unsigned long rowIndex1, rowIndex2; + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - bool result = (this->GetRowIndex(rowIndex1,itemOneID) && this->GetRowIndex(rowIndex2,itemTwoID) && (rowIndex1 < rowIndex2)); - return result; -} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */ -void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice) -{ - OSStatus errorStatus; + // check if the data view control pointer still exists because this call back function can still be called when the control has already been deleted: + if (dataViewCtrlPtr != NULL) + switch (message) + { + case kDataBrowserContainerClosed: + dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary) + { + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserContainerOpened: + dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary) + { + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + // add children to the expanded container: + dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast(itemID))); + } /* block */ + break; + case kDataBrowserEditStarted: + dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary) + { + // initialize wxWidget event: + DataBrowserPropertyID propertyID; + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); + if (this->GetPropertyID(itemData,&propertyID) == noErr) + { + // variable definition and initialization: + DataBrowserTableViewColumnIndex columnIndex; + + wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found.")); + dataViewEvent.SetColumn(columnIndex); + dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID)); + } /* if */ + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserEditStopped: + { + // initialize wxWidget event: + DataBrowserPropertyID propertyID; + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); + if (this->GetPropertyID(itemData,&propertyID) == noErr) + { + // variable definition and initialization: + DataBrowserTableViewColumnIndex columnIndex; - unsigned long column; - unsigned long row; + wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found.")); + dataViewEvent.SetColumn(columnIndex); + dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID)); + } /* if */ + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserItemAdded: + dataViewCtrlPtr->FinishCustomItemEditing(); + break; + case kDataBrowserItemDeselected: + dataViewCtrlPtr->FinishCustomItemEditing(); + break; + case kDataBrowserItemDoubleClicked: + { + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserItemRemoved: + dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary) + break; + case kDataBrowserItemSelected: + break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged + case kDataBrowserSelectionSetChanged: + { + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserTargetChanged: // no idea if this notification is ever sent + break; + case kDataBrowserUserStateChanged: + { + // finish custom item editing if necessary: + dataViewCtrlPtr->FinishCustomItemEditing(); + // update column widths: + for (size_t i=0; iGetColumnCount(); ++i) + { + // constant definition for abbreviational purposes: + wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumn(i); + // variable definition: + UInt16 columnWidth; + + wxCHECK_RET(this->GetColumnWidth(columnPtr->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined")); + columnPtr->SetWidthVariable(columnWidth); + } /* for */ + // update sorting orders: + DataBrowserPropertyID propertyID; // variable definition + + if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID)) + { + DataBrowserSortOrder sortOrder; + DataBrowserTableViewColumnIndex columnIndex; + + if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr)) + { + // variable definition and initialization: + wxDataViewColumn* columnPtr; + columnPtr = dataViewCtrlPtr->GetColumn(columnIndex); + // check if the sort order has changed: + if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) || + !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing)) + { + columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending())); + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion + + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetColumn(columnIndex); + dataViewEvent.SetDataViewColumn(columnPtr); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + } /* if */ + } /* if */ + } /* if */ + } /* block */ + break; + } /* switch */ +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */ + +void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice) +{ + DataBrowserTableViewColumnIndex columnIndex; wxDataViewColumn* dataViewColumnPtr; @@ -653,24 +992,19 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse wxVariant dataToRender; - - wxCHECK_RET(this->GetPropertyColumn(property,&column) == noErr,_("Could not determine column index.")); dataViewCtrlPtr = dynamic_cast(this->GetPeer()); wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly.")); wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL,_("Pointer to model not set correctly.")); - if (dynamic_cast(dataViewCtrlPtr->GetModel()) == NULL) - { - wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist.")); - } /* if */ - else - { - wxCHECK_RET(this->GetItemRow(itemID,&row) == noErr,_("Row index does not exist.")); - } /* if */ - dataViewColumnPtr = dataViewCtrlPtr->GetColumn(column); + wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex) == noErr,_("Could not determine column index.")); + dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID); wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing.")); dataViewCustomRendererPtr = dynamic_cast(dataViewColumnPtr->GetRenderer()); wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column.")); - dataViewCtrlPtr->GetModel()->GetValue(dataToRender,column,row); + dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast(itemID)),dataViewColumnPtr->GetModelColumn()); + dataViewCustomRendererPtr->SetValue(dataToRender); + + wxDataViewItem dataitem( reinterpret_cast(itemID) ); + dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataitem,columnIndex); dataViewCustomRendererPtr->SetValue(dataToRender); // try to determine the content's size (drawable part): @@ -691,216 +1025,107 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse content.left += 5; content.right -= 3; content.bottom -= 3; - // extra space for the scrollbars: + // extra space for the scrollbars: content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); - // make sure that 'Render' can draw only in the allowed area: - dataViewCustomRendererPtr->GetDC()->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1); - (void) (dataViewCustomRendererPtr->Render(wxRect(static_cast(rectangle->left),static_cast(rectangle->top), - static_cast(1+rectangle->right-rectangle->left),static_cast(1+rectangle->bottom-rectangle->top)), - dataViewCustomRendererPtr->GetDC(),((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0))); - dataViewCustomRendererPtr->GetDC()->DestroyClippingRegion(); // probably not necessary + wxDC *dc = dataViewCustomRendererPtr->GetDC(); + + wxRect cellrect( static_cast(rectangle->left), + static_cast(rectangle->top+2), + static_cast(1+rectangle->right-rectangle->left), + static_cast(rectangle->bottom-rectangle->top) ); + + bool is_active = IsControlActive( this->m_controlRef ); + if (state == kDataBrowserItemIsSelected) + { + + wxColour col( wxMacCreateCGColorFromHITheme( (is_active) ? + kThemeBrushAlternatePrimaryHighlightColor + : kThemeBrushSecondaryHighlightColor ) ); + + wxRect rect = cellrect; + Rect itemrect; + GetDataBrowserItemPartBounds( this->m_controlRef, itemID, propertyID, + kDataBrowserPropertyEnclosingPart, &itemrect ); + rect.x = itemrect.left; + rect.width = itemrect.right-itemrect.left+1; + + wxBrush selBrush( col ); + wxPen oldpen( dc->GetPen() ); + wxBrush oldbrush( dc->GetBrush() ); + dc->SetPen( *wxTRANSPARENT_PEN ); + dc->SetBrush( selBrush ); + dc->DrawRectangle(rect); + dc->SetBrush( oldbrush ); + dc->SetPen( oldpen ); + } + + wxDataViewModel *model = dataViewCtrlPtr->GetModel(); + if ((columnIndex == 0) || !model->IsContainer(dataitem) || model->HasContainerColumns(dataitem)) + { + // make sure that 'Render' can draw only in the allowed area: + dc->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1); + (void) (dataViewCustomRendererPtr->Render( cellrect, dc, + ((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0))); + dc->DestroyClippingRegion(); // probably not necessary + } + + dataViewCustomRendererPtr->SetDC(NULL); } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */ -OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean getValue) +Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit) { - if (getValue) - { - // variable definition: - unsigned long column; - unsigned long row; - wxDataViewCtrl* dataViewCtrlPtr; - wxDataViewColumn* dataViewColumnPtr; - - verify_noerr(this->GetPropertyColumn(property,&column)); - dataViewCtrlPtr = dynamic_cast(this->GetPeer()); - wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); - if (dynamic_cast(dataViewCtrlPtr->GetModel()) == NULL) - { - wxCHECK_MSG(this->GetRowIndex(row,itemID),errDataBrowserNotConfigured,_("Row index does not exist.")); - } /* if */ - else - { - wxCHECK_MSG(this->GetItemRow(itemID,&row) == noErr,errDataBrowserNotConfigured,_("Row index does not exist.")); - } /* if */ - dataViewColumnPtr = dataViewCtrlPtr->GetColumn(column); - wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column for the specified column index.")); - switch (dataViewColumnPtr->GetRenderer()->GetPropertyType()) - { - case kDataBrowserCheckboxType: - { - // variable definitions: - ThemeButtonValue buttonValue; - OSStatus errorStatus; + return false; +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */ - errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue); - if (errorStatus == noErr) - { - if (buttonValue == kThemeButtonOn) - { - // variable definition and initialization: - wxVariant modifiedData(true); +Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID WXUNUSED(itemID), DataBrowserPropertyID WXUNUSED(property), Rect const* WXUNUSED(theRect), Rect const* WXUNUSED(mouseRect)) +{ + return true; +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */ - return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast(column),static_cast(row)) ? noErr : errDataBrowserNotConfigured); - } /* if */ - else if (buttonValue == kThemeButtonOff) - { - // variable definition and initialization: - wxVariant modifiedData(false); +DataBrowserTrackingResult wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point WXUNUSED(startPt), EventModifiers WXUNUSED(modifiers)) +{ + wxDataViewColumn* dataViewColumnPtr; - return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast(column),static_cast(row)) ? noErr : errDataBrowserNotConfigured); - } /* if */ - else - return errDataBrowserInvalidPropertyData; - } /* if */ - else - return errorStatus; - } /* block */ - case kDataBrowserTextType: - { - // variable definitions: - CFStringRef stringReference; - OSStatus errorStatus; + wxDataViewCtrl* dataViewCtrlPtr; + + wxDataViewCustomRenderer* dataViewCustomRendererPtr; + + wxDataViewItem dataViewCustomRendererItem; - errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference); - if (errorStatus == noErr) - { - // variable definitions and initializations: - wxMacCFStringHolder modifiedString(stringReference); - wxVariant modifiedData(modifiedString.AsString()); - if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast(column),static_cast(row))) - return noErr; - else - return errDataBrowserNotConfigured; - } /* if */ - else - return errorStatus; - } /* block */ - default: - return errDataBrowserPropertyNotSupported; - } /* switch */ - } /* if */ - else + dataViewCustomRendererItem = reinterpret_cast(itemID); + wxCHECK_MSG(dataViewCustomRendererItem.IsOk(),kDataBrowserNothingHit,_("Invalid data view item")); + dataViewCtrlPtr = dynamic_cast(this->GetPeer()); + wxCHECK_MSG(dataViewCtrlPtr != NULL,kDataBrowserNothingHit,_("Pointer to data view control not set correctly.")); + dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID); + wxCHECK_MSG(dataViewColumnPtr != NULL,kDataBrowserNothingHit,_("No column existing.")); + dataViewCustomRendererPtr = dynamic_cast(dataViewColumnPtr->GetRenderer()); + wxCHECK_MSG(dataViewCustomRendererPtr != NULL,kDataBrowserNothingHit,_("No renderer or invalid renderer type specified for custom data column.")); + // if the currently edited item is identical to the to be edited nothing is done (this hit should only be handled in the control itself): + if (dataViewCtrlPtr->GetCustomRendererItem() == dataViewCustomRendererItem) + return kDataBrowserContentHit; + // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished: + if (dataViewCtrlPtr->GetCustomRendererPtr() != NULL) { - if (property >= kMinPropertyID) // in case of data columns set the data - { - // variable definitions: - OSStatus errorStatus; - unsigned long columnPosition; - unsigned long rowPosition; - wxVariant variant; - wxDataViewColumn* dataViewColumnPtr; - wxDataViewCtrl* dataViewCtrlPtr; - - errorStatus = this->GetPropertyColumn(property,&columnPosition); - wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Column index does not exist.")); - dataViewCtrlPtr = dynamic_cast(this->GetPeer());wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); - dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnPosition); wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing.")); - if (dynamic_cast(dataViewCtrlPtr->GetModel()) == NULL) - { - wxCHECK_MSG(this->GetRowIndex(rowPosition,itemID),errDataBrowserNotConfigured,_("Row index does not exist.")); - } /* if */ - else - { - wxCHECK_MSG(this->GetItemRow(itemID,&rowPosition) == noErr,errDataBrowserNotConfigured,_("Row index does not exist.")); - } /* if */ - dataViewCtrlPtr->GetModel()->GetValue(variant,dataViewColumnPtr->GetModelColumn(),rowPosition); - wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column.")); - dataViewColumnPtr->GetRenderer()->SetDataReference(itemData); - dataViewColumnPtr->GetRenderer()->SetValue(variant); - wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed.")); - } /* if */ - else // react on special system requests - switch (property) - { - case kDataBrowserItemIsContainerProperty: - return ::SetDataBrowserItemDataBooleanValue(itemData,false); - case kDataBrowserItemIsEditableProperty: - return ::SetDataBrowserItemDataBooleanValue(itemData,true); - } /* switch */ + dataViewCtrlPtr->GetCustomRendererPtr()->FinishEditing(); + dataViewCtrlPtr->SetCustomRendererItem(wxDataViewItem()); + dataViewCtrlPtr->SetCustomRendererPtr (NULL); } /* if */ - return errDataBrowserPropertyNotSupported; -} /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */ - -void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef WXUNUSED(itemData)) -{ - switch (message) + // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item: + if (dataViewCustomRendererPtr->HasEditorCtrl()) { - case kDataBrowserItemDoubleClicked: - { - // variable definitions: - unsigned long row; - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly.")); - wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist.")); - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED,dataViewCtrlPtr->GetId()); // variable defintion - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetRow(row); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserItemSelected: - { - // variable definitions: - unsigned long row; - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly.")); - if (dynamic_cast(dataViewCtrlPtr->GetModel()) == NULL) - { - wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist.")); - } /* if */ - else - { - wxCHECK_RET(this->GetItemRow(itemID,&row) == noErr,_("Row index does not exist.")); - } /* if */ - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED,dataViewCtrlPtr->GetId()); // variable defintion - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetRow(row); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserUserStateChanged: - { - DataBrowserPropertyID propertyId; - - if ((this->GetSortProperty(&propertyId) == noErr) && (propertyId >= kMinPropertyID)) - { - DataBrowserSortOrder sortOrder; - unsigned long column; - - if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetPropertyColumn(propertyId,&column) == noErr)) - { - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - if ( dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) || - !(dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing)) - { - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetColumn(column); - dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumn(column)); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* if */ - } /* if */ - } /* if */ - } /* block */ - break; - } /* switch */ -} /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */ - + // variable definition: + wxRect wxRectangle; + + ::wxMacNativeToRect(theRect,&wxRectangle); + dataViewCustomRendererPtr->StartEditing(dataViewCustomRendererItem,wxRectangle); + dataViewCtrlPtr->SetCustomRendererItem(dataViewCustomRendererItem); + dataViewCtrlPtr->SetCustomRendererPtr (dataViewCustomRendererPtr); + } /* if */ + return kDataBrowserContentHit; +} /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */ -#endif - // wxUSE_GENERICDATAVIEWCTRL +#endif // wxUSE_GENERICDATAVIEWCTRL +#endif // wxUSE_DATAVIEWCTRL