bump product version to 4.1.6.2
[LibreOffice.git] / reportdesign / source / ui / report / SectionWindow.cxx
blobd6a49ed62423d7e54a50bedbd1c722f59d3375bb
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 "ReportRuler.hxx"
22 #include "rptui_slotid.hrc"
23 #include "ReportController.hxx"
24 #include "SectionView.hxx"
25 #include "RptDef.hxx"
26 #include "ReportSection.hxx"
27 #include "DesignView.hxx"
28 #include "uistrings.hrc"
29 #include "helpids.hrc"
30 #include "RptResId.hrc"
31 #include "StartMarker.hxx"
32 #include "EndMarker.hxx"
33 #include "ViewsWindow.hxx"
35 #include <svtools/colorcfg.hxx>
36 #include <functional>
37 #include <algorithm>
38 #include <vcl/svapp.hxx>
39 #include <connectivity/dbtools.hxx>
41 namespace rptui
43 using namespace ::com::sun::star;
44 using namespace ::comphelper;
46 DBG_NAME( rpt_OSectionWindow )
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( this,_sColorEntry)
52 ,m_aReportSection( this,_xSection)
53 ,m_aSplitter(this)
54 ,m_aEndMarker( this,_sColorEntry)
56 DBG_CTOR( rpt_OSectionWindow,NULL);
57 SetUniqueId(UID_RPT_SECTIONSWINDOW);
58 const MapMode& rMapMode = _pParent->GetMapMode();
59 SetMapMode( rMapMode );
60 ImplInitSettings();
61 // TRY
62 m_aSplitter.SetMapMode( MapMode( MAP_100TH_MM ) );
63 m_aSplitter.SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
64 m_aSplitter.SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
65 m_aSplitter.SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
66 m_aSplitter.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
67 m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,_xSection->getHeight())).Height());
70 m_aStartMarker.setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
72 m_aStartMarker.zoom(rMapMode.GetScaleX());
73 setZoomFactor(rMapMode.GetScaleX(),m_aReportSection);
74 setZoomFactor(rMapMode.GetScaleX(),m_aSplitter);
75 setZoomFactor(rMapMode.GetScaleX(),m_aEndMarker);
77 m_aSplitter.Show();
78 m_aStartMarker.Show();
79 m_aReportSection.Show();
80 m_aEndMarker.Show();
81 Show();
83 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
84 m_pSectionMulti->addProperty(PROPERTY_NAME);
85 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
87 beans::PropertyChangeEvent aEvent;
88 aEvent.Source = _xSection;
89 aEvent.PropertyName = PROPERTY_NAME;
90 uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
91 if ( xGroup.is() )
93 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
94 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
95 aEvent.Source = xGroup;
96 aEvent.PropertyName = PROPERTY_EXPRESSION;
99 _propertyChanged(aEvent);
101 // -----------------------------------------------------------------------------
102 OSectionWindow::~OSectionWindow()
104 DBG_DTOR( rpt_OSectionWindow,NULL);
107 if ( m_pSectionMulti.is() )
108 m_pSectionMulti->dispose();
109 if ( m_pGroupMulti.is() )
110 m_pGroupMulti->dispose();
112 catch (uno::Exception&)
116 // -----------------------------------------------------------------------------
117 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
119 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
120 if ( xSection.is() )
122 const uno::Reference< report::XSection> xCurrentSection = m_aReportSection.getSection();
123 if ( _rEvent.PropertyName.equals(PROPERTY_HEIGHT) )
125 m_pParent->getView()->SetUpdateMode(sal_False);
126 //Resize();
127 m_pParent->getView()->notifySizeChanged();
128 m_pParent->resize(*this);
129 m_pParent->getView()->SetUpdateMode(sal_True);
130 // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
132 else if ( _rEvent.PropertyName.equals(PROPERTY_NAME) && !xSection->getGroup().is() )
134 uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
135 if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
136 || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
137 || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
138 || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
140 m_aStartMarker.Invalidate(INVALIDATE_NOERASE);
142 else
144 String sTitle = String(ModuleRes(RID_STR_DETAIL));
145 m_aStartMarker.setTitle(sTitle);
146 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
150 else if ( _rEvent.PropertyName.equals(PROPERTY_EXPRESSION) )
152 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
153 if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)))
155 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
159 // -----------------------------------------------------------------------------
160 bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OReportHelper> _pIsSectionOn)
162 OReportHelper aReportHelper(_xReport);
163 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection.getSection();
164 if ( bRet )
166 String sTitle = String(ModuleRes(_nResId));
167 m_aStartMarker.setTitle(sTitle);
168 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
170 return bRet;
172 // -----------------------------------------------------------------------------
173 bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OGroupHelper> _pIsSectionOn)
175 OGroupHelper aGroupHelper(_xGroup);
176 const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection.getSection() ;
177 if ( bRet )
179 OUString sExpression = _xGroup->getExpression();
180 OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
181 if ( !sLabel.isEmpty() )
183 sExpression = sLabel;
186 String sTitle = ModuleRes(_nResId).toString();
187 sTitle.SearchAndReplace(OUString('#') ,sExpression);
188 m_aStartMarker.setTitle(sTitle);
189 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
191 return bRet;
193 //------------------------------------------------------------------------------
194 void OSectionWindow::ImplInitSettings()
196 static bool t = false;
197 if ( t )
199 EnableChildTransparentMode( sal_True );
200 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
201 SetPaintTransparent( sal_True );
203 SetBackground( );
205 //-----------------------------------------------------------------------------
206 void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
208 Window::DataChanged( rDCEvt );
210 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
211 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
213 ImplInitSettings();
214 Invalidate();
217 //------------------------------------------------------------------------------
218 void OSectionWindow::Resize()
220 Window::Resize();
222 Size aOutputSize = GetOutputSizePixel();
223 Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
224 aEndWidth *= GetMapMode().GetScaleX();
226 const Point aThumbPos = m_pParent->getView()->getThumbPos();
227 aOutputSize.Width() -= aThumbPos.X();
228 aOutputSize.Height() -= m_aSplitter.GetSizePixel().Height();
230 if ( m_aStartMarker.isCollapsed() )
232 Point aPos(0,0);
233 m_aStartMarker.SetPosSizePixel(aPos,aOutputSize);
235 else
237 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
239 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
240 aStartWidth *= GetMapMode().GetScaleX();
242 // set start marker
243 m_aStartMarker.SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
245 // set report section
246 const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
247 Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
248 Point aReportPos(aStartWidth,0);
249 aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
250 if ( bShowEndMarker )
251 aSectionSize.Width() -= (long)aEndWidth;
253 m_aReportSection.SetPosSizePixel(aReportPos,aSectionSize);
255 // set splitter
256 aReportPos.Y() += aSectionSize.Height();
257 m_aSplitter.SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter.GetSizePixel().Height()));
258 aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
259 m_aSplitter.SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
261 // set end marker
262 aReportPos.X() += aSectionSize.Width();
263 aReportPos.Y() = 0;
264 m_aEndMarker.Show(bShowEndMarker);
265 m_aEndMarker.SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
268 // -----------------------------------------------------------------------------
269 void OSectionWindow::setCollapsed(sal_Bool _bCollapsed)
271 if ( m_aStartMarker.isCollapsed() != _bCollapsed )
273 m_aStartMarker.setCollapsed(_bCollapsed);
276 //-----------------------------------------------------------------------------
277 void OSectionWindow::showProperties()
279 m_pParent->getView()->showProperties( m_aReportSection.getSection().get() );
281 //-----------------------------------------------------------------------------
282 void OSectionWindow::setMarked(sal_Bool _bMark)
284 m_aStartMarker.setMarked(_bMark);
285 m_aEndMarker.setMarked(_bMark);
287 // -----------------------------------------------------------------------------
288 IMPL_LINK( OSectionWindow, Collapsed, OColorListener *, _pMarker )
290 if ( _pMarker )
292 sal_Bool bShow = !_pMarker->isCollapsed();
293 m_aReportSection.Show(bShow);
294 m_aEndMarker.Show(bShow);
295 m_aSplitter.Show(bShow);
297 m_pParent->resize(*this);
299 return 0L;
301 // -----------------------------------------------------------------------------
302 void OSectionWindow::zoom(const Fraction& _aZoom)
304 setZoomFactor(_aZoom,*this);
305 m_aStartMarker.zoom(_aZoom);
307 setZoomFactor(_aZoom,m_aReportSection);
308 setZoomFactor(_aZoom,m_aSplitter);
309 setZoomFactor(_aZoom,m_aEndMarker);
310 Invalidate();
312 //-----------------------------------------------------------------------------
313 IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*, )
315 const String sUndoAction( ModuleRes( RID_STR_UNDO_CHANGE_SIZE ) );
316 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, String() );
317 return 0L;
319 //------------------------------------------------------------------------------
320 IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*, )
322 getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
323 return 0L;
325 //-----------------------------------------------------------------------------
326 IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
328 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
330 return 0L;
333 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
335 const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
336 nSplitPos = m_aSplitter.PixelToLogic(Size(0,nSplitPos)).Height();
338 const sal_Int32 nCount = xSection->getCount();
339 for (sal_Int32 i = 0; i < nCount; ++i)
341 uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
342 if ( xReportComponent.is() )
344 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
348 if ( nSplitPos < 0 )
349 nSplitPos = 0;
351 xSection->setHeight(nSplitPos);
352 m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,nSplitPos)).Height());
354 return 0L;
356 // -----------------------------------------------------------------------------
357 void lcl_scroll(Window& _rWindow,const Point& _aDelta)
359 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
360 _rWindow.Invalidate(INVALIDATE_TRANSPARENT);
362 // -----------------------------------------------------------------------------
363 void lcl_setOrigin(Window& _rWindow,long _nX, long _nY)
365 MapMode aMap = _rWindow.GetMapMode();
366 aMap.SetOrigin( Point(- _nX, - _nY));
367 _rWindow.SetMapMode( aMap );
369 //----------------------------------------------------------------------------
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,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,aDiff);
385 lcl_scroll(m_aEndMarker,m_aEndMarker.PixelToLogic(Point(_nX,0)));
387 lcl_setOrigin(m_aSplitter,_nX, 0);
388 lcl_scroll(m_aSplitter,aDiff);
390 //==============================================================================
391 } // rptui
392 //==============================================================================
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */