Difference between revisions of "Calc/Implementation/Calc copy paste"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
== Copy&paste,clipboard concepts ==
== Copy&paste,clipboard concepts ==

Latest revision as of 08:44, 27 April 2012

Copy&paste,clipboard concepts

  • Clipboard

Users can copy, cut and paste information such as text and pictures from one program into another or between different editors. The Clipboard stores your information, which can be a picture or a section of text from a word processor, in a temporary storage, enabling you to move that snippet of information from one place to another.

The clipboard is a software facility that can be used for short-term data storage and/or data transfer between documents or applications, via copy and paste operations. It is most commonly a part of a GUI environment and is usually implemented as an anonymous, temporary data buffer that can be accessed from programs within the environment via defined programming interfaces. A typical application accesses clipboard functionality by mapping user input (keybindings, menu selections, etc.) to these interfaces.

  • OLE clipboard

Microsoft Windows defines a number of standard formats that can be used for transferring data through the Clipboard. These include metafiles, text, bitmaps, and others. OLE defines a number of OLE-specific formats, as well. It is a good idea for applications that need more detail than given by these standard formats to register their own custom Clipboard formats.

For example, Microsoft Excel registers a custom format for spreadsheets. This format carries much more information than, for example, a bitmap does. When this data is pasted into an application that supports the spreadsheet format, all the formulas and values from the spreadsheet are retained and can be updated if necessary. Microsoft Excel also puts data on the Clipboard in formats so that it can be pasted as an OLE item. Any OLE document container can paste this information as an embedded item.

System clipboard and internal clipboard in OpenOffice

When copy&paste, the operation system will tell the clipboard how many formats it can be supported to do data exchange and transfer, this process is called format register. This figure will show the registered formats when copy a picture in Microsoft windows.

Window clipboard.png

when doing copy in OpenOffice, the register action occurred at first, and OpenOffice will collect all supported formats and register them to the clipboard of operation system. For example, in presentation, in the function of SdTransferable::AddSupportedFormats(), it will call TransferableHelper::AddFormat() to add a single format.

There are two kinds of clipboard in OpenOffice, external clipboard and internal clipboard. Here is the top structure of copy&paster in OpenOffice.

Copy paste structure.JPG

The class of SotExchange is a data format manager for system clipboard. It will initialize an array to represent data format. The class of DataFlavorRepresentation has three member variables: pMimeType, pName and pType. The pMimeType indicates the MIME content-type(type/subtype) string describing the data format of the object to transfer. MimeType must follows the RFC2045 and RFC2046(Request For Comments). The pName indicates a human readable name for the data format, The pType indicates the type of the object to transfer, for example, xOutputStream. Here take RTF format as an example: The values of that three variables are like this(defined in the file of sot/source/base/exchange.cxx): { "text/richtext", "Rich Text Format", &::getCppuType( (const Sequence< sal_Int8 >*) 0 ) }.

The other data structure is DataFlavor, it is a struct in the ::com::sun::star::datatransfer namespace. The real function of DataFlavor is equal with DataFlavorRepresentation, these two structs can be mapped each other. DataFlavor can be used by UNO API.

The external clipboard is a wrapper of operate system clipboard and it cooperated with OpenOffice 's Data Transfer Classes to transfer data between operate system clipboard and itself. External clipboard is a bridge between operation system clipboard and the applications in OpenOffice.

The internal clipboard is used for private data transfer in the applications of OpenOffice. The internal clipboard,copy&paste may be executed in the same document or same kind of documents in a same process, such as copying some data in a Writer document to paste these data to another Writer document. For the efficiency consideration, OpenOffice uses internal clipboard to do copy&paste in such scenarios. Which object can handle internal clipboard? The answer is document module, such as ScModule, SdModule and SwModule. Document module can be a bridge for the documents with same type in a same process. So those documents with the same type can copy&paste through internal clipboard directly. When doing a copy&paste between documents with different types, the internal clipboard can not be used anymore, because the module of the document type is unknown by the other. The internal clipboard can be represented by a figure like:


Process of copy&paste in spreadsheet

When getting data from clipboard, the real data transferring starts immediately. Operation system will ask OpenOffice to get the real transferable data. Openoffice creates the OLE object when copying cells from a sheet and paste them into Writer. In the function of ScTransferObj::InitDocShell (sc/source/ui/app/transobj.cxx),it creates and fills a ScDocShell, which is an embedded object. And the main point entry is ScTransferObj::GetData(), which will call InitDocShell to create OLE object by the object format. If pasting the object in writer, the real OLE spreadsheet document is inserted.


When copy some cells in a spreadsheet, paste it in the same document, then Openoffice will use the internal clipboard. And Openoffice uses the such logic to make a decision. The principle of format selection is more complex, more complex clipboard format is used. It is presented in the function of ScViewFunc::PasteFromSystem()

if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
// special case for tables from drawing
if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
PasteFromSystem( FORMAT_RTF );
else PasteFromSystem( SOT_FORMATSTR_ID_DRAWING );
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
Else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ))
{ ……
if ( bDoRtf )
PasteFromSystem( FORMAT_RTF );
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ))
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ))
else if (aDataHelper.HasFormat(nBiff8))
else if (aDataHelper.HasFormat(nBiff5))
else if (aDataHelper.HasFormat(FORMAT_RTF))
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML))
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_HTML_SIMPLE))
else if (aDataHelper.HasFormat(SOT_FORMATSTR_ID_SYLK))
else if (aDataHelper.HasFormat(FORMAT_STRING))
else if (aDataHelper.HasFormat(FORMAT_GDIMETAFILE))
else if (aDataHelper.HasFormat(FORMAT_BITMAP))
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ))
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ))
else if (aDataHelper.HasFormat( SOT_FORMATSTR_ID_BITMAP_WINDDB ) )

To the internal clipboard, the main class is ScClipData in the sc\inc\scmod.hxx, it is defined as
struct ScClipData

ScTransferObj* pCellClipboard;

ScDrawTransferObj* pDrawClipboard;
ScTransferObj is used for the selected cells, ScDrawTransferObj for the selected drawing objects.

Personal tools