[NUI] Add SystemFontSizeChangedManager class
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / SystemFontSizeChangedManager.cs
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 extern alias TizenSystemSettings;
19 using TizenSystemSettings.Tizen.System;
20
21 using System;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// A static class which adds user handler to the SystemSettings.FontSizeChanged event.
27     /// This class also adds user handler to the last of the SystemSettings.FontSizeChanged event.
28     /// </summary>
29     internal static class SystemFontSizeChangedManager
30     {
31         static SystemFontSizeChangedManager()
32         {
33             SystemSettings.FontSizeChanged += SystemFontSizeChanged;
34         }
35
36         /// <summary>
37         /// The handler invoked last after all handlers added to the SystemSettings.FontSizeChanged event are invoked.
38         /// </summary>
39         public static event EventHandler<FontSizeChangedEventArgs> Finished;
40
41         /// <summary>
42         /// Adds the given handler to the SystemSettings.FontSizeChanged event.
43         /// </summary>
44         /// <param name="handler">A handler to be added to the event</param>
45         public static void Add(EventHandler<FontSizeChangedEventArgs> handler)
46         {
47             proxy.Add(handler);
48         }
49
50         /// <summary>
51         /// Removes the given handler from the SystemSettings.FontSizeChanged event.
52         /// </summary>
53         /// <param name="handler">A handler to be added to the event</param>
54         public static void Remove(EventHandler<FontSizeChangedEventArgs> handler)
55         {
56             proxy.Remove(handler);
57         }
58
59         private static void SystemFontSizeChanged(object sender, FontSizeChangedEventArgs args)
60         {
61             proxy.Invoke(sender, args);
62             Finished?.Invoke(sender, args);
63         }
64
65         private static WeakEvent<EventHandler<FontSizeChangedEventArgs>> proxy = new WeakEvent<EventHandler<FontSizeChangedEventArgs>>();
66     }
67 }