示例#1
0
文件: ListViews.cpp 项目: DonCN/haiku
// SimpleItem::DrawItem
void
SimpleItem::Draw(BView *owner, BRect frame, uint32 flags)
{
	DrawBackground(owner, frame, flags);
	// label
	owner->SetHighColor(0, 0, 0, 255);
	font_height fh;
	owner->GetFontHeight(&fh);
	const char* text = Text();
	BString truncatedString(text);
	owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
						  frame.Width() - TEXT_OFFSET - 4.0);
	float height = frame.Height();
	float textHeight = fh.ascent + fh.descent;
	BPoint textPoint;
	textPoint.x = frame.left + TEXT_OFFSET;
	textPoint.y = frame.top
				  + ceilf(height / 2.0 - textHeight / 2.0
				  		  + fh.ascent);
	owner->DrawString(truncatedString.String(), textPoint);
}
示例#2
0
void
TeamsColumn::DrawField(BField* field, BRect rect, BView* parent)
{
	BBitmapStringField* bitmapField
		= dynamic_cast<BBitmapStringField*>(field);
	BStringField* stringField = dynamic_cast<BStringField*>(field);

	if (bitmapField) {
		const BBitmap* bitmap = bitmapField->Bitmap();

		// figure out the placement
		float x = 0.0;
		BRect r = bitmap ? bitmap->Bounds() : BRect(0, 0, 15, 15);
		float y = rect.top + ((rect.Height() - r.Height()) / 2);
		float width = 0.0;

		switch (Alignment()) {
			default:
			case B_ALIGN_LEFT:
			case B_ALIGN_CENTER:
				x = rect.left + sTextMargin;
				width = rect.right - (x + r.Width()) - (2 * sTextMargin);
				r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
				break;

			case B_ALIGN_RIGHT:
				x = rect.right - sTextMargin - r.Width();
				width = (x - rect.left - (2 * sTextMargin));
				r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
				break;
		}

		if (width != bitmapField->Width()) {
			BString truncatedString(bitmapField->String());
			parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
			bitmapField->SetClippedString(truncatedString.String());
			bitmapField->SetWidth(width);
		}

		// draw the bitmap
		if (bitmap) {
			parent->SetDrawingMode(B_OP_ALPHA);
			parent->DrawBitmap(bitmap, BPoint(x, y));
			parent->SetDrawingMode(B_OP_OVER);
		}

		// draw the string
		DrawString(bitmapField->ClippedString(), parent, r);

	} else if (stringField) {

		float width = rect.Width() - (2 * sTextMargin);

		if (width != stringField->Width()) {
			BString truncatedString(stringField->String());

			parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
			stringField->SetClippedString(truncatedString.String());
			stringField->SetWidth(width);
		}

		DrawString(stringField->ClippedString(), parent, rect);
	}
}
示例#3
0
ModelMenuItem * 
BSlowContextMenu::NewModelItem(Model *model, const BMessage *invokeMessage,
	const BMessenger &target, bool suppressFolderHierarchy,
	BContainerWindow *parentWindow, const BObjectList<BString> *typeslist,
	TrackingHookData *hook)
{
	if (model->InitCheck() != B_OK)
		return NULL;

	entry_ref ref;
	bool container = false;
	if (model->IsSymLink()) {
	
		Model *newResolvedModel = NULL;
		Model *result = model->LinkTo();

		if (!result) {
			newResolvedModel = new Model(model->EntryRef(), true, true);

			if (newResolvedModel->InitCheck() != B_OK) {
				// broken link, still can show though, bail
				delete newResolvedModel;
				newResolvedModel = NULL;
			}
			
			result = newResolvedModel;
		}

		if (result) {
			BModelOpener opener(result);
				// open the model, if it ain't open already
					
			PoseInfo poseInfo;
			ssize_t size = -1;
			
			if (result->Node()) 
				size = result->Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
					&poseInfo, sizeof(poseInfo));
	
			result->CloseNode();

			ref = *result->EntryRef();
			container = result->IsContainer();
		}
		model->SetLinkTo(result);
	} else {
		ref = *model->EntryRef();
		container = model->IsContainer();
	}

	BMessage *message = new BMessage(*invokeMessage);
	message->AddRef("refs", model->EntryRef());

	// Truncate the name if necessary
	BString truncatedString(model->Name());
	be_plain_font->TruncateString(&truncatedString, B_TRUNCATE_END,
		BNavMenu::GetMaxMenuWidth());

	ModelMenuItem *item = NULL;
	if (!container || suppressFolderHierarchy) {
		item = new ModelMenuItem(model, truncatedString.String(), message);
		if (invokeMessage->what != B_REFS_RECEIVED)
			item->SetEnabled(false);
	} else {
		BNavMenu *menu = new BNavMenu(truncatedString.String(),
			invokeMessage->what, target, parentWindow, typeslist);
		
		menu->SetNavDir(&ref);
		if (hook)
			menu->InitTrackingHook(hook->fTrackingHook, &(hook->fTarget),
				hook->fDragMessage);

		item = new ModelMenuItem(model, menu);
		item->SetMessage(message);
	}

	return item;
}
示例#4
0
/*****************************************************************************
 * PlaylistItem::DrawItem
 *****************************************************************************/
