Merge "(FrameCallback) All values now local & baking of the value supported" into...
[platform/core/uifw/dali-core.git] / dali / public-api / events / key-event.cpp
1 /*
2  * Copyright (c) 2017 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 <dali/public-api/events/key-event.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/events/key-event-impl.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29 const unsigned int MODIFIER_SHIFT = 0x1;
30 const unsigned int MODIFIER_CTRL  = 0x2;
31 const unsigned int MODIFIER_ALT   = 0x4;
32 const int KEY_INVALID_CODE = -1;
33 }
34
35 KeyEvent::KeyEvent()
36 : keyPressedName(""),
37   keyPressed(""),
38   keyCode(KEY_INVALID_CODE),
39   keyModifier(0),
40   time(0),
41   state(KeyEvent::Down)
42 {
43   new Internal::KeyEventImpl( this );
44 }
45
46 KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier,unsigned long timeStamp, const State& keyState)
47 : keyPressedName(keyName),
48   keyPressed(keyString),
49   keyCode(keyCode),
50   keyModifier(keyModifier),
51   time(timeStamp),
52   state(keyState)
53 {
54   new Internal::KeyEventImpl( this );
55 }
56
57 KeyEvent::KeyEvent( const KeyEvent& rhs )
58 : keyPressedName( rhs.keyPressedName ),
59   keyPressed( rhs.keyPressed ),
60   keyCode( rhs.keyCode ),
61   keyModifier( rhs.keyModifier ),
62   time( rhs.time ),
63   state( rhs.state )
64 {
65   Internal::KeyEventImpl* impl = new Internal::KeyEventImpl( this );
66   *impl = *GetImplementation( &rhs );
67 }
68
69 KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
70 {
71   if( this != &rhs )
72   {
73     keyPressedName = rhs.keyPressedName;
74     keyPressed = rhs.keyPressed;
75     keyCode = rhs.keyCode;
76     keyModifier = rhs.keyModifier;
77     time = rhs.time;
78     state = rhs.state;
79
80     *GetImplementation( this ) = *GetImplementation( &rhs );
81   }
82
83   return *this;
84 }
85
86 KeyEvent::~KeyEvent()
87 {
88   delete GetImplementation( this );
89 }
90
91 bool KeyEvent::IsShiftModifier() const
92 {
93   if ((MODIFIER_SHIFT & keyModifier) == MODIFIER_SHIFT)
94   {
95     return true;
96   }
97
98   return false;
99 }
100
101 bool KeyEvent::IsCtrlModifier() const
102 {
103   if ((MODIFIER_CTRL & keyModifier) == MODIFIER_CTRL)
104   {
105     return true;
106   }
107
108   return false;
109 }
110
111 bool KeyEvent::IsAltModifier() const
112 {
113   if ((MODIFIER_ALT & keyModifier) == MODIFIER_ALT)
114   {
115     return true;
116   }
117
118   return false;
119 }
120
121 std::string KeyEvent::GetCompose() const
122 {
123   return GetImplementation( this )->GetCompose();
124 }
125
126 std::string KeyEvent::GetDeviceName() const
127 {
128   return GetImplementation( this )->GetDeviceName();
129 }
130
131 Device::Class::Type KeyEvent::GetDeviceClass() const
132 {
133   return GetImplementation( this )->GetDeviceClass();
134 }
135
136 Device::Subclass::Type KeyEvent::GetDeviceSubclass() const
137 {
138   return GetImplementation( this )->GetDeviceSubclass();
139 }
140
141
142 } // namespace Dali