Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include <svx/sidebar/SidebarDialControl.hxx>
20 :
21 : #include <vcl/builderfactory.hxx>
22 : #include <vcl/svapp.hxx>
23 : #include <vcl/settings.hxx>
24 :
25 : namespace svx { namespace sidebar {
26 :
27 1 : SidebarDialControl::SidebarDialControl (vcl::Window* pParent, WinBits nBits)
28 1 : : svx::DialControl(pParent, nBits)
29 : {
30 1 : Init(GetOutputSizePixel());
31 1 : }
32 :
33 1 : VCL_BUILDER_FACTORY_ARGS(SidebarDialControl, WB_TABSTOP)
34 :
35 1 : Size SidebarDialControl::GetOptimalSize() const
36 : {
37 1 : return LogicToPixel(Size(10, 10), MAP_APPFONT);
38 : }
39 :
40 0 : void SidebarDialControl::MouseButtonDown( const MouseEvent& rMEvt )
41 : {
42 0 : if( rMEvt.IsLeft() )
43 : {
44 0 : GrabFocus();
45 0 : CaptureMouse();
46 0 : mpImpl->mnOldAngle = mpImpl->mnAngle;
47 0 : HandleMouseEvent( rMEvt.GetPosPixel(), true );
48 : }
49 0 : }
50 :
51 0 : void SidebarDialControl::HandleMouseEvent( const Point& rPos, bool bInitial )
52 : {
53 0 : long nX = rPos.X() - mpImpl->mnCenterX;
54 0 : long nY = mpImpl->mnCenterY - rPos.Y();
55 0 : double fH = sqrt( static_cast< double >( nX ) * nX + static_cast< double >( nY ) * nY );
56 0 : if( fH != 0.0 )
57 : {
58 0 : double fAngle = acos( nX / fH );
59 0 : sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 );
60 0 : if( nY < 0 )
61 0 : nAngle = 36000 - nAngle;
62 0 : if( bInitial ) // round to entire 15 degrees
63 0 : nAngle = ((nAngle + 750) / 1500) * 1500;
64 :
65 0 : if (AllSettings::GetLayoutRTL())
66 0 : nAngle = 18000 - nAngle;
67 0 : SetRotation( nAngle, true );
68 : }
69 0 : }
70 :
71 390 : } } // end of namespace svx::sidebar
72 :
73 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|