2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include "localized-control-factory-impl.h"
21 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <dali/integration-api/debug.h>
39 namespace // unnamed namespace
45 LocalizedControlFactory::LocalizedControlFactory()
47 mSignalsConnected( false )
51 LocalizedControlFactory::~LocalizedControlFactory()
55 Dali::Toolkit::TextView LocalizedControlFactory::CreateLocalizedTextView( const std::string& textID, const std::string& textDomain, const std::string& textViewTheme )
57 if( !mSignalsConnected )
59 Stage::GetCurrent().GetObjectRegistry().ObjectDestroyedSignal().Connect( this, &LocalizedControlFactory::OnObjectDestruction );
60 Adaptor::Get().LanguageChangedSignal().Connect( this, &LocalizedControlFactory::OnLanguageChanged );
61 mSignalsConnected = true;
64 const string& localizedText = dgettext(textDomain.c_str(), textID.c_str());
65 Dali::Toolkit::TextView textView = Dali::Toolkit::TextView::New();
66 textView.SetText(localizedText);
68 LocalisedStringInfo info(textID, textDomain, textViewTheme);
70 mObjectEntries[textView.GetObjectPtr()] = info;
75 void LocalizedControlFactory::OnObjectDestruction( const Dali::RefObject* objectPointer )
77 if(!mObjectEntries.empty())
79 //Needs optimization. All the destructed objects are currently checked for existence in entries.
80 mObjectEntries.erase(objectPointer);
84 void LocalizedControlFactory::OnLanguageChanged( Dali::Adaptor& adaptor)
86 if(!mObjectEntries.empty())
88 ObjectEntriesIterator iter = mObjectEntries.begin();
89 ObjectEntriesIterator iterEnd = mObjectEntries.end();
90 while(iter != iterEnd)
92 RefObject* refObjectPtr = const_cast<RefObject*> (iter->first);
93 BaseHandle handle(static_cast<BaseObject*>(refObjectPtr));
94 LocalisedStringInfo info = iter->second;
96 const string& localizedText = dgettext(info.textDomain.c_str(), info.textID.c_str());
98 Toolkit::TextView textView = Dali::Toolkit::TextView::DownCast( handle );
102 textView.SetText( localizedText );
106 DALI_ASSERT_ALWAYS(false && "Corrupt TextView internal pointer in entries!");
116 } // namespace Internal
118 } // namespace Toolkit