]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/listctrl_mac.cpp
fixing 64-32 bit conversion warnings, no brush must be set for color bitmaps, only...
[wxWidgets.git] / src / mac / carbon / listctrl_mac.cpp
index 21b7bd0b8475d5e5268a07c39ad623636b2cb94c..13a20ac2200f4318dde07d23c6fc9c052949c3d8 100644 (file)
@@ -771,6 +771,8 @@ wxListCtrl::~wxListCtrl()
         delete m_imageListState;
 
     delete m_renameTimer;
+    
+    WX_CLEAR_LIST(wxColumnList, m_colsInfo);
 }
 
 /*static*/
@@ -1047,9 +1049,10 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
 
     if (m_dbImpl)
     {
-        int mywidth = width;
-        if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER)
-            mywidth = 150;
+        if ( width == wxLIST_AUTOSIZE_USEHEADER )
+        {
+            width = 150; // FIXME
+        }
 
         if (col == -1)
         {
@@ -1061,17 +1064,22 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
                 colInfo.SetWidth(width);
                 SetColumn(column, colInfo);
 
+                const int mywidth = (width == wxLIST_AUTOSIZE)
+                                    ? CalcColumnAutoWidth(column) : width;
                 m_dbImpl->SetColumnWidth(column, mywidth);
             }
         }
         else
         {
+            if ( width == wxLIST_AUTOSIZE )
+                width = CalcColumnAutoWidth(col);
+
             wxListItem colInfo;
             GetColumn(col, colInfo);
 
             colInfo.SetWidth(width);
             SetColumn(col, colInfo);
-            m_dbImpl->SetColumnWidth(col, mywidth);
+            m_dbImpl->SetColumnWidth(col, width);
         }
         return true;
     }
@@ -2412,6 +2420,7 @@ void wxListCtrl::SetFocus()
 
 wxMacListCtrlItem::~wxMacListCtrlItem()
 {
+    WX_CLEAR_HASH_MAP( wxListItemList, m_rowItems );
 }
 
 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner ,
@@ -2991,18 +3000,27 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI
 
 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
     DataBrowserItemNotification message,
-    DataBrowserItemDataRef WXUNUSED(itemData) )
+    DataBrowserItemDataRef itemData )
 {
+    wxMacListCtrlItem *item = NULL;
+    if ( !m_isVirtual )
+    {
+        item = (wxMacListCtrlItem *) itemID;
+    }
+    
     // we want to depend on as little as possible to make sure tear-down of controls is safe
-    if ( message == kDataBrowserItemRemoved)
+    if ( message == kDataBrowserItemRemoved )
     {
-        // make sure MacDelete does the proper teardown.
+        if ( item )
+            item->Notification(this, message, itemData);
         return;
     }
     else if ( message == kDataBrowserItemAdded )
     {
         // we don't issue events on adding, the item is not really stored in the list yet, so we
         // avoid asserts by getting out now
+        if ( item )
+            item->Notification(this, message, itemData);
         return  ;
     }
 
@@ -3329,5 +3347,36 @@ void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item )
     }
 }
 
+int wxListCtrl::CalcColumnAutoWidth(int col) const
+{
+    int width = 0;
+
+    for ( int i = 0; i < GetItemCount(); i++ )
+    {
+        wxListItem info;
+        info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE);
+        info.SetId(i);
+        info.SetColumn(col);
+        GetItem(info);
+
+        const wxFont font = info.GetFont();
+
+        int w = 0;
+        if ( font.IsOk() )
+            GetTextExtent(info.GetText(), &w, NULL, NULL, NULL, &font);
+        else
+            GetTextExtent(info.GetText(), &w, NULL);
+
+        w += 2 * kItemPadding;
+
+        if ( info.GetImage() != -1 )
+            w += kIconWidth;
+
+        width = wxMax(width, w);
+    }
+
+    return width;
+}
+
 #endif // wxUSE_LISTCTRL