]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/databrow.cpp
Use IsOk() instead of Ok()
[wxWidgets.git] / src / mac / carbon / databrow.cpp
index 6b1f83a6f35403d114daec93e207a2e24c451810..a313cb60f88019ffb353cc2166fb3ad4b6dc28f9 100644 (file)
@@ -19,6 +19,7 @@
     #include "wx/app.h"
     #include "wx/toplevel.h"
     #include "wx/font.h"
+    #include "wx/settings.h"
 #endif
 
 #include "wx/dataview.h"
@@ -92,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;
@@ -581,7 +578,6 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse
 
   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."));
@@ -590,7 +586,9 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse
   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):
@@ -615,12 +613,49 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse
   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)
@@ -685,7 +720,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
             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)))
@@ -741,7 +776,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
             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 */
@@ -757,7 +792,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
             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 */
@@ -795,7 +830,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
           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:
@@ -806,7 +841,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
           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 */
@@ -829,7 +864,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
             dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
           } /* if */
          // finally send the equivalent wxWidget event:
-          dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+          dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
         } /* block */
         break;
       case kDataBrowserEditStopped:
@@ -850,7 +885,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
             dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
           } /* if */
          // finally send the equivalent wxWidget event:
-          dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+          dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
         } /* block */
         break;
       case kDataBrowserItemAdded:
@@ -865,7 +900,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
           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:
@@ -880,7 +915,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
           dataViewEvent.SetEventObject(dataViewCtrlPtr);
           dataViewEvent.SetModel      (dataViewCtrlPtr->GetModel());
          // finally send the equivalent wxWidget event:
-          dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+          dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
         } /* block */
         break;
       case kDataBrowserUserStateChanged:
@@ -921,7 +956,7 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
                 dataViewEvent.SetColumn(columnIndex);
                 dataViewEvent.SetDataViewColumn(columnPtr);
                // finally send the equivalent wxWidget event:
-                dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+                dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
               } /* if */
             } /* if */
           } /* if */