mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00

This patch enables basic drag&drop between applications. You initiate a drag by creating a GDragOperation object and calling exec() on it. This creates a nested event loop in the calling program that only returns once the drag operation has ended. On the receiving side, you get a call to GWidget::drop_event() with a GDropEvent containing information about the dropped data. The only data passed right now is a piece of text that's also used to visually indicate that a drag is happening (by showing the text in a little box that follows the mouse cursor around.) There are things to fix here, but we're off to a nice start. :^)
36 lines
773 B
C++
36 lines
773 B
C++
#pragma once
|
|
|
|
#include <LibCore/CEventLoop.h>
|
|
#include <LibCore/CObject.h>
|
|
|
|
class GWindowServerConnection;
|
|
|
|
class GDragOperation : public CObject {
|
|
C_OBJECT(GDragOperation)
|
|
public:
|
|
enum class Outcome {
|
|
None,
|
|
Accepted,
|
|
Cancelled,
|
|
};
|
|
|
|
virtual ~GDragOperation() override;
|
|
|
|
void set_text(const String& text) { m_text = text; }
|
|
|
|
Outcome exec();
|
|
Outcome outcome() const { return m_outcome; }
|
|
|
|
static void notify_accepted(Badge<GWindowServerConnection>);
|
|
static void notify_cancelled(Badge<GWindowServerConnection>);
|
|
|
|
protected:
|
|
explicit GDragOperation(CObject* parent = nullptr);
|
|
|
|
private:
|
|
void done(Outcome);
|
|
|
|
OwnPtr<CEventLoop> m_event_loop;
|
|
Outcome m_outcome { Outcome::None };
|
|
String m_text;
|
|
};
|