xref: /aoo41x/main/vcl/source/window/mouseevent.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/MouseEvent.hpp>
28 #include <com/sun/star/awt/KeyModifier.hpp>
29 #include <com/sun/star/awt/MouseButton.hpp>
30 #include <tools/debug.hxx>
31 #include <vcl/event.hxx>
32 
33 /** inits this vcl KeyEvent with all settings from the given awt event **/
MouseEvent(const::com::sun::star::awt::MouseEvent & rEvent)34 MouseEvent::MouseEvent( const ::com::sun::star::awt::MouseEvent& rEvent )
35 : maPos( rEvent.X, rEvent.Y )
36 , mnMode( 0 )
37 , mnClicks( static_cast< sal_uInt16 >( rEvent.ClickCount ) )
38 , mnCode( 0 )
39 {
40 	if( rEvent.Modifiers )
41 	{
42 		if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::SHIFT) != 0 )
43 			mnCode |= KEY_SHIFT;
44 		if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD1) != 0 )
45 			mnCode |= KEY_MOD1;
46 		if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD2) != 0 )
47 			mnCode |= KEY_MOD2;
48                 if( (rEvent.Modifiers & ::com::sun::star::awt::KeyModifier::MOD3) != 0 )
49                         mnCode |= KEY_MOD3;
50 	}
51 
52 	if( rEvent.Buttons )
53 	{
54 		if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::LEFT) != 0 )
55 			mnCode |= MOUSE_LEFT;
56 		if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::RIGHT) != 0 )
57 			mnCode |= MOUSE_RIGHT;
58 		if( (rEvent.Buttons & ::com::sun::star::awt::MouseButton::MIDDLE) != 0 )
59 			mnCode |= MOUSE_MIDDLE;
60 	}
61 }
62 
63 /** fills out the given awt KeyEvent with all settings from this vcl event **/
InitMouseEvent(::com::sun::star::awt::MouseEvent & rEvent) const64 void MouseEvent::InitMouseEvent( ::com::sun::star::awt::MouseEvent& rEvent ) const
65 {
66 	rEvent.Modifiers = 0;
67 	if ( IsShift() )
68 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
69 	if ( IsMod1() )
70 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
71 	if ( IsMod2() )
72 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
73         if ( IsMod3() )
74                 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD3;
75 
76 	rEvent.Buttons = 0;
77 	if ( IsLeft() )
78 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
79 	if ( IsRight() )
80 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
81 	if ( IsMiddle() )
82 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
83 
84 	rEvent.X = GetPosPixel().X();
85 	rEvent.Y = GetPosPixel().Y();
86 	rEvent.ClickCount = GetClicks();
87 	rEvent.PopupTrigger = sal_False;
88 }
89