aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-03-28 09:24:53 +1100
committerNeil <nyamatongwe@gmail.com>2019-03-28 09:24:53 +1100
commita01ce5f6d0768ce760447ebb82ce2522a24ef76a (patch)
tree4f974f35176f85847f107e3033e8ba917f456d1c
parent12433a8312899131e23896db58709a07a0103c5f (diff)
parentf26ce8da060279b8c6be63e29dac6f339bd65be4 (diff)
downloadscintilla-mirror-a01ce5f6d0768ce760447ebb82ce2522a24ef76a.tar.gz
Merged Win32 and GTK work.
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--gtk/ScintillaGTK.cxx74
-rw-r--r--gtk/ScintillaGTK.h5
3 files changed, 50 insertions, 33 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 381dc4ecd..6f08fe033 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -571,6 +571,10 @@
Implement high-priority idle on Win32 to make redraw smoother and more efficient.
</li>
<li>
+ Fix flicker when inserting primary selection on GTK.
+ <a href="https://sourceforge.net/p/scintilla/bugs/2087/">Bug #2087</a>.
+ </li>
+ <li>
Avoid potential long hangs with idle styling for huge documents on Cocoa and GTK.
</li>
<ul>
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index f213c0097..9d6fa275f 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -131,7 +131,6 @@ enum {
TARGET_URI
};
-GdkAtom ScintillaGTK::atomClipboard = nullptr;
GdkAtom ScintillaGTK::atomUTF8 = nullptr;
GdkAtom ScintillaGTK::atomString = nullptr;
GdkAtom ScintillaGTK::atomUriList = nullptr;
@@ -1262,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(GDK_SELECTION_CLIPBOARD);
}
void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
@@ -1423,9 +1432,13 @@ 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) ||
+ if ((SelectionOfGSD(selection_data) == GDK_SELECTION_CLIPBOARD) ||
(SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY)) {
if ((atomSought == atomUTF8) && (LengthOfGSD(selection_data) <= 0)) {
atomSought = atomString;
@@ -1526,7 +1539,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se
void ScintillaGTK::StoreOnClipboard(SelectionText *clipText) {
GtkClipboard *clipBoard =
- gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomClipboard);
+ gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_CLIPBOARD);
if (clipBoard == nullptr) // Occurs if widget isn't in a toplevel
return;
@@ -1737,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));
@@ -3020,7 +3031,6 @@ void ScintillaGTK::ClassInit(OBJECT_CLASS *object_class, GtkWidgetClass *widget_
#ifdef SCI_LEXER
Scintilla_LinkLexers();
#endif
- atomClipboard = gdk_atom_intern("CLIPBOARD", FALSE);
atomUTF8 = gdk_atom_intern("UTF8_STRING", FALSE);
atomString = GDK_SELECTION_TYPE_STRING;
atomUriList = gdk_atom_intern("text/uri-list", FALSE);
diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h
index 501903b42..27f900455 100644
--- a/gtk/ScintillaGTK.h
+++ b/gtk/ScintillaGTK.h
@@ -36,7 +36,6 @@ class ScintillaGTK : public ScintillaBase {
GtkWidgetClass *parentClass;
- static GdkAtom atomClipboard;
static GdkAtom atomUTF8;
static GdkAtom atomString;
static GdkAtom atomUriList;
@@ -127,13 +126,17 @@ private:
int KeyDefault(int key, int modifiers) override;
void CopyToClipboard(const SelectionText &selectedText) override;
void Copy() override;
+ void RequestSelection(GdkAtom atomSelection);
void Paste() override;
void CreateCallTipWindow(PRectangle rc) override;
void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override;
bool OwnPrimarySelection();
void ClaimSelection() override;
void GetGtkSelectionText(GtkSelectionData *selectionData, SelectionText &selText);
+public: // Public for SelectionReceiver
+ GObject *MainObject() const noexcept;
void ReceivedSelection(GtkSelectionData *selection_data);
+private:
void ReceivedDrop(GtkSelectionData *selection_data);
static void GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *text);
void StoreOnClipboard(SelectionText *clipText);