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 "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>
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 SetUniqueId(UID_RPT_SECTIONSWINDOW
);
57 const MapMode
& rMapMode
= _pParent
->GetMapMode();
58 SetMapMode( rMapMode
);
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());
77 m_aStartMarker
->Show();
78 m_aReportSection
->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());
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()
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();
123 vcl::Window::dispose();
126 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
)
127 throw (uno::RuntimeException
, std::exception
)
130 const uno::Reference
< report::XSection
> xSection(_rEvent
.Source
,uno::UNO_QUERY
);
133 const uno::Reference
< report::XSection
> xCurrentSection
= m_aReportSection
->getSection();
134 if ( _rEvent
.PropertyName
== PROPERTY_HEIGHT
)
136 m_pParent
->getView()->SetUpdateMode(false);
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
);
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();
177 OUString sTitle
= ModuleRes(_nResId
);
178 m_aStartMarker
->setTitle(sTitle
);
179 m_aStartMarker
->Invalidate(INVALIDATE_CHILDREN
);
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() ;
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
);
205 void OSectionWindow::ImplInitSettings()
207 static bool t
= false;
210 EnableChildTransparentMode( true );
211 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
212 SetPaintTransparent( true );
217 void OSectionWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
219 Window::DataChanged( rDCEvt
);
221 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
222 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
229 void OSectionWindow::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() )
244 m_aStartMarker
->SetPosSizePixel(aPos
,aOutputSize
);
248 const bool bShowEndMarker
= m_pParent
->getView()->GetTotalWidth() <= (aThumbPos
.X() + aOutputSize
.Width() );
250 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
));
251 aStartWidth
*= GetMapMode().GetScaleX();
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
);
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
));
273 aReportPos
.X() += aSectionSize
.Width();
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
)
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);
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());
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() );
331 IMPL_LINK( OSectionWindow
, EndSplitHdl
, Splitter
*, )
333 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
337 IMPL_LINK( OSectionWindow
, SplitHdl
, Splitter
*, _pSplitter
)
339 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
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());
362 xSection
->setHeight(nSplitPos
);
363 m_aSplitter
->SetSplitPosPixel(m_aSplitter
->LogicToPixel(Size(0,nSplitPos
)).Height());
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
);
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */