bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / ui / report / SectionWindow.cxx
blobbb37ceb4cdd46412c95d586eb7214c08527bd844
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 "uistrings.hrc"
28 #include "helpids.hrc"
29 #include "RptResId.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 SetUniqueId(UID_RPT_SECTIONSWINDOW);
57 const MapMode& rMapMode = _pParent->GetMapMode();
58 SetMapMode( rMapMode );
59 ImplInitSettings();
60 // TRY
61 m_aSplitter->SetMapMode( MapMode( MAP_100TH_MM ) );
62 m_aSplitter->SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
63 m_aSplitter->SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
64 m_aSplitter->SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
65 m_aSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
66 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,_xSection->getHeight())).Height());
69 m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
71 m_aStartMarker->zoom(rMapMode.GetScaleX());
72 setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection.get());
73 setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter.get());
74 setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker.get());
76 m_aSplitter->Show();
77 m_aStartMarker->Show();
78 m_aReportSection->Show();
79 m_aEndMarker->Show();
80 Show();
82 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
83 m_pSectionMulti->addProperty(PROPERTY_NAME);
84 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
86 beans::PropertyChangeEvent aEvent;
87 aEvent.Source = _xSection;
88 aEvent.PropertyName = PROPERTY_NAME;
89 uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
90 if ( xGroup.is() )
92 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
93 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
94 aEvent.Source = xGroup;
95 aEvent.PropertyName = PROPERTY_EXPRESSION;
98 _propertyChanged(aEvent);
101 OSectionWindow::~OSectionWindow()
103 disposeOnce();
106 void OSectionWindow::dispose()
110 if ( m_pSectionMulti.is() )
111 m_pSectionMulti->dispose();
112 if ( m_pGroupMulti.is() )
113 m_pGroupMulti->dispose();
115 catch (uno::Exception&)
118 m_aStartMarker.disposeAndClear();
119 m_aReportSection.disposeAndClear();
120 m_aSplitter.disposeAndClear();
121 m_aEndMarker.disposeAndClear();
122 m_pParent.clear();
123 vcl::Window::dispose();
126 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
127 throw (uno::RuntimeException, std::exception)
129 SolarMutexGuard g;
130 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
131 if ( xSection.is() )
133 const uno::Reference< report::XSection> xCurrentSection = m_aReportSection->getSection();
134 if ( _rEvent.PropertyName == PROPERTY_HEIGHT )
136 m_pParent->getView()->SetUpdateMode(false);
137 //Resize();
138 m_pParent->getView()->notifySizeChanged();
139 m_pParent->resize(*this);
140 m_pParent->getView()->SetUpdateMode(true);
141 // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
143 else if ( _rEvent.PropertyName == PROPERTY_NAME && !xSection->getGroup().is() )
145 uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
146 if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
147 || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
148 || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
149 || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
151 m_aStartMarker->Invalidate(INVALIDATE_NOERASE);
153 else
155 OUString sTitle = ModuleRes(RID_STR_DETAIL);
156 m_aStartMarker->setTitle(sTitle);
157 m_aStartMarker->Invalidate(INVALIDATE_CHILDREN);
161 else if ( _rEvent.PropertyName == PROPERTY_EXPRESSION )
163 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
164 if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)))
166 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
171 bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection, const ::std::mem_fun_t<bool,OReportHelper>& _pIsSectionOn)
173 OReportHelper aReportHelper(_xReport);
174 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection->getSection();
175 if ( bRet )
177 OUString sTitle = ModuleRes(_nResId);
178 m_aStartMarker->setTitle(sTitle);
179 m_aStartMarker->Invalidate(INVALIDATE_CHILDREN);
181 return bRet;
184 bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection, const ::std::mem_fun_t<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( ModuleRes(_nResId).toString() );
198 sTitle = sTitle.replaceFirst("#", sExpression);
199 m_aStartMarker->setTitle( sTitle );
200 m_aStartMarker->Invalidate(INVALIDATE_CHILDREN);
202 return bRet;
205 void OSectionWindow::ImplInitSettings()
207 static bool t = false;
208 if ( t )
210 EnableChildTransparentMode( true );
211 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
212 SetPaintTransparent( true );
214 SetBackground( );
217 void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
219 Window::DataChanged( rDCEvt );
221 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
222 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
224 ImplInitSettings();
225 Invalidate();
229 void OSectionWindow::Resize()
231 Window::Resize();
233 Size aOutputSize = GetOutputSizePixel();
234 Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
235 aEndWidth *= GetMapMode().GetScaleX();
237 const Point aThumbPos = m_pParent->getView()->getThumbPos();
238 aOutputSize.Width() -= aThumbPos.X();
239 aOutputSize.Height() -= m_aSplitter->GetSizePixel().Height();
241 if ( m_aStartMarker->isCollapsed() )
243 Point aPos(0,0);
244 m_aStartMarker->SetPosSizePixel(aPos,aOutputSize);
246 else
248 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
250 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
251 aStartWidth *= GetMapMode().GetScaleX();
253 // set start marker
254 m_aStartMarker->SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
256 // set report section
257 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
258 Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
259 Point aReportPos(aStartWidth,0);
260 aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
261 if ( bShowEndMarker )
262 aSectionSize.Width() -= (long)aEndWidth;
264 m_aReportSection->SetPosSizePixel(aReportPos,aSectionSize);
266 // set splitter
267 aReportPos.Y() += aSectionSize.Height();
268 m_aSplitter->SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter->GetSizePixel().Height()));
269 aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
270 m_aSplitter->SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
272 // set end marker
273 aReportPos.X() += aSectionSize.Width();
274 aReportPos.Y() = 0;
275 m_aEndMarker->Show(bShowEndMarker);
276 m_aEndMarker->SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
280 void OSectionWindow::setCollapsed(bool _bCollapsed)
282 if ( m_aStartMarker->isCollapsed() != _bCollapsed )
284 m_aStartMarker->setCollapsed(_bCollapsed);
288 void OSectionWindow::showProperties()
290 m_pParent->getView()->showProperties( m_aReportSection->getSection().get() );
293 void OSectionWindow::setMarked(bool _bMark)
295 m_aStartMarker->setMarked(_bMark);
296 m_aEndMarker->setMarked(_bMark);
299 IMPL_LINK( OSectionWindow, Collapsed, OColorListener *, _pMarker )
301 if ( _pMarker )
303 bool bShow = !_pMarker->isCollapsed();
304 m_aReportSection->Show(bShow);
305 m_aEndMarker->Show(bShow);
306 m_aSplitter->Show(bShow);
308 m_pParent->resize(*this);
310 return 0L;
313 void OSectionWindow::zoom(const Fraction& _aZoom)
315 setZoomFactor(_aZoom,*this);
316 m_aStartMarker->zoom(_aZoom);
318 setZoomFactor(_aZoom, *m_aReportSection.get());
319 setZoomFactor(_aZoom, *m_aSplitter.get());
320 setZoomFactor(_aZoom, *m_aEndMarker.get());
321 Invalidate();
324 IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*, )
326 const OUString sUndoAction( ModuleRes( RID_STR_UNDO_CHANGE_SIZE ) );
327 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, OUString() );
328 return 0L;
331 IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*, )
333 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
334 return 0L;
337 IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
339 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
341 return 0L;
344 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
346 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
347 nSplitPos = m_aSplitter->PixelToLogic(Size(0,nSplitPos)).Height();
349 const sal_Int32 nCount = xSection->getCount();
350 for (sal_Int32 i = 0; i < nCount; ++i)
352 uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
353 if ( xReportComponent.is() )
355 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
359 if ( nSplitPos < 0 )
360 nSplitPos = 0;
362 xSection->setHeight(nSplitPos);
363 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,nSplitPos)).Height());
365 return 0L;
368 void lcl_scroll(vcl::Window& _rWindow,const Point& _aDelta)
370 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
371 _rWindow.Invalidate(INVALIDATE_TRANSPARENT);
374 void lcl_setOrigin(vcl::Window& _rWindow,long _nX, long _nY)
376 MapMode aMap = _rWindow.GetMapMode();
377 aMap.SetOrigin( Point(- _nX, - _nY));
378 _rWindow.SetMapMode( aMap );
381 void OSectionWindow::scrollChildren(long _nX)
383 const Point aDelta( _nX,0 );
385 MapMode aMapMode( m_aReportSection->GetMapMode() );
386 const Point aOld = aMapMode.GetOrigin();
387 lcl_setOrigin(*m_aReportSection.get(), aDelta.X(), 0);
389 aMapMode = m_aReportSection->GetMapMode();
390 const Point aNew = aMapMode.GetOrigin();
391 const Point aDiff = aOld - aNew;
393 lcl_scroll(*m_aReportSection.get(), aDiff);
396 lcl_scroll(*m_aEndMarker.get(), m_aEndMarker->PixelToLogic(Point(_nX,0)));
398 lcl_setOrigin(*m_aSplitter.get(),_nX, 0);
399 lcl_scroll(*m_aSplitter.get(),aDiff);
402 } // rptui
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */