void
LanguageListView::MessageReceived(BMessage* message)
{
	if (message->WasDropped() && _AcceptsDragMessage(message)) {
		// Someone just dropped something on us
		BMessage dragMessage(*message);
		dragMessage.AddInt32("drop_index", fDropIndex);
		dragMessage.AddPointer("drop_target", this);
		Messenger().SendMessage(&dragMessage);
	} else
		BOutlineListView::MessageReceived(message);
}
void CCrossHairDragView::MouseDown(BPoint where)
{
	// Send a message as drag message, which isn't understood
	// by the target. The target will respond with a 
	// B_NOT_UNDERSTOOD message. The reply is ignored.
	BMessage dragMessage('!+#@');

	float width  = crossHair->Bounds().Width();
	float height = crossHair->Bounds().Height();

	SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);

	isDragged = true;

	// The drag bitmap is deleted by the system. Create a copy
	// of the crosshair bitmap.
	BBitmap *clone = CreateCloneBitmap(crossHair);

	DragMessage(&dragMessage, clone, B_OP_OVER, BPoint(width/2,height/2), this);
}
bool
FactoryDragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
	BALM::CustomizableAddOn* addOn = fInstalledComponents.ItemAt(index);
	BMessage dragMessage(kMsgCreateComponent);
	dragMessage.AddString("component", addOn->Name());

	BRect frame;
	BBitmap* bitmap = BALM::EditorHelper::CreateBitmap(addOn, frame, NULL);
	if (bitmap != NULL) {
		DragMessage(&dragMessage, bitmap, BPoint(frame.Width() / 2,
			frame.Height() / 2));
	} else {
		frame.OffsetTo(fCurrentMousePosition.x - frame.Width() / 2,
			fCurrentMousePosition.y - frame.Height() / 2);
		DragMessage(&dragMessage, frame);
	}

	return true;
}
bool
PartitionListView::InitiateDrag(BPoint rowPoint, bool wasSelected)
{
	PartitionListRow* draggedRow
		= dynamic_cast<PartitionListRow*>(RowAt(rowPoint));
	if (draggedRow == NULL)
		return false;

	const char* draggedPath = draggedRow->DevicePath();
	if (draggedPath == NULL)
		return false;

	BRect draggedRowRect;
	GetRowRect(draggedRow, &draggedRowRect);

	BMessage dragMessage(B_MIME_DATA);
	dragMessage.AddData("text/plain", B_MIME_TYPE, draggedPath,
		strlen(draggedPath));

	DragMessage(&dragMessage, draggedRowRect, NULL);
	return true;
}
Esempio n. 5
0
// MouseMoved
void
ObjectView::MouseMoved(BPoint where, uint32 transit,
					   const BMessage* dragMessage)
{
//	BRect dirty(where, where);
//	dirty.InsetBy(-10, -10);
//	Invalidate(dirty);
	
if (dragMessage) {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y);
//Window()->CurrentMessage()->PrintToStream();
} else {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f))\n", where.x, where.y);
}

	if (fScrolling) {
		BCursor cursor(kGrabCursor);
		SetViewCursor(&cursor);
	
		BPoint offset = fLastMousePos - where;
		ScrollBy(offset.x, offset.y);
		fLastMousePos = where + offset;
	} else if (fInitiatingDrag) {
		BPoint offset = fLastMousePos - where;
		if (sqrtf(offset.x * offset.x + offset.y * offset.y) > 5.0) {
			BMessage dragMessage('drag');
			BBitmap* dragBitmap = new BBitmap(BRect(0, 0, 40, 40), B_RGBA32, true);
			if (dragBitmap->Lock()) {
				BView* helper = new BView(dragBitmap->Bounds(), "offscreen view",
										  B_FOLLOW_ALL, B_WILL_DRAW);
				dragBitmap->AddChild(helper);
				helper->SetDrawingMode(B_OP_ALPHA);
				helper->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);

				BRect r(helper->Bounds());
				helper->SetHighColor(0, 0, 0, 128);
				helper->StrokeRect(r);

				helper->SetHighColor(200, 200, 200, 100);
				r.InsetBy(1, 1);
				helper->FillRect(r);

				helper->SetHighColor(0, 0, 0, 255);
				const char* text = "Test";
				float pos = (r.Width() - helper->StringWidth(text)) / 2;
				helper->DrawString(text, BPoint(pos, 25));
				helper->Sync();
			}
			
			DragMessage(&dragMessage, dragBitmap, B_OP_ALPHA, B_ORIGIN, this);
			fInitiatingDrag = false;
		}
	} else {
		BCursor cursor(kMoveCursor);
		SetViewCursor(&cursor);
	
		if (fState && fState->IsTracking()) {
			BRect before = fState->Bounds();
	
			fState->MouseMoved(where);
	
			BRect after = fState->Bounds();
			BRect invalid(before | after);
			Invalidate(invalid);
		}
	}
//	SetViewCursor();
}