Re: How to handle key_press_event in PAscal (FPC)



On Sun, 2001-08-26 at 20:38, Zeljko wrote:
> 
> Please HELP about this .
> 
> Calling for this function is from
> 
> gtk_signal_connect(entry,'key_press_event'......etc
> 
> Function callback_of_some_entry(widget:PGtkWidget; event:PGDKEvent; 
> data:pgpointer): gint; cdecl;
> 
> Begin
> 	case <WHAT??> of
> 		GDK_Return : Do_THIS;
> 		GDK_Tab     : Do_That;
> 		GDK_F1       : do_something_else;
> 	End;
> 
> 	callback_of_some_entry:=0;
> End;
> 
> Could be C example also

It is going to be, 'cause I don't have any pascal bindings around, and
it has been at least 10 years since I last touched pascal.  Hope it's
helpful anyway.

The attached file shows an example of this.  The <WHAT??> in the above
is event->key.keyval (in C that is.  Don't know the equivalent in
pascal).

	/mailund

-- 
 And the Lord spake unto Elvis, "Thou hast spoken against me Elvis,
 and I curse thee to have thy blue suede shoes trod upon for all
 time..."
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

static void
key_event (GtkEntry *entry, GdkEvent *event)
{
  switch (event->key.keyval)
    {
    case GDK_Tab:
      if (strcmp ("a", gtk_entry_get_text (entry)) == 0)
	gtk_entry_set_text (entry, "ape");
      else if (strcmp ("b", gtk_entry_get_text (entry)) == 0)
	gtk_entry_set_text (entry, "bonobo");
      else if (strcmp ("c", gtk_entry_get_text (entry)) == 0)
	gtk_entry_set_text (entry, "chimpanzee");
      break;
    case GDK_Return:
      g_print ("text is now \"%s\"\n", gtk_entry_get_text (entry));
      break;
    case GDK_F1:
      gtk_entry_set_text (entry, "...<< F1 >>...");
      break;
    }

}



int
main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *entry;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  entry = gtk_entry_new ();
  gtk_container_add (GTK_CONTAINER (win), entry);

  gtk_signal_connect (GTK_OBJECT (entry), "key_press_event",
		      GTK_SIGNAL_FUNC (key_event), entry);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}

Attachment: pgpIxKXBaZam5.pgp
Description: PGP signature



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