/////////////////////////////////////////////////////////////////////////////
// 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$
#include "wx/wxprec.h"
-#if wxUSE_DATAVIEWCTRL
-#if !defined(wxUSE_GENERICDATAVIEWCTRL) || wxUSE_GENERICDATAVIEWCTRL == 0
+#if wxUSE_DATAVIEWCTRL && !defined(wxUSE_GENERICDATAVIEWCTRL)
+
+#include <limits>
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/dataview.h"
#include "wx/utils.h"
-#include "wx/mac/private.h"
#include "wx/mac/carbon/databrow.h"
+#include "wx/mac/private.h"
#include "wx/mac/uma.h"
-#include <limits>
-
-#if defined(__MWERKS__) && wxUSE_UNICODE
-#if __MWERKS__ < 0x4100
- #include <wtime.h>
-#endif
-#endif
-
// ============================================================================
// wxMacDataBrowserTableViewControl
// ============================================================================
if (gDataBrowserTableViewItemNotificationUPP == NULL)
{
gDataBrowserTableViewItemNotificationUPP =
-#if TARGET_API_MAC_OSX
(DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
-#else
- NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
-#endif
}
DataBrowserCallbacks callbacks;
flags |= kDataBrowserSelectOnlyOne;
(void) this->SetSelectionFlags(flags);
} /* if */
+
OptionBits attributes; // variable definition
-
+
if (this->GetAttributes(&attributes) == noErr) // get default settings
{
if ((style & wxDV_VERT_RULES) != 0)
attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers;
(void) this->SetAttributes(attributes);
} /* if */
+
if ((style & wxDV_NO_HEADER) != 0)
this->SetHeaderButtonHeight(0);
} /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
// 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::GetFreeItemID(DataBrowserItemID* id) const
{
ItemCount NoOfItems;
-
-
+
+
verify_noerr(this->GetItemCount(&NoOfItems));
if (NoOfItems == 0)
{
// 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 */
{
DataBrowserItemID* itemIDPtr;
Handle handle(::NewHandle(0));
-
+
size_t NoOfItems;
DataBrowserSortOrder sortOrder;
DataBrowserTableViewColumnIndex columnIndex;
-
+
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(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."));
wxDataViewColumn* dataViewColumnPtr;
wxDataViewCtrl* dataViewCtrlPtr;
-
+
wxDataViewCustomRenderer* dataViewCustomRendererPtr;
wxVariant dataToRender;
-
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(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."));
wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing."));
dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
- dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),columnIndex);
+
+ wxDataViewItem dataitem( reinterpret_cast<void*>(itemID) );
+ dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataitem,columnIndex);
dataViewCustomRendererPtr->SetValue(dataToRender);
// try to determine the content's size (drawable part):
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<int>(rectangle->left),static_cast<int>(rectangle->top),
- static_cast<int>(1+rectangle->right-rectangle->left),static_cast<int>(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<int>(rectangle->left),
+ static_cast<int>(rectangle->top+2),
+ static_cast<int>(1+rectangle->right-rectangle->left),
+ static_cast<int>(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)
{
// variable definitions:
wxDataViewCtrl* dataViewCtrlPtr;
-
+
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
if (dataViewCtrlPtr->IsDeleting())
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"));
if (errorStatus == noErr)
{
// variable definitions and initializations:
- wxMacCFStringHolder modifiedString(stringReference);
+ wxCFStringRef modifiedString(stringReference);
wxVariant modifiedData(modifiedString.AsString());
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
wxVariant variant;
wxDataViewColumn* dataViewColumnPtr;
wxDataViewCtrl* dataViewCtrlPtr;
-
+
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(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."));
{
// variable definitions:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(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<void*>(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 */
{
// variable definitions:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(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<void*>(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 */
{
// variable definition:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(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<void*>(itemID))));
{
// initialize wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
-
+
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserContainerOpened:
{
// initialize wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
-
+
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// add children to the expanded container:
dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
} /* block */
case kDataBrowserEditStarted:
{
// initialize wxWidget event:
- DataBrowserPropertyID propertyID;
+ DataBrowserPropertyID propertyID;
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
-
+
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(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));
+ dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
} /* if */
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserEditStopped:
{
// initialize wxWidget event:
- DataBrowserPropertyID propertyID;
+ DataBrowserPropertyID propertyID;
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
-
+
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
if (this->GetPropertyID(itemData,&propertyID) == noErr)
wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
dataViewEvent.SetColumn(columnIndex);
- dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
+ dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
} /* if */
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserItemAdded:
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserItemRemoved:
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserUserStateChanged:
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 */
{
DataBrowserSortOrder sortOrder;
DataBrowserTableViewColumnIndex columnIndex;
-
+
if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
{
// variable definition and initialization:
dataViewEvent.SetColumn(columnIndex);
dataViewEvent.SetDataViewColumn(columnPtr);
// finally send the equivalent wxWidget event:
- dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+ dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
} /* if */
} /* if */
} /* if */
} /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
-#endif // wxUSE_GENERICDATAVIEWCTRL
-#endif // wxUSE_DATAVIEWCTRL
+#endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL