xref: /trunk/main/vcl/source/window/mouseevent.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <com/sun/star/awt/MouseEvent.hpp>
32 #include <com/sun/star/awt/KeyModifier.hpp>
33 #include <com/sun/star/awt/MouseButton.hpp>
34 #include <tools/debug.hxx>
35 #include <vcl/event.hxx>
36 
37 /** inits this vcl KeyEvent with all settings from the given awt event **/
38 MouseEvent::MouseEvent( const ::com::sun::star::awt::MouseEvent& rEvent )
39 : maPos( rEvent.X, rEvent.Y )
40 , mnMode( 0 )
41 , mnClicks( static_cast< sal_uInt16 >( rEvent.ClickCount ) )
42 , mnCode( 0 )
43 {
44     if( rEvent.Modifiers )
45     {
46         if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::SHIFT) != 0 )
47             mnCode |= KEY_SHIFT;
48         if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD1) != 0 )
49             mnCode |= KEY_MOD1;
50         if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD2) != 0 )
51             mnCode |= KEY_MOD2;
52                 if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD3) != 0 )
53                         mnCode |= KEY_MOD3;
54     }
55 
56     if( rEvent.Buttons )
57     {
58         if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::LEFT) != 0 )
59             mnCode |= MOUSE_LEFT;
60         if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::RIGHT) != 0 )
61             mnCode |= MOUSE_RIGHT;
62         if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::MIDDLE) != 0 )
63             mnCode |= MOUSE_MIDDLE;
64     }
65 }
66 
67 /** fills out the given awt KeyEvent with all settings from this vcl event **/
68 void MouseEvent::InitMouseEvent( ::com::sun::star::awt::MouseEvent& rEvent ) const
69 {
70     rEvent.Modifiers = 0;
71     if ( IsShift() )
72         rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
73     if ( IsMod1() )
74         rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
75     if ( IsMod2() )
76         rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
77         if ( IsMod3() )
78                 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD3;
79 
80     rEvent.Buttons = 0;
81     if ( IsLeft() )
82         rEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
83     if ( IsRight() )
84         rEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
85     if ( IsMiddle() )
86         rEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
87 
88     rEvent.X = GetPosPixel().X();
89     rEvent.Y = GetPosPixel().Y();
90     rEvent.ClickCount = GetClicks();
91     rEvent.PopupTrigger = sal_False;
92 }
93