Clipboard

Native clipboard.

Header#include "nativeui/clipboard.h"
Namespacenamespace nu
Typeclass

The Clipboard class can not be created by user, its instance can only be recevied by using App.GetClipboard.

// Get the default copy-paste clipboard.
nu::Clipboard* clipboard = nu::App::GetCurrent()->GetClipboard(nu::Clipboard::Type::CopyPaste);

// Changing the content of clipboard with multiple formats of data.
std::vector<nu::Clipboard::Data> objects;
// Add text.
objects.emplace_back(nu::Clipboard::Text, "some text");
// Add HTML.
objects.emplace_back(nu::Clipboard::HTML, "<strong>some text</strong>");
// Add Image.
objects.emplace_back(new nu::Image("..."));
// Add file paths.
objects.emplace_back({
  base::FilePath(FILE_PATH_LITERAL("/some/path")),
});
// Change data.
clipboard->SetData(std::move(objects));

// Read data.
Data data = clipboard->GetData(nu::Clipboard::Data::Type::Text);
if (data.type() == nu::Clipboard::Data::Type::Text)
  LOG(INFO) << data.str();

Methods

void Clear()

Clear the clipboard.

void SetText(const std::string& text)

Set text as clipboard's content.

Parameters

std::string GetText() const

Return the content of clipboard as text.

Return

std::string

bool IsDataAvailable(Clipboard::Data::Type type) const

Return whether the data of type is available.

Parameters

Return

bool

Clipboard::Data GetData(Clipboard::Data::Type type) const

Get the data of type from clipboard.

You should always check the type of returned data before using it.

Parameters

Return

Clipboard::Data

void SetData(std::vector<Clipboard::Data> objects)

Set clipboard's content.

Parameters

NativeClipboard GetNative() const

Return the native handle of clipboard.

Return

NativeClipboard