X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/194027acb360e71d5c378db3eb08d63e01e164d0..87d3576fdc86ca3dfdece3c2d6df3f449a22670e:/src/mac/carbon/databrow.cpp?ds=inline diff --git a/src/mac/carbon/databrow.cpp b/src/mac/carbon/databrow.cpp index bde0284cbf..a313cb60f8 100644 --- a/src/mac/carbon/databrow.cpp +++ b/src/mac/carbon/databrow.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // Name: src/mac/carbon/databrow.cpp // Purpose: Classes and functions for the Carbon data browser -// Author: +// Author: // Modified by: // Created: 2007-05-18 // RCS-ID: $Id$ @@ -9,51 +9,25 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef wxUSE_GENERICDATAVIEWCTRL - -#include - -#include -#include -#include -#include - #include "wx/wxprec.h" -#include "wx/utils.h" +#if wxUSE_DATAVIEWCTRL && !defined(wxUSE_GENERICDATAVIEWCTRL) + +#include #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/toplevel.h" #include "wx/font.h" + #include "wx/settings.h" #endif -#include "wx/apptrait.h" - -#include "wx/mac/uma.h" - - -#ifdef __DARWIN__ - #include -#else - #include - #include - #include -#endif - -#include "wx/mac/private.h" - -#if defined(__MWERKS__) && wxUSE_UNICODE -#if __MWERKS__ < 0x4100 || !defined(__DARWIN__) - #include -#endif -#endif - -#include +#include "wx/dataview.h" +#include "wx/utils.h" #include "wx/mac/carbon/databrow.h" - -#include "wx/dataview.h" +#include "wx/mac/private.h" +#include "wx/mac/uma.h" // ============================================================================ // wxMacDataBrowserTableViewControl @@ -119,11 +93,7 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee if (gDataBrowserTableViewItemNotificationUPP == NULL) { gDataBrowserTableViewItemNotificationUPP = -#if TARGET_API_MAC_OSX (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc); -#else - NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc); -#endif } DataBrowserCallbacks callbacks; @@ -153,9 +123,9 @@ 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 { if ((style & wxDV_VERT_RULES) != 0) @@ -164,7 +134,7 @@ wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* pee attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers; (void) this->SetAttributes(attributes); } /* if */ -#endif + if ((style & wxDV_NO_HEADER) != 0) this->SetHeaderButtonHeight(0); } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */ @@ -209,18 +179,21 @@ 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 propertyID, UInt16* width) const { return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width); } +OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const +{ + return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width ); +} + OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const { return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height); @@ -231,27 +204,25 @@ OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height) return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height); } -OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const +OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID property, DataBrowserPropertyPart part, Rect* bounds) { - return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width ); -} + return ::GetDataBrowserItemPartBounds(this->m_controlRef,item,property,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(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 propertyID, UInt16 width) { @@ -268,20 +239,25 @@ OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height) return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height); } -OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars( bool horiz, bool vert ) +OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert) { - return SetDataBrowserHasScrollBars(this->m_controlRef, horiz, vert ); -} + return ::SetDataBrowserHasScrollBars(this->m_controlRef,horiz,vert); +} /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */ OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height) { - return SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef, height ); -} + return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height); +} /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */ -OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) +OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle) { - return SetDataBrowserTableViewHiliteStyle(this->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) { @@ -319,6 +295,11 @@ OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyI return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags); } +OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID) +{ + return ::GetDataBrowserItemDataProperty(itemData,propertyID); +} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */ + OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID) { return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID); @@ -330,18 +311,23 @@ OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyI // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns // the column position for the property id: DataBrowserTableViewColumnIndex index; - + return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index); } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */ -OSStatus wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex index) +OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID) +{ + return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID); +} /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */ + +OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index) { DataBrowserTableViewColumnID propertyID; this->GetPropertyID(index,&propertyID); return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID); -} /* wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex) */ +} /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */ OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index) { @@ -369,8 +355,8 @@ OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const { ItemCount NoOfItems; - - + + verify_noerr(this->GetItemCount(&NoOfItems)); if (NoOfItems == 0) { @@ -419,7 +405,7 @@ OSStatus wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns // the column position for the property id: DataBrowserTableViewColumnIndex index; - + return ::GetDataBrowserTableViewItemRow(this->m_controlRef,itemID,&index); } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */ @@ -446,7 +432,7 @@ size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserIt { DataBrowserItemID* itemIDPtr; Handle handle(::NewHandle(0)); - + size_t NoOfItems; @@ -491,25 +477,43 @@ OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, Dat return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation ); } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */ +OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const +{ + return ::GetDataBrowserSortOrder(this->m_controlRef,order); +} + OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const { return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID); } +OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren) +{ + return ::SortDataBrowserContainer(this->m_controlRef,container,sortChildren); +} /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */ + +OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order) +{ + return ::SetDataBrowserSortOrder(this->m_controlRef,order); +} + OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID) { return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID); } -OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const +// +// container handling +// +OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID) { - return ::GetDataBrowserSortOrder(this->m_controlRef,order); -} + return ::CloseDataBrowserContainer(this->m_controlRef,containerID); +} /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */ -OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order) +OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID) { - return ::SetDataBrowserSortOrder(this->m_controlRef,order); -} + return ::OpenDataBrowserContainer(this->m_controlRef,containerID); +} /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */ IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl) @@ -542,20 +546,24 @@ wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl // Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty) { + DataBrowserSortOrder sortOrder; + + DataBrowserTableViewColumnIndex columnIndex; + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - + 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) { - // variable definition: - DataBrowserTableViewColumnIndex columnIndex; - wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index.")); - dataViewCtrlPtr->GetModel()->SetSortingColumn(columnIndex); } /* if */ - return static_cast(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast(itemOneID)),wxDataViewItem(reinterpret_cast(itemTwoID))) < 0); + else + columnIndex = 0; + this->GetSortOrder(&sortOrder); + return static_cast(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast(itemOneID)),wxDataViewItem(reinterpret_cast(itemTwoID)), + columnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0); } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice) @@ -565,12 +573,11 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse wxDataViewColumn* dataViewColumnPtr; wxDataViewCtrl* dataViewCtrlPtr; - + wxDataViewCustomRenderer* dataViewCustomRendererPtr; wxVariant dataToRender; - 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.")); @@ -579,7 +586,9 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse 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,wxDataViewItem(reinterpret_cast(itemID)),columnIndex); + + wxDataViewItem dataitem( reinterpret_cast(itemID) ); + dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataitem,columnIndex); dataViewCustomRendererPtr->SetValue(dataToRender); // try to determine the content's size (drawable part): @@ -600,16 +609,53 @@ 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 propertyID, DataBrowserItemDataRef itemData, Boolean getValue) @@ -617,104 +663,144 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( if (getValue) { // variable definitions: - DataBrowserTableViewColumnIndex columnIndex; - OSStatus errorStatus; - wxDataViewCtrl* dataViewCtrlPtr; - 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.")); - errorStatus = this->GetColumnIndex(propertyID,&columnIndex); - wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index")); - dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex); - wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index.")); - switch (dataViewColumnPtr->GetRenderer()->GetPropertyType()) + 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 { - case kDataBrowserCheckboxType: - { - // variable definition: - ThemeButtonValue buttonValue; + // variable definitions: + DataBrowserTableViewColumnIndex columnIndex; + OSStatus errorStatus; + wxDataViewColumn* dataViewColumnPtr; - errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue); - if (errorStatus == noErr) + wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly.")); + errorStatus = this->GetColumnIndex(propertyID,&columnIndex); + wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index")); + dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex); + 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: { - if (buttonValue == kThemeButtonOn) - { - // variable definition and initialization: - wxVariant modifiedData(true); + // variable definition: + ThemeButtonValue buttonValue; - return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),static_cast(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured)); - } /* if */ - else if (buttonValue == kThemeButtonOff) + errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue); + if (errorStatus == noErr) { - // variable definition and initialization: - wxVariant modifiedData(false); - - return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),static_cast(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured)); + if (buttonValue == kThemeButtonOn) + { + // variable definition and initialization: + wxVariant modifiedData(true); + + return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),static_cast(columnIndex)) ? 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)),static_cast(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured)); + } /* if */ + else + return errDataBrowserInvalidPropertyData; } /* if */ else - return errDataBrowserInvalidPropertyData; - } /* if */ - else - return errorStatus; - } /* block */ - case kDataBrowserTextType: - { - // variable definitions: - CFStringRef stringReference; - - errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference); - if (errorStatus == noErr) + return errorStatus; + } /* block */ + case kDataBrowserTextType: { - // variable definitions and initializations: - wxMacCFStringHolder modifiedString(stringReference); - wxVariant modifiedData(modifiedString.AsString()); + // variable definitions: + CFStringRef stringReference; - if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),static_cast(columnIndex))) - return noErr; + errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference); + if (errorStatus == noErr) + { + // variable definitions and initializations: + wxCFStringRef modifiedString(stringReference); + wxVariant modifiedData(modifiedString.AsString()); + + if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast(itemID)),static_cast(columnIndex))) + return noErr; + else + return errDataBrowserNotConfigured; + } /* if */ else - return errDataBrowserNotConfigured; - } /* if */ - else - return errorStatus; - } /* block */ - default: - return errDataBrowserPropertyNotSupported; - } /* switch */ + return errorStatus; + } /* block */ + default: + return errDataBrowserPropertyNotSupported; + } /* switch */ + } /* if */ } /* if */ else { - if (propertyID >= kMinPropertyID) // in case of data columns set the data + if (propertyID >= kMinPropertyID) // in case data columns set the data { // variable definitions: - DataBrowserTableViewColumnIndex columnIndex; - OSStatus errorStatus; - wxVariant variant; - wxDataViewColumn* dataViewColumnPtr; - wxDataViewCtrl* dataViewCtrlPtr; - + 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.")); - errorStatus = this->GetColumnIndex(propertyID,&columnIndex); - wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Column index does not exist.")); - dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex); + 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()); - dataViewColumnPtr->GetRenderer()->SetDataReference(itemData); - dataViewColumnPtr->GetRenderer()->SetValue(variant); - wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed.")); + 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 + { 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))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->HandleWindowEvent(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))); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->HandleWindowEvent(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)))); @@ -722,86 +808,162 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( case kDataBrowserItemIsEditableProperty: return ::SetDataBrowserItemDataBooleanValue(itemData,true); } /* switch */ + } /* if */ } /* if */ return errDataBrowserPropertyNotSupported; } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */ -void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef WXUNUSED(itemData)) +void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData) { - switch (message) - { - case kDataBrowserContainerOpened: - { - // variable definitions: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly.")); - dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast(itemID))); - } /* block */ - break; - case kDataBrowserItemDoubleClicked: - { - // variable definitions: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly.")); - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserItemSelected: - { - // variable definitions: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly.")); - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED,dataViewCtrlPtr->GetId()); // variable definition - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast(itemID))); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserUserStateChanged: - { - DataBrowserPropertyID propertyID; - - if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID)) + wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + + + // 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: + { + // 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->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserContainerOpened: { - DataBrowserSortOrder sortOrder; - DataBrowserTableViewColumnIndex columnIndex; - - if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr)) + // 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->HandleWindowEvent(dataViewEvent); + // add children to the expanded container: + dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast(itemID))); + } /* block */ + break; + case kDataBrowserEditStarted: + { + // 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: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + 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->HandleWindowEvent(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; + + 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->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserItemAdded: + break; // not used anymore + case kDataBrowserItemDeselected: + break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged + 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->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserItemRemoved: + break; // not used anymore + 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 - if ( dataViewCtrlPtr->GetColumn(columnIndex)->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) || - !(dataViewCtrlPtr->GetColumn(columnIndex)->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing)) + dataViewEvent.SetEventObject(dataViewCtrlPtr); + dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); + // finally send the equivalent wxWidget event: + dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserUserStateChanged: + { + // 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 order status: + 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)) { - // initialize wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetColumn(columnIndex); - dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumn(columnIndex)); - // finally sent the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + // 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->HandleWindowEvent(dataViewEvent); + } /* if */ } /* if */ } /* if */ - } /* if */ - } /* block */ - break; - } /* switch */ + } /* block */ + break; + } /* switch */ } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */ -#endif - // wxUSE_GENERICDATAVIEWCTRL +#endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL