xref: /aoo41x/main/vcl/source/window/keyevent.cxx (revision 9f62ea84)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <com/sun/star/awt/KeyEvent.hpp>
28 #include <com/sun/star/awt/KeyModifier.hpp>
29 #include <tools/debug.hxx>
30 #include <vcl/event.hxx>
31 
KeyEvent(const KeyEvent & rKeyEvent)32 KeyEvent::KeyEvent (const KeyEvent& rKeyEvent) :
33     maKeyCode (rKeyEvent.maKeyCode),
34     mnRepeat  (rKeyEvent.mnRepeat),
35     mnCharCode(rKeyEvent.mnCharCode)
36 {}
37 
38 /** inits this vcl KeyEvent with all settings from the given awt event **/
KeyEvent(const::com::sun::star::awt::KeyEvent & rEvent)39 KeyEvent::KeyEvent( const ::com::sun::star::awt::KeyEvent& rEvent )
40 {
41     maKeyCode = KeyCode(
42 		rEvent.KeyCode,
43 		(rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::SHIFT) != 0,
44 		(rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD1) != 0,
45 		(rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD2) != 0,
46                 (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD3) != 0);
47 	mnRepeat = 0;
48     mnCharCode = rEvent.KeyChar;
49 }
50 
51 /** fills out the given awt KeyEvent with all settings from this vcl event **/
InitKeyEvent(::com::sun::star::awt::KeyEvent & rEvent) const52 void KeyEvent::InitKeyEvent( ::com::sun::star::awt::KeyEvent& rEvent ) const
53 {
54 	rEvent.Modifiers = 0;
55 	if( GetKeyCode().IsShift() )
56 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
57 	if( GetKeyCode().IsMod1() )
58 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
59 	if( GetKeyCode().IsMod2() )
60 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
61         if( GetKeyCode().IsMod3() )
62                 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD3;
63 
64 	rEvent.KeyCode = GetKeyCode().GetCode();
65 	rEvent.KeyChar = GetCharCode();
66 	rEvent.KeyFunc = sal::static_int_cast< sal_Int16 >(GetKeyCode().GetFunction());
67 }
68 
LogicalTextDirectionality(TextDirectionality eMode) const69 KeyEvent KeyEvent::LogicalTextDirectionality (TextDirectionality eMode) const
70 {
71     KeyEvent aClone(*this);
72 
73     sal_uInt16 nCode = maKeyCode.GetCode();
74     sal_uInt16 nMod  = maKeyCode.GetAllModifier();
75 
76     switch (eMode)
77     {
78         case TextDirectionality_RightToLeft_TopToBottom:
79             switch (nCode)
80             {
81                 case KEY_LEFT:  aClone.maKeyCode = KeyCode(KEY_RIGHT, nMod); break;
82                 case KEY_RIGHT: aClone.maKeyCode = KeyCode(KEY_LEFT,  nMod); break;
83             }
84             break;
85 
86         case TextDirectionality_TopToBottom_RightToLeft:
87             switch (nCode)
88             {
89                 case KEY_DOWN:  aClone.maKeyCode = KeyCode(KEY_RIGHT, nMod); break;
90                 case KEY_UP:    aClone.maKeyCode = KeyCode(KEY_LEFT,  nMod); break;
91                 case KEY_LEFT:  aClone.maKeyCode = KeyCode(KEY_DOWN,  nMod); break;
92                 case KEY_RIGHT: aClone.maKeyCode = KeyCode(KEY_UP,    nMod); break;
93             }
94             break;
95 
96         case TextDirectionality_LeftToRight_TopToBottom:
97             /* do nothing */
98             break;
99     }
100 
101     return aClone;
102 }
103 
104 
105 // -------------------------------------------------------
106 
GetMousePosPixel() const107 const Point&   HelpEvent::GetMousePosPixel() const
108 {
109     //DBG_ASSERT( !mbKeyboardActivated, "Keyboard help has no mouse position !");
110     return maPos;
111 }
112 
113