Commit 51a481d9 authored by Elliot Lee's avatar Elliot Lee
Browse files

Added gtk_entry_set_editable()

parent d2aa891c
......@@ -325,6 +325,7 @@ gtk_entry_init (GtkEntry *entry)
entry->have_selection = FALSE;
entry->timer = 0;
entry->visible = 1;
entry->editable = 1;
entry->clipboard_text = NULL;
#ifdef USE_XIM
......@@ -452,7 +453,7 @@ gtk_entry_set_position (GtkEntry *entry,
void
gtk_entry_set_visibility (GtkEntry *entry,
gint visible)
gboolean visible)
{
g_return_if_fail (entry != NULL);
g_return_if_fail (GTK_IS_ENTRY (entry));
......@@ -460,6 +461,16 @@ gtk_entry_set_visibility (GtkEntry *entry,
entry->visible = visible;
}
void
gtk_entry_set_editable(GtkEntry *entry,
gboolean editable)
{
g_return_if_fail (entry != NULL);
g_return_if_fail (GTK_IS_ENTRY (entry));
entry->editable = editable;
gtk_entry_queue_draw(entry);
}
gchar*
gtk_entry_get_text (GtkEntry *entry)
{
......@@ -966,6 +977,9 @@ gtk_entry_key_press (GtkWidget *widget,
entry = GTK_ENTRY (widget);
return_val = FALSE;
if(entry->editable == FALSE)
return FALSE;
extend_selection = event->state & GDK_SHIFT_MASK;
extend_start = FALSE;
......@@ -1020,7 +1034,9 @@ gtk_entry_key_press (GtkWidget *widget,
if (event->state & GDK_CONTROL_MASK)
gtk_delete_line (entry);
else if (event->state & GDK_SHIFT_MASK)
gtk_entry_cut_clipboard (entry, event);
{
gtk_entry_cut_clipboard (entry, event);
}
else
gtk_delete_forward_character (entry);
}
......@@ -1449,7 +1465,8 @@ gtk_entry_draw_text (GtkEntry *entry)
}
}
gtk_entry_draw_cursor (entry);
if(entry->editable)
gtk_entry_draw_cursor (entry);
}
}
......
......@@ -52,6 +52,7 @@ struct _GtkEntry
gint16 scroll_offset;
guint have_selection : 1;
guint visible : 1;
guint editable : 1;
guint32 timer;
GdkIC ic;
......@@ -74,7 +75,6 @@ struct _GtkEntryClass
void (* activate) (GtkEntry *entry);
};
guint gtk_entry_get_type (void);
GtkWidget* gtk_entry_new (void);
GtkWidget* gtk_entry_new_with_max_length (guint16 max);
......@@ -91,7 +91,9 @@ void gtk_entry_select_region (GtkEntry *entry,
gint start,
gint end);
void gtk_entry_set_visibility (GtkEntry *entry,
gint visible);
gboolean visible);
void gtk_entry_set_editable (GtkEntry *entry,
gboolean editable);
#ifdef __cplusplus
......
......@@ -1331,12 +1331,21 @@ create_scrolled_windows ()
/*
* GtkEntry
*/
void entry_toggle_editable (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_editable(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
void
create_entry ()
{
static GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *editable_check;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *separator;
......@@ -1366,7 +1375,6 @@ create_entry ()
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
entry = gtk_entry_new ();
/* gtk_widget_set_usize (entry, 0, 25); */
gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
......@@ -1375,6 +1383,12 @@ create_entry ()
gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
editable_check = gtk_check_button_new_with_label("Editable");
gtk_box_pack_start (GTK_BOX (box2), editable_check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(editable_check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE);
gtk_widget_show (editable_check);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
......
......@@ -1331,12 +1331,21 @@ create_scrolled_windows ()
/*
* GtkEntry
*/
void entry_toggle_editable (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_editable(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
void
create_entry ()
{
static GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *editable_check;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *separator;
......@@ -1366,7 +1375,6 @@ create_entry ()
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
entry = gtk_entry_new ();
/* gtk_widget_set_usize (entry, 0, 25); */
gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
......@@ -1375,6 +1383,12 @@ create_entry ()
gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
editable_check = gtk_check_button_new_with_label("Editable");
gtk_box_pack_start (GTK_BOX (box2), editable_check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(editable_check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(editable_check), TRUE);
gtk_widget_show (editable_check);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment