Get the style color and number just once
[LibreOffice.git] / reportdesign / source / ui / report / ReportWindow.cxx
blob91813270915f95b7d8103a74226f2f3f4d4f7f04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <unotools/syslocale.hxx>
27 #include <unotools/localedatawrapper.hxx>
29 #include <vcl/settings.hxx>
31 #include <RptDef.hxx>
32 #include <strings.hxx>
33 #include <ReportController.hxx>
34 #include <ScrollHelper.hxx>
36 #include <helpids.h>
37 #include <dlgedfac.hxx>
40 #define SECTION_OFFSET 3
41 namespace rptui
43 using namespace ::com::sun::star;
44 using namespace ::comphelper;
48 OReportWindow::OReportWindow(OScrollWindowHelper* _pParent,ODesignView* _pView)
49 : Window(_pParent,WB_DIALOGCONTROL)
50 , ::comphelper::OPropertyChangeListener()
51 ,m_aHRuler(VclPtr<Ruler>::Create(this))
52 ,m_pView(_pView)
53 ,m_pParent(_pParent)
54 ,m_aViewsWindow(VclPtr<rptui::OViewsWindow>::Create(this))
55 ,m_pObjFac( new DlgEdFactory() )
57 SetHelpId(UID_RPT_REPORTWINDOW);
58 SetMapMode( MapMode( MapUnit::Map100thMM ) );
60 m_aViewsWindow->Show();
62 m_aHRuler->Show();
63 m_aHRuler->Activate();
64 m_aHRuler->SetPagePos();
65 m_aHRuler->SetBorders();
66 m_aHRuler->SetIndents();
67 m_aHRuler->SetMargin1();
68 m_aHRuler->SetMargin2();
69 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
70 m_aHRuler->SetUnit(MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH);
72 ImplInitSettings();
73 m_pReportListener = addStyleListener(_pView->getController().getReportDefinition(),this);
76 OReportWindow::~OReportWindow()
78 disposeOnce();
81 void OReportWindow::dispose()
83 if ( m_pReportListener.is() )
84 m_pReportListener->dispose();
85 m_aHRuler.disposeAndClear();
86 m_aViewsWindow.disposeAndClear();
87 m_pView.clear();
88 m_pParent.clear();
89 vcl::Window::dispose();
92 void OReportWindow::SetInsertObj( SdrObjKind eObj,const OUString& _sShapeType )
94 m_aViewsWindow->SetInsertObj( eObj,_sShapeType);
97 OUString const & OReportWindow::GetInsertObjString() const
99 return m_aViewsWindow->GetInsertObjString();
102 void OReportWindow::SetMode( DlgEdMode eNewMode )
104 m_aViewsWindow->SetMode(eNewMode);
107 void OReportWindow::removeSection(sal_uInt16 _nPosition)
109 m_aViewsWindow->removeSection(_nPosition);
110 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
111 m_aViewsWindow->Invalidate(InvalidateFlags::Transparent);
114 void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry,sal_uInt16 _nPosition)
116 if ( !_xSection.is() )
117 return;
119 m_aViewsWindow->addSection(_xSection,_sColorEntry,_nPosition);
121 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
124 void OReportWindow::toggleGrid(bool _bVisible)
126 m_aViewsWindow->toggleGrid(_bVisible);
129 void OReportWindow::showRuler(bool _bShow)
131 m_aHRuler->Show(_bShow);
133 m_aViewsWindow->showRuler(_bShow);
136 sal_Int32 OReportWindow::getMaxMarkerWidth() const
138 Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH));
139 aStartWidth *= m_aViewsWindow->GetMapMode().GetScaleX();
140 return sal_Int32(static_cast<tools::Long>(aStartWidth));
143 sal_Int32 OReportWindow::GetTotalWidth() const
145 sal_Int32 nWidth = 0;
146 if ( !m_aViewsWindow->empty() )
148 Fraction aStartWidth(tools::Long(REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH ));
149 const Fraction aZoom(m_pView->getController().getZoomValue(),100);
150 aStartWidth *= aZoom;
151 sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
152 nPaperWidth = tools::Long(nPaperWidth * aZoom);
153 const Size aPageSize = LogicToPixel(Size(nPaperWidth,0));
154 nWidth = aPageSize.Width() + tools::Long(aStartWidth);
156 return nWidth;
159 void OReportWindow::Resize()
161 Window::Resize();
162 if ( m_aViewsWindow->empty() )
163 return;
165 const Size aTotalOutputSize = GetOutputSizePixel();
166 Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
168 const Point aOffset = LogicToPixel(Point(SECTION_OFFSET, 0), MapMode(MapUnit::MapAppFont));
169 Point aStartPoint(static_cast<tools::Long>(aStartWidth) + aOffset.X(),0);
170 uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
171 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
172 sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
173 sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
174 Size aPageSize = m_aViewsWindow->LogicToPixel(Size(nPaperWidth ,0));
175 nLeftMargin = m_aViewsWindow->LogicToPixel(Size(nLeftMargin,0)).Width();
176 nRightMargin = m_aViewsWindow->LogicToPixel(Size(nRightMargin,0)).Width();
178 aPageSize.setHeight( m_aHRuler->GetSizePixel().Height() );
180 const tools::Long nTermp(m_aViewsWindow->getTotalHeight() + aPageSize.Height());
181 tools::Long nSectionsHeight = ::std::max<tools::Long>(nTermp,aTotalOutputSize.Height());
183 m_aHRuler->SetPosSizePixel(aStartPoint,aPageSize);
184 m_aHRuler->SetNullOffset(nLeftMargin);
185 m_aHRuler->SetMargin1(0);
186 m_aHRuler->SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
188 aStartPoint.AdjustY(aPageSize.Height() );
189 nSectionsHeight -= aStartPoint.Y();
191 aStartPoint.setX( aOffset.X() );
193 m_aViewsWindow->SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
196 Point OReportWindow::getThumbPos() const
198 return m_pParent->getThumbPos();
201 void OReportWindow::ImplInitSettings()
203 SetBackground( );
206 void OReportWindow::DataChanged( const DataChangedEvent& rDCEvt )
208 Window::DataChanged( rDCEvt );
210 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
211 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
213 ImplInitSettings();
214 Invalidate();
218 sal_Int32 OReportWindow::GetTotalHeight() const
220 return m_aViewsWindow->getTotalHeight();
223 void OReportWindow::ScrollChildren(const Point& _aThumbPos)
225 MapMode aMap = m_aHRuler->GetMapMode();
226 Point aOrg( aMap.GetOrigin() );
227 if ( aOrg.X() != (-_aThumbPos.X()) )
229 aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
230 m_aHRuler->SetMapMode( aMap );
231 m_aHRuler->Scroll(-(aOrg.X() + _aThumbPos.X()),0);
234 m_aViewsWindow->scrollChildren(_aThumbPos);
237 sal_uInt16 OReportWindow::getSectionCount() const
239 return m_aViewsWindow->getSectionCount();
242 void OReportWindow::notifySizeChanged()
244 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
247 bool OReportWindow::HasSelection() const
249 return m_aViewsWindow->HasSelection();
252 void OReportWindow::Delete()
255 m_aViewsWindow->Delete();
258 void OReportWindow::Copy()
261 m_aViewsWindow->Copy();
264 void OReportWindow::Paste()
267 m_aViewsWindow->Paste();
270 bool OReportWindow::IsPasteAllowed() const
272 return m_aViewsWindow->IsPasteAllowed();
275 void OReportWindow::SelectAll(const SdrObjKind _nObjectType)
278 m_aViewsWindow->SelectAll(_nObjectType);
281 void OReportWindow::unmarkAllObjects()
284 m_aViewsWindow->unmarkAllObjects(nullptr);
287 void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
289 OSectionWindow* pSectionWindow = m_aViewsWindow->getSectionWindow( _xReportComponent );
290 m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
293 bool OReportWindow::handleKeyEvent(const KeyEvent& _rEvent)
295 return m_aViewsWindow->handleKeyEvent(_rEvent);
298 void OReportWindow::setMarked(OSectionView const * _pSectionView, bool _bMark)
300 if ( _pSectionView )
301 m_aViewsWindow->setMarked(_pSectionView,_bMark);
304 void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
307 m_aViewsWindow->setMarked(_xSection,_bMark);
310 void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
313 m_aViewsWindow->setMarked(_xShape,_bMark);
316 OSectionWindow* OReportWindow::getMarkedSection(NearSectionAccess nsa) const
318 return m_aViewsWindow->getMarkedSection(nsa);
321 OSectionWindow* OReportWindow::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
323 return m_aViewsWindow->getSectionWindow(_xSection);
326 void OReportWindow::markSection(const sal_uInt16 _nPos)
329 m_aViewsWindow->markSection(_nPos);
332 void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
335 m_aViewsWindow->fillCollapsedSections(_rCollapsedPositions);
338 void OReportWindow::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollapsedSections)
341 m_aViewsWindow->collapseSections(_aCollapsedSections);
344 void OReportWindow::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
346 m_aViewsWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
349 void OReportWindow::setGridSnap(bool bOn)
352 m_aViewsWindow->setGridSnap(bOn);
355 void OReportWindow::setDragStripes(bool bOn)
357 m_aViewsWindow->setDragStripes(bOn);
360 sal_uInt32 OReportWindow::getMarkedObjectCount() const
362 return m_aViewsWindow->getMarkedObjectCount();
365 void OReportWindow::zoom(const Fraction& _aZoom)
367 m_aHRuler->SetZoom(_aZoom);
368 m_aHRuler->Invalidate();
370 m_aViewsWindow->zoom(_aZoom);
372 notifySizeChanged();
373 const Point aNewThumbPos( m_pParent->getThumbPos() );
375 ScrollChildren( aNewThumbPos );
376 Resize();
378 Invalidate(InvalidateFlags::NoErase | InvalidateFlags::NoChildren | InvalidateFlags::Transparent);
381 void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
383 m_aViewsWindow->fillControlModelSelection(_rSelection);
386 sal_Int32 OReportWindow::impl_getRealPixelWidth() const
388 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
389 MapMode aMap( MapUnit::Map100thMM );
390 const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
391 return aPageSize.Width() + REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH + SECTION_OFFSET;
394 sal_uInt16 OReportWindow::getZoomFactor(SvxZoomType _eType) const
396 sal_uInt16 nZoom(100);
397 const Size aSize( GetSizePixel() );
398 switch( _eType)
400 case SvxZoomType::PERCENT:
401 nZoom = m_pView->getController().getZoomValue();
402 break;
403 case SvxZoomType::OPTIMAL:
404 break;
405 case SvxZoomType::WHOLEPAGE:
407 nZoom = static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Width()*100,impl_getRealPixelWidth())));
408 MapMode aMap( MapUnit::Map100thMM );
409 const Size aHeight = m_aViewsWindow->LogicToPixel(m_aViewsWindow->PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler->GetSizePixel().Height())),aMap);
410 nZoom = ::std::min(nZoom,static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Height()*100,aHeight.Height()))));
412 break;
413 case SvxZoomType::PAGEWIDTH:
414 nZoom = static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Width()*100,impl_getRealPixelWidth())));
415 break;
416 default:
417 break;
420 return nZoom;
423 void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent&)
425 Resize();
426 m_aViewsWindow->Resize();
427 Invalidate(InvalidateFlags::Transparent);
430 } //rptui
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */