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