/******************************************************************************************** > BOOL MakeBitmapFilter::FindCentreInsertionPosition(Spread** Spread, DocCoord* Position) Author: Will_Cowling (Xara Group Ltd) <*****@*****.**> (from Simon) Created: 12/6/96 Inputs: - Outputs: Spread: The spread to place the clipboard objects on Position:The centre of the view (Spread coords) Purpose: Finds the centre insertion position for clipboard objects ********************************************************************************************/ BOOL MakeBitmapFilter::FindCentreInsertionPosition(Spread** Spread, DocCoord* Position) { // --------------------------------------------------------------------------------- // Find out which spread is in the centre of the view // this is the spread that the pasted objects will be placed on // Obtain the current DocView DocView* CurDocView = DocView::GetCurrent(); ENSURE(CurDocView != NULL, "The current DocView is NULL"); if (CurDocView == NULL) return FALSE; // No DocView // Get the view rect WorkRect WrkViewRect = CurDocView->GetViewRect(); if (WrkViewRect.IsEmpty() || (!WrkViewRect.IsValid()) ) return FALSE; // Defensive // Determine the centre of the view WorkCoord WrkCentreOfView; WrkCentreOfView.x = WrkViewRect.lox + (WrkViewRect.Width()/2); WrkCentreOfView.y = WrkViewRect.loy + (WrkViewRect.Height()/2); // FindEnclosing spread requires an OilCoord OilCoord OilCentreOfView = WrkCentreOfView.ToOil(CurDocView->GetScrollOffsets()); // Find out which spread to insert the pasteboard objects onto (*Spread) = CurDocView->FindEnclosingSpread(OilCentreOfView); if ((*Spread) == NULL) return FALSE; // There is no spread // Phew // --------------------------------------------------------------------------------- // Now lets find the spread coordinate of the centre of the view DocRect DocViewRect = CurDocView->GetDocViewRect(*Spread); if ( DocViewRect.IsEmpty() || (!DocViewRect.IsValid()) ) { ERROR3("DocViewRect is invalid"); return FALSE; // Defensive } // Find the centre of the DocViewRect DocCoord DocCentreOfView; DocCentreOfView.x = DocViewRect.lox + (DocViewRect.Width()/2); DocCentreOfView.y = DocViewRect.loy + (DocViewRect.Height()/2); // -------------------------------------------------------------------------------- // Now convert from DocCoords to spread coords DocRect PhysSpreadRect = (*Spread)->GetPasteboardRect(); (*Position).x = DocCentreOfView.x - PhysSpreadRect.lo.x; (*Position).y = DocCentreOfView.y - PhysSpreadRect.lo.y; return TRUE; }
KernelBitmap* SGNameDrag::MakeImage(UINT32 nDepth) { // If there's no current View, or no Spread, then fail. DocView* pView = DocView::GetCurrent(); if (pView == 0) return 0; Spread* pSpread = pView->FindEnclosingSpread(OilCoord(0, 0)); if (pSpread == 0) return 0; // Create a device context for the display. CDC sdc; sdc.CreateDC("DISPLAY", 0, 0, 0); // Calculate the size of the rendering and set up the rendering matrix etc. Matrix matConvert; FIXED16 fxScale = 1; INT32 nSel = NameGallery::Instance()->GetSelectedItemCount(); DocRect drClip(0, 0, SG_DefaultNameText, nSel * SG_DefaultSmallIcon); // Work out the destination bitmap's characteristics. double dpi = (double) GetDeviceCaps(sdc.m_hDC, LOGPIXELSX); if (nDepth == 0) nDepth = GetDeviceCaps(sdc.m_hDC, BITSPIXEL) * GetDeviceCaps(sdc.m_hDC, PLANES); // Create a render region with the given properties of the display etc. GRenderBitmap* pRenderer = new GRenderBitmap(drClip, matConvert, fxScale, nDepth, dpi); ERRORIF(pRenderer == 0, _R(IDE_NOMORE_MEMORY), 0); pRenderer->AttachDevice(pView, &sdc, pSpread); pRenderer->StartRender(); pRenderer->SaveContext(); // Blank the background. pRenderer->SetLineWidth(0); pRenderer->SetLineColour(COLOUR_WHITE); pRenderer->SetFillColour(COLOUR_WHITE); pRenderer->DrawRect(&drClip); // Render the item's name. DocColour dcText(COLOUR_BLACK), dcBack(COLOUR_WHITE); pRenderer->SetFixedSystemTextColours(&dcText, &dcBack); String_256 strName; m_pSourceItem->GetNameText(&strName); pRenderer->DrawFixedSystemText(&strName, drClip); // Create a kernel bitmap from the OIL bitmap and return it. pRenderer->RestoreContext(); pRenderer->StopRender(); OILBitmap* pOilMaskBmp = pRenderer->ExtractBitmap(); delete pRenderer; KernelBitmap* pkb = new KernelBitmap(pOilMaskBmp, TRUE); ERRORIF(pkb == 0, _R(IDE_NOMORE_MEMORY), 0); return pkb; }
KernelBitmap* GalleryLineDragInfo::GetSolidDragMask() { // Note we abuse this call (like our base class abuses this call) to create the bitmap // itself. We don't use DragMask itself anymore (i.e. it stays NULL) if (!DragMask && !TheBitmap) { DocView *View = DocView::GetCurrent(); if (View == NULL) { return NULL; } Spread *pSpread = View->FindEnclosingSpread(OilCoord(0,0)); if (pSpread == NULL) { return NULL; } // Find the size of the rendered item. DocRect ClipRegion(0,0, 750*100, 750*50); // ClipRegion.lo.x = ClipRegion.lo.y = 0; // SourceItem->GetSize(c_eLineAttrDragTextPos, &ClipRegion.hi.x, &ClipRegion.hi.y); Matrix ConvertMatrix; FIXED16 ViewScale = 1; wxScreenDC DisplayDC; double dpi = (double) OSRenderRegion::GetFixedDCPPI(DisplayDC).GetWidth(); GRenderBitmap* pMaskRegion = new GRenderBitmap(ClipRegion, ConvertMatrix, ViewScale, 32, dpi); pMaskRegion->SetDoCompression(TRUE); // misnamed call to indicate we want transparency pMaskRegion->AttachDevice(View, &DisplayDC, pSpread); // Make a Mask Bitmap pMaskRegion->StartRender(); SourceItem->Render(pMaskRegion, ClipRegion, c_eLineAttrDragTextPos); pMaskRegion->StopRender(); OILBitmap* pOilMaskBmp = pMaskRegion->ExtractBitmap(); TheBitmap = new KernelBitmap(pOilMaskBmp, TRUE); delete pMaskRegion; } return BitmapDragInformation::GetSolidDragMask(); }
BOOL ScreenCamView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point) { if (!m_DropFormatOK || pDataObject == NULL) return FALSE; // Document* pSelDoc = Document::GetSelected(); Document* pClipDoc = InternalClipboard::Instance(); if (pClipDoc != NULL) { Document::SetSelectedViewAndSpread(pClipDoc); pClipDoc->ResetInsertionPosition(); pClipDoc->SetCurrent(); // If there is *still* a format on the external clip board we like, then it's ok to drop CLIPFORMAT ClipFormat = ExternalClipboard::GetBestPasteFormat(pDataObject); ExternalClipboard* pExtClipBoard = ExternalClipboard::GetExternalClipboard(); if (ClipFormat != 0 && pExtClipBoard !=NULL && pExtClipBoard->PrepareForOlePaste(pDataObject)) { Document::SetSelectedViewAndSpread(GetDocument()->GetKernelDoc(),GetDocViewPtr()); DocView *pDocView = DocView::GetCurrent(); if (pDocView != NULL) { // Make the drop point a WinCoord so we can turn it into an oil coord WinCoord DropPoint(point.x,point.y); // Turn it into Oil coordinates... OilCoord OilPos = DropPoint.ToOil(pDocView); // Find the spread that contains the coord Spread* pSpread = pDocView->FindEnclosingSpread(OilPos); if (pSpread != NULL) { // First of all convert the OilCoord into device coords DocCoord Centre = OilPos.ToDoc(pSpread, pDocView); // Translate the coord to spread coords pSpread->DocCoordToSpreadCoord(&Centre); // 'Centre' now contains the centre point for the paste, in spread coords TRY { // Wrap all this in a TRY/CATCH block so that if OLE throws a wobbly, we can // ensure that the clipboard remains intacted on exit. // Copy the selection to the drag'n'drop clipboard. OpDescriptor* pOp = OpDescriptor::FindOpDescriptor(OPTOKEN_PASTE); ERROR3IF(!pOp, "No paste operation in ScreenCamView::OnDrop"); if (pOp != NULL) { Document::SetSelectedViewAndSpread(pClipDoc); pClipDoc->SetCurrent(); pClipDoc->ResetInsertionPosition(); InsertionNode* pInsertNode = pClipDoc->GetInsertionPosition(); if (pInsertNode != NULL) { pInsertNode->UnlinkNodeFromTree(); delete pInsertNode; pInsertNode = NULL; } Document::SetSelectedViewAndSpread(GetDocument()->GetKernelDoc(),GetDocViewPtr()); // create a param object that contains the centre point in the spread at which // we would like the objects to be pasted OpParamPasteAtPosition Param(pSpread,Centre); // Call the paste op via its DoWithParams() funtion pOp->Invoke(&Param); } } CATCH_ALL(e) { if (m_ClipBoardSwapped = FALSE) { // TRACEUSER( "Markn", _T("Swapping back to clipboard doc (Catch in ScreenCamView::OnDrop())\n")); InternalClipboard::Swap(); ExternalClipboard::UpdateSystemClipboard(TRUE); } THROW_LAST(); } END_CATCH_ALL }