X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b7dbd50c8989a64a90a8b6079d52b006b4a003c1..e388dc214c74a5ac2d3c4d5f810fcfbd5f7fa01a:/src/mac/carbon/listctrl_mac.cpp diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index 276081e22d..337bbaa8e8 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -30,6 +30,7 @@ #ifndef WX_PRECOMP #include "wx/intl.h" + #include "wx/settings.h" #endif #include "wx/mac/uma.h" @@ -772,6 +773,19 @@ wxListCtrl::~wxListCtrl() delete m_renameTimer; } +/*static*/ +wxVisualAttributes +wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + + attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); + attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); + attr.font.MacCreateFromThemeFont(kThemeViewsFont); + + return attr; +} + // ---------------------------------------------------------------------------- // set/get/change style // ---------------------------------------------------------------------------- @@ -967,10 +981,10 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) { wxFontEncoding enc; if ( m_font.Ok() ) - enc = m_font.GetEncoding(); + enc = GetFont().GetEncoding(); else enc = wxLocale::GetSystemEncoding(); - wxMacCFStringHolder cfTitle; + wxCFStringRef cfTitle; cfTitle.Assign( item.GetText() , enc ); if(columnDesc.titleString) CFRelease(columnDesc.titleString); @@ -1033,31 +1047,37 @@ 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) { for (int column = 0; column < GetColumnCount(); column++) { wxListItem colInfo; - GetColumn(col, colInfo); + GetColumn(column, colInfo); colInfo.SetWidth(width); - SetColumn(col, colInfo); + SetColumn(column, colInfo); - m_dbImpl->SetColumnWidth(col, mywidth); + 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; } @@ -2297,9 +2317,26 @@ void wxListCtrl::RefreshItem(long item) return; } - wxRect rect; - GetItemRect(item, rect); - RefreshRect(rect); + if (m_dbImpl) + { + DataBrowserItemID id; + + if ( !IsVirtual() ) + { + wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(item); + id = (DataBrowserItemID) thisItem; + } + else + id = item+1; + + m_dbImpl->wxMacDataBrowserControl::UpdateItems + ( + kDataBrowserNoItem, + 1, &id, + kDataBrowserItemNoProperty, // preSortProperty + kDataBrowserNoItem // update all columns + ); + } } void wxListCtrl::RefreshItems(long itemFrom, long itemTo) @@ -2310,14 +2347,35 @@ void wxListCtrl::RefreshItems(long itemFrom, long itemTo) return; } - wxRect rect1, rect2; - GetItemRect(itemFrom, rect1); - GetItemRect(itemTo, rect2); + if (m_dbImpl) + { + const long count = itemTo - itemFrom + 1; + DataBrowserItemID *ids = new DataBrowserItemID[count]; + + if ( !IsVirtual() ) + { + for ( long i = 0; i < count; i++ ) + { + wxMacDataItem* thisItem = m_dbImpl->GetItemFromLine(itemFrom+i); + ids[i] = (DataBrowserItemID) thisItem; + } + } + else + { + for ( long i = 0; i < count; i++ ) + ids[i] = itemFrom+i+1; + } - wxRect rect = rect1; - rect.height = rect2.GetBottom() - rect1.GetTop(); + m_dbImpl->wxMacDataBrowserControl::UpdateItems + ( + kDataBrowserNoItem, + count, ids, + kDataBrowserItemNoProperty, // preSortProperty + kDataBrowserNoItem // update all columns + ); - RefreshRect(rect); + delete[] ids; + } } void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget ) @@ -2662,12 +2720,10 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (bgColor == wxNullColour) bgColor = listBgColor; - wxFont listFont = list->GetFont(); - if (font == wxNullFont) - font = listFont; + if (!font.Ok()) + font = list->GetFont(); - wxMacCFStringHolder cfString; - cfString.Assign( text, wxLocale::GetSystemEncoding() ); + wxCFStringRef cfString( text, wxLocale::GetSystemEncoding() ); Rect enclosingRect; CGRect enclosingCGRect, iconCGRect, textCGRect; @@ -2718,9 +2774,9 @@ void wxMacDataBrowserListCtrlControl::DrawItem( } CGContextSaveGState(context); - CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX, - (float)backgroundColor.green / (float)USHRT_MAX, - (float)backgroundColor.blue / (float)USHRT_MAX, 1.0); + CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX, + (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX, + (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); CGContextFillRect(context, enclosingCGRect); CGContextRestoreGState(context); @@ -2738,9 +2794,9 @@ void wxMacDataBrowserListCtrlControl::DrawItem( bgColor.GetRGBColor(&backgroundColor); CGContextSaveGState(context); - CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX, - (float)backgroundColor.green / (float)USHRT_MAX, - (float)backgroundColor.blue / (float)USHRT_MAX, 1.0); + CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX, + (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX, + (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); CGContextFillRect(context, enclosingCGRect); CGContextRestoreGState(context); @@ -2791,8 +2847,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (font.Ok()) { - if (font.GetFamily() != wxFONTFAMILY_DEFAULT) - info.fontID = font.MacGetThemeFontID(); + info.fontID = font.MacGetThemeFontID(); ::TextSize( (short)(font.MacGetFontSize()) ) ; ::TextFace( font.MacGetFontStyle() ) ; @@ -2823,9 +2878,9 @@ void wxMacDataBrowserListCtrlControl::DrawItem( info.truncationMaxLines = 1; CGContextSaveGState(context); - CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX, - (float)labelColor.green / (float)USHRT_MAX, - (float)labelColor.blue / (float)USHRT_MAX, 1.0); + CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX, + (CGFloat)labelColor.green / (CGFloat)USHRT_MAX, + (CGFloat)labelColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal); @@ -2848,7 +2903,7 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI OSStatus err = errDataBrowserPropertyNotSupported; wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl ); - wxMacListCtrlItem* lcItem; + wxMacListCtrlItem* lcItem = NULL; if (listColumn >= 0) { @@ -2888,10 +2943,8 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI default : if ( property >= kMinColumnId ) { - wxMacCFStringHolder cfStr; - if (!text.IsEmpty()){ - cfStr.Assign( text, wxLocale::GetSystemEncoding() ); + wxCFStringRef cfStr( text, wxLocale::GetSystemEncoding() ); err = ::SetDataBrowserItemDataText( itemData, cfStr ); err = noErr; } @@ -2926,7 +2979,7 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI // can then deal with the veto CFStringRef sr ; verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ; - wxMacCFStringHolder cfStr(sr) ;; + wxCFStringRef cfStr(sr) ;; if (m_isVirtual) list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ; else @@ -3282,5 +3335,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