1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
37 #include <vcl/svapp.hxx>
38 #include <vcl/settings.hxx>
40 #include <connectivity/dbtools.hxx>
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
)
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
);
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());
76 m_aStartMarker
->Show();
77 m_aReportSection
->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());
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()
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();
122 vcl::Window::dispose();
125 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
)
128 const uno::Reference
< report::XSection
> xSection(_rEvent
.Source
,uno::UNO_QUERY
);
131 if ( _rEvent
.PropertyName
== PROPERTY_HEIGHT
)
133 m_pParent
->getView()->SetUpdateMode(false);
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
);
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();
177 OUString sTitle
= RptResId(pResId
);
178 m_aStartMarker
->setTitle(sTitle
);
179 m_aStartMarker
->Invalidate(InvalidateFlags::Children
);
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() ;
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
);
208 void OSectionWindow::ImplInitSettings()
210 EnableChildTransparentMode();
211 SetParentClipMode( ParentClipMode::NoClip
);
212 SetPaintTransparent( true );
216 void OSectionWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
218 Window::DataChanged( rDCEvt
);
220 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
221 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
228 void OSectionWindow::Resize()
232 Size aOutputSize
= GetOutputSizePixel();
233 long nEndWidth
= long(REPORT_ENDMARKER_WIDTH
* GetMapMode().GetScaleX());
235 const Point aThumbPos
= m_pParent
->getView()->getThumbPos();
236 aOutputSize
.AdjustWidth( -(aThumbPos
.X()) );
237 aOutputSize
.AdjustHeight( -m_aSplitter
->GetSizePixel().Height() );
239 if ( m_aStartMarker
->isCollapsed() )
242 m_aStartMarker
->SetPosSizePixel(aPos
,aOutputSize
);
246 const bool bShowEndMarker
= m_pParent
->getView()->GetTotalWidth() <= (aThumbPos
.X() + aOutputSize
.Width() );
248 long nStartWidth
= long(REPORT_STARTMARKER_WIDTH
* GetMapMode().GetScaleX());
251 m_aStartMarker
->SetPosSizePixel(Point(0,0),Size(nStartWidth
,aOutputSize
.Height()));
253 // set report section
254 const uno::Reference
< report::XSection
> xSection
= m_aReportSection
->getSection();
255 Size aSectionSize
= LogicToPixel( Size( 0,xSection
->getHeight() ) );
256 Point
aReportPos(nStartWidth
,0);
257 aSectionSize
.setWidth( aOutputSize
.Width() - nStartWidth
);
258 if ( bShowEndMarker
)
259 aSectionSize
.AdjustWidth( -nEndWidth
);
261 m_aReportSection
->SetPosSizePixel(aReportPos
,aSectionSize
);
264 aReportPos
.AdjustY(aSectionSize
.Height() );
265 m_aSplitter
->SetPosSizePixel(aReportPos
,Size(aSectionSize
.Width(),m_aSplitter
->GetSizePixel().Height()));
266 aSectionSize
.setHeight( static_cast<long>(1000 * static_cast<double>(GetMapMode().GetScaleY())) );
267 m_aSplitter
->SetDragRectPixel( tools::Rectangle(Point(nStartWidth
,0),aSectionSize
));
270 aReportPos
.AdjustX(aSectionSize
.Width() );
271 aReportPos
.setY( 0 );
272 m_aEndMarker
->Show(bShowEndMarker
);
273 m_aEndMarker
->SetPosSizePixel(aReportPos
,Size(nEndWidth
,aOutputSize
.Height()));
277 void OSectionWindow::setCollapsed(bool _bCollapsed
)
279 if ( m_aStartMarker
->isCollapsed() != _bCollapsed
)
281 m_aStartMarker
->setCollapsed(_bCollapsed
);
285 void OSectionWindow::showProperties()
287 m_pParent
->getView()->showProperties( m_aReportSection
->getSection().get() );
290 void OSectionWindow::setMarked(bool _bMark
)
292 m_aStartMarker
->setMarked(_bMark
);
293 m_aEndMarker
->setMarked(_bMark
);
296 IMPL_LINK( OSectionWindow
, Collapsed
, OColorListener
&, _rMarker
, void )
298 bool bShow
= !_rMarker
.isCollapsed();
299 m_aReportSection
->Show(bShow
);
300 m_aEndMarker
->Show(bShow
);
301 m_aSplitter
->Show(bShow
);
303 m_pParent
->resize(*this);
306 void OSectionWindow::zoom(const Fraction
& _aZoom
)
308 setZoomFactor(_aZoom
,*this);
309 m_aStartMarker
->zoom(_aZoom
);
311 setZoomFactor(_aZoom
, *m_aReportSection
.get());
312 setZoomFactor(_aZoom
, *m_aSplitter
.get());
313 setZoomFactor(_aZoom
, *m_aEndMarker
.get());
317 IMPL_LINK_NOARG( OSectionWindow
, StartSplitHdl
, Splitter
*, void)
319 const OUString
sUndoAction( RptResId( RID_STR_UNDO_CHANGE_SIZE
) );
320 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction
, OUString(), 0, ViewShellId(-1) );
323 IMPL_LINK_NOARG( OSectionWindow
, EndSplitHdl
, Splitter
*, void )
325 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
328 IMPL_LINK( OSectionWindow
, SplitHdl
, Splitter
*, _pSplitter
, void )
330 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
335 sal_Int32 nSplitPos
= _pSplitter
->GetSplitPosPixel();
337 const uno::Reference
< report::XSection
> xSection
= m_aReportSection
->getSection();
338 nSplitPos
= m_aSplitter
->PixelToLogic(Size(0,nSplitPos
)).Height();
340 const sal_Int32 nCount
= xSection
->getCount();
341 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
343 uno::Reference
<report::XReportComponent
> xReportComponent(xSection
->getByIndex(i
),uno::UNO_QUERY
);
344 if ( xReportComponent
.is() )
346 nSplitPos
= ::std::max(nSplitPos
,xReportComponent
->getPositionY() + xReportComponent
->getHeight());
353 xSection
->setHeight(nSplitPos
);
354 m_aSplitter
->SetSplitPosPixel(m_aSplitter
->LogicToPixel(Size(0,nSplitPos
)).Height());
357 static void lcl_scroll(vcl::Window
& _rWindow
,const Point
& _aDelta
)
359 _rWindow
.Scroll(-_aDelta
.X(),-_aDelta
.Y());
360 _rWindow
.Invalidate(InvalidateFlags::Transparent
);
363 static void lcl_setOrigin(vcl::Window
& _rWindow
,long _nX
, long _nY
)
365 MapMode aMap
= _rWindow
.GetMapMode();
366 aMap
.SetOrigin( Point(- _nX
, - _nY
));
367 _rWindow
.SetMapMode( aMap
);
370 void OSectionWindow::scrollChildren(long _nX
)
372 const Point
aDelta( _nX
,0 );
374 MapMode
aMapMode( m_aReportSection
->GetMapMode() );
375 const Point aOld
= aMapMode
.GetOrigin();
376 lcl_setOrigin(*m_aReportSection
.get(), aDelta
.X(), 0);
378 aMapMode
= m_aReportSection
->GetMapMode();
379 const Point aNew
= aMapMode
.GetOrigin();
380 const Point aDiff
= aOld
- aNew
;
382 lcl_scroll(*m_aReportSection
.get(), aDiff
);
385 lcl_scroll(*m_aEndMarker
.get(), m_aEndMarker
->PixelToLogic(Point(_nX
,0)));
387 lcl_setOrigin(*m_aSplitter
.get(),_nX
, 0);
388 lcl_scroll(*m_aSplitter
.get(),aDiff
);
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */