2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "localized-control-factory-impl.h"
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali/integration-api/debug.h>
40 namespace // unnamed namespace
46 LocalizedControlFactory::LocalizedControlFactory()
48 mSignalsConnected( false )
52 LocalizedControlFactory::~LocalizedControlFactory()
56 Dali::Toolkit::TextView LocalizedControlFactory::CreateLocalizedTextView( const std::string& textID, const std::string& textDomain, const std::string& textViewTheme )
58 if( !mSignalsConnected )
60 Stage::GetCurrent().GetObjectRegistry().ObjectDestroyedSignal().Connect( this, &LocalizedControlFactory::OnObjectDestruction );
61 Adaptor::Get().LanguageChangedSignal().Connect( this, &LocalizedControlFactory::OnLanguageChanged );
62 mSignalsConnected = true;
65 const string& localizedText = dgettext(textDomain.c_str(), textID.c_str());
66 Dali::Toolkit::TextView textView = Dali::Toolkit::TextView::New();
67 textView.SetText(localizedText);
69 LocalisedStringInfo info(textID, textDomain, textViewTheme);
71 mObjectEntries[textView.GetObjectPtr()] = info;
76 void LocalizedControlFactory::OnObjectDestruction( const Dali::RefObject* objectPointer )
78 if(!mObjectEntries.empty())
80 //Needs optimization. All the destructed objects are currently checked for existence in entries.
81 mObjectEntries.erase(objectPointer);
85 void LocalizedControlFactory::OnLanguageChanged( Dali::Adaptor& adaptor)
87 if(!mObjectEntries.empty())
89 ObjectEntriesIterator iter = mObjectEntries.begin();
90 ObjectEntriesIterator iterEnd = mObjectEntries.end();
91 while(iter != iterEnd)
93 RefObject* refObjectPtr = const_cast<RefObject*> (iter->first);
94 BaseHandle handle(static_cast<BaseObject*>(refObjectPtr));
95 LocalisedStringInfo info = iter->second;
97 const string& localizedText = dgettext(info.textDomain.c_str(), info.textID.c_str());
99 Toolkit::TextView textView = Dali::Toolkit::TextView::DownCast( handle );
103 textView.SetText( localizedText );
107 DALI_ASSERT_ALWAYS(false && "Corrupt TextView internal pointer in entries!");
117 } // namespace Internal
119 } // namespace Toolkit