"accept" signal for entry widget?



Hi,

I'm using the latest GTK snapshot (gtk+970606), and cannot find a way
to make the "entry" widget signal when user "accepts" the value,
eg. presses the enter key.

I looked into gtkentry.c and found that entry_signals defines only
three signals ("insert_text", "delete_text" and "changed"), also
control_keys[] doesn't define any action for ctrl-m or ctrl-j. 

Also any signals are raised only after processing gtk_entry_key_press
meaning that the signal handlers won't get their hands on the keypress
before the ^M/^J is already lost..

I would need to verify the entry value after user has "finished" with
it (presses enter), now it seems impossible because the available
signals are called after every character with no way to tell when
enter has been pressed.

I could of course try something like fiddling with class
key_press_event field but dunno.. Also, I would need capability to
change the entry field into a password field, eg. with no character
echo (or replacement with "*"?), I think this needs fiddling with
gtk_entry_draw_text and a boolean value (maybe a flag value, with
options to display text normally, as empty regardless of contest or
replace characters with an asterisk).

Having said that, I figured out there's no help like own help and
patched gtkentry.[ch] to have an additional signal "accept" which is
invoked when the user hits GDK_Return key. Works For Me(tm) patch,
that is. 

--
santtu@iki.fi                    I have become death, destroyer of the worlds.
*** gtk+970606/gtk/gtkentry.c	Fri Jun  6 10:02:00 1997
--- gtk+970606-mod/gtk/gtkentry.c	Sat Jun 14 20:32:42 1997
***************
*** 32,37 ****
--- 32,38 ----
    INSERT_TEXT,
    DELETE_TEXT,
    CHANGED,
+   ACCEPT,
    LAST_SIGNAL
  };
  
***************
*** 131,137 ****
  static void gtk_select_region             (GtkEntry          *entry,
  					   gint               start,
  					   gint               end);
! 
  
  static GtkWidgetClass *parent_class = NULL;
  static gint entry_signals[LAST_SIGNAL] = { 0 };
--- 132,138 ----
  static void gtk_select_region             (GtkEntry          *entry,
  					   gint               start,
  					   gint               end);
! static void gtk_accept_line               (GtkEntry          *entry);
  
  static GtkWidgetClass *parent_class = NULL;
  static gint entry_signals[LAST_SIGNAL] = { 0 };
***************
*** 150,156 ****
    NULL,                          /* j */
    gtk_delete_to_line_end,        /* k */
    NULL,                          /* l */
!   NULL,                          /* m */
    NULL,                          /* n */
    NULL,                          /* o */
    NULL,                          /* p */
--- 151,157 ----
    NULL,                          /* j */
    gtk_delete_to_line_end,        /* k */
    NULL,                          /* l */
!   gtk_accept_line,               /* m */
    NULL,                          /* n */
    NULL,                          /* o */
    NULL,                          /* p */
***************
*** 248,253 ****
--- 249,259 ----
  				     object_class->type,
  				     GTK_SIGNAL_OFFSET (GtkEntryClass, changed),
  				     gtk_signal_default_marshaller, GTK_ARG_NONE, 0);
+   entry_signals[3] = gtk_signal_new ("accept",
+ 				     GTK_RUN_LAST,
+ 				     object_class->type,
+ 				     GTK_SIGNAL_OFFSET (GtkEntryClass, accept),
+ 				     gtk_signal_default_marshaller, GTK_ARG_NONE, 0);
  
    gtk_object_class_add_signals (object_class, entry_signals, LAST_SIGNAL);
  
***************
*** 273,278 ****
--- 279,285 ----
    class->insert_text = gtk_real_entry_insert_text;
    class->delete_text = gtk_real_entry_delete_text;
    class->changed = gtk_entry_adjust_scroll;
+   class->accept = NULL;
  }
  
  static void
***************
*** 802,807 ****
--- 809,817 ----
        return_val = TRUE;
        gtk_move_forward_character (entry);
        break;
+     case GDK_Return:
+ 	gtk_accept_line(entry);
+ 	break;
      default:
        if ((event->keyval >= 0x20) && (event->keyval <= 0xFF))
  	{
***************
*** 1511,1514 ****
--- 1521,1530 ----
    entry->have_selection = TRUE;
    entry->selection_start_pos = start;
    entry->selection_end_pos = end;
+ }
+ 
+ static void
+ gtk_accept_line (GtkEntry *entry)
+ {
+     gtk_signal_emit(GTK_OBJECT(entry), entry_signals[ACCEPT]);
  }
*** gtk+970606/gtk/gtkentry.h	Mon Apr 28 00:14:33 1997
--- gtk+970606-mod/gtk/gtkentry.h	Sat Jun 14 20:35:11 1997
***************
*** 65,70 ****
--- 65,71 ----
  			 gint      start_pos,
  			 gint      end_pos);
    void (* changed)      (GtkEntry *entry);
+   void (* accept)       (GtkEntry *entry);
  };
  
  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]