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