void
PlaylistItem::Draw( BView *owner, BRect frame, bool tintedLine,
                    uint32 mode, bool active, bool playing )
{
    rgb_color color = (rgb_color){ 255, 255, 255, 255 };
    if ( tintedLine )
        color = tint_color( color, 1.04 );
    // background
    if ( IsSelected() )
        color = tint_color( color, B_DARKEN_2_TINT );
    owner->SetLowColor( color );
    owner->FillRect( frame, B_SOLID_LOW );
    // label
    owner->SetHighColor( 0, 0, 0, 255 );
    font_height fh;
    owner->GetFontHeight( &fh );
    const char* text = Text();
    switch ( mode )
    {
        case DISPLAY_NAME:
            if ( fName.CountChars() > 0 )
                text = fName.String();
            break;
        case DISPLAY_PATH:
        default:
            break;
    }
    BString truncatedString( text );
    owner->TruncateString( &truncatedString, B_TRUNCATE_MIDDLE,
                           frame.Width() - TEXT_OFFSET - 4.0 );
    owner->DrawString( truncatedString.String(),
                       BPoint( frame.left + TEXT_OFFSET,
                               frame.top + fh.ascent + 1.0 ) );
    // playmark
    if ( active )
    {
        rgb_color black = (rgb_color){ 0, 0, 0, 255 };
        rgb_color green = (rgb_color){ 0, 255, 0, 255 };
        BRect r( 0.0, 0.0, 10.0, 10.0 );
        r.OffsetTo( frame.left + 4.0,
                    ceilf( ( frame.top + frame.bottom ) / 2.0 ) - 5.0 );
        if ( !playing )
            green = tint_color( color, B_DARKEN_1_TINT );
        rgb_color lightGreen = tint_color( green, B_LIGHTEN_2_TINT );
        rgb_color darkGreen = tint_color( green, B_DARKEN_2_TINT );
        BPoint arrow[3];
        arrow[0] = r.LeftTop();
        arrow[1] = r.LeftBottom();
        arrow[2].x = r.right;
        arrow[2].y = ( r.top + r.bottom ) / 2.0;
        owner->BeginLineArray( 6 );
            // black outline
            owner->AddLine( arrow[0], arrow[1], black );
            owner->AddLine( BPoint( arrow[1].x + 1.0, arrow[1].y - 1.0 ),
                            arrow[2], black );
            owner->AddLine( arrow[0], arrow[2], black );
            // inset arrow
            arrow[0].x += 1.0;
            arrow[0].y += 2.0;
            arrow[1].x += 1.0;
            arrow[1].y -= 2.0;
            arrow[2].x -= 2.0;
            // highlights and shadow
            owner->AddLine( arrow[1], arrow[2], darkGreen );
            owner->AddLine( arrow[0], arrow[2], lightGreen );
            owner->AddLine( arrow[0], arrow[1], lightGreen );
        owner->EndLineArray();
        // fill green
        arrow[0].x += 1.0;
        arrow[0].y += 1.0;
        arrow[1].x += 1.0;
        arrow[1].y -= 1.0;
        arrow[2].x -= 2.0;
        owner->SetHighColor( green );
        owner->FillPolygon( arrow, 3 );
    }
}
示例#5
0
void
PackageColumn::DrawField(BField* field, BRect rect, BView* parent)
{
    BBitmapStringField* bitmapField
        = dynamic_cast<BBitmapStringField*>(field);
    BStringField* stringField = dynamic_cast<BStringField*>(field);
    RatingField* ratingField = dynamic_cast<RatingField*>(field);

    if (bitmapField != NULL) {
        const BBitmap* bitmap = bitmapField->Bitmap();

        // figure out the placement
        float x = 0.0;
        BRect r = bitmap ? bitmap->Bounds() : BRect(0, 0, 15, 15);
        float y = rect.top + ((rect.Height() - r.Height()) / 2);
        float width = 0.0;

        switch (Alignment()) {
        default:
        case B_ALIGN_LEFT:
        case B_ALIGN_CENTER:
            x = rect.left + sTextMargin;
            width = rect.right - (x + r.Width()) - (2 * sTextMargin);
            r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
            break;

        case B_ALIGN_RIGHT:
            x = rect.right - sTextMargin - r.Width();
            width = (x - rect.left - (2 * sTextMargin));
            r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
            break;
        }

        if (width != bitmapField->Width()) {
            BString truncatedString(bitmapField->String());
            parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
            bitmapField->SetClippedString(truncatedString.String());
            bitmapField->SetWidth(width);
        }

        // draw the bitmap
        if (bitmap != NULL) {
            parent->SetDrawingMode(B_OP_ALPHA);
            parent->DrawBitmap(bitmap, BPoint(x, y));
            parent->SetDrawingMode(B_OP_OVER);
        }

        // draw the string
        DrawString(bitmapField->ClippedString(), parent, r);

    } else if (stringField != NULL) {

        float width = rect.Width() - (2 * sTextMargin);

        if (width != stringField->Width()) {
            BString truncatedString(stringField->String());

            parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
            stringField->SetClippedString(truncatedString.String());
            stringField->SetWidth(width);
        }

        DrawString(stringField->ClippedString(), parent, rect);

    } else if (ratingField != NULL) {

        const float kDefaultTextMargin = 8;

        float width = rect.Width() - (2 * kDefaultTextMargin);

        BString string = "★★★★★";
        float stringWidth = parent->StringWidth(string);
        bool drawOverlay = true;

        if (width < stringWidth) {
            string.SetToFormat("%.1f", ratingField->Rating());
            drawOverlay = false;
            stringWidth = parent->StringWidth(string);
        }

        switch (Alignment()) {
        default:
        case B_ALIGN_LEFT:
            rect.left += kDefaultTextMargin;
            break;
        case B_ALIGN_CENTER:
            rect.left = rect.left + (width - stringWidth) / 2.0f;
            break;

        case B_ALIGN_RIGHT:
            rect.left = rect.right - (stringWidth + kDefaultTextMargin);
            break;
        }

        rect.left = floorf(rect.left);
        rect.right = rect.left + stringWidth;

        if (drawOverlay)
            parent->SetHighColor(0, 170, 255);

        font_height	fontHeight;
        parent->GetFontHeight(&fontHeight);
        float y = rect.top + (rect.Height()
                              - (fontHeight.ascent + fontHeight.descent)) / 2
                  + fontHeight.ascent;

        parent->DrawString(string, BPoint(rect.left, y));

        if (drawOverlay) {
            rect.left = ceilf(rect.left
                              + (ratingField->Rating() / 5.0f) * rect.Width());

            rgb_color color = parent->LowColor();
            color.alpha = 190;
            parent->SetHighColor(color);

            parent->SetDrawingMode(B_OP_ALPHA);
            parent->FillRect(rect, B_SOLID_HIGH);

        }
    }
}
示例#6
0
BMenuItem*
BRecentItemsList::GetNextMenuItem(const BMessage* fileOpenInvokeMessage,
	const BMessage* containerOpenInvokeMessage, BHandler* target,
	entry_ref* currentItemRef)
{
	entry_ref ref;
	if (GetNextRef(&ref) != B_OK)
		return NULL;

	Model model(&ref, true);
	if (model.InitCheck() != B_OK)
		return NULL;

	bool container = false;
	if (model.IsSymLink()) {

		Model* newResolvedModel = NULL;
		Model* result = model.LinkTo();

		if (result == NULL) {
			newResolvedModel = new Model(model.EntryRef(), true, true);

			if (newResolvedModel->InitCheck() != B_OK) {
				// broken link, still can show though, bail
				delete newResolvedModel;
				result = NULL;
			} else
				result = newResolvedModel;
		} else {
			BModelOpener opener(result);
				// open the model, if it ain't open already

			PoseInfo poseInfo;
			BNode* resultNode = result->Node();
			if (resultNode != NULL) {
				resultNode->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
					&poseInfo, sizeof(poseInfo));
			}

			result->CloseNode();

			ref = *result->EntryRef();
			container = result->IsContainer();
		}
		model.SetLinkTo(result);
	} else {
		ref = *model.EntryRef();
		container = model.IsContainer();
	}

	// if user asked for it, return the current item ref
	if (currentItemRef != NULL)
		*currentItemRef = ref;

	BMessage* message;
	if (container && containerOpenInvokeMessage)
		message = new BMessage(*containerOpenInvokeMessage);
	else if (!container && fileOpenInvokeMessage)
		message = new BMessage(*fileOpenInvokeMessage);
	else
		message = new BMessage(B_REFS_RECEIVED);

	message->AddRef("refs", model.EntryRef());

	// Truncate the name if necessary
	BString truncatedString(model.Name());
	be_plain_font->TruncateString(&truncatedString, B_TRUNCATE_END,
		BNavMenu::GetMaxMenuWidth());

	ModelMenuItem* item = NULL;
	if (!container || !fNavMenuFolders)
		item = new ModelMenuItem(&model, truncatedString.String(), message);
	else {
		// add another nav menu item if it's a directory
		BNavMenu* menu = new BNavMenu(truncatedString.String(), message->what,
			target, 0);

		menu->SetNavDir(&ref);
		item = new ModelMenuItem(&model, menu);
		item->SetMessage(message);
	}

	if (item != NULL && target != NULL)
		item->SetTarget(target);

	return item;
}