1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
44 SetMapMode( MAP_100TH_MM
);
48 SvxXConnectionPreview::~SvxXConnectionPreview()
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();
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
)
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
90 pObjList
= new SdrObjList( pView
->GetModel(), NULL
);
95 SdrObject
* pObj1
= pTmpObj1
->Clone();
96 pObjList
->InsertObject( pObj1
);
97 pEdgeObj
->ConnectToNode( sal_True
, pObj1
);
101 SdrObject
* pObj2
= pTmpObj2
->Clone();
102 pObjList
->InsertObject( pObj2
);
103 pEdgeObj
->ConnectToNode( sal_False
, pObj2
);
105 pObjList
->InsertObject( pEdgeObj
);
111 pEdgeObj
= new SdrEdgeObj();
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
);
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
;
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
);
149 aDisplayMap
.SetScaleX( aMinFrac
);
150 aDisplayMap
.SetScaleY( aMinFrac
);
153 aNewPos
.X() = ( nWidth
- aNewSize
.Width() ) >> 1;
154 aNewPos
.Y() = ( nHeight
- aNewSize
.Height() ) >> 1;
156 aDisplayMap
.SetOrigin( LogicToLogic( aNewPos
, aMapMode
, aDisplayMap
) );
157 SetMapMode( aDisplayMap
);
160 aNewPos
= aDisplayMap
.GetOrigin();
161 aNewPos
-= Point( aRect
.TopLeft().X(), aRect
.TopLeft().Y() );
162 aDisplayMap
.SetOrigin( aNewPos
);
163 SetMapMode( aDisplayMap
);
167 MouseEvent
aMEvt( aPos
, 1, 0, MOUSE_RIGHT
);
168 MouseButtonDown( aMEvt
);
172 void SvxXConnectionPreview::Paint( const Rectangle
& )
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
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
);
190 "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
191 aObjectVector
.push_back(pObject
);
194 sdr::contact::ObjectContactOfObjListPainter
aPainter(*this, aObjectVector
, 0);
195 sdr::contact::DisplayInfo aDisplayInfo
;
198 aPainter
.ProcessDisplay(aDisplayInfo
);
202 void SvxXConnectionPreview::SetAttributes( const SfxItemSet
& rInAttrs
)
204 pEdgeObj
->SetMergedItemSetAndBroadcast(rInAttrs
);
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();
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();
239 pMultFrac
= new Fraction( 3, 2 );
241 pMultFrac
= new Fraction( 11, 10 );
246 pMultFrac
= new Fraction( 2, 3 );
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 );
268 aMapMode
.SetOrigin( aPt
);
269 SetMapMode( aMapMode
);
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
) )
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */