2019-02-17 03:21:57 +00:00
|
|
|
|
/* 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"
|
2019-05-29 17:10:46 +00:00
|
|
|
|
#include "gtkgestureclick.h"
|
2019-02-17 03:21:57 +00:00
|
|
|
|
#include "gtkbox.h"
|
|
|
|
|
#include "gtkimage.h"
|
2019-03-13 20:27:07 +00:00
|
|
|
|
#include "gtkcheckmenuitem.h"
|
2019-02-17 03:21:57 +00:00
|
|
|
|
#include "gtkintl.h"
|
2019-03-13 23:17:19 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2019-02-17 03:21:57 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
#include "gtkstylecontext.h"
|
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
|
|
|
|
|
|
|
|
|
#include "a11y/gtkentryaccessible.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
|
* SECTION:gtkpasswordentry
|
2019-02-17 03:21:57 +00:00
|
|
|
|
* @Short_description: An entry for secrets
|
|
|
|
|
* @Title: GtkPasswordEntry
|
|
|
|
|
*
|
2019-03-13 20:27:07 +00:00
|
|
|
|
* #GtkPasswordEntry is entry that has been tailored for entering secrets.
|
|
|
|
|
* It does not show its contents in clear text, does not allow to copy it
|
|
|
|
|
* to the clipboard, and it shows a warning when Caps Lock is engaged.
|
2019-02-24 20:29:08 +00:00
|
|
|
|
*
|
2019-03-13 20:27:07 +00:00
|
|
|
|
* Optionally, it can offer a way to reveal the contents in clear text.
|
|
|
|
|
*
|
|
|
|
|
* GtkPasswordEntry provides only minimal API and should be used with the
|
|
|
|
|
* #GtkEditable API.
|
2019-02-17 03:21:57 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
GtkWidget *icon;
|
2019-03-13 20:27:07 +00:00
|
|
|
|
GtkWidget *peek_icon;
|
2019-03-27 04:21:11 +00:00
|
|
|
|
GdkKeymap *keymap;
|
2019-02-17 03:21:57 +00:00
|
|
|
|
} GtkPasswordEntryPrivate;
|
|
|
|
|
|
2019-05-19 17:29:37 +00:00
|
|
|
|
struct _GtkPasswordEntryClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
|
enum {
|
|
|
|
|
PROP_PLACEHOLDER_TEXT = 1,
|
|
|
|
|
PROP_ACTIVATES_DEFAULT,
|
2019-03-13 20:27:07 +00:00
|
|
|
|
PROP_SHOW_PEEK_ICON,
|
2019-03-13 23:17:19 +00:00
|
|
|
|
NUM_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
|
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
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) &&
|
2019-03-15 18:35:25 +00:00
|
|
|
|
gdk_keymap_get_caps_lock_state (priv->keymap) &&
|
|
|
|
|
!priv->peek_icon)
|
2019-02-17 03:21:57 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 20:27:07 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_password_entry_toggle_peek (GtkPasswordEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
if (gtk_text_get_visibility (GTK_TEXT (priv->entry)))
|
|
|
|
|
{
|
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (priv->entry), FALSE);
|
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (priv->peek_icon), "eye-not-looking-symbolic");
|
|
|
|
|
gtk_widget_set_tooltip_text (priv->peek_icon, _("Show text"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (priv->entry), TRUE);
|
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (priv->peek_icon), "eye-open-negative-filled-symbolic");
|
|
|
|
|
gtk_widget_set_tooltip_text (priv->peek_icon, _("Hide text"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
populate_popup (GtkText *text,
|
|
|
|
|
GtkWidget *popup,
|
|
|
|
|
GtkPasswordEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
if (priv->peek_icon != NULL)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
|
|
item = gtk_check_menu_item_new_with_mnemonic (_("_Show text"));
|
|
|
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
|
|
|
|
|
gtk_text_get_visibility (text));
|
|
|
|
|
g_signal_connect_swapped (item, "activate",
|
|
|
|
|
G_CALLBACK (gtk_password_entry_toggle_peek), entry);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (popup), item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_password_entry_init (GtkPasswordEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
priv->entry = gtk_text_new ();
|
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (priv->entry), FALSE);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
gtk_widget_set_parent (priv->entry, GTK_WIDGET (entry));
|
2019-02-17 03:21:57 +00:00
|
|
|
|
gtk_editable_init_delegate (GTK_EDITABLE (entry));
|
|
|
|
|
g_signal_connect_swapped (priv->entry, "notify::has-focus", G_CALLBACK (focus_changed), entry);
|
2019-03-13 20:27:07 +00:00
|
|
|
|
g_signal_connect (priv->entry, "populate-popup", G_CALLBACK (populate_popup), entry);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
2019-03-14 22:59:35 +00:00
|
|
|
|
priv->icon = gtk_image_new_from_icon_name ("caps-lock-symbolic");
|
2019-02-17 03:21:57 +00:00
|
|
|
|
gtk_widget_set_tooltip_text (priv->icon, _("Caps Lock is on"));
|
2019-03-15 00:03:34 +00:00
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (priv->icon), "caps-lock-indicator");
|
2019-03-14 23:17:39 +00:00
|
|
|
|
gtk_widget_set_cursor (priv->icon, gtk_widget_get_cursor (priv->entry));
|
2019-03-27 04:21:11 +00:00
|
|
|
|
gtk_widget_set_parent (priv->icon, GTK_WIDGET (entry));
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2019-03-13 20:34:27 +00:00
|
|
|
|
keymap_state_changed (priv->keymap, widget);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-03-13 20:27:07 +00:00
|
|
|
|
g_clear_pointer (&priv->peek_icon, gtk_widget_unparent);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-03-13 23:17:19 +00:00
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
|
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:
|
2019-03-17 01:03:52 +00:00
|
|
|
|
if (gtk_text_get_activates_default (GTK_TEXT (priv->entry)) != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
gtk_text_set_activates_default (GTK_TEXT (priv->entry), g_value_get_boolean (value));
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-03-13 20:27:07 +00:00
|
|
|
|
|
|
|
|
|
case PROP_SHOW_PEEK_ICON:
|
|
|
|
|
gtk_password_entry_set_show_peek_icon (entry, g_value_get_boolean (value));
|
2019-03-13 23:17:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-17 03:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_password_entry_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2019-03-13 23:17:19 +00:00
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
|
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)));
|
2019-04-13 08:51:37 +00:00
|
|
|
|
break;
|
2019-03-13 20:27:07 +00:00
|
|
|
|
|
|
|
|
|
case PROP_SHOW_PEEK_ICON:
|
|
|
|
|
g_value_set_boolean (value, gtk_password_entry_get_show_peek_icon (entry));
|
2019-03-13 23:17:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-17 03:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
int icon_min = 0, icon_nat = 0;
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
2019-03-27 04:21:11 +00:00
|
|
|
|
gtk_widget_measure (priv->entry, orientation, for_size,
|
2019-02-17 03:21:57 +00:00
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
|
|
|
|
|
if (priv->icon && gtk_widget_get_visible (priv->icon))
|
|
|
|
|
gtk_widget_measure (priv->icon, orientation, for_size,
|
|
|
|
|
&icon_min, &icon_nat,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (priv->peek_icon && gtk_widget_get_visible (priv->peek_icon))
|
|
|
|
|
gtk_widget_measure (priv->peek_icon, orientation, for_size,
|
|
|
|
|
&icon_min, &icon_nat,
|
|
|
|
|
NULL, NULL);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
int icon_min = 0, icon_nat = 0;
|
|
|
|
|
int peek_min = 0, peek_nat = 0;
|
|
|
|
|
int text_width;
|
|
|
|
|
|
|
|
|
|
if (priv->icon && gtk_widget_get_visible (priv->icon))
|
|
|
|
|
gtk_widget_measure (priv->icon, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
|
&icon_min, &icon_nat,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (priv->peek_icon && gtk_widget_get_visible (priv->peek_icon))
|
|
|
|
|
gtk_widget_measure (priv->peek_icon, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
|
&peek_min, &peek_nat,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
text_width = width - icon_nat - peek_nat;
|
|
|
|
|
|
|
|
|
|
gtk_widget_size_allocate (priv->entry,
|
|
|
|
|
&(GtkAllocation) { 0, 0, text_width, height },
|
2019-02-17 03:21:57 +00:00
|
|
|
|
baseline);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
|
|
|
|
|
if (priv->icon && gtk_widget_get_visible (priv->icon))
|
|
|
|
|
gtk_widget_size_allocate (priv->icon,
|
|
|
|
|
&(GtkAllocation) { text_width, 0, icon_nat, height },
|
|
|
|
|
baseline);
|
|
|
|
|
|
|
|
|
|
if (priv->peek_icon && gtk_widget_get_visible (priv->peek_icon))
|
|
|
|
|
gtk_widget_size_allocate (priv->peek_icon,
|
|
|
|
|
&(GtkAllocation) { text_width + icon_nat, 0, peek_nat, height },
|
|
|
|
|
baseline);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 03:14:19 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_password_entry_mnemonic_activate (GtkWidget *widget,
|
|
|
|
|
gboolean group_cycling)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (priv->entry);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
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;
|
2019-03-04 03:14:19 +00:00
|
|
|
|
widget_class->mnemonic_activate = gtk_password_entry_mnemonic_activate;
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
|
props[PROP_PLACEHOLDER_TEXT] =
|
|
|
|
|
g_param_spec_string ("placeholder-text",
|
|
|
|
|
P_("Placeholder text"),
|
|
|
|
|
P_("Show text in the entry when it’s empty and unfocused"),
|
|
|
|
|
NULL,
|
2019-03-17 01:03:52 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2019-03-13 23:17:19 +00:00
|
|
|
|
|
|
|
|
|
props[PROP_ACTIVATES_DEFAULT] =
|
|
|
|
|
g_param_spec_boolean ("activates-default",
|
|
|
|
|
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);
|
|
|
|
|
|
2019-03-13 20:27:07 +00:00
|
|
|
|
props[PROP_SHOW_PEEK_ICON] =
|
|
|
|
|
g_param_spec_boolean ("show-peek-icon",
|
|
|
|
|
P_("Show Peek Icon"),
|
|
|
|
|
P_("Whether to show an icon for revealing the content"),
|
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
|
|
|
|
|
gtk_editable_install_properties (object_class, NUM_PROPERTIES);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
2019-03-13 20:27:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_password_entry_set_show_peek_icon:
|
|
|
|
|
* @entry: a #GtkPasswordEntry
|
2019-05-02 02:57:49 +00:00
|
|
|
|
* @show_peek_icon: whether to show the peek icon
|
2019-03-13 20:27:07 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets whether the entry should have a clickable icon
|
|
|
|
|
* to show the contents of the entry in clear text.
|
|
|
|
|
*
|
|
|
|
|
* Setting this to %FALSE also hides the text again.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_password_entry_set_show_peek_icon (GtkPasswordEntry *entry,
|
|
|
|
|
gboolean show_peek_icon)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_PASSWORD_ENTRY (entry));
|
|
|
|
|
|
|
|
|
|
if (show_peek_icon == (priv->peek_icon != NULL))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (show_peek_icon)
|
|
|
|
|
{
|
|
|
|
|
GtkGesture *press;
|
|
|
|
|
|
|
|
|
|
priv->peek_icon = gtk_image_new_from_icon_name ("eye-not-looking-symbolic");
|
|
|
|
|
gtk_widget_set_tooltip_text (priv->peek_icon, _("Show text"));
|
2019-03-27 04:21:11 +00:00
|
|
|
|
gtk_widget_set_parent (priv->peek_icon, GTK_WIDGET (entry));
|
2019-03-13 20:27:07 +00:00
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
|
press = gtk_gesture_click_new ();
|
2019-03-13 20:27:07 +00:00
|
|
|
|
g_signal_connect_swapped (press, "released",
|
|
|
|
|
G_CALLBACK (gtk_password_entry_toggle_peek), entry);
|
|
|
|
|
gtk_widget_add_controller (priv->peek_icon, GTK_EVENT_CONTROLLER (press));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_clear_pointer (&priv->peek_icon, gtk_widget_unparent);
|
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (priv->entry), FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 18:35:25 +00:00
|
|
|
|
keymap_state_changed (priv->keymap, GTK_WIDGET (entry));
|
|
|
|
|
|
2019-03-13 20:27:07 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_SHOW_PEEK_ICON]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_password_entry_get_show_peek_icon:
|
|
|
|
|
* @entry: a #GtkPasswordEntry
|
|
|
|
|
*
|
|
|
|
|
* Returns whether the entry is showing a clickable icon
|
|
|
|
|
* to reveal the contents of the entry in clear text.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if an icon is shown
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PASSWORD_ENTRY (entry), FALSE);
|
|
|
|
|
|
|
|
|
|
return priv->peek_icon != NULL;
|
|
|
|
|
}
|