Merge branch 'text' into 'master'

GtkEntry reshuffling

Closes #1483

See merge request GNOME/gtk!585
This commit is contained in:
Matthias Clasen 2019-02-19 05:45:44 +00:00
commit 9174616a17
56 changed files with 10072 additions and 6782 deletions

View File

@ -13,7 +13,7 @@ search_changed_cb (GtkSearchEntry *entry,
GtkLabel *result_label) GtkLabel *result_label)
{ {
const char *text; const char *text;
text = gtk_entry_get_text (GTK_ENTRY (entry)); text = gtk_editable_get_text (GTK_EDITABLE (entry));
g_message ("search changed: %s", text); g_message ("search changed: %s", text);
gtk_label_set_text (result_label, text ? text : ""); gtk_label_set_text (result_label, text ? text : "");
} }
@ -22,7 +22,7 @@ static void
changed_cb (GtkEditable *editable) changed_cb (GtkEditable *editable)
{ {
const char *text; const char *text;
text = gtk_entry_get_text (GTK_ENTRY (editable)); text = gtk_editable_get_text (GTK_EDITABLE (editable));
g_message ("changed: %s", text); g_message ("changed: %s", text);
} }
@ -85,7 +85,7 @@ do_search_entry2 (GtkWidget *do_widget)
gtk_widget_set_halign (container, GTK_ALIGN_CENTER); gtk_widget_set_halign (container, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (container), entry); gtk_container_add (GTK_CONTAINER (container), entry);
searchbar = gtk_search_bar_new (); searchbar = gtk_search_bar_new ();
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (searchbar), GTK_ENTRY (entry)); gtk_search_bar_connect_entry (GTK_SEARCH_BAR (searchbar), GTK_EDITABLE (entry));
gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (searchbar), FALSE); gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (searchbar), FALSE);
gtk_container_add (GTK_CONTAINER (searchbar), container); gtk_container_add (GTK_CONTAINER (searchbar), container);
gtk_container_add (GTK_CONTAINER (vbox), searchbar); gtk_container_add (GTK_CONTAINER (vbox), searchbar);

View File

@ -474,7 +474,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</child> </child>
<child> <child>
<object class="GtkEntry" id="entry1"> <object class="GtkEntry" id="entry1">
<property name="can-focus">1</property>
<property name="enable-emoji-completion">1</property> <property name="enable-emoji-completion">1</property>
<property name="invisible_char">•</property> <property name="invisible_char">•</property>
<property name="placeholder-text" translatable="yes">Click icon to change mode</property> <property name="placeholder-text" translatable="yes">Click icon to change mode</property>
@ -486,7 +485,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child> <child>
<object class="GtkEntry" id="entry2"> <object class="GtkEntry" id="entry2">
<property name="sensitive">0</property> <property name="sensitive">0</property>
<property name="can-focus">1</property>
<property name="invisible-char">•</property> <property name="invisible-char">•</property>
<property name="text" translatable="yes">entry</property> <property name="text" translatable="yes">entry</property>
</object> </object>
@ -498,7 +496,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</style> </style>
<child> <child>
<object class="GtkEntry" id="entry24"> <object class="GtkEntry" id="entry24">
<property name="can-focus">1</property>
<property name="invisible-char">•</property> <property name="invisible-char">•</property>
<property name="text" translatable="yes">entry</property> <property name="text" translatable="yes">entry</property>
<property name="hexpand">1</property> <property name="hexpand">1</property>
@ -575,7 +572,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</child> </child>
<child> <child>
<object class="GtkSpinButton" id="spinbutton1"> <object class="GtkSpinButton" id="spinbutton1">
<property name="can-focus">1</property>
<property name="width-chars">2</property> <property name="width-chars">2</property>
<property name="max-width-chars">2</property> <property name="max-width-chars">2</property>
<property name="adjustment">adjustment2</property> <property name="adjustment">adjustment2</property>
@ -583,7 +579,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</child> </child>
<child> <child>
<object class="GtkSpinButton" id="spinbutton2"> <object class="GtkSpinButton" id="spinbutton2">
<property name="can-focus">1</property>
<property name="sensitive">0</property> <property name="sensitive">0</property>
<property name="width-chars">2</property> <property name="width-chars">2</property>
<property name="max-width-chars">2</property> <property name="max-width-chars">2</property>
@ -3000,14 +2995,12 @@ microphone-sensitivity-medium-symbolic</property>
<property name="halign">center</property> <property name="halign">center</property>
<child> <child>
<object class="GtkEntry"> <object class="GtkEntry">
<property name="can-focus">1</property>
<property name="placeholder-text" translatable="yes">Name…</property> <property name="placeholder-text" translatable="yes">Name…</property>
<property name="completion">name_completion</property> <property name="completion">name_completion</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkEntry"> <object class="GtkEntry">
<property name="can-focus">1</property>
<property name="show-emoji-icon">1</property> <property name="show-emoji-icon">1</property>
<property name="placeholder-text" translatable="yes">Age…</property> <property name="placeholder-text" translatable="yes">Age…</property>
</object> </object>

View File

@ -138,14 +138,16 @@
<chapter id="NumericEntry"> <chapter id="NumericEntry">
<title>Numeric and Text Data Entry</title> <title>Numeric and Text Data Entry</title>
<xi:include href="xml/gtkentry.xml" /> <xi:include href="xml/gtkeditable.xml" />
<xi:include href="xml/gtkentrybuffer.xml" /> <xi:include href="xml/gtkentrybuffer.xml" />
<xi:include href="xml/gtktext.xml" />
<xi:include href="xml/gtkentry.xml" />
<xi:include href="xml/gtkentrycompletion.xml" /> <xi:include href="xml/gtkentrycompletion.xml" />
<xi:include href="xml/gtkpasswordentry.xml" />
<xi:include href="xml/gtkscale.xml" /> <xi:include href="xml/gtkscale.xml" />
<xi:include href="xml/gtkspinbutton.xml" /> <xi:include href="xml/gtkspinbutton.xml" />
<xi:include href="xml/gtksearchentry.xml" /> <xi:include href="xml/gtksearchentry.xml" />
<xi:include href="xml/gtksearchbar.xml" /> <xi:include href="xml/gtksearchbar.xml" />
<xi:include href="xml/gtkeditable.xml" />
</chapter> </chapter>
<chapter id="TextWidgetObjects"> <chapter id="TextWidgetObjects">

View File

@ -844,19 +844,30 @@ gtk_drawing_area_get_type
<FILE>gtkeditable</FILE> <FILE>gtkeditable</FILE>
<TITLE>GtkEditable</TITLE> <TITLE>GtkEditable</TITLE>
GtkEditable GtkEditable
gtk_editable_select_region gtk_editable_get_text
gtk_editable_get_selection_bounds gtk_editable_set_text
gtk_editable_get_chars
gtk_editable_insert_text gtk_editable_insert_text
gtk_editable_delete_text gtk_editable_delete_text
gtk_editable_get_chars gtk_editable_get_selection_bounds
gtk_editable_cut_clipboard gtk_editable_select_region
gtk_editable_copy_clipboard
gtk_editable_paste_clipboard
gtk_editable_delete_selection gtk_editable_delete_selection
gtk_editable_set_position gtk_editable_set_position
gtk_editable_get_position gtk_editable_get_position
gtk_editable_set_editable gtk_editable_set_editable
gtk_editable_get_editable gtk_editable_get_editable
gtk_editable_set_alignment
gtk_editable_get_alignment
gtk_editable_get_width_chars
gtk_editable_set_width_chars
gtk_editable_get_max_width_chars
gtk_editable_set_max_width_chars
<SUBSECTION>
gtk_editable_install_properties
gtk_editable_init_delegate
gtk_editable_finish_delegate
gtk_editable_delegate_set_property
gtk_editable_delegate_get_property
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_EDITABLE GTK_EDITABLE
GTK_IS_EDITABLE GTK_IS_EDITABLE
@ -866,6 +877,44 @@ GTK_EDITABLE_GET_IFACE
gtk_editable_get_type gtk_editable_get_type
</SECTION> </SECTION>
<SECTION>
<FILE>gtktext</FILE>
<TITLE>GtkText</TITLE>
GtkText
GtkTextClass
gtk_text_new
gtk_text_new_with_buffer
gtk_text_set_buffer
gtk_text_get_buffer
gtk_text_set_visibility
gtk_text_get_visibility
gtk_text_set_invisible_char
gtk_text_get_invisible_char
gtk_text_unset_invisible_char
gtk_text_set_has_frame
gtk_text_get_has_frame
gtk_text_set_overwrite_mode
gtk_text_get_overwrite_mode
gtk_text_set_max_length
gtk_text_get_max_length
gtk_text_get_text_length
gtk_text_set_activates_default
gtk_text_get_activates_default
gtk_text_set_placeholder_text
gtk_text_get_placeholder_text
gtk_text_set_input_purpose
gtk_text_get_input_purpose
gtk_text_set_input_hints
gtk_text_get_input_hints
gtk_text_set_attributes
gtk_text_get_attributes
gtk_text_set_tabs
gtk_text_get_tabs
gtk_text_grab_focus_without_selecting
<SUBSECTION Private>
gtk_text_get_type
</SECTION>
<SECTION> <SECTION>
<FILE>gtkentry</FILE> <FILE>gtkentry</FILE>
<TITLE>GtkEntry</TITLE> <TITLE>GtkEntry</TITLE>
@ -899,10 +948,6 @@ gtk_entry_set_placeholder_text
gtk_entry_get_placeholder_text gtk_entry_get_placeholder_text
gtk_entry_set_overwrite_mode gtk_entry_set_overwrite_mode
gtk_entry_get_overwrite_mode gtk_entry_get_overwrite_mode
gtk_entry_get_layout
gtk_entry_get_layout_offsets
gtk_entry_layout_index_to_text_index
gtk_entry_text_index_to_layout_index
gtk_entry_set_attributes gtk_entry_set_attributes
gtk_entry_get_attributes gtk_entry_get_attributes
gtk_entry_set_completion gtk_entry_set_completion
@ -912,7 +957,6 @@ gtk_entry_get_progress_fraction
gtk_entry_set_progress_pulse_step gtk_entry_set_progress_pulse_step
gtk_entry_get_progress_pulse_step gtk_entry_get_progress_pulse_step
gtk_entry_progress_pulse gtk_entry_progress_pulse
gtk_entry_im_context_filter_keypress
gtk_entry_reset_im_context gtk_entry_reset_im_context
gtk_entry_set_tabs gtk_entry_set_tabs
gtk_entry_get_tabs gtk_entry_get_tabs
@ -958,6 +1002,15 @@ GtkEntryPrivate
gtk_entry_get_type gtk_entry_get_type
</SECTION> </SECTION>
<SECTION>
<FILE>gtkpasswordentry</FILE>
<TITLE>GtkPasswordEntry</TITLE>
GtkPasswordEntry
gtk_password_entry_new
<SUBSECTION Private>
gtk_password_entry_get_type
</SECTION>
<SECTION> <SECTION>
<FILE>gtkentrybuffer</FILE> <FILE>gtkentrybuffer</FILE>
<TITLE>GtkEntryBuffer</TITLE> <TITLE>GtkEntryBuffer</TITLE>

View File

@ -118,6 +118,7 @@ gtk_page_setup_get_type
@DISABLE_ON_W32@gtk_page_setup_unix_dialog_get_type @DISABLE_ON_W32@gtk_page_setup_unix_dialog_get_type
gtk_paned_get_type gtk_paned_get_type
gtk_paper_size_get_type gtk_paper_size_get_type
gtk_password_entry_get_type
gtk_picture_get_type gtk_picture_get_type
gtk_popover_get_type gtk_popover_get_type
gtk_popover_menu_get_type gtk_popover_menu_get_type
@ -168,6 +169,7 @@ gtk_style_context_get_type
gtk_style_provider_get_type gtk_style_provider_get_type
gtk_text_buffer_get_type gtk_text_buffer_get_type
gtk_text_child_anchor_get_type gtk_text_child_anchor_get_type
gtk_text_get_type
gtk_text_iter_get_type gtk_text_iter_get_type
gtk_text_mark_get_type gtk_text_mark_get_type
gtk_text_tag_get_type gtk_text_tag_get_type

View File

@ -601,6 +601,23 @@
to pages. You can easily do that yourself. to pages. You can easily do that yourself.
</para> </para>
</section> </section>
<section>
<title>Adapt to changes in the API of GtkEntry and GtkSearchEntry</title>
<para>
The GtkEditable has been made more useful, and the core functionality of
GtkEntry has been broken out as a GtkText widget. GtkEntry, GtkSearchEntry,
GtkSpinButton and the new GtkPasswordEntry now use a GtkText widget internally
and implement GtkEditable. In particular, this means that it is no longer
possible to use GtkEntry API such as gtk_entry_grab_focus_without_selecting()
on a search entry.
</para>
<para>
Use GtkEditable API for editable functionality, and widget-specific APIs for
things that go beyond the common interface. For password entries, use
GtkPasswordEntry.
</para>
</section>
</section> </section>
</chapter> </chapter>

View File

@ -28,7 +28,7 @@ activate_cb (GtkApplication *app,
menu_button = gtk_menu_button_new (); menu_button = gtk_menu_button_new ();
gtk_container_add (GTK_CONTAINER (box), menu_button); gtk_container_add (GTK_CONTAINER (box), menu_button);
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_ENTRY (entry)); gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_EDITABLE (entry));
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (search_bar), window); gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (search_bar), window);
} }

View File

@ -26,6 +26,7 @@
#include "gtkpango.h" #include "gtkpango.h"
#include "gtkentryaccessible.h" #include "gtkentryaccessible.h"
#include "gtkentryprivate.h" #include "gtkentryprivate.h"
#include "gtktextprivate.h"
#include "gtkcomboboxaccessible.h" #include "gtkcomboboxaccessible.h"
#include "gtkstylecontextprivate.h" #include "gtkstylecontextprivate.h"
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
@ -762,7 +763,7 @@ gtk_entry_accessible_get_text (AtkText *atk_text,
if (widget == NULL) if (widget == NULL)
return NULL; return NULL;
return _gtk_entry_get_display_text (GTK_ENTRY (widget), start_pos, end_pos); return gtk_text_get_display_text (gtk_entry_get_text_widget (GTK_ENTRY (widget)), start_pos, end_pos);
} }
static gchar * static gchar *
@ -778,7 +779,7 @@ gtk_entry_accessible_get_text_before_offset (AtkText *text,
if (widget == NULL) if (widget == NULL)
return NULL; return NULL;
return _gtk_pango_get_text_before (gtk_entry_get_layout (GTK_ENTRY (widget)), return _gtk_pango_get_text_before (gtk_text_get_layout (gtk_entry_get_text_widget (GTK_ENTRY (widget))),
boundary_type, offset, boundary_type, offset,
start_offset, end_offset); start_offset, end_offset);
} }
@ -796,7 +797,7 @@ gtk_entry_accessible_get_text_at_offset (AtkText *text,
if (widget == NULL) if (widget == NULL)
return NULL; return NULL;
return _gtk_pango_get_text_at (gtk_entry_get_layout (GTK_ENTRY (widget)), return _gtk_pango_get_text_at (gtk_text_get_layout (gtk_entry_get_text_widget (GTK_ENTRY (widget))),
boundary_type, offset, boundary_type, offset,
start_offset, end_offset); start_offset, end_offset);
} }
@ -814,7 +815,7 @@ gtk_entry_accessible_get_text_after_offset (AtkText *text,
if (widget == NULL) if (widget == NULL)
return NULL; return NULL;
return _gtk_pango_get_text_after (gtk_entry_get_layout (GTK_ENTRY (widget)), return _gtk_pango_get_text_after (gtk_text_get_layout (gtk_entry_get_text_widget (GTK_ENTRY (widget))),
boundary_type, offset, boundary_type, offset,
start_offset, end_offset); start_offset, end_offset);
} }
@ -830,7 +831,7 @@ gtk_entry_accessible_get_character_count (AtkText *atk_text)
if (widget == NULL) if (widget == NULL)
return 0; return 0;
text = _gtk_entry_get_display_text (GTK_ENTRY (widget), 0, -1); text = gtk_text_get_display_text (gtk_entry_get_text_widget (GTK_ENTRY (widget)), 0, -1);
char_count = 0; char_count = 0;
if (text) if (text)
@ -900,7 +901,7 @@ gtk_entry_accessible_get_run_attributes (AtkText *text,
attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION, attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
gtk_widget_get_direction (widget)); gtk_widget_get_direction (widget));
attributes = _gtk_pango_get_run_attributes (attributes, attributes = _gtk_pango_get_run_attributes (attributes,
gtk_entry_get_layout (GTK_ENTRY (widget)), gtk_text_get_layout (gtk_entry_get_text_widget (GTK_ENTRY (widget))),
offset, offset,
start_offset, start_offset,
end_offset); end_offset);
@ -922,7 +923,7 @@ gtk_entry_accessible_get_default_attributes (AtkText *text)
attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION, attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
gtk_widget_get_direction (widget)); gtk_widget_get_direction (widget));
attributes = _gtk_pango_get_default_attributes (attributes, attributes = _gtk_pango_get_default_attributes (attributes,
gtk_entry_get_layout (GTK_ENTRY (widget))); gtk_text_get_layout (gtk_entry_get_text_widget (GTK_ENTRY (widget))));
attributes = _gtk_style_context_get_attributes (attributes, attributes = _gtk_style_context_get_attributes (attributes,
gtk_widget_get_style_context (widget)); gtk_widget_get_style_context (widget));
@ -940,6 +941,7 @@ gtk_entry_accessible_get_character_extents (AtkText *text,
{ {
GtkWidget *widget; GtkWidget *widget;
GtkEntry *entry; GtkEntry *entry;
GtkText *textw;
PangoRectangle char_rect; PangoRectangle char_rect;
gchar *entry_text; gchar *entry_text;
gint index, x_layout, y_layout; gint index, x_layout, y_layout;
@ -952,13 +954,14 @@ gtk_entry_accessible_get_character_extents (AtkText *text,
return; return;
entry = GTK_ENTRY (widget); entry = GTK_ENTRY (widget);
textw = gtk_entry_get_text_widget (entry);
gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout); gtk_text_get_layout_offsets (textw, &x_layout, &y_layout);
entry_text = _gtk_entry_get_display_text (entry, 0, -1); entry_text = gtk_text_get_display_text (textw, 0, -1);
index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text; index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
g_free (entry_text); g_free (entry_text);
pango_layout_index_to_pos (gtk_entry_get_layout (entry), index, &char_rect); pango_layout_index_to_pos (gtk_text_get_layout (textw), index, &char_rect);
pango_extents_to_pixels (&char_rect, NULL); pango_extents_to_pixels (&char_rect, NULL);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
@ -989,6 +992,7 @@ gtk_entry_accessible_get_offset_at_point (AtkText *atk_text,
{ {
GtkWidget *widget; GtkWidget *widget;
GtkEntry *entry; GtkEntry *entry;
GtkText *textw;
gchar *text; gchar *text;
gint index, x_layout, y_layout; gint index, x_layout, y_layout;
gint x_surface, y_surface; gint x_surface, y_surface;
@ -1001,8 +1005,9 @@ gtk_entry_accessible_get_offset_at_point (AtkText *atk_text,
return -1; return -1;
entry = GTK_ENTRY (widget); entry = GTK_ENTRY (widget);
textw = gtk_entry_get_text_widget (entry);
gtk_entry_get_layout_offsets (entry, &x_layout, &y_layout); gtk_text_get_layout_offsets (textw, &x_layout, &y_layout);
surface = gtk_widget_get_surface (widget); surface = gtk_widget_get_surface (widget);
gdk_surface_get_origin (surface, &x_surface, &y_surface); gdk_surface_get_origin (surface, &x_surface, &y_surface);
@ -1018,7 +1023,7 @@ gtk_entry_accessible_get_offset_at_point (AtkText *atk_text,
x_local += x_surface; x_local += x_surface;
y_local += y_surface; y_local += y_surface;
} }
if (!pango_layout_xy_to_index (gtk_entry_get_layout (entry), if (!pango_layout_xy_to_index (gtk_text_get_layout (textw),
x_local * PANGO_SCALE, x_local * PANGO_SCALE,
y_local * PANGO_SCALE, y_local * PANGO_SCALE,
&index, NULL)) &index, NULL))
@ -1032,7 +1037,7 @@ gtk_entry_accessible_get_offset_at_point (AtkText *atk_text,
offset = -1; offset = -1;
if (index != -1) if (index != -1)
{ {
text = _gtk_entry_get_display_text (entry, 0, -1); text = gtk_text_get_display_text (textw, 0, -1);
offset = g_utf8_pointer_to_offset (text, text + index); offset = g_utf8_pointer_to_offset (text, text + index);
g_free (text); g_free (text);
} }
@ -1167,7 +1172,7 @@ gtk_entry_accessible_get_character_at_offset (AtkText *atk_text,
if (!gtk_entry_get_visibility (GTK_ENTRY (widget))) if (!gtk_entry_get_visibility (GTK_ENTRY (widget)))
return result; return result;
text = _gtk_entry_get_display_text (GTK_ENTRY (widget), 0, -1); text = gtk_text_get_display_text (gtk_entry_get_text_widget (GTK_ENTRY (widget)), 0, -1);
if (offset < g_utf8_strlen (text, -1)) if (offset < g_utf8_strlen (text, -1))
{ {
index = g_utf8_offset_to_pointer (text, offset); index = g_utf8_offset_to_pointer (text, offset);
@ -1402,7 +1407,7 @@ delete_text_cb (GtkEditable *editable,
{ {
gchar *text; gchar *text;
text = _gtk_entry_get_display_text (GTK_ENTRY (editable), 0, -1); text = gtk_text_get_display_text (gtk_entry_get_text_widget (GTK_ENTRY (editable)), 0, -1);
end = g_utf8_strlen (text, -1); end = g_utf8_strlen (text, -1);
g_free (text); g_free (text);
} }

1030
gtk/a11y/gtktextaccessible.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
/* GTK+ - accessibility implementations
* Copyright 2001 Sun Microsystems Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_TEXT_ACCESSIBLE_H__
#define __GTK_TEXT_ACCESSIBLE_H__
#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk-a11y.h> can be included directly."
#endif
#include <gtk/a11y/gtkwidgetaccessible.h>
G_BEGIN_DECLS
#define GTK_TYPE_TEXT_ACCESSIBLE (gtk_text_accessible_get_type ())
#define GTK_TEXT_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_ACCESSIBLE, GtkTextAccessible))
#define GTK_TEXT_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_ACCESSIBLE, GtkTextAccessibleClass))
#define GTK_IS_TEXT_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_ACCESSIBLE))
#define GTK_IS_TEXT_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_ACCESSIBLE))
#define GTK_TEXT_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_ACCESSIBLE, GtkTextAccessibleClass))
typedef struct _GtkTextAccessible GtkTextAccessible;
typedef struct _GtkTextAccessibleClass GtkTextAccessibleClass;
typedef struct _GtkTextAccessiblePrivate GtkTextAccessiblePrivate;
struct _GtkTextAccessible
{
GtkWidgetAccessible parent;
GtkTextAccessiblePrivate *priv;
};
struct _GtkTextAccessibleClass
{
GtkWidgetAccessibleClass parent_class;
};
GDK_AVAILABLE_IN_ALL
GType gtk_text_accessible_get_type (void);
G_END_DECLS
#endif /* __GTK_TEXT_ACCESSIBLE_H__ */

View File

@ -46,6 +46,7 @@ a11y_sources = files([
'gtkstackaccessible.c', 'gtkstackaccessible.c',
'gtkstatusbaraccessible.c', 'gtkstatusbaraccessible.c',
'gtkswitchaccessible.c', 'gtkswitchaccessible.c',
'gtktextaccessible.c',
'gtktextcellaccessible.c', 'gtktextcellaccessible.c',
'gtktextviewaccessible.c', 'gtktextviewaccessible.c',
'gtktogglebuttonaccessible.c', 'gtktogglebuttonaccessible.c',
@ -100,6 +101,7 @@ a11y_headers = files([
'gtkstackaccessible.h', 'gtkstackaccessible.h',
'gtkstatusbaraccessible.h', 'gtkstatusbaraccessible.h',
'gtkswitchaccessible.h', 'gtkswitchaccessible.h',
'gtktextaccessible.h',
'gtktextcellaccessible.h', 'gtktextcellaccessible.h',
'gtktextviewaccessible.h', 'gtktextviewaccessible.h',
'gtktogglebuttonaccessible.h', 'gtktogglebuttonaccessible.h',

View File

@ -159,8 +159,9 @@
#include <gtk/gtkoverlay.h> #include <gtk/gtkoverlay.h>
#include <gtk/gtkpadcontroller.h> #include <gtk/gtkpadcontroller.h>
#include <gtk/gtkpagesetup.h> #include <gtk/gtkpagesetup.h>
#include <gtk/gtkpapersize.h>
#include <gtk/gtkpaned.h> #include <gtk/gtkpaned.h>
#include <gtk/gtkpapersize.h>
#include <gtk/gtkpasswordentry.h>
#include <gtk/gtkpicture.h> #include <gtk/gtkpicture.h>
#include <gtk/gtkpopover.h> #include <gtk/gtkpopover.h>
#include <gtk/gtkpopovermenu.h> #include <gtk/gtkpopovermenu.h>
@ -211,6 +212,7 @@
#include <gtk/gtkstylecontext.h> #include <gtk/gtkstylecontext.h>
#include <gtk/gtkstyleprovider.h> #include <gtk/gtkstyleprovider.h>
#include <gtk/gtkswitch.h> #include <gtk/gtkswitch.h>
#include <gtk/gtktext.h>
#include <gtk/gtktextbuffer.h> #include <gtk/gtktextbuffer.h>
#include <gtk/gtktextchild.h> #include <gtk/gtktextchild.h>
#include <gtk/gtktextiter.h> #include <gtk/gtktextiter.h>

View File

@ -362,7 +362,7 @@ construct_appchooser_widget (GtkAppChooserDialog *self)
g_object_unref (info); g_object_unref (info);
_gtk_app_chooser_widget_set_search_entry (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget), _gtk_app_chooser_widget_set_search_entry (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget),
GTK_ENTRY (self->priv->search_entry)); GTK_EDITABLE (self->priv->search_entry));
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (self->priv->search_bar), gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (self->priv->search_bar),
GTK_WIDGET (self)); GTK_WIDGET (self));

View File

@ -45,7 +45,7 @@ struct _GtkAppChooserIface {
void void
_gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self, _gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self,
GtkEntry *entry); GtkEditable *editable);
G_END_DECLS G_END_DECLS

View File

@ -1489,7 +1489,7 @@ gtk_app_chooser_widget_get_default_text (GtkAppChooserWidget *self)
void void
_gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self, _gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self,
GtkEntry *entry) GtkEditable *entry)
{ {
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (self->priv->program_list), entry); gtk_tree_view_set_search_entry (GTK_TREE_VIEW (self->priv->program_list), entry);

File diff suppressed because it is too large Load Diff

View File

@ -45,82 +45,131 @@ typedef struct _GtkEditableInterface GtkEditableInterface;
struct _GtkEditableInterface struct _GtkEditableInterface
{ {
GTypeInterface base_iface; GTypeInterface base_iface;
/* signals */ /* signals */
void (* insert_text) (GtkEditable *editable, void (* insert_text) (GtkEditable *editable,
const gchar *new_text, const gchar *text,
gint new_text_length, int length,
gint *position); int *position);
void (* delete_text) (GtkEditable *editable, void (* delete_text) (GtkEditable *editable,
gint start_pos, int start_pos,
gint end_pos); int end_pos);
void (* changed) (GtkEditable *editable); void (* changed) (GtkEditable *editable);
/* vtable */ /* vtable */
void (* do_insert_text) (GtkEditable *editable, const char * (* get_text) (GtkEditable *editable);
const gchar *new_text, void (* do_insert_text) (GtkEditable *editable,
gint new_text_length, const char *text,
gint *position); int length,
void (* do_delete_text) (GtkEditable *editable, int *position);
gint start_pos, void (* do_delete_text) (GtkEditable *editable,
gint end_pos); int start_pos,
int end_pos);
gchar* (* get_chars) (GtkEditable *editable,
gint start_pos,
gint end_pos);
void (* set_selection_bounds) (GtkEditable *editable,
gint start_pos,
gint end_pos);
gboolean (* get_selection_bounds) (GtkEditable *editable, gboolean (* get_selection_bounds) (GtkEditable *editable,
gint *start_pos, int *start_pos,
gint *end_pos); int *end_pos);
void (* set_position) (GtkEditable *editable, void (* set_selection_bounds) (GtkEditable *editable,
gint position); int start_pos,
gint (* get_position) (GtkEditable *editable); int end_pos);
GtkEditable * (* get_delegate) (GtkEditable *editable);
}; };
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GType gtk_editable_get_type (void) G_GNUC_CONST; GType gtk_editable_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_editable_select_region (GtkEditable *editable, const char * gtk_editable_get_text (GtkEditable *editable);
gint start_pos,
gint end_pos);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_editable_get_selection_bounds (GtkEditable *editable, void gtk_editable_set_text (GtkEditable *editable,
gint *start_pos, const char *text);
gint *end_pos); GDK_AVAILABLE_IN_ALL
char * gtk_editable_get_chars (GtkEditable *editable,
int start_pos,
int end_pos);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_editable_insert_text (GtkEditable *editable, void gtk_editable_insert_text (GtkEditable *editable,
const gchar *new_text, const char *text,
gint new_text_length, int length,
gint *position); int *position);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_editable_delete_text (GtkEditable *editable, void gtk_editable_delete_text (GtkEditable *editable,
gint start_pos, int start_pos,
gint end_pos); int end_pos);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gchar* gtk_editable_get_chars (GtkEditable *editable, gboolean gtk_editable_get_selection_bounds (GtkEditable *editable,
gint start_pos, int *start_pos,
gint end_pos); int *end_pos);
GDK_AVAILABLE_IN_ALL
void gtk_editable_cut_clipboard (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_copy_clipboard (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_paste_clipboard (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_editable_delete_selection (GtkEditable *editable); void gtk_editable_delete_selection (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_select_region (GtkEditable *editable,
int start_pos,
int end_pos);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_editable_set_position (GtkEditable *editable, void gtk_editable_set_position (GtkEditable *editable,
gint position); int position);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gint gtk_editable_get_position (GtkEditable *editable); int gtk_editable_get_position (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_set_editable (GtkEditable *editable,
gboolean is_editable);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_editable_get_editable (GtkEditable *editable); gboolean gtk_editable_get_editable (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_set_editable (GtkEditable *editable,
gboolean is_editable);
GDK_AVAILABLE_IN_ALL
float gtk_editable_get_alignment (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_set_alignment (GtkEditable *editable,
float xalign);
GDK_AVAILABLE_IN_ALL
int gtk_editable_get_width_chars (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_set_width_chars (GtkEditable *editable,
int n_chars);
GDK_AVAILABLE_IN_ALL
int gtk_editable_get_max_width_chars (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_set_max_width_chars (GtkEditable *editable,
int n_chars);
/* api for implementations */
typedef enum {
GTK_EDITABLE_PROP_TEXT,
GTK_EDITABLE_PROP_CURSOR_POSITION,
GTK_EDITABLE_PROP_SELECTION_BOUND,
GTK_EDITABLE_PROP_EDITABLE,
GTK_EDITABLE_PROP_WIDTH_CHARS,
GTK_EDITABLE_PROP_MAX_WIDTH_CHARS,
GTK_EDITABLE_PROP_XALIGN,
GTK_EDITABLE_NUM_PROPERTIES
} GtkEditableProperties;
GDK_AVAILABLE_IN_ALL
guint gtk_editable_install_properties (GObjectClass *object_class,
guint first_prop);
GDK_AVAILABLE_IN_ALL
void gtk_editable_init_delegate (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
void gtk_editable_finish_delegate (GtkEditable *editable);
GDK_AVAILABLE_IN_ALL
gboolean gtk_editable_delegate_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
GDK_AVAILABLE_IN_ALL
gboolean gtk_editable_delegate_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_END_DECLS G_END_DECLS

View File

@ -19,7 +19,8 @@
#include "gtkemojicompletion.h" #include "gtkemojicompletion.h"
#include "gtkentryprivate.h" #include "gtktextprivate.h"
#include "gtkeditable.h"
#include "gtkbox.h" #include "gtkbox.h"
#include "gtkcssprovider.h" #include "gtkcssprovider.h"
#include "gtklistbox.h" #include "gtklistbox.h"
@ -28,6 +29,7 @@
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkgesturelongpress.h" #include "gtkgesturelongpress.h"
#include "gtkeventcontrollerkey.h"
#include "gtkflowbox.h" #include "gtkflowbox.h"
#include "gtkstack.h" #include "gtkstack.h"
@ -35,7 +37,7 @@ struct _GtkEmojiCompletion
{ {
GtkPopover parent_instance; GtkPopover parent_instance;
GtkEntry *entry; GtkText *entry;
char *text; char *text;
guint length; guint length;
guint offset; guint offset;
@ -54,7 +56,7 @@ struct _GtkEmojiCompletionClass {
}; };
static void connect_signals (GtkEmojiCompletion *completion, static void connect_signals (GtkEmojiCompletion *completion,
GtkEntry *entry); GtkText *text);
static void disconnect_signals (GtkEmojiCompletion *completion); static void disconnect_signals (GtkEmojiCompletion *completion);
static int populate_completion (GtkEmojiCompletion *completion, static int populate_completion (GtkEmojiCompletion *completion,
const char *text, const char *text,
@ -86,7 +88,7 @@ update_completion (GtkEmojiCompletion *completion)
n_matches = 0; n_matches = 0;
text = gtk_entry_get_text (GTK_ENTRY (completion->entry)); text = gtk_editable_get_text (GTK_EDITABLE (completion->entry));
length = strlen (text); length = strlen (text);
if (length > 0) if (length > 0)
@ -125,7 +127,8 @@ next:
} }
static void static void
entry_changed (GtkEntry *entry, GtkEmojiCompletion *completion) changed_cb (GtkText *text,
GtkEmojiCompletion *completion)
{ {
update_completion (completion); update_completion (completion);
} }
@ -143,9 +146,9 @@ emoji_activated (GtkWidget *row,
g_signal_handler_block (completion->entry, completion->changed_id); g_signal_handler_block (completion->entry, completion->changed_id);
length = g_utf8_strlen (gtk_entry_get_text (completion->entry), -1); length = g_utf8_strlen (gtk_editable_get_text (GTK_EDITABLE (completion->entry)), -1);
gtk_entry_set_positions (completion->entry, length - completion->length, length); gtk_editable_select_region (GTK_EDITABLE (completion->entry), length - completion->length, length);
gtk_entry_enter_text (completion->entry, emoji); gtk_text_enter_text (completion->entry, emoji);
g_signal_handler_unblock (completion->entry, completion->changed_id); g_signal_handler_unblock (completion->entry, completion->changed_id);
} }
@ -167,7 +170,6 @@ child_activated (GtkFlowBox *box,
{ {
GtkEmojiCompletion *completion = data; GtkEmojiCompletion *completion = data;
g_print ("child activated\n");
emoji_activated (GTK_WIDGET (child), completion); emoji_activated (GTK_WIDGET (child), completion);
} }
@ -300,11 +302,11 @@ move_active_variation (GtkEmojiCompletion *completion,
} }
static gboolean static gboolean
entry_key_press (GtkEventControllerKey *key, key_press_cb (GtkEventControllerKey *key,
guint keyval, guint keyval,
guint keycode, guint keycode,
GdkModifierType modifiers, GdkModifierType modifiers,
GtkEmojiCompletion *completion) GtkEmojiCompletion *completion)
{ {
if (!gtk_widget_get_visible (GTK_WIDGET (completion))) if (!gtk_widget_get_visible (GTK_WIDGET (completion)))
return FALSE; return FALSE;
@ -368,27 +370,27 @@ entry_key_press (GtkEventControllerKey *key,
} }
static gboolean static gboolean
entry_focus_out (GtkWidget *entry, focus_out_cb (GtkWidget *text,
GParamSpec *pspec, GParamSpec *pspec,
GtkEmojiCompletion *completion) GtkEmojiCompletion *completion)
{ {
if (!gtk_widget_has_focus (entry)) if (!gtk_widget_has_focus (text))
gtk_popover_popdown (GTK_POPOVER (completion)); gtk_popover_popdown (GTK_POPOVER (completion));
return FALSE; return FALSE;
} }
static void static void
connect_signals (GtkEmojiCompletion *completion, connect_signals (GtkEmojiCompletion *completion,
GtkEntry *entry) GtkText *entry)
{ {
GtkEventController *key_controller; GtkEventController *key_controller;
completion->entry = g_object_ref (entry); completion->entry = g_object_ref (entry);
key_controller = gtk_entry_get_key_controller (entry); key_controller = gtk_text_get_key_controller (entry);
completion->changed_id = g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), completion); g_signal_connect (key_controller, "key-pressed", G_CALLBACK (key_press_cb), completion);
g_signal_connect (key_controller, "key-pressed", G_CALLBACK (entry_key_press), completion); completion->changed_id = g_signal_connect (entry, "changed", G_CALLBACK (changed_cb), completion);
g_signal_connect (entry, "notify::has-focus", G_CALLBACK (entry_focus_out), completion); g_signal_connect (entry, "notify::has-focus", G_CALLBACK (focus_out_cb), completion);
} }
static void static void
@ -396,11 +398,11 @@ disconnect_signals (GtkEmojiCompletion *completion)
{ {
GtkEventController *key_controller; GtkEventController *key_controller;
key_controller = gtk_entry_get_key_controller (completion->entry); key_controller = gtk_text_get_key_controller (completion->entry);
g_signal_handlers_disconnect_by_func (completion->entry, entry_changed, completion); g_signal_handlers_disconnect_by_func (completion->entry, changed_cb, completion);
g_signal_handlers_disconnect_by_func (key_controller, entry_key_press, completion); g_signal_handlers_disconnect_by_func (key_controller, key_press_cb, completion);
g_signal_handlers_disconnect_by_func (completion->entry, entry_focus_out, completion); g_signal_handlers_disconnect_by_func (completion->entry, focus_out_cb, completion);
g_clear_object (&completion->entry); g_clear_object (&completion->entry);
} }
@ -554,8 +556,8 @@ add_emoji (GtkWidget *list,
static int static int
populate_completion (GtkEmojiCompletion *completion, populate_completion (GtkEmojiCompletion *completion,
const char *text, const char *text,
guint offset) guint offset)
{ {
GList *children, *l; GList *children, *l;
guint n_matches; guint n_matches;
@ -657,15 +659,15 @@ gtk_emoji_completion_class_init (GtkEmojiCompletionClass *klass)
} }
GtkWidget * GtkWidget *
gtk_emoji_completion_new (GtkEntry *entry) gtk_emoji_completion_new (GtkText *text)
{ {
GtkEmojiCompletion *completion; GtkEmojiCompletion *completion;
completion = GTK_EMOJI_COMPLETION (g_object_new (GTK_TYPE_EMOJI_COMPLETION, completion = GTK_EMOJI_COMPLETION (g_object_new (GTK_TYPE_EMOJI_COMPLETION,
"relative-to", entry, "relative-to", text,
NULL)); NULL));
connect_signals (completion, entry); connect_signals (completion, text);
return GTK_WIDGET (completion); return GTK_WIDGET (completion);
} }

View File

@ -21,7 +21,7 @@
#error "Only <gtk/gtk.h> can be included directly." #error "Only <gtk/gtk.h> can be included directly."
#endif #endif
#include <gtk/gtkentry.h> #include <gtk/gtktext.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -36,6 +36,6 @@ typedef struct _GtkEmojiCompletion GtkEmojiCompletion;
typedef struct _GtkEmojiCompletionClass GtkEmojiCompletionClass; typedef struct _GtkEmojiCompletionClass GtkEmojiCompletionClass;
GType gtk_emoji_completion_get_type (void) G_GNUC_CONST; GType gtk_emoji_completion_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_emoji_completion_new (GtkEntry *entry); GtkWidget *gtk_emoji_completion_new (GtkText *text);
G_END_DECLS G_END_DECLS

File diff suppressed because it is too large Load Diff

View File

@ -115,28 +115,9 @@ struct _GtkEntryClass
{ {
GtkWidgetClass parent_class; GtkWidgetClass parent_class;
/* Hook to customize right-click popup */
void (* populate_popup) (GtkEntry *entry,
GtkWidget *popup);
/* Action signals /* Action signals
*/ */
void (* activate) (GtkEntry *entry); void (* activate) (GtkEntry *entry);
void (* move_cursor) (GtkEntry *entry,
GtkMovementStep step,
gint count,
gboolean extend_selection);
void (* insert_at_cursor) (GtkEntry *entry,
const gchar *str);
void (* delete_from_cursor) (GtkEntry *entry,
GtkDeleteType type,
gint count);
void (* backspace) (GtkEntry *entry);
void (* cut_clipboard) (GtkEntry *entry);
void (* copy_clipboard) (GtkEntry *entry);
void (* paste_clipboard) (GtkEntry *entry);
void (* toggle_overwrite) (GtkEntry *entry);
void (* insert_emoji) (GtkEntry *entry);
/*< private >*/ /*< private >*/
@ -224,12 +205,6 @@ void gtk_entry_set_text (GtkEntry *entry,
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
const gchar* gtk_entry_get_text (GtkEntry *entry); const gchar* gtk_entry_get_text (GtkEntry *entry);
GDK_AVAILABLE_IN_ALL
PangoLayout* gtk_entry_get_layout (GtkEntry *entry);
GDK_AVAILABLE_IN_ALL
void gtk_entry_get_layout_offsets (GtkEntry *entry,
gint *x,
gint *y);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_entry_set_alignment (GtkEntry *entry, void gtk_entry_set_alignment (GtkEntry *entry,
gfloat xalign); gfloat xalign);
@ -242,13 +217,6 @@ void gtk_entry_set_completion (GtkEntry *entry,
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkEntryCompletion *gtk_entry_get_completion (GtkEntry *entry); GtkEntryCompletion *gtk_entry_get_completion (GtkEntry *entry);
GDK_AVAILABLE_IN_ALL
gint gtk_entry_layout_index_to_text_index (GtkEntry *entry,
gint layout_index);
GDK_AVAILABLE_IN_ALL
gint gtk_entry_text_index_to_layout_index (GtkEntry *entry,
gint text_index);
/* Progress API /* Progress API
*/ */
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
@ -341,9 +309,6 @@ void gtk_entry_get_icon_area (GtkEntry *
GdkRectangle *icon_area); GdkRectangle *icon_area);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_entry_im_context_filter_keypress (GtkEntry *entry,
GdkEventKey *event);
GDK_AVAILABLE_IN_ALL
void gtk_entry_reset_im_context (GtkEntry *entry); void gtk_entry_reset_im_context (GtkEntry *entry);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -67,6 +67,7 @@
#include "gtkentrycompletion.h" #include "gtkentrycompletion.h"
#include "gtkentryprivate.h" #include "gtkentryprivate.h"
#include "gtktextprivate.h"
#include "gtkcelllayout.h" #include "gtkcelllayout.h"
#include "gtkcellareabox.h" #include "gtkcellareabox.h"
@ -496,8 +497,9 @@ propagate_to_entry (GtkEventControllerKey *key,
GtkEntryCompletion *completion) GtkEntryCompletion *completion)
{ {
GtkEntryCompletionPrivate *priv = completion->priv; GtkEntryCompletionPrivate *priv = completion->priv;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
return gtk_event_controller_key_forward (key, priv->entry); return gtk_event_controller_key_forward (key, GTK_WIDGET (text));
} }
static void static void
@ -894,6 +896,7 @@ gtk_entry_completion_list_activated (GtkTreeView *treeview,
gboolean entry_set; gboolean entry_set;
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter child_iter; GtkTreeIter child_iter;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model), &iter, path); gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model), &iter, path);
gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model, gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model,
@ -901,12 +904,10 @@ gtk_entry_completion_list_activated (GtkTreeView *treeview,
&iter); &iter);
model = gtk_tree_model_filter_get_model (completion->priv->filter_model); model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
g_signal_handler_block (completion->priv->entry, g_signal_handler_block (text, completion->priv->changed_id);
completion->priv->changed_id);
g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED], g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
0, model, &child_iter, &entry_set); 0, model, &child_iter, &entry_set);
g_signal_handler_unblock (completion->priv->entry, g_signal_handler_unblock (text, completion->priv->changed_id);
completion->priv->changed_id);
_gtk_entry_completion_popdown (completion); _gtk_entry_completion_popdown (completion);
} }
@ -1493,14 +1494,15 @@ static void
gtk_entry_completion_popup (GtkEntryCompletion *completion) gtk_entry_completion_popup (GtkEntryCompletion *completion)
{ {
GtkWidget *toplevel; GtkWidget *toplevel;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
if (gtk_widget_get_mapped (completion->priv->popup_window)) if (gtk_widget_get_mapped (completion->priv->popup_window))
return; return;
if (!gtk_widget_get_mapped (completion->priv->entry)) if (!gtk_widget_get_mapped (GTK_WIDGET (text)))
return; return;
if (!gtk_widget_has_focus (completion->priv->entry)) if (!gtk_widget_has_focus (GTK_WIDGET (text)))
return; return;
if (completion->priv->has_grab) if (completion->priv->has_grab)
@ -1709,29 +1711,30 @@ gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
static void static void
gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion, gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
const gchar *text) const gchar *new_text)
{ {
GtkEntryCompletionPrivate *priv = completion->priv; GtkEntryCompletionPrivate *priv = completion->priv;
gint len; gint len;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
priv = completion->priv; priv = completion->priv;
if (priv->changed_id > 0) if (priv->changed_id > 0)
g_signal_handler_block (priv->entry, priv->changed_id); g_signal_handler_block (text, priv->changed_id);
if (priv->insert_text_id > 0) if (priv->insert_text_id > 0)
g_signal_handler_block (priv->entry, priv->insert_text_id); g_signal_handler_block (text, priv->insert_text_id);
gtk_entry_set_text (GTK_ENTRY (priv->entry), text); gtk_editable_set_text (GTK_EDITABLE (priv->entry), new_text);
len = strlen (priv->completion_prefix); len = strlen (priv->completion_prefix);
gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1); gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
if (priv->changed_id > 0) if (priv->changed_id > 0)
g_signal_handler_unblock (priv->entry, priv->changed_id); g_signal_handler_unblock (text, priv->changed_id);
if (priv->insert_text_id > 0) if (priv->insert_text_id > 0)
g_signal_handler_unblock (priv->entry, priv->insert_text_id); g_signal_handler_unblock (text, priv->insert_text_id);
} }
static gboolean static gboolean
@ -1766,13 +1769,13 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
{ {
gboolean done; gboolean done;
gchar *prefix; gchar *prefix;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
if (completion->priv->insert_text_id > 0) if (completion->priv->insert_text_id > 0)
g_signal_handler_block (completion->priv->entry, g_signal_handler_block (text, completion->priv->insert_text_id);
completion->priv->insert_text_id);
prefix = gtk_entry_completion_compute_prefix (completion, prefix = gtk_entry_completion_compute_prefix (completion,
gtk_entry_get_text (GTK_ENTRY (completion->priv->entry))); gtk_editable_get_text (GTK_EDITABLE (completion->priv->entry)));
if (prefix) if (prefix)
{ {
@ -1782,8 +1785,7 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
} }
if (completion->priv->insert_text_id > 0) if (completion->priv->insert_text_id > 0)
g_signal_handler_unblock (completion->priv->entry, g_signal_handler_unblock (text, completion->priv->insert_text_id);
completion->priv->insert_text_id);
} }
/** /**
@ -2066,6 +2068,7 @@ gtk_entry_completion_key_pressed (GtkEventControllerKey *controller,
gint matches, actions = 0; gint matches, actions = 0;
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data); GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
GtkWidget *widget = completion->priv->entry; GtkWidget *widget = completion->priv->entry;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (widget));
if (!completion->priv->popup_completion) if (!completion->priv->popup_completion)
return FALSE; return FALSE;
@ -2296,10 +2299,10 @@ keypress_completion_out:
{ {
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter); gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
g_signal_handler_block (widget, completion->priv->changed_id); g_signal_handler_block (text, completion->priv->changed_id);
g_signal_emit_by_name (completion, "match-selected", g_signal_emit_by_name (completion, "match-selected",
child_model, &child_iter, &entry_set); child_model, &child_iter, &entry_set);
g_signal_handler_unblock (widget, completion->priv->changed_id); g_signal_handler_unblock (text, completion->priv->changed_id);
if (!entry_set) if (!entry_set)
{ {
@ -2349,7 +2352,6 @@ gtk_entry_completion_changed (GtkWidget *widget,
gpointer user_data) gpointer user_data)
{ {
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data); GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
GtkEntry *entry = GTK_ENTRY (widget);
GdkDevice *device; GdkDevice *device;
if (!completion->priv->popup_completion) if (!completion->priv->popup_completion)
@ -2362,12 +2364,12 @@ gtk_entry_completion_changed (GtkWidget *widget,
completion->priv->completion_timeout = 0; completion->priv->completion_timeout = 0;
} }
if (!gtk_entry_get_text (entry)) if (!gtk_editable_get_text (GTK_EDITABLE (widget)))
return; return;
/* no need to normalize for this test */ /* no need to normalize for this test */
if (completion->priv->minimum_key_length > 0 && if (completion->priv->minimum_key_length > 0 &&
strcmp ("", gtk_entry_get_text (entry)) == 0) strcmp ("", gtk_editable_get_text (GTK_EDITABLE (widget))) == 0)
{ {
if (gtk_widget_get_visible (completion->priv->popup_window)) if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion); _gtk_entry_completion_popdown (completion);
@ -2401,11 +2403,10 @@ check_completion_callback (GtkEntryCompletion *completion)
} }
static void static void
clear_completion_callback (GtkEntry *entry, clear_completion_callback (GObject *text,
GParamSpec *pspec) GParamSpec *pspec,
GtkEntryCompletion *completion)
{ {
GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
if (!completion->priv->inline_completion) if (!completion->priv->inline_completion)
return; return;
@ -2415,22 +2416,20 @@ clear_completion_callback (GtkEntry *entry,
} }
static gboolean static gboolean
accept_completion_callback (GtkEntry *entry) accept_completion_callback (GtkEntryCompletion *completion)
{ {
GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
if (!completion->priv->inline_completion) if (!completion->priv->inline_completion)
return FALSE; return FALSE;
if (completion->priv->has_completion) if (completion->priv->has_completion)
gtk_editable_set_position (GTK_EDITABLE (entry), gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry),
gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry))); gtk_entry_buffer_get_length (gtk_entry_get_buffer (GTK_ENTRY (completion->priv->entry))));
return FALSE; return FALSE;
} }
static void static void
completion_insert_text_callback (GtkEntry *entry, completion_insert_text_callback (GtkText *entry,
const gchar *text, const gchar *text,
gint length, gint length,
gint position, gint position,
@ -2457,26 +2456,21 @@ connect_completion_signals (GtkEntryCompletion *completion)
{ {
GtkEntryCompletionPrivate *priv = completion->priv; GtkEntryCompletionPrivate *priv = completion->priv;
GtkEventController *controller; GtkEventController *controller;
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
controller = priv->entry_key_controller = gtk_event_controller_key_new (); controller = priv->entry_key_controller = gtk_event_controller_key_new ();
g_signal_connect (controller, "key-pressed", g_signal_connect (controller, "key-pressed",
G_CALLBACK (gtk_entry_completion_key_pressed), completion); G_CALLBACK (gtk_entry_completion_key_pressed), completion);
g_signal_connect_swapped (controller, "focus-out", g_signal_connect_swapped (controller, "focus-out", G_CALLBACK (accept_completion_callback), completion);
G_CALLBACK (accept_completion_callback), gtk_widget_add_controller (GTK_WIDGET (text), controller);
completion->priv->entry);
gtk_widget_add_controller (completion->priv->entry, controller);
completion->priv->changed_id = completion->priv->changed_id =
g_signal_connect (completion->priv->entry, "changed", g_signal_connect (text, "changed", G_CALLBACK (gtk_entry_completion_changed), completion);
G_CALLBACK (gtk_entry_completion_changed), completion);
completion->priv->insert_text_id = completion->priv->insert_text_id =
g_signal_connect (completion->priv->entry, "insert-text", g_signal_connect (text, "insert-text", G_CALLBACK (completion_insert_text_callback), completion);
G_CALLBACK (completion_insert_text_callback), completion); g_signal_connect (text, "notify", G_CALLBACK (clear_completion_callback), completion);
g_signal_connect (completion->priv->entry, "notify", g_signal_connect_swapped (text, "activate", G_CALLBACK (accept_completion_callback), completion);
G_CALLBACK (clear_completion_callback), completion);
g_signal_connect (completion->priv->entry, "activate",
G_CALLBACK (accept_completion_callback), completion);
} }
static void static void
@ -2512,31 +2506,25 @@ unset_accessible_relation (GtkWidget *window,
static void static void
disconnect_completion_signals (GtkEntryCompletion *completion) disconnect_completion_signals (GtkEntryCompletion *completion)
{ {
gtk_widget_remove_controller (completion->priv->entry, GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
completion->priv->entry_key_controller);
gtk_widget_remove_controller (GTK_WIDGET (text), completion->priv->entry_key_controller);
if (completion->priv->changed_id > 0 && if (completion->priv->changed_id > 0 &&
g_signal_handler_is_connected (completion->priv->entry, g_signal_handler_is_connected (text, completion->priv->changed_id))
completion->priv->changed_id))
{ {
g_signal_handler_disconnect (completion->priv->entry, g_signal_handler_disconnect (text, completion->priv->changed_id);
completion->priv->changed_id);
completion->priv->changed_id = 0; completion->priv->changed_id = 0;
} }
if (completion->priv->insert_text_id > 0 && if (completion->priv->insert_text_id > 0 &&
g_signal_handler_is_connected (completion->priv->entry, g_signal_handler_is_connected (text, completion->priv->insert_text_id))
completion->priv->insert_text_id))
{ {
g_signal_handler_disconnect (completion->priv->entry, g_signal_handler_disconnect (text, completion->priv->insert_text_id);
completion->priv->insert_text_id);
completion->priv->insert_text_id = 0; completion->priv->insert_text_id = 0;
} }
g_signal_handlers_disconnect_by_func (completion->priv->entry, g_signal_handlers_disconnect_by_func (text, G_CALLBACK (completion_insert_text_callback), completion);
G_CALLBACK (completion_insert_text_callback), completion); g_signal_handlers_disconnect_by_func (text, G_CALLBACK (clear_completion_callback), completion);
g_signal_handlers_disconnect_by_func (completion->priv->entry, g_signal_handlers_disconnect_by_func (text, G_CALLBACK (accept_completion_callback), completion);
G_CALLBACK (clear_completion_callback), completion);
g_signal_handlers_disconnect_by_func (completion->priv->entry,
G_CALLBACK (accept_completion_callback), completion);
} }
void void

View File

@ -26,6 +26,7 @@
#include "gtktreemodelfilter.h" #include "gtktreemodelfilter.h"
#include "gtktreeviewcolumn.h" #include "gtktreeviewcolumn.h"
#include "gtkeventcontrollerkey.h" #include "gtkeventcontrollerkey.h"
#include "gtktextprivate.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -84,17 +85,12 @@ void _gtk_entry_completion_connect (GtkEntryCompletion *completion,
GtkEntry *entry); GtkEntry *entry);
void _gtk_entry_completion_disconnect (GtkEntryCompletion *completion); void _gtk_entry_completion_disconnect (GtkEntryCompletion *completion);
gchar* _gtk_entry_get_display_text (GtkEntry *entry,
gint start_pos,
gint end_pos);
GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry); GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry);
void gtk_entry_enter_text (GtkEntry *entry, void gtk_entry_enter_text (GtkEntry *entry,
const char *text); const char *text);
void gtk_entry_set_positions (GtkEntry *entry,
int current_pos,
int selection_bound);
GtkEventController * gtk_entry_get_key_controller (GtkEntry *entry); GtkEventController * gtk_entry_get_key_controller (GtkEntry *entry);
GtkText *gtk_entry_get_text_widget (GtkEntry *entry);
G_END_DECLS G_END_DECLS

View File

@ -3064,7 +3064,7 @@ operation_mode_set_search (GtkFileChooserWidget *impl)
gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list"); gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
} }
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->search_entry)); gtk_widget_grab_focus (priv->search_entry);
gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "search"); gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "search");
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->browse_header_revealer), TRUE); gtk_revealer_set_reveal_child (GTK_REVEALER (priv->browse_header_revealer), TRUE);
location_bar_update (impl); location_bar_update (impl);
@ -7043,7 +7043,7 @@ search_engine_finished_cb (GtkSearchEngine *engine,
if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->search_model), NULL) == 0) if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->search_model), NULL) == 0)
{ {
gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "empty"); gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "empty");
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->search_entry)); gtk_widget_grab_focus (priv->search_entry);
} }
} }
@ -7084,7 +7084,7 @@ search_stop_searching (GtkFileChooserWidget *impl,
if (remove_query && priv->search_entry) if (remove_query && priv->search_entry)
{ {
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (priv->search_entry), "");
} }
if (priv->search_engine) if (priv->search_engine)
@ -7218,7 +7218,7 @@ search_entry_activate_cb (GtkFileChooserWidget *impl)
if (priv->operation_mode != OPERATION_MODE_SEARCH) if (priv->operation_mode != OPERATION_MODE_SEARCH)
return; return;
text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); text = gtk_editable_get_text (GTK_EDITABLE (priv->search_entry));
/* reset any existing query object */ /* reset any existing query object */
g_set_object (&priv->search_query, NULL); g_set_object (&priv->search_query, NULL);
@ -7254,7 +7254,7 @@ search_setup_widgets (GtkFileChooserWidget *impl)
query = gtk_query_get_text (priv->search_query); query = gtk_query_get_text (priv->search_query);
if (query) if (query)
{ {
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), query); gtk_editable_set_text (GTK_EDITABLE (priv->search_entry), query);
search_start_query (impl, query); search_start_query (impl, query);
} }
else else

View File

@ -372,11 +372,11 @@ text_changed_cb (GtkEntry *entry,
} }
static void static void
stop_search_cb (GtkEntry *entry, stop_search_cb (GtkSearchEntry *entry,
GtkFontChooserWidget *fc) GtkFontChooserWidget *fc)
{ {
if (gtk_entry_get_text (entry)[0] != 0) if (gtk_editable_get_text (GTK_EDITABLE (entry))[0] != 0)
gtk_entry_set_text (entry, ""); gtk_editable_set_text (GTK_EDITABLE (entry), "");
else else
{ {
GtkWidget *dialog; GtkWidget *dialog;
@ -623,7 +623,7 @@ gtk_font_chooser_widget_map (GtkWidget *widget)
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget); GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
GtkFontChooserWidgetPrivate *priv = fontchooser->priv; GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (priv->search_entry), "");
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "list"); gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "list");
g_simple_action_set_state (G_SIMPLE_ACTION (priv->tweak_action), g_variant_new_boolean (FALSE)); g_simple_action_set_state (G_SIMPLE_ACTION (priv->tweak_action), g_variant_new_boolean (FALSE));
@ -767,7 +767,7 @@ change_tweak (GSimpleAction *action,
} }
else else
{ {
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (fontchooser->priv->search_entry)); gtk_widget_grab_focus (fontchooser->priv->search_entry);
gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->priv->stack), "list"); gtk_stack_set_visible_child_name (GTK_STACK (fontchooser->priv->stack), "list");
} }
@ -1034,7 +1034,7 @@ visible_func (GtkTreeModel *model,
} }
/* If there's no filter string we show the item */ /* If there's no filter string we show the item */
search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); search_text = gtk_editable_get_text (GTK_EDITABLE (priv->search_entry));
if (strlen (search_text) == 0) if (strlen (search_text) == 0)
return TRUE; return TRUE;

271
gtk/gtkpasswordentry.c Normal file
View File

@ -0,0 +1,271 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2019 Red Hat, Inc.
*
* Authors:
* - Matthias Clasen <mclasen@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkpasswordentry.h"
#include "gtkaccessible.h"
#include "gtkbindings.h"
#include "gtktextprivate.h"
#include "gtkeditable.h"
#include "gtkbox.h"
#include "gtkimage.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtkstylecontext.h"
#include "gtkeventcontrollerkey.h"
#include "a11y/gtkentryaccessible.h"
/**
* SECTION:gtkpasswordhentry
* @Short_description: An entry for secrets
* @Title: GtkPasswordEntry
*
* #GtkPasswordEntry is entry that has been tailored for
* entering secrets.
*/
typedef struct {
GtkWidget *box;
GtkWidget *entry;
GtkWidget *icon;
GdkKeymap *keymap;
} GtkPasswordEntryPrivate;
static void gtk_password_entry_editable_init (GtkEditableInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkPasswordEntry, gtk_password_entry, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkPasswordEntry)
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_password_entry_editable_init))
static void
keymap_state_changed (GdkKeymap *keymap,
GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
if (gtk_editable_get_editable (GTK_EDITABLE (entry)) &&
gtk_widget_has_focus (priv->entry) &&
gdk_keymap_get_caps_lock_state (priv->keymap))
gtk_widget_show (priv->icon);
else
gtk_widget_hide (priv->icon);
}
static void
focus_changed (GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
if (priv->keymap)
keymap_state_changed (priv->keymap, widget);
}
static void
gtk_password_entry_init (GtkPasswordEntry *entry)
{
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
gtk_widget_set_has_surface (GTK_WIDGET (entry), FALSE);
priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_parent (priv->box, GTK_WIDGET (entry));
priv->entry = gtk_text_new ();
gtk_text_set_visibility (GTK_TEXT (priv->entry), FALSE);
gtk_widget_set_hexpand (priv->entry, TRUE);
gtk_widget_set_vexpand (priv->entry, TRUE);
gtk_container_add (GTK_CONTAINER (priv->box), priv->entry);
gtk_editable_init_delegate (GTK_EDITABLE (entry));
g_signal_connect_swapped (priv->entry, "notify::has-focus", G_CALLBACK (focus_changed), entry);
priv->icon = gtk_image_new_from_icon_name ("dialog-warning-symbolic");
gtk_widget_set_tooltip_text (priv->icon, _("Caps Lock is on"));
gtk_container_add (GTK_CONTAINER (priv->box), priv->icon);
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (entry)), I_("password"));
}
static void
gtk_password_entry_realize (GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
GTK_WIDGET_CLASS (gtk_password_entry_parent_class)->realize (widget);
priv->keymap = gdk_display_get_keymap (gtk_widget_get_display (widget));
g_signal_connect (priv->keymap, "state-changed", G_CALLBACK (keymap_state_changed), entry);
}
static void
gtk_password_entry_dispose (GObject *object)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
if (priv->keymap)
g_signal_handlers_disconnect_by_func (priv->keymap, keymap_state_changed, entry);
if (priv->entry)
gtk_editable_finish_delegate (GTK_EDITABLE (entry));
g_clear_pointer (&priv->entry, gtk_widget_unparent);
g_clear_pointer (&priv->icon, gtk_widget_unparent);
g_clear_pointer (&priv->box, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_password_entry_parent_class)->dispose (object);
}
static void
gtk_password_entry_finalize (GObject *object)
{
G_OBJECT_CLASS (gtk_password_entry_parent_class)->finalize (object);
}
static void
gtk_password_entry_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
return;
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
static void
gtk_password_entry_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
return;
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
static void
gtk_password_entry_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
gtk_widget_measure (priv->box, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_password_entry_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
gtk_widget_size_allocate (priv->box,
&(GtkAllocation) { 0, 0, width, height },
baseline);
}
static AtkObject *
gtk_password_entry_get_accessible (GtkWidget *widget)
{
AtkObject *atk_obj;
atk_obj = GTK_WIDGET_CLASS (gtk_password_entry_parent_class)->get_accessible (widget);
atk_object_set_name (atk_obj, _("Password"));
return atk_obj;
}
static void
gtk_password_entry_grab_focus (GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
gtk_widget_grab_focus (priv->entry);
}
static void
gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = gtk_password_entry_dispose;
object_class->finalize = gtk_password_entry_finalize;
object_class->get_property = gtk_password_entry_get_property;
object_class->set_property = gtk_password_entry_set_property;
widget_class->realize = gtk_password_entry_realize;
widget_class->measure = gtk_password_entry_measure;
widget_class->size_allocate = gtk_password_entry_size_allocate;
widget_class->get_accessible = gtk_password_entry_get_accessible;
widget_class->grab_focus = gtk_password_entry_grab_focus;
gtk_editable_install_properties (object_class, 1);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("entry"));
}
static GtkEditable *
gtk_password_entry_get_delegate (GtkEditable *editable)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (editable);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
return GTK_EDITABLE (priv->entry);
}
static void
gtk_password_entry_editable_init (GtkEditableInterface *iface)
{
iface->get_delegate = gtk_password_entry_get_delegate;
}
/**
* gtk_password_entry_new:
*
* Creates a #GtkPasswordEntry.
*
* Returns: a new #GtkPasswordEntry
*/
GtkWidget *
gtk_password_entry_new (void)
{
return GTK_WIDGET (g_object_new (GTK_TYPE_PASSWORD_ENTRY, NULL));
}

60
gtk/gtkpasswordentry.h Normal file
View File

@ -0,0 +1,60 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2019 Red Hat, Inc.
*
* Authors:
* - MAtthias Clasen <mclasen@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_PASSWORD_ENTRY_H__
#define __GTK_PASSWORD_ENTRY_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkentry.h>
G_BEGIN_DECLS
#define GTK_TYPE_PASSWORD_ENTRY (gtk_password_entry_get_type ())
#define GTK_PASSWORD_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PASSWORD_ENTRY, GtkPasswordEntry))
#define GTK_PASSWORD_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PASSWORD_ENTRY, GtkPasswordEntryClass))
#define GTK_IS_PASSWORD_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PASSWORD_ENTRY))
#define GTK_IS_PASSWORD_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PASSWORD_ENTRY))
#define GTK_PASSWORD_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PASSWORD_ENTRY, GtkPasswordEntryClass))
typedef struct _GtkPasswordEntry GtkPasswordEntry;
typedef struct _GtkPasswordEntryClass GtkPasswordEntryClass;
struct _GtkPasswordEntry
{
GtkWidget parent;
};
struct _GtkPasswordEntryClass
{
GtkWidgetClass parent_class;
};
GDK_AVAILABLE_IN_ALL
GType gtk_password_entry_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_password_entry_new (void);
G_END_DECLS
#endif /* __GTK_PASSWORD_ENTRY_H__ */

View File

@ -148,9 +148,9 @@ gtk_search_bar_handle_event_for_entry (GtkSearchBar *bar,
preedit_change_id = g_signal_connect (priv->entry, "preedit-changed", preedit_change_id = g_signal_connect (priv->entry, "preedit-changed",
G_CALLBACK (preedit_changed_cb), &preedit_changed); G_CALLBACK (preedit_changed_cb), &preedit_changed);
old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))); old_text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (priv->entry)));
res = gtk_widget_event (priv->entry, event); res = gtk_widget_event (priv->entry, event);
new_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))); new_text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (priv->entry)));
g_signal_handler_disconnect (priv->entry, preedit_change_id); g_signal_handler_disconnect (priv->entry, preedit_change_id);
@ -255,10 +255,12 @@ reveal_child_changed_cb (GObject *object,
if (priv->entry) if (priv->entry)
{ {
if (reveal_child) if (reveal_child && GTK_IS_ENTRY (priv->entry))
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->entry)); gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->entry));
else if (GTK_IS_SEARCH_ENTRY (priv->entry))
gtk_widget_grab_focus (priv->entry);
else else
gtk_entry_set_text (GTK_ENTRY (priv->entry), ""); gtk_editable_set_text (GTK_EDITABLE (priv->entry), "");
} }
g_object_notify (G_OBJECT (bar), "search-mode-enabled"); g_object_notify (G_OBJECT (bar), "search-mode-enabled");
@ -284,8 +286,8 @@ gtk_search_bar_add (GtkContainer *container,
/* If an entry is the only child, save the developer a couple of /* If an entry is the only child, save the developer a couple of
* lines of code * lines of code
*/ */
if (GTK_IS_ENTRY (child)) if (GTK_IS_EDITABLE (child))
gtk_search_bar_connect_entry (bar, GTK_ENTRY (child)); gtk_search_bar_connect_entry (bar, GTK_EDITABLE (child));
_gtk_bin_set_child (GTK_BIN (container), child); _gtk_bin_set_child (GTK_BIN (container), child);
} }
@ -297,7 +299,7 @@ gtk_search_bar_remove (GtkContainer *container,
GtkSearchBar *bar = GTK_SEARCH_BAR (container); GtkSearchBar *bar = GTK_SEARCH_BAR (container);
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar); GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
if (GTK_IS_ENTRY (child)) if (GTK_IS_EDITABLE (child))
gtk_search_bar_connect_entry (bar, NULL); gtk_search_bar_connect_entry (bar, NULL);
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->box_center), NULL); gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->box_center), NULL);
@ -350,7 +352,7 @@ gtk_search_bar_get_property (GObject *object,
} }
static void gtk_search_bar_set_entry (GtkSearchBar *bar, static void gtk_search_bar_set_entry (GtkSearchBar *bar,
GtkEntry *entry); GtkEditable *editable);
static void static void
gtk_search_bar_dispose (GObject *object) gtk_search_bar_dispose (GObject *object)
@ -494,7 +496,7 @@ gtk_search_bar_new (void)
static void static void
gtk_search_bar_set_entry (GtkSearchBar *bar, gtk_search_bar_set_entry (GtkSearchBar *bar,
GtkEntry *entry) GtkEditable *entry)
{ {
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar); GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
@ -527,7 +529,7 @@ gtk_search_bar_set_entry (GtkSearchBar *bar,
/** /**
* gtk_search_bar_connect_entry: * gtk_search_bar_connect_entry:
* @bar: a #GtkSearchBar * @bar: a #GtkSearchBar
* @entry: a #GtkEntry * @entry: a #GtkEditable
* *
* Connects the #GtkEntry widget passed as the one to be used in * Connects the #GtkEntry widget passed as the one to be used in
* this search bar. The entry should be a descendant of the search bar. * this search bar. The entry should be a descendant of the search bar.
@ -536,10 +538,10 @@ gtk_search_bar_set_entry (GtkSearchBar *bar,
*/ */
void void
gtk_search_bar_connect_entry (GtkSearchBar *bar, gtk_search_bar_connect_entry (GtkSearchBar *bar,
GtkEntry *entry) GtkEditable *entry)
{ {
g_return_if_fail (GTK_IS_SEARCH_BAR (bar)); g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry)); g_return_if_fail (entry == NULL || GTK_IS_EDITABLE (entry));
gtk_search_bar_set_entry (bar, entry); gtk_search_bar_set_entry (bar, entry);
} }

