2019-03-08 09:27:19 -03:00
|
|
|
#include <WindowServer/WSClipboard.h>
|
|
|
|
|
|
|
|
|
|
WSClipboard& WSClipboard::the()
|
|
|
|
|
{
|
2019-04-05 00:10:18 -03:00
|
|
|
static WSClipboard* s_the;
|
|
|
|
|
if (!s_the)
|
|
|
|
|
s_the = new WSClipboard;
|
|
|
|
|
return *s_the;
|
2019-03-08 09:27:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WSClipboard::WSClipboard()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WSClipboard::~WSClipboard()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:17:35 -03:00
|
|
|
const u8* WSClipboard::data() const
|
2019-03-08 09:27:19 -03:00
|
|
|
{
|
|
|
|
|
if (!m_shared_buffer)
|
|
|
|
|
return nullptr;
|
2019-07-03 16:17:35 -03:00
|
|
|
return (const u8*)m_shared_buffer->data();
|
2019-03-08 09:27:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WSClipboard::size() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_shared_buffer)
|
|
|
|
|
return 0;
|
|
|
|
|
return m_contents_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSClipboard::clear()
|
|
|
|
|
{
|
|
|
|
|
m_shared_buffer = nullptr;
|
|
|
|
|
m_contents_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 04:19:05 -03:00
|
|
|
void WSClipboard::set_data(NonnullRefPtr<SharedBuffer>&& data, int contents_size, const String& data_type)
|
2019-03-08 09:27:19 -03:00
|
|
|
{
|
2019-09-14 04:19:05 -03:00
|
|
|
dbg() << "WSClipboard::set_data <- [" << data_type << "] " << data->data() << " (" << contents_size << " bytes)";
|
2019-03-08 09:27:19 -03:00
|
|
|
m_shared_buffer = move(data);
|
|
|
|
|
m_contents_size = contents_size;
|
2019-09-14 04:19:05 -03:00
|
|
|
m_data_type = data_type;
|
|
|
|
|
|
|
|
|
|
if (on_content_change)
|
|
|
|
|
on_content_change();
|
2019-03-08 09:27:19 -03:00
|
|
|
}
|