mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:17:45 +00:00
LibGUI+WindowServer: Make DragOperation hold a MimeData instance
...instead of maybe bitmap + a single mime type and its corresponding data. This allows drag&drop operations to hold multiple different kinds of data, and the views/applications to choose between those. For instance, Spreadsheet can keep the structure of the dragged cells, and still provide text-only data to be passed to different unrelated editors.
This commit is contained in:
parent
c930e02624
commit
6d1e47e7dd
15 changed files with 98 additions and 59 deletions
|
@ -755,7 +755,7 @@ OwnPtr<Messages::WindowServer::StartDragResponse> ClientConnection::handle(const
|
|||
bitmap = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, message.bitmap_size());
|
||||
}
|
||||
|
||||
wm.start_dnd_drag(*this, message.text(), bitmap, message.data_type(), message.data());
|
||||
wm.start_dnd_drag(*this, message.text(), bitmap, Core::MimeData::construct(message.mime_data()));
|
||||
return make<Messages::WindowServer::StartDragResponse>(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <Kernel/API/KeyCode.h>
|
||||
#include <LibCore/Event.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <WindowServer/Cursor.h>
|
||||
#include <WindowServer/WindowType.h>
|
||||
|
@ -128,7 +129,7 @@ public:
|
|||
const String& drag_data_type() const { return m_drag_data_type; }
|
||||
|
||||
void set_drag(bool b) { m_drag = b; }
|
||||
void set_drag_data_type(const String& drag_data_type) { m_drag_data_type = drag_data_type; }
|
||||
void set_mime_data(const Core::MimeData& mime_data) { m_mime_data = mime_data; }
|
||||
|
||||
MouseEvent translated(const Gfx::IntPoint& delta) const { return MouseEvent((Type)type(), m_position.translated(delta), m_buttons, m_button, m_modifiers, m_wheel_delta); }
|
||||
|
||||
|
@ -140,6 +141,7 @@ private:
|
|||
int m_wheel_delta { 0 };
|
||||
bool m_drag { false };
|
||||
String m_drag_data_type;
|
||||
RefPtr<const Core::MimeData> m_mime_data;
|
||||
};
|
||||
|
||||
class ResizeEvent final : public Event {
|
||||
|
|
|
@ -32,7 +32,7 @@ endpoint WindowClient = 4
|
|||
DragAccepted() =|
|
||||
DragCancelled() =|
|
||||
|
||||
DragDropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, String data_type, String data) =|
|
||||
DragDropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] String text, HashMap<String,ByteBuffer> mime_data) =|
|
||||
|
||||
UpdateSystemTheme(i32 system_theme_buffer_id) =|
|
||||
|
||||
|
|
|
@ -705,7 +705,7 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event, Window*& hovered_win
|
|||
hovered_window = &window;
|
||||
auto translated_event = event.translated(-window.position());
|
||||
translated_event.set_drag(true);
|
||||
translated_event.set_drag_data_type(m_dnd_data_type);
|
||||
translated_event.set_mime_data(*m_dnd_mime_data);
|
||||
deliver_mouse_event(window, translated_event);
|
||||
return IterationDecision::Break;
|
||||
});
|
||||
|
@ -727,7 +727,7 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event, Window*& hovered_win
|
|||
m_dnd_client->post_message(Messages::WindowClient::DragAccepted());
|
||||
if (hovered_window->client()) {
|
||||
auto translated_event = event.translated(-hovered_window->position());
|
||||
hovered_window->client()->post_message(Messages::WindowClient::DragDropped(hovered_window->window_id(), translated_event.position(), m_dnd_text, m_dnd_data_type, m_dnd_data));
|
||||
hovered_window->client()->post_message(Messages::WindowClient::DragDropped(hovered_window->window_id(), translated_event.position(), m_dnd_text, m_dnd_mime_data->all_data()));
|
||||
}
|
||||
} else {
|
||||
m_dnd_client->post_message(Messages::WindowClient::DragCancelled());
|
||||
|
@ -1355,14 +1355,13 @@ Gfx::IntRect WindowManager::maximized_window_rect(const Window& window) const
|
|||
return rect;
|
||||
}
|
||||
|
||||
void WindowManager::start_dnd_drag(ClientConnection& client, const String& text, Gfx::Bitmap* bitmap, const String& data_type, const String& data)
|
||||
void WindowManager::start_dnd_drag(ClientConnection& client, const String& text, Gfx::Bitmap* bitmap, const Core::MimeData& mime_data)
|
||||
{
|
||||
ASSERT(!m_dnd_client);
|
||||
m_dnd_client = client.make_weak_ptr();
|
||||
m_dnd_text = text;
|
||||
m_dnd_bitmap = bitmap;
|
||||
m_dnd_data_type = data_type;
|
||||
m_dnd_data = data;
|
||||
m_dnd_mime_data = mime_data;
|
||||
Compositor::the().invalidate_cursor();
|
||||
m_active_input_tracking_window = nullptr;
|
||||
}
|
||||
|
|
|
@ -100,12 +100,11 @@ public:
|
|||
|
||||
const ClientConnection* dnd_client() const { return m_dnd_client.ptr(); }
|
||||
const String& dnd_text() const { return m_dnd_text; }
|
||||
const String& dnd_data_type() const { return m_dnd_data_type; }
|
||||
const String& dnd_data() const { return m_dnd_data; }
|
||||
const Core::MimeData& dnd_mime_data() const { return *m_dnd_mime_data; }
|
||||
const Gfx::Bitmap* dnd_bitmap() const { return m_dnd_bitmap; }
|
||||
Gfx::IntRect dnd_rect() const;
|
||||
|
||||
void start_dnd_drag(ClientConnection&, const String& text, Gfx::Bitmap*, const String& data_type, const String& data);
|
||||
void start_dnd_drag(ClientConnection&, const String& text, Gfx::Bitmap*, const Core::MimeData&);
|
||||
void end_dnd_drag();
|
||||
|
||||
Window* active_window() { return m_active_window.ptr(); }
|
||||
|
@ -331,8 +330,7 @@ private:
|
|||
|
||||
WeakPtr<ClientConnection> m_dnd_client;
|
||||
String m_dnd_text;
|
||||
String m_dnd_data_type;
|
||||
String m_dnd_data;
|
||||
RefPtr<Core::MimeData> m_dnd_mime_data;
|
||||
RefPtr<Gfx::Bitmap> m_dnd_bitmap;
|
||||
};
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ endpoint WindowServer = 2
|
|||
SetWindowCursor(i32 window_id, i32 cursor_type) => ()
|
||||
SetWindowCustomCursor(i32 window_id, Gfx::ShareableBitmap cursor) => ()
|
||||
|
||||
StartDrag([UTF8] String text, String data_type, String data, i32 bitmap_id, Gfx::IntSize bitmap_size) => (bool started)
|
||||
StartDrag([UTF8] String text, HashMap<String,ByteBuffer> mime_data, i32 bitmap_id, Gfx::IntSize bitmap_size) => (bool started)
|
||||
|
||||
SetSystemTheme(String theme_path, [UTF8] String theme_name) => (bool success)
|
||||
GetSystemTheme() => ([UTF8] String theme_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue