aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/ScintillaGTK.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/ScintillaGTK.cxx')
-rw-r--r--gtk/ScintillaGTK.cxx68
1 files changed, 40 insertions, 28 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index d97ba7c31..dae9f2861 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -1261,37 +1261,47 @@ void ScintillaGTK::Copy() {
}
}
-void ScintillaGTK::Paste() {
- atomSought = atomUTF8;
- GtkClipboard *clipBoard =
- gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomClipboard);
- if (clipBoard == nullptr)
- return;
+namespace {
- // helper class for the asynchronous paste not to risk calling in a destroyed ScintillaGTK
- class Helper : GObjectWatcher {
- ScintillaGTK *sci;
+// Helper class for the asynchronous paste not to risk calling in a destroyed ScintillaGTK
- void Destroyed() override {
- sci = nullptr;
- }
+class SelectionReceiver : GObjectWatcher {
+ ScintillaGTK *sci;
- public:
- Helper(ScintillaGTK *sci_) :
- GObjectWatcher(G_OBJECT(PWidget(sci_->wMain))),
- sci(sci_) {
- }
+ void Destroyed() override {
+ sci = nullptr;
+ }
- static void ClipboardReceived(GtkClipboard *, GtkSelectionData *selection_data, gpointer data) {
- Helper *self = static_cast<Helper *>(data);
- if (self->sci) {
- self->sci->ReceivedSelection(selection_data);
- }
- delete self;
+public:
+ SelectionReceiver(ScintillaGTK *sci_) :
+ GObjectWatcher(G_OBJECT(sci_->MainObject())),
+ sci(sci_) {
+ }
+
+ static void ClipboardReceived(GtkClipboard *, GtkSelectionData *selection_data, gpointer data) {
+ SelectionReceiver *self = static_cast<SelectionReceiver *>(data);
+ if (self->sci) {
+ self->sci->ReceivedSelection(selection_data);
}
- };
+ delete self;
+ }
+};
+
+}
+
+void ScintillaGTK::RequestSelection(GdkAtom atomSelection) {
+ atomSought = atomUTF8;
+ GtkClipboard *clipBoard =
+ gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomSelection);
+ if (clipBoard) {
+ gtk_clipboard_request_contents(clipBoard, atomSought,
+ SelectionReceiver::ClipboardReceived,
+ new SelectionReceiver(this));
+ }
+}
- gtk_clipboard_request_contents(clipBoard, atomSought, Helper::ClipboardReceived, new Helper(this));
+void ScintillaGTK::Paste() {
+ RequestSelection(atomClipboard);
}
void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
@@ -1422,6 +1432,10 @@ void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, Selectio
}
}
+GObject *ScintillaGTK::MainObject() const noexcept {
+ return G_OBJECT(PWidget(wMain));
+}
+
void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) {
try {
if ((SelectionOfGSD(selection_data) == atomClipboard) ||
@@ -1736,9 +1750,7 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) {
sel.Clear();
SetSelection(pos, pos);
- atomSought = atomUTF8;
- gtk_selection_convert(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY,
- atomSought, event->time);
+ RequestSelection(GDK_SELECTION_PRIMARY);
} else if (event->button == 3) {
if (!PointInSelection(pt))
SetEmptySelection(PositionFromLocation(pt));