3f509e8c0ea0e13f9a500da23dc9fb729df1647f
[platform/core/uifw/dali-adaptor.git] / adaptors / common / clipboard-event-notifier-impl.cpp
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 "clipboard-event-notifier-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/dali-core.h>
23
24 // INTERNAL INCLUDES
25 #include <adaptor-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 namespace
37 {
38 BaseHandle Create()
39 {
40   BaseHandle handle( ClipboardEventNotifier::Get() );
41
42   if ( !handle && Adaptor::IsAvailable() )
43   {
44     Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
45     Dali::ClipboardEventNotifier notifier( ClipboardEventNotifier::New() );
46     adaptorImpl.RegisterSingleton( typeid( notifier ), notifier );
47     handle = notifier;
48   }
49
50   return handle;
51 }
52 TypeRegistration CLIPBOARD_EVENT_NOTIFIER_TYPE( typeid(Dali::ClipboardEventNotifier), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
53
54 } // unnamed namespace
55
56 Dali::ClipboardEventNotifier ClipboardEventNotifier::New()
57 {
58   Dali::ClipboardEventNotifier notifier = Dali::ClipboardEventNotifier(new ClipboardEventNotifier());
59
60   return notifier;
61 }
62
63 Dali::ClipboardEventNotifier ClipboardEventNotifier::Get()
64 {
65   Dali::ClipboardEventNotifier notifier;
66
67   if ( Adaptor::IsAvailable() )
68   {
69     // Check whether the singleton is already created
70     Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::ClipboardEventNotifier ) );
71     if(handle)
72     {
73       // If so, downcast the handle
74       notifier = Dali::ClipboardEventNotifier( dynamic_cast< ClipboardEventNotifier* >( handle.GetObjectPtr() ) );
75     }
76   }
77
78   return notifier;
79 }
80
81 const std::string& ClipboardEventNotifier::GetContent() const
82 {
83   return mContent;
84 }
85
86 void ClipboardEventNotifier::SetContent( const std::string& content )
87 {
88   mContent = content;
89 }
90
91 void ClipboardEventNotifier::ClearContent()
92 {
93   mContent.clear();
94 }
95
96 void ClipboardEventNotifier::EmitContentSelectedSignal()
97 {
98   if ( !mContentSelectedSignalV2.Empty() )
99   {
100     Dali::ClipboardEventNotifier handle( this );
101     mContentSelectedSignalV2.Emit( handle );
102   }
103 }
104
105 ClipboardEventNotifier::ClipboardEventNotifier()
106 : mContent()
107 {
108 }
109
110 ClipboardEventNotifier::~ClipboardEventNotifier()
111 {
112 }
113
114 } // namespace Adaptor
115
116 } // namespace Internal
117
118 } // namespace Dali