void MimeTypeItem::DrawItem(BView* owner, BRect frame, bool complete) { BFont font; if (IsSupertypeOnly()) { owner->GetFont(&font); BFont boldFont(font); boldFont.SetFace(B_BOLD_FACE); owner->SetFont(&boldFont); } BRect rect = frame; if (fFlat) { // This is where the latch would be - yet can freely consider this // as an ugly hack rect.left -= 11.0f; } if (fShowIcon) { rgb_color lowColor = owner->LowColor(); if (IsSelected() || complete) { if (IsSelected()) owner->SetLowColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR)); owner->FillRect(rect, B_SOLID_LOW); } BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_RGBA32); BMimeType mimeType(fType.String()); status_t status = icon_for_type(mimeType, bitmap, B_MINI_ICON); if (status < B_OK) { // get default generic/application icon BMimeType genericType(fApplicationMode ? B_ELF_APP_MIME_TYPE : B_FILE_MIME_TYPE); status = icon_for_type(genericType, bitmap, B_MINI_ICON); } if (status == B_OK) { BPoint point(rect.left + 2.0f, rect.top + (rect.Height() - B_MINI_ICON) / 2.0f); owner->SetDrawingMode(B_OP_ALPHA); owner->DrawBitmap(&bitmap, point); } owner->SetDrawingMode(B_OP_COPY); owner->MovePenTo(rect.left + B_MINI_ICON + 8.0f, frame.top + fBaselineOffset); owner->DrawString(Text()); owner->SetLowColor(lowColor); } else BStringItem::DrawItem(owner, rect, complete); if (IsSupertypeOnly()) owner->SetFont(&font); }
void MimeTypeItem::UpdateText() { if (IsSupertypeOnly()) return; BMimeType type(fType.String()); char description[B_MIME_TYPE_LENGTH]; if (type.GetShortDescription(description) == B_OK) SetText(description); else SetText(Subtype()); fDescription = Text(); }
void MimeTypeItem::_SetTo(BMimeType& type) { fIsSupertype = type.IsSupertypeOnly(); if (IsSupertypeOnly()) { // this is a super type fSupertype = type.Type(); fDescription = type.Type(); return; } const char* subType = strchr(type.Type(), '/'); fSupertype.SetTo(type.Type(), subType - type.Type()); fSubtype.SetTo(subType + 1); // omit the slash UpdateText(); }