fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / dialog / connctrl.cxx
blob59b149ca257b3f115879dce4ad1fc9fc1098e62d
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 .
20 #include <svx/svdoedge.hxx>
21 #include <svx/svdattrx.hxx>
22 #include <svx/svdmark.hxx>
23 #include <svx/svdview.hxx>
25 #include <svx/svdpage.hxx> // SdrObjList
27 #include "svx/connctrl.hxx"
28 #include <svx/dialmgr.hxx>
29 #include "svx/dlgutil.hxx"
31 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
33 #include <svx/sdr/contact/displayinfo.hxx>
34 #include <vcl/svapp.hxx>
36 SvxXConnectionPreview::SvxXConnectionPreview( Window* pParent, const ResId& rResId,
37 const SfxItemSet& rInAttrs ) :
38 Control ( pParent, rResId ),
39 rAttrs ( rInAttrs ),
40 pEdgeObj( NULL ),
41 pObjList( NULL ),
42 pView ( NULL )
44 SetMapMode( MAP_100TH_MM );
45 SetStyles();
48 SvxXConnectionPreview::~SvxXConnectionPreview()
50 delete pObjList;
53 void SvxXConnectionPreview::Construct()
55 DBG_ASSERT( pView, "No valid view is passed on! ");
57 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
58 sal_uIntPtr nMarkCount = rMarkList.GetMarkCount();
60 if( nMarkCount >= 1 )
62 bool bFound = false;
63 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
66 for( sal_uInt16 i = 0; i < nMarkCount && !bFound; i++ )
68 pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
69 sal_uInt32 nInv = pObj->GetObjInventor();
70 sal_uInt16 nId = pObj->GetObjIdentifier();
71 if( nInv == SdrInventor && nId == OBJ_EDGE )
73 bFound = true;
74 SdrEdgeObj* pTmpEdgeObj = (SdrEdgeObj*) pObj;
75 pEdgeObj = (SdrEdgeObj*) pTmpEdgeObj->Clone();
77 SdrObjConnection& rConn1 = (SdrObjConnection&)pEdgeObj->GetConnection( sal_True );
78 SdrObjConnection& rConn2 = (SdrObjConnection&)pEdgeObj->GetConnection( sal_False );
80 rConn1 = pTmpEdgeObj->GetConnection( sal_True );
81 rConn2 = pTmpEdgeObj->GetConnection( sal_False );
83 SdrObject* pTmpObj1 = pTmpEdgeObj->GetConnectedNode( sal_True );
84 SdrObject* pTmpObj2 = pTmpEdgeObj->GetConnectedNode( sal_False );
86 // potential memory leak here (!). Create SdrObjList only when there is
87 // not yet one.
88 if(!pObjList)
90 pObjList = new SdrObjList( pView->GetModel(), NULL );
93 if( pTmpObj1 )
95 SdrObject* pObj1 = pTmpObj1->Clone();
96 pObjList->InsertObject( pObj1 );
97 pEdgeObj->ConnectToNode( sal_True, pObj1 );
99 if( pTmpObj2 )
101 SdrObject* pObj2 = pTmpObj2->Clone();
102 pObjList->InsertObject( pObj2 );
103 pEdgeObj->ConnectToNode( sal_False, pObj2 );
105 pObjList->InsertObject( pEdgeObj );
110 if( !pEdgeObj )
111 pEdgeObj = new SdrEdgeObj();
113 // Adapt size
114 if( pObjList )
116 OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
117 Rectangle aRect = pObjList->GetAllObjBoundRect();
119 MapMode aMapMode = GetMapMode();
120 aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
121 SetMapMode( aMapMode );
123 MapMode aDisplayMap( aMapMode );
124 Point aNewPos;
125 Size aNewSize;
126 const Size aWinSize = PixelToLogic( GetOutputSizePixel(), aDisplayMap );
127 const long nWidth = aWinSize.Width();
128 const long nHeight = aWinSize.Height();
129 double fRectWH = (double) aRect.GetWidth() / aRect.GetHeight();
130 double fWinWH = (double) nWidth / nHeight;
132 // Adapt bitmap to Thumb size (not here!)
133 if ( fRectWH < fWinWH)
135 aNewSize.Width() = (long) ( (double) nHeight * fRectWH );
136 aNewSize.Height()= nHeight;
138 else
140 aNewSize.Width() = nWidth;
141 aNewSize.Height()= (long) ( (double) nWidth / fRectWH );
144 Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() );
145 Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() );
146 Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 );
148 // Implement MapMode
149 aDisplayMap.SetScaleX( aMinFrac );
150 aDisplayMap.SetScaleY( aMinFrac );
152 // Centering
153 aNewPos.X() = ( nWidth - aNewSize.Width() ) >> 1;
154 aNewPos.Y() = ( nHeight - aNewSize.Height() ) >> 1;
156 aDisplayMap.SetOrigin( LogicToLogic( aNewPos, aMapMode, aDisplayMap ) );
157 SetMapMode( aDisplayMap );
159 // Origin
160 aNewPos = aDisplayMap.GetOrigin();
161 aNewPos -= Point( aRect.TopLeft().X(), aRect.TopLeft().Y() );
162 aDisplayMap.SetOrigin( aNewPos );
163 SetMapMode( aDisplayMap );
166 Point aPos;
167 MouseEvent aMEvt( aPos, 1, 0, MOUSE_RIGHT );
168 MouseButtonDown( aMEvt );
172 void SvxXConnectionPreview::Paint( const Rectangle& )
174 if( pObjList )
176 // #110094#
177 // This will not work anymore. To not start at Adam and Eve, i will
178 // ATM not try to change all this stuff to really using an own model
179 // and a view. I will just try to provide a mechanism to paint such
180 // objects without own model and without a page/view with the new
181 // mechanism.
183 // New stuff: Use a ObjectContactOfObjListPainter.
184 sdr::contact::SdrObjectVector aObjectVector;
186 for(sal_uInt32 a(0L); a < pObjList->GetObjCount(); a++)
188 SdrObject* pObject = pObjList->GetObj(a);
189 DBG_ASSERT(pObject,
190 "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
191 aObjectVector.push_back(pObject);
194 sdr::contact::ObjectContactOfObjListPainter aPainter(*this, aObjectVector, 0);
195 sdr::contact::DisplayInfo aDisplayInfo;
197 // do processing
198 aPainter.ProcessDisplay(aDisplayInfo);
202 void SvxXConnectionPreview::SetAttributes( const SfxItemSet& rInAttrs )
204 pEdgeObj->SetMergedItemSetAndBroadcast(rInAttrs);
206 Invalidate();
210 // Get number of lines which are offset based on the preview object
212 sal_uInt16 SvxXConnectionPreview::GetLineDeltaAnz()
214 const SfxItemSet& rSet = pEdgeObj->GetMergedItemSet();
215 sal_uInt16 nCount(0);
217 if(SFX_ITEM_DONTCARE != rSet.GetItemState(SDRATTR_EDGELINEDELTAANZ))
218 nCount = ((const SdrEdgeLineDeltaAnzItem&)rSet.Get(SDRATTR_EDGELINEDELTAANZ)).GetValue();
220 return nCount;
223 void SvxXConnectionPreview::MouseButtonDown( const MouseEvent& rMEvt )
225 bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
226 bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
227 bool bCtrl = rMEvt.IsMod1();
229 if( bZoomIn || bZoomOut )
231 MapMode aMapMode = GetMapMode();
232 Fraction aXFrac = aMapMode.GetScaleX();
233 Fraction aYFrac = aMapMode.GetScaleY();
234 Fraction* pMultFrac;
236 if( bZoomIn )
238 if( bCtrl )
239 pMultFrac = new Fraction( 3, 2 );
240 else
241 pMultFrac = new Fraction( 11, 10 );
243 else
245 if( bCtrl )
246 pMultFrac = new Fraction( 2, 3 );
247 else
248 pMultFrac = new Fraction( 10, 11 );
251 aXFrac *= *pMultFrac;
252 aYFrac *= *pMultFrac;
253 if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
254 (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
256 aMapMode.SetScaleX( aXFrac );
257 aMapMode.SetScaleY( aYFrac );
258 SetMapMode( aMapMode );
260 Size aOutSize( GetOutputSize() );
262 Point aPt( aMapMode.GetOrigin() );
263 long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
264 long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
265 aPt.X() += nX;
266 aPt.Y() += nY;
268 aMapMode.SetOrigin( aPt );
269 SetMapMode( aMapMode );
271 Invalidate();
273 delete pMultFrac;
277 void SvxXConnectionPreview::SetStyles()
279 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
280 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
281 SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
284 void SvxXConnectionPreview::DataChanged( const DataChangedEvent& rDCEvt )
286 Control::DataChanged( rDCEvt );
288 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
290 SetStyles();
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */