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"
|
|
|
|
|
2020-06-05 19:15:28 +00:00
|
|
|
#include "gtkpasswordentryprivate.h"
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2020-10-13 01:33:55 +00:00
|
|
|
#include "gtkaccessibleprivate.h"
|
2019-02-17 03:21:57 +00:00
|
|
|
#include "gtktextprivate.h"
|
|
|
|
#include "gtkeditable.h"
|
2020-09-04 11:52:03 +00:00
|
|
|
#include "gtkeventcontrollerkey.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"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2021-06-08 11:25:11 +00:00
|
|
|
#include "gtkpasswordentrybuffer.h"
|
2020-09-04 11:52:03 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2020-10-22 18:27:19 +00:00
|
|
|
#include "gtkcsspositionvalueprivate.h"
|
2021-01-28 04:07:55 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2021-07-08 21:16:06 +00:00
|
|
|
#include "gtkjoinedmenuprivate.h"
|
2020-10-22 18:27:19 +00:00
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-22 04:40:14 +00:00
|
|
|
* GtkPasswordEntry:
|
|
|
|
*
|
|
|
|
* `GtkPasswordEntry` is an entry that has been tailored for entering secrets.
|
|
|
|
*
|
|
|
|
* ![An example GtkPasswordEntry](password-entry.png)
|
2019-02-17 03:21:57 +00:00
|
|
|
*
|
2019-03-13 20:27:07 +00:00
|
|
|
* It does not show its contents in clear text, does not allow to copy it
|
2020-09-08 22:40:44 +00:00
|
|
|
* to the clipboard, and it shows a warning when Caps Lock is engaged. If
|
2021-02-22 04:40:14 +00:00
|
|
|
* the underlying platform allows it, `GtkPasswordEntry` will also place
|
|
|
|
* the text in a non-pageable memory area, to avoid it being written out
|
|
|
|
* to disk by the operating system.
|
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.
|
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* `GtkPasswordEntry` provides only minimal API and should be used with
|
|
|
|
* the [iface@Gtk.Editable] API.
|
2020-06-26 15:56:27 +00:00
|
|
|
*
|
|
|
|
* # CSS Nodes
|
|
|
|
*
|
2021-02-28 01:03:43 +00:00
|
|
|
* ```
|
2020-06-26 15:56:27 +00:00
|
|
|
* entry.password
|
|
|
|
* ╰── text
|
|
|
|
* ├── image.caps-lock-indicator
|
|
|
|
* ┊
|
2021-02-28 01:03:43 +00:00
|
|
|
* ```
|
2020-06-26 15:56:27 +00:00
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* `GtkPasswordEntry` has a single CSS node with name entry that carries
|
2020-06-26 15:56:27 +00:00
|
|
|
* a .passwordstyle class. The text Css node below it has a child with
|
|
|
|
* name image and style class .caps-lock-indicator for the Caps Lock
|
|
|
|
* icon, and possibly other children.
|
2020-07-28 22:23:57 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* `GtkPasswordEntry` uses the %GTK_ACCESSIBLE_ROLE_TEXT_BOX role.
|
2019-02-17 03:21:57 +00:00
|
|
|
*/
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
struct _GtkPasswordEntry
|
|
|
|
{
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *icon;
|
2019-03-13 20:27:07 +00:00
|
|
|
GtkWidget *peek_icon;
|
2020-04-05 05:04:20 +00:00
|
|
|
GdkDevice *keyboard;
|
2019-04-11 18:46:55 +00:00
|
|
|
GMenuModel *extra_menu;
|
2020-09-19 17:23:40 +00:00
|
|
|
};
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2019-05-19 17:29:37 +00:00
|
|
|
struct _GtkPasswordEntryClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
2020-09-19 17:25:03 +00:00
|
|
|
enum {
|
|
|
|
ACTIVATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
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-04-11 18:46:55 +00:00
|
|
|
PROP_EXTRA_MENU,
|
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);
|
2020-10-13 01:33:55 +00:00
|
|
|
static void gtk_password_entry_accessible_init (GtkAccessibleInterface *iface);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkPasswordEntry, gtk_password_entry, GTK_TYPE_WIDGET,
|
2020-10-13 01:33:55 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE, gtk_password_entry_accessible_init)
|
2019-02-17 03:21:57 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_password_entry_editable_init))
|
|
|
|
|
|
|
|
static void
|
2020-04-05 05:04:20 +00:00
|
|
|
caps_lock_state_changed (GdkDevice *device,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkWidget *widget)
|
2019-02-17 03:21:57 +00:00
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
|
|
|
|
|
|
|
|
if (gtk_editable_get_editable (GTK_EDITABLE (entry)) &&
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_has_focus (entry->entry) &&
|
|
|
|
!gtk_text_get_visibility (GTK_TEXT (entry->entry)) &&
|
2020-04-05 05:04:20 +00:00
|
|
|
gdk_device_get_caps_lock_state (device))
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_show (entry->icon);
|
2019-02-17 03:21:57 +00:00
|
|
|
else
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_hide (entry->icon);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
focus_changed (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->keyboard)
|
|
|
|
caps_lock_state_changed (entry->keyboard, NULL, widget);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
2020-10-15 20:18:35 +00:00
|
|
|
|
2021-08-23 23:12:31 +00:00
|
|
|
static void
|
|
|
|
gtk_password_entry_icon_press (GtkGesture *gesture)
|
|
|
|
{
|
|
|
|
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_CLAIMED);
|
|
|
|
}
|
|
|
|
|
2020-10-15 20:18:35 +00:00
|
|
|
/*< private >
|
|
|
|
* gtk_password_entry_toggle_peek:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @entry: a `GtkPasswordEntry`
|
2020-10-15 20:18:35 +00:00
|
|
|
*
|
|
|
|
* Toggles the text visibility.
|
|
|
|
*/
|
|
|
|
void
|
2019-03-13 20:27:07 +00:00
|
|
|
gtk_password_entry_toggle_peek (GtkPasswordEntry *entry)
|
2019-06-15 19:30:10 +00:00
|
|
|
{
|
|
|
|
gboolean visibility;
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
visibility = gtk_text_get_visibility (GTK_TEXT (entry->entry));
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (entry->entry), !visibility);
|
2019-06-15 19:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
visibility_toggled (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkPasswordEntry *entry)
|
2019-03-13 20:27:07 +00:00
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
if (gtk_text_get_visibility (GTK_TEXT (entry->entry)))
|
2019-03-13 20:27:07 +00:00
|
|
|
{
|
2022-04-22 12:21:02 +00:00
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (entry->peek_icon), "view-conceal-symbolic");
|
2021-07-20 11:00:05 +00:00
|
|
|
gtk_widget_set_tooltip_text (entry->peek_icon, _("Hide Text"));
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-22 12:21:02 +00:00
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (entry->peek_icon), "view-reveal-symbolic");
|
2021-07-20 11:00:05 +00:00
|
|
|
gtk_widget_set_tooltip_text (entry->peek_icon, _("Show Text"));
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
2020-04-05 04:30:23 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->keyboard)
|
|
|
|
caps_lock_state_changed (entry->keyboard, NULL, GTK_WIDGET (entry));
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 17:25:03 +00:00
|
|
|
static void
|
|
|
|
activate_cb (GtkPasswordEntry *entry)
|
|
|
|
{
|
|
|
|
g_signal_emit (entry, signals[ACTIVATE], 0);
|
|
|
|
}
|
|
|
|
|
2021-08-23 23:13:29 +00:00
|
|
|
static void
|
|
|
|
catchall_click_press (GtkGestureClick *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
|
|
|
}
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
static void
|
|
|
|
gtk_password_entry_init (GtkPasswordEntry *entry)
|
|
|
|
{
|
2021-08-23 23:13:29 +00:00
|
|
|
GtkGesture *catchall;
|
2020-09-04 11:52:03 +00:00
|
|
|
GtkEntryBuffer *buffer = gtk_password_entry_buffer_new ();
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
entry->entry = gtk_text_new ();
|
|
|
|
gtk_text_set_buffer (GTK_TEXT (entry->entry), buffer);
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (entry->entry), FALSE);
|
|
|
|
gtk_widget_set_parent (entry->entry, GTK_WIDGET (entry));
|
2019-02-17 03:21:57 +00:00
|
|
|
gtk_editable_init_delegate (GTK_EDITABLE (entry));
|
2020-09-19 17:23:40 +00:00
|
|
|
g_signal_connect_swapped (entry->entry, "notify::has-focus", G_CALLBACK (focus_changed), entry);
|
2020-09-19 17:25:03 +00:00
|
|
|
g_signal_connect_swapped (entry->entry, "activate", G_CALLBACK (activate_cb), entry);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
entry->icon = gtk_image_new_from_icon_name ("caps-lock-symbolic");
|
|
|
|
gtk_widget_set_tooltip_text (entry->icon, _("Caps Lock is on"));
|
|
|
|
gtk_widget_add_css_class (entry->icon, "caps-lock-indicator");
|
|
|
|
gtk_widget_set_cursor (entry->icon, gtk_widget_get_cursor (entry->entry));
|
|
|
|
gtk_widget_set_parent (entry->icon, GTK_WIDGET (entry));
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2021-08-23 23:13:29 +00:00
|
|
|
catchall = gtk_gesture_click_new ();
|
|
|
|
g_signal_connect (catchall, "pressed",
|
|
|
|
G_CALLBACK (catchall_click_press), entry);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (entry),
|
|
|
|
GTK_EVENT_CONTROLLER (catchall));
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (entry), I_("password"));
|
2019-04-11 18:46:55 +00:00
|
|
|
|
|
|
|
gtk_password_entry_set_extra_menu (entry, NULL);
|
2020-09-04 11:52:03 +00:00
|
|
|
|
|
|
|
/* Transfer ownership to the GtkText widget */
|
|
|
|
g_object_unref (buffer);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_password_entry_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
|
2020-05-15 01:27:45 +00:00
|
|
|
GdkSeat *seat;
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_password_entry_parent_class)->realize (widget);
|
|
|
|
|
2020-05-15 01:27:45 +00:00
|
|
|
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
|
|
|
|
if (seat)
|
2020-09-19 17:23:40 +00:00
|
|
|
entry->keyboard = gdk_seat_get_keyboard (seat);
|
2020-05-15 01:27:45 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->keyboard)
|
2020-05-15 01:27:45 +00:00
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
g_signal_connect (entry->keyboard, "notify::caps-lock-state",
|
2020-05-15 01:27:45 +00:00
|
|
|
G_CALLBACK (caps_lock_state_changed), entry);
|
2020-09-19 17:23:40 +00:00
|
|
|
caps_lock_state_changed (entry->keyboard, NULL, widget);
|
2020-05-15 01:27:45 +00:00
|
|
|
}
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_password_entry_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->keyboard)
|
|
|
|
g_signal_handlers_disconnect_by_func (entry->keyboard, caps_lock_state_changed, entry);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->entry)
|
2019-02-17 03:21:57 +00:00
|
|
|
gtk_editable_finish_delegate (GTK_EDITABLE (entry));
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
g_clear_pointer (&entry->entry, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&entry->icon, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&entry->peek_icon, gtk_widget_unparent);
|
|
|
|
g_clear_object (&entry->extra_menu);
|
2019-02-17 03:21:57 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_password_entry_parent_class)->dispose (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);
|
2020-07-28 22:23:57 +00:00
|
|
|
const char *text;
|
2019-03-13 23:17:19 +00:00
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
|
2020-07-28 22:23:57 +00:00
|
|
|
{
|
|
|
|
if (prop_id == NUM_PROPERTIES + GTK_EDITABLE_PROP_EDITABLE)
|
|
|
|
{
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_READ_ONLY, !g_value_get_boolean (value),
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PLACEHOLDER_TEXT:
|
2020-07-28 22:23:57 +00:00
|
|
|
text = g_value_get_string (value);
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_text_set_placeholder_text (GTK_TEXT (entry->entry), text);
|
2020-07-28 22:23:57 +00:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER, text,
|
|
|
|
-1);
|
2019-03-13 23:17:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTIVATES_DEFAULT:
|
2020-09-19 17:23:40 +00:00
|
|
|
if (gtk_text_get_activates_default (GTK_TEXT (entry->entry)) != g_value_get_boolean (value))
|
2019-03-17 01:03:52 +00:00
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_text_set_activates_default (GTK_TEXT (entry->entry), g_value_get_boolean (value));
|
2019-03-17 01:03:52 +00:00
|
|
|
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;
|
|
|
|
|
2019-04-11 18:46:55 +00:00
|
|
|
case PROP_EXTRA_MENU:
|
|
|
|
gtk_password_entry_set_extra_menu (entry, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
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);
|
|
|
|
|
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:
|
2020-09-19 17:23:40 +00:00
|
|
|
g_value_set_string (value, gtk_text_get_placeholder_text (GTK_TEXT (entry->entry)));
|
2019-03-13 23:17:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTIVATES_DEFAULT:
|
2020-09-19 17:23:40 +00:00
|
|
|
g_value_set_boolean (value, gtk_text_get_activates_default (GTK_TEXT (entry->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;
|
|
|
|
|
2019-04-11 18:46:55 +00:00
|
|
|
case PROP_EXTRA_MENU:
|
2020-09-19 17:23:40 +00:00
|
|
|
g_value_set_object (value, entry->extra_menu);
|
2019-04-11 18:46:55 +00:00
|
|
|
break;
|
|
|
|
|
2019-03-13 23:17:19 +00:00
|
|
|
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);
|
2019-03-27 04:21:11 +00:00
|
|
|
int icon_min = 0, icon_nat = 0;
|
2019-02-17 03:21:57 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_measure (entry->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
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->icon && gtk_widget_get_visible (entry->icon))
|
|
|
|
gtk_widget_measure (entry->icon, orientation, for_size,
|
2019-03-27 04:21:11 +00:00
|
|
|
&icon_min, &icon_nat,
|
|
|
|
NULL, NULL);
|
2020-10-22 18:27:19 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->peek_icon && gtk_widget_get_visible (entry->peek_icon))
|
|
|
|
gtk_widget_measure (entry->peek_icon, orientation, for_size,
|
2019-03-27 04:21:11 +00:00
|
|
|
&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);
|
2020-10-22 18:27:19 +00:00
|
|
|
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
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;
|
2020-10-22 18:27:19 +00:00
|
|
|
int spacing;
|
|
|
|
|
|
|
|
spacing = _gtk_css_position_value_get_x (style->size->border_spacing, 100);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->icon && gtk_widget_get_visible (entry->icon))
|
|
|
|
gtk_widget_measure (entry->icon, GTK_ORIENTATION_HORIZONTAL, -1,
|
2019-03-27 04:21:11 +00:00
|
|
|
&icon_min, &icon_nat,
|
|
|
|
NULL, NULL);
|
2020-10-22 18:27:19 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->peek_icon && gtk_widget_get_visible (entry->peek_icon))
|
|
|
|
gtk_widget_measure (entry->peek_icon, GTK_ORIENTATION_HORIZONTAL, -1,
|
2019-03-27 04:21:11 +00:00
|
|
|
&peek_min, &peek_nat,
|
|
|
|
NULL, NULL);
|
2020-10-22 18:27:19 +00:00
|
|
|
|
|
|
|
text_width = width - (icon_nat + (icon_nat > 0 ? spacing : 0))
|
|
|
|
- (peek_nat + (peek_nat > 0 ? spacing : 0));
|
2019-03-27 04:21:11 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_size_allocate (entry->entry,
|
2019-03-27 04:21:11 +00:00
|
|
|
&(GtkAllocation) { 0, 0, text_width, height },
|
2019-02-17 03:21:57 +00:00
|
|
|
baseline);
|
2019-03-27 04:21:11 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->icon && gtk_widget_get_visible (entry->icon))
|
|
|
|
gtk_widget_size_allocate (entry->icon,
|
2020-10-22 18:27:19 +00:00
|
|
|
&(GtkAllocation) { text_width + spacing, 0, icon_nat, height },
|
2019-03-27 04:21:11 +00:00
|
|
|
baseline);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->peek_icon && gtk_widget_get_visible (entry->peek_icon))
|
|
|
|
gtk_widget_size_allocate (entry->peek_icon,
|
2020-10-22 18:27:19 +00:00
|
|
|
&(GtkAllocation) { text_width + spacing + icon_nat + (icon_nat > 0 ? spacing : 0), 0, peek_nat, height },
|
2019-03-27 04:21:11 +00:00
|
|
|
baseline);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_grab_focus (entry->entry);
|
2019-03-04 03:14:19 +00:00
|
|
|
|
|
|
|
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->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;
|
2019-03-04 03:14:19 +00:00
|
|
|
widget_class->mnemonic_activate = gtk_password_entry_mnemonic_activate;
|
2020-05-11 03:58:30 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
2020-06-15 17:45:57 +00:00
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2020-04-08 11:43:28 +00:00
|
|
|
|
2021-02-22 04:40:14 +00:00
|
|
|
/**
|
|
|
|
* GtkPasswordEntry:placeholder-text:
|
|
|
|
*
|
|
|
|
* The text that will be displayed in the `GtkPasswordEntry`
|
|
|
|
* when it is empty and unfocused.
|
|
|
|
*/
|
2019-03-13 23:17:19 +00:00
|
|
|
props[PROP_PLACEHOLDER_TEXT] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("placeholder-text", NULL, NULL,
|
2019-03-13 23:17:19 +00:00
|
|
|
NULL,
|
2019-03-17 01:03:52 +00:00
|
|
|
GTK_PARAM_READWRITE);
|
2019-03-13 23:17:19 +00:00
|
|
|
|
2021-02-22 04:40:14 +00:00
|
|
|
/**
|
|
|
|
* GtkPasswordEntry:activates-default:
|
|
|
|
*
|
|
|
|
* Whether to activate the default widget when Enter is pressed.
|
|
|
|
*/
|
2019-03-13 23:17:19 +00:00
|
|
|
props[PROP_ACTIVATES_DEFAULT] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("activates-default", NULL, NULL,
|
2019-03-13 23:17:19 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2021-02-22 04:40:14 +00:00
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* GtkPasswordEntry:show-peek-icon: (attributes org.gtk.Property.get=gtk_password_entry_get_show_peek_icon org.gtk.Property.set=gtk_password_entry_set_show_peek_icon)
|
2021-02-22 04:40:14 +00:00
|
|
|
*
|
|
|
|
* Whether to show an icon for revealing the content.
|
|
|
|
*/
|
2019-03-13 20:27:07 +00:00
|
|
|
props[PROP_SHOW_PEEK_ICON] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("show-peek-icon", NULL, NULL,
|
2019-03-13 20:27:07 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2019-04-11 18:46:55 +00:00
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* GtkPasswordEntry:extra-menu: (attributes org.gtk.Property.get=gtk_password_entry_get_extra_menu org.gtk.Property.set=gtk_password_entry_set_extra_menu)
|
2019-04-11 18:46:55 +00:00
|
|
|
*
|
|
|
|
* A menu model whose contents will be appended to
|
|
|
|
* the context menu.
|
|
|
|
*/
|
|
|
|
props[PROP_EXTRA_MENU] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("extra-menu", NULL, NULL,
|
2019-04-11 18:46:55 +00:00
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
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
|
|
|
|
2020-09-29 02:52:35 +00:00
|
|
|
/**
|
2021-02-22 04:40:14 +00:00
|
|
|
* GtkPasswordEntry::activate:
|
2020-09-29 02:52:35 +00:00
|
|
|
* @self: The widget on which the signal is emitted
|
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* Emitted when the entry is activated.
|
|
|
|
*
|
|
|
|
* The keybindings for this signal are all forms of the Enter key.
|
2020-09-29 02:52:35 +00:00
|
|
|
*/
|
2020-09-19 17:25:03 +00:00
|
|
|
signals[ACTIVATE] =
|
|
|
|
g_signal_new (I_("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
0,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("entry"));
|
2020-07-28 22:23:57 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TEXT_BOX);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkEditable *
|
|
|
|
gtk_password_entry_get_delegate (GtkEditable *editable)
|
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (editable);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
return GTK_EDITABLE (entry->entry);
|
2019-02-17 03:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_password_entry_editable_init (GtkEditableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_delegate = gtk_password_entry_get_delegate;
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:33:55 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_password_entry_accessible_get_platform_state (GtkAccessible *self,
|
|
|
|
GtkAccessiblePlatformState state)
|
|
|
|
{
|
|
|
|
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (self);
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE:
|
|
|
|
return gtk_widget_get_focusable (GTK_WIDGET (entry->entry));
|
|
|
|
case GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED:
|
|
|
|
return gtk_widget_has_focus (GTK_WIDGET (entry->entry));
|
2021-04-17 19:23:04 +00:00
|
|
|
case GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE:
|
|
|
|
return FALSE;
|
2020-10-13 01:33:55 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_password_entry_accessible_init (GtkAccessibleInterface *iface)
|
|
|
|
{
|
|
|
|
GtkAccessibleInterface *parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
iface->get_at_context = parent_iface->get_at_context;
|
|
|
|
iface->get_platform_state = gtk_password_entry_accessible_get_platform_state;
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:17:13 +00:00
|
|
|
/*< private >
|
|
|
|
* gtk_password_entry_get_text_widget
|
2021-05-20 13:17:04 +00:00
|
|
|
* @entry: a `GtkPasswordEntry`
|
2020-12-16 15:17:13 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Retrieves the `GtkText` delegate of the `GtkPasswordEntry`.
|
2020-12-16 15:17:13 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Returns: (transfer none): the `GtkText` delegate widget
|
2020-12-16 15:17:13 +00:00
|
|
|
*/
|
2020-06-05 19:15:28 +00:00
|
|
|
GtkText *
|
|
|
|
gtk_password_entry_get_text_widget (GtkPasswordEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_PASSWORD_ENTRY (entry), NULL);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
return GTK_TEXT (entry->entry);
|
2020-06-05 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 03:21:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_password_entry_new:
|
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* Creates a `GtkPasswordEntry`.
|
2019-02-17 03:21:57 +00:00
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* Returns: a new `GtkPasswordEntry`
|
2019-02-17 03:21:57 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* gtk_password_entry_set_show_peek_icon: (attributes org.gtk.Method.set_property=show-peek-icon)
|
2021-02-22 04:40:14 +00:00
|
|
|
* @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
|
2021-02-22 04:40:14 +00:00
|
|
|
* to reveal the contents.
|
2019-03-13 20:27:07 +00:00
|
|
|
*
|
|
|
|
* Setting this to %FALSE also hides the text again.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_password_entry_set_show_peek_icon (GtkPasswordEntry *entry,
|
|
|
|
gboolean show_peek_icon)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_PASSWORD_ENTRY (entry));
|
|
|
|
|
2019-07-24 06:10:37 +00:00
|
|
|
show_peek_icon = !!show_peek_icon;
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (show_peek_icon == (entry->peek_icon != NULL))
|
2019-03-13 20:27:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (show_peek_icon)
|
|
|
|
{
|
|
|
|
GtkGesture *press;
|
|
|
|
|
2022-04-22 12:21:02 +00:00
|
|
|
entry->peek_icon = gtk_image_new_from_icon_name ("view-reveal-symbolic");
|
2021-07-20 11:00:05 +00:00
|
|
|
gtk_widget_set_tooltip_text (entry->peek_icon, _("Show Text"));
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_set_parent (entry->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 ();
|
2021-08-23 23:12:31 +00:00
|
|
|
g_signal_connect (press, "pressed",
|
|
|
|
G_CALLBACK (gtk_password_entry_icon_press), entry);
|
2019-03-13 20:27:07 +00:00
|
|
|
g_signal_connect_swapped (press, "released",
|
|
|
|
G_CALLBACK (gtk_password_entry_toggle_peek), entry);
|
2020-09-19 17:23:40 +00:00
|
|
|
gtk_widget_add_controller (entry->peek_icon, GTK_EVENT_CONTROLLER (press));
|
2019-06-15 19:30:10 +00:00
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
g_signal_connect (entry->entry, "notify::visibility",
|
2019-06-15 19:30:10 +00:00
|
|
|
G_CALLBACK (visibility_toggled), entry);
|
2020-09-19 17:23:40 +00:00
|
|
|
visibility_toggled (G_OBJECT (entry->entry), NULL, entry);
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
g_clear_pointer (&entry->peek_icon, gtk_widget_unparent);
|
|
|
|
gtk_text_set_visibility (GTK_TEXT (entry->entry), FALSE);
|
|
|
|
g_signal_handlers_disconnect_by_func (entry->entry,
|
2019-06-15 19:30:10 +00:00
|
|
|
visibility_toggled,
|
|
|
|
entry);
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->keyboard)
|
|
|
|
caps_lock_state_changed (entry->keyboard, NULL, GTK_WIDGET (entry));
|
2019-03-15 18:35:25 +00:00
|
|
|
|
2019-03-13 20:27:07 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_SHOW_PEEK_ICON]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* gtk_password_entry_get_show_peek_icon: (attributes org.gtk.Method.get_property=show-peek-icon)
|
2021-02-22 04:40:14 +00:00
|
|
|
* @entry: a `GtkPasswordEntry`
|
2019-03-13 20:27:07 +00:00
|
|
|
*
|
2021-02-22 04:40:14 +00:00
|
|
|
* Returns whether the entry is showing an icon to
|
|
|
|
* reveal the contents.
|
2019-03-13 20:27:07 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if an icon is shown
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_PASSWORD_ENTRY (entry), FALSE);
|
|
|
|
|
2020-09-19 17:23:40 +00:00
|
|
|
return entry->peek_icon != NULL;
|
2019-03-13 20:27:07 +00:00
|
|
|
}
|
2019-04-11 18:46:55 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* gtk_password_entry_set_extra_menu: (attributes org.gtk.Method.set_property=extra-menu)
|
2021-02-22 04:40:14 +00:00
|
|
|
* @entry: a `GtkPasswordEntry`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @model: (nullable): a `GMenuModel`
|
2019-04-11 18:46:55 +00:00
|
|
|
*
|
|
|
|
* Sets a menu model to add when constructing
|
|
|
|
* the context menu for @entry.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_password_entry_set_extra_menu (GtkPasswordEntry *entry,
|
|
|
|
GMenuModel *model)
|
|
|
|
{
|
2021-07-08 21:16:06 +00:00
|
|
|
GtkJoinedMenu *joined;
|
2019-04-11 18:46:55 +00:00
|
|
|
GMenu *menu;
|
|
|
|
GMenu *section;
|
|
|
|
GMenuItem *item;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_PASSWORD_ENTRY (entry));
|
|
|
|
|
2019-06-15 19:30:10 +00:00
|
|
|
/* bypass this check for the initial call from init */
|
2020-09-19 17:23:40 +00:00
|
|
|
if (entry->extra_menu)
|
2019-06-15 19:30:10 +00:00
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
if (!g_set_object (&entry->extra_menu, model))
|
2019-06-15 19:30:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-11 18:46:55 +00:00
|
|
|
|
2021-07-08 21:16:06 +00:00
|
|
|
joined = gtk_joined_menu_new ();
|
2019-04-11 18:46:55 +00:00
|
|
|
menu = g_menu_new ();
|
|
|
|
|
|
|
|
section = g_menu_new ();
|
2019-06-15 19:30:10 +00:00
|
|
|
item = g_menu_item_new (_("_Show Text"), "misc.toggle-visibility");
|
2022-04-22 12:21:02 +00:00
|
|
|
g_menu_item_set_attribute (item, "touch-icon", "s", "view-reveal-symbolic");
|
2019-04-11 18:46:55 +00:00
|
|
|
g_menu_append_item (section, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
|
|
|
|
g_object_unref (section);
|
|
|
|
|
2021-07-08 21:16:06 +00:00
|
|
|
gtk_joined_menu_append_menu (joined, G_MENU_MODEL (menu));
|
|
|
|
g_object_unref (menu);
|
|
|
|
|
2019-04-11 18:46:55 +00:00
|
|
|
if (model)
|
2021-07-08 21:16:06 +00:00
|
|
|
gtk_joined_menu_append_menu (joined, model);
|
2019-04-11 18:46:55 +00:00
|
|
|
|
2021-07-08 21:16:06 +00:00
|
|
|
gtk_text_set_extra_menu (GTK_TEXT (entry->entry), G_MENU_MODEL (joined));
|
2019-04-11 18:46:55 +00:00
|
|
|
|
2021-07-08 21:16:06 +00:00
|
|
|
g_object_unref (joined);
|
2019-04-11 18:46:55 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_EXTRA_MENU]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:03:03 +00:00
|
|
|
* gtk_password_entry_get_extra_menu: (attributes org.gtk.Method.get_property=extra-menu)
|
2021-02-22 04:40:14 +00:00
|
|
|
* @entry: a `GtkPasswordEntry`
|
2019-04-11 18:46:55 +00:00
|
|
|
*
|
|
|
|
* Gets the menu model set with gtk_password_entry_set_extra_menu().
|
|
|
|
*
|
2022-01-01 16:49:11 +00:00
|
|
|
* Returns: (transfer none) (nullable): the menu model
|
2019-04-11 18:46:55 +00:00
|
|
|
*/
|
|
|
|
GMenuModel *
|
|
|
|
gtk_password_entry_get_extra_menu (GtkPasswordEntry *entry)
|
|
|
|
{
|
2020-09-19 17:23:40 +00:00
|
|
|
return entry->extra_menu;
|
2019-04-11 18:46:55 +00:00
|
|
|
}
|