Browse Source

Work on auto-selecting contents in an edit field when you tab into it

Shaddock Heath 9 years ago
parent
commit
28c3c511ea
2 changed files with 41 additions and 0 deletions
  1. 40 0
      Source/Atomic/UI/UIEditField.cpp
  2. 1 0
      Source/Atomic/UI/UIEditField.h

+ 40 - 0
Source/Atomic/UI/UIEditField.cpp

@@ -194,6 +194,31 @@ void UIEditField::SetTextAlign(UI_TEXT_ALIGN align)
 
 }
 
+void UIEditField::OnFocusChanged(bool focused)
+{
+    UIWidget::OnFocusChanged(focused);
+
+    if (!widget_)
+        return;
+
+    // safe cast?
+    TBEditField* w = (TBEditField*) widget_;
+
+    TBStyleEdit* styleEdit = w->GetStyleEdit();
+    if (styleEdit != NULL)
+    {
+        if (focused)
+        {
+            styleEdit->selection.SelectAll();
+        }
+        else
+        {
+            styleEdit->selection.SelectNothing();
+        }
+    }
+
+}
+
 bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
 {
     if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("edit_complete"))
@@ -203,6 +228,21 @@ 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();
+   //         }
+   //     }
+   // }
 
     return UIWidget::OnEvent(ev);
 }

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

@@ -72,6 +72,7 @@ protected:
 
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
 
+    virtual void OnFocusChanged(bool focused);
 private:
 
 };