LibreOffice Module svx (master)  1
connctrl.cxx
Go to the documentation of this file.
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 
27 #include <svx/svdmark.hxx>
28 #include <svx/svdoedge.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svx/svdview.hxx>
31 #include <svx/sxelditm.hxx>
32 
33 #include <vcl/settings.hxx>
34 #include <memory>
35 
37  : pEdgeObj(nullptr)
38  , pView(nullptr)
39 {
40  SetMapMode(MapMode(MapUnit::Map100thMM));
41 }
42 
44 {
46  Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(118 , 121), MapMode(MapUnit::MapAppFont)));
47  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
48  SetOutputSizePixel(aSize);
49 }
50 
52 {
53 }
54 
56 {
57  AdaptSize();
58 
59  Invalidate();
60 }
61 
63 {
64  // Adapt size
65  if( !pSdrPage )
66  return;
67 
68  SetMapMode(MapMode(MapUnit::Map100thMM));
69 
70  OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
71  tools::Rectangle aRect = pSdrPage->GetAllObjBoundRect();
72 
73  MapMode aMapMode = GetMapMode();
74  aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
75  SetMapMode( aMapMode );
76 
77  MapMode aDisplayMap( aMapMode );
78  Point aNewPos;
79  Size aNewSize;
80  const Size aWinSize = GetDrawingArea()->get_ref_device().PixelToLogic(GetOutputSizePixel(), aDisplayMap);
81  const long nWidth = aWinSize.Width();
82  const long nHeight = aWinSize.Height();
83  if (aRect.GetHeight() == 0)
84  return;
85  double fRectWH = static_cast<double>(aRect.GetWidth()) / aRect.GetHeight();
86  if (nHeight == 0)
87  return;
88  double fWinWH = static_cast<double>(nWidth) / nHeight;
89 
90  // Adapt bitmap to Thumb size (not here!)
91  if ( fRectWH < fWinWH)
92  {
93  aNewSize.setWidth( static_cast<long>( static_cast<double>(nHeight) * fRectWH ) );
94  aNewSize.setHeight( nHeight );
95  }
96  else
97  {
98  aNewSize.setWidth( nWidth );
99  aNewSize.setHeight( static_cast<long>( static_cast<double>(nWidth) / fRectWH ) );
100  }
101 
102  Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() );
103  Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() );
104  Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 );
105 
106  // Implement MapMode
107  aDisplayMap.SetScaleX( aMinFrac );
108  aDisplayMap.SetScaleY( aMinFrac );
109 
110  // Centering
111  aNewPos.setX( ( nWidth - aNewSize.Width() ) >> 1 );
112  aNewPos.setY( ( nHeight - aNewSize.Height() ) >> 1 );
113 
114  aDisplayMap.SetOrigin(OutputDevice::LogicToLogic(aNewPos, aMapMode, aDisplayMap));
115  SetMapMode( aDisplayMap );
116 
117  // Origin
118  aNewPos = aDisplayMap.GetOrigin();
119  aNewPos -= Point( aRect.TopLeft().X(), aRect.TopLeft().Y() );
120  aDisplayMap.SetOrigin( aNewPos );
121  SetMapMode( aDisplayMap );
122 
123  MouseEvent aMEvt( Point(), 1, MouseEventModifiers::NONE, MOUSE_RIGHT );
124  MouseButtonDown( aMEvt );
125 }
126 
128 {
129  DBG_ASSERT( pView, "No valid view is passed on! ");
130 
131  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
132  const size_t nMarkCount = rMarkList.GetMarkCount();
133 
134  if( nMarkCount >= 1 )
135  {
136  bool bFound = false;
137 
138  for( size_t i = 0; i < nMarkCount && !bFound; ++i )
139  {
140  const SdrObject* pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
141  SdrInventor nInv = pObj->GetObjInventor();
142  sal_uInt16 nId = pObj->GetObjIdentifier();
143  if( nInv == SdrInventor::Default && nId == OBJ_EDGE )
144  {
145  bFound = true;
146 
147  // potential memory leak here (!). Create SdrObjList only when there is
148  // not yet one.
149  if(!pSdrPage)
150  {
151  pSdrPage.reset( new SdrPage(
153  false) );
154  }
155 
156  const SdrEdgeObj* pTmpEdgeObj = static_cast<const SdrEdgeObj*>(pObj);
157  pEdgeObj = pTmpEdgeObj->CloneSdrObject(pSdrPage->getSdrModelFromSdrPage());
158 
159  SdrObjConnection& rConn1 = pEdgeObj->GetConnection( true );
160  SdrObjConnection& rConn2 = pEdgeObj->GetConnection( false );
161 
162  rConn1 = pTmpEdgeObj->GetConnection( true );
163  rConn2 = pTmpEdgeObj->GetConnection( false );
164 
165  SdrObject* pTmpObj1 = pTmpEdgeObj->GetConnectedNode( true );
166  SdrObject* pTmpObj2 = pTmpEdgeObj->GetConnectedNode( false );
167 
168  if( pTmpObj1 )
169  {
170  SdrObject* pObj1 = pTmpObj1->CloneSdrObject(pSdrPage->getSdrModelFromSdrPage());
171  pSdrPage->InsertObject( pObj1 );
172  pEdgeObj->ConnectToNode( true, pObj1 );
173  }
174 
175  if( pTmpObj2 )
176  {
177  SdrObject* pObj2 = pTmpObj2->CloneSdrObject(pSdrPage->getSdrModelFromSdrPage());
178  pSdrPage->InsertObject( pObj2 );
179  pEdgeObj->ConnectToNode( false, pObj2 );
180  }
181 
182  pSdrPage->InsertObject( pEdgeObj );
183  }
184  }
185  }
186 
187  if( !pEdgeObj )
188  {
190  }
191 
192  AdaptSize();
193 }
194 
196 {
197  rRenderContext.Push(PushFlags::ALL);
198 
199  rRenderContext.SetMapMode(GetMapMode());
200 
203  rRenderContext.SetBackground(Wallpaper(rStyles.GetFieldColor()));
204 
205  if (pSdrPage)
206  {
207  // This will not work anymore. To not start at Adam and Eve, i will
208  // ATM not try to change all this stuff to really using an own model
209  // and a view. I will just try to provide a mechanism to paint such
210  // objects without own model and without a page/view with the new
211  // mechanism.
212 
213  // New stuff: Use an ObjectContactOfObjListPainter.
214  sdr::contact::SdrObjectVector aObjectVector;
215 
216  for (size_t a = 0; a < pSdrPage->GetObjCount(); ++a)
217  {
218  SdrObject* pObject = pSdrPage->GetObj(a);
219  DBG_ASSERT(pObject,
220  "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
221  aObjectVector.push_back(pObject);
222  }
223 
224  sdr::contact::ObjectContactOfObjListPainter aPainter(rRenderContext, aObjectVector, nullptr);
225  sdr::contact::DisplayInfo aDisplayInfo;
226 
227  // do processing
228  aPainter.ProcessDisplay(aDisplayInfo);
229  }
230 
231  rRenderContext.Pop();
232 }
233 
235 {
237 
238  Invalidate();
239 }
240 
241 // Get number of lines which are offset based on the preview object
242 
244 {
245  const SfxItemSet& rSet = pEdgeObj->GetMergedItemSet();
246  sal_uInt16 nCount(0);
247 
248  if(SfxItemState::DONTCARE != rSet.GetItemState(SDRATTR_EDGELINEDELTACOUNT))
249  nCount = rSet.Get(SDRATTR_EDGELINEDELTACOUNT).GetValue();
250 
251  return nCount;
252 }
253 
255 {
256  bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
257  bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
258  bool bCtrl = rMEvt.IsMod1();
259 
260  if( bZoomIn || bZoomOut )
261  {
262  MapMode aMapMode = GetMapMode();
263  Fraction aXFrac = aMapMode.GetScaleX();
264  Fraction aYFrac = aMapMode.GetScaleY();
265  std::unique_ptr<Fraction> pMultFrac;
266 
267  if( bZoomIn )
268  {
269  if( bCtrl )
270  pMultFrac.reset(new Fraction( 3, 2 ));
271  else
272  pMultFrac.reset(new Fraction( 11, 10 ));
273  }
274  else
275  {
276  if( bCtrl )
277  pMultFrac.reset(new Fraction( 2, 3 ));
278  else
279  pMultFrac.reset(new Fraction( 10, 11 ));
280  }
281 
282  aXFrac *= *pMultFrac;
283  aYFrac *= *pMultFrac;
284  if( static_cast<double>(aXFrac) > 0.001 && static_cast<double>(aXFrac) < 1000.0 &&
285  static_cast<double>(aYFrac) > 0.001 && static_cast<double>(aYFrac) < 1000.0 )
286  {
287  aMapMode.SetScaleX( aXFrac );
288  aMapMode.SetScaleY( aYFrac );
289  SetMapMode( aMapMode );
290 
291  Size aOutSize(GetOutputSizePixel());
292  aOutSize = GetDrawingArea()->get_ref_device().PixelToLogic(aOutSize);
293 
294  Point aPt( aMapMode.GetOrigin() );
295  long nX = static_cast<long>( ( static_cast<double>(aOutSize.Width()) - ( static_cast<double>(aOutSize.Width()) * static_cast<double>(*pMultFrac) ) ) / 2.0 + 0.5 );
296  long nY = static_cast<long>( ( static_cast<double>(aOutSize.Height()) - ( static_cast<double>(aOutSize.Height()) * static_cast<double>(*pMultFrac) ) ) / 2.0 + 0.5 );
297  aPt.AdjustX(nX );
298  aPt.AdjustY(nY );
299 
300  aMapMode.SetOrigin( aPt );
301  SetMapMode( aMapMode );
302 
303  Invalidate();
304  }
305  }
306 
307  return true;
308 }
309 
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
const Fraction & GetScaleX() const
long Width() const
#define OUTPUT_DRAWMODE_CONTRAST
Definition: dlgctrl.cxx:47
long GetWidth() const
Utility class SdrObjConnection.
Definition: svdoedge.hxx:38
size_t GetMarkCount() const
Definition: svdmark.hxx:180
long GetHeight() const
virtual void Resize() override
Definition: connctrl.cxx:55
SVX_DLLPRIVATE const MapMode & GetMapMode() const
Definition: connctrl.hxx:50
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Height() const
sal_uInt16 GetLineDeltaCount() const
Definition: connctrl.cxx:243
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) ObjectContactPainter typedef::std::vector< SdrObject * > SdrObjectVector
sal_Int16 nId
bool IsShift() const
const MapMode & GetMapMode() const
SdrInventor
Definition: svdobj.hxx:152
virtual ~SvxXConnectionPreview() override
Definition: connctrl.cxx:51
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
OLE object.
Definition: svdobj.hxx:138
#define OUTPUT_DRAWMODE_COLOR
Definition: dlgctrl.cxx:46
EmbeddedObjectRef * pObject
void SetMapMode()
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: connctrl.cxx:43
constexpr TypedWhichId< SdrEdgeLineDeltaCountItem > SDRATTR_EDGELINEDELTACOUNT(SDRATTR_EDGE_FIRST+7)
Size const & GetOutputSizePixel() const
void ConnectToNode(bool bTail1, SdrObject *pObj) override
Definition: svdoedge.cxx:448
void SetDrawMode(DrawModeFlags nDrawMode)
void SetBackground()
SVX_DLLPRIVATE void AdaptSize()
Definition: connctrl.cxx:62
const Fraction & GetScaleY() const
int nCount
bool GetHighContrastMode() const
SVX_DLLPRIVATE void SetMapMode(const MapMode &rNewMapMode)
Definition: connctrl.hxx:49
OutputDevice * GetFirstOutputDevice() const
Definition: svdpntv.cxx:87
virtual OutputDevice & get_ref_device()=0
SdrObject * GetConnectedNode(bool bTail1) const override
Definition: svdoedge.cxx:472
virtual SdrEdgeObj * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: svdoedge.cxx:1643
virtual void ProcessDisplay(DisplayInfo &rDisplayInfo) override
void SetMapUnit(MapUnit eUnit)
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
void SetScaleX(const Fraction &rScaleX)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: connctrl.cxx:195
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
int i
uno_Any a
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: connctrl.cxx:254
virtual sal_uInt16 GetObjIdentifier() const
Definition: svdobj.cxx:558
SdrEdgeObj * pEdgeObj
Definition: connctrl.hxx:44
const SdrMarkList & GetMarkedObjectList() const
Definition: svdmrkv.hxx:252
void SetOrigin(const Point &rOrigin)
const Color & GetFieldColor() const
void SetAttributes(const SfxItemSet &rInAttrs)
Definition: connctrl.cxx:234
void SetMergedItemSetAndBroadcast(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1929
void SetScaleY(const Fraction &rScaleY)
MapUnit GetMapUnit() const
Abstract DrawObject.
Definition: svdobj.hxx:312
SdrObjConnection & GetConnection(bool bTail1)
Definition: svdoedge.hxx:197
void SetOutputSizePixel(const Size &rSize)
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:553
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
weld::DrawingArea * GetDrawingArea() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1889
bool IsLeft() const
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
Definition: svdobj.cxx:974
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
const Point & GetOrigin() const
const SdrView * pView
Definition: connctrl.hxx:46
std::unique_ptr< SdrPage > pSdrPage
Definition: connctrl.hxx:45
SdrModel & getSdrModelFromSdrView() const
Definition: svdpntv.hxx:262
bool IsRight() const
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
virtual void set_size_request(int nWidth, int nHeight)=0
void Push(PushFlags nFlags=PushFlags::ALL)
void setWidth(long nWidth)
#define MOUSE_RIGHT
Utility class SdrEdgeObj.
Definition: svdoedge.hxx:128
bool IsMod1() const
void setHeight(long nHeight)