Browse Source

Added accept_failed callback hooks to provide feedback when the user attempts to submit a disabled field--this lets us do things like flash the text field red to get their attention.

M. Ian Graham 18 years ago
parent
commit
4429b66c8d
3 changed files with 44 additions and 0 deletions
  1. 23 0
      panda/src/pgui/pgEntry.I
  2. 18 0
      panda/src/pgui/pgEntry.cxx
  3. 3 0
      panda/src/pgui/pgEntry.h

+ 23 - 0
panda/src/pgui/pgEntry.I

@@ -413,6 +413,18 @@ get_accept_prefix() {
   return "accept-";
   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
 //     Function: PGEntry::get_overflow_prefix
 //       Access: Published, Static
 //       Access: Published, Static
@@ -460,6 +472,17 @@ get_accept_event(const ButtonHandle &button) const {
   return "accept-" + button.get_name() + "-" + get_id();
   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
 //     Function: PGEntry::get_overflow_event
 //       Access: Published
 //       Access: Published

+ 18 - 0
panda/src/pgui/pgEntry.cxx

@@ -215,6 +215,9 @@ press(const MouseWatcherParameter &param, bool background) {
           if (_accept_enabled) {
           if (_accept_enabled) {
             accept(param);
             accept(param);
           }
           }
+          else {
+            accept_failed(param);
+          }
           
           
         } else if (button == KeyboardButton::backspace()) {
         } else if (button == KeyboardButton::backspace()) {
           // Backspace.  Remove the character to the left of the cursor.
           // Backspace.  Remove the character to the left of the cursor.
@@ -410,6 +413,21 @@ accept(const MouseWatcherParameter &param) {
   set_focus(false);
   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 &param) {
+  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
 //     Function: PGEntry::overflow
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 3 - 0
panda/src/pgui/pgEntry.h

@@ -61,6 +61,7 @@ public:
   virtual void candidate(const MouseWatcherParameter &param, bool background);
   virtual void candidate(const MouseWatcherParameter &param, bool background);
 
 
   virtual void accept(const MouseWatcherParameter &param);
   virtual void accept(const MouseWatcherParameter &param);
+  virtual void accept_failed(const MouseWatcherParameter &param);
   virtual void overflow(const MouseWatcherParameter &param);
   virtual void overflow(const MouseWatcherParameter &param);
   virtual void type(const MouseWatcherParameter &param);
   virtual void type(const MouseWatcherParameter &param);
   virtual void erase(const MouseWatcherParameter &param);
   virtual void erase(const MouseWatcherParameter &param);
@@ -118,11 +119,13 @@ PUBLISHED:
   virtual void set_focus(bool focus);
   virtual void set_focus(bool focus);
 
 
   INLINE static string get_accept_prefix();
   INLINE static string get_accept_prefix();
+  INLINE static string get_accept_failed_prefix();
   INLINE static string get_overflow_prefix();
   INLINE static string get_overflow_prefix();
   INLINE static string get_type_prefix();
   INLINE static string get_type_prefix();
   INLINE static string get_erase_prefix();
   INLINE static string get_erase_prefix();
 
 
   INLINE string get_accept_event(const ButtonHandle &button) const;
   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_overflow_event() const;
   INLINE string get_type_event() const;
   INLINE string get_type_event() const;
   INLINE string get_erase_event() const;
   INLINE string get_erase_event() const;