From: Kangho Hur Date: Thu, 9 Mar 2017 11:33:10 +0000 (+0900) Subject: Add elm_focus related APIs X-Git-Tag: submit/trunk/20170823.075128~110^2~153^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de7066ef5a09ea06bd9320f5eee2d4d8ac0937e8;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add elm_focus related APIs Change-Id: I47b4892e37c03788fc9f0da97c1b51f77a9d51a3 --- diff --git a/src/ElmSharp/ElmSharp/Widget.cs b/src/ElmSharp/ElmSharp/Widget.cs index 1db45a5..06df4db 100644 --- a/src/ElmSharp/ElmSharp/Widget.cs +++ b/src/ElmSharp/ElmSharp/Widget.cs @@ -19,6 +19,16 @@ using System.Collections.Generic; namespace ElmSharp { + public enum FocusDirection + { + Previous, + Next, + Up, + Down, + Right, + Left + } + public abstract class Widget : EvasObject { Dictionary _partContents = new Dictionary(); @@ -78,6 +88,14 @@ namespace ElmSharp } } + public bool IsFocusAllowed + { + get + { + return Interop.Elementary.elm_object_focus_allow_get(RealHandle); + } + } + public virtual string Text { get @@ -136,6 +154,21 @@ namespace ElmSharp Interop.Elementary.elm_object_focus_set(RealHandle, isFocus); } + public void AllowFocus(bool isAllowFocus) + { + Interop.Elementary.elm_object_focus_allow_set(RealHandle, isAllowFocus); + } + + public void FocusNext(FocusDirection direction) + { + Interop.Elementary.elm_object_focus_next(RealHandle, (int)direction); + } + + public void SetNextFocusObject(EvasObject next, FocusDirection direction) + { + Interop.Elementary.elm_object_focus_next_object_set(RealHandle, next.RealHandle, (int)direction); + } + public void SetPartContent(string part, EvasObject content) { SetPartContent(part, content, false); diff --git a/src/ElmSharp/Interop/Interop.Elementary.cs b/src/ElmSharp/Interop/Interop.Elementary.cs index aa17cc0..07505ae 100644 --- a/src/ElmSharp/Interop/Interop.Elementary.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.cs @@ -221,6 +221,21 @@ internal static partial class Interop internal static extern void elm_object_focus_set(IntPtr obj, bool focus); [DllImport(Libraries.Elementary)] + internal static extern bool elm_object_focus_allow_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_focus_allow_set(IntPtr obj, bool enable); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_focus_next(IntPtr obj, int direction); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_focus_next_object_set(IntPtr obj, IntPtr next, int direction); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_focus_next_item_set(IntPtr obj, IntPtr nextItem, int direction); + + [DllImport(Libraries.Elementary)] internal static extern void elm_theme_extension_add(IntPtr theme, string path); [DllImport(Libraries.Elementary)] diff --git a/test/ElmSharp.Test/ElmSharp.Test.csproj b/test/ElmSharp.Test/ElmSharp.Test.csproj old mode 100755 new mode 100644 index 74232bd..219b24d --- a/test/ElmSharp.Test/ElmSharp.Test.csproj +++ b/test/ElmSharp.Test/ElmSharp.Test.csproj @@ -47,6 +47,7 @@ + diff --git a/test/ElmSharp.Test/TC/FocusTest1.cs b/test/ElmSharp.Test/TC/FocusTest1.cs new file mode 100644 index 0000000..033280b --- /dev/null +++ b/test/ElmSharp.Test/TC/FocusTest1.cs @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace ElmSharp.Test +{ + public class FocusTest1 : TestCaseBase + { + public override string TestName => "FocusTest1"; + public override string TestDescription => "To test basic operation of Focus"; + + Button currentButton; + Label lbInfo; + + public override void Run(Window window) + { + Conformant conformant = new Conformant(window); + conformant.Show(); + Box box = new Box(window); + conformant.SetContent(box); + box.Show(); + + Box buttonBox1 = new Box(window) + { + IsHorizontal = true, + AlignmentX = -1, + AlignmentY = 0, + }; + buttonBox1.Show(); + + Box buttonBox2 = new Box(window) + { + IsHorizontal = true, + AlignmentX = -1, + AlignmentY = 0, + }; + buttonBox2.Show(); + + Box buttonBox3 = new Box(window) + { + IsHorizontal = true, + AlignmentX = -1, + AlignmentY = 0, + }; + buttonBox3.Show(); + + Button leftButton = new Button(window) + { + Text = "Left", + BackgroundColor = Color.Gray, + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + leftButton.Show(); + + Button rightButton = new Button(window) + { + Text = "Right", + BackgroundColor = Color.Gray, + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + rightButton.Show(); + + Button upButton = new Button(window) + { + Text = "Up", + BackgroundColor = Color.Gray, + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + upButton.Show(); + + Button downButton = new Button(window) + { + Text = "Down", + BackgroundColor = Color.Gray, + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + downButton.Show(); + + leftButton.Focused += Button_Focused; + leftButton.Unfocused += Button_Unfocused; + rightButton.Focused += Button_Focused; + rightButton.Unfocused += Button_Unfocused; + upButton.Focused += Button_Focused; + upButton.Unfocused += Button_Unfocused; + downButton.Focused += Button_Focused; + downButton.Unfocused += Button_Unfocused; + + leftButton.AllowFocus(false); + rightButton.AllowFocus(false); + upButton.AllowFocus(false); + downButton.AllowFocus(false); + + buttonBox1.PackEnd(leftButton); + buttonBox1.PackEnd(rightButton); + buttonBox1.PackEnd(upButton); + buttonBox1.PackEnd(downButton); + + Button buttonA = new Button(window) + { + Text = "A", + AlignmentX = 0.5, + WeightX = 1, + WeightY = 1 + }; + buttonA.Show(); + + Button buttonB = new Button(window) + { + Text = "B", + AlignmentX = 0.5, + WeightX = 1, + WeightY = 1 + }; + buttonB.Show(); + + buttonBox2.PackEnd(buttonA); + buttonBox2.PackEnd(buttonB); + + buttonA.Focused += Button_Focused; + buttonA.Unfocused += Button_Unfocused; + buttonB.Focused += Button_Focused; + buttonB.Unfocused += Button_Unfocused; + + Button itemButton1 = new Button(window) + { + Text = "No.1", + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + itemButton1.Show(); + + Button itemButton2 = new Button(window) + { + Text = "No.2", + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + itemButton2.Show(); + + Button itemButton3 = new Button(window) + { + Text = "No.3", + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + itemButton3.Show(); + + Button itemButton4 = new Button(window) { + Text = "No.4", + AlignmentX = -1, + AlignmentY = -1, + WeightX = 1, + WeightY = 1 + }; + itemButton4.Show(); + + itemButton1.Focused += Button_Focused; + itemButton1.Unfocused += Button_Unfocused; + itemButton2.Focused += Button_Focused; + itemButton2.Unfocused += Button_Unfocused; + itemButton3.Focused += Button_Focused; + itemButton3.Unfocused += Button_Unfocused; + itemButton4.Focused += Button_Focused; + itemButton4.Unfocused += Button_Unfocused; + + itemButton1.SetNextFocusObject(itemButton4, FocusDirection.Left); + itemButton2.SetNextFocusObject(itemButton1, FocusDirection.Left); + itemButton3.SetNextFocusObject(itemButton2, FocusDirection.Left); + itemButton4.SetNextFocusObject(itemButton3, FocusDirection.Left); + itemButton1.SetNextFocusObject(itemButton2, FocusDirection.Right); + itemButton2.SetNextFocusObject(itemButton3, FocusDirection.Right); + itemButton3.SetNextFocusObject(itemButton4, FocusDirection.Right); + itemButton4.SetNextFocusObject(itemButton1, FocusDirection.Right); + itemButton1.SetNextFocusObject(buttonA, FocusDirection.Up); + itemButton2.SetNextFocusObject(buttonA, FocusDirection.Up); + itemButton3.SetNextFocusObject(buttonA, FocusDirection.Up); + itemButton4.SetNextFocusObject(buttonA, FocusDirection.Up); + + buttonA.SetNextFocusObject(buttonB, FocusDirection.Left); + buttonB.SetNextFocusObject(buttonA, FocusDirection.Left); + buttonA.SetNextFocusObject(buttonB, FocusDirection.Right); + buttonB.SetNextFocusObject(buttonA, FocusDirection.Right); + buttonA.SetNextFocusObject(itemButton1, FocusDirection.Down); + buttonB.SetNextFocusObject(itemButton1, FocusDirection.Down); + + buttonBox3.PackEnd(itemButton1); + buttonBox3.PackEnd(itemButton2); + buttonBox3.PackEnd(itemButton3); + buttonBox3.PackEnd(itemButton4); + + leftButton.Clicked += (s, e) => + { + if (currentButton != null) + { + currentButton.FocusNext(FocusDirection.Left); + } + }; + rightButton.Clicked += (s, e) => + { + if (currentButton != null) + { + currentButton.FocusNext(FocusDirection.Right); + } + }; + upButton.Clicked += (s, e) => + { + if (currentButton != null) + { + currentButton.FocusNext(FocusDirection.Up); + } + }; + downButton.Clicked += (s, e) => + { + if (currentButton != null) + { + currentButton.FocusNext(FocusDirection.Down); + } + }; + + lbInfo = new Label(window) { + Color = Color.White, + AlignmentX = -1, + AlignmentY = 0, + WeightX = 1 + }; + lbInfo.Show(); + + box.PackEnd(lbInfo); + box.PackEnd(buttonBox1); + box.PackEnd(buttonBox2); + box.PackEnd(buttonBox3); + } + + void Button_Focused(object sender, EventArgs e) + { + var btn = sender as Button; + if (btn!=null) + { + btn.BackgroundColor = Color.Red; + currentButton = btn; + lbInfo.Text = "Focused Button : " + btn.Text; + } + } + + void Button_Unfocused(object sender, EventArgs e) + { + var btn = sender as Button; + if (btn != null) + { + btn.BackgroundColor = Color.Default; + currentButton = btn; + lbInfo.Text = ""; + } + } + } +}