fixed bug with text area gadgets when pressing "Escape" key
[rocksndiamonds.git] / src / libgame / gadgets.c
index f84815b0effb46f94ab5bc4f399e6a84f7864b73..c961021a3e2a56e855ed93d9096f270a5823ba63 100644 (file)
@@ -2228,6 +2228,8 @@ boolean HandleGadgetsKeyInput(Key key)
   {
     if (anyTextGadgetActive())
     {
+      boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0);
+
       // restore previous text (before activating text gadget)
       if (gi->type & GD_TYPE_TEXT_INPUT)
       {
@@ -2236,8 +2238,24 @@ boolean HandleGadgetsKeyInput(Key key)
        CheckRangeOfNumericInputGadget(gi);
       }
 
+      // store current text for text area gadgets when pressing "Escape" key
+      if (gi->type & GD_TYPE_TEXT_AREA)
+      {
+       if (!strEqual(gi->textarea.last_value, gi->textarea.value))
+         strcpy(gi->textarea.last_value, gi->textarea.value);
+       else
+         gadget_changed = FALSE;
+      }
+
       DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
 
+      if (gi->type & GD_TYPE_TEXT_AREA)
+      {
+       gi->event.type = GD_EVENT_TEXT_LEAVING;
+
+       DoGadgetCallbackAction(gi, gadget_changed);
+      }
+
       last_gi = NULL;
 
       StopTextInput();