1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <ReportWindow.hxx>
20 #include <ReportSection.hxx>
21 #include <SectionView.hxx>
22 #include <ViewsWindow.hxx>
23 #include <DesignView.hxx>
24 #include <UITools.hxx>
26 #include <svtools/colorcfg.hxx>
27 #include <svl/itempool.hxx>
28 #include <unotools/syslocale.hxx>
29 #include <unotools/localedatawrapper.hxx>
31 #include <vcl/settings.hxx>
34 #include <dlgedfunc.hxx>
35 #include <RptModel.hxx>
36 #include <strings.hxx>
37 #include <RptPage.hxx>
38 #include <ReportController.hxx>
39 #include <EndMarker.hxx>
40 #include <ColorChanger.hxx>
41 #include <ScrollHelper.hxx>
44 #include <dlgedfac.hxx>
47 #define SECTION_OFFSET 3
50 using namespace ::com::sun::star
;
51 using namespace ::comphelper
;
53 // class OReportWindow
56 OReportWindow::OReportWindow(OScrollWindowHelper
* _pParent
,ODesignView
* _pView
)
57 : Window(_pParent
,WB_DIALOGCONTROL
)
58 , ::comphelper::OPropertyChangeListener(m_aMutex
)
59 ,m_aHRuler(VclPtr
<Ruler
>::Create(this))
62 ,m_aViewsWindow(VclPtr
<rptui::OViewsWindow
>::Create(this))
63 ,m_pObjFac( new DlgEdFactory() )
65 SetHelpId(UID_RPT_REPORTWINDOW
);
66 SetMapMode( MapMode( MapUnit::Map100thMM
) );
68 m_aViewsWindow
->Show();
71 m_aHRuler
->Activate();
72 m_aHRuler
->SetPagePos();
73 m_aHRuler
->SetBorders();
74 m_aHRuler
->SetIndents();
75 m_aHRuler
->SetMargin1();
76 m_aHRuler
->SetMargin2();
77 const MeasurementSystem eSystem
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
78 m_aHRuler
->SetUnit(MeasurementSystem::Metric
== eSystem
? FieldUnit::CM
: FieldUnit::INCH
);
81 m_pReportListener
= addStyleListener(_pView
->getController().getReportDefinition(),this);
84 OReportWindow::~OReportWindow()
89 void OReportWindow::dispose()
91 if ( m_pReportListener
.is() )
92 m_pReportListener
->dispose();
93 m_aHRuler
.disposeAndClear();
94 m_aViewsWindow
.disposeAndClear();
97 vcl::Window::dispose();
100 void OReportWindow::SetInsertObj( sal_uInt16 eObj
,const OUString
& _sShapeType
)
102 m_aViewsWindow
->SetInsertObj( eObj
,_sShapeType
);
105 OUString
const & OReportWindow::GetInsertObjString() const
107 return m_aViewsWindow
->GetInsertObjString();
110 void OReportWindow::SetMode( DlgEdMode eNewMode
)
112 m_aViewsWindow
->SetMode(eNewMode
);
115 void OReportWindow::removeSection(sal_uInt16 _nPosition
)
117 m_aViewsWindow
->removeSection(_nPosition
);
118 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
119 m_aViewsWindow
->Invalidate(InvalidateFlags::Transparent
);
122 void OReportWindow::addSection(const uno::Reference
< report::XSection
>& _xSection
,const OUString
& _sColorEntry
,sal_uInt16 _nPosition
)
124 if ( !_xSection
.is() )
127 m_aViewsWindow
->addSection(_xSection
,_sColorEntry
,_nPosition
);
129 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
132 void OReportWindow::toggleGrid(bool _bVisible
)
134 m_aViewsWindow
->toggleGrid(_bVisible
);
137 void OReportWindow::showRuler(bool _bShow
)
139 m_aHRuler
->Show(_bShow
);
141 m_aViewsWindow
->showRuler(_bShow
);
144 sal_Int32
OReportWindow::getMaxMarkerWidth() const
146 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
));
147 aStartWidth
*= m_aViewsWindow
->GetMapMode().GetScaleX();
148 return sal_Int32(static_cast<long>(aStartWidth
));
151 sal_Int32
OReportWindow::GetTotalWidth() const
153 sal_Int32 nWidth
= 0;
154 if ( !m_aViewsWindow
->empty() )
156 Fraction
aStartWidth(long(REPORT_ENDMARKER_WIDTH
+ REPORT_STARTMARKER_WIDTH
));
157 const Fraction
aZoom(m_pView
->getController().getZoomValue(),100);
158 aStartWidth
*= aZoom
;
159 sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(m_pView
->getController().getReportDefinition(),PROPERTY_PAPERSIZE
).Width
;
160 nPaperWidth
= long(nPaperWidth
* aZoom
);
161 const Size aPageSize
= LogicToPixel(Size(nPaperWidth
,0));
162 nWidth
= aPageSize
.Width() + long(aStartWidth
);
167 void OReportWindow::Resize()
170 if ( !m_aViewsWindow
->empty() )
172 const Size aTotalOutputSize
= GetOutputSizePixel();
173 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
)*m_pView
->getController().getZoomValue(),100);
175 const Point aOffset
= LogicToPixel(Point(SECTION_OFFSET
, 0), MapMode(MapUnit::MapAppFont
));
176 Point
aStartPoint(static_cast<long>(aStartWidth
) + aOffset
.X(),0);
177 uno::Reference
<report::XReportDefinition
> xReportDefinition
= getReportView()->getController().getReportDefinition();
178 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(xReportDefinition
,PROPERTY_PAPERSIZE
).Width
;
179 sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
180 sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
181 Size aPageSize
= m_aViewsWindow
->LogicToPixel(Size(nPaperWidth
,0));
182 nLeftMargin
= m_aViewsWindow
->LogicToPixel(Size(nLeftMargin
,0)).Width();
183 nRightMargin
= m_aViewsWindow
->LogicToPixel(Size(nRightMargin
,0)).Width();
185 aPageSize
.setHeight( m_aHRuler
->GetSizePixel().Height() );
187 const long nTermp(m_aViewsWindow
->getTotalHeight() + aPageSize
.Height());
188 long nSectionsHeight
= ::std::max
<long>(nTermp
,aTotalOutputSize
.Height());
190 m_aHRuler
->SetPosSizePixel(aStartPoint
,aPageSize
);
191 m_aHRuler
->SetNullOffset(nLeftMargin
);
192 m_aHRuler
->SetMargin1(0);
193 m_aHRuler
->SetMargin2(aPageSize
.Width() - nLeftMargin
- nRightMargin
);
195 aStartPoint
.AdjustY(aPageSize
.Height() );
196 nSectionsHeight
-= aStartPoint
.Y();
198 aStartPoint
.setX( aOffset
.X() );
200 m_aViewsWindow
->SetPosSizePixel(aStartPoint
,Size(aTotalOutputSize
.Width(),nSectionsHeight
));
204 Point
OReportWindow::getThumbPos() const
206 return m_pParent
->getThumbPos();
209 void OReportWindow::ImplInitSettings()
214 void OReportWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
216 Window::DataChanged( rDCEvt
);
218 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
219 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
226 sal_Int32
OReportWindow::GetTotalHeight() const
228 return m_aViewsWindow
->getTotalHeight();
231 void OReportWindow::ScrollChildren(const Point
& _aThumbPos
)
233 MapMode aMap
= m_aHRuler
->GetMapMode();
234 Point
aOrg( aMap
.GetOrigin() );
235 if ( aOrg
.X() != (-_aThumbPos
.X()) )
237 aMap
.SetOrigin( Point(- _aThumbPos
.X(), aOrg
.Y()));
238 m_aHRuler
->SetMapMode( aMap
);
239 m_aHRuler
->Scroll(-(aOrg
.X() + _aThumbPos
.X()),0);
242 m_aViewsWindow
->scrollChildren(_aThumbPos
);
245 sal_uInt16
OReportWindow::getSectionCount() const
247 return m_aViewsWindow
->getSectionCount();
250 void OReportWindow::notifySizeChanged()
252 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
255 bool OReportWindow::HasSelection() const
257 return m_aViewsWindow
->HasSelection();
260 void OReportWindow::Delete()
263 m_aViewsWindow
->Delete();
266 void OReportWindow::Copy()
269 m_aViewsWindow
->Copy();
272 void OReportWindow::Paste()
275 m_aViewsWindow
->Paste();
278 bool OReportWindow::IsPasteAllowed() const
280 return m_aViewsWindow
->IsPasteAllowed();
283 void OReportWindow::SelectAll(const sal_uInt16 _nObjectType
)
286 m_aViewsWindow
->SelectAll(_nObjectType
);
289 void OReportWindow::unmarkAllObjects()
292 m_aViewsWindow
->unmarkAllObjects(nullptr);
295 void OReportWindow::showProperties(const uno::Reference
< report::XSection
>& _xReportComponent
)
297 OSectionWindow
* pSectionWindow
= m_aViewsWindow
->getSectionWindow( _xReportComponent
);
298 m_pView
->UpdatePropertyBrowserDelayed(pSectionWindow
->getReportSection().getSectionView());
301 bool OReportWindow::handleKeyEvent(const KeyEvent
& _rEvent
)
303 return m_aViewsWindow
->handleKeyEvent(_rEvent
);
306 void OReportWindow::setMarked(OSectionView
const * _pSectionView
, bool _bMark
)
309 m_aViewsWindow
->setMarked(_pSectionView
,_bMark
);
312 void OReportWindow::setMarked(const uno::Reference
< report::XSection
>& _xSection
, bool _bMark
)
315 m_aViewsWindow
->setMarked(_xSection
,_bMark
);
318 void OReportWindow::setMarked(const uno::Sequence
< uno::Reference
< report::XReportComponent
> >& _xShape
, bool _bMark
)
321 m_aViewsWindow
->setMarked(_xShape
,_bMark
);
324 OSectionWindow
* OReportWindow::getMarkedSection(NearSectionAccess nsa
) const
326 return m_aViewsWindow
->getMarkedSection(nsa
);
329 OSectionWindow
* OReportWindow::getSectionWindow(const css::uno::Reference
< css::report::XSection
>& _xSection
) const
331 return m_aViewsWindow
->getSectionWindow(_xSection
);
334 void OReportWindow::markSection(const sal_uInt16 _nPos
)
337 m_aViewsWindow
->markSection(_nPos
);
340 void OReportWindow::fillCollapsedSections(::std::vector
<sal_uInt16
>& _rCollapsedPositions
) const
343 m_aViewsWindow
->fillCollapsedSections(_rCollapsedPositions
);
346 void OReportWindow::collapseSections(const uno::Sequence
< css::beans::PropertyValue
>& _aCollpasedSections
)
349 m_aViewsWindow
->collapseSections(_aCollpasedSections
);
352 void OReportWindow::alignMarkedObjects(ControlModification _nControlModification
, bool _bAlignAtSection
)
354 m_aViewsWindow
->alignMarkedObjects(_nControlModification
, _bAlignAtSection
);
357 void OReportWindow::setGridSnap(bool bOn
)
360 m_aViewsWindow
->setGridSnap(bOn
);
363 void OReportWindow::setDragStripes(bool bOn
)
365 m_aViewsWindow
->setDragStripes(bOn
);
368 sal_uInt32
OReportWindow::getMarkedObjectCount() const
370 return m_aViewsWindow
->getMarkedObjectCount();
373 void OReportWindow::zoom(const Fraction
& _aZoom
)
375 m_aHRuler
->SetZoom(_aZoom
);
376 m_aHRuler
->Invalidate();
378 m_aViewsWindow
->zoom(_aZoom
);
381 const Point
aNewThumbPos( m_pParent
->getThumbPos() );
383 ScrollChildren( aNewThumbPos
);
386 Invalidate(InvalidateFlags::NoErase
| InvalidateFlags::NoChildren
| InvalidateFlags::Transparent
);
389 void OReportWindow::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
391 m_aViewsWindow
->fillControlModelSelection(_rSelection
);
394 sal_Int32
OReportWindow::impl_getRealPixelWidth() const
396 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(m_pView
->getController().getReportDefinition(),PROPERTY_PAPERSIZE
).Width
;
397 MapMode
aMap( MapUnit::Map100thMM
);
398 const Size aPageSize
= LogicToPixel(Size(nPaperWidth
,0),aMap
);
399 return aPageSize
.Width() + REPORT_ENDMARKER_WIDTH
+ REPORT_STARTMARKER_WIDTH
+ SECTION_OFFSET
;
402 sal_uInt16
OReportWindow::getZoomFactor(SvxZoomType _eType
) const
404 sal_uInt16
nZoom(100);
405 const Size
aSize( GetSizePixel() );
408 case SvxZoomType::PERCENT
:
409 nZoom
= m_pView
->getController().getZoomValue();
411 case SvxZoomType::OPTIMAL
:
413 case SvxZoomType::WHOLEPAGE
:
415 nZoom
= static_cast<sal_uInt16
>(static_cast<long>(Fraction(aSize
.Width()*100,impl_getRealPixelWidth())));
416 MapMode
aMap( MapUnit::Map100thMM
);
417 const Size aHeight
= m_aViewsWindow
->LogicToPixel(m_aViewsWindow
->PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler
->GetSizePixel().Height())),aMap
);
418 nZoom
= ::std::min(nZoom
,static_cast<sal_uInt16
>(static_cast<long>(Fraction(aSize
.Height()*100,aHeight
.Height()))));
421 case SvxZoomType::PAGEWIDTH
:
422 nZoom
= static_cast<sal_uInt16
>(static_cast<long>(Fraction(aSize
.Width()*100,impl_getRealPixelWidth())));
431 void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent
&)
434 m_aViewsWindow
->Resize();
435 Invalidate(InvalidateFlags::Transparent
);
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */