2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
22 namespace Tizen.NUI.BaseComponents
25 /// A control which renders a short text string.<br />
26 /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
28 /// <since_tizen> 3 </since_tizen>
29 public partial class TextLabel
32 private EventHandler<AnchorClickedEventArgs> textLabelAnchorClickedEventHandler;
33 private AnchorClickedCallbackDelegate textLabelAnchorClickedCallbackDelegate;
35 private EventHandler textLabelTextFitChangedEventHandler;
36 private TextFitChangedCallbackDelegate textLabelTextFitChangedCallbackDelegate;
38 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39 private delegate void AnchorClickedCallbackDelegate(IntPtr textLabel, IntPtr href, uint hrefLength);
41 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
42 private delegate void TextFitChangedCallbackDelegate(IntPtr textLabel);
45 /// The AnchorClicked signal is emitted when the anchor is clicked.
47 /// <since_tizen> 9 </since_tizen>
48 public event EventHandler<AnchorClickedEventArgs> AnchorClicked
52 if (textLabelAnchorClickedEventHandler == null)
54 textLabelAnchorClickedCallbackDelegate = (OnAnchorClicked);
55 AnchorClickedSignal().Connect(textLabelAnchorClickedCallbackDelegate);
57 textLabelAnchorClickedEventHandler += value;
61 textLabelAnchorClickedEventHandler -= value;
62 if (textLabelAnchorClickedEventHandler == null && AnchorClickedSignal().Empty() == false)
64 AnchorClickedSignal().Disconnect(textLabelAnchorClickedCallbackDelegate);
69 internal TextLabelSignal AnchorClickedSignal()
71 TextLabelSignal ret = new TextLabelSignal(Interop.TextLabel.AnchorClickedSignal(SwigCPtr), false);
72 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76 private void OnAnchorClicked(IntPtr textLabel, IntPtr href, uint hrefLength)
78 // Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
79 // But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
80 AnchorClickedEventArgs e = new AnchorClickedEventArgs();
82 // Populate all members of "e" (AnchorClickedEventArgs) with real data
83 e.Href = Marshal.PtrToStringAnsi(href);
84 //here we send all data to user event handlers
85 textLabelAnchorClickedEventHandler?.Invoke(this, e);
89 /// An event for the TextFitChanged signal which can be used to subscribe or unsubscribe the event handler
90 /// provided by the user. The TextFitChanged signal is emitted when the text fit properties changes.<br />
92 [EditorBrowsable(EditorBrowsableState.Never)]
93 public event EventHandler TextFitChanged
97 if (textLabelTextFitChangedEventHandler == null)
99 textLabelTextFitChangedCallbackDelegate = (OnTextFitChanged);
100 TextFitChangedSignal().Connect(textLabelTextFitChangedCallbackDelegate);
102 textLabelTextFitChangedEventHandler += value;
106 textLabelTextFitChangedEventHandler -= value;
107 if (textLabelTextFitChangedEventHandler == null && TextFitChangedSignal().Empty() == false)
109 TextFitChangedSignal().Disconnect(textLabelTextFitChangedCallbackDelegate);
114 internal TextLabelSignal TextFitChangedSignal()
116 TextLabelSignal ret = new TextLabelSignal(Interop.TextLabel.TextFitChangedSignal(SwigCPtr), false);
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 private void OnTextFitChanged(IntPtr textLabel)
123 // no data to be sent to the user, as in NUI there is no event provide old values.
124 textLabelTextFitChangedEventHandler?.Invoke(this, EventArgs.Empty);