Dali 3D User Interface Engine
style-monitor-impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 // CLASS HEADER
19 #include "style-monitor-impl.h"
20 
21 // EXTERNAL INCLUDES
23 #include <fstream>
24 #include <sstream>
26 
27 // INTERNAL INCLUDES
28 #include <adaptor-impl.h>
29 #include <singleton-service-impl.h>
30 
31 namespace Dali
32 {
33 
34 namespace Internal
35 {
36 
37 namespace Adaptor
38 {
39 
40 namespace
41 {
42 
43 #if defined(DEBUG_ENABLED)
44 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_STYLE_MONITOR");
45 #endif
46 
52 void GetSystemDefaultFontFamily( TextAbstraction::FontClient& fontClient, std::string& fontFamily )
53 {
54  TextAbstraction::FontDescription defaultFontDescription;
55  if ( fontClient )
56  {
57  fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
58  fontFamily = defaultFontDescription.family;
59  }
60 }
61 
62 } // unnamed namespace
63 
65 {
66  Dali::StyleMonitor styleMonitor;
67 
69  if( service )
70  {
71  // Check whether the singleton is already created
72  Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
73  if( handle )
74  {
75  // If so, downcast the handle
76  styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
77  }
78  else
79  {
80  Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
81  styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
82  service.Register( typeid( styleMonitor ), styleMonitor );
83  }
84  }
85 
86  return styleMonitor;
87 }
88 
90 : mPlatformAbstraction(platformAbstraction),
91  mDefaultFontSize(-1)
92 {
95  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
97 }
98 
100 {
101 }
102 
104 {
105  switch ( styleChange )
106  {
108  {
109  if ( mFontClient )
110  {
111  mFontClient.ResetSystemDefaults();
113  }
114  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
115  break;
116  }
117 
119  {
121  break;
122  }
123 
125  {
126  break;
127  }
128  }
129 
130  EmitStyleChangeSignal(styleChange);
131 }
132 
134 {
135  return mDefaultFontFamily;
136 }
137 
139 {
140  return mDefaultFontStyle;
141 }
142 
144 {
145  return mDefaultFontSize;
146 }
147 
148 const std::string& StyleMonitor::GetTheme() const
149 {
151 }
152 
153 void StyleMonitor::SetTheme(const std::string& path)
154 {
157 }
158 
159 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
160 {
161  bool retval( false );
162  std::ifstream in( filename.c_str(), std::ios::in );
163  if( in )
164  {
165  std::stringstream buffer;
166  buffer << in.rdbuf();
167 
168  output = buffer.str();
169 
170  in.close();
171  retval = true;
172  }
173  return retval;
174 }
175 
177 {
178  return mStyleChangeSignal;
179 }
180 
182 {
183  if( !mStyleChangeSignal.Empty() )
184  {
185  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n" );
186  Dali::StyleMonitor handle( this );
187  mStyleChangeSignal.Emit( handle, styleChange );
188  }
189 }
190 
191 } // namespace Adaptor
192 
193 } // namespace Internal
194 
195 } // namespace Dali
Dali Docs Home
Read more about Dali