+ verify_noerr( SetHasScrollBars( (style & wxHSCROLL) != 0 , true ) );
+}
+
+pascal Boolean wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
+ ControlRef browser,
+ DataBrowserItemID itemID,
+ DataBrowserPropertyID property,
+ CFStringRef theString,
+ Rect *maxEditTextRect,
+ Boolean *shrinkToFit)
+{
+ Boolean result = false;
+ wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl);
+ if ( ctl != 0 )
+ {
+ result = ctl->ConfirmEditText(itemID, property, theString, maxEditTextRect, shrinkToFit);
+ theString = CFSTR("Hello!");
+ }
+ return result;
+}
+
+bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
+ DataBrowserItemID itemID,
+ DataBrowserPropertyID property,
+ CFStringRef theString,
+ Rect *maxEditTextRect,
+ Boolean *shrinkToFit)
+{
+ return false;
+}
+
+pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
+ ControlRef browser,
+ DataBrowserItemID itemID,
+ DataBrowserPropertyID property,
+ DataBrowserItemState itemState,
+ const Rect *itemRect,
+ SInt16 gdDepth,
+ Boolean colorDevice)
+{
+ wxMacDataBrowserListCtrlControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserListCtrlControl);
+ if ( ctl != 0 )
+ {
+ ctl->DrawItem(itemID, property, itemState, itemRect, gdDepth, colorDevice);
+ }
+}
+
+// routines needed for DrawItem
+enum
+{
+ kIconWidth = 16,
+ kIconHeight = 16,
+ kTextBoxHeight = 14,
+ kIconTextSpacingV = 2,
+ kItemPadding = 4,
+ kContentHeight = kIconHeight + kTextBoxHeight + kIconTextSpacingV
+};
+
+static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false)
+{
+ float textBottom;
+ float iconH, iconW = 0;
+ float padding = kItemPadding;
+ if (hasIcon)
+ {
+ iconH = kIconHeight;
+ iconW = kIconWidth;
+ padding = padding*2;
+ }
+
+ textBottom = inItemRect.origin.y;
+
+ *outIconRect = CGRectMake(inItemRect.origin.x + kItemPadding,
+ textBottom + kIconTextSpacingV, kIconWidth,
+ kIconHeight);
+
+ *outTextRect = CGRectMake(inItemRect.origin.x + padding + iconW,
+ textBottom + kIconTextSpacingV, inItemRect.size.width - padding - iconW,
+ inItemRect.size.height - kIconTextSpacingV);
+}
+
+void wxMacDataBrowserListCtrlControl::DrawItem(
+ DataBrowserItemID itemID,
+ DataBrowserPropertyID property,
+ DataBrowserItemState itemState,
+ const Rect *itemRect,
+ SInt16 gdDepth,
+ Boolean colorDevice)
+{
+ wxString text;
+ wxFont font = wxNullFont;
+ int imgIndex = -1;
+ short listColumn = property - kMinColumnId;
+
+ wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
+ wxMacListCtrlItem* lcItem;
+ wxColour color = *wxBLACK;
+ wxColour bgColor = wxNullColour;
+
+ if (listColumn >= 0)
+ {
+ if (!m_isVirtual)
+ {
+ lcItem = (wxMacListCtrlItem*) itemID;
+ if (lcItem->HasColumnInfo(listColumn)){
+ wxListItem* item = lcItem->GetColumnInfo(listColumn);
+
+ // we always use the 0 column to get font and text/background colors.
+ if (lcItem->HasColumnInfo(0))
+ {
+ wxListItem* firstItem = lcItem->GetColumnInfo(0);
+ color = firstItem->GetTextColour();
+ bgColor = firstItem->GetBackgroundColour();
+ font = firstItem->GetFont();
+ }
+
+ if (item->GetMask() & wxLIST_MASK_TEXT)
+ text = item->GetText();
+ if (item->GetMask() & wxLIST_MASK_IMAGE)
+ imgIndex = item->GetImage();
+ }
+
+ }
+ else
+ {
+ long itemNum = (long)itemID-1;
+ if (itemNum >= 0 && itemNum < list->GetItemCount())
+ {
+ text = list->OnGetItemText( itemNum, listColumn );
+ imgIndex = list->OnGetItemColumnImage( itemNum, listColumn );
+ wxListItemAttr* attrs = list->OnGetItemAttr( itemNum );
+ if (attrs)
+ {
+ if (attrs->HasBackgroundColour())
+ bgColor = attrs->GetBackgroundColour();
+ if (attrs->HasTextColour())
+ color = attrs->GetTextColour();
+ if (attrs->HasFont())
+ font = attrs->GetFont();
+ }
+ }
+ }
+ }
+
+ wxColour listBgColor = list->GetBackgroundColour();
+ if (bgColor == wxNullColour)
+ bgColor = listBgColor;
+
+ wxFont listFont = list->GetFont();
+ if (font == wxNullFont)
+ font = listFont;
+
+ wxMacCFStringHolder cfString;
+ cfString.Assign( text, wxLocale::GetSystemEncoding() );
+
+ Rect enclosingRect;
+ CGRect enclosingCGRect, iconCGRect, textCGRect;
+ Boolean active;
+ ThemeDrawingState savedState = NULL;
+ CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
+ RGBColor labelColor;
+ labelColor.red = 0;
+ labelColor.green = 0;
+ labelColor.blue = 0;
+
+ RGBColor backgroundColor;
+ backgroundColor.red = 255;
+ backgroundColor.green = 255;
+ backgroundColor.blue = 255;
+
+ GetDataBrowserItemPartBounds(GetControlRef(), itemID, property, kDataBrowserPropertyEnclosingPart,
+ &enclosingRect);
+
+ enclosingCGRect = CGRectMake(enclosingRect.left,
+ enclosingRect.top,
+ enclosingRect.right - enclosingRect.left,
+ enclosingRect.bottom - enclosingRect.top);
+
+ bool hasFocus = (wxWindow::FindFocus() == list);
+ active = IsControlActive(GetControlRef());
+
+ // don't paint the background over the vertical rule line
+ if ( list->GetWindowStyleFlag() & wxLC_VRULES )
+ {
+ enclosingCGRect.origin.x += 1;
+ enclosingCGRect.size.width -= 1;
+ }
+ if (itemState == kDataBrowserItemIsSelected)
+ {
+
+ GetThemeDrawingState(&savedState);
+
+ if (active && hasFocus)
+ {
+ GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &backgroundColor);
+ GetThemeTextColor(kThemeTextColorWhite, gdDepth, colorDevice, &labelColor);
+ }
+ else
+ {
+ GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &backgroundColor);
+ GetThemeTextColor(kThemeTextColorBlack, gdDepth, colorDevice, &labelColor);
+ }
+ CGContextSaveGState(context);
+
+ CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX,
+ (float)backgroundColor.green / (float)USHRT_MAX,
+ (float)backgroundColor.blue / (float)USHRT_MAX, 1.0);
+ CGContextFillRect(context, enclosingCGRect);
+
+ CGContextRestoreGState(context);
+ }
+ else
+ {
+
+ if (color.Ok())
+ labelColor = MAC_WXCOLORREF( color.GetPixel() );
+ else if (list->GetTextColour().Ok())
+ labelColor = MAC_WXCOLORREF( list->GetTextColour().GetPixel() );
+
+ if (bgColor.Ok())
+ {
+ backgroundColor = MAC_WXCOLORREF( bgColor.GetPixel() );
+ CGContextSaveGState(context);
+
+ CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX,
+ (float)backgroundColor.green / (float)USHRT_MAX,
+ (float)backgroundColor.blue / (float)USHRT_MAX, 1.0);
+ CGContextFillRect(context, enclosingCGRect);
+
+ CGContextRestoreGState(context);
+ }
+ }
+
+ calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
+
+ if (imgIndex != -1)
+ {
+ wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
+ if (imageList && imageList->GetImageCount() > 0){
+ wxBitmap bmp = imageList->GetBitmap(imgIndex);
+ IconRef icon = bmp.GetBitmapData()->GetIconRef();
+
+ CGContextSaveGState(context);
+ CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
+ CGContextScaleCTM(context,1.0f,-1.0f);
+ PlotIconRefInContext(context, &iconCGRect, kAlignNone,
+ active ? kTransformNone : kTransformDisabled, NULL,
+ kPlotIconRefNormalFlags, icon);
+
+ CGContextRestoreGState(context);
+ }
+ }
+
+ HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
+ UInt16 fontID = kThemeViewsFont;
+
+ if (font.Ok())
+ {
+ if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
+ fontID = font.MacGetThemeFontID();
+
+// FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
+#ifndef __LP64__
+ ::TextSize( (short)(font.MacGetFontSize()) ) ;
+ ::TextFace( font.MacGetFontStyle() ) ;
+#endif
+ }
+
+ wxListItem item;
+ list->GetColumn(listColumn, item);
+ if (item.GetMask() & wxLIST_MASK_FORMAT)
+ {
+ if (item.GetAlign() == wxLIST_FORMAT_LEFT)
+ hFlush = kHIThemeTextHorizontalFlushLeft;
+ else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
+ hFlush = kHIThemeTextHorizontalFlushCenter;
+ else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
+ {
+ hFlush = kHIThemeTextHorizontalFlushRight;
+ textCGRect.origin.x -= kItemPadding; // give a little extra paddding
+ }
+ }
+
+ HIThemeTextInfo info;
+ info.version = kHIThemeTextInfoVersionZero;
+ info.state = active ? kThemeStateActive : kThemeStateInactive;
+ info.fontID = fontID;
+ info.horizontalFlushness = hFlush;
+ info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
+ info.options = kHIThemeTextBoxOptionNone;
+ info.truncationPosition = kHIThemeTextTruncationEnd;
+ 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);
+
+ HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
+
+ CGContextRestoreGState(context);
+
+ if (savedState != NULL)
+ SetThemeDrawingState(savedState, true);