diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkentry.c | 23 | ||||
-rw-r--r-- | gtk/gtkentry.h | 6 | ||||
-rw-r--r-- | gtk/testgtk.c | 16 |
3 files changed, 39 insertions, 6 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 3cb48d076e..5069f150b2 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -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); } } diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h index e1e4bc0679..aa17365386 100644 --- a/gtk/gtkentry.h +++ b/gtk/gtkentry.h @@ -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 diff --git a/gtk/testgtk.c b/gtk/testgtk.c index cf0a793ff6..9c6aaf7951 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -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); |