// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef wxUSE_GENERICDATAVIEWCTRL
+#include "wx/wxprec.h"
-#include <limits>
+#if wxUSE_DATAVIEWCTRL
+#ifndef wxUSE_GENERICDATAVIEWCTRL
-#include "wx/wxprec.h"
#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/dataview.h"
-#include "wx/utils.h"
-
#include "wx/mac/carbon/databrow.h"
#include "wx/mac/private.h"
#include "wx/mac/uma.h"
+#include <limits>
+
// ============================================================================
// Variables used globally in databrow.cpp
// ============================================================================
{
DataBrowserSortOrder sortOrder;
- DataBrowserTableViewColumnIndex columnIndex;
+ DataBrowserTableViewColumnIndex modelColumnIndex;
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
if (sortProperty >= kMinPropertyID)
{
- wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index."));
+ // variable definition and initialization:
+ wxDataViewColumn* ColumnPtr(dataViewCtrlPtr->GetColumnPtr(sortProperty));
+
+ wxCHECK_MSG(ColumnPtr != NULL,false,_("Could not determine column index."));
+ modelColumnIndex = ColumnPtr->GetModelColumn();
} /* if */
else
- columnIndex = 0;
+ modelColumnIndex = 0;
this->GetSortOrder(&sortOrder);
return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID)),
- columnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
+ modelColumnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* WXUNUSED(selection))
else
{
// variable definitions:
- DataBrowserTableViewColumnIndex columnIndex;
- OSStatus errorStatus;
- wxDataViewColumn* dataViewColumnPtr;
+ 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"));
- dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
+ dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
+
+ wxDataViewItem dvItem(reinterpret_cast<void*>(itemID));
+ unsigned int col = dataViewColumnPtr->GetModelColumn();
+
switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
{
case kDataBrowserCheckboxType:
// variable definition and initialization:
wxVariant modifiedData(true);
- return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
+ if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
+ dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
+ return noErr;
+ else
+ return errDataBrowserInvalidPropertyData;
} /* if */
else if (buttonValue == kThemeButtonOff)
{
// variable definition and initialization:
wxVariant modifiedData(false);
- return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
+ if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
+ dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
+ return noErr;
+ else
+ return errDataBrowserInvalidPropertyData;
} /* if */
else
return errDataBrowserInvalidPropertyData;
wxMacCFStringHolder modifiedString(stringReference);
#endif
wxVariant modifiedData(modifiedString.AsString());
-
- if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
- return noErr;
- else
- return errDataBrowserNotConfigured;
+
+ if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData, dvItem, col) &&
+ dataViewCtrlPtr->GetModel()->ValueChanged(dvItem, col))
+ return noErr;
+ else
+ return errDataBrowserInvalidPropertyData;
} /* if */
else
return errorStatus;
void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
{
+ DataBrowserTableViewColumnIndex columnIndex;
+
wxDataViewColumn* dataViewColumnPtr;
wxDataViewCtrl* dataViewCtrlPtr;
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(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<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
dataViewCustomRendererPtr->SetValue(dataToRender);
+ wxDataViewItem dataitem( reinterpret_cast<void*>(itemID) );
+ dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataitem,columnIndex);
+ dataViewCustomRendererPtr->SetValue(dataToRender);
+
// try to determine the content's size (drawable part):
Rect content;
RgnHandle rgn(NewRgn());
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) */
Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit)
} /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
#endif // wxUSE_GENERICDATAVIEWCTRL
+#endif // wxUSE_DATAVIEWCTRL