KiCad PCB EDA Suite
Loading...
Searching...
No Matches
clipboard.cpp File Reference
#include "clipboard.h"
#include <wx/clipbrd.h>
#include <wx/dataobj.h>
#include <wx/image.h>
#include <wx/log.h>
#include <wx/mstream.h>
#include <wx/string.h>
#include <wx/sstream.h>
#include <io/csv.h>

Go to the source code of this file.

Functions

bool SaveClipboard (const std::string &aTextUTF8)
 Store information to the system clipboard.
 
bool SaveClipboard (const std::string &aTextUTF8, const std::vector< CLIPBOARD_MIME_DATA > &aMimeData)
 Store information to the system clipboard with additional MIME types.
 
std::string GetClipboardUTF8 ()
 Return the information currently stored in the system clipboard.
 
std::unique_ptr< wxBitmap > GetImageFromClipboard ()
 Get image data from the clipboard, if there is any.
 
bool SaveTabularDataToClipboard (const std::vector< std::vector< wxString > > &aData)
 Store tabular data to the system clipboard.
 
bool GetTabularDataFromClipboard (std::vector< std::vector< wxString > > &aData)
 Attempt to get tabular data from the clipboard.
 
bool EncodeImageToPng (const wxImage &aImage, wxMemoryBuffer &aOutput)
 Encode an image to PNG format with fast compression settings optimized for clipboard use.
 
bool AddPngToClipboardData (wxDataObjectComposite *aData, const wxMemoryBuffer &aPngData, const wxImage *aFallbackImage)
 Adds pre-encoded PNG data to clipboard in a platform-specific way.
 
bool AddTransparentImageToClipboardData (wxDataObjectComposite *aData, wxImage aImage)
 Adds an image to clipboard data in a platform-specific way such that transparency is supported.
 

Function Documentation

◆ AddPngToClipboardData()

bool AddPngToClipboardData ( wxDataObjectComposite * aData,
const wxMemoryBuffer & aPngData,
const wxImage * aFallbackImage = nullptr )

Adds pre-encoded PNG data to clipboard in a platform-specific way.

On Windows: Adds empty CF_BITMAP marker and "PNG" format entry On GTK: Adds as wxDF_BITMAP (which maps to image/png) On macOS: Falls back to wxBitmapDataObject with the provided image

Parameters
aDataClipboard composite to add PNG to
aPngDataPre-encoded PNG bytes
aFallbackImageOptional image for macOS fallback (required on macOS)
Returns
true on success

Definition at line 324 of file clipboard.cpp.

Referenced by AddTransparentImageToClipboardData(), and SCH_EDITOR_CONTROL::doCopy().

◆ AddTransparentImageToClipboardData()

bool AddTransparentImageToClipboardData ( wxDataObjectComposite * aData,
wxImage aImage )

Adds an image to clipboard data in a platform-specific way such that transparency is supported.

Convenience function that encodes PNG internally.

Definition at line 349 of file clipboard.cpp.

References AddPngToClipboardData(), and EncodeImageToPng().

Referenced by SCH_EDITOR_CONTROL::DrawSheetOnClipboard().

◆ EncodeImageToPng()

bool EncodeImageToPng ( const wxImage & aImage,
wxMemoryBuffer & aOutput )

Encode an image to PNG format with fast compression settings optimized for clipboard use.

Parameters
aImageSource image to encode
aOutputBuffer to receive PNG data
Returns
true on success

Definition at line 293 of file clipboard.cpp.

Referenced by AddTransparentImageToClipboardData(), and SCH_EDITOR_CONTROL::doCopy().

◆ GetClipboardUTF8()

std::string GetClipboardUTF8 ( )

◆ GetImageFromClipboard()

std::unique_ptr< wxBitmap > GetImageFromClipboard ( )

Get image data from the clipboard, if there is any.

If there's a filename there, and it can be loaded as an image, do that.

Definition at line 168 of file clipboard.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PCB_CONTROL::Paste(), PL_EDIT_TOOL::Paste(), and SCH_EDITOR_CONTROL::Paste().

◆ GetTabularDataFromClipboard()

bool GetTabularDataFromClipboard ( std::vector< std::vector< wxString > > & aData)

◆ SaveClipboard() [1/2]

◆ SaveClipboard() [2/2]

bool SaveClipboard ( const std::string & aTextUTF8,
const std::vector< CLIPBOARD_MIME_DATA > & aMimeData )

Store information to the system clipboard with additional MIME types.

Creates a composite clipboard object with text as the primary format and additional custom MIME type data. When aMimeData is empty, falls back to SaveClipboard(aTextUTF8).

Parameters
aTextUTF8is the text to store, expected UTF8 encoding. Stored as primary text format.
aMimeDatais additional data to store by MIME type (e.g., image/svg+xml, image/png).
Returns
False if error occurred.

Definition at line 56 of file clipboard.cpp.

References SaveClipboard().

◆ SaveTabularDataToClipboard()

bool SaveTabularDataToClipboard ( const std::vector< std::vector< wxString > > & aData)