]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't show anything in the cells which should be empty in Cocoa wxDVC.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Oct 2009 01:03:36 +0000 (01:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Oct 2009 01:03:36 +0000 (01:03 +0000)
Implement a custom NSTableColumn-derived class to return nil for the cells
which shouldn't show anything at all because they are part of a container row.

This finally fixes the totally wrong display of the first page of the dataview
sample under OS X.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/dataview.h
src/osx/cocoa/dataview.mm

index ded2b5f9b77bd973ba9133dfd7981e983e3e8e52..e31a75229649cd9c6d3e2133fa60474209699a05 100644 (file)
@@ -498,6 +498,9 @@ public:
     wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects);
     wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const;
 
+    // Cocoa-specific helpers
+    id GetItemAtRow(int row) const;
+
 private:
     wxCocoaOutlineDataSource* m_DataSource;
 
index 8140fd610149460d29a3a437dce8180b61e8f403..de70d511ca13d0f466f6395006a698a4657552b7 100644 (file)
 // ============================================================================
 // Classes used locally in dataview.mm
 // ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxCustomRendererObject
+// ----------------------------------------------------------------------------
+
 @interface wxCustomRendererObject : NSObject <NSCopying>
 {
 @public
 }
 @end
 
+// ----------------------------------------------------------------------------
+// wxDVCNSTableColumn: exists only to override NSTableColumn:dataCellForRow:
+// ----------------------------------------------------------------------------
+
+@interface wxDVCNSTableColumn : NSTableColumn
+{
+}
+
+    -(id) dataCellForRow:(NSInteger)row;
+@end
+
+@implementation wxDVCNSTableColumn
+
+-(id) dataCellForRow:(NSInteger)row
+{
+    // what we want to do here is to simply return nil for the cells which
+    // shouldn't show anything as otherwise we would show e.g. empty combo box
+    // or progress cells in the columns using the corresponding types even for
+    // the container rows which is wrong
+
+    // half of the problem is just finding the objects we need from the column
+    // pointer which is itself stashed inside wxPointerObject which we use as
+    // our identifier
+    const wxDataViewColumn * const
+        dvCol = static_cast<wxDataViewColumn *>(
+                    [(wxPointerObject *)[self identifier] pointer]
+                );
+
+    const wxDataViewCtrl * const dvc = dvCol->GetOwner();
+    const wxCocoaDataViewControl * const
+        peer = static_cast<wxCocoaDataViewControl *>(dvc->GetPeer());
+
+
+    // once we do have everything, simply ask NSOutlineView for the item...
+    const id item = peer->GetItemAtRow(row);
+    if ( item )
+    {
+        // ... and if it succeeded, ask the model whether it has any value
+        wxDataViewItem dvItem([((wxPointerObject*) item) pointer]);
+
+        if ( !dvc->GetModel()->HasValue(dvItem, dvCol->GetModelColumn()) )
+            return nil;
+    }
+
+    return [super dataCellForRow:row];
+}
+
+@end
+
 // ============================================================================
 // local helpers
 // ============================================================================
@@ -196,8 +250,8 @@ NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column)
 
     wxCHECK_MSG( renderer, NULL, "column should have a renderer" );
 
-    NSTableColumn * const nativeColumn(
-        [[NSTableColumn alloc] initWithIdentifier:
+    wxDVCNSTableColumn * const nativeColumn(
+        [[wxDVCNSTableColumn alloc] initWithIdentifier:
             [[[wxPointerObject alloc] initWithPointer:
                 const_cast<wxDataViewColumn*>(column)]
              autorelease]]
@@ -558,16 +612,20 @@ outlineView:(NSOutlineView*)outlineView
     objectValueForTableColumn:(NSTableColumn*)tableColumn
     byItem:(id)item
 {
+    wxCHECK_MSG( model, nil, "Valid model in data source does not exist." );
+
     wxDataViewColumn* col(static_cast<wxDataViewColumn*>([[tableColumn identifier] pointer]));
+    const unsigned colIdx = col->GetModelColumn();
 
     wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]);
 
-    wxVariant value;
-
+    if ( model->HasValue(dataViewItem, colIdx) )
+    {
+        wxVariant value;
+        model->GetValue(value,dataViewItem, colIdx);
+        col->GetRenderer()->SetValue(value);
+    }
 
-    wxCHECK_MSG( model, 0, "Valid model in data source does not exist." );
-    model->GetValue(value,dataViewItem,col->GetModelColumn());
-    col->GetRenderer()->SetValue(value);
     return nil;
 }
 
@@ -1036,6 +1094,13 @@ outlineView:(NSOutlineView*)outlineView
 {
     wxCustomRendererObject * const
         obj = static_cast<wxCustomRendererObject *>([self objectValue]);
+    if ( !obj )
+    {
+        // this may happen for the custom cells in container rows: they don't
+        // have any values
+        return;
+    }
+
     wxDataViewCustomRenderer * const renderer = obj->customRenderer;
 
     // draw its own background:
@@ -1542,12 +1607,16 @@ item:(id)item
                     [[tableColumn identifier] pointer]
                     )
              );
+    const unsigned colIdx = dvCol->GetModelColumn();
+
+    wxDataViewItem dvItem([static_cast<wxPointerObject *>(item) pointer]);
+
+    if ( !model->HasValue(dvItem, colIdx) )
+        return;
 
     wxDataViewRenderer * const renderer = dvCol->GetRenderer();
     wxDataViewRendererNativeData * const data = renderer->GetNativeData();
 
-    wxDataViewItem dvItem([static_cast<wxPointerObject *>(item) pointer]);
-
     // set the font and text colour to use: we need to do it if we had ever
     // changed them before, even if this item itself doesn't have any special
     // attributes as otherwise it would reuse the attributes from the previous
@@ -1556,7 +1625,7 @@ item:(id)item
     NSColor *colText = NULL;
 
     wxDataViewItemAttr attr;
-    if ( model && model->GetAttr(dvItem, dvCol->GetModelColumn(), attr) )
+    if ( model && model->GetAttr(dvItem, colIdx, attr) )
     {
         if ( attr.HasFont() )
         {
@@ -2178,6 +2247,11 @@ wxDataObjectComposite* wxCocoaDataViewControl::GetDnDDataObjects(NSData* dataObj
     }
 }
 
+id wxCocoaDataViewControl::GetItemAtRow(int row) const
+{
+    return [m_OutlineView itemAtRow:row];
+}
+
 // ----------------------------------------------------------------------------
 // wxDataViewRendererNativeData
 // ----------------------------------------------------------------------------