lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / ui / report / SectionWindow.cxx
blobf76f3469ca4820c19b26ee0fe27ed090eab44093
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 <rptui_slotid.hrc>
22 #include <ReportController.hxx>
23 #include <SectionView.hxx>
24 #include <RptDef.hxx>
25 #include <ReportSection.hxx>
26 #include <DesignView.hxx>
27 #include <strings.hxx>
28 #include <core_resource.hxx>
29 #include <strings.hrc>
30 #include <StartMarker.hxx>
31 #include <EndMarker.hxx>
32 #include <ViewsWindow.hxx>
34 #include <svtools/colorcfg.hxx>
35 #include <functional>
36 #include <algorithm>
37 #include <vcl/svapp.hxx>
38 #include <vcl/settings.hxx>
40 #include <connectivity/dbtools.hxx>
42 namespace rptui
44 using namespace ::com::sun::star;
45 using namespace ::comphelper;
47 OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry)
48 : Window( _pParent,WB_DIALOGCONTROL)
49 ,OPropertyChangeListener(m_aMutex)
50 ,m_pParent(_pParent)
51 ,m_aStartMarker( VclPtr<rptui::OStartMarker>::Create(this,_sColorEntry))
52 ,m_aReportSection( VclPtr<rptui::OReportSection>::Create(this,_xSection))
53 ,m_aSplitter(VclPtr<Splitter>::Create(this))
54 ,m_aEndMarker( VclPtr<rptui::OEndMarker>::Create(this,_sColorEntry))
56 const MapMode& rMapMode = _pParent->GetMapMode();
57 SetMapMode( rMapMode );
58 ImplInitSettings();
59 // TRY
60 m_aSplitter->SetMapMode( MapMode( MapUnit::Map100thMM ) );
61 m_aSplitter->SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
62 m_aSplitter->SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
63 m_aSplitter->SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
64 m_aSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
65 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,_xSection->getHeight())).Height());
68 m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
70 m_aStartMarker->zoom(rMapMode.GetScaleX());
71 setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection.get());
72 setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter.get());
73 setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker.get());
75 m_aSplitter->Show();
76 m_aStartMarker->Show();
77 m_aReportSection->Show();
78 m_aEndMarker->Show();
79 Show();
81 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
82 m_pSectionMulti->addProperty(PROPERTY_NAME);
83 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
85 beans::PropertyChangeEvent aEvent;
86 aEvent.Source = _xSection;
87 aEvent.PropertyName = PROPERTY_NAME;
88 uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
89 if ( xGroup.is() )
91 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
92 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
93 aEvent.Source = xGroup;
94 aEvent.PropertyName = PROPERTY_EXPRESSION;
97 _propertyChanged(aEvent);
100 OSectionWindow::~OSectionWindow()
102 disposeOnce();
105 void OSectionWindow::dispose()
109 if ( m_pSectionMulti.is() )
110 m_pSectionMulti->dispose();
111 if ( m_pGroupMulti.is() )
112 m_pGroupMulti->dispose();
114 catch (uno::Exception&)
117 m_aStartMarker.disposeAndClear();
118 m_aReportSection.disposeAndClear();
119 m_aSplitter.disposeAndClear();
120 m_aEndMarker.disposeAndClear();
121 m_pParent.clear();
122 vcl::Window::dispose();
125 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
127 SolarMutexGuard g;
128 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
129 if ( xSection.is() )
131 if ( _rEvent.PropertyName == PROPERTY_HEIGHT )
133 m_pParent->getView()->SetUpdateMode(false);
134 //Resize();
135 m_pParent->getView()->notifySizeChanged();
136 m_pParent->resize(*this);
137 m_pParent->getView()->SetUpdateMode(true);
138 // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
140 else if ( _rEvent.PropertyName == PROPERTY_NAME && !xSection->getGroup().is() )
142 uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
143 if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fn(&OReportHelper::getReportHeader),::std::mem_fn(&OReportHelper::getReportHeaderOn))
144 || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fn(&OReportHelper::getReportFooter),::std::mem_fn(&OReportHelper::getReportFooterOn))
145 || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fn(&OReportHelper::getPageHeader),::std::mem_fn(&OReportHelper::getPageHeaderOn))
146 || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fn(&OReportHelper::getPageFooter),::std::mem_fn(&OReportHelper::getPageFooterOn)) )
148 m_aStartMarker->Invalidate(InvalidateFlags::NoErase);
150 else
152 OUString sTitle = RptResId(RID_STR_DETAIL);
153 m_aStartMarker->setTitle(sTitle);
154 m_aStartMarker->Invalidate(InvalidateFlags::Children);
158 else if ( _rEvent.PropertyName == PROPERTY_EXPRESSION )
160 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
161 if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fn(&OGroupHelper::getHeader),::std::mem_fn(&OGroupHelper::getHeaderOn)))
163 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fn(&OGroupHelper::getFooter),::std::mem_fn(&OGroupHelper::getFooterOn));
168 bool OSectionWindow::setReportSectionTitle(
169 const uno::Reference<report::XReportDefinition>& _xReport, const char* pResId,
170 const ::std::function<uno::Reference<report::XSection>(OReportHelper*)>& _pGetSection,
171 const ::std::function<bool(OReportHelper*)>& _pIsSectionOn)
173 OReportHelper aReportHelper(_xReport);
174 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection->getSection();
175 if ( bRet )
177 OUString sTitle = RptResId(pResId);
178 m_aStartMarker->setTitle(sTitle);
179 m_aStartMarker->Invalidate(InvalidateFlags::Children);
181 return bRet;
184 bool OSectionWindow::setGroupSectionTitle(
185 const uno::Reference<report::XGroup>& _xGroup, const char* pResId,
186 const ::std::function<uno::Reference<report::XSection>(OGroupHelper*)>& _pGetSection,
187 const ::std::function<bool(OGroupHelper*)>& _pIsSectionOn)
189 OGroupHelper aGroupHelper(_xGroup);
190 const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection->getSection() ;
191 if ( bRet )
193 OUString sExpression = _xGroup->getExpression();
194 OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
195 if ( !sLabel.isEmpty() )
197 sExpression = sLabel;
200 OUString sTitle(RptResId(pResId));
201 sTitle = sTitle.replaceFirst("#", sExpression);
202 m_aStartMarker->setTitle( sTitle );
203 m_aStartMarker->Invalidate(InvalidateFlags::Children);
205 return bRet;
208 void OSectionWindow::ImplInitSettings()
210 static bool t = false;
211 if ( t )
213 EnableChildTransparentMode();
214 SetParentClipMode( ParentClipMode::NoClip );
215 SetPaintTransparent( true );
217 SetBackground( );
220 void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
222 Window::DataChanged( rDCEvt );
224 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
225 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
227 ImplInitSettings();
228 Invalidate();
232 void OSectionWindow::Resize()
234 Window::Resize();
236 Size aOutputSize = GetOutputSizePixel();
237 long nEndWidth = long(REPORT_ENDMARKER_WIDTH * GetMapMode().GetScaleX());
239 const Point aThumbPos = m_pParent->getView()->getThumbPos();
240 aOutputSize.AdjustWidth( -(aThumbPos.X()) );
241 aOutputSize.AdjustHeight( -m_aSplitter->GetSizePixel().Height() );
243 if ( m_aStartMarker->isCollapsed() )
245 Point aPos(0,0);
246 m_aStartMarker->SetPosSizePixel(aPos,aOutputSize);
248 else
250 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
252 long nStartWidth = long(REPORT_STARTMARKER_WIDTH * GetMapMode().GetScaleX());
254 // set start marker
255 m_aStartMarker->SetPosSizePixel(Point(0,0),Size(nStartWidth,aOutputSize.Height()));
257 // set report section
258 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
259 Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
260 Point aReportPos(nStartWidth,0);
261 aSectionSize.setWidth( aOutputSize.Width() - nStartWidth );
262 if ( bShowEndMarker )
263 aSectionSize.AdjustWidth( -nEndWidth );
265 m_aReportSection->SetPosSizePixel(aReportPos,aSectionSize);
267 // set splitter
268 aReportPos.AdjustY(aSectionSize.Height() );
269 m_aSplitter->SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter->GetSizePixel().Height()));
270 aSectionSize.setHeight( static_cast<long>(1000 * static_cast<double>(GetMapMode().GetScaleY())) );
271 m_aSplitter->SetDragRectPixel( tools::Rectangle(Point(nStartWidth,0),aSectionSize));
273 // set end marker
274 aReportPos.AdjustX(aSectionSize.Width() );
275 aReportPos.setY( 0 );
276 m_aEndMarker->Show(bShowEndMarker);
277 m_aEndMarker->SetPosSizePixel(aReportPos,Size(nEndWidth,aOutputSize.Height()));
281 void OSectionWindow::setCollapsed(bool _bCollapsed)
283 if ( m_aStartMarker->isCollapsed() != _bCollapsed )
285 m_aStartMarker->setCollapsed(_bCollapsed);
289 void OSectionWindow::showProperties()
291 m_pParent->getView()->showProperties( m_aReportSection->getSection().get() );
294 void OSectionWindow::setMarked(bool _bMark)
296 m_aStartMarker->setMarked(_bMark);
297 m_aEndMarker->setMarked(_bMark);
300 IMPL_LINK( OSectionWindow, Collapsed, OColorListener&, _rMarker, void )
302 bool bShow = !_rMarker.isCollapsed();
303 m_aReportSection->Show(bShow);
304 m_aEndMarker->Show(bShow);
305 m_aSplitter->Show(bShow);
307 m_pParent->resize(*this);
310 void OSectionWindow::zoom(const Fraction& _aZoom)
312 setZoomFactor(_aZoom,*this);
313 m_aStartMarker->zoom(_aZoom);
315 setZoomFactor(_aZoom, *m_aReportSection.get());
316 setZoomFactor(_aZoom, *m_aSplitter.get());
317 setZoomFactor(_aZoom, *m_aEndMarker.get());
318 Invalidate();
321 IMPL_LINK_NOARG( OSectionWindow, StartSplitHdl, Splitter*, void)
323 const OUString sUndoAction( RptResId( RID_STR_UNDO_CHANGE_SIZE ) );
324 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, OUString(), 0, ViewShellId(-1) );
327 IMPL_LINK_NOARG( OSectionWindow, EndSplitHdl, Splitter*, void )
329 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
332 IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter, void )
334 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
336 return;
339 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
341 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
342 nSplitPos = m_aSplitter->PixelToLogic(Size(0,nSplitPos)).Height();
344 const sal_Int32 nCount = xSection->getCount();
345 for (sal_Int32 i = 0; i < nCount; ++i)
347 uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
348 if ( xReportComponent.is() )
350 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
354 if ( nSplitPos < 0 )
355 nSplitPos = 0;
357 xSection->setHeight(nSplitPos);
358 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,nSplitPos)).Height());
361 static void lcl_scroll(vcl::Window& _rWindow,const Point& _aDelta)
363 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
364 _rWindow.Invalidate(InvalidateFlags::Transparent);
367 static void lcl_setOrigin(vcl::Window& _rWindow,long _nX, long _nY)
369 MapMode aMap = _rWindow.GetMapMode();
370 aMap.SetOrigin( Point(- _nX, - _nY));
371 _rWindow.SetMapMode( aMap );
374 void OSectionWindow::scrollChildren(long _nX)
376 const Point aDelta( _nX,0 );
378 MapMode aMapMode( m_aReportSection->GetMapMode() );
379 const Point aOld = aMapMode.GetOrigin();
380 lcl_setOrigin(*m_aReportSection.get(), aDelta.X(), 0);
382 aMapMode = m_aReportSection->GetMapMode();
383 const Point aNew = aMapMode.GetOrigin();
384 const Point aDiff = aOld - aNew;
386 lcl_scroll(*m_aReportSection.get(), aDiff);
389 lcl_scroll(*m_aEndMarker.get(), m_aEndMarker->PixelToLogic(Point(_nX,0)));
391 lcl_setOrigin(*m_aSplitter.get(),_nX, 0);
392 lcl_scroll(*m_aSplitter.get(),aDiff);
395 } // rptui
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */