LibreOffice Module reportdesign (master) 1
SectionWindow.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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>
31
32#include <functional>
33#include <algorithm>
34#include <vcl/svapp.hxx>
35#include <vcl/settings.hxx>
36
37namespace rptui
38{
39using namespace ::com::sun::star;
40using namespace ::comphelper;
41
42OSectionWindow::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))
50{
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());
61
62
63 m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
64
65 m_aStartMarker->zoom(rMapMode.GetScaleX());
66 setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection);
67 setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter);
68 setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker);
69
70 m_aSplitter->Show();
71 m_aStartMarker->Show();
72 m_aReportSection->Show();
73 m_aEndMarker->Show();
74 Show();
75
76 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection);
77 m_pSectionMulti->addProperty(PROPERTY_NAME);
78 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
79
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() )
85 {
86 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup);
87 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
88 aEvent.Source = xGroup;
89 aEvent.PropertyName = PROPERTY_EXPRESSION;
90 }
91
92 _propertyChanged(aEvent);
93}
94
95OSectionWindow::~OSectionWindow()
96{
97 disposeOnce();
98}
99
100void OSectionWindow::dispose()
101{
102 try
103 {
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();
110 }
111 catch (uno::Exception&)
112 {
113 }
114 m_aStartMarker.disposeAndClear();
115 m_aReportSection.disposeAndClear();
116 m_aSplitter.disposeAndClear();
117 m_aEndMarker.disposeAndClear();
118 m_pParent.clear();
120}
121
122void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
123{
125 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
126 if ( xSection.is() )
127 {
128 if ( _rEvent.PropertyName == PROPERTY_HEIGHT )
129 {
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();
136 }
137 else if ( _rEvent.PropertyName == PROPERTY_NAME && !xSection->getGroup().is() )
138 {
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)) )
144 {
145 m_aStartMarker->Invalidate(InvalidateFlags::NoErase);
146 }
147 else
148 {
149 OUString sTitle = RptResId(RID_STR_DETAIL);
150 m_aStartMarker->setTitle(sTitle);
151 m_aStartMarker->Invalidate(InvalidateFlags::Children);
152 }
153 }
154 }
155 else if ( _rEvent.PropertyName == PROPERTY_EXPRESSION )
156 {
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)))
159 {
160 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fn(&OGroupHelper::getFooter),::std::mem_fn(&OGroupHelper::getFooterOn));
161 }
162 }
163}
164
165bool 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)
169{
170 OReportHelper aReportHelper(_xReport);
171 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection->getSection();
172 if ( bRet )
173 {
174 OUString sTitle = RptResId(pResId);
175 m_aStartMarker->setTitle(sTitle);
176 m_aStartMarker->Invalidate(InvalidateFlags::Children);
177 }
178 return bRet;
179}
180
181bool 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)
185{
186 OGroupHelper aGroupHelper(_xGroup);
187 const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection->getSection() ;
188 if ( bRet )
189 {
190 OUString sExpression = _xGroup->getExpression();
191 OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
192 if ( !sLabel.isEmpty() )
193 {
194 sExpression = sLabel;
195 }
196
197 OUString sTitle(RptResId(pResId));
198 sTitle = sTitle.replaceFirst("#", sExpression);
199 m_aStartMarker->setTitle( sTitle );
200 m_aStartMarker->Invalidate(InvalidateFlags::Children);
201 }
202 return bRet;
203}
204
205void OSectionWindow::ImplInitSettings()
206{
207 EnableChildTransparentMode();
208 SetParentClipMode( ParentClipMode::NoClip );
209 SetPaintTransparent( true );
210 SetBackground( );
211}
212
213void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
214{
215 Window::DataChanged( rDCEvt );
216
217 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
218 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
219 {
220 ImplInitSettings();
221 Invalidate();
222 }
223}
224
225void OSectionWindow::Resize()
226{
227 Window::Resize();
228
229 Size aOutputSize = GetOutputSizePixel();
230 tools::Long nEndWidth = tools::Long(REPORT_ENDMARKER_WIDTH * GetMapMode().GetScaleX());
231
232 const Point aThumbPos = m_pParent->getView()->getThumbPos();
233 aOutputSize.AdjustWidth( -(aThumbPos.X()) );
234 aOutputSize.AdjustHeight( -m_aSplitter->GetSizePixel().Height() );
235
236 if ( m_aStartMarker->isCollapsed() )
237 {
238 Point aPos(0,0);
239 m_aStartMarker->SetPosSizePixel(aPos,aOutputSize);
240 }
241 else
242 {
243 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
244
245 tools::Long nStartWidth = tools::Long(REPORT_STARTMARKER_WIDTH * GetMapMode().GetScaleX());
246
247 // set start marker
248 m_aStartMarker->SetPosSizePixel(Point(0,0),Size(nStartWidth,aOutputSize.Height()));
249
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 );
257
258 m_aReportSection->SetPosSizePixel(aReportPos,aSectionSize);
259
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));
265
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()));
271 }
272}
273
274void OSectionWindow::setCollapsed(bool _bCollapsed)
275{
276 if ( m_aStartMarker->isCollapsed() != _bCollapsed )
277 {
278 m_aStartMarker->setCollapsed(_bCollapsed);
279 }
280}
281
282void OSectionWindow::showProperties()
283{
284 m_pParent->getView()->showProperties( m_aReportSection->getSection() );
285}
286
287void OSectionWindow::setMarked(bool _bMark)
288{
289 m_aStartMarker->setMarked(_bMark);
290 m_aEndMarker->setMarked(_bMark);
291}
292
293IMPL_LINK( OSectionWindow, Collapsed, OColorListener&, _rMarker, void )
294{
295 bool bShow = !_rMarker.isCollapsed();
296 m_aReportSection->Show(bShow);
297 m_aEndMarker->Show(bShow);
298 m_aSplitter->Show(bShow);
299
300 m_pParent->resize(*this);
301}
302
303void OSectionWindow::zoom(const Fraction& _aZoom)
304{
305 setZoomFactor(_aZoom,*this);
306 m_aStartMarker->zoom(_aZoom);
307
308 setZoomFactor(_aZoom, *m_aReportSection);
309 setZoomFactor(_aZoom, *m_aSplitter);
310 setZoomFactor(_aZoom, *m_aEndMarker);
311 Invalidate();
312}
313
315{
316 const OUString sUndoAction( RptResId( RID_STR_UNDO_CHANGE_SIZE ) );
317 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, OUString(), 0, ViewShellId(-1) );
318}
319
321{
322 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
323}
324
325IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter, void )
326{
327 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
328 {
329 return;
330 }
331
332 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
333
334 const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
335 nSplitPos = m_aSplitter->PixelToLogic(Size(0,nSplitPos)).Height();
336
337 const sal_Int32 nCount = xSection->getCount();
338 for (sal_Int32 i = 0; i < nCount; ++i)
339 {
340 uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
341 if ( xReportComponent.is() )
342 {
343 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
344 }
345 }
346
347 if ( nSplitPos < 0 )
348 nSplitPos = 0;
349
350 xSection->setHeight(nSplitPos);
351 m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,nSplitPos)).Height());
352}
353
354static void lcl_scroll(vcl::Window& _rWindow,const Point& _aDelta)
355{
356 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
357 _rWindow.Invalidate(InvalidateFlags::Transparent);
358}
359
360static void lcl_setOrigin(vcl::Window& _rWindow,tools::Long _nX, tools::Long _nY)
361{
362 MapMode aMap = _rWindow.GetMapMode();
363 aMap.SetOrigin( Point(- _nX, - _nY));
364 _rWindow.SetMapMode( aMap );
365}
366
367void OSectionWindow::scrollChildren(tools::Long _nX)
368{
369 const Point aDelta( _nX,0 );
370
371 MapMode aMapMode( m_aReportSection->GetMapMode() );
372 const Point aOld = aMapMode.GetOrigin();
373 lcl_setOrigin(*m_aReportSection, aDelta.X(), 0);
374
375 aMapMode = m_aReportSection->GetMapMode();
376 const Point aNew = aMapMode.GetOrigin();
377 const Point aDiff = aOld - aNew;
378 {
379 lcl_scroll(*m_aReportSection, aDiff);
380 }
381
382 lcl_scroll(*m_aEndMarker, m_aEndMarker->PixelToLogic(Point(_nX,0)));
383
384 lcl_setOrigin(*m_aSplitter,_nX, 0);
385 lcl_scroll(*m_aSplitter,aDiff);
386}
387
388} // rptui
389
390
391/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define REPORT_STARTMARKER_WIDTH
#define REPORT_ENDMARKER_WIDTH
AnyEventRef aEvent
static const AllSettings & GetSettings()
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
const Fraction & GetScaleX() const
const Point & GetOrigin() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
Helper class to allow std::mem_fun for SAL_CALL.
Definition: UndoActions.hxx:49
Helper class to allow std::mem_fun for SAL_CALL.
Definition: UndoActions.hxx:72
OSectionWindow(OSectionWindow const &)=delete
virtual void dispose() override
void SetMapMode()
const MapMode & GetMapMode() const
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
OUString RptResId(TranslateId aId)
int nCount
std::mutex m_aMutex
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
SwView * getView(const uno::Reference< frame::XModel > &xModel)
static void lcl_scroll(vcl::Window &_rWindow, const Point &_aDelta)
IMPL_LINK_NOARG(OSectionWindow, EndSplitHdl, Splitter *, void)
static void lcl_setOrigin(vcl::Window &_rWindow, tools::Long _nX, tools::Long _nY)
IMPL_LINK(OSectionWindow, SplitHdl, Splitter *, _pSplitter, void)
void setZoomFactor(const Fraction &_aZoom, vcl::Window &_rWindow)
sets the map mode at the window
Definition: UITools.cxx:997
long Long
HashMap_OWString_Interface aMap
constexpr OUStringLiteral PROPERTY_EXPRESSION
Definition: strings.hxx:52
constexpr OUStringLiteral PROPERTY_NAME
Definition: strings.hxx:36
constexpr OUStringLiteral PROPERTY_HEIGHT
Definition: strings.hxx:37
WinBits const WB_DIALOGCONTROL