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