Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2022, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <AK/OwnPtr.h>
11#include <LibCore/MimeData.h>
12#include <LibCore/Object.h>
13#include <LibGUI/Forward.h>
14#include <LibGfx/Forward.h>
15
16namespace GUI {
17
18class DragOperation : public Core::Object {
19 C_OBJECT(DragOperation)
20public:
21 enum class Outcome {
22 None,
23 Accepted,
24 Cancelled,
25 };
26
27 virtual ~DragOperation() override = default;
28
29 void set_mime_data(RefPtr<Core::MimeData> mime_data) { m_mime_data = move(mime_data); }
30 void set_text(DeprecatedString const& text);
31 void set_bitmap(Gfx::Bitmap const* bitmap);
32 void set_data(DeprecatedString const& data_type, DeprecatedString const& data);
33
34 Outcome exec();
35 Outcome outcome() const { return m_outcome; }
36
37 static void notify_accepted(Badge<ConnectionToWindowServer>);
38 static void notify_cancelled(Badge<ConnectionToWindowServer>);
39
40protected:
41 explicit DragOperation(Core::Object* parent = nullptr);
42
43private:
44 void done(Outcome);
45
46 OwnPtr<Core::EventLoop> m_event_loop;
47 Outcome m_outcome { Outcome::None };
48 RefPtr<Core::MimeData> m_mime_data;
49};
50
51}