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 */
BPicture * FlattenPictureTest::SaveAndRestore(BPicture *picture) { BMallocIO *data = new BMallocIO(); AutoDelete<BMallocIO> _data(data); TEST_AND_RETURN(data == NULL, "BMallocIO could not be allocated for flattening the picture!" , NULL); picture->Flatten(data); data->Seek(0, SEEK_SET); BPicture *archivedPicture = new BPicture(); TEST_AND_RETURN(archivedPicture == NULL, "BPicture could not be allocated for unflattening the picture!" , NULL); archivedPicture->Unflatten(data); return archivedPicture; }
void BPrintJob::_AddPicture(BPicture& picture, BRect& rect, BPoint& where) { ASSERT(fSpoolFile != NULL); fCurrentPageHeader->number_of_pictures++; fSpoolFile->Write(&where, sizeof(BRect)); fSpoolFile->Write(&rect, sizeof(BPoint)); picture.Flatten(fSpoolFile); }
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(); }
status_t PrintJobPage::NextPicture(BPicture& picture, BPoint& point, BRect& rect) { if (fPicture >= fNumberOfPictures) return B_ERROR; fPicture++; fJobFile.Seek(fNextPicture, SEEK_SET); fJobFile.Read(&point, sizeof(BPoint)); fJobFile.Read(&rect, sizeof(BRect)); status_t rc = picture.Unflatten(&fJobFile); fNextPicture = fJobFile.Position(); if (rc != B_OK) fPicture = fNumberOfPictures; return rc; }