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.
17 #include "style-change-processor.h"
19 #include <boost/thread/tss.hpp>
21 #include "dali-toolkit/public-api/controls/control.h"
22 #include "dali-toolkit/public-api/controls/control-impl.h"
35 boost::thread_specific_ptr<StyleChangeProcessor> gThreadLocalStyleChangeProcessor;
36 } // unnamed namespace
38 StyleChangeProcessor::~StyleChangeProcessor()
42 void StyleChangeProcessor::Register( ControlImpl* control )
44 // Only create a style change processor if we have not created one in the local thread storage.
45 if (!gThreadLocalStyleChangeProcessor.get())
47 gThreadLocalStyleChangeProcessor.reset(new StyleChangeProcessor);
50 gThreadLocalStyleChangeProcessor->Reference();
52 std::vector<ControlImpl*>& controls( gThreadLocalStyleChangeProcessor->mControls );
54 // Store the Control raw pointer to allow traverse all off stage controls.
55 DALI_ASSERT_ALWAYS( ( std::find( controls.begin(), controls.end(), control ) == controls.end() ) && "StyleChangeProcessor::Register. The control has been registered twice." );
57 controls.push_back( control );
60 void StyleChangeProcessor::Unregister( ControlImpl* control )
62 if (gThreadLocalStyleChangeProcessor.get())
64 std::vector<ControlImpl*>& controls( gThreadLocalStyleChangeProcessor->mControls );
66 // Removes the control from the vector as is not needed to notify it about style changes.
67 std::vector<ControlImpl*>::iterator it = std::find( controls.begin(), controls.end(), control );
68 std::vector<ControlImpl*>::iterator endIt = controls.end();
69 DALI_ASSERT_ALWAYS( ( it != endIt ) && "StyleChangeProcessor::UnRegister. The control has not been registered in the StyleChangeProcessor." );
72 controls.erase( endIt - 1 );
74 gThreadLocalStyleChangeProcessor->Unreference();
78 void StyleChangeProcessor::Reference()
83 void StyleChangeProcessor::Unreference()
87 // If our count is 0, then we should reset the local storage which will call our destructor as well.
88 gThreadLocalStyleChangeProcessor.reset();
92 StyleChangeProcessor::StyleChangeProcessor()
95 if ( Adaptor::IsAvailable() )
97 StyleMonitor::Get().StyleChangeSignal().Connect(this, &StyleChangeProcessor::StyleChanged);
101 void StyleChangeProcessor::StyleChanged(Dali::StyleMonitor styleMonitor, StyleChange styleChange)
103 // Traverse all registered controls.
104 std::vector<ControlImpl*>& controls( gThreadLocalStyleChangeProcessor->mControls );
106 for( std::vector<ControlImpl*>::iterator it = controls.begin(), endIt = controls.end(); it != endIt; ++it )
108 // Create a valid handle.
109 IntrusivePtr<ControlImpl> implementation( *it );
113 implementation->OnStyleChange( styleChange );
118 } // namespace Internal
120 } // namespace Toolkit