Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / style-monitor.h
1 #ifndef DALI_STYLE_MONITOR_H
2 #define DALI_STYLE_MONITOR_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/dali-signal.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/adaptor-framework/style-change.h>
29
30 namespace Dali
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 namespace Adaptor
35 {
36 class StyleMonitor;
37 }
38 } // namespace DALI_INTERNAL
39
40 /**
41  * @brief Monitors the platform for style changes.
42  *
43  * This is a handle to the adaptor's style monitor which holds the platform's style information.
44  * It provides a signal when any aspect of the default style changes on the device.
45  * @see Adaptor::GetStyleMonitor
46  */
47 class DALI_ADAPTOR_API StyleMonitor : public BaseHandle
48 {
49 public:                                                                        // Typedefs
50   typedef Signal<void(StyleMonitor, StyleChange::Type)> StyleChangeSignalType; ///< StyleChange Signal type
51
52 public: // Creation & Destruction
53   /**
54    * @brief Create an uninitialized StyleMonitor handle.
55    *
56    * Tthis can be set by retrieving the style monitor from the Adaptor
57    * or the Application classes.  Calling member functions when
58    * uninitialized is not allowed.
59    */
60   StyleMonitor();
61
62   /**
63    * @brief Creates a copy of the handle.
64    *
65    * The copy will point to the same implementation as the original.
66    * @param[in]  monitor  The Style Monitor to copy from.
67    */
68   StyleMonitor(const StyleMonitor& monitor);
69
70   /**
71    * @brief Retrieve the initialized instance of the StyleMonitor.
72    * @return Handle to StyleMonitor.
73    */
74   static StyleMonitor Get();
75
76   /**
77    * @brief Destructor
78    *
79    * This is non-virtual since derived Handle types must not contain data or virtual methods.
80    */
81   ~StyleMonitor();
82
83   /**
84    * @brief Downcast an Object handle to StyleMonitor handle.
85    *
86    * If handle points to a StyleMonitor object the downcast produces a
87    * valid handle. If not the returned handle is left uninitialized.
88    *
89    * @param[in] handle to An object @return handle to a Timer object
90    * or an uninitialized handle
91    */
92   static StyleMonitor DownCast(BaseHandle handle);
93
94 public: // Style Information
95   /**
96    * @brief Retrieves the default font family.
97    * @return The default font family.
98    */
99   std::string GetDefaultFontFamily() const;
100
101   /**
102    * @brief Retrieves the default font style.
103    * @return The default font style.
104    */
105   std::string GetDefaultFontStyle() const;
106
107   /**
108    * @brief Retrieves the default font size.
109    *
110    * This is an logical size, which is mapped to a UI Control specific point-size in stylesheets.
111    * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
112    * @return The default font size, or a negative value if not set.
113    */
114   int GetDefaultFontSize() const;
115
116   /**
117    * @brief Retrieves the user defined Theme.
118    * @return The user defined Theme.
119    */
120   const std::string& GetTheme() const;
121
122   /**
123    * @brief Sets an user defined Theme.
124    * @param[in] themeFilePath Path of the user defined theme
125    */
126   void SetTheme(const std::string& themeFilePath);
127
128   /**
129    * @brief Utility to load a theme file
130    * @param filename of the theme
131    * @param output to write the contents to
132    * @return true if the load is successful
133    */
134   bool LoadThemeFile(const std::string& filename, std::string& output);
135
136 public: // Signals
137   /**
138    * @brief This signal is emitted whenever the style changes on the device.
139    *
140    * A callback of the following type may be connected:
141    * @code
142    *   void YourCallbackName(StyleMonitor styleMonitor, StyleChange change);
143    * @endcode
144    * @return The signal to connect to.
145    */
146   StyleChangeSignalType& StyleChangeSignal();
147
148 public: // Operators
149   /**
150    * @brief Assignment operator.
151    *
152    * The handle points to the same implementation as the one being copied from.
153    * @param[in]  monitor  The Style Monitor to copy from.
154    * @return reference to this object
155    */
156   StyleMonitor& operator=(const StyleMonitor& monitor);
157
158 public: // Not intended for application developers
159   /**
160    * @brief This constructor is used internally to create a handle from an object pointer.
161    * @param [in] styleMonitor A pointer the internal style monitor.
162    */
163   explicit DALI_INTERNAL StyleMonitor(Internal::Adaptor::StyleMonitor* styleMonitor);
164 };
165
166 } // namespace Dali
167
168 #endif // DALI_STYLE_MONITOR_H