[NUI] Add SystemSettings.FontTypeChanged in Text components
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / TextLabel.cs
index 5d5a9b8..feaff57 100755 (executable)
@@ -81,6 +81,9 @@ namespace Tizen.NUI.BaseComponents
 
         static TextLabel() { }
 
+        static private string defaultFontFamily = "TizenSans";
+        private string fontFamily = defaultFontFamily;
+        private bool hasSystemFontTypeChanged = false;
         private string textLabelSid = null;
         private bool systemlangTextFlag = false;
         private TextLabelSelectorData selectorData;
@@ -166,6 +169,11 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private bool HasStyle()
+        {
+            return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
@@ -253,6 +261,51 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private string InternalFontFamily
+        {
+            get
+            {
+                if (HasStyle())
+                    return fontFamily;
+                else
+                    return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
+            }
+            set
+            {
+                string newFontFamily;
+
+                if (string.Equals(fontFamily, value)) return;
+
+                fontFamily = value;
+                if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
+                {
+                    try
+                    {
+                        newFontFamily = SystemSettings.FontType;
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine("{0} Exception caught.", e);
+                        newFontFamily = defaultFontFamily;
+                    }
+                    AddSystemSettingsFontTypeChanged();
+                }
+                else
+                {
+                    newFontFamily = fontFamily;
+                    RemoveSystemSettingsFontTypeChanged();
+                }
+
+                SetInternalFontFamily(newFontFamily);
+            }
+        }
+
+        private void SetInternalFontFamily(string fontFamily)
+        {
+            Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
+            RequestLayout();
+        }
+
         /// <summary>
         /// The FontStyle property.<br />
         /// The requested font style to use.<br />
@@ -1513,6 +1566,8 @@ namespace Tizen.NUI.BaseComponents
                 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
             }
 
+            RemoveSystemSettingsFontTypeChanged();
+
             removeFontSizeChangedCallback();
 
             if (type == DisposeTypes.Explicit)
@@ -1608,6 +1663,45 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
+        {
+            SetInternalFontFamily(e.Value);
+        }
+
+        private void AddSystemSettingsFontTypeChanged()
+        {
+            if (HasStyle() && !hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged += SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = true;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = false;
+                }
+            }
+        }
+        
+        private void RemoveSystemSettingsFontTypeChanged()
+        {
+            if (hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged -= SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = false;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = true;
+                }
+            }
+        }
+
         private void RequestLayout()
         {
             Layout?.RequestLayout();