summaryrefslogtreecommitdiff
path: root/Servers/WindowServer/WSClipboard.cpp
blob: 8e7239ec6ffeb747c866bef93498f421560d1e95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <WindowServer/WSClipboard.h>

WSClipboard& WSClipboard::the()
{
    static WSClipboard* s_the;
    if (!s_the)
        s_the = new WSClipboard;
    return *s_the;
}

WSClipboard::WSClipboard()
{
}

WSClipboard::~WSClipboard()
{
}

const u8* WSClipboard::data() const
{
    if (!m_shared_buffer)
        return nullptr;
    return (const u8*)m_shared_buffer->data();
}

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;
}

void WSClipboard::set_data(NonnullRefPtr<SharedBuffer>&& data, int contents_size, const String& data_type)
{
    dbg() << "WSClipboard::set_data <- [" << data_type << "] " << data->data() << " (" << contents_size << " bytes)";
    m_shared_buffer = move(data);
    m_contents_size = contents_size;
    m_data_type = data_type;

    if (on_content_change)
        on_content_change();
}