Browse Source

- Added in logic to auto-select the entire contents of a UIEditField the first time you select the field with the mouse. If the field already has focus and you click it again, it goes to the normal unselected mode with a caret at the point you clicked.

Shaddock Heath 9 years ago
parent
commit
6521ad0a90
2 changed files with 21 additions and 15 deletions
  1. 18 15
      Source/Atomic/UI/UIEditField.cpp
  2. 3 0
      Source/Atomic/UI/UIEditField.h

+ 18 - 15
Source/Atomic/UI/UIEditField.cpp

@@ -210,6 +210,7 @@ void UIEditField::OnFocusChanged(bool focused)
         if (focused)
         {
             styleEdit->selection.SelectAll();
+            firstFocusFlag_ = true;
         }
         else
         {
@@ -228,21 +229,23 @@ bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
         SendEvent(E_UIWIDGETEDITCOMPLETE, eventData);
         return true;
     }
-   // else if (ev.type == EVENT_TYPE_POINTER_DOWN)
-   // {
-   //     // Select the entire value in the field when it is selected
-   //     if (widget_  && widget_->IsCaptured() == false)
-   //     {
-   //         // safe cast?
-   //         TBEditField* w = (TBEditField*) widget_;
-
-   //         TBStyleEdit* styleEdit = w->GetStyleEdit();
-   //         if (styleEdit != NULL)
-   //         {
-   //             styleEdit->selection.SelectAll();
-   //         }
-   //     }
-   // }
+    else if (ev.type == EVENT_TYPE_POINTER_DOWN)
+    {
+        // Select the entire value in the field when it is selected
+        if (widget_ && firstFocusFlag_)
+        {
+            firstFocusFlag_ = false;
+
+            // safe cast?
+            TBEditField* w = (TBEditField*) widget_;
+
+            TBStyleEdit* styleEdit = w->GetStyleEdit();
+            if (styleEdit != NULL)
+            {
+                styleEdit->selection.SelectAll();
+            }
+        }
+    }
 
     return UIWidget::OnEvent(ev);
 }

+ 3 - 0
Source/Atomic/UI/UIEditField.h

@@ -73,6 +73,9 @@ protected:
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
 
     virtual void OnFocusChanged(bool focused);
+
+    // Used to keep track of if we have just been focused for the click select
+    bool firstFocusFlag_;
 private:
 
 };