diff --git a/panda/src/pgui/pgEntry.I b/panda/src/pgui/pgEntry.I index e9a0232e77..423d5e501a 100644 --- a/panda/src/pgui/pgEntry.I +++ b/panda/src/pgui/pgEntry.I @@ -413,6 +413,18 @@ get_accept_prefix() { return "accept-"; } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_accept_failed_prefix +// Access: Published, Static +// Description: Returns the prefix that is used to define the accept +// failed event for all PGEntries. This event is the +// concatenation of this string followed by get_id(). +//////////////////////////////////////////////////////////////////// +INLINE string PGEntry:: +get_accept_failed_prefix() { + return "acceptfailed-"; +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::get_overflow_prefix // Access: Published, Static @@ -460,6 +472,17 @@ get_accept_event(const ButtonHandle &button) const { return "accept-" + button.get_name() + "-" + get_id(); } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_accept_failed_event +// Access: Published +// Description: Returns the event name that will be thrown when the +// entry cannot accept an input +//////////////////////////////////////////////////////////////////// +INLINE string PGEntry:: +get_accept_failed_event(const ButtonHandle &button) const { + return "acceptfailed-" + button.get_name() + "-" + get_id(); +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::get_overflow_event // Access: Published diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index 0ccb580b30..3b07b58e5e 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -215,6 +215,9 @@ press(const MouseWatcherParameter ¶m, bool background) { if (_accept_enabled) { accept(param); } + else { + accept_failed(param); + } } else if (button == KeyboardButton::backspace()) { // Backspace. Remove the character to the left of the cursor. @@ -410,6 +413,21 @@ accept(const MouseWatcherParameter ¶m) { set_focus(false); } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::accept_failed +// Access: Public, Virtual +// Description: This is a callback hook function, called whenever the +// user presses Enter but we can't accept the input. +//////////////////////////////////////////////////////////////////// +void PGEntry:: +accept_failed(const MouseWatcherParameter ¶m) { + PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); + string event = get_accept_failed_event(param.get_button()); + play_sound(event); + throw_event(event, EventParameter(ep)); + //set_focus(false); +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::overflow // Access: Public, Virtual diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 76d0305606..148a0dc72e 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -61,6 +61,7 @@ public: virtual void candidate(const MouseWatcherParameter ¶m, bool background); virtual void accept(const MouseWatcherParameter ¶m); + virtual void accept_failed(const MouseWatcherParameter ¶m); virtual void overflow(const MouseWatcherParameter ¶m); virtual void type(const MouseWatcherParameter ¶m); virtual void erase(const MouseWatcherParameter ¶m); @@ -118,11 +119,13 @@ PUBLISHED: virtual void set_focus(bool focus); INLINE static string get_accept_prefix(); + INLINE static string get_accept_failed_prefix(); INLINE static string get_overflow_prefix(); INLINE static string get_type_prefix(); INLINE static string get_erase_prefix(); INLINE string get_accept_event(const ButtonHandle &button) const; + INLINE string get_accept_failed_event(const ButtonHandle &button) const; INLINE string get_overflow_event() const; INLINE string get_type_event() const; INLINE string get_erase_event() const;