]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/dataview.cpp
Use IsOk() instead of Ok()
[wxWidgets.git] / src / mac / carbon / dataview.cpp
index b21daeba48e383f96134a01938c31b75d9d9b5b5..9b4a88fff9040c9c3637753e8faab69c082bced9 100644 (file)
 #include "wx/mac/carbon/databrow.h"
 
 #ifndef WX_PRECOMP
-  #include "wx/timer.h"
+    #include "wx/timer.h"
+    #include "wx/settings.h"
+    #include "wx/dcclient.h"
+    #include "wx/icon.h"
 #endif
 
-#include "wx/icon.h"
 #include "wx/renderer.h"
 
 //-----------------------------------------------------------------------------
@@ -82,7 +84,7 @@ static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
         DataViewEvent.SetColumn(columnIndex);
         DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex));
        // finally sent the equivalent wxWidget event:
-        DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent);
+        DataViewCtrlPtr->HandleWindowEvent(DataViewEvent);
         return ::CallNextEventHandler(handler,EventReference);
       } /* if */
       else
@@ -111,7 +113,7 @@ static DataBrowserItemID* CreateDataBrowserItemIDArray(size_t& noOfEntries, wxDa
   return itemIDs;
 } /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
 
-static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDescription, wxDataViewColumn const* columnPtr, DataBrowserPropertyID columnPropertyID, wxMacCFStringHolder const& title)
+static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDescription, wxDataViewColumn const* columnPtr, DataBrowserPropertyID columnPropertyID, wxCFStringRef const& title)
 {
  // set properties for the column:
   columnDescription.propertyDesc.propertyID    = columnPropertyID;
@@ -167,10 +169,10 @@ static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDes
   columnDescription.headerBtnDesc.btnFontStyle.style = normal;
   columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
   if (columnPtr->GetBitmap().Ok())
-    columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetBitmapData()->GetIconRef();
+    columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
  // done:
   return true;
-} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
+} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxCFStringRef const&) */
 
 //-----------------------------------------------------------------------------
 // local function pointers
@@ -236,7 +238,7 @@ public:
       dataViewEvent.SetEventObject(dataViewCtrlPtr);
       dataViewEvent.SetItem(item);
      // sent the equivalent wxWidget event:
-      dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+      dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
      // done
       return true;
     } /* if */
@@ -268,7 +270,7 @@ public:
       for (size_t i=0; i<noOfEntries; ++i)
       {
         dataViewEvent.SetItem(reinterpret_cast<void*>(itemIDs[i]));
-        dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+        dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
       } /* for */
     } /* if */
    // release allocated array space:
@@ -355,7 +357,7 @@ public:
       dataViewEvent.SetColumn(col);
       dataViewEvent.SetItem(item);
      // send the equivalent wxWidget event:
-      dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
+      dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
      // done
       return true;
     } /* if */
@@ -365,7 +367,12 @@ public:
 
   virtual bool Cleared(void)
   {
-    return (this->m_dataViewControlPtr->RemoveItems() == noErr);
+    bool noFailureFlag = (this->m_dataViewControlPtr->RemoveItems() == noErr);
+    wxDataViewItem item;
+    wxDataViewItemArray array;
+    GetOwner()->GetChildren( item, array );
+    ItemsAdded( item, array );
+    return noFailureFlag;
   } /* Cleared(void) */
 
   virtual void Resort(void)
@@ -443,7 +450,7 @@ wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
 void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
 {
     wxDataViewCtrl *view = GetOwner()->GetOwner();
-    wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : view->GetForegroundColour();
+    wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? *wxWHITE : view->GetForegroundColour();
     dc->SetTextForeground(col);
     dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
 }
@@ -454,7 +461,7 @@ wxDC* wxDataViewCustomRenderer::GetDC(void)
   {
     if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
       return NULL;
-    this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
+    this->m_DCPtr = new wxWindowDC(this->GetOwner()->GetOwner());
   } /* if */
   return this->m_DCPtr;
 } /* wxDataViewCustomRenderer::GetDC(void) */
@@ -491,7 +498,7 @@ bool wxDataViewTextRenderer::Render(void)
   if (this->GetValue().GetType() == this->GetVariantType())
   {
    // variable definition:
-    wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+    wxCFStringRef cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
 
     return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
   } /* if */
@@ -517,17 +524,6 @@ wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const& variantty
     
 IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
 
-// ---------------------------------------------------------
-// wxDataViewTextRendererAttr
-// ---------------------------------------------------------
-
-wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const& varianttype, wxDataViewCellMode mode, int align)
-                       :wxDataViewTextRenderer(varianttype,mode,align)
-{
-}
-
-IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
-
 // ---------------------------------------------------------
 // wxDataViewBitmapRenderer
 // ---------------------------------------------------------
@@ -545,7 +541,7 @@ bool wxDataViewBitmapRenderer::Render(void)
     
     bitmap << this->GetValue();
     if (bitmap.Ok())
-      return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
+      return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetIconRef()) == noErr);
     else
       return true;
   } /* if */
@@ -579,10 +575,15 @@ bool wxDataViewIconTextRenderer::Render(void)
     iconText << this->GetValue();
 
    // variable definition:
-    wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+    wxCFStringRef cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+
+    if (iconText.GetIcon().IsOk())
+    {
+       if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) != noErr)
+          return false;
+    }
     
-    return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) == noErr) &&
-            (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr));
+    return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
   } /* if */
   else
     return false;
@@ -743,7 +744,7 @@ void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
 
       wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
       if (this->GetBitmap().Ok())
-        headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
+        headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetIconRef();
       else
         headerDescription.btnContentInfo.u.iconRef = NULL;
       wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
@@ -881,7 +882,7 @@ void wxDataViewColumn::SetTitle(wxString const& title)
     {
      // variable definition and initialization:
       DataBrowserListViewHeaderDesc headerDescription;
-      wxMacCFStringHolder           cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+      wxCFStringRef           cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
       
       wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
       headerDescription.titleString = cfTitle;
@@ -937,6 +938,8 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
 
   InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
 
+  ::SetDataBrowserTableViewHiliteStyle( this->m_peer->GetControlRef(), kDataBrowserTableViewFillHilite );
+
   return true;
 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
 
@@ -958,7 +961,7 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* columnPtr)
 
   wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
 
-  wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding());
+  wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding());
 
 
  // first, some error checking:
@@ -1074,7 +1077,7 @@ bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr)
 
   wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
 
-  wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding());
+  wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding());
 
 
  // first, some error checking: