X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/07c51ff1fa68e0667f164cfa8b2317666c367642..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/mac/carbon/databrow.cpp diff --git a/src/mac/carbon/databrow.cpp b/src/mac/carbon/databrow.cpp index 9e8236b740..e7fe19a2a6 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,12 +179,10 @@ 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 { @@ -251,12 +219,10 @@ OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt 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) { @@ -273,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) { @@ -340,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) { @@ -379,8 +355,8 @@ OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const { ItemCount NoOfItems; - - + + verify_noerr(this->GetItemCount(&NoOfItems)); if (NoOfItems == 0) { @@ -429,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 */ @@ -456,7 +432,7 @@ size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserIt { DataBrowserItemID* itemIDPtr; Handle handle(::NewHandle(0)); - + size_t NoOfItems; @@ -526,6 +502,19 @@ OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID 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) // ============================================================================ @@ -560,9 +549,9 @@ Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrow 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.")); @@ -584,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.")); @@ -598,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): @@ -619,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) @@ -637,7 +664,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( { // variable definitions: wxDataViewCtrl* dataViewCtrlPtr; - + dataViewCtrlPtr = dynamic_cast(this->GetPeer()); wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly.")); if (dataViewCtrlPtr->IsDeleting()) @@ -648,7 +675,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( DataBrowserTableViewColumnIndex columnIndex; OSStatus errorStatus; wxDataViewColumn* dataViewColumnPtr; - + 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")); @@ -714,59 +741,58 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( 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->GetEventHandler()->ProcessEvent(dataViewEvent); + dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); // opening the container is allowed if not vetoed: return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed()); } /* block */ - return noErr; 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->GetEventHandler()->ProcessEvent(dataViewEvent); + dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); // opening the container is allowed if not vetoed: return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed()); } /* block */ @@ -774,7 +800,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc( { // 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)))); @@ -782,147 +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 kDataBrowserContainerClosed: - { - // variable definitions: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - if (dataViewCtrlPtr != NULL) // can become NULL when the window is being deleted (wxWidget has already disposed the data before receiving this event + 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->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* if */ - } /* block */ - break; - 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))); - // 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); - } /* block */ - break; - case kDataBrowserItemAdded: - { - // 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_MODEL_ITEM_ADDED,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 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 send the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserItemRemoved: - { - // variable definitions: - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); + dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserContainerOpened: + { + // initialize wxWidget event: + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition - if (dataViewCtrlPtr != NULL) // can become NULL when the window is being deleted (wxWidget has already disposed the data before receiving this event + 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: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED,dataViewCtrlPtr->GetId()); // variable definition - + 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); - } /* if */ - } /* 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 send the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - } /* block */ - break; - case kDataBrowserUserStateChanged: - { - DataBrowserPropertyID propertyID; - - if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID)) + dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + } /* block */ + break; + case kDataBrowserEditStopped: { - DataBrowserSortOrder sortOrder; - DataBrowserTableViewColumnIndex columnIndex; - - if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr)) + // 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: - wxDataViewColumn* columnPtr; - wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast(this->GetPeer())); - - wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data vie wcontrol not set correctly.")); - columnPtr = dataViewCtrlPtr->GetColumn(columnIndex); - // check if the sort order has changed: - if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) || - !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing)) + 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 + + 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)) { - 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); + // 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