Use o3tl::convert in Math
[LibreOffice.git] / reportdesign / source / ui / report / SectionWindow.cxx
blob60d5235f84bbb602c71bf20bf7f66c8064040e44
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 <SectionWindow.hxx>
20 #include <ReportWindow.hxx>
21 #include <UITools.hxx>
22 #include <ReportController.hxx>
23 #include <ReportSection.hxx>
24 #include <DesignView.hxx>
25 #include <strings.hxx>
26 #include <core_resource.hxx>
27 #include <strings.hrc>
28 #include <StartMarker.hxx>
29 #include <EndMarker.hxx>
30 #include <ViewsWindow.hxx>
32 #include <functional>
33 #include <algorithm>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
37 namespace rptui
39 using namespace ::com::sun::star;
40 using namespace ::comphelper;
42 OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry)
43 : Window( _pParent,WB_DIALOGCONTROL)
44 ,OPropertyChangeListener(m_aMutex)
45 ,m_pParent(_pParent)
46 ,m_aStartMarker( VclPtr<rptui::OStartMarker>::Create(this,_sColorEntry))
47 ,m_aReportSection( VclPtr<rptui::OReportSection>::Create(this,_xSection))
48 ,m_aSplitter(VclPtr<Splitter>::Create(this))
49 ,m_aEndMarker( VclPtr<rptui::OEndMarker>::Create(this,_sColorEntry))
51 const MapMode& rMapMode = _pParent->GetMapMode();
52 SetMapMode( rMapMode );
53 ImplInitSettings();
54 // TRY
55 m_aSplitter->SetMapMode( MapMode( MapUnit::Map100thMM ) );
56 m_aSplitter->SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
57 m_aSplitter->SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
58 m_aSplitter->SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
59 m_aSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
60 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,_xSection->getHeight())).Height());
63 m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
65 m_aStartMarker->zoom(rMapMode.GetScaleX());
66 setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection);
67 setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter);
68 setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker);
70 m_aSplitter->Show();
71 m_aStartMarker->Show();
72 m_aReportSection->Show();
73 m_aEndMarker->Show();
74 Show();
76 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection);
77 m_pSectionMulti->addProperty(PROPERTY_NAME);
78 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
80 beans::PropertyChangeEvent aEvent;
81 aEvent.Source = _xSection;
82 aEvent.PropertyName = PROPERTY_NAME;
83 uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
84 if ( xGroup.is() )
86 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup);
87 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
88 aEvent.Source = xGroup;
89 aEvent.PropertyName = PROPERTY_EXPRESSION;
92 _propertyChanged(aEvent);
95 OSectionWindow::~OSectionWindow()
97 disposeOnce();
100 void OSectionWindow::dispose()
104 if ( m_pSectionMulti.is() )
105 m_pSectionMulti->dispose();
106 m_pSectionMulti.clear();
107 if ( m_pGroupMulti.is() )
108 m_pGroupMulti->dispose();
109 m_pGroupMulti.clear();
111 catch (uno::Exception&)
114 m_aStartMarker.disposeAndClear();
115 m_aReportSection.disposeAndClear();
116 m_aSplitter.disposeAndClear();
117 m_aEndMarker.disposeAndClear();
118 m_pParent.clear();
119 vcl::Window::dispose();
122 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
124 SolarMutexGuard g;
125 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
126 if ( xSection.is() )
128 if ( _rEvent.PropertyName == PROPERTY_HEIGHT )
130 m_pParent->getView()->SetUpdateMode(false);
131 //Resize();
132 m_pParent->getView()->notifySizeChanged();
133 m_pParent->resize(*this);
134 m_pParent->getView()->SetUpdateMode(true);
135 // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
137 else if ( _rEvent.PropertyName == PROPERTY_NAME && !xSection->getGroup().is() )
139 uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
140 if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fn(&OReportHelper::getReportHeader),::std::mem_fn(&OReportHelper::getReportHeaderOn))
141 || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fn(&OReportHelper::getReportFooter),::std::mem_fn(&OReportHelper::getReportFooterOn))
142 || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fn(&OReportHelper::getPageHeader),::std::mem_fn(&OReportHelper::getPageHeaderOn))
143 || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fn(&OReportHelper::getPageFooter),::std::mem_fn(&OReportHelper::getPageFooterOn)) )
145 m_aStartMarker->Invalidate(InvalidateFlags::NoErase);
147 else
149 OUString sTitle = RptResId(RID_STR_DETAIL);
150 m_aStartMarker->setTitle(sTitle);
151 m_aStartMarker->Invalidate(InvalidateFlags::Children);
155 else if ( _rEvent.PropertyName == PROPERTY_EXPRESSION )
157 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
158 if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fn(&OGroupHelper::getHeader),::std::mem_fn(&OGroupHelper::getHeaderOn)))
160 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fn(&OGroupHelper::getFooter),::std::mem_fn(&OGroupHelper::getFooterOn));
165 bool OSectionWindow::setReportSectionTitle(
166 const uno::Reference<report::XReportDefinition>& _xReport, TranslateId pResId,
167 const ::std::function<uno::Reference<report::XSection>(OReportHelper*)>& _pGetSection,
168 const ::std::function<bool(OReportHelper*)>& _pIsSectionOn)
170 OReportHelper aReportHelper(_xReport);
171 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection->getSection();
172 if ( bRet )
174 OUString sTitle = RptResId(pResId);
175 m_aStartMarker->setTitle(sTitle);
176 m_aStartMarker->Invalidate(InvalidateFlags::Children);
178 return bRet;
181 bool OSectionWindow::setGroupSectionTitle(
182 const uno::Reference<report::XGroup>& _xGroup, TranslateId pResId,
183 const ::std::function<uno::Reference<report::XSection>(OGroupHelper*)>& _pGetSection,
184 const ::std::function<bool(OGroupHelper*)>& _pIsSectionOn)
186 OGroupHelper aGroupHelper(_xGroup);
187 const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection->getSection() ;
188 if ( bRet )
190 OUString sExpression = _xGroup->getExpression();
191 OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
192 if ( !sLabel.isEmpty() )
194 sExpression = sLabel;
197 OUString sTitle(RptResId(pResId));
198 sTitle = sTitle.replaceFirst("#", sExpression);
199 m_aStartMarker->setTitle( sTitle );
200 m_aStartMarker->Invalidate(InvalidateFlags::Children);
202 return bRet;
205 void OSectionWindow::ImplInitSettings()
207 EnableChildTransparentMode();
208 SetParentClipMode( ParentClipMode::NoClip );
209 SetPaintTransparent( true );
210 SetBackground( );
213 void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
215 Window::DataChanged( rDCEvt );
217 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
218 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
220 ImplInitSettings();
221 Invalidate();
225 void OSectionWindow::Resize()
227 Window::Resize();
229 Size aOutputSize = GetOutputSizePixel();
230 tools::Long nEndWidth = tools::Long(REPORT_ENDMARKER_WIDTH * GetMapMode().GetScaleX());
232 const Point aThumbPos = m_pParent->getView()->getThumbPos();
233 aOutputSize.AdjustWidth( -(aThumbPos.X()) );
234 aOutputSize.AdjustHeight( -m_aSplitter->GetSizePixel().Height() );
236 if ( m_aStartMarker->isCollapsed() )
238 Point aPos(0,0);
239 m_aStartMarker->SetPosSizePixel(aPos,aOutputSize);
241 else
243 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
245 tools::Long nStartWidth = tools::Long(REPORT_STARTMARKER_WIDTH * GetMapMode().GetScaleX());
247 // set start marker
248 m_aStartMarker->SetPosSizePixel(Point(0,0),Size(nStartWidth,aOutputSize.Height()));
250 // set report section
251 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
252 Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
253 Point aReportPos(nStartWidth,0);
254 aSectionSize.setWidth( aOutputSize.Width() - nStartWidth );
255 if ( bShowEndMarker )
256 aSectionSize.AdjustWidth( -nEndWidth );
258 m_aReportSection->SetPosSizePixel(aReportPos,aSectionSize);
260 // set splitter
261 aReportPos.AdjustY(aSectionSize.Height() );
262 m_aSplitter->SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter->GetSizePixel().Height()));
263 aSectionSize.setHeight( static_cast<tools::Long>(1000 * static_cast<double>(GetMapMode().GetScaleY())) );
264 m_aSplitter->SetDragRectPixel( tools::Rectangle(Point(nStartWidth,0),aSectionSize));
266 // set end marker
267 aReportPos.AdjustX(aSectionSize.Width() );
268 aReportPos.setY( 0 );
269 m_aEndMarker->Show(bShowEndMarker);
270 m_aEndMarker->SetPosSizePixel(aReportPos,Size(nEndWidth,aOutputSize.Height()));
274 void OSectionWindow::setCollapsed(bool _bCollapsed)
276 if ( m_aStartMarker->isCollapsed() != _bCollapsed )
278 m_aStartMarker->setCollapsed(_bCollapsed);
282 void OSectionWindow::showProperties()
284 m_pParent->getView()->showProperties( m_aReportSection->getSection() );
287 void OSectionWindow::setMarked(bool _bMark)
289 m_aStartMarker->setMarked(_bMark);
290 m_aEndMarker->setMarked(_bMark);
293 IMPL_LINK( OSectionWindow, Collapsed, OColorListener&, _rMarker, void )
295 bool bShow = !_rMarker.isCollapsed();
296 m_aReportSection->Show(bShow);
297 m_aEndMarker->Show(bShow);
298 m_aSplitter->Show(bShow);
300 m_pParent->resize(*this);
303 void OSectionWindow::zoom(const Fraction& _aZoom)
305 setZoomFactor(_aZoom,*this);
306 m_aStartMarker->zoom(_aZoom);
308 setZoomFactor(_aZoom, *m_aReportSection);
309 setZoomFactor(_aZoom, *m_aSplitter);
310 setZoomFactor(_aZoom, *m_aEndMarker);
311 Invalidate();
314 IMPL_LINK_NOARG( OSectionWindow, StartSplitHdl, Splitter*, void)
316 const OUString sUndoAction( RptResId( RID_STR_UNDO_CHANGE_SIZE ) );
317 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, OUString(), 0, ViewShellId(-1) );
320 IMPL_LINK_NOARG( OSectionWindow, EndSplitHdl, Splitter*, void )
322 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
325 IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter, void )
327 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
329 return;
332 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
334 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
335 nSplitPos = m_aSplitter->PixelToLogic(Size(0,nSplitPos)).Height();
337 const sal_Int32 nCount = xSection->getCount();
338 for (sal_Int32 i = 0; i < nCount; ++i)
340 uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
341 if ( xReportComponent.is() )
343 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
347 if ( nSplitPos < 0 )
348 nSplitPos = 0;
350 xSection->setHeight(nSplitPos);
351 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,nSplitPos)).Height());
354 static void lcl_scroll(vcl::Window& _rWindow,const Point& _aDelta)
356 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
357 _rWindow.Invalidate(InvalidateFlags::Transparent);
360 static void lcl_setOrigin(vcl::Window& _rWindow,tools::Long _nX, tools::Long _nY)
362 MapMode aMap = _rWindow.GetMapMode();
363 aMap.SetOrigin( Point(- _nX, - _nY));
364 _rWindow.SetMapMode( aMap );
367 void OSectionWindow::scrollChildren(tools::Long _nX)
369 const Point aDelta( _nX,0 );
371 MapMode aMapMode( m_aReportSection->GetMapMode() );
372 const Point aOld = aMapMode.GetOrigin();
373 lcl_setOrigin(*m_aReportSection, aDelta.X(), 0);
375 aMapMode = m_aReportSection->GetMapMode();
376 const Point aNew = aMapMode.GetOrigin();
377 const Point aDiff = aOld - aNew;
379 lcl_scroll(*m_aReportSection, aDiff);
382 lcl_scroll(*m_aEndMarker, m_aEndMarker->PixelToLogic(Point(_nX,0)));
384 lcl_setOrigin(*m_aSplitter,_nX, 0);
385 lcl_scroll(*m_aSplitter,aDiff);
388 } // rptui
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */