Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ViewsWindow.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/reportdesign/inc -I /home/maarten/src/libreoffice/core/reportdesign/source/inc -I /home/maarten/src/libreoffice/core/reportdesign/source/ui/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx

/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx

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 <ViewsWindow.hxx>
21#include <ScrollHelper.hxx>
22#include <UndoActions.hxx>
23#include <ReportWindow.hxx>
24#include <DesignView.hxx>
25#include <svtools/colorcfg.hxx>
26#include <ReportController.hxx>
27#include <UITools.hxx>
28#include <RptDef.hxx>
29#include <strings.hrc>
30#include <SectionView.hxx>
31#include <ReportSection.hxx>
32#include <strings.hxx>
33#include <rptui_slotid.hrc>
34#include <dlgedclip.hxx>
35#include <RptObject.hxx>
36#include <EndMarker.hxx>
37#include <sal/log.hxx>
38#include <svx/unoshape.hxx>
39#include <vcl/svapp.hxx>
40#include <vcl/settings.hxx>
41#include <core_resource.hxx>
42#include <svx/svdundo.hxx>
43#include <toolkit/helper/convert.hxx>
44#include <algorithm>
45#include <cstdlib>
46#include <numeric>
47
48namespace rptui
49{
50#define DEFAUL_MOVE_SIZE100 100
51
52using namespace ::com::sun::star;
53using namespace ::comphelper;
54
55static bool lcl_getNewRectSize(const tools::Rectangle& _aObjRect,long& _nXMov, long& _nYMov,SdrObject const * _pObj,SdrView const * _pView, ControlModification _nControlModification)
56{
57 bool bMoveAllowed = _nXMov != 0 || _nYMov != 0;
58 if ( bMoveAllowed )
59 {
60 tools::Rectangle aNewRect = _aObjRect;
61 SdrObject* pOverlappedObj = nullptr;
62 do
63 {
64 aNewRect = _aObjRect;
65 switch(_nControlModification)
66 {
67 case ControlModification::HEIGHT_GREATEST:
68 case ControlModification::WIDTH_GREATEST:
69 aNewRect.setWidth(_nXMov);
70 aNewRect.setHeight(_nYMov);
71 break;
72 default:
73 aNewRect.Move(_nXMov,_nYMov);
74 break;
75 }
76 if (dynamic_cast<OUnoObject const *>(_pObj) != nullptr || dynamic_cast<OOle2Obj const *>(_pObj) != nullptr)
77 {
78 pOverlappedObj = isOver(aNewRect,*_pObj->getSdrPageFromSdrObject(),*_pView,true,_pObj);
79 if ( pOverlappedObj && _pObj != pOverlappedObj )
80 {
81 tools::Rectangle aOverlappingRect = pOverlappedObj->GetSnapRect();
82 sal_Int32 nXTemp = _nXMov;
83 sal_Int32 nYTemp = _nYMov;
84 switch(_nControlModification)
85 {
86 case ControlModification::LEFT:
87 nXTemp += aOverlappingRect.Right() - aNewRect.Left();
88 bMoveAllowed = _nXMov != nXTemp;
89 break;
90 case ControlModification::RIGHT:
91 nXTemp += aOverlappingRect.Left() - aNewRect.Right();
92 bMoveAllowed = _nXMov != nXTemp;
93 break;
94 case ControlModification::TOP:
95 nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
96 bMoveAllowed = _nYMov != nYTemp;
97 break;
98 case ControlModification::BOTTOM:
99 nYTemp += aOverlappingRect.Top() - aNewRect.Bottom();
100 bMoveAllowed = _nYMov != nYTemp;
101 break;
102 case ControlModification::CENTER_HORIZONTAL:
103 if ( _aObjRect.Left() < aOverlappingRect.Left() )
104 nXTemp += aOverlappingRect.Left() - aNewRect.Left() - aNewRect.getWidth();
105 else
106 nXTemp += aOverlappingRect.Right() - aNewRect.Left();
107 bMoveAllowed = _nXMov != nXTemp;
108 break;
109 case ControlModification::CENTER_VERTICAL:
110 if ( _aObjRect.Top() < aOverlappingRect.Top() )
111 nYTemp += aOverlappingRect.Top() - aNewRect.Top() - aNewRect.getHeight();
112 else
113 nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
114 bMoveAllowed = _nYMov != nYTemp;
115 break;
116 case ControlModification::HEIGHT_GREATEST:
117 case ControlModification::WIDTH_GREATEST:
118 {
119 tools::Rectangle aIntersectionRect = aNewRect.GetIntersection(aOverlappingRect);
120 if ( !aIntersectionRect.IsEmpty() )
121 {
122 if ( _nControlModification == ControlModification::WIDTH_GREATEST )
123 {
124 if ( aNewRect.Left() < aIntersectionRect.Left() )
125 {
126 aNewRect.SetRight( aIntersectionRect.Left() );
127 }
128 else if ( aNewRect.Left() < aIntersectionRect.Right() )
129 {
130 aNewRect.SetLeft( aIntersectionRect.Right() );
131 }
132 }
133 else if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
134 {
135 if ( aNewRect.Top() < aIntersectionRect.Top() )
136 {
137 aNewRect.SetBottom( aIntersectionRect.Top() );
138 }
139 else if ( aNewRect.Top() < aIntersectionRect.Bottom() )
140 {
141 aNewRect.SetTop( aIntersectionRect.Bottom() );
142 }
143 }
144 nYTemp = aNewRect.getHeight();
145 bMoveAllowed = _nYMov != nYTemp;
146 nXTemp = aNewRect.getWidth();
147 bMoveAllowed = bMoveAllowed && _nXMov != nXTemp;
148 }
149 }
150 break;
151 default:
152 break;
153 }
154
155 _nXMov = nXTemp;
156 _nYMov = nYTemp;
157 }
158 else
159 pOverlappedObj = nullptr;
160 }
161 }
162 while ( pOverlappedObj && bMoveAllowed );
163 }
164 return bMoveAllowed;
165}
166
167OViewsWindow::OViewsWindow( OReportWindow* _pReportWindow)
168 : Window( _pReportWindow,WB_DIALOGCONTROL)
169 , m_pParent(_pReportWindow)
170 , m_bInUnmark(false)
171{
172 SetPaintTransparent(true);
173 SetMapMode(MapMode(MapUnit::Map100thMM));
174 m_aColorConfig.AddListener(this);
175 ImplInitSettings();
176}
177
178OViewsWindow::~OViewsWindow()
179{
180 disposeOnce();
181}
182
183void OViewsWindow::dispose()
184{
185 m_aColorConfig.RemoveListener(this);
186 for (auto& rxSection : m_aSections)
187 rxSection.disposeAndClear();
1
Calling 'VclPtr::disposeAndClear'
188 m_aSections.clear();
189 m_pParent.clear();
190 vcl::Window::dispose();
191}
192
193void OViewsWindow::impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet)
194{
195 const uno::Reference< report::XSection> xSection = _rSectionWindow.getReportSection().getSection();
196
197 Size aSectionSize = _rSectionWindow.LogicToPixel( Size( 0,xSection->getHeight() ) );
198 aSectionSize.setWidth( getView()->GetTotalWidth() );
199
200 const sal_Int32 nMinHeight = _rSectionWindow.getStartMarker().getMinHeight();
201 if ( _rSectionWindow.getStartMarker().isCollapsed() || nMinHeight > aSectionSize.Height() )
202 {
203 aSectionSize.setHeight( nMinHeight );
204 }
205 aSectionSize.AdjustHeight(static_cast<long>(StyleSettings::GetSplitSize() * static_cast<double>(_rSectionWindow.GetMapMode().GetScaleY())) );
206
207 if ( _bSet )
208 _rSectionWindow.SetPosSizePixel(_rStartPoint,aSectionSize);
209
210 _rStartPoint.AdjustY(aSectionSize.Height() );
211}
212
213
214void OViewsWindow::resize(const OSectionWindow& _rSectionWindow)
215{
216 bool bSet = false;
217 Point aStartPoint;
218 for (VclPtr<OSectionWindow> const & pSectionWindow : m_aSections)
219 {
220 if ( pSectionWindow == &_rSectionWindow )
221 {
222 aStartPoint = pSectionWindow->GetPosPixel();
223 bSet = true;
224 }
225
226 if ( bSet )
227 {
228 impl_resizeSectionWindow(*pSectionWindow,aStartPoint,bSet);
229 static const InvalidateFlags nIn = InvalidateFlags::Update | InvalidateFlags::Transparent;
230 pSectionWindow->getStartMarker().Invalidate( nIn ); // InvalidateFlags::NoErase |InvalidateFlags::NoChildren| InvalidateFlags::Transparent
231 pSectionWindow->getEndMarker().Invalidate( nIn );
232 }
233 }
234 m_pParent->notifySizeChanged();
235}
236
237void OViewsWindow::Resize()
238{
239 Window::Resize();
240 if ( !m_aSections.empty() )
241 {
242 const Point aOffset(m_pParent->getThumbPos());
243 Point aStartPoint(0,-aOffset.Y());
244 for (VclPtr<OSectionWindow> const & pSectionWindow : m_aSections)
245 {
246 impl_resizeSectionWindow(*pSectionWindow,aStartPoint,true);
247 }
248 }
249}
250
251void OViewsWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
252{
253 Window::Paint(rRenderContext, rRect);
254
255 rRenderContext.SetBackground();
256 rRenderContext.SetFillColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
257 rRenderContext.SetTextFillColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
258
259 Size aOut(GetOutputSizePixel());
260 long nStartWidth = long(REPORT_STARTMARKER_WIDTH120 * rRenderContext.GetMapMode().GetScaleX());
261
262 aOut.AdjustWidth( -nStartWidth );
263 aOut = rRenderContext.PixelToLogic(aOut);
264
265 tools::Rectangle aRect(rRenderContext.PixelToLogic(Point(nStartWidth,0)), aOut);
266 Wallpaper aWall(m_aColorConfig.GetColorValue(::svtools::APPBACKGROUND).nColor);
267 rRenderContext.DrawWallpaper(aRect, aWall);
268}
269
270void OViewsWindow::ImplInitSettings()
271{
272 EnableChildTransparentMode();
273}
274
275void OViewsWindow::DataChanged( const DataChangedEvent& rDCEvt )
276{
277 Window::DataChanged( rDCEvt );
278
279 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
280 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
281 {
282 ImplInitSettings();
283 Invalidate();
284 }
285}
286
287void OViewsWindow::addSection(const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry,sal_uInt16 _nPosition)
288{
289 VclPtrInstance<OSectionWindow> pSectionWindow(this,_xSection,_sColorEntry);
290 m_aSections.insert(getIteratorAtPos(_nPosition) , TSectionsMap::value_type(pSectionWindow));
291 m_pParent->setMarked(&pSectionWindow->getReportSection().getSectionView(),m_aSections.size() == 1);
292 Resize();
293}
294
295void OViewsWindow::removeSection(sal_uInt16 _nPosition)
296{
297 if ( _nPosition < m_aSections.size() )
298 {
299 TSectionsMap::iterator aPos = getIteratorAtPos(_nPosition);
300 TSectionsMap::const_iterator aNew = getIteratorAtPos(_nPosition == 0 ? _nPosition+1: _nPosition - 1);
301
302 m_pParent->getReportView()->UpdatePropertyBrowserDelayed((*aNew)->getReportSection().getSectionView());
303
304 aPos->disposeAndClear();
305 m_aSections.erase(aPos);
306 Resize();
307 }
308}
309
310void OViewsWindow::toggleGrid(bool _bVisible)
311{
312 ::std::for_each(m_aSections.begin(),m_aSections.end(),
313 [_bVisible] (const TSectionsMap::value_type& sectionPtr) {
314 sectionPtr->getReportSection().SetGridVisible(_bVisible);
315 });
316 ::std::for_each(m_aSections.begin(),m_aSections.end(),
317 [] (const TSectionsMap::value_type& sectionPtr) {
318 sectionPtr->getReportSection().Window::Invalidate(InvalidateFlags::NoErase);
319 });
320}
321
322sal_Int32 OViewsWindow::getTotalHeight() const
323{
324 return std::accumulate(m_aSections.begin(), m_aSections.end(), sal_Int32(0),
325 [](const sal_Int32 nHeight, const VclPtr<OSectionWindow>& rxSection) { return nHeight + rxSection->GetSizePixel().Height(); });
326}
327
328sal_uInt16 OViewsWindow::getSectionCount() const
329{
330 return static_cast<sal_uInt16>(m_aSections.size());
331}
332
333void OViewsWindow::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
334{
335 for (const auto& rxSection : m_aSections)
336 rxSection->getReportSection().getSectionView().SetCurrentObj( eObj, SdrInventor::ReportDesign );
337
338 m_sShapeType = _sShapeType;
339}
340
341
342void OViewsWindow::SetMode( DlgEdMode eNewMode )
343{
344 ::std::for_each(m_aSections.begin(),m_aSections.end(),
345 [&eNewMode] (const TSectionsMap::value_type& sectionPtr) {
346 sectionPtr->getReportSection().SetMode(eNewMode);
347 });
348}
349
350bool OViewsWindow::HasSelection() const
351{
352 return std::any_of(m_aSections.begin(), m_aSections.end(),
353 [](const VclPtr<OSectionWindow>& rxSection) { return rxSection->getReportSection().getSectionView().AreObjectsMarked(); });
354}
355
356void OViewsWindow::Delete()
357{
358 m_bInUnmark = true;
359 ::std::for_each(m_aSections.begin(),m_aSections.end(),
360 [] (const TSectionsMap::value_type& sectionPtr) {
361 sectionPtr->getReportSection().Delete();
362 });
363 m_bInUnmark = false;
364}
365
366void OViewsWindow::Copy()
367{
368 uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
369 ::std::for_each(m_aSections.begin(),m_aSections.end(),
370 [&aAllreadyCopiedObjects] (const TSectionsMap::value_type& sectionPtr) {
371 sectionPtr->getReportSection().Copy(aAllreadyCopiedObjects);
372 });
373
374 rtl::Reference<OReportExchange> pCopy = new OReportExchange(aAllreadyCopiedObjects);
375 pCopy->CopyToClipboard(this);
376}
377
378void OViewsWindow::Paste()
379{
380 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(this));
381 OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aTransferData);
382 if ( aCopies.getLength() > 1 )
383 ::std::for_each(m_aSections.begin(),m_aSections.end(),
384 [&aCopies] (const TSectionsMap::value_type& sectionPtr) {
385 sectionPtr->getReportSection().Paste(aCopies);
386 });
387 else
388 {
389 OSectionWindow* pMarkedSection = getMarkedSection();
390 if ( pMarkedSection )
391 pMarkedSection->getReportSection().Paste(aCopies,true);
392 }
393}
394
395OSectionWindow* OViewsWindow::getSectionWindow(const uno::Reference< report::XSection>& _xSection) const
396{
397 OSL_ENSURE(_xSection.is(),"Section is NULL!")do { if (true && (!(_xSection.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "397" ": "), "%s", "Section is NULL!"); } } while (false
)
;
398
399 OSectionWindow* pSectionWindow = nullptr;
400 for (VclPtr<OSectionWindow> const & p : m_aSections)
401 {
402 if (p->getReportSection().getSection() == _xSection)
403 {
404 pSectionWindow = p.get();
405 break;
406 }
407 }
408
409 return pSectionWindow;
410}
411
412
413OSectionWindow* OViewsWindow::getMarkedSection(NearSectionAccess nsa) const
414{
415 OSectionWindow* pRet = nullptr;
416 TSectionsMap::const_iterator aIter = m_aSections.begin();
417 TSectionsMap::const_iterator aEnd = m_aSections.end();
418 sal_uInt32 nCurrentPosition = 0;
419 for (; aIter != aEnd ; ++aIter)
420 {
421 if ( (*aIter)->getStartMarker().isMarked() )
422 {
423 if (nsa == CURRENT)
424 {
425 pRet = aIter->get();
426 break;
427 }
428 else if ( nsa == PREVIOUS )
429 {
430 if (nCurrentPosition > 0)
431 {
432 pRet = (--aIter)->get();
433 if (pRet == nullptr)
434 {
435 pRet = m_aSections.begin()->get();
436 }
437 }
438 else
439 {
440 // if we are out of bounds return the first one
441 pRet = m_aSections.begin()->get();
442 }
443 break;
444 }
445 else if ( nsa == POST )
446 {
447 sal_uInt32 nSize = m_aSections.size();
448 if ((nCurrentPosition + 1) < nSize)
449 {
450 pRet = (++aIter)->get();
451 if (pRet == nullptr)
452 {
453 pRet = (--aEnd)->get();
454 }
455 }
456 else
457 {
458 // if we are out of bounds return the last one
459 pRet = (--aEnd)->get();
460 }
461 break;
462 }
463 }
464 ++nCurrentPosition;
465 }
466
467 return pRet;
468}
469
470void OViewsWindow::markSection(const sal_uInt16 _nPos)
471{
472 if ( _nPos < m_aSections.size() )
473 m_pParent->setMarked(m_aSections[_nPos]->getReportSection().getSection(),true);
474}
475
476bool OViewsWindow::IsPasteAllowed() const
477{
478 TransferableDataHelper aTransferData( TransferableDataHelper::CreateFromSystemClipboard( const_cast< OViewsWindow* >( this ) ) );
479 return aTransferData.HasFormat(OReportExchange::getDescriptorFormatId());
480}
481
482void OViewsWindow::SelectAll(const sal_uInt16 _nObjectType)
483{
484 m_bInUnmark = true;
485 ::std::for_each(m_aSections.begin(),m_aSections.end(),
486 [&_nObjectType] (const TSectionsMap::value_type& sectionPtr) {
487 sectionPtr->getReportSection().SelectAll(_nObjectType);
488 });
489 m_bInUnmark = false;
490}
491
492void OViewsWindow::unmarkAllObjects(OSectionView const * _pSectionView)
493{
494 if ( m_bInUnmark )
495 return;
496
497 m_bInUnmark = true;
498 for (const auto& rxSection : m_aSections)
499 {
500 if ( &rxSection->getReportSection().getSectionView() != _pSectionView )
501 {
502 rxSection->getReportSection().deactivateOle();
503 rxSection->getReportSection().getSectionView().UnmarkAllObj();
504 }
505 }
506 m_bInUnmark = false;
507}
508
509void OViewsWindow::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints)
510{
511 ImplInitSettings();
512 Invalidate();
513}
514
515void OViewsWindow::MouseButtonDown( const MouseEvent& rMEvt )
516{
517 if ( rMEvt.IsLeft() )
518 {
519 GrabFocus();
520 const uno::Sequence< beans::PropertyValue> aArgs;
521 getView()->getReportView()->getController().executeChecked(SID_SELECT_REPORT( ((((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149)
+ 1) + 200) + 1) + 12 )
,aArgs);
522 }
523 Window::MouseButtonDown(rMEvt);
524}
525
526void OViewsWindow::showRuler(bool _bShow)
527{
528 ::std::for_each(m_aSections.begin(),m_aSections.end(),
529 [_bShow] (const TSectionsMap::value_type& sectionPtr) {
530 sectionPtr->getStartMarker().showRuler(_bShow);
531 });
532 ::std::for_each(m_aSections.begin(),m_aSections.end(),
533 [] (const TSectionsMap::value_type& sectionPtr) {
534 sectionPtr->getStartMarker().Window::Invalidate(InvalidateFlags::NoErase);
535 });
536}
537
538void OViewsWindow::MouseButtonUp( const MouseEvent& rMEvt )
539{
540 if ( !rMEvt.IsLeft() )
541 return;
542
543 auto aIter = std::find_if(m_aSections.begin(), m_aSections.end(),
544 [](const VclPtr<OSectionWindow>& rxSection) { return rxSection->getReportSection().getSectionView().AreObjectsMarked(); });
545 if (aIter != m_aSections.end())
546 {
547 (*aIter)->getReportSection().MouseButtonUp(rMEvt);
548 }
549
550 // remove special insert mode
551 for (const auto& rxSection : m_aSections)
552 {
553 rxSection->getReportSection().getPage()->resetSpecialMode();
554 }
555}
556
557bool OViewsWindow::handleKeyEvent(const KeyEvent& _rEvent)
558{
559 bool bRet = false;
560 for (const auto& rxSection : m_aSections)
561 {
562 if ( rxSection->getStartMarker().isMarked() )
563 {
564 bRet = rxSection->getReportSection().handleKeyEvent(_rEvent);
565 }
566 }
567 return bRet;
568}
569
570OViewsWindow::TSectionsMap::iterator OViewsWindow::getIteratorAtPos(sal_uInt16 _nPos)
571{
572 TSectionsMap::iterator aRet = m_aSections.end();
573 if ( _nPos < m_aSections.size() )
574 aRet = m_aSections.begin() + _nPos;
575 return aRet;
576}
577
578void OViewsWindow::setMarked(OSectionView const * _pSectionView, bool _bMark)
579{
580 OSL_ENSURE(_pSectionView != nullptr,"SectionView is NULL!")do { if (true && (!(_pSectionView != nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "580" ": "), "%s", "SectionView is NULL!"); } } while (false
)
;
581 if ( _pSectionView )
582 setMarked(_pSectionView->getReportSection()->getSection(),_bMark);
583}
584
585void OViewsWindow::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
586{
587 for (const auto& rxSection : m_aSections)
588 {
589 if ( rxSection->getReportSection().getSection() != _xSection )
590 {
591 rxSection->setMarked(false);
592 }
593 else if ( rxSection->getStartMarker().isMarked() != _bMark )
594 {
595 rxSection->setMarked(_bMark);
596 }
597 }
598}
599
600void OViewsWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _aShapes, bool _bMark)
601{
602 bool bFirst = true;
603 for(const uno::Reference< report::XReportComponent>& rShape : _aShapes)
604 {
605 const uno::Reference< report::XSection> xSection = rShape->getSection();
606 if ( xSection.is() )
607 {
608 if ( bFirst )
609 {
610 bFirst = false;
611 m_pParent->setMarked(xSection,_bMark);
612 }
613 OSectionWindow* pSectionWindow = getSectionWindow(xSection);
614 if ( pSectionWindow )
615 {
616 SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( rShape );
617 SdrObject* pObject = pShape ? pShape->GetSdrObject() : nullptr;
618 OSL_ENSURE( pObject, "OViewsWindow::setMarked: no SdrObject for the shape!" )do { if (true && (!(pObject))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "618" ": "), "%s", "OViewsWindow::setMarked: no SdrObject for the shape!"
); } } while (false)
;
619 if ( pObject )
620 pSectionWindow->getReportSection().getSectionView().MarkObj( pObject, pSectionWindow->getReportSection().getSectionView().GetSdrPageView(), !_bMark );
621 }
622 }
623 }
624}
625
626void OViewsWindow::collectRectangles(TRectangleMap& _rSortRectangles)
627{
628 for (const auto& rxSection : m_aSections)
629 {
630 OSectionView& rView = rxSection->getReportSection().getSectionView();
631 if ( rView.AreObjectsMarked() )
632 {
633 rView.SortMarkedObjects();
634 const size_t nCount = rView.GetMarkedObjectCount();
635 for (size_t i=0; i < nCount; ++i)
636 {
637 const SdrMark* pM = rView.GetSdrMarkByIndex(i);
638 SdrObject* pObj = pM->GetMarkedSdrObj();
639 tools::Rectangle aObjRect(pObj->GetSnapRect());
640 _rSortRectangles.emplace(aObjRect,TRectangleMap::mapped_type(pObj,&rView));
641 }
642 }
643 }
644}
645
646void OViewsWindow::collectBoundResizeRect(const TRectangleMap& _rSortRectangles, ControlModification _nControlModification,bool _bAlignAtSection, tools::Rectangle& _rBound, tools::Rectangle& _rResize)
647{
648 bool bOnlyOnce = false;
649 for (const auto& [aObjRect, rObjViewPair] : _rSortRectangles)
650 {
651 if ( _rResize.IsEmpty() )
652 _rResize = aObjRect;
653 switch(_nControlModification)
654 {
655 case ControlModification::WIDTH_SMALLEST:
656 if ( _rResize.getWidth() > aObjRect.getWidth() )
657 _rResize = aObjRect;
658 break;
659 case ControlModification::HEIGHT_SMALLEST:
660 if ( _rResize.getHeight() > aObjRect.getHeight() )
661 _rResize = aObjRect;
662 break;
663 case ControlModification::WIDTH_GREATEST:
664 if ( _rResize.getWidth() < aObjRect.getWidth() )
665 _rResize = aObjRect;
666 break;
667 case ControlModification::HEIGHT_GREATEST:
668 if ( _rResize.getHeight() < aObjRect.getHeight() )
669 _rResize = aObjRect;
670 break;
671 default: break;
672 }
673
674 SdrObjTransformInfoRec aInfo;
675 const SdrObject* pObj = rObjViewPair.first;
676 pObj->TakeObjInfo(aInfo);
677 bool bHasFixed = !aInfo.bMoveAllowed || pObj->IsMoveProtect();
678 if ( bHasFixed )
679 _rBound.Union(aObjRect);
680 else
681 {
682 if ( _bAlignAtSection || _rSortRectangles.size() == 1 )
683 { // align single object at the page
684 if ( ! bOnlyOnce )
685 {
686 bOnlyOnce = true;
687 OReportSection* pReportSection = rObjViewPair.second->getReportSection();
688 const uno::Reference< report::XSection>& xSection = pReportSection->getSection();
689 try
690 {
691 uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
692 _rBound.Union(tools::Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN"LeftMargin"),0,
693 getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE"Size").Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN"RightMargin"),
694 xSection->getHeight()));
695 }
696 catch(const uno::Exception &){}
697 }
698 }
699 else
700 {
701 _rBound.Union(rObjViewPair.second->GetMarkedObjRect());
702 }
703 }
704 }
705}
706
707void OViewsWindow::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
708{
709 if ( _nControlModification == ControlModification::NONE )
710 return;
711
712 Point aRefPoint;
713 RectangleLess::CompareMode eCompareMode = RectangleLess::POS_LEFT;
714 switch (_nControlModification)
715 {
716 case ControlModification::TOP : eCompareMode = RectangleLess::POS_UPPER; break;
717 case ControlModification::BOTTOM: eCompareMode = RectangleLess::POS_DOWN; break;
718 case ControlModification::LEFT : eCompareMode = RectangleLess::POS_LEFT; break;
719 case ControlModification::RIGHT : eCompareMode = RectangleLess::POS_RIGHT; break;
720 case ControlModification::CENTER_HORIZONTAL :
721 case ControlModification::CENTER_VERTICAL :
722 {
723 eCompareMode = (ControlModification::CENTER_VERTICAL == _nControlModification) ? RectangleLess::POS_CENTER_VERTICAL : RectangleLess::POS_CENTER_HORIZONTAL;
724 uno::Reference<report::XSection> xSection = (*m_aSections.begin())->getReportSection().getSection();
725 uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
726 aRefPoint = tools::Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN"LeftMargin"),0,
727 getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE"Size").Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN"RightMargin"),
728 xSection->getHeight()).Center();
729 }
730 break;
731 default: break;
732 }
733 RectangleLess aCompare(eCompareMode,aRefPoint);
734 TRectangleMap aSortRectangles(aCompare);
735 collectRectangles(aSortRectangles);
736
737 tools::Rectangle aBound;
738 tools::Rectangle aResize;
739 collectBoundResizeRect(aSortRectangles,_nControlModification,_bAlignAtSection,aBound,aResize);
740
741 bool bMove = true;
742
743 auto aGetFun = ::std::mem_fn(&tools::Rectangle::Bottom);
744 auto aSetFun = ::std::mem_fn(&tools::Rectangle::SetBottom);
745 auto aRefFun = ::std::mem_fn(&tools::Rectangle::Top);
746 TRectangleMap::const_iterator aRectIter = aSortRectangles.begin();
747 TRectangleMap::const_iterator aRectEnd = aSortRectangles.end();
748 for (;aRectIter != aRectEnd ; ++aRectIter)
749 {
750 tools::Rectangle aObjRect = aRectIter->first;
751 SdrObject* pObj = aRectIter->second.first;
752 SdrView* pView = aRectIter->second.second;
753 Point aCenter(aBound.Center());
754 SdrObjTransformInfoRec aInfo;
755 pObj->TakeObjInfo(aInfo);
756 if (aInfo.bMoveAllowed && !pObj->IsMoveProtect())
757 {
758 long nXMov = 0;
759 long nYMov = 0;
760 long* pValue = &nXMov;
761 switch(_nControlModification)
762 {
763 case ControlModification::TOP :
764 aGetFun = ::std::mem_fn(&tools::Rectangle::Top);
765 aSetFun = ::std::mem_fn(&tools::Rectangle::SetTop);
766 aRefFun = ::std::mem_fn(&tools::Rectangle::Bottom);
767 pValue = &nYMov;
768 break;
769 case ControlModification::BOTTOM:
770 // defaults are already set
771 pValue = &nYMov;
772 break;
773 case ControlModification::CENTER_VERTICAL:
774 nYMov = aCenter.Y() - aObjRect.Center().Y();
775 pValue = &nYMov;
776 bMove = false;
777 break;
778 case ControlModification::RIGHT :
779 aGetFun = ::std::mem_fn(&tools::Rectangle::Right);
780 aSetFun = ::std::mem_fn(&tools::Rectangle::SetRight);
781 aRefFun = ::std::mem_fn(&tools::Rectangle::Left);
782 break;
783 case ControlModification::CENTER_HORIZONTAL:
784 nXMov = aCenter.X() - aObjRect.Center().X();
785 bMove = false;
786 break;
787 case ControlModification::LEFT :
788 aGetFun = ::std::mem_fn(&tools::Rectangle::Left);
789 aSetFun = ::std::mem_fn(&tools::Rectangle::SetLeft);
790 aRefFun = ::std::mem_fn(&tools::Rectangle::Right);
791 break;
792 default:
793 bMove = false;
794 break;
795 }
796 if ( bMove )
797 {
798 tools::Rectangle aTest = aObjRect;
799 aSetFun(&aTest, aGetFun(&aBound));
800 TRectangleMap::const_iterator aInterSectRectIter = aSortRectangles.begin();
801 for (; aInterSectRectIter != aRectIter; ++aInterSectRectIter)
802 {
803 if ( pView == aInterSectRectIter->second.second && (dynamic_cast<OUnoObject*>(aInterSectRectIter->second.first) || dynamic_cast<OOle2Obj*>(aInterSectRectIter->second.first)))
804 {
805 SdrObject* pPreviousObj = aInterSectRectIter->second.first;
806 tools::Rectangle aIntersectRect = aTest.GetIntersection( pPreviousObj->GetSnapRect());
807 if ( !aIntersectRect.IsEmpty() && (aIntersectRect.Left() != aIntersectRect.Right() && aIntersectRect.Top() != aIntersectRect.Bottom() ) )
808 {
809 *pValue = aRefFun(&aIntersectRect) - aGetFun(&aObjRect);
810 break;
811 }
812 }
813 }
814 if ( aInterSectRectIter == aRectIter )
815 *pValue = aGetFun(&aBound) - aGetFun(&aObjRect);
816 }
817
818 if ( lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification) )
819 {
820 const Size aSize(nXMov,nYMov);
821 pView->AddUndo(pView->GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pObj,aSize));
822 pObj->Move(aSize);
823 aObjRect = pObj->GetSnapRect();
824 }
825
826 // resizing control
827 if ( !aResize.IsEmpty() && aObjRect != aResize )
828 {
829 nXMov = aResize.getWidth();
830 nYMov = aResize.getHeight();
831 switch(_nControlModification)
832 {
833 case ControlModification::WIDTH_GREATEST:
834 case ControlModification::HEIGHT_GREATEST:
835 if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
836 nXMov = aObjRect.getWidth();
837 else if ( _nControlModification == ControlModification::WIDTH_GREATEST )
838 nYMov = aObjRect.getHeight();
839 lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification);
840 [[fallthrough]];
841 case ControlModification::WIDTH_SMALLEST:
842 case ControlModification::HEIGHT_SMALLEST:
843 pView->AddUndo( pView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
844 {
845 OObjectBase* pObjBase = dynamic_cast<OObjectBase*>(pObj);
846 OSL_ENSURE(pObjBase,"Where comes this object from?")do { if (true && (!(pObjBase))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "846" ": "), "%s", "Where comes this object from?"); } }
while (false)
;
847 if ( pObjBase )
848 {
849 if ( _nControlModification == ControlModification::WIDTH_SMALLEST || _nControlModification == ControlModification::WIDTH_GREATEST )
850 pObjBase->getReportComponent()->setSize(awt::Size(nXMov,aObjRect.getHeight()));
851 else if ( _nControlModification == ControlModification::HEIGHT_GREATEST || _nControlModification == ControlModification::HEIGHT_SMALLEST )
852 pObjBase->getReportComponent()->setSize(awt::Size(aObjRect.getWidth(),nYMov));
853 }
854 }
855 break;
856 default:
857 break;
858 }
859 }
860 }
861 pView->AdjustMarkHdl();
862 }
863}
864
865void OViewsWindow::createDefault()
866{
867 OSectionWindow* pMarkedSection = getMarkedSection();
868 if ( pMarkedSection )
869 pMarkedSection->getReportSection().createDefault(m_sShapeType);
870}
871
872void OViewsWindow::setGridSnap(bool bOn)
873{
874 for (const auto& rxSection : m_aSections)
875 {
876 rxSection->getReportSection().getSectionView().SetGridSnap(bOn);
877 rxSection->getReportSection().Invalidate();
878 }
879}
880
881void OViewsWindow::setDragStripes(bool bOn)
882{
883 for (const auto& rxSection : m_aSections)
884 rxSection->getReportSection().getSectionView().SetDragStripes(bOn);
885}
886
887sal_uInt16 OViewsWindow::getPosition(const OSectionWindow* _pSectionWindow) const
888{
889 auto aIter = std::find_if(m_aSections.begin(), m_aSections.end(),
890 [&_pSectionWindow](const VclPtr<OSectionWindow>& rxSection) { return _pSectionWindow == rxSection.get(); });
891 return static_cast<sal_uInt16>(std::distance(m_aSections.begin(), aIter));
892}
893
894OSectionWindow* OViewsWindow::getSectionWindow(const sal_uInt16 _nPos) const
895{
896 OSectionWindow* aReturn = nullptr;
897
898 if ( _nPos < m_aSections.size() )
899 aReturn = m_aSections[_nPos].get();
900
901 return aReturn;
902}
903
904namespace
905{
906 enum SectionViewAction
907 {
908 eEndDragObj,
909 eEndAction,
910 eForceToAnotherPage,
911 eBreakAction
912 };
913 class ApplySectionViewAction
914 {
915 private:
916 SectionViewAction m_eAction;
917
918 public:
919 explicit ApplySectionViewAction()
920 : m_eAction(eEndDragObj)
921 {
922 }
923
924 explicit ApplySectionViewAction(SectionViewAction _eAction)
925 : m_eAction(_eAction)
926 {
927 }
928
929 void operator() ( const OViewsWindow::TSectionsMap::value_type& _rhs )
930 {
931 OSectionView& rView( _rhs->getReportSection().getSectionView() );
932 switch ( m_eAction )
933 {
934 case eEndDragObj:
935 rView.EndDragObj();
936 break;
937 case eEndAction:
938 if ( rView.IsAction() )
939 rView.EndAction ( );
940 break;
941 case eForceToAnotherPage:
942 rView.ForceMarkedToAnotherPage();
943 break;
944 case eBreakAction:
945 if ( rView.IsAction() )
946 rView.BrkAction ( );
947 break;
948 // default:
949
950 }
951 }
952 };
953}
954
955void OViewsWindow::BrkAction()
956{
957 EndDragObj_removeInvisibleObjects();
958 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eBreakAction) );
959}
960
961void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const tools::Rectangle& _aRect, const OSectionView& _rSection)
962{
963 Point aNewPos(0,0);
964
965 for (const auto& rxSection : m_aSections)
966 {
967 OReportSection& rReportSection = rxSection->getReportSection();
968 rReportSection.getPage()->setSpecialMode();
969 OSectionView& rView = rReportSection.getSectionView();
970
971 if ( &rView != &_rSection )
972 {
973 SdrObject *pNewObj = new SdrUnoObj(
974 rView.getSdrModelFromSdrView(),
975 "com.sun.star.form.component.FixedText");
976
977 pNewObj->SetLogicRect(_aRect);
978 pNewObj->Move(Size(0, aNewPos.Y()));
979 bool bChanged = rView.GetModel()->IsChanged();
980 rReportSection.getPage()->InsertObject(pNewObj);
981 rView.GetModel()->SetChanged(bChanged);
982 m_aBegDragTempList.push_back(pNewObj);
983
984 rView.MarkObj( pNewObj, rView.GetSdrPageView() );
985 }
986 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
987 aNewPos.AdjustY( -nSectionHeight );
988 }
989}
990
991void OViewsWindow::BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection)
992{
993 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Clickpoint X:" <<
_aPnt.X() << " Y:" << _aPnt.Y()) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Clickpoint X:" << _aPnt.X() <<
" Y:" << _aPnt.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Clickpoint X:"
<< _aPnt.X() << " Y:" << _aPnt.Y(); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"),
("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Clickpoint X:" << _aPnt.X() << " Y:"
<< _aPnt.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Clickpoint X:" << _aPnt.X() <<
" Y:" << _aPnt.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Clickpoint X:"
<< _aPnt.X() << " Y:" << _aPnt.Y(); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"),
("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
994 "reportdesign", "Clickpoint X:" << _aPnt.X() << " Y:" << _aPnt.Y())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Clickpoint X:" <<
_aPnt.X() << " Y:" << _aPnt.Y()) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Clickpoint X:" << _aPnt.X() <<
" Y:" << _aPnt.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Clickpoint X:"
<< _aPnt.X() << " Y:" << _aPnt.Y(); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"),
("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Clickpoint X:" << _aPnt.X() << " Y:"
<< _aPnt.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Clickpoint X:" << _aPnt.X() <<
" Y:" << _aPnt.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Clickpoint X:"
<< _aPnt.X() << " Y:" << _aPnt.Y(); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"),
("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "994" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
995
996 m_aBegDragTempList.clear();
997
998 // Calculate the absolute clickpoint in the views
999 Point aAbsolutePnt = _aPnt;
1000 for (const auto& rxSection : m_aSections)
1001 {
1002 OReportSection& rReportSection = rxSection->getReportSection();
1003 OSectionView* pView = &rReportSection.getSectionView();
1004 if (pView == _pSection)
1005 break;
1006 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1007 aAbsolutePnt.AdjustY(nSectionHeight );
1008 }
1009 m_aDragDelta = Point(SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF));
1010 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Absolute X:" <<
aAbsolutePnt.X() << " Y:" << aAbsolutePnt.Y()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Absolute X:" << aAbsolutePnt.X() << " Y:"
<< aAbsolutePnt.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1011 "reportdesign",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Absolute X:" <<
aAbsolutePnt.X() << " Y:" << aAbsolutePnt.Y()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Absolute X:" << aAbsolutePnt.X() << " Y:"
<< aAbsolutePnt.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1012 "Absolute X:" << aAbsolutePnt.X() << " Y:" << aAbsolutePnt.Y())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Absolute X:" <<
aAbsolutePnt.X() << " Y:" << aAbsolutePnt.Y()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Absolute X:" << aAbsolutePnt.X() << " Y:"
<< aAbsolutePnt.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Absolute X:" << aAbsolutePnt.
X() << " Y:" << aAbsolutePnt.Y()), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"Absolute X:" << aAbsolutePnt.X() << " Y:" <<
aAbsolutePnt.Y(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1012" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1013
1014 // Create drag lines over all viewable Views
1015 // Therefore we need to identify the marked objects
1016 // and create temporary objects on all other views at the same position
1017 // relative to its occurrence.
1018
1019 int nViewCount = 0;
1020 Point aNewObjPos(0,0);
1021 Point aLeftTop(SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF));
1022 for (const auto& rxSection : m_aSections)
1023 {
1024 OReportSection& rReportSection = rxSection->getReportSection();
1025
1026 OSectionView& rView = rReportSection.getSectionView();
1027
1028 if ( rView.AreObjectsMarked() )
1029 {
1030 const size_t nCount = rView.GetMarkedObjectCount();
1031 for (size_t i=0; i < nCount; ++i)
1032 {
1033 const SdrMark* pM = rView.GetSdrMarkByIndex(i);
1034 SdrObject* pObj = pM->GetMarkedSdrObj();
1035 if (::std::find(m_aBegDragTempList.begin(),m_aBegDragTempList.end(),pObj) == m_aBegDragTempList.end())
1036 {
1037 tools::Rectangle aRect( pObj->GetCurrentBoundRect() );
1038 aRect.Move(0, aNewObjPos.Y());
1039
1040 aLeftTop.setX( ::std::min( aRect.Left(), aLeftTop.X() ) );
1041 aLeftTop.setY( ::std::min( aRect.Top(), aLeftTop.Y() ) );
1042
1043 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "createInvisible X:" <<
aRect.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "createInvisible X:" << aRect.Left() <<
" Y:" << aRect.Top() << " on View #" << nViewCount
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1044 "reportdesign",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "createInvisible X:" <<
aRect.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "createInvisible X:" << aRect.Left() <<
" Y:" << aRect.Top() << " on View #" << nViewCount
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1045 "createInvisible X:" << aRect.Left() << " Y:"do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "createInvisible X:" <<
aRect.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "createInvisible X:" << aRect.Left() <<
" Y:" << aRect.Top() << " on View #" << nViewCount
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1046 << aRect.Top() << " on View #" << nViewCount)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "createInvisible X:" <<
aRect.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "createInvisible X:" << aRect.Left() <<
" Y:" << aRect.Top() << " on View #" << nViewCount
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createInvisible X:" << aRect.
Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "createInvisible X:" << aRect
.Left() << " Y:" << aRect.Top() << " on View #"
<< nViewCount; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1046" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1047
1048 BegDragObj_createInvisibleObjectAtPosition(aRect, rView);
1049 }
1050 }
1051 }
1052 ++nViewCount;
1053 tools::Rectangle aClipRect = rView.GetWorkArea();
1054 aClipRect.SetTop( -aNewObjPos.Y() );
1055 rView.SetWorkArea( aClipRect );
1056
1057 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1058 aNewObjPos.AdjustY(nSectionHeight );
1059 }
1060
1061 const sal_Int32 nDeltaX = std::abs(aLeftTop.X() - aAbsolutePnt.X());
1062 const sal_Int32 nDeltaY = std::abs(aLeftTop.Y() - aAbsolutePnt.Y());
1063 m_aDragDelta.setX( nDeltaX );
1064 m_aDragDelta.setY( nDeltaY );
1065
1066 Point aNewPos = aAbsolutePnt;
1067
1068 const short nDrgLog = static_cast<short>(PixelToLogic(Size(3,0)).Width());
1069 nViewCount = 0;
1070 for (const auto& rxSection : m_aSections)
1071 {
1072 OReportSection& rReportSection = rxSection->getReportSection();
1073
1074 SdrHdl* pHdl = _pHdl;
1075 if ( pHdl )
1076 {
1077 if ( &rReportSection.getSectionView() != _pSection )
1078 {
1079 const SdrHdlList& rHdlList = rReportSection.getSectionView().GetHdlList();
1080 pHdl = rHdlList.GetHdl(_pHdl->GetKind());
1081 }
1082 }
1083 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aNewPos
.X() << " Y:" << aNewPos.Y() << " on View#"
<< nViewCount++) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aNewPos.X() << " Y:" <<
aNewPos.Y() << " on View#" << nViewCount++) == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1084 "reportdesign",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aNewPos
.X() << " Y:" << aNewPos.Y() << " on View#"
<< nViewCount++) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aNewPos.X() << " Y:" <<
aNewPos.Y() << " on View#" << nViewCount++) == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1085 "X:" << aNewPos.X() << " Y:" << aNewPos.Y() << " on View#"do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aNewPos
.X() << " Y:" << aNewPos.Y() << " on View#"
<< nViewCount++) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aNewPos.X() << " Y:" <<
aNewPos.Y() << " on View#" << nViewCount++) == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1086 << nViewCount++)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aNewPos
.X() << " Y:" << aNewPos.Y() << " on View#"
<< nViewCount++) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aNewPos.X() << " Y:" <<
aNewPos.Y() << " on View#" << nViewCount++) == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"
), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aNewPos.X() << " Y:"
<< aNewPos.Y() << " on View#" << nViewCount
++), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "X:" << aNewPos.X() << " Y:" << aNewPos
.Y() << " on View#" << nViewCount++; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1086" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1087 rReportSection.getSectionView().BegDragObj(aNewPos, nullptr, pHdl, nDrgLog);
1088
1089 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1090 aNewPos.AdjustY( -nSectionHeight );
1091 }
1092}
1093
1094
1095void OViewsWindow::ForceMarkedToAnotherPage()
1096{
1097 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eForceToAnotherPage ) );
1098}
1099
1100void OViewsWindow::BegMarkObj(const Point& _aPnt,const OSectionView* _pSection)
1101{
1102 bool bAdd = true;
1103 Point aNewPos = _aPnt;
1104
1105 long nLastSectionHeight = 0;
1106 for (const auto& rxSection : m_aSections)
1107 {
1108 OReportSection& rReportSection = rxSection->getReportSection();
1109 if ( &rReportSection.getSectionView() == _pSection )
1110 {
1111 bAdd = false;
1112 aNewPos = _aPnt; // 2,2
1113 }
1114 else if ( bAdd )
1115 {
1116 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1117 aNewPos.AdjustY(nSectionHeight );
1118 }
1119 else
1120 {
1121 aNewPos.AdjustY( -nLastSectionHeight );
1122 }
1123 rReportSection.getSectionView().BegMarkObj ( aNewPos );
1124 nLastSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1125 }
1126}
1127
1128OSectionView* OViewsWindow::getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt)
1129{
1130 OSectionView* pSection = nullptr;
1131 TSectionsMap::const_iterator aIter = m_aSections.begin();
1132 const TSectionsMap::const_iterator aEnd = m_aSections.end();
1133 aIter = std::find_if(aIter, aEnd, [&_pSection](const VclPtr<OSectionWindow>& rxSection) {
1134 return &rxSection->getReportSection().getSectionView() == _pSection; });
1135 sal_Int32 nCount = static_cast<sal_Int32>(std::distance(m_aSections.cbegin(), aIter));
1136 OSL_ENSURE(aIter != aEnd,"This can never happen!")do { if (true && (!(aIter != aEnd))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1136" ": "), "%s", "This can never happen!"); } } while
(false)
;
1137 if ( _rPnt.Y() < 0 )
1138 {
1139 if ( nCount )
1140 --aIter;
1141 for (; nCount && (_rPnt.Y() < 0); --nCount)
1142 {
1143 OReportSection& rReportSection = (*aIter)->getReportSection();
1144 const sal_Int32 nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1145 _rPnt.AdjustY(nHeight );
1146 if ( (nCount -1) > 0 && (_rPnt.Y() < 0) )
1147 --aIter;
1148 }
1149 if ( nCount == 0 )
1150 pSection = &(*m_aSections.begin())->getReportSection().getSectionView();
1151 else
1152 pSection = &(*aIter)->getReportSection().getSectionView();
1153 }
1154 else
1155 {
1156 for (; aIter != aEnd; ++aIter)
1157 {
1158 OReportSection& rReportSection = (*aIter)->getReportSection();
1159 const long nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1160 if ( (_rPnt.Y() - nHeight) < 0 )
1161 break;
1162 _rPnt.AdjustY( -nHeight );
1163 }
1164 if ( aIter != aEnd )
1165 pSection = &(*aIter)->getReportSection().getSectionView();
1166 else
1167 pSection = &(*(aEnd-1))->getReportSection().getSectionView();
1168 }
1169
1170 return pSection;
1171}
1172
1173void OViewsWindow::EndDragObj_removeInvisibleObjects()
1174{
1175 for (const auto& rxSection : m_aSections)
1176 {
1177 OReportSection& rReportSection = rxSection->getReportSection();
1178 rReportSection.getPage()->resetSpecialMode();
1179 }
1180}
1181
1182void OViewsWindow::EndDragObj(bool _bControlKeyPressed, const OSectionView* _pSection, const Point& _aPnt)
1183{
1184 const OUString sUndoAction = RptResId(RID_STR_UNDO_CHANGEPOSITIONreinterpret_cast<char const *>("RID_STR_UNDO_CHANGEPOSITION"
"\004" u8"Change Object")
);
1185 const UndoContext aUndoContext( getView()->getReportView()->getController().getUndoManager(), sUndoAction );
1186
1187 Point aNewPos = _aPnt;
1188 OSectionView* pInSection = getSectionRelativeToPosition(_pSection, aNewPos);
1189 if (!_bControlKeyPressed &&
1190 _pSection && !_pSection->IsDragResize() && /* Not in resize mode */
1191 _pSection != pInSection)
1192 {
1193 EndDragObj_removeInvisibleObjects();
1194
1195 // we need to manipulate the current clickpoint, we subtract the old delta from BeginDrag
1196 aNewPos -= m_aDragDelta;
1197
1198 uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
1199 for (const auto& rxSection : m_aSections)
1200 {
1201 OReportSection& rReportSection = rxSection->getReportSection();
1202 if ( pInSection != &rReportSection.getSectionView() )
1203 {
1204 rReportSection.getSectionView().BrkAction();
1205 rReportSection.Copy(aAllreadyCopiedObjects,true);
1206 }
1207 else
1208 pInSection->EndDragObj();
1209 }
1210
1211 if ( aAllreadyCopiedObjects.hasElements() )
1212 {
1213 try
1214 {
1215 uno::Reference<report::XReportDefinition> xReportDefinition = getView()->getReportView()->getController().getReportDefinition();
1216 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN"LeftMargin");
1217 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN"RightMargin");
1218 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE"Size").Width;
1219
1220 if ( aNewPos.X() < nLeftMargin )
1221 aNewPos.setX( nLeftMargin );
1222 if ( aNewPos.Y() < 0 )
1223 aNewPos.setY( 0 );
1224
1225 Point aPrevious;
1226 for (beans::NamedValue const & namedVal : std::as_const(aAllreadyCopiedObjects))
1227 {
1228 uno::Sequence< uno::Reference<report::XReportComponent> > aClones;
1229 namedVal.Value >>= aClones;
1230 uno::Reference<report::XReportComponent>* pColIter = aClones.getArray();
1231 const uno::Reference<report::XReportComponent>* pColEnd = pColIter + aClones.getLength();
1232
1233 // move the cloned Components to new positions
1234 for (; pColIter != pColEnd; ++pColIter)
1235 {
1236 uno::Reference< report::XReportComponent> xRC(*pColIter);
1237 aPrevious = VCLPoint(xRC->getPosition());
1238 awt::Size aSize = xRC->getSize();
1239
1240 if ( aNewPos.X() < nLeftMargin )
1241 {
1242 aNewPos.setX( nLeftMargin );
1243 }
1244 else if ( (aNewPos.X() + aSize.Width) > (nPaperWidth - nRightMargin) )
1245 {
1246 aNewPos.setX( nPaperWidth - nRightMargin - aSize.Width );
1247 }
1248 if ( aNewPos.Y() < 0 )
1249 {
1250 aNewPos.setY( 0 );
1251 }
1252 if ( aNewPos.X() < 0 )
1253 {
1254 aSize.Width += aNewPos.X();
1255 aNewPos.setX( 0 );
1256 xRC->setSize(aSize);
1257 }
1258 xRC->setPosition(AWTPoint(aNewPos));
1259 if ( (pColIter+1) != pColEnd )
1260 {
1261 // bring aNewPos to the position of the next object
1262 uno::Reference< report::XReportComponent> xRCNext = *(pColIter + 1);
1263 Point aNextPosition = VCLPoint(xRCNext->getPosition());
1264 aNewPos += aNextPosition - aPrevious;
1265 }
1266 }
1267 }
1268 }
1269 catch(uno::Exception&)
1270 {
1271 }
1272 pInSection->getReportSection()->Paste(aAllreadyCopiedObjects,true);
1273 }
1274 }
1275 else
1276 {
1277 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction() );
1278 EndDragObj_removeInvisibleObjects();
1279 }
1280 m_aDragDelta = Point(SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF), SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF));
1281}
1282
1283void OViewsWindow::EndAction()
1284{
1285 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eEndAction) );
1286}
1287
1288void OViewsWindow::MovAction(const Point& _aPnt,const OSectionView* _pSection, bool _bControlKeySet)
1289{
1290 Point aRealMousePos = _aPnt;
1291 Point aCurrentSectionPos;
1292 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y()) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aRealMousePos.X() << " Y:" <<
aRealMousePos.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1293 "reportdesign",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y()) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aRealMousePos.X() << " Y:" <<
aRealMousePos.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1294 "X:" << aRealMousePos.X() << " Y:" << aRealMousePos.Y())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "reportdesign")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y()) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "X:" << aRealMousePos.X() << " Y:" <<
aRealMousePos.Y()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "X:" << aRealMousePos.X() <<
" Y:" << aRealMousePos.Y()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "X:" << aRealMousePos
.X() << " Y:" << aRealMousePos.Y(); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("reportdesign"), ("/home/maarten/src/libreoffice/core/reportdesign/source/ui/report/ViewsWindow.cxx"
":" "1294" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1295
1296 Point aHdlPos;
1297 SdrHdl* pHdl = _pSection->GetDragHdl();
1298 if ( pHdl )
1299 {
1300 aHdlPos = pHdl->GetPos();
1301 }
1302
1303 for (const auto& rxSection : m_aSections)
1304 {
1305 OReportSection& rReportSection = rxSection->getReportSection();
1306 if ( &rReportSection.getSectionView() == _pSection )
1307 break;
1308 const long nSectionHeight = rxSection->PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1309 aCurrentSectionPos.AdjustY(nSectionHeight );
1310 }
1311 aRealMousePos += aCurrentSectionPos;
1312
1313 // If control key is pressed the work area is limited to the section with the current selection.
1314 Point aPosForWorkArea(0,0);
1315 for (const auto& rxSection : m_aSections)
1316 {
1317 OReportSection& rReportSection = rxSection->getReportSection();
1318 OSectionView& rView = rReportSection.getSectionView();
1319 const long nSectionHeight = rxSection->PixelToLogic(rxSection->GetOutputSizePixel()).Height();
1320
1321 if (_bControlKeySet)
1322 {
1323 tools::Rectangle aClipRect = rView.GetWorkArea();
1324 aClipRect.SetTop( aCurrentSectionPos.Y() - aPosForWorkArea.Y() );
1325 aClipRect.SetBottom( aClipRect.Top() + nSectionHeight );
1326 rView.SetWorkArea( aClipRect );
1327 }
1328 else
1329 {
1330 tools::Rectangle aClipRect = rView.GetWorkArea();
1331 aClipRect.SetTop( -aPosForWorkArea.Y() );
1332 rView.SetWorkArea( aClipRect );
1333 }
1334 aPosForWorkArea.AdjustY(nSectionHeight );
1335 }
1336
1337
1338 for (const auto& rxSection : m_aSections)
1339 {
1340 OReportSection& rReportSection = rxSection->getReportSection();
1341 SdrHdl* pCurrentHdl = rReportSection.getSectionView().GetDragHdl();
1342 if ( pCurrentHdl && aRealMousePos.Y() > 0 )
1343 aRealMousePos = _aPnt + pCurrentHdl->GetPos() - aHdlPos;
1344 rReportSection.getSectionView().MovAction ( aRealMousePos );
1345 const long nSectionHeight = rxSection->PixelToLogic(rxSection->GetOutputSizePixel()).Height();
1346 aRealMousePos.AdjustY( -nSectionHeight );
1347 }
1348}
1349
1350bool OViewsWindow::IsAction() const
1351{
1352 return std::any_of(m_aSections.begin(), m_aSections.end(),
1353 [](const VclPtr<OSectionWindow>& rxSection) { return rxSection->getReportSection().getSectionView().IsAction(); });
1354}
1355
1356bool OViewsWindow::IsDragObj() const
1357{
1358 return std::any_of(m_aSections.begin(), m_aSections.end(),
1359 [](const VclPtr<OSectionWindow>& rxSection) { return rxSection->getReportSection().getSectionView().IsAction(); });
1360}
1361
1362sal_uInt32 OViewsWindow::getMarkedObjectCount() const
1363{
1364 return std::accumulate(m_aSections.begin(), m_aSections.end(), sal_uInt32(0),
1365 [](const sal_uInt32 nCount, const VclPtr<OSectionWindow>& rxSection) {
1366 return nCount + static_cast<sal_uInt32>(rxSection->getReportSection().getSectionView().GetMarkedObjectCount()); });
1367}
1368
1369void OViewsWindow::handleKey(const vcl::KeyCode& _rCode)
1370{
1371 const sal_uInt16 nCode = _rCode.GetCode();
1372 if ( _rCode.IsMod1() )
1373 {
1374 // scroll page
1375 OScrollWindowHelper* pScrollWindow = getView()->getScrollWindow();
1376 ScrollBar& rScrollBar = ( nCode == KEY_LEFT || nCode == KEY_RIGHT ) ? pScrollWindow->GetHScroll() : pScrollWindow->GetVScroll();
1377 if ( rScrollBar.IsVisible() )
1378 rScrollBar.DoScrollAction(( nCode == KEY_RIGHT || nCode == KEY_UP ) ? ScrollType::LineUp : ScrollType::LineDown );
1379 return;
1380 }
1381
1382 for (const auto& rxSection : m_aSections)
1383 {
1384 OReportSection& rReportSection = rxSection->getReportSection();
1385 long nX = 0;
1386 long nY = 0;
1387
1388 if ( nCode == KEY_UP )
1389 nY = -1;
1390 else if ( nCode == KEY_DOWN )
1391 nY = 1;
1392 else if ( nCode == KEY_LEFT )
1393 nX = -1;
1394 else if ( nCode == KEY_RIGHT )
1395 nX = 1;
1396
1397 if ( rReportSection.getSectionView().AreObjectsMarked() )
1398 {
1399 if ( _rCode.IsMod2() )
1400 {
1401 // move in 1 pixel distance
1402 const Size aPixelSize = rReportSection.PixelToLogic( Size( 1, 1 ) );
1403 nX *= aPixelSize.Width();
1404 nY *= aPixelSize.Height();
1405 }
1406 else
1407 {
1408 // move in 1 mm distance
1409 nX *= DEFAUL_MOVE_SIZE100;
1410 nY *= DEFAUL_MOVE_SIZE100;
1411 }
1412
1413 OSectionView& rView = rReportSection.getSectionView();
1414 const SdrHdlList& rHdlList = rView.GetHdlList();
1415 SdrHdl* pHdl = rHdlList.GetFocusHdl();
1416
1417 if ( pHdl == nullptr )
1418 {
1419 // no handle selected
1420 if ( rView.IsMoveAllowed() )
1421 {
1422 // restrict movement to work area
1423 tools::Rectangle rWorkArea = rView.GetWorkArea();
1424 rWorkArea.AdjustRight( 1 );
1425
1426 if ( !rWorkArea.IsEmpty() )
1427 {
1428 if ( rWorkArea.Top() < 0 )
1429 rWorkArea.SetTop( 0 );
1430 tools::Rectangle aMarkRect( rView.GetMarkedObjRect() );
1431 aMarkRect.Move( nX, nY );
1432
1433 if ( !rWorkArea.IsInside( aMarkRect ) )
1434 {
1435 if ( aMarkRect.Left() < rWorkArea.Left() )
1436 nX += rWorkArea.Left() - aMarkRect.Left();
1437
1438 if ( aMarkRect.Right() > rWorkArea.Right() )
1439 nX -= aMarkRect.Right() - rWorkArea.Right();
1440
1441 if ( aMarkRect.Top() < rWorkArea.Top() )
1442 nY += rWorkArea.Top() - aMarkRect.Top();
1443
1444 if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
1445 nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
1446 }
1447 bool bCheck = false;
1448 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1449 for (size_t i = 0; !bCheck && i < rMarkList.GetMarkCount(); ++i )
1450 {
1451 SdrMark* pMark = rMarkList.GetMark(i);
1452 bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != nullptr|| dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
1453 }
1454
1455
1456 if ( bCheck )
1457 {
1458 SdrObject* pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1459 if ( pOverlapped )
1460 {
1461 do
1462 {
1463 tools::Rectangle aOver = pOverlapped->GetLastBoundRect();
1464 Point aPos;
1465 if ( nCode == KEY_UP )
1466 {
1467 aPos.setX( aMarkRect.Left() );
1468 aPos.setY( aOver.Top() - aMarkRect.getHeight() );
1469 nY += (aPos.Y() - aMarkRect.Top());
1470 }
1471 else if ( nCode == KEY_DOWN )
1472 {
1473 aPos.setX( aMarkRect.Left() );
1474 aPos.setY( aOver.Bottom() );
1475 nY += (aPos.Y() - aMarkRect.Top());
1476 }
1477 else if ( nCode == KEY_LEFT )
1478 {
1479 aPos.setX( aOver.Left() - aMarkRect.getWidth() );
1480 aPos.setY( aMarkRect.Top() );
1481 nX += (aPos.X() - aMarkRect.Left());
1482 }
1483 else if ( nCode == KEY_RIGHT )
1484 {
1485 aPos.setX( aOver.Right() );
1486 aPos.setY( aMarkRect.Top() );
1487 nX += (aPos.X() - aMarkRect.Left());
1488 }
1489
1490 aMarkRect.SetPos(aPos);
1491 if ( !rWorkArea.IsInside( aMarkRect ) )
1492 {
1493 break;
1494 }
1495 pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1496 }
1497 while(pOverlapped != nullptr);
1498 if (pOverlapped != nullptr)
1499 break;
1500 }
1501 }
1502 }
1503
1504 if ( nX != 0 || nY != 0 )
1505 {
1506 rView.MoveAllMarked( Size( nX, nY ) );
1507 rView.MakeVisible( rView.GetAllMarkedRect(), rReportSection);
1508 }
1509 }
1510 }
1511 else // pHdl != nullptr
1512 {
1513 // move the handle
1514 if (nX || nY)
1515 {
1516 const Point aStartPoint( pHdl->GetPos() );
1517 const Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
1518 const SdrDragStat& rDragStat = rView.GetDragStat();
1519
1520 // start dragging
1521 rView.BegDragObj( aStartPoint, nullptr, pHdl, 0 );
1522
1523 if ( rView.IsDragObj() )
1524 {
1525 const bool bWasNoSnap = rDragStat.IsNoSnap();
1526 const bool bWasSnapEnabled = rView.IsSnapEnabled();
1527
1528 // switch snapping off
1529 if ( !bWasNoSnap )
1530 const_cast<SdrDragStat&>(rDragStat).SetNoSnap();
1531 if ( bWasSnapEnabled )
1532 rView.SetSnapEnabled( false );
1533
1534 tools::Rectangle aNewRect;
1535 bool bCheck = false;
1536 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1537 for (size_t i = 0; !bCheck && i < rMarkList.GetMarkCount(); ++i )
1538 {
1539 SdrMark* pMark = rMarkList.GetMark(i);
1540 bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != nullptr || dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj()) != nullptr;
1541 if ( bCheck )
1542 aNewRect.Union(pMark->GetMarkedSdrObj()->GetLastBoundRect());
1543 }
1544
1545 switch(pHdl->GetKind())
1546 {
1547 case SdrHdlKind::Left:
1548 case SdrHdlKind::UpperLeft:
1549 case SdrHdlKind::LowerLeft:
1550 case SdrHdlKind::Upper:
1551 aNewRect.AdjustLeft(nX );
1552 aNewRect.AdjustTop(nY );
1553 break;
1554 case SdrHdlKind::UpperRight:
1555 case SdrHdlKind::Right:
1556 case SdrHdlKind::LowerRight:
1557 case SdrHdlKind::Lower:
1558 aNewRect.setWidth(aNewRect.getWidth() + nX);
1559 aNewRect.setHeight(aNewRect.getHeight() + nY);
1560 break;
1561 default:
1562 break;
1563 }
1564 if ( !(bCheck && isOver(aNewRect,*rReportSection.getPage(),rView)) )
1565 rView.MovAction(aEndPoint);
1566 rView.EndDragObj();
1567
1568 // restore snap
1569 if ( !bWasNoSnap )
1570 const_cast<SdrDragStat&>(rDragStat).SetNoSnap( bWasNoSnap );
1571 if ( bWasSnapEnabled )
1572 rView.SetSnapEnabled( bWasSnapEnabled );
1573 }
1574
1575 // make moved handle visible
1576 const tools::Rectangle aVisRect( aEndPoint - Point( DEFAUL_MOVE_SIZE100, DEFAUL_MOVE_SIZE100 ), Size( 200, 200 ) );
1577 rView.MakeVisible( aVisRect, rReportSection);
1578 }
1579 }
1580 rView.AdjustMarkHdl();
1581 }
1582 }
1583}
1584
1585void OViewsWindow::stopScrollTimer()
1586{
1587 ::std::for_each(m_aSections.begin(),m_aSections.end(),
1588 [] (const TSectionsMap::value_type& sectionPtr) {
1589 sectionPtr->getReportSection().stopScrollTimer();
1590 });
1591}
1592
1593void OViewsWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
1594{
1595 sal_uInt16 i = 0;
1596 for (const auto& rxSection : m_aSections)
1597 {
1598 if ( rxSection->getStartMarker().isCollapsed() )
1599 _rCollapsedPositions.push_back(i);
1600 ++i;
1601 }
1602}
1603
1604void OViewsWindow::collapseSections(const uno::Sequence< beans::PropertyValue>& _aCollapsedSections)
1605{
1606 for (const beans::PropertyValue& rSection : _aCollapsedSections)
1607 {
1608 sal_uInt16 nPos = sal_uInt16(-1);
1609 if ( (rSection.Value >>= nPos) && nPos < m_aSections.size() )
1610 {
1611 m_aSections[nPos]->setCollapsed(true);
1612 }
1613 }
1614}
1615
1616void OViewsWindow::zoom(const Fraction& _aZoom)
1617{
1618 const MapMode& aMapMode = GetMapMode();
1619
1620 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH120));
1621 if ( _aZoom < aMapMode.GetScaleX() )
1622 aStartWidth *= aMapMode.GetScaleX();
1623 else
1624 aStartWidth *= _aZoom;
1625
1626 setZoomFactor(_aZoom,*this);
1627
1628 for (const auto& rxSection : m_aSections)
1629 {
1630 rxSection->zoom(_aZoom);
1631 }
1632
1633 Resize();
1634
1635 Size aOut = GetOutputSizePixel();
1636 aOut.setWidth( long(aStartWidth) );
1637 aOut = PixelToLogic(aOut);
1638
1639 tools::Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
1640 Invalidate(aRect, InvalidateFlags::NoChildren);
1641}
1642
1643void OViewsWindow::scrollChildren(const Point& _aThumbPos)
1644{
1645 const Point aPos(PixelToLogic(_aThumbPos));
1646 {
1647 MapMode aMapMode = GetMapMode();
1648 const Point aOld = aMapMode.GetOrigin();
1649 aMapMode.SetOrigin(m_pParent->GetMapMode().GetOrigin());
1650
1651 const Point aPosY(m_pParent->PixelToLogic(_aThumbPos,aMapMode));
1652
1653 aMapMode.SetOrigin( Point(aOld.X() , - aPosY.Y()));
1654 SetMapMode( aMapMode );
1655 Scroll(0, -( aOld.Y() + aPosY.Y()),ScrollFlags::Children);
1656 }
1657
1658 for (const auto& rxSection : m_aSections)
1659 {
1660 rxSection->scrollChildren(aPos.X());
1661 }
1662}
1663
1664void OViewsWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
1665{
1666 for (const auto& rxSection : m_aSections)
1667 {
1668 rxSection->getReportSection().fillControlModelSelection(_rSelection);
1669 }
1670}
1671
1672} // rptui
1673
1674
1675/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
2
Calling copy constructor for 'Reference<rptui::OSectionWindow>'
5
Returning from copy constructor for 'Reference<rptui::OSectionWindow>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
6
Calling 'Reference::clear'
13
Returning; memory was released
205 if (aTmp.get()) {
14
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
3
Assuming field 'm_pBody' is non-null
4
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
)
7
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
8
Calling 'VclReferenceBase::release'
12
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
15
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
9
Assuming the condition is true
10
Taking true branch
40 delete this;
11
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif