///////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/dataview.mm
// Purpose: wxDataView
-// Author:
+// Author:
// Modified by:
// Created: 2009-01-31
// RCS-ID: $Id: dataview.mm$
-// Copyright:
+// Copyright:
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
NSTableColumn* tableColumn; // not owned by the class
wxDataViewCustomRenderer* customRenderer; // not owned by the class
-
+
wxPointerObject* item; // not owned by the class
}
-(id) copyWithZone:(NSZone*)zone
{
wxCustomRendererObject* copy;
-
-
+
+
copy = [[[self class] allocWithZone:zone] init];
copy->customRenderer = customRenderer;
copy->item = item;
static NSInteger CompareItems(id item1, id item2, void* context)
{
NSArray* const sortDescriptors = (NSArray*) context;
-
+
NSUInteger const noOfDescriptors = [sortDescriptors count];
NSInteger result(NSOrderedAscending);
wxSortDescriptorObject* const sortDescriptor = (wxSortDescriptorObject*)[sortDescriptors objectAtIndex:i];
int wxComparisonResult;
-
+
wxComparisonResult = [sortDescriptor modelPtr]->Compare(wxDataViewItem([((wxPointerObject*) item1) pointer]),
wxDataViewItem([((wxPointerObject*) item2) pointer]),
[sortDescriptor columnPtr]->GetModelColumn(),
{
self = [super init];
if (self != nil)
- self.pointer = NULL;
+ self->pointer = NULL;
return self;
}
{
self = [super init];
if (self != nil)
- self.pointer = initPointer;
+ self->pointer = initPointer;
return self;
}
-(id) copyWithZone:(NSZone*)zone
{
wxSortDescriptorObject* copy;
-
-
+
+
copy = [super copyWithZone:zone];
copy->columnPtr = columnPtr;
copy->modelPtr = modelPtr;
[children release];
[items release];
-
+
[super dealloc];
}
NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]);
-
+
if (bestType != nil)
{
wxDataViewCtrl* const dataViewCtrlPtr(implementation->GetDataViewCtrl());
{
NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]);
NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]);
-
+
indexDraggedItem = 0;
while (indexDraggedItem < noOfDraggedItems)
{
CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation
wxDataObjectComposite* dataObjects (new wxDataObjectComposite());
wxTextDataObject* textDataObject(new wxTextDataObject());
-
+
osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32);
if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData)))
dataObjects->Add(textDataObject);
NSArray* newDescriptors;
NSMutableArray* wxSortDescriptors;
-
+
NSUInteger noOfDescriptors;
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]);
-
+
if (bestType != nil)
{
wxDataViewCtrl* const dataViewCtrlPtr(implementation->GetDataViewCtrl());
{
NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]);
NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]);
-
+
indexDraggedItem = 0;
while (indexDraggedItem < noOfDraggedItems)
{
CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation
wxDataObjectComposite* dataObjects (new wxDataObjectComposite());
wxTextDataObject* textDataObject(new wxTextDataObject());
-
+
osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32);
if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData)))
dataObjects->Add(textDataObject);
// string representation exists
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewItemArray dataViewItems;
size_t const dataBufferSize = sizeof(wxDataFormatId)+dataSize;
// variable definitions (used in all case statements):
wxMemoryBuffer dataBuffer(dataBufferSize);
-
+
dataBuffer.AppendData(&idDataFormat,sizeof(wxDataFormatId));
switch (idDataFormat)
{
if (dataStringAvailable)
{
wxCFStringRef osxString(dataString);
-
+
[pasteboard declareTypes:[NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil] owner:nil];
[pasteboard setPropertyList:dataArray forType:DataViewPboardType];
[pasteboard setString:osxString.AsNSString() forType:NSStringPboardType];
-(id) copyWithZone:(NSZone*)zone
{
wxImageTextCell* cell;
-
-
+
+
cell = (wxImageTextCell*) [super copyWithZone:zone];
cell->image = [image retain];
cell->imageSize = imageSize;
// to draw an image correctly the coordinate system has to be transformed to a bottom-top coordinate system, otherwise the image's
// content is flipped:
NSAffineTransform* coordinateTransform([NSAffineTransform transform]);
-
+
if ([controlView isFlipped])
{
[coordinateTransform scaleXBy: 1.0 yBy:-1.0]; // first the coordinate system is brought back to bottom-top orientation
// if the image was not hit let's try the text part:
if (textFrame.size.width > [self cellTextSize].width) // for unknown reasons the alignment of the text cell is ignored; therefore change the size so that
textFrame.size.width = [self cellTextSize].width; // alignment does not influence the visualization anymore
- return [super hitTestForEvent:event inRect:textFrame ofView:controlView];
+ return [super hitTestForEvent:event inRect:textFrame ofView:controlView];
}
#endif
if (imageFrame.size.height > imageSize.height)
imageFrame.size.height = imageSize.height;
imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height));
-
+
return imageFrame;
}
// has full control if a context menu should be shown or not
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId());
wxDataViewItemArray selectedItems;
wxDataViewColumn* const dataViewColumnPtr(reinterpret_cast<wxDataViewColumn*>([[tableColumn identifier] pointer]));
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,dataViewCtrlPtr->GetId());
// remove the sort order from the previously sorted column table (it can also be that
// no sorted column table exists):
UInt32 const noOfColumns = [outlineView numberOfColumns];
-
+
for (UInt32 i=0; i<noOfColumns; ++i)
[[[outlineView tableColumns] objectAtIndex:i] setSortDescriptorPrototype:nil];
// make column table sortable:
NSArray* sortDescriptors;
NSSortDescriptor* sortDescriptor;
-
+
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[NSString stringWithFormat:@"%d",[outlineView columnWithIdentifier:[tableColumn identifier]]]
ascending:YES];
sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
-(BOOL) outlineView:(NSOutlineView*)outlineView shouldCollapseItem:(id)item
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
-(BOOL) outlineView:(NSOutlineView*)outlineView shouldExpandItem:(id)item
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
wxDataViewColumn* const dataViewColumnPtr(reinterpret_cast<wxDataViewColumn*>([[[[self tableColumns] objectAtIndex:newColumnPosition] identifier] pointer]));
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED,dataViewCtrlPtr->GetId());
-(void) outlineViewItemDidCollapse:(NSNotification*)notification
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId());
-(void) outlineViewItemDidExpand:(NSNotification*)notification
{
wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl();
-
+
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId());
{
// initialize scrollview (the outline view is part of a scrollview):
NSScrollView* scrollview = (NSScrollView*) this->GetWXWidget(); // definition for abbreviational purposes
-
+
[scrollview setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[scrollview setBorderType:NSNoBorder];
int wxCocoaDataViewControl::GetSelections(wxDataViewItemArray& sel) const
{
NSIndexSet* selectedRowIndexes([this->m_OutlineView selectedRowIndexes]);
-
+
NSUInteger indexRow;
-
+
sel.Empty();
sel.Alloc([selectedRowIndexes count]);
indexRow = [selectedRowIndexes firstIndex];
int indexColumn;
int indexRow;
-
+
indexColumn = [this->m_OutlineView columnAtPoint:nativePoint];
indexRow = [this->m_OutlineView rowAtPoint: nativePoint];
if ((indexColumn >= 0) && (indexRow >= 0))
size_t indexFormat;
wxDataFormat* formats;
-
+
// get all formats and check afterwards if the formats are compatible; if they are compatible the preferred format is returned otherwise
// wxDF_INVALID is returned;
// currently compatible types (ordered by priority are):
{
wxDataFormatId dataFormatID;
-
+
[dataObject getBytes:&dataFormatID length:sizeof(wxDataFormatId)];
switch (dataFormatID)
{
case wxDF_UNICODETEXT:
{
wxTextDataObject* textDataObject(new wxTextDataObject());
-
+
if (textDataObject->SetData(wxDataFormat(dataFormatID),[dataObject length]-sizeof(wxDataFormatId),reinterpret_cast<char const*>([dataObject bytes])+sizeof(wxDataFormatId)))
{
wxDataObjectComposite* dataObjectComposite(new wxDataObjectComposite());
:wxDataViewRenderer(varianttype,mode,align)
{
NSTextFieldCell* cell;
-
-
+
+
cell = [[NSTextFieldCell alloc] init];
[cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)];
[cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
:wxDataViewRenderer(varianttype,mode,align)
{
NSImageCell* cell;
-
-
+
+
cell = [[NSImageCell alloc] init];
this->SetNativeData(new wxDataViewRendererNativeData(cell));
[cell release];
:wxDataViewRenderer(wxT("string"),mode,alignment), m_Choices(choices)
{
NSPopUpButtonCell* cell;
-
-
+
+
cell = [[NSPopUpButtonCell alloc] init];
[cell setControlSize:NSMiniControlSize];
[cell setFont:[[NSFont fontWithName:[[cell font] fontName] size:[NSFont systemFontSizeForControlSize:NSMiniControlSize]] autorelease]];
NSDateFormatter* dateFormatter;
-
+
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
:wxDataViewRenderer(varianttype,mode)
{
wxImageTextCell* cell;
-
-
+
+
cell = [[wxImageTextCell alloc] init];
[cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)];
this->SetNativeData(new wxDataViewRendererNativeData(cell));
if (this->GetValue().GetType() == this->GetVariantType())
{
wxDataViewIconText iconText;
-
+
wxImageTextCell* cell;
cell = (wxImageTextCell*) this->GetNativeData()->GetItemCell();
:wxDataViewRenderer(varianttype,mode)
{
NSButtonCell* cell;
-
-
+
+
cell = [[NSButtonCell alloc] init];
[cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)];
[cell setButtonType:NSSwitchButton];
:wxDataViewRenderer(varianttype,mode,align)
{
NSLevelIndicatorCell* cell;
-
-
+
+
cell = [[NSLevelIndicatorCell alloc] initWithLevelIndicatorStyle:NSContinuousCapacityLevelIndicatorStyle];
[cell setMinValue:0];
[cell setMaxValue:100];
NSArray* sortDescriptors;
NSSortDescriptor* sortDescriptor;
NSTableColumn* tableColumn;
-
+
tableColumn = this->m_NativeDataPtr->GetNativeColumnPtr();
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[[tableColumn sortDescriptorPrototype] key] ascending:m_ascending];
sortDescriptors = [NSArray arrayWithObject:sortDescriptor];