Re: [gtkmm] signal_key_press_event() question



Well thank you for this excellent explanation, i am just starting to fiddle
with inheritance and stuff and this kind of thing seems essential.
I share your love/hate feeling towards c++, but i think in time i will learn
to love it. :-)

----- Original Message ----- 
From: "Daniel J. Lauk" <Daniel Lauk Student FH-Reutlingen de>
To: <mmlist xs4all nl>; <gtkmm-list gnome org>
Sent: Thursday, October 07, 2004 2:04 PM
Subject: Re: [gtkmm] signal_key_press_event() question


> Well, actually...
> ...if you had return on_key_press_event(event); at the end of your event
handler
> (where I put the Gtk::Entry::on_...), then you created an infinite loop,
yes.
>
> ...if you had it at the place where it is in your sample code below, than
the
> following occurs: If <ENTER> is pressed the key code gets changed to <TAB>
and
> the handler is reinvoked. That's perfectly fine. Only, for all non-<ENTER>
keys
> the handler simply does nothing (besides returning false).
>
> What the call Gtk::Entry::on_... does, is: it calls the (overridden)
method
> of the base class (I think the correct c.s. terminology is a "super
call").
> This is very important if you derive classes that "add" special behaviour
or
> vary the original one only a little bit (e.g. modifying/ignoring a certain
key).
> If you'd like your derived class to handle the event totally different,
you
> wouldn't call the base classes method.
>
> I hope that helped you a little bit and you'll have a lot of fun with this
awful
> language. I myself really hate C++ for giving the programmer so many
possibilities...
> no, wait... that's actually the reason why I love it... or hate? ... Eh,
anyway,
> you better make up your mind and decide for yourself, what you like and
what
> not :^)
>
> Regards,
>
> DJ
>
> >thanks for your reply,
> >
> >I tried almost the same:
> >    return on_key_press_event(event);  //this of course resulted in an
> >endless loop
> >instead of
> >    return Gtk::Entry::on_key_press_event(event);
> >I think this will bypass my NumberEntry::on_key_press_event() and thus
avoid
>
> >the endless loop, (i still have to learn some things about c++).
> >I will try this.
> >
> >thank you,
> >Marco
> >
> >----- Original Message ----- 
> >From: "Daniel J. Lauk" <Daniel Lauk Student FH-Reutlingen de>
> >To: <schwein chello nl>;
> ><"gtkmm-list gnome org"@loginmail.fh-reutlingen.de>;
<gtkmm-list gnome org>
>
> >Sent: Thursday, October 07, 2004 9:10 AM
> >Subject: Re: [gtkmm] signal_key_press_event() question
> >
> >
> >> Hi.
> >>
> >> First of all, I think, that your Gdk event handler is not doing all it
> >should,
> >> but I'm not sure.
> >> Anyway, what you'd probably like is, to have the same behaviour as with
a
>
> >regular
> >> Gtk::Entry except for the thing with the <ENTER> to <TAB> conversion,
> >right?
> >>
> >> I'm not absolutely sure on this, but you might like to experiment with
the
>
> >following
> >> code:
> >>
> >> <code>
> >> bool NumberEntry::on_key_press_event(GdkEventKey* event)
> >> {
> >>   /* first (if necessary) change the key code */
> >>   //36 = enter, 108 = keypad enter, 13 = tab
> >>   if (event->hardware_keycode==36 ||
> >>       event->hardware_keycode==108)
> >>   {
> >>     event->hardware_keycode = 13;
> >>   }
> >>
> >>   /* and now do, what Gtk::Entry would have done */
> >>   return Gtk::Entry::on_key_press_event(event);
> >> }
> >> </code>
> >>
> >> Best regards,
> >>
> >> DJ
> >>
> >> >I want to catch a keypress of enter and turn it into a tab (to go to
the
>
> >> >next entry) to enable the user to quickly enter lots of numbers with
the
>
> >> >numerical keypad.
> >> >
> >> >Then i tried this code to catch a keypress in a Gtk::Entry, but this
only
>
> >>
> >> >works with non-printable keys (tab, function keys etc.)
> >> >So i think that all printable characters get processed by the entry's
> >> >on_key_press_event() and never make it to OnKeyPress() ?.
> >> >
> >> >class NumberEntry : public Gtk::Entry
> >> >{ public:
> >> > NumberEntry();
> >> > ~NumberEntry();
> >> > bool OnKeyPress(GdkEventKey* event);
> >> >};
> >> >
> >> >NumberEntry::NumberEntry()
> >> >{ signal_key_press_event().connect(sigc::mem_fun(*this,
> >> >&NumberEntry::OnKeyPress));
> >> >}
> >> >
> >> >bool NumberEntry::OnKeyPress(GdkEventKey* event)
> >> >{ cout << "Pressed " << event->hardware_keycode << endl;
> >> > return false;
> >> >}
> >> >
> >> >
> >> >I also tried overriding the on_key_press_event() function and was able
to
>
> >>
> >> >turn an enter into a tab, however no printable characters made it into
> >the
> >>
> >> >entry box.
> >> >
> >> >bool NumberEntry::on_key_press_event(GdkEventKey* event)
> >> >{ cout << "Pressed " << event->hardware_keycode << endl;
> >> > //36 = enter, 108 = keypad enter, 13 = tab
> >> > if (event->hardware_keycode==36 || event->hardware_keycode==108)
> >> > { event->hardware_keycode = 23;
> >> > return on_key_press_event(event); //tab to next
> >> > }
> >> > return false;
> >> >}
> >> >
> >> >i'm kinda stuck now, what am i doing wrong?, or is there maybe a much
> >> >simpler way to achieve what i want?
> >> >
> >> >thanks for any help,
> >> >Marco
> >> _______________________________________________
> >> gtkmm-list mailing list
> >> gtkmm-list gnome org
> >> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >>
> >
> >
>
>




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