View File

@ -78,7 +78,7 @@ GtkWidget* gtk_search_bar_new (void);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_search_bar_connect_entry (GtkSearchBar *bar, void gtk_search_bar_connect_entry (GtkSearchBar *bar,
GtkEntry *entry); GtkEditable *entry);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_search_bar_get_search_mode (GtkSearchBar *bar); gboolean gtk_search_bar_get_search_mode (GtkSearchBar *bar);

View File

@ -31,7 +31,13 @@
#include "gtkaccessible.h" #include "gtkaccessible.h"
#include "gtkbindings.h" #include "gtkbindings.h"
#include "gtkeditable.h"
#include "gtkbox.h"
#include "gtkgesturemultipress.h"
#include "gtktextprivate.h"
#include "gtkimage.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkmarshalers.h" #include "gtkmarshalers.h"
#include "gtkstylecontext.h" #include "gtkstylecontext.h"
#include "gtkeventcontrollerkey.h" #include "gtkeventcontrollerkey.h"
@ -69,6 +75,7 @@
*/ */
enum { enum {
ACTIVATE,
SEARCH_CHANGED, SEARCH_CHANGED,
NEXT_MATCH, NEXT_MATCH,
PREVIOUS_MATCH, PREVIOUS_MATCH,
@ -76,25 +83,33 @@ enum {
LAST_SIGNAL LAST_SIGNAL
}; };
enum {
PROP_0,
PROP_PLACEHOLDER_TEXT,
PROP_ACTIVATES_DEFAULT,
NUM_PROPERTIES,
};
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
typedef struct { typedef struct {
GtkWidget *capture_widget; GtkWidget *capture_widget;
GtkEventController *capture_widget_controller; GtkEventController *capture_widget_controller;
GtkWidget *box;
GtkWidget *entry;
GtkWidget *icon;
guint delayed_changed_id; guint delayed_changed_id;
gboolean content_changed; gboolean content_changed;
gboolean search_stopped; gboolean search_stopped;
} GtkSearchEntryPrivate; } GtkSearchEntryPrivate;
static void gtk_search_entry_icon_release (GtkEntry *entry,
GtkEntryIconPosition icon_pos);
static void gtk_search_entry_changed (GtkEditable *editable);
static void gtk_search_entry_editable_init (GtkEditableInterface *iface); static void gtk_search_entry_editable_init (GtkEditableInterface *iface);
static GtkEditableInterface *parent_editable_iface; G_DEFINE_TYPE_WITH_CODE (GtkSearchEntry, gtk_search_entry, GTK_TYPE_WIDGET,
G_DEFINE_TYPE_WITH_CODE (GtkSearchEntry, gtk_search_entry, GTK_TYPE_ENTRY,
G_ADD_PRIVATE (GtkSearchEntry) G_ADD_PRIVATE (GtkSearchEntry)
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
gtk_search_entry_editable_init)) gtk_search_entry_editable_init))
@ -102,36 +117,23 @@ G_DEFINE_TYPE_WITH_CODE (GtkSearchEntry, gtk_search_entry, GTK_TYPE_ENTRY,
/* 150 mseconds of delay */ /* 150 mseconds of delay */
#define DELAYED_TIMEOUT_ID 150 #define DELAYED_TIMEOUT_ID 150
/* This widget got created without a private structure, meaning
* that we cannot now have one without breaking ABI */
#define GET_PRIV(e) ((GtkSearchEntryPrivate *) gtk_search_entry_get_instance_private ((GtkSearchEntry *) (e)))
static void static void
gtk_search_entry_preedit_changed (GtkEntry *entry, text_changed (GtkSearchEntry *entry)
const gchar *preedit)
{ {
GtkSearchEntryPrivate *priv = GET_PRIV (entry); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
priv->content_changed = TRUE; priv->content_changed = TRUE;
} }
static void
gtk_search_entry_notify (GObject *object,
GParamSpec *pspec)
{
GtkSearchEntryPrivate *priv = GET_PRIV (object);
if (strcmp (pspec->name, "text") == 0)
priv->content_changed = TRUE;
if (G_OBJECT_CLASS (gtk_search_entry_parent_class)->notify)
G_OBJECT_CLASS (gtk_search_entry_parent_class)->notify (object, pspec);
}
static void static void
gtk_search_entry_finalize (GObject *object) gtk_search_entry_finalize (GObject *object)
{ {
GtkSearchEntryPrivate *priv = GET_PRIV (object); GtkSearchEntry *entry = GTK_SEARCH_ENTRY (object);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gtk_editable_finish_delegate (GTK_EDITABLE (entry));
g_clear_pointer (&priv->box, gtk_widget_unparent);
if (priv->delayed_changed_id > 0) if (priv->delayed_changed_id > 0)
g_source_remove (priv->delayed_changed_id); g_source_remove (priv->delayed_changed_id);
@ -144,29 +146,147 @@ gtk_search_entry_finalize (GObject *object)
static void static void
gtk_search_entry_stop_search (GtkSearchEntry *entry) gtk_search_entry_stop_search (GtkSearchEntry *entry)
{ {
GtkSearchEntryPrivate *priv = GET_PRIV (entry); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
priv->search_stopped = TRUE; priv->search_stopped = TRUE;
} }
static void
gtk_search_entry_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (object);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
return;
switch (prop_id)
{
case PROP_PLACEHOLDER_TEXT:
gtk_text_set_placeholder_text (GTK_TEXT (priv->entry), g_value_get_string (value));
break;
case PROP_ACTIVATES_DEFAULT:
gtk_text_set_activates_default (GTK_TEXT (priv->entry), g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gtk_search_entry_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (object);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
return;
switch (prop_id)
{
case PROP_PLACEHOLDER_TEXT:
g_value_set_string (value, gtk_text_get_placeholder_text (GTK_TEXT (priv->entry)));
break;
case PROP_ACTIVATES_DEFAULT:
g_value_set_boolean (value, gtk_text_get_activates_default (GTK_TEXT (priv->entry)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gtk_search_entry_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (widget);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gtk_widget_measure (priv->box, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_search_entry_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (widget);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gtk_widget_size_allocate (priv->box,
&(GtkAllocation) { 0, 0, width, height },
baseline);
}
static void
gtk_search_entry_grab_focus (GtkWidget *widget)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (widget);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gtk_text_grab_focus_without_selecting (GTK_TEXT (priv->entry));
}
static void static void
gtk_search_entry_class_init (GtkSearchEntryClass *klass) gtk_search_entry_class_init (GtkSearchEntryClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkBindingSet *binding_set; GtkBindingSet *binding_set;
object_class->finalize = gtk_search_entry_finalize; object_class->finalize = gtk_search_entry_finalize;
object_class->notify = gtk_search_entry_notify; object_class->get_property = gtk_search_entry_get_property;
object_class->set_property = gtk_search_entry_set_property;
widget_class->measure = gtk_search_entry_measure;
widget_class->size_allocate = gtk_search_entry_size_allocate;
widget_class->grab_focus = gtk_search_entry_grab_focus;
klass->stop_search = gtk_search_entry_stop_search; klass->stop_search = gtk_search_entry_stop_search;
g_signal_override_class_handler ("icon-release", props[PROP_PLACEHOLDER_TEXT] =
GTK_TYPE_SEARCH_ENTRY, g_param_spec_string ("placeholder-text",
G_CALLBACK (gtk_search_entry_icon_release)); P_("Placeholder text"),
P_("Show text in the entry when its empty and unfocused"),
NULL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_signal_override_class_handler ("preedit-changed", props[PROP_ACTIVATES_DEFAULT] =
GTK_TYPE_SEARCH_ENTRY, g_param_spec_boolean ("activates-default",
G_CALLBACK (gtk_search_entry_preedit_changed)); P_("Activates default"),
P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
gtk_editable_install_properties (object_class, NUM_PROPERTIES);
signals[ACTIVATE] =
g_signal_new (I_("activate"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkSearchEntryClass, activate),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/** /**
* GtkSearchEntry::search-changed: * GtkSearchEntry::search-changed:
@ -257,37 +377,42 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
"previous-match", 0); "previous-match", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
"stop-search", 0); "stop-search", 0);
gtk_widget_class_set_css_name (widget_class, I_("entry"));
}
static GtkEditable *
gtk_search_entry_get_delegate (GtkEditable *editable)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (editable);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
return GTK_EDITABLE (priv->entry);
} }
static void static void
gtk_search_entry_editable_init (GtkEditableInterface *iface) gtk_search_entry_editable_init (GtkEditableInterface *iface)
{ {
parent_editable_iface = g_type_interface_peek_parent (iface); iface->get_delegate = gtk_search_entry_get_delegate;
iface->do_insert_text = parent_editable_iface->do_insert_text;
iface->do_delete_text = parent_editable_iface->do_delete_text;
iface->insert_text = parent_editable_iface->insert_text;
iface->delete_text = parent_editable_iface->delete_text;
iface->get_chars = parent_editable_iface->get_chars;
iface->set_selection_bounds = parent_editable_iface->set_selection_bounds;
iface->get_selection_bounds = parent_editable_iface->get_selection_bounds;
iface->set_position = parent_editable_iface->set_position;
iface->get_position = parent_editable_iface->get_position;
iface->changed = gtk_search_entry_changed;
} }
static void static void
gtk_search_entry_icon_release (GtkEntry *entry, gtk_search_entry_icon_release (GtkGestureMultiPress *press,
GtkEntryIconPosition icon_pos) int n_press,
double x,
double y,
GtkSearchEntry *entry)
{ {
if (icon_pos == GTK_ENTRY_ICON_SECONDARY) GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gtk_entry_set_text (entry, "");
gtk_editable_set_text (GTK_EDITABLE (priv->entry), "");
} }
static gboolean static gboolean
gtk_search_entry_changed_timeout_cb (gpointer user_data) gtk_search_entry_changed_timeout_cb (gpointer user_data)
{ {
GtkSearchEntry *entry = user_data; GtkSearchEntry *entry = user_data;
GtkSearchEntryPrivate *priv = GET_PRIV (entry); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
g_signal_emit (entry, signals[SEARCH_CHANGED], 0); g_signal_emit (entry, signals[SEARCH_CHANGED], 0);
priv->delayed_changed_id = 0; priv->delayed_changed_id = 0;
@ -298,7 +423,7 @@ gtk_search_entry_changed_timeout_cb (gpointer user_data)
static void static void
reset_timeout (GtkSearchEntry *entry) reset_timeout (GtkSearchEntry *entry)
{ {
GtkSearchEntryPrivate *priv = GET_PRIV (entry); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
if (priv->delayed_changed_id > 0) if (priv->delayed_changed_id > 0)
g_source_remove (priv->delayed_changed_id); g_source_remove (priv->delayed_changed_id);
@ -309,35 +434,19 @@ reset_timeout (GtkSearchEntry *entry)
} }
static void static void
gtk_search_entry_changed (GtkEditable *editable) gtk_search_entry_changed (GtkEditable *editable,
GtkSearchEntry *entry)
{ {
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (editable); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
GtkSearchEntryPrivate *priv = GET_PRIV (entry); const char *str;
const char *str, *icon_name;
gboolean cleared;
/* Update the icons first */ /* Update the icons first */
str = gtk_entry_get_text (GTK_ENTRY (entry)); str = gtk_editable_get_text (GTK_EDITABLE (priv->entry));
if (str == NULL || *str == '\0') if (str == NULL || *str == '\0')
{ {
icon_name = NULL; gtk_widget_hide (priv->icon);
cleared = TRUE;
}
else
{
icon_name = "edit-clear-symbolic";
cleared = FALSE;
}
g_object_set (entry,
"secondary-icon-name", icon_name,
"secondary-icon-activatable", !cleared,
"secondary-icon-sensitive", !cleared,
NULL);
if (cleared)
{
if (priv->delayed_changed_id > 0) if (priv->delayed_changed_id > 0)
{ {
g_source_remove (priv->delayed_changed_id); g_source_remove (priv->delayed_changed_id);
@ -347,21 +456,62 @@ gtk_search_entry_changed (GtkEditable *editable)
} }
else else
{ {
gtk_widget_show (priv->icon);
/* Queue up the timeout */ /* Queue up the timeout */
reset_timeout (entry); reset_timeout (entry);
} }
} }
static void
notify_cb (GObject *object,
GParamSpec *pspec,
gpointer data)
{
/* The editable interface properties are already forwarded by the editable delegate setup */
if (g_str_equal (pspec->name, "placeholder-text") ||
g_str_equal (pspec->name, "activates-default"))
g_object_notify (data, pspec->name);
}
static void
activate_cb (GtkText *text,
gpointer data)
{
g_signal_emit (data, signals[ACTIVATE], 0);
}
static void static void
gtk_search_entry_init (GtkSearchEntry *entry) gtk_search_entry_init (GtkSearchEntry *entry)
{ {
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
AtkObject *atk_obj; AtkObject *atk_obj;
GtkGesture *press;
g_object_set (entry, gtk_widget_set_has_surface (GTK_WIDGET (entry), FALSE);
"primary-icon-name", "edit-find-symbolic",
"primary-icon-activatable", FALSE, priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
"primary-icon-sensitive", FALSE, gtk_widget_set_parent (priv->box, GTK_WIDGET (entry));
NULL);
priv->entry = gtk_text_new ();
gtk_widget_set_hexpand (priv->entry, TRUE);
gtk_widget_set_vexpand (priv->entry, TRUE);
gtk_container_add (GTK_CONTAINER (priv->box), GTK_WIDGET (priv->entry));
gtk_editable_init_delegate (GTK_EDITABLE (entry));
g_signal_connect_swapped (priv->entry, "changed", G_CALLBACK (text_changed), entry);
g_signal_connect_after (priv->entry, "changed", G_CALLBACK (gtk_search_entry_changed), entry);
g_signal_connect_swapped (priv->entry, "preedit-changed", G_CALLBACK (text_changed), entry);
g_signal_connect (priv->entry, "notify", G_CALLBACK (notify_cb), entry);
g_signal_connect (priv->entry, "activate", G_CALLBACK (activate_cb), entry);
priv->icon = gtk_image_new_from_icon_name ("edit-clear-symbolic");
gtk_widget_set_tooltip_text (priv->icon, _("Clear entry"));
gtk_container_add (GTK_CONTAINER (priv->box), GTK_WIDGET (priv->icon));
gtk_widget_hide (priv->icon);
press = gtk_gesture_multi_press_new ();
g_signal_connect (press, "released", G_CALLBACK (gtk_search_entry_icon_release), entry);
gtk_widget_add_controller (priv->icon, GTK_EVENT_CONTROLLER (press));
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (entry)); atk_obj = gtk_widget_get_accessible (GTK_WIDGET (entry));
if (GTK_IS_ACCESSIBLE (atk_obj)) if (GTK_IS_ACCESSIBLE (atk_obj))
@ -431,7 +581,7 @@ gboolean
gtk_search_entry_handle_event (GtkSearchEntry *entry, gtk_search_entry_handle_event (GtkSearchEntry *entry,
GdkEvent *event) GdkEvent *event)
{ {
GtkSearchEntryPrivate *priv = GET_PRIV (entry); GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
gboolean handled; gboolean handled;
guint keyval, state; guint keyval, state;
@ -544,3 +694,10 @@ gtk_search_entry_get_key_capture_widget (GtkSearchEntry *entry)
return priv->capture_widget; return priv->capture_widget;
} }
GtkEventController *
gtk_search_entry_get_key_controller (GtkSearchEntry *entry)
{
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
return gtk_text_get_key_controller (GTK_TEXT (priv->entry));
}

View File

@ -48,17 +48,18 @@ typedef struct _GtkSearchEntryClass GtkSearchEntryClass;
struct _GtkSearchEntry struct _GtkSearchEntry
{ {
GtkEntry parent; GtkWidget parent;
}; };
struct _GtkSearchEntryClass struct _GtkSearchEntryClass
{ {
GtkEntryClass parent_class; GtkWidgetClass parent_class;
void (*search_changed) (GtkSearchEntry *entry); void (* activate) (GtkSearchEntry *entry);
void (*next_match) (GtkSearchEntry *entry); void (* search_changed) (GtkSearchEntry *entry);
void (*previous_match) (GtkSearchEntry *entry); void (* next_match) (GtkSearchEntry *entry);
void (*stop_search) (GtkSearchEntry *entry); void (* previous_match) (GtkSearchEntry *entry);
void (* stop_search) (GtkSearchEntry *entry);
}; };
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
@ -78,7 +79,6 @@ GDK_AVAILABLE_IN_ALL
GtkWidget* gtk_search_entry_get_key_capture_widget (GtkSearchEntry *entry); GtkWidget* gtk_search_entry_get_key_capture_widget (GtkSearchEntry *entry);
G_END_DECLS G_END_DECLS
#endif /* __GTK_SEARCH_ENTRY_H__ */ #endif /* __GTK_SEARCH_ENTRY_H__ */

View File

@ -32,6 +32,8 @@ G_BEGIN_DECLS
gboolean gtk_search_entry_is_keynav (guint keyval, gboolean gtk_search_entry_is_keynav (guint keyval,
GdkModifierType state); GdkModifierType state);
GtkEventController * gtk_search_entry_get_key_controller (GtkSearchEntry *entry);
G_END_DECLS G_END_DECLS
#endif /* __GTK_SEARCH_ENTRY_PRIVATE_H__ */ #endif /* __GTK_SEARCH_ENTRY_PRIVATE_H__ */

View File

@ -35,7 +35,8 @@
#include "gtkbutton.h" #include "gtkbutton.h"
#include "gtkcssstylepropertyprivate.h" #include "gtkcssstylepropertyprivate.h"
#include "gtkeditable.h" #include "gtkeditable.h"
#include "gtkentry.h" #include "gtkimage.h"
#include "gtktext.h"
#include "gtkeventcontrollerkey.h" #include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollermotion.h" #include "gtkeventcontrollermotion.h"
#include "gtkeventcontrollerscroll.h" #include "gtkeventcontrollerscroll.h"
@ -94,7 +95,7 @@
* |[<!-- language="plain" --> * |[<!-- language="plain" -->
* spinbutton.horizontal * spinbutton.horizontal
* box.horizontal * box.horizontal
* entry * text
* undershoot.left * undershoot.left
* undershoot.right * undershoot.right
* button.down * button.down
@ -105,7 +106,7 @@
* spinbutton.vertical * spinbutton.vertical
* box.vertical * box.vertical
* button.up * button.up
* entry * text
* undershoot.left * undershoot.left
* undershoot.right * undershoot.right
* button.down * button.down
@ -113,8 +114,8 @@
* *
* GtkSpinButtons main CSS node has the name spinbutton. It creates subnodes * GtkSpinButtons main CSS node has the name spinbutton. It creates subnodes
* for the entry and the two buttons, with these names. The button nodes have * for the entry and the two buttons, with these names. The button nodes have
* the style classes .up and .down. The GtkEntry subnodes (if present) are put * the style classes .up and .down. The GtkText subnodes (if present) are put
* below the entry node. The orientation of the spin button is reflected in * below the text node. The orientation of the spin button is reflected in
* the .vertical or .horizontal style class on the main node. * the .vertical or .horizontal style class on the main node.
* *
* ## Using a GtkSpinButton to get an integer * ## Using a GtkSpinButton to get an integer
@ -221,11 +222,8 @@ enum {
PROP_WRAP, PROP_WRAP,
PROP_UPDATE_POLICY, PROP_UPDATE_POLICY,
PROP_VALUE, PROP_VALUE,
PROP_WIDTH_CHARS,
PROP_MAX_WIDTH_CHARS,
PROP_TEXT,
NUM_SPINBUTTON_PROPS, NUM_SPINBUTTON_PROPS,
PROP_ORIENTATION, PROP_ORIENTATION = NUM_SPINBUTTON_PROPS
}; };
/* Signals */ /* Signals */
@ -271,7 +269,7 @@ static gboolean gtk_spin_button_stop_spinning (GtkSpinButton *spin);
static void gtk_spin_button_value_changed (GtkAdjustment *adjustment, static void gtk_spin_button_value_changed (GtkAdjustment *adjustment,
GtkSpinButton *spin_button); GtkSpinButton *spin_button);
static void gtk_spin_button_activate (GtkEntry *entry, static void gtk_spin_button_activate (GtkText *entry,
gpointer user_data); gpointer user_data);
static void gtk_spin_button_unset_adjustment (GtkSpinButton *spin_button); static void gtk_spin_button_unset_adjustment (GtkSpinButton *spin_button);
static void gtk_spin_button_set_orientation (GtkSpinButton *spin_button, static void gtk_spin_button_set_orientation (GtkSpinButton *spin_button,
@ -385,33 +383,9 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
spinbutton_props[PROP_WIDTH_CHARS] =
g_param_spec_int ("width-chars",
P_("Width in chars"),
P_("Number of characters to leave space for in the entry"),
-1, G_MAXINT,
0,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
spinbutton_props[PROP_MAX_WIDTH_CHARS] =
g_param_spec_int ("max-width-chars",
P_("Maximum width in characters"),
P_("The desired maximum width of the entry, in characters"),
-1, G_MAXINT,
0,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
spinbutton_props[PROP_TEXT] =
g_param_spec_string ("text",
P_("Text"),
P_("The contents of the entry"),
"0", /* Default value of the default adjustment */
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, NUM_SPINBUTTON_PROPS, spinbutton_props); g_object_class_install_properties (gobject_class, NUM_SPINBUTTON_PROPS, spinbutton_props);
g_object_class_override_property (gobject_class, g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation");
PROP_ORIENTATION, gtk_editable_install_properties (gobject_class, PROP_ORIENTATION + 1);
"orientation");
/** /**
* GtkSpinButton::input: * GtkSpinButton::input:
@ -549,9 +523,19 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
gtk_widget_class_set_css_name (widget_class, I_("spinbutton")); gtk_widget_class_set_css_name (widget_class, I_("spinbutton"));
} }
static GtkEditable *
gtk_spin_button_get_delegate (GtkEditable *editable)
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (editable);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
return GTK_EDITABLE (priv->entry);
}
static void static void
gtk_spin_button_editable_init (GtkEditableInterface *iface) gtk_spin_button_editable_init (GtkEditableInterface *iface)
{ {
iface->get_delegate = gtk_spin_button_get_delegate;
iface->insert_text = gtk_spin_button_insert_text; iface->insert_text = gtk_spin_button_insert_text;
} }
@ -564,6 +548,9 @@ gtk_spin_button_set_property (GObject *object,
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object); GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
return;
switch (prop_id) switch (prop_id)
{ {
GtkAdjustment *adjustment; GtkAdjustment *adjustment;
@ -602,15 +589,6 @@ gtk_spin_button_set_property (GObject *object,
case PROP_ORIENTATION: case PROP_ORIENTATION:
gtk_spin_button_set_orientation (spin_button, g_value_get_enum (value)); gtk_spin_button_set_orientation (spin_button, g_value_get_enum (value));
break; break;
case PROP_WIDTH_CHARS:
gtk_spin_button_set_width_chars (spin_button, g_value_get_int (value));
break;
case PROP_MAX_WIDTH_CHARS:
gtk_spin_button_set_max_width_chars (spin_button, g_value_get_int (value));
break;
case PROP_TEXT:
gtk_spin_button_set_text (spin_button, g_value_get_string (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -626,6 +604,9 @@ gtk_spin_button_get_property (GObject *object,
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object); GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
return;
switch (prop_id) switch (prop_id)
{ {
case PROP_ADJUSTMENT: case PROP_ADJUSTMENT:
@ -655,15 +636,6 @@ gtk_spin_button_get_property (GObject *object,
case PROP_ORIENTATION: case PROP_ORIENTATION:
g_value_set_enum (value, priv->orientation); g_value_set_enum (value, priv->orientation);
break; break;
case PROP_WIDTH_CHARS:
g_value_set_int (value, gtk_spin_button_get_width_chars (spin_button));
break;
case PROP_MAX_WIDTH_CHARS:
g_value_set_int (value, gtk_spin_button_get_max_width_chars (spin_button));
break;
case PROP_TEXT:
g_value_set_string (value, gtk_spin_button_get_text (spin_button));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -861,20 +833,19 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->orientation = GTK_ORIENTATION_HORIZONTAL;
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (spin_button)); _gtk_orientable_set_style_classes (GTK_ORIENTABLE (spin_button));
gtk_widget_set_focus_on_click (GTK_WIDGET (spin_button), TRUE);
priv->box = gtk_box_new (priv->orientation, 0); priv->box = gtk_box_new (priv->orientation, 0);
gtk_widget_set_parent (priv->box, GTK_WIDGET (spin_button)); gtk_widget_set_parent (priv->box, GTK_WIDGET (spin_button));
priv->entry = gtk_entry_new (); priv->entry = gtk_text_new ();
gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 0); gtk_editable_init_delegate (GTK_EDITABLE (spin_button));
gtk_entry_set_max_width_chars (GTK_ENTRY (priv->entry), 0); gtk_editable_set_width_chars (GTK_EDITABLE (priv->entry), 0);
gtk_editable_set_max_width_chars (GTK_EDITABLE (priv->entry), 0);
gtk_widget_set_hexpand (priv->entry, TRUE); gtk_widget_set_hexpand (priv->entry, TRUE);
gtk_widget_set_vexpand (priv->entry, TRUE); gtk_widget_set_vexpand (priv->entry, TRUE);
g_signal_connect (priv->entry, "activate", G_CALLBACK (gtk_spin_button_activate), spin_button); g_signal_connect (priv->entry, "activate", G_CALLBACK (gtk_spin_button_activate), spin_button);
gtk_container_add (GTK_CONTAINER (priv->box), priv->entry); gtk_container_add (GTK_CONTAINER (priv->box), priv->entry);
priv->down_button = gtk_button_new (); priv->down_button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (priv->down_button), gtk_image_new_from_icon_name ("value-decrease-symbolic")); gtk_container_add (GTK_CONTAINER (priv->down_button), gtk_image_new_from_icon_name ("value-decrease-symbolic"));
gtk_style_context_add_class (gtk_widget_get_style_context (priv->down_button), "image-button"); gtk_style_context_add_class (gtk_widget_get_style_context (priv->down_button), "image-button");
@ -941,6 +912,8 @@ gtk_spin_button_finalize (GObject *object)
gtk_spin_button_unset_adjustment (spin_button); gtk_spin_button_unset_adjustment (spin_button);
gtk_editable_finish_delegate (GTK_EDITABLE (spin_button));
gtk_widget_unparent (priv->box); gtk_widget_unparent (priv->box);
G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object);
@ -960,6 +933,7 @@ gtk_spin_button_realize (GtkWidget *widget)
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget); GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
gboolean return_val; gboolean return_val;
const char *text;
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->realize (widget); GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->realize (widget);
@ -969,8 +943,8 @@ gtk_spin_button_realize (GtkWidget *widget)
/* If output wasn't processed explicitly by the method connected to the /* If output wasn't processed explicitly by the method connected to the
* 'output' signal; and if we don't have any explicit 'text' set initially, * 'output' signal; and if we don't have any explicit 'text' set initially,
* fallback to the default output. */ * fallback to the default output. */
if (!return_val && text = gtk_editable_get_text (GTK_EDITABLE (priv->entry));
(priv->numeric || gtk_entry_get_text (GTK_ENTRY (priv->entry)) == NULL)) if (!return_val && (priv->numeric || text == NULL || *text == '\0'))
gtk_spin_button_default_output (spin_button); gtk_spin_button_default_output (spin_button);
} }
@ -1026,7 +1000,7 @@ gtk_spin_button_set_orientation (GtkSpinButton *spin,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin);
GtkEntry *entry = GTK_ENTRY (priv->entry); GtkEditable *editable = GTK_EDITABLE (priv->entry);
if (priv->orientation == orientation) if (priv->orientation == orientation)
return; return;
@ -1036,11 +1010,11 @@ gtk_spin_button_set_orientation (GtkSpinButton *spin,
/* change alignment if it's the default */ /* change alignment if it's the default */
if (priv->orientation == GTK_ORIENTATION_VERTICAL && if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
gtk_entry_get_alignment (entry) == 0.0) gtk_editable_get_alignment (editable) == 0.0)
gtk_entry_set_alignment (entry, 0.5); gtk_editable_set_alignment (editable, 0.5);
else if (priv->orientation == GTK_ORIENTATION_HORIZONTAL && else if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_entry_get_alignment (entry) == 0.5) gtk_editable_get_alignment (editable) == 0.5)
gtk_entry_set_alignment (entry, 0.0); gtk_editable_set_alignment (editable, 0.0);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{ {
@ -1330,7 +1304,7 @@ gtk_spin_button_snap (GtkSpinButton *spin_button,
} }
static void static void
gtk_spin_button_activate (GtkEntry *entry, gtk_spin_button_activate (GtkText *entry,
gpointer user_data) gpointer user_data)
{ {
GtkSpinButton *spin_button = user_data; GtkSpinButton *spin_button = user_data;
@ -1348,11 +1322,6 @@ gtk_spin_button_insert_text (GtkEditable *editable,
{ {
GtkSpinButton *spin = GTK_SPIN_BUTTON (editable); GtkSpinButton *spin = GTK_SPIN_BUTTON (editable);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin);
GtkEntry *entry = GTK_ENTRY (priv->entry);
GtkEditableInterface *parent_editable_iface;
parent_editable_iface = g_type_interface_peek (gtk_spin_button_parent_class,
GTK_TYPE_EDITABLE);
if (priv->numeric) if (priv->numeric)
{ {
@ -1365,8 +1334,8 @@ gtk_spin_button_insert_text (GtkEditable *editable,
gint entry_length; gint entry_length;
const gchar *entry_text; const gchar *entry_text;
entry_length = gtk_entry_get_text_length (entry); entry_text = gtk_editable_get_text (GTK_EDITABLE (priv->entry));
entry_text = gtk_entry_get_text (entry); entry_length = g_utf8_strlen (entry_text, -1);
lc = localeconv (); lc = localeconv ();
@ -1444,8 +1413,8 @@ gtk_spin_button_insert_text (GtkEditable *editable,
} }
} }
parent_editable_iface->insert_text (editable, new_text, gtk_editable_insert_text (GTK_EDITABLE (priv->entry),
new_text_length, position); new_text, new_text_length, position);
} }
static void static void
@ -1505,8 +1474,9 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button,
{ {
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button); GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
gchar *err = NULL; gchar *err = NULL;
const char *text = gtk_editable_get_text (GTK_EDITABLE (priv->entry));
*new_val = g_strtod (gtk_entry_get_text (GTK_ENTRY (priv->entry)), &err); *new_val = g_strtod (text, &err);
if (*err) if (*err)
return GTK_INPUT_ERROR; return GTK_INPUT_ERROR;
else else
@ -1520,8 +1490,8 @@ gtk_spin_button_default_output (GtkSpinButton *spin_button)
gchar *buf = gtk_spin_button_format_for_value (spin_button, gchar *buf = gtk_spin_button_format_for_value (spin_button,
gtk_adjustment_get_value (priv->adjustment)); gtk_adjustment_get_value (priv->adjustment));
if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (priv->entry)))) if (strcmp (buf, gtk_editable_get_text (GTK_EDITABLE (priv->entry))))
gtk_entry_set_text (GTK_ENTRY (priv->entry), buf); gtk_editable_set_text (GTK_EDITABLE (priv->entry), buf);
g_free (buf); g_free (buf);
} }
@ -2260,7 +2230,7 @@ gtk_spin_button_get_text (GtkSpinButton *spin_button)
g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), NULL); g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), NULL);
return gtk_entry_get_text (GTK_ENTRY (priv->entry)); return gtk_editable_get_text (GTK_EDITABLE (priv->entry));
} }
/** /**
@ -2279,9 +2249,7 @@ gtk_spin_button_set_text (GtkSpinButton *spin_button,
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
gtk_entry_set_text (GTK_ENTRY (priv->entry), text); gtk_editable_set_text (GTK_EDITABLE (priv->entry), text);
g_object_notify_by_pspec (G_OBJECT (spin_button), spinbutton_props[PROP_TEXT]);
} }
/** /**
@ -2303,7 +2271,7 @@ gtk_spin_button_get_max_width_chars (GtkSpinButton *spin_button)
g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), -1); g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), -1);
return gtk_entry_get_max_width_chars (GTK_ENTRY (priv->entry)); return gtk_editable_get_max_width_chars (GTK_EDITABLE (priv->entry));
} }
/** /**
@ -2323,11 +2291,7 @@ gtk_spin_button_set_max_width_chars (GtkSpinButton *spin_button,
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
if (max_width_chars != gtk_entry_get_max_width_chars (GTK_ENTRY (priv->entry))) gtk_editable_set_max_width_chars (GTK_EDITABLE (priv->entry), max_width_chars);
{
gtk_entry_set_max_width_chars (GTK_ENTRY (priv->entry), max_width_chars);
g_object_notify_by_pspec (G_OBJECT (spin_button), spinbutton_props[PROP_MAX_WIDTH_CHARS]);
}
} }
/** /**
@ -2347,7 +2311,7 @@ gtk_spin_button_get_width_chars (GtkSpinButton *spin_button)
g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), -1); g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), -1);
return gtk_entry_get_width_chars (GTK_ENTRY (priv->entry)); return gtk_editable_get_width_chars (GTK_EDITABLE (priv->entry));
} }
/** /**
@ -2366,9 +2330,5 @@ gtk_spin_button_set_width_chars (GtkSpinButton *spin_button,
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
if (width_chars != gtk_entry_get_width_chars (GTK_ENTRY (priv->entry))) gtk_editable_set_width_chars (GTK_EDITABLE (priv->entry), width_chars);
{
gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), width_chars);
g_object_notify_by_pspec (G_OBJECT (spin_button), spinbutton_props[PROP_WIDTH_CHARS]);
}
} }

6710
gtk/gtktext.c Normal file

File diff suppressed because it is too large Load Diff

223
gtk/gtktext.h Normal file
View File

@ -0,0 +1,223 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* Copyright (C) 2004-2006 Christian Hammond
* Copyright (C) 2008 Cody Russell
* Copyright (C) 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_TEXT_H__
#define __GTK_TEXT_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkeditable.h>
#include <gtk/gtkentrybuffer.h>
G_BEGIN_DECLS
#define GTK_TYPE_TEXT (gtk_text_get_type ())
#define GTK_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT, GtkText))
#define GTK_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT, GtkTextClass))
#define GTK_IS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT))
#define GTK_IS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT))
#define GTK_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT, GtkTextClass))
typedef struct _GtkText GtkText;
typedef struct _GtkTextClass GtkTextClass;
struct _GtkText
{
/*< private >*/
GtkWidget parent_instance;
};
/**
* GtkTextClass:
* @parent_class: The parent class.
* @populate_popup: Class handler for the #GtkText::populate-popup signal. If
* non-%NULL, this will be called to add additional entries to the context
* menu when it is displayed.
* @activate: Class handler for the #GtkText::activate signal. The default
* implementation calls gtk_window_activate_default() on the entrys top-level
* window.
* @move_cursor: Class handler for the #GtkText::move-cursor signal. The
* default implementation specifies the standard #GtkText cursor movement
* behavior.
* @insert_at_cursor: Class handler for the #GtkText::insert-at-cursor signal.
* The default implementation inserts text at the cursor.
* @delete_from_cursor: Class handler for the #GtkText::delete-from-cursor
* signal. The default implementation deletes the selection or the specified
* number of characters or words.
* @backspace: Class handler for the #GtkText::backspace signal. The default
* implementation deletes the selection or a single character or word.
* @cut_clipboard: Class handler for the #GtkText::cut-clipboard signal. The
* default implementation cuts the selection, if one exists.
* @copy_clipboard: Class handler for the #GtkText::copy-clipboard signal. The
* default implementation copies the selection, if one exists.
* @paste_clipboard: Class handler for the #GtkText::paste-clipboard signal.
* The default implementation pastes at the current cursor position or over
* the current selection if one exists.
* @toggle_overwrite: Class handler for the #GtkText::toggle-overwrite signal.
* The default implementation toggles overwrite mode and blinks the cursor.
* @insert_emoji: Class handler for the #GtkText::insert-emoji signal.
*
* Class structure for #GtkText. All virtual functions have a default
* implementation. Derived classes may set the virtual function pointers for the
* signal handlers to %NULL, but must keep @get_text_area_size and
* @get_frame_size non-%NULL; either use the default implementation, or provide
* a custom one.
*/
struct _GtkTextClass
{
GtkWidgetClass parent_class;
/* Hook to customize right-click popup */
void (* populate_popup) (GtkText *self,
GtkWidget *popup);
/* Action signals
*/
void (* activate) (GtkText *self);
void (* move_cursor) (GtkText *self,
GtkMovementStep step,
gint count,
gboolean extend);
void (* insert_at_cursor) (GtkText *self,
const gchar *str);
void (* delete_from_cursor) (GtkText *self,
GtkDeleteType type,
gint count);
void (* backspace) (GtkText *self);
void (* cut_clipboard) (GtkText *self);
void (* copy_clipboard) (GtkText *self);
void (* paste_clipboard) (GtkText *self);
void (* toggle_overwrite) (GtkText *self);
void (* insert_emoji) (GtkText *self);
/*< private >*/
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
};
GDK_AVAILABLE_IN_ALL
GType gtk_text_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_text_new (void);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_text_new_with_buffer (GtkEntryBuffer *buffer);
GDK_AVAILABLE_IN_ALL
GtkEntryBuffer *gtk_text_get_buffer (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_buffer (GtkText *self,
GtkEntryBuffer *buffer);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_visibility (GtkText *self,
gboolean visible);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_get_visibility (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_invisible_char (GtkText *self,
gunichar ch);
GDK_AVAILABLE_IN_ALL
gunichar gtk_text_get_invisible_char (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_unset_invisible_char (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_has_frame (GtkText *self,
gboolean has_frame);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_get_has_frame (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_overwrite_mode (GtkText *self,
gboolean overwrite);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_get_overwrite_mode (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_max_length (GtkText *self,
int length);
GDK_AVAILABLE_IN_ALL
gint gtk_text_get_max_length (GtkText *self);
GDK_AVAILABLE_IN_ALL
guint16 gtk_text_get_text_length (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_activates_default (GtkText *self,
gboolean activates);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_get_activates_default (GtkText *self);
GDK_AVAILABLE_IN_ALL
const char * gtk_text_get_placeholder_text (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_placeholder_text (GtkText *self,
const char *text);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_input_purpose (GtkText *self,
GtkInputPurpose purpose);
GDK_AVAILABLE_IN_ALL
GtkInputPurpose gtk_text_get_input_purpose (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_input_hints (GtkText *self,
GtkInputHints hints);
GDK_AVAILABLE_IN_ALL
GtkInputHints gtk_text_get_input_hints (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_attributes (GtkText *self,
PangoAttrList *attrs);
GDK_AVAILABLE_IN_ALL
PangoAttrList * gtk_text_get_attributes (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_tabs (GtkText *self,
PangoTabArray *tabs);
GDK_AVAILABLE_IN_ALL
PangoTabArray * gtk_text_get_tabs (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_grab_focus_without_selecting (GtkText *self);
G_END_DECLS
#endif /* __GTK_TEXT_H__ */

46
gtk/gtktextprivate.h Normal file
View File

@ -0,0 +1,46 @@
/* gtkentryprivate.h
* Copyright (C) 2019 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_TEXT_PRIVATE_H__
#define __GTK_TEXT_PRIVATE_H__
#include "gtktext.h"
#include "gtkeventcontroller.h"
#include "gtkimcontext.h"
G_BEGIN_DECLS
char * gtk_text_get_display_text (GtkText *entry,
int start_pos,
int end_pos);
GtkIMContext * gtk_text_get_im_context (GtkText *entry);
void gtk_text_enter_text (GtkText *entry,
const char *text);
void gtk_text_set_positions (GtkText *entry,
int current_pos,
int selection_bound);
PangoLayout * gtk_text_get_layout (GtkText *entry);
void gtk_text_get_layout_offsets (GtkText *entry,
int *x,
int *y);
void gtk_text_reset_im_context (GtkText *entry);
GtkEventController *gtk_text_get_key_controller (GtkText *entry);
G_END_DECLS
#endif /* __GTK_TEXT_PRIVATE_H__ */

View File

@ -34,6 +34,7 @@
#include "gtkdragdest.h" #include "gtkdragdest.h"
#include "gtkdragsource.h" #include "gtkdragsource.h"
#include "gtkentryprivate.h" #include "gtkentryprivate.h"
#include "gtksearchentryprivate.h"
#include "gtkeventcontrollerkey.h" #include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollermotion.h" #include "gtkeventcontrollermotion.h"
#include "gtkeventcontrollerscroll.h" #include "gtkeventcontrollerscroll.h"
@ -46,6 +47,7 @@
#include "gtkmain.h" #include "gtkmain.h"
#include "gtkmarshalers.h" #include "gtkmarshalers.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtktext.h"
#include "gtktreerbtreeprivate.h" #include "gtktreerbtreeprivate.h"
#include "gtkrendericonprivate.h" #include "gtkrendericonprivate.h"
#include "gtkscrollable.h" #include "gtkscrollable.h"
@ -799,10 +801,10 @@ static void gtk_tree_view_search_position_func (GtkTreeView *tree_
static void gtk_tree_view_search_disable_popdown (GtkEntry *entry, static void gtk_tree_view_search_disable_popdown (GtkEntry *entry,
GtkMenu *menu, GtkMenu *menu,
gpointer data); gpointer data);
static void gtk_tree_view_search_preedit_changed (GtkIMContext *im_context, static void gtk_tree_view_search_preedit_changed (GtkText *text,
const char *preedit,
GtkTreeView *tree_view); GtkTreeView *tree_view);
static void gtk_tree_view_search_commit (GtkIMContext *im_context, static void gtk_tree_view_search_changed (GtkEditable *editable,
gchar *buf,
GtkTreeView *tree_view); GtkTreeView *tree_view);
static void gtk_tree_view_search_activate (GtkEntry *entry, static void gtk_tree_view_search_activate (GtkEntry *entry,
GtkTreeView *tree_view); GtkTreeView *tree_view);
@ -2110,10 +2112,17 @@ gtk_tree_view_destroy (GtkWidget *widget)
if (tree_view->priv->search_custom_entry_set) if (tree_view->priv->search_custom_entry_set)
{ {
GtkEventController *controller;
g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry, g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
G_CALLBACK (gtk_tree_view_search_init), G_CALLBACK (gtk_tree_view_search_init),
tree_view); tree_view);
g_signal_handlers_disconnect_by_func (gtk_entry_get_key_controller (GTK_ENTRY (tree_view->priv->search_entry)),
if (GTK_IS_ENTRY (tree_view->priv->search_entry))
controller = gtk_entry_get_key_controller (GTK_ENTRY (tree_view->priv->search_entry));
else
controller = gtk_search_entry_get_key_controller (GTK_SEARCH_ENTRY (tree_view->priv->search_entry));
g_signal_handlers_disconnect_by_func (controller,
G_CALLBACK (gtk_tree_view_search_key_pressed), G_CALLBACK (gtk_tree_view_search_key_pressed),
tree_view); tree_view);
@ -5383,7 +5392,7 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
} }
else else
{ {
gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (tree_view->priv->search_entry), "");
return FALSE; return FALSE;
} }
} }
@ -10239,23 +10248,15 @@ gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view)
gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_container_add (GTK_CONTAINER (frame), vbox);
/* add entry */ /* add entry */
tree_view->priv->search_entry = gtk_entry_new (); tree_view->priv->search_entry = gtk_text_new ();
gtk_widget_show (tree_view->priv->search_entry);
g_signal_connect (tree_view->priv->search_entry, "populate-popup", g_signal_connect (tree_view->priv->search_entry, "populate-popup",
G_CALLBACK (gtk_tree_view_search_disable_popdown), G_CALLBACK (gtk_tree_view_search_disable_popdown), tree_view);
tree_view); g_signal_connect (tree_view->priv->search_entry, "activate",
g_signal_connect (tree_view->priv->search_entry, G_CALLBACK (gtk_tree_view_search_activate), tree_view);
"activate", G_CALLBACK (gtk_tree_view_search_activate), g_signal_connect (tree_view->priv->search_entry, "preedit-changed",
tree_view); G_CALLBACK (gtk_tree_view_search_preedit_changed), tree_view);
g_signal_connect (tree_view->priv->search_entry, "changed",
g_signal_connect (_gtk_entry_get_im_context (GTK_ENTRY (tree_view->priv->search_entry)), G_CALLBACK (gtk_tree_view_search_changed), tree_view);
"preedit-changed",
G_CALLBACK (gtk_tree_view_search_preedit_changed),
tree_view);
g_signal_connect (_gtk_entry_get_im_context (GTK_ENTRY (tree_view->priv->search_entry)),
"commit",
G_CALLBACK (gtk_tree_view_search_commit),
tree_view);
gtk_container_add (GTK_CONTAINER (vbox), gtk_container_add (GTK_CONTAINER (vbox),
tree_view->priv->search_entry); tree_view->priv->search_entry);
@ -10317,13 +10318,16 @@ gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view,
gtk_tree_view_ensure_interactive_directory (tree_view); gtk_tree_view_ensure_interactive_directory (tree_view);
if (keybinding) if (keybinding)
gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (tree_view->priv->search_entry), "");
/* done, show it */ /* done, show it */
tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data); tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
/* Grab focus without selecting all the text. */ /* Grab focus without selecting all the text. */
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (tree_view->priv->search_entry)); if (GTK_IS_ENTRY (tree_view->priv->search_entry))
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (tree_view->priv->search_entry));
else
gtk_widget_grab_focus (tree_view->priv->search_entry);
gtk_widget_show (tree_view->priv->search_window); gtk_widget_show (tree_view->priv->search_window);
if (tree_view->priv->search_entry_changed_id == 0) if (tree_view->priv->search_entry_changed_id == 0)
@ -13639,13 +13643,13 @@ gtk_tree_view_set_search_equal_func (GtkTreeView *tree_view,
* *
* Returns: (transfer none): the entry currently in use as search entry. * Returns: (transfer none): the entry currently in use as search entry.
*/ */
GtkEntry * GtkEditable *
gtk_tree_view_get_search_entry (GtkTreeView *tree_view) gtk_tree_view_get_search_entry (GtkTreeView *tree_view)
{ {
g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL); g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
if (tree_view->priv->search_custom_entry_set) if (tree_view->priv->search_custom_entry_set)
return GTK_ENTRY (tree_view->priv->search_entry); return GTK_EDITABLE (tree_view->priv->search_entry);
return NULL; return NULL;
} }
@ -13663,10 +13667,10 @@ gtk_tree_view_get_search_entry (GtkTreeView *tree_view)
*/ */
void void
gtk_tree_view_set_search_entry (GtkTreeView *tree_view, gtk_tree_view_set_search_entry (GtkTreeView *tree_view,
GtkEntry *entry) GtkEditable *entry)
{ {
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry)); g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry) || GTK_IS_SEARCH_ENTRY (entry));
if (tree_view->priv->search_custom_entry_set) if (tree_view->priv->search_custom_entry_set)
{ {
@ -13690,6 +13694,8 @@ gtk_tree_view_set_search_entry (GtkTreeView *tree_view,
if (entry) if (entry)
{ {
GtkEventController *controller;
tree_view->priv->search_entry = GTK_WIDGET (g_object_ref (entry)); tree_view->priv->search_entry = GTK_WIDGET (g_object_ref (entry));
tree_view->priv->search_custom_entry_set = TRUE; tree_view->priv->search_custom_entry_set = TRUE;
@ -13701,10 +13707,12 @@ gtk_tree_view_set_search_entry (GtkTreeView *tree_view,
tree_view); tree_view);
} }
g_signal_connect (gtk_entry_get_key_controller (GTK_ENTRY (tree_view->priv->search_entry)), if (GTK_IS_ENTRY (entry))
"key-pressed", controller = gtk_entry_get_key_controller (GTK_ENTRY (entry));
G_CALLBACK (gtk_tree_view_search_key_pressed), else
tree_view); controller = gtk_search_entry_get_key_controller (GTK_SEARCH_ENTRY (entry));
g_signal_connect (controller, "key-pressed",
G_CALLBACK (gtk_tree_view_search_key_pressed), tree_view);
gtk_tree_view_search_init (tree_view->priv->search_entry, tree_view); gtk_tree_view_search_init (tree_view->priv->search_entry, tree_view);
} }
@ -13846,7 +13854,8 @@ gtk_tree_view_search_disable_popdown (GtkEntry *entry,
* callback. * callback.
*/ */
static void static void
gtk_tree_view_search_preedit_changed (GtkIMContext *im_context, gtk_tree_view_search_preedit_changed (GtkText *text,
const char *predit,
GtkTreeView *tree_view) GtkTreeView *tree_view)
{ {
tree_view->priv->imcontext_changed = 1; tree_view->priv->imcontext_changed = 1;
@ -13863,9 +13872,8 @@ gtk_tree_view_search_preedit_changed (GtkIMContext *im_context,
} }
static void static void
gtk_tree_view_search_commit (GtkIMContext *im_context, gtk_tree_view_search_changed (GtkEditable *editable,
gchar *buf, GtkTreeView *tree_view)
GtkTreeView *tree_view)
{ {
tree_view->priv->imcontext_changed = 1; tree_view->priv->imcontext_changed = 1;
} }
@ -14273,10 +14281,9 @@ gtk_tree_view_search_init (GtkWidget *entry,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeSelection *selection; GtkTreeSelection *selection;
g_return_if_fail (GTK_IS_ENTRY (entry));
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
text = gtk_entry_get_text (GTK_ENTRY (entry)); text = gtk_editable_get_text (GTK_EDITABLE (entry));
model = gtk_tree_view_get_model (tree_view); model = gtk_tree_view_get_model (tree_view);
selection = gtk_tree_view_get_selection (tree_view); selection = gtk_tree_view_get_selection (tree_view);

View File

@ -433,10 +433,10 @@ void gtk_tree_view_set_search_equal_func (GtkTreeView
GDestroyNotify search_destroy); GDestroyNotify search_destroy);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkEntry *gtk_tree_view_get_search_entry (GtkTreeView *tree_view); GtkEditable *gtk_tree_view_get_search_entry (GtkTreeView *tree_view);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_tree_view_set_search_entry (GtkTreeView *tree_view, void gtk_tree_view_set_search_entry (GtkTreeView *tree_view,
GtkEntry *entry); GtkEditable *entry);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkTreeViewSearchPositionFunc gtk_tree_view_get_search_position_func (GtkTreeView *tree_view); GtkTreeViewSearchPositionFunc gtk_tree_view_get_search_position_func (GtkTreeView *tree_view);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -916,7 +916,7 @@ search (GtkInspectorObjectTree *wt,
guint i, selected, n, row; guint i, selected, n, row;
const char *text; const char *text;
text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); text = gtk_editable_get_text (GTK_EDITABLE (priv->search_entry));
if (gtk_list_box_get_selected_row (priv->list)) if (gtk_list_box_get_selected_row (priv->list))
{ {
selected = gtk_list_box_row_get_index (gtk_list_box_get_selected_row (priv->list)); selected = gtk_list_box_row_get_index (gtk_list_box_get_selected_row (priv->list));
@ -998,7 +998,7 @@ static void
stop_search (GtkWidget *entry, stop_search (GtkWidget *entry,
GtkInspectorObjectTree *wt) GtkInspectorObjectTree *wt)
{ {
gtk_entry_set_text (GTK_ENTRY (wt->priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (wt->priv->search_entry), "");
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar), FALSE); gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar), FALSE);
} }
@ -1155,7 +1155,7 @@ gtk_inspector_object_tree_init (GtkInspectorObjectTree *wt)
gtk_widget_init_template (GTK_WIDGET (wt)); gtk_widget_init_template (GTK_WIDGET (wt));
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (wt->priv->search_bar), gtk_search_bar_connect_entry (GTK_SEARCH_BAR (wt->priv->search_bar),
GTK_ENTRY (wt->priv->search_entry)); GTK_EDITABLE (wt->priv->search_entry));
root_model = create_root_model (); root_model = create_root_model ();
wt->priv->tree_model = gtk_tree_list_model_new (FALSE, wt->priv->tree_model = gtk_tree_list_model_new (FALSE,

View File

@ -79,7 +79,7 @@ static void
search_close_clicked (GtkWidget *button, search_close_clicked (GtkWidget *button,
GtkInspectorPropList *pl) GtkInspectorPropList *pl)
{ {
gtk_entry_set_text (GTK_ENTRY (pl->priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (pl->priv->search_entry), "");
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title"); gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
} }
@ -275,7 +275,7 @@ constructed (GObject *object)
pl->priv->search_stack = gtk_widget_get_parent (pl->priv->search_entry); pl->priv->search_stack = gtk_widget_get_parent (pl->priv->search_entry);
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (pl->priv->tree), gtk_tree_view_set_search_entry (GTK_TREE_VIEW (pl->priv->tree),
GTK_ENTRY (pl->priv->search_entry)); GTK_EDITABLE (pl->priv->search_entry));
g_signal_connect (pl->priv->search_entry, "stop-search", g_signal_connect (pl->priv->search_entry, "stop-search",
G_CALLBACK (search_close_clicked), pl); G_CALLBACK (search_close_clicked), pl);
@ -525,7 +525,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
cleanup_object (pl); cleanup_object (pl);
gtk_entry_set_text (GTK_ENTRY (pl->priv->search_entry), ""); gtk_editable_set_text (GTK_EDITABLE (pl->priv->search_entry), "");
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title"); gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
if (pl->priv->child_properties) if (pl->priv->child_properties)

View File

@ -548,7 +548,7 @@ match_row (GtkTreeModel *model,
const gchar *text; const gchar *text;
gboolean match; gboolean match;
text = gtk_entry_get_text (GTK_ENTRY (sl->priv->search_entry)); text = gtk_editable_get_text (GTK_EDITABLE (sl->priv->search_entry));
gtk_tree_model_get (model, iter, gtk_tree_model_get (model, iter,
COLUMN_NAME, &name, COLUMN_NAME, &name,
COLUMN_PATH, &path, COLUMN_PATH, &path,
@ -622,7 +622,7 @@ gtk_inspector_resource_list_init (GtkInspectorResourceList *sl)
g_signal_connect (sl, "map", G_CALLBACK (on_map), NULL); g_signal_connect (sl, "map", G_CALLBACK (on_map), NULL);
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (sl->priv->search_bar), gtk_search_bar_connect_entry (GTK_SEARCH_BAR (sl->priv->search_bar),
GTK_ENTRY (sl->priv->search_entry)); GTK_EDITABLE (sl->priv->search_entry));
g_signal_connect (sl->priv->search_bar, "notify::search-mode-enabled", g_signal_connect (sl->priv->search_bar, "notify::search-mode-enabled",
G_CALLBACK (search_mode_changed), sl); G_CALLBACK (search_mode_changed), sl);

View File

@ -374,7 +374,7 @@ gtk_inspector_statistics_init (GtkInspectorStatistics *sl)
GINT_TO_POINTER (COLUMN_CUMULATIVE2), NULL); GINT_TO_POINTER (COLUMN_CUMULATIVE2), NULL);
sl->priv->counts = g_hash_table_new_full (NULL, NULL, NULL, type_data_free); sl->priv->counts = g_hash_table_new_full (NULL, NULL, NULL, type_data_free);
gtk_tree_view_set_search_entry (sl->priv->view, GTK_ENTRY (sl->priv->search_entry)); gtk_tree_view_set_search_entry (sl->priv->view, GTK_EDITABLE (sl->priv->search_entry));
gtk_tree_view_set_search_equal_func (sl->priv->view, match_row, sl, NULL); gtk_tree_view_set_search_equal_func (sl->priv->view, match_row, sl, NULL);
g_signal_connect (sl, "hierarchy-changed", G_CALLBACK (hierarchy_changed), NULL); g_signal_connect (sl, "hierarchy-changed", G_CALLBACK (hierarchy_changed), NULL);
} }

View File

@ -293,6 +293,7 @@ gtk_public_sources = files([
'gtkpagesetup.c', 'gtkpagesetup.c',
'gtkpaned.c', 'gtkpaned.c',
'gtkpapersize.c', 'gtkpapersize.c',
'gtkpasswordentry.c',
'gtkpicture.c', 'gtkpicture.c',
'gtkpopover.c', 'gtkpopover.c',
'gtkpopovermenu.c', 'gtkpopovermenu.c',
@ -352,6 +353,7 @@ gtk_public_sources = files([
'gtkstyleprovider.c', 'gtkstyleprovider.c',
'gtkswitch.c', 'gtkswitch.c',
'gtktestutils.c', 'gtktestutils.c',
'gtktext.c',
'gtktextattributes.c', 'gtktextattributes.c',
'gtktextbuffer.c', 'gtktextbuffer.c',
'gtktextchild.c', 'gtktextchild.c',
@ -537,6 +539,7 @@ gtk_public_headers = files([
'gtkpagesetup.h', 'gtkpagesetup.h',
'gtkpaned.h', 'gtkpaned.h',
'gtkpapersize.h', 'gtkpapersize.h',
'gtkpasswordentry.h',
'gtkpicture.h', 'gtkpicture.h',
'gtkpopover.h', 'gtkpopover.h',
'gtkpopovermenu.h', 'gtkpopovermenu.h',
@ -588,6 +591,7 @@ gtk_public_headers = files([
'gtkstyleprovider.h', 'gtkstyleprovider.h',
'gtkswitch.h', 'gtkswitch.h',
'gtktestutils.h', 'gtktestutils.h',
'gtktext.h',
'gtktextbuffer.h', 'gtktextbuffer.h',
'gtktextchild.h', 'gtktextchild.h',
'gtktextiter.h', 'gtktextiter.h',

View File

@ -36,14 +36,8 @@
<property name="column-spacing">6</property> <property name="column-spacing">6</property>
<child> <child>
<object class="GtkSearchEntry" id="search_entry"> <object class="GtkSearchEntry" id="search_entry">
<property name="can-focus">1</property>
<property name="hexpand">1</property> <property name="hexpand">1</property>
<property name="activates-default">1</property> <property name="activates-default">1</property>
<property name="primary-icon-name">edit-find-symbolic</property>
<property name="primary-icon-activatable">0</property>
<property name="secondary-icon-activatable">0</property>
<property name="primary-icon-sensitive">0</property>
<property name="secondary-icon-sensitive">0</property>
<property name="placeholder-text" translatable="yes">Search font name</property> <property name="placeholder-text" translatable="yes">Search font name</property>
<signal name="search-changed" handler="text_changed_cb" swapped="no"/> <signal name="search-changed" handler="text_changed_cb" swapped="no"/>
<signal name="stop-search" handler="stop_search_cb" swapped="no"/> <signal name="stop-search" handler="stop_search_cb" swapped="no"/>

View File

@ -241,22 +241,9 @@ main (int argc, char **argv)
gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER); gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
entry = gtk_entry_new (); entry = gtk_password_entry_new ();
gtk_widget_set_hexpand (entry, TRUE); gtk_widget_set_hexpand (entry, TRUE);
gtk_grid_attach (GTK_GRID (grid), entry, 1, 3, 1, 1); gtk_grid_attach (GTK_GRID (grid), entry, 1, 3, 1, 1);
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
GTK_ENTRY_ICON_PRIMARY,
"dialog-password-symbolic");
gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
GTK_ENTRY_ICON_PRIMARY,
FALSE);
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
GTK_ENTRY_ICON_PRIMARY,
"The password is hidden for security");
/* Name - Does not set any icons. */ /* Name - Does not set any icons. */
label = gtk_label_new ("Name:"); label = gtk_label_new ("Name:");

View File

@ -87,7 +87,7 @@ switch_search_method (GtkWidget *button,
if (!gtk_tree_view_get_search_entry (GTK_TREE_VIEW (tree_view))) if (!gtk_tree_view_get_search_entry (GTK_TREE_VIEW (tree_view)))
{ {
gpointer data = g_object_get_data (tree_view, "my-search-entry"); gpointer data = g_object_get_data (tree_view, "my-search-entry");
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (data)); gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_EDITABLE (data));
} }
else else
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), NULL); gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), NULL);
@ -145,7 +145,7 @@ main (int argc, char *argv[])
*/ */
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (entry)); gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_EDITABLE (entry));
g_object_set_data (G_OBJECT (tree_view), "my-search-entry", entry); g_object_set_data (G_OBJECT (tree_view), "my-search-entry", entry);
g_signal_connect (button, "clicked", g_signal_connect (button, "clicked",
G_CALLBACK (switch_search_method), tree_view); G_CALLBACK (switch_search_method), tree_view);

View File

@ -60,8 +60,7 @@ window1
<AtkText> <AtkText>
text: FancyPants text: FancyPants
character count: 10 character count: 10
caret offset: 10 caret offset: 0
selection 0: (0, 10) FancyPants
default attributes: bg-color: <omitted> default attributes: bg-color: <omitted>
bg-full-height: 0 bg-full-height: 0
direction: <omitted> direction: <omitted>
@ -365,7 +364,7 @@ See the GNU General Public License, version 3 or later for details.
"filler" "filler"
parent: headerbar1 parent: headerbar1
index: 0 index: 0
state: enabled horizontal sensitive state: enabled horizontal sensitive showing visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -375,7 +374,7 @@ See the GNU General Public License, version 3 or later for details.
parent: stack_switcher parent: stack_switcher
index: 0 index: 0
name: About name: About
state: checked enabled focusable sensitive visible state: checked enabled focusable sensitive showing visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -391,7 +390,7 @@ See the GNU General Public License, version 3 or later for details.
parent: stack_switcher parent: stack_switcher
index: 1 index: 1
name: Credits name: Credits
state: enabled focusable sensitive state: enabled focusable sensitive showing visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -423,7 +422,7 @@ See the GNU General Public License, version 3 or later for details.
parent: stack_switcher parent: stack_switcher
index: 3 index: 3
name: System name: System
state: enabled focusable sensitive state: enabled focusable sensitive showing visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget

View File

@ -109,7 +109,7 @@ window1
"text" "text"
parent: combo2 parent: combo2
index: 1 index: 1
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -196,7 +196,7 @@ window1
"text" "text"
parent: combo4 parent: combo4
index: 1 index: 1
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget

View File

@ -144,7 +144,7 @@ window1
parent: box1 parent: box1
index: 3 index: 3
labelled-by: label1 labelled-by: label1
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -188,7 +188,7 @@ window1
parent: box1 parent: box1
index: 4 index: 4
labelled-by: label2 labelled-by: label2
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget
@ -230,7 +230,7 @@ window1
"text" "text"
parent: box1 parent: box1
index: 5 index: 5
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget

View File

@ -62,7 +62,7 @@ window1
parent: box1 parent: box1
index: 1 index: 1
labelled-by: label1 labelled-by: label1
state: editable enabled focusable sensitive showing single-line visible state: editable enabled sensitive showing single-line visible
toolkit: gtk toolkit: gtk
<AtkComponent> <AtkComponent>
layer: widget layer: widget

View File

@ -22,7 +22,6 @@ window1
index: 0 index: 0
state: editable enabled focusable sensitive showing single-line visible state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk toolkit: gtk
placeholder-text: Subject or Addresses contain
<AtkComponent> <AtkComponent>
layer: widget layer: widget
alpha: 1 alpha: 1
@ -64,7 +63,6 @@ window1
index: 1 index: 1
state: editable enabled focusable sensitive showing single-line visible state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk toolkit: gtk
placeholder-text: Message contains
<AtkComponent> <AtkComponent>
layer: widget layer: widget
alpha: 1 alpha: 1
@ -106,7 +104,6 @@ window1
index: 2 index: 2
state: editable enabled focusable sensitive showing single-line visible state: editable enabled focusable sensitive showing single-line visible
toolkit: gtk toolkit: gtk
placeholder-text: Body contains
<AtkComponent> <AtkComponent>
layer: widget layer: widget
alpha: 1 alpha: 1

View File

@ -27,8 +27,8 @@ set_text (GtkWidget *widget,
{ {
if (GTK_IS_LABEL (widget)) if (GTK_IS_LABEL (widget))
gtk_label_set_text (GTK_LABEL (widget), text); gtk_label_set_text (GTK_LABEL (widget), text);
else if (GTK_IS_ENTRY (widget)) else if (GTK_IS_EDITABLE (widget))
gtk_entry_set_text (GTK_ENTRY (widget), text); gtk_editable_set_text (GTK_EDITABLE (widget), text);
else if (GTK_IS_TEXT_VIEW (widget)) else if (GTK_IS_TEXT_VIEW (widget))
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1); gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1);
else else
@ -47,12 +47,12 @@ append_text (GtkWidget *widget,
gtk_label_set_text (GTK_LABEL (widget), tmp); gtk_label_set_text (GTK_LABEL (widget), tmp);
g_free (tmp); g_free (tmp);
} }
else if (GTK_IS_ENTRY (widget)) else if (GTK_IS_EDITABLE (widget))
{ {
gchar *tmp; gchar *tmp;
tmp = g_strconcat (gtk_entry_get_text (GTK_ENTRY (widget)), text, NULL); tmp = g_strconcat (gtk_editable_get_text (GTK_EDITABLE (widget)), text, NULL);
gtk_entry_set_text (GTK_ENTRY (widget), tmp); gtk_editable_set_text (GTK_EDITABLE (widget), tmp);
g_free (tmp); g_free (tmp);
} }
else if (GTK_IS_TEXT_VIEW (widget)) else if (GTK_IS_TEXT_VIEW (widget))
@ -134,7 +134,7 @@ test_text_changed (GtkWidget *widget)
SignalData insert_data; SignalData insert_data;
gboolean cant_append = FALSE; gboolean cant_append = FALSE;
if (GTK_IS_LABEL (widget) || GTK_IS_ENTRY (widget)) if (GTK_IS_LABEL (widget) || GTK_IS_TEXT (widget))
cant_append = TRUE; cant_append = TRUE;
atk_text = ATK_TEXT (gtk_widget_get_accessible (widget)); atk_text = ATK_TEXT (gtk_widget_get_accessible (widget));
@ -874,9 +874,9 @@ test_words (GtkWidget *widget)
for (i = 0; expected[i].offset != -1; i++) for (i = 0; expected[i].offset != -1; i++)
{ {
if (GTK_IS_ENTRY (widget)) if (GTK_IS_TEXT (widget))
{ {
/* GtkEntry sets single-paragraph mode on its pango layout */ /* GtkText sets single-paragraph mode on its pango layout */
if (expected[i].boundary == ATK_TEXT_BOUNDARY_LINE_START || if (expected[i].boundary == ATK_TEXT_BOUNDARY_LINE_START ||
expected[i].boundary == ATK_TEXT_BOUNDARY_LINE_END) expected[i].boundary == ATK_TEXT_BOUNDARY_LINE_END)
continue; continue;
@ -1094,7 +1094,7 @@ main (int argc, char *argv[])
g_test_add_func ("/text/bold/GtkLabel", test_bold_label); g_test_add_func ("/text/bold/GtkLabel", test_bold_label);
add_text_tests (gtk_label_new ("")); add_text_tests (gtk_label_new (""));
add_text_tests (gtk_entry_new ()); add_text_tests (gtk_text_new ());
add_text_tests (gtk_text_view_new ()); add_text_tests (gtk_text_view_new ());
return g_test_run (); return g_test_run ();

View File

@ -21,8 +21,9 @@
combobox:dir(ltr) combobox:dir(ltr)
box.linked.horizontal:dir(ltr) box.linked.horizontal:dir(ltr)
entry.combo:dir(ltr) entry.combo:dir(ltr)
undershoot.left:dir(ltr) text.flat:dir(ltr)
undershoot.right:dir(ltr) undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
button.combo:dir(ltr) button.combo:dir(ltr)
box.horizontal:dir(ltr) box.horizontal:dir(ltr)
arrow:dir(ltr) arrow:dir(ltr)

View File

@ -5,22 +5,25 @@
label:dir(ltr) label:dir(ltr)
label:dir(ltr) label:dir(ltr)
entry:dir(ltr) entry:dir(ltr)
undershoot.left:dir(ltr) text.flat:dir(ltr)
undershoot.right:dir(ltr) undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
progress.horizontal:dir(ltr) progress.horizontal:dir(ltr)
trough:dir(ltr) trough:dir(ltr)
progress.left:dir(ltr) progress.left:dir(ltr)
entry:dir(ltr) entry:dir(ltr)
undershoot.left:dir(ltr) text.flat:dir(ltr)
undershoot.right:dir(ltr) undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
entry:dir(ltr) entry:dir(ltr)
image.left:dir(ltr) image.left:dir(ltr)
undershoot.left:dir(ltr) text.flat:dir(ltr)
undershoot.right:dir(ltr) undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
image.right:dir(ltr) image.right:dir(ltr)
spinbutton.horizontal:dir(ltr) spinbutton.horizontal:dir(ltr)
box.horizontal:dir(ltr) box.horizontal:dir(ltr)
entry:dir(ltr) text.flat:dir(ltr)
undershoot.left:dir(ltr) undershoot.left:dir(ltr)
undershoot.right:dir(ltr) undershoot.right:dir(ltr)
button.image-button.down:dir(ltr) button.image-button.down:dir(ltr)

View File

@ -228,12 +228,19 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_GNUC_END_IGNORE_DEPRECATIONS G_GNUC_END_IGNORE_DEPRECATIONS
/* Default invisible char is determined at runtime */ /* Default invisible char is determined at runtime,
* and buffer gets created on-demand
*/
if (g_type_is_a (type, GTK_TYPE_ENTRY) && if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
(strcmp (pspec->name, "invisible-char") == 0 || (strcmp (pspec->name, "invisible-char") == 0 ||
strcmp (pspec->name, "buffer") == 0)) strcmp (pspec->name, "buffer") == 0))
continue; continue;
if (g_type_is_a (type, GTK_TYPE_TEXT) &&
(strcmp (pspec->name, "invisible-char") == 0 ||
strcmp (pspec->name, "buffer") == 0))
continue;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (g_type_is_a (type, GTK_TYPE_ENTRY_COMPLETION) && if (g_type_is_a (type, GTK_TYPE_ENTRY_COMPLETION) &&

View File

@ -12,10 +12,10 @@ test_window_focus (void)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (window), box); gtk_container_add (GTK_CONTAINER (window), box);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("label1")); gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("label1"));
entry1 = gtk_entry_new (); entry1 = gtk_text_new ();
gtk_container_add (GTK_CONTAINER (box), entry1); gtk_container_add (GTK_CONTAINER (box), entry1);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("label2")); gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("label2"));
entry2 = gtk_entry_new (); entry2 = gtk_text_new ();
gtk_container_add (GTK_CONTAINER (box), entry2); gtk_container_add (GTK_CONTAINER (box), entry2);
g_assert_null (gtk_window_get_focus (GTK_WINDOW (window))); g_assert_null (gtk_window_get_focus (GTK_WINDOW (window)));