void TypeIconView::Draw(BRect updateRect) { if (!IsEnabled()) return; IconView::Draw(updateRect); const char* text = NULL; switch (IconSource()) { case kNoIcon: text = B_TRANSLATE("no icon"); break; case kApplicationIcon: text = B_TRANSLATE("(from application)"); break; case kSupertypeIcon: text = B_TRANSLATE("(from super type)"); break; default: return; } SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); SetLowColor(ViewColor()); font_height fontHeight; GetFontHeight(&fontHeight); float y = fontHeight.ascent; if (IconSource() == kNoIcon) { // center text in the middle of the icon y += (IconSize() - fontHeight.ascent - fontHeight.descent) / 2.0f; } else y += IconSize() + 3.0f; DrawString(text, BPoint(ceilf((Bounds().Width() - StringWidth(text)) / 2.0f), ceilf(y))); }
BRect TypeIconView::BitmapRect() const { if (IconSource() == kNoIcon) { // this also defines the drop target area font_height fontHeight; GetFontHeight(&fontHeight); float width = StringWidth("no icon") + 8.0f; float height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0f; float x = (Bounds().Width() - width) / 2.0f; float y = ceilf((IconSize() - fontHeight.ascent - fontHeight.descent) / 2.0f) - 3.0f; return BRect(x, y, x + width, y + height); } float x = (Bounds().Width() - IconSize()) / 2.0f; return BRect(x, 0.0f, x + IconSize() - 1, IconSize() - 1); }