Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / sidebar / possize / SidebarDialControl.cxx
blobe48fa55dee442469a4b8a911e084ac95b5549561
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <svx/sidebar/SidebarDialControl.hxx>
21 #include <vcl/builder.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
25 namespace svx { namespace sidebar {
27 SidebarDialControl::SidebarDialControl (Window* pParent, WinBits nBits)
28 : svx::DialControl(pParent, nBits)
30 Init(GetOutputSizePixel());
33 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSidebarDialControl(Window *pParent, VclBuilder::stringmap &)
35 return new SidebarDialControl(pParent, WB_TABSTOP);
38 SidebarDialControl::~SidebarDialControl (void)
42 Size SidebarDialControl::GetOptimalSize() const
44 return LogicToPixel(Size(10, 10), MAP_APPFONT);
47 void SidebarDialControl::MouseButtonDown( const MouseEvent& rMEvt )
49 if( rMEvt.IsLeft() )
51 GrabFocus();
52 CaptureMouse();
53 mpImpl->mnOldAngle = mpImpl->mnAngle;
54 HandleMouseEvent( rMEvt.GetPosPixel(), true );
58 void SidebarDialControl::HandleMouseEvent( const Point& rPos, bool bInitial )
60 long nX = rPos.X() - mpImpl->mnCenterX;
61 long nY = mpImpl->mnCenterY - rPos.Y();
62 double fH = sqrt( static_cast< double >( nX ) * nX + static_cast< double >( nY ) * nY );
63 if( fH != 0.0 )
65 double fAngle = acos( nX / fH );
66 sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 );
67 if( nY < 0 )
68 nAngle = 36000 - nAngle;
69 if( bInitial ) // round to entire 15 degrees
70 nAngle = ((nAngle + 750) / 1500) * 1500;
72 if (Application::GetSettings().GetLayoutRTL())
73 nAngle = 18000 - nAngle;
74 SetRotation( nAngle, true );
78 } } // end of namespace svx::sidebar
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */