void CCellView::StartDrag(BPoint where, bool copy) { ClearAnts(); BMessage msg(B_SIMPLE_DATA); msg.AddPointer("container", fContainer); msg.AddPointer("cellview", this); msg.AddData("range", 'rang', &fSelection, sizeof(range)); msg.AddBool("dragacopy", copy); BRegion rgn; SelectionToRegion(rgn); cell c; GetCellHitBy(where, c); BRect dragRect = rgn.Frame(); dragRect.OffsetBy(fCellWidths[c.h] - fCellWidths[fSelection.left], fCellHeights[c.v] - fCellHeights[fSelection.top]); BMallocIO buf; CTextConverter conv(buf, fContainer); conv.ConvertToText(&fSelection); msg.AddData("text/plain", B_MIME_DATA, buf.Buffer(), buf.BufferLength()); // and add a nice picture BPicture pic; BRect r; GetPictureOfSelection(&pic, r); pic.Archive(&msg); // msg.AddData("picture", 'PICT', pic.Data(), pic.DataSize()); msg.AddData("rect of pict", 'RECT', &r, sizeof(BRect)); fDragIsAcceptable = true; DragMessage(&msg, dragRect, this); } /* CCellView::StartDrag */
void PictureView::AllAttached() { BeginPicture(new BPicture); DrawStuff(this); BPicture *picture = EndPicture(); if (picture == NULL) return; BMessage message; picture->Archive(&message); message.PrintToStream(); BMallocIO stream; status_t status = picture->Flatten(&stream); delete picture; if (status != B_OK) printf("Error flattening BPicture: %s\n", strerror(status)); if (status == B_OK) { stream.Seek(0, SEEK_SET); fPicture = new BPicture(); status = fPicture->Unflatten(&stream); if (status != B_OK) { printf("Error unflattening BPicture: %s\n", strerror(status)); return; } } BMessage message2; fPicture->Archive(&message2); message2.PrintToStream(); }