Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svdoedge.hxx>
30 : : #include <svx/svdattrx.hxx>
31 : : #include <svx/svdmark.hxx>
32 : : #include <svx/svdview.hxx>
33 : :
34 : : #include <svx/svdpage.hxx> // SdrObjList
35 : :
36 : : #include "svx/connctrl.hxx"
37 : : #include <svx/dialmgr.hxx>
38 : : #include "svx/dlgutil.hxx"
39 : :
40 : : #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
41 : :
42 : : #include <svx/sdr/contact/displayinfo.hxx>
43 : : #include <vcl/svapp.hxx>
44 : :
45 : 0 : SvxXConnectionPreview::SvxXConnectionPreview( Window* pParent, const ResId& rResId,
46 : : const SfxItemSet& rInAttrs ) :
47 : : Control ( pParent, rResId ),
48 : : rAttrs ( rInAttrs ),
49 : : pEdgeObj( NULL ),
50 : : pObjList( NULL ),
51 : 0 : pView ( NULL )
52 : : {
53 [ # # ][ # # ]: 0 : SetMapMode( MAP_100TH_MM );
[ # # ]
54 [ # # ]: 0 : SetStyles();
55 : 0 : }
56 : :
57 : 0 : SvxXConnectionPreview::~SvxXConnectionPreview()
58 : : {
59 [ # # ][ # # ]: 0 : delete pObjList;
60 [ # # ]: 0 : }
61 : :
62 : 0 : void SvxXConnectionPreview::Construct()
63 : : {
64 : : DBG_ASSERT( pView, "No valid view is passed on! ");
65 : :
66 : 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
67 : 0 : sal_uIntPtr nMarkCount = rMarkList.GetMarkCount();
68 : :
69 [ # # ]: 0 : if( nMarkCount >= 1 )
70 : : {
71 : 0 : sal_Bool bFound = sal_False;
72 : 0 : const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
73 : :
74 : :
75 [ # # ][ # # ]: 0 : for( sal_uInt16 i = 0; i < nMarkCount && !bFound; i++ )
[ # # ]
76 : : {
77 : 0 : pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
78 : 0 : sal_uInt32 nInv = pObj->GetObjInventor();
79 : 0 : sal_uInt16 nId = pObj->GetObjIdentifier();
80 [ # # ][ # # ]: 0 : if( nInv == SdrInventor && nId == OBJ_EDGE )
81 : : {
82 : 0 : bFound = sal_True;
83 : 0 : SdrEdgeObj* pTmpEdgeObj = (SdrEdgeObj*) pObj;
84 : 0 : pEdgeObj = (SdrEdgeObj*) pTmpEdgeObj->Clone();
85 : :
86 : 0 : SdrObjConnection& rConn1 = (SdrObjConnection&)pEdgeObj->GetConnection( sal_True );
87 : 0 : SdrObjConnection& rConn2 = (SdrObjConnection&)pEdgeObj->GetConnection( sal_False );
88 : :
89 : 0 : rConn1 = pTmpEdgeObj->GetConnection( sal_True );
90 : 0 : rConn2 = pTmpEdgeObj->GetConnection( sal_False );
91 : :
92 : 0 : SdrObject* pTmpObj1 = pTmpEdgeObj->GetConnectedNode( sal_True );
93 : 0 : SdrObject* pTmpObj2 = pTmpEdgeObj->GetConnectedNode( sal_False );
94 : :
95 : : // potential memory leak here (!). Create SdrObjList only when there is
96 : : // not yet one.
97 [ # # ]: 0 : if(!pObjList)
98 : : {
99 [ # # ]: 0 : pObjList = new SdrObjList( pView->GetModel(), NULL );
100 : : }
101 : :
102 [ # # ]: 0 : if( pTmpObj1 )
103 : : {
104 : 0 : SdrObject* pObj1 = pTmpObj1->Clone();
105 : 0 : pObjList->InsertObject( pObj1 );
106 : 0 : pEdgeObj->ConnectToNode( sal_True, pObj1 );
107 : : }
108 [ # # ]: 0 : if( pTmpObj2 )
109 : : {
110 : 0 : SdrObject* pObj2 = pTmpObj2->Clone();
111 : 0 : pObjList->InsertObject( pObj2 );
112 : 0 : pEdgeObj->ConnectToNode( sal_False, pObj2 );
113 : : }
114 : 0 : pObjList->InsertObject( pEdgeObj );
115 : : }
116 : : }
117 : : }
118 : :
119 [ # # ]: 0 : if( !pEdgeObj )
120 [ # # ]: 0 : pEdgeObj = new SdrEdgeObj();
121 : :
122 : : // Adapt size
123 [ # # ]: 0 : if( pObjList )
124 : : {
125 [ # # ]: 0 : OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
126 [ # # ]: 0 : Rectangle aRect = pObjList->GetAllObjBoundRect();
127 : :
128 [ # # ]: 0 : MapMode aMapMode = GetMapMode();
129 [ # # ]: 0 : aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
130 [ # # ]: 0 : SetMapMode( aMapMode );
131 : :
132 [ # # ]: 0 : MapMode aDisplayMap( aMapMode );
133 : 0 : Point aNewPos;
134 : 0 : Size aNewSize;
135 [ # # ]: 0 : const Size aWinSize = PixelToLogic( GetOutputSizePixel(), aDisplayMap );
136 : 0 : const long nWidth = aWinSize.Width();
137 : 0 : const long nHeight = aWinSize.Height();
138 [ # # ][ # # ]: 0 : double fRectWH = (double) aRect.GetWidth() / aRect.GetHeight();
139 : 0 : double fWinWH = (double) nWidth / nHeight;
140 : :
141 : : // Adapt bitmap to Thumb size (not here!)
142 [ # # ]: 0 : if ( fRectWH < fWinWH)
143 : : {
144 : 0 : aNewSize.Width() = (long) ( (double) nHeight * fRectWH );
145 : 0 : aNewSize.Height()= nHeight;
146 : : }
147 : : else
148 : : {
149 : 0 : aNewSize.Width() = nWidth;
150 : 0 : aNewSize.Height()= (long) ( (double) nWidth / fRectWH );
151 : : }
152 : :
153 [ # # ][ # # ]: 0 : Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() );
154 [ # # ][ # # ]: 0 : Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() );
155 [ # # ][ # # ]: 0 : Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 );
[ # # ]
156 : :
157 : : // Implement MapMode
158 [ # # ]: 0 : aDisplayMap.SetScaleX( aMinFrac );
159 [ # # ]: 0 : aDisplayMap.SetScaleY( aMinFrac );
160 : :
161 : : // Centering
162 : 0 : aNewPos.X() = ( nWidth - aNewSize.Width() ) >> 1;
163 : 0 : aNewPos.Y() = ( nHeight - aNewSize.Height() ) >> 1;
164 : :
165 [ # # ][ # # ]: 0 : aDisplayMap.SetOrigin( LogicToLogic( aNewPos, aMapMode, aDisplayMap ) );
166 [ # # ]: 0 : SetMapMode( aDisplayMap );
167 : :
168 : : // Origin
169 : 0 : aNewPos = aDisplayMap.GetOrigin();
170 : 0 : aNewPos -= Point( aRect.TopLeft().X(), aRect.TopLeft().Y() );
171 [ # # ]: 0 : aDisplayMap.SetOrigin( aNewPos );
172 [ # # ]: 0 : SetMapMode( aDisplayMap );
173 : :
174 : :
175 : 0 : Point aPos;
176 [ # # ]: 0 : MouseEvent aMEvt( aPos, 1, 0, MOUSE_RIGHT );
177 [ # # ][ # # ]: 0 : MouseButtonDown( aMEvt );
[ # # ]
178 : : }
179 : 0 : }
180 : :
181 : 0 : void SvxXConnectionPreview::Paint( const Rectangle& )
182 : : {
183 [ # # ]: 0 : if( pObjList )
184 : : {
185 : : // #110094#
186 : : // This will not work anymore. To not start at Adam and Eve, i will
187 : : // ATM not try to change all this stuff to really using an own model
188 : : // and a view. I will just try to provide a mechanism to paint such
189 : : // objects without own model and without a page/view with the new
190 : : // mechanism.
191 : :
192 : : // New stuff: Use a ObjectContactOfObjListPainter.
193 [ # # ]: 0 : sdr::contact::SdrObjectVector aObjectVector;
194 : :
195 [ # # ][ # # ]: 0 : for(sal_uInt32 a(0L); a < pObjList->GetObjCount(); a++)
196 : : {
197 [ # # ]: 0 : SdrObject* pObject = pObjList->GetObj(a);
198 : : DBG_ASSERT(pObject,
199 : : "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
200 [ # # ]: 0 : aObjectVector.push_back(pObject);
201 : : }
202 : :
203 [ # # ]: 0 : sdr::contact::ObjectContactOfObjListPainter aPainter(*this, aObjectVector, 0);
204 [ # # ]: 0 : sdr::contact::DisplayInfo aDisplayInfo;
205 : :
206 : : // do processing
207 [ # # ][ # # ]: 0 : aPainter.ProcessDisplay(aDisplayInfo);
[ # # ]
208 : : }
209 : 0 : }
210 : :
211 : 0 : void SvxXConnectionPreview::SetAttributes( const SfxItemSet& rInAttrs )
212 : : {
213 : 0 : pEdgeObj->SetMergedItemSetAndBroadcast(rInAttrs);
214 : :
215 : 0 : Invalidate();
216 : 0 : }
217 : :
218 : :
219 : : // Get number of lines which are offset based on the preview object
220 : :
221 : 0 : sal_uInt16 SvxXConnectionPreview::GetLineDeltaAnz()
222 : : {
223 : 0 : const SfxItemSet& rSet = pEdgeObj->GetMergedItemSet();
224 : 0 : sal_uInt16 nCount(0);
225 : :
226 [ # # ]: 0 : if(SFX_ITEM_DONTCARE != rSet.GetItemState(SDRATTR_EDGELINEDELTAANZ))
227 : 0 : nCount = ((const SdrEdgeLineDeltaAnzItem&)rSet.Get(SDRATTR_EDGELINEDELTAANZ)).GetValue();
228 : :
229 : 0 : return nCount;
230 : : }
231 : :
232 : 0 : void SvxXConnectionPreview::MouseButtonDown( const MouseEvent& rMEvt )
233 : : {
234 [ # # ][ # # ]: 0 : sal_Bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
235 [ # # ][ # # ]: 0 : sal_Bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
236 : 0 : sal_Bool bCtrl = rMEvt.IsMod1();
237 : :
238 [ # # ][ # # ]: 0 : if( bZoomIn || bZoomOut )
239 : : {
240 [ # # ]: 0 : MapMode aMapMode = GetMapMode();
241 [ # # ]: 0 : Fraction aXFrac = aMapMode.GetScaleX();
242 [ # # ]: 0 : Fraction aYFrac = aMapMode.GetScaleY();
243 : : Fraction* pMultFrac;
244 : :
245 [ # # ]: 0 : if( bZoomIn )
246 : : {
247 [ # # ]: 0 : if( bCtrl )
248 [ # # ][ # # ]: 0 : pMultFrac = new Fraction( 3, 2 );
249 : : else
250 [ # # ][ # # ]: 0 : pMultFrac = new Fraction( 11, 10 );
251 : : }
252 : : else
253 : : {
254 [ # # ]: 0 : if( bCtrl )
255 [ # # ][ # # ]: 0 : pMultFrac = new Fraction( 2, 3 );
256 : : else
257 [ # # ][ # # ]: 0 : pMultFrac = new Fraction( 10, 11 );
258 : : }
259 : :
260 [ # # ]: 0 : aXFrac *= *pMultFrac;
261 [ # # ]: 0 : aYFrac *= *pMultFrac;
262 [ # # ][ # # ]: 0 : if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
263 [ # # ][ # # ]: 0 : (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
264 : : {
265 [ # # ]: 0 : aMapMode.SetScaleX( aXFrac );
266 [ # # ]: 0 : aMapMode.SetScaleY( aYFrac );
267 [ # # ]: 0 : SetMapMode( aMapMode );
268 : :
269 [ # # ]: 0 : Size aOutSize( GetOutputSize() );
270 : :
271 : 0 : Point aPt( aMapMode.GetOrigin() );
272 [ # # ]: 0 : long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
273 [ # # ]: 0 : long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
274 : 0 : aPt.X() += nX;
275 : 0 : aPt.Y() += nY;
276 : :
277 [ # # ]: 0 : aMapMode.SetOrigin( aPt );
278 [ # # ]: 0 : SetMapMode( aMapMode );
279 : :
280 [ # # ]: 0 : Invalidate();
281 : : }
282 [ # # ]: 0 : delete pMultFrac;
283 : : }
284 : 0 : }
285 : :
286 : 0 : void SvxXConnectionPreview::SetStyles()
287 : : {
288 : 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
289 [ # # ]: 0 : SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
290 [ # # ][ # # ]: 0 : SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
[ # # ]
291 : 0 : }
292 : :
293 : 0 : void SvxXConnectionPreview::DataChanged( const DataChangedEvent& rDCEvt )
294 : : {
295 : 0 : Control::DataChanged( rDCEvt );
296 : :
297 [ # # ][ # # ]: 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
[ # # ]
298 : : {
299 : 0 : SetStyles();
300 : : }
301 : 0 : }
302 : :
303 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|