forked from AuroraMiddleware/gtk
Do without GtkSelectionWindow
Just populate a toolbar directly, in GtkEntry and GtkTextView.
This commit is contained in:
parent
a8ea64dbb1
commit
bb3c56abe2
@ -66,7 +66,7 @@
|
|||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "gtkstylecontextprivate.h"
|
#include "gtkstylecontextprivate.h"
|
||||||
#include "gtktexthandleprivate.h"
|
#include "gtktexthandleprivate.h"
|
||||||
#include "gtkselectionwindowprivate.h"
|
#include "gtkbubblewindowprivate.h"
|
||||||
|
|
||||||
#include "a11y/gtkentryaccessible.h"
|
#include "a11y/gtkentryaccessible.h"
|
||||||
|
|
||||||
@ -9256,8 +9256,34 @@ gtk_entry_popup_menu (GtkWidget *widget)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_entry_selection_bubble_popup_cb (gpointer user_data)
|
activate_bubble_cb (GtkWidget *item,
|
||||||
|
GtkEntry *entry)
|
||||||
|
{
|
||||||
|
const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
|
||||||
|
g_signal_emit_by_name (entry, signal);
|
||||||
|
gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
append_bubble_action (GtkEntry *entry,
|
||||||
|
GtkWidget *toolbar,
|
||||||
|
const gchar *stock_id,
|
||||||
|
const gchar *signal,
|
||||||
|
gboolean sensitive)
|
||||||
|
{
|
||||||
|
GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
|
||||||
|
g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
|
||||||
|
g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), entry);
|
||||||
|
gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
|
||||||
|
gtk_widget_show (GTK_WIDGET (item));
|
||||||
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bubble_targets_received (GtkClipboard *clipboard,
|
||||||
|
GtkSelectionData *data,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkEntry *entry = user_data;
|
GtkEntry *entry = user_data;
|
||||||
GtkEntryPrivate *priv = entry->priv;
|
GtkEntryPrivate *priv = entry->priv;
|
||||||
@ -9265,33 +9291,39 @@ gtk_entry_selection_bubble_popup_cb (gpointer user_data)
|
|||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
gint start_x, end_x;
|
gint start_x, end_x;
|
||||||
gboolean has_selection;
|
gboolean has_selection;
|
||||||
|
gboolean has_clipboard;
|
||||||
|
DisplayMode mode;
|
||||||
|
GtkWidget *toolbar;
|
||||||
|
|
||||||
has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
|
has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (!has_selection && !priv->editable)
|
if (!has_selection && !priv->editable)
|
||||||
{
|
{
|
||||||
priv->selection_bubble_timeout_id = 0;
|
priv->selection_bubble_timeout_id = 0;
|
||||||
return FALSE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->selection_bubble)
|
if (priv->selection_bubble)
|
||||||
gtk_widget_destroy (priv->selection_bubble);
|
gtk_widget_destroy (priv->selection_bubble);
|
||||||
|
|
||||||
priv->selection_bubble = gtk_selection_window_new ();
|
priv->selection_bubble = gtk_bubble_window_new ();
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "cut",
|
toolbar = gtk_toolbar_new ();
|
||||||
G_CALLBACK (gtk_entry_cut_clipboard),
|
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
|
||||||
entry);
|
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "copy",
|
gtk_widget_show (toolbar);
|
||||||
G_CALLBACK (gtk_entry_copy_clipboard),
|
gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
|
||||||
entry);
|
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "paste",
|
|
||||||
G_CALLBACK (gtk_entry_paste_clipboard),
|
|
||||||
entry);
|
|
||||||
|
|
||||||
gtk_selection_window_set_editable (GTK_SELECTION_WINDOW (priv->selection_bubble),
|
has_clipboard = gtk_selection_data_targets_include_text (data);
|
||||||
priv->editable);
|
mode = gtk_entry_get_display_mode (entry);
|
||||||
gtk_selection_window_set_has_selection (GTK_SELECTION_WINDOW (priv->selection_bubble),
|
|
||||||
has_selection);
|
append_bubble_action (entry, toolbar, GTK_STOCK_CUT, "cut-clipboard",
|
||||||
|
priv->editable && has_selection && mode == DISPLAY_NORMAL);
|
||||||
|
|
||||||
|
append_bubble_action (entry, toolbar, GTK_STOCK_COPY, "copy-clipboard",
|
||||||
|
has_selection && mode == DISPLAY_NORMAL);
|
||||||
|
|
||||||
|
append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
|
||||||
|
priv->editable && has_clipboard);
|
||||||
|
|
||||||
gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
|
gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
|
||||||
|
|
||||||
@ -9321,7 +9353,18 @@ gtk_entry_selection_bubble_popup_cb (gpointer user_data)
|
|||||||
priv->text_area, &rect, GTK_POS_TOP);
|
priv->text_area, &rect, GTK_POS_TOP);
|
||||||
|
|
||||||
priv->selection_bubble_timeout_id = 0;
|
priv->selection_bubble_timeout_id = 0;
|
||||||
return FALSE;
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gtk_entry_selection_bubble_popup_cb (gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkEntry *entry = user_data;
|
||||||
|
|
||||||
|
gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
|
||||||
|
gdk_atom_intern_static_string ("TARGETS"),
|
||||||
|
bubble_targets_received,
|
||||||
|
entry);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
#include "gtktexthandleprivate.h"
|
#include "gtktexthandleprivate.h"
|
||||||
#include "gtkstylecontextprivate.h"
|
#include "gtkstylecontextprivate.h"
|
||||||
#include "gtkcssstylepropertyprivate.h"
|
#include "gtkcssstylepropertyprivate.h"
|
||||||
#include "gtkselectionwindowprivate.h"
|
#include "gtkbubblewindowprivate.h"
|
||||||
|
|
||||||
#include "a11y/gtktextviewaccessibleprivate.h"
|
#include "a11y/gtktextviewaccessibleprivate.h"
|
||||||
|
|
||||||
@ -8762,42 +8762,78 @@ gtk_text_view_get_selection_rect (GtkTextView *text_view,
|
|||||||
rect->height = y2 - y1;
|
rect->height = y2 - y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_text_view_selection_bubble_popup_cb (gpointer user_data)
|
activate_bubble_cb (GtkWidget *item,
|
||||||
|
GtkTextView *text_view)
|
||||||
|
{
|
||||||
|
const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
|
||||||
|
g_signal_emit_by_name (text_view, signal);
|
||||||
|
gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (text_view->priv->selection_bubble));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
append_bubble_action (GtkTextView *text_view,
|
||||||
|
GtkWidget *toolbar,
|
||||||
|
const gchar *stock_id,
|
||||||
|
const gchar *signal,
|
||||||
|
gboolean sensitive)
|
||||||
|
{
|
||||||
|
GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
|
||||||
|
g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
|
||||||
|
g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), text_view);
|
||||||
|
gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
|
||||||
|
gtk_widget_show (GTK_WIDGET (item));
|
||||||
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bubble_targets_received (GtkClipboard *clipboard,
|
||||||
|
GtkSelectionData *data,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkTextView *text_view = user_data;
|
GtkTextView *text_view = user_data;
|
||||||
GtkTextViewPrivate *priv = text_view->priv;
|
GtkTextViewPrivate *priv = text_view->priv;
|
||||||
cairo_rectangle_int_t rect;
|
cairo_rectangle_int_t rect;
|
||||||
gboolean has_selection;
|
gboolean has_selection;
|
||||||
|
gboolean has_clipboard;
|
||||||
|
gboolean can_insert;
|
||||||
|
GtkTextIter iter;
|
||||||
|
GtkTextIter sel_start, sel_end;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
|
GtkToolbar *toolbar;
|
||||||
|
|
||||||
has_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
|
has_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
|
||||||
NULL, NULL);
|
&sel_start, &sel_end);
|
||||||
if (!priv->editable && !has_selection)
|
if (!priv->editable && !has_selection)
|
||||||
{
|
{
|
||||||
priv->selection_bubble_timeout_id = 0;
|
priv->selection_bubble_timeout_id = 0;
|
||||||
return FALSE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->selection_bubble)
|
if (priv->selection_bubble)
|
||||||
gtk_widget_destroy (priv->selection_bubble);
|
gtk_widget_destroy (priv->selection_bubble);
|
||||||
|
|
||||||
window = gtk_widget_get_window (GTK_WIDGET (text_view));
|
window = gtk_widget_get_window (GTK_WIDGET (text_view));
|
||||||
priv->selection_bubble = gtk_selection_window_new ();
|
priv->selection_bubble = gtk_bubble_window_new ();
|
||||||
gtk_selection_window_set_editable (GTK_SELECTION_WINDOW (priv->selection_bubble),
|
toolbar = gtk_toolbar_new ();
|
||||||
priv->editable);
|
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
|
||||||
gtk_selection_window_set_has_selection (GTK_SELECTION_WINDOW (priv->selection_bubble),
|
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
|
||||||
has_selection);
|
gtk_widget_show (toolbar);
|
||||||
|
gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
|
||||||
|
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "cut",
|
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
|
||||||
G_CALLBACK (gtk_text_view_cut_clipboard),
|
gtk_text_buffer_get_insert (get_buffer (text_view)));
|
||||||
text_view);
|
can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "copy",
|
has_clipboard = gtk_selection_data_targets_include_text (data);
|
||||||
G_CALLBACK (gtk_text_view_copy_clipboard),
|
|
||||||
text_view);
|
append_bubble_action (text_view, toolbar, GTK_STOCK_CUT, "cut-clipboard",
|
||||||
g_signal_connect_swapped (priv->selection_bubble, "paste",
|
has_selection &&
|
||||||
G_CALLBACK (gtk_text_view_paste_clipboard),
|
range_contains_editable_text (&sel_start, &sel_end,
|
||||||
text_view);
|
priv->editable));
|
||||||
|
append_bubble_action (text_view, toolbar, GTK_STOCK_COPY, "copy-clipboard",
|
||||||
|
has_selection);
|
||||||
|
append_bubble_action (text_view, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
|
||||||
|
can_insert && has_clipboard);
|
||||||
|
|
||||||
gtk_text_view_get_selection_rect (text_view, &rect);
|
gtk_text_view_get_selection_rect (text_view, &rect);
|
||||||
rect.x -= priv->xoffset;
|
rect.x -= priv->xoffset;
|
||||||
@ -8806,7 +8842,19 @@ gtk_text_view_selection_bubble_popup_cb (gpointer user_data)
|
|||||||
window, &rect, GTK_POS_TOP);
|
window, &rect, GTK_POS_TOP);
|
||||||
|
|
||||||
priv->selection_bubble_timeout_id = 0;
|
priv->selection_bubble_timeout_id = 0;
|
||||||
return FALSE;
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gtk_text_view_selection_bubble_popup_cb (gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkTextView *text_view = user_data;
|
||||||
|
gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
|
||||||
|
GDK_SELECTION_CLIPBOARD),
|
||||||
|
gdk_atom_intern_static_string ("TARGETS"),
|
||||||
|
bubble_targets_received,
|
||||||
|
text_view);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user