2008-12-19 17:44:56 +00:00
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <stdio.h>
|
2008-12-27 04:00:52 +00:00
|
|
|
|
#include "prop-editor.h"
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
delete_event_cb (GtkWidget *editor,
|
|
|
|
|
gint response,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (editor);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
properties_cb (GtkWidget *button,
|
|
|
|
|
GObject *entry)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *editor;
|
|
|
|
|
|
|
|
|
|
editor = g_object_get_data (entry, "properties-dialog");
|
|
|
|
|
|
|
|
|
|
if (editor == NULL)
|
|
|
|
|
{
|
|
|
|
|
editor = create_prop_editor (G_OBJECT (entry), G_TYPE_INVALID);
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (editor),
|
|
|
|
|
GTK_WINDOW (gtk_widget_get_toplevel (button)));
|
|
|
|
|
g_signal_connect (editor, "delete-event", G_CALLBACK (delete_event_cb), NULL);
|
|
|
|
|
g_object_set_data (entry, "properties-dialog", editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (editor));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-27 04:56:55 +00:00
|
|
|
|
static void
|
|
|
|
|
clear_pressed (GtkEntry *entry, gint icon, GdkEvent *event, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
if (icon == GTK_ENTRY_ICON_SECONDARY)
|
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-31 07:29:23 +00:00
|
|
|
|
static void
|
|
|
|
|
drag_begin_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
|
|
pos = gtk_entry_get_current_icon_drag_source (GTK_ENTRY (widget));
|
|
|
|
|
if (pos != -1)
|
2013-06-24 21:31:22 +00:00
|
|
|
|
gtk_drag_set_icon_name (context, "dialog-info", 2, 2);
|
2008-12-31 07:29:23 +00:00
|
|
|
|
|
|
|
|
|
g_print ("drag begin %d\n", pos);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-27 04:56:55 +00:00
|
|
|
|
static void
|
|
|
|
|
drag_data_get_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
GtkSelectionData *data,
|
|
|
|
|
guint info,
|
|
|
|
|
guint time,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
|
|
pos = gtk_entry_get_current_icon_drag_source (GTK_ENTRY (widget));
|
|
|
|
|
|
|
|
|
|
if (pos == GTK_ENTRY_ICON_PRIMARY)
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
gint start, end;
|
|
|
|
|
|
|
|
|
|
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end))
|
|
|
|
|
{
|
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
|
|
str = gtk_editable_get_chars (GTK_EDITABLE (widget), start, end);
|
|
|
|
|
gtk_selection_data_set_text (data, str, -1);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
gtk_selection_data_set_text (data, "XXX", -1);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *window;
|
2011-09-27 20:35:49 +00:00
|
|
|
|
GtkWidget *grid;
|
2008-12-19 17:44:56 +00:00
|
|
|
|
GtkWidget *label;
|
|
|
|
|
GtkWidget *entry;
|
2008-12-27 04:00:52 +00:00
|
|
|
|
GtkWidget *button;
|
2008-12-19 17:44:56 +00:00
|
|
|
|
GIcon *icon;
|
2008-12-27 04:56:55 +00:00
|
|
|
|
GtkTargetList *tlist;
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Gtk Entry Icons Test");
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 12);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (window), "destroy",
|
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
|
|
|
2011-09-27 20:35:49 +00:00
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), grid);
|
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Open File - Sets the icon using a GIcon
|
|
|
|
|
*/
|
|
|
|
|
label = gtk_label_new ("Open File:");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 0, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
|
icon = g_themed_icon_new ("folder-symbolic");
|
|
|
|
|
g_themed_icon_append_name (G_THEMED_ICON (icon), "folder-symbolic");
|
2008-12-27 04:00:52 +00:00
|
|
|
|
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
icon);
|
|
|
|
|
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
|
2008-12-27 04:56:55 +00:00
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
2008-12-19 17:44:56 +00:00
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
|
|
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
"Open a file");
|
|
|
|
|
|
2008-12-27 04:00:52 +00:00
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 0, 1, 1);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (properties_cb), entry);
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 17:44:56 +00:00
|
|
|
|
/*
|
2013-06-24 21:31:22 +00:00
|
|
|
|
* Save File - sets the icon using an icon name.
|
2008-12-19 17:44:56 +00:00
|
|
|
|
*/
|
|
|
|
|
label = gtk_label_new ("Save File:");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.5);
|
|
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), "Right-to-left");
|
|
|
|
|
gtk_widget_set_direction (entry, GTK_TEXT_DIR_RTL);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
"document-save-symbolic");
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
"Save a file");
|
2008-12-27 04:56:55 +00:00
|
|
|
|
tlist = gtk_target_list_new (NULL, 0);
|
|
|
|
|
gtk_target_list_add_text_targets (tlist, 0);
|
|
|
|
|
gtk_entry_set_icon_drag_source (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
tlist, GDK_ACTION_COPY);
|
2008-12-31 07:29:23 +00:00
|
|
|
|
g_signal_connect_after (entry, "drag-begin",
|
|
|
|
|
G_CALLBACK (drag_begin_cb), NULL);
|
2008-12-27 04:56:55 +00:00
|
|
|
|
g_signal_connect (entry, "drag-data-get",
|
|
|
|
|
G_CALLBACK (drag_data_get_cb), NULL);
|
|
|
|
|
gtk_target_list_unref (tlist);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2008-12-27 04:00:52 +00:00
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 1, 1, 1);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (properties_cb), entry);
|
|
|
|
|
|
2008-12-19 17:44:56 +00:00
|
|
|
|
/*
|
|
|
|
|
* Search - Uses a helper function
|
|
|
|
|
*/
|
|
|
|
|
label = gtk_label_new ("Search:");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 2, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
"edit-find-symbolic");
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
|
"edit-clear-symbolic");
|
2008-12-27 04:00:52 +00:00
|
|
|
|
|
2008-12-31 07:29:23 +00:00
|
|
|
|
g_signal_connect (entry, "icon-press", G_CALLBACK (clear_pressed), NULL);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 2, 1, 1);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (properties_cb), entry);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2013-06-24 21:31:22 +00:00
|
|
|
|
* Password - Sets the icon using an icon name
|
2008-12-19 17:44:56 +00:00
|
|
|
|
*/
|
|
|
|
|
label = gtk_label_new ("Password:");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 3, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
|
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
"dialog-password-symbolic");
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2008-12-27 04:56:55 +00:00
|
|
|
|
gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
|
|
|
|
|
GTK_ENTRY_ICON_PRIMARY,
|
|
|
|
|
FALSE);
|
|
|
|
|
|
2008-12-27 04:00:52 +00:00
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 3, 1, 1);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (properties_cb), entry);
|
|
|
|
|
|
2008-12-19 17:44:56 +00:00
|
|
|
|
/* Name - Does not set any icons. */
|
|
|
|
|
label = gtk_label_new ("Name:");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 4, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 1, 4, 1, 1);
|
2008-12-19 17:44:56 +00:00
|
|
|
|
|
2008-12-27 04:00:52 +00:00
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
2011-09-27 20:35:49 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 2, 4, 1, 1);
|
2008-12-27 04:00:52 +00:00
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (properties_cb), entry);
|
|
|
|
|
|
2008-12-19 17:44:56 +00:00
|
|
|
|
gtk_widget_show_all (window);
|
|
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|