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/builder.hxx>
22 : #include <vcl/svapp.hxx>
23 :
24 : namespace svx { namespace sidebar {
25 :
26 0 : SidebarDialControl::SidebarDialControl (Window* pParent, WinBits nBits)
27 0 : : svx::DialControl(pParent, nBits)
28 : {
29 0 : Init(GetOutputSizePixel());
30 0 : }
31 :
32 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSidebarDialControl(Window *pParent, VclBuilder::stringmap &)
33 : {
34 0 : return new SidebarDialControl(pParent, WB_TABSTOP);
35 : }
36 :
37 0 : SidebarDialControl::SidebarDialControl (
38 : Window* pParent,
39 : const ResId& rResId)
40 0 : : svx::DialControl(pParent, rResId)
41 : {
42 0 : Init(GetOutputSizePixel());
43 0 : }
44 :
45 0 : SidebarDialControl::~SidebarDialControl (void)
46 : {
47 0 : }
48 :
49 0 : Size SidebarDialControl::GetOptimalSize() const
50 : {
51 0 : return LogicToPixel(Size(10, 10), MAP_APPFONT);
52 : }
53 :
54 0 : void SidebarDialControl::MouseButtonDown( const MouseEvent& rMEvt )
55 : {
56 0 : if( rMEvt.IsLeft() )
57 : {
58 0 : GrabFocus();
59 0 : CaptureMouse();
60 0 : mpImpl->mnOldAngle = mpImpl->mnAngle;
61 0 : HandleMouseEvent( rMEvt.GetPosPixel(), true );
62 : }
63 0 : }
64 :
65 0 : void SidebarDialControl::HandleMouseEvent( const Point& rPos, bool bInitial )
66 : {
67 0 : long nX = rPos.X() - mpImpl->mnCenterX;
68 0 : long nY = mpImpl->mnCenterY - rPos.Y();
69 0 : double fH = sqrt( static_cast< double >( nX ) * nX + static_cast< double >( nY ) * nY );
70 0 : if( fH != 0.0 )
71 : {
72 0 : double fAngle = acos( nX / fH );
73 0 : sal_Int32 nAngle = static_cast< sal_Int32 >( fAngle / F_PI180 * 100.0 );
74 0 : if( nY < 0 )
75 0 : nAngle = 36000 - nAngle;
76 0 : if( bInitial ) // round to entire 15 degrees
77 0 : nAngle = ((nAngle + 750) / 1500) * 1500;
78 :
79 0 : if (Application::GetSettings().GetLayoutRTL())
80 0 : nAngle = 18000 - nAngle;
81 0 : SetRotation( nAngle, true );
82 : }
83 0 : }
84 :
85 216 : } } // end of namespace svx::sidebar
86 :
87 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|