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