update dev300-m58
[ooovba.git] / vcl / source / window / keyevent.cxx
blobf146d5a4739c0a6d32d3c7c0fb10dcfd0b4e73f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: keyevent.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include <com/sun/star/awt/KeyEvent.hpp>
35 #include <com/sun/star/awt/KeyModifier.hpp>
36 #include <tools/debug.hxx>
37 #include <vcl/event.hxx>
39 KeyEvent::KeyEvent (const KeyEvent& rKeyEvent) :
40 maKeyCode (rKeyEvent.maKeyCode),
41 mnRepeat (rKeyEvent.mnRepeat),
42 mnCharCode(rKeyEvent.mnCharCode)
45 /** inits this vcl KeyEvent with all settings from the given awt event **/
46 KeyEvent::KeyEvent( const ::com::sun::star::awt::KeyEvent& rEvent )
48 maKeyCode = KeyCode(
49 rEvent.KeyCode,
50 (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::SHIFT) != 0,
51 (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD1) != 0,
52 (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD2) != 0,
53 (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD3) != 0);
54 mnRepeat = 0;
55 mnCharCode = rEvent.KeyChar;
58 /** fills out the given awt KeyEvent with all settings from this vcl event **/
59 void KeyEvent::InitKeyEvent( ::com::sun::star::awt::KeyEvent& rEvent ) const
61 rEvent.Modifiers = 0;
62 if( GetKeyCode().IsShift() )
63 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
64 if( GetKeyCode().IsMod1() )
65 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
66 if( GetKeyCode().IsMod2() )
67 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
68 if( GetKeyCode().IsMod3() )
69 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD3;
71 rEvent.KeyCode = GetKeyCode().GetCode();
72 rEvent.KeyChar = GetCharCode();
73 rEvent.KeyFunc = sal::static_int_cast< sal_Int16 >(GetKeyCode().GetFunction());
76 KeyEvent KeyEvent::LogicalTextDirectionality (TextDirectionality eMode) const
78 KeyEvent aClone(*this);
80 USHORT nCode = maKeyCode.GetCode();
81 USHORT nMod = maKeyCode.GetAllModifier();
83 switch (eMode)
85 case TextDirectionality_RightToLeft_TopToBottom:
86 switch (nCode)
88 case KEY_LEFT: aClone.maKeyCode = KeyCode(KEY_RIGHT, nMod); break;
89 case KEY_RIGHT: aClone.maKeyCode = KeyCode(KEY_LEFT, nMod); break;
91 break;
93 case TextDirectionality_TopToBottom_RightToLeft:
94 switch (nCode)
96 case KEY_DOWN: aClone.maKeyCode = KeyCode(KEY_RIGHT, nMod); break;
97 case KEY_UP: aClone.maKeyCode = KeyCode(KEY_LEFT, nMod); break;
98 case KEY_LEFT: aClone.maKeyCode = KeyCode(KEY_DOWN, nMod); break;
99 case KEY_RIGHT: aClone.maKeyCode = KeyCode(KEY_UP, nMod); break;
101 break;
103 case TextDirectionality_LeftToRight_TopToBottom:
104 /* do nothing */
105 break;
108 return aClone;
112 // -------------------------------------------------------
114 const Point& HelpEvent::GetMousePosPixel() const
116 //DBG_ASSERT( !mbKeyboardActivated, "Keyboard help has no mouse position !");
117 return maPos;