sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / report / SectionWindow.cxx
blob91e445c1d99ca891278fb5d12c74753156656654
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SectionWindow.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "SectionWindow.hxx"
32 #include "ReportWindow.hxx"
33 #include "ReportRuler.hxx"
34 #include "rptui_slotid.hrc"
35 #include <svtools/colorcfg.hxx>
36 #include "ReportController.hxx"
37 #include "SectionView.hxx"
38 #include "RptDef.hxx"
39 #include "ReportSection.hxx"
40 #include "DesignView.hxx"
41 #include "uistrings.hrc"
42 #include "helpids.hrc"
43 #include "RptResId.hrc"
44 #include <boost/bind.hpp>
45 #include <functional>
46 #include <algorithm>
47 #include <vcl/svapp.hxx>
48 #include "StartMarker.hxx"
49 #include "EndMarker.hxx"
50 #include "ViewsWindow.hxx"
52 namespace rptui
54 #define SECTION_OFFSET 3
56 using namespace ::com::sun::star;
57 using namespace ::comphelper;
59 DBG_NAME( rpt_OSectionWindow )
60 OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry)
61 : Window( _pParent,WB_DIALOGCONTROL)
62 ,OPropertyChangeListener(m_aMutex)
63 ,m_pParent(_pParent)
64 ,m_aStartMarker( this,_sColorEntry)
65 ,m_aReportSection( this,_xSection)
66 ,m_aSplitter(this)
67 ,m_aEndMarker( this,_sColorEntry)
69 DBG_CTOR( rpt_OSectionWindow,NULL);
70 SetUniqueId(UID_RPT_SECTIONSWINDOW);
71 const MapMode& rMapMode = _pParent->GetMapMode();
72 SetMapMode( rMapMode );
73 ImplInitSettings();
74 // TRY
75 m_aSplitter.SetMapMode( MapMode( MAP_100TH_MM ) );
76 m_aSplitter.SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
77 m_aSplitter.SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
78 m_aSplitter.SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
79 m_aSplitter.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
80 m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,_xSection->getHeight())).Height());
83 m_aStartMarker.setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
85 m_aStartMarker.zoom(rMapMode.GetScaleX());
86 setZoomFactor(rMapMode.GetScaleX(),m_aReportSection);
87 setZoomFactor(rMapMode.GetScaleX(),m_aSplitter);
88 setZoomFactor(rMapMode.GetScaleX(),m_aEndMarker);
90 m_aSplitter.Show();
91 m_aStartMarker.Show();
92 m_aReportSection.Show();
93 m_aEndMarker.Show();
94 Show();
96 m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
97 m_pSectionMulti->addProperty(PROPERTY_NAME);
98 m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
100 beans::PropertyChangeEvent aEvent;
101 aEvent.Source = _xSection;
102 aEvent.PropertyName = PROPERTY_NAME;
103 uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
104 if ( xGroup.is() )
106 m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
107 m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
108 aEvent.Source = xGroup;
109 aEvent.PropertyName = PROPERTY_EXPRESSION;
112 _propertyChanged(aEvent);
113 SetPaintTransparent(TRUE);
115 // -----------------------------------------------------------------------------
116 OSectionWindow::~OSectionWindow()
118 DBG_DTOR( rpt_OSectionWindow,NULL);
121 if ( m_pSectionMulti.is() )
122 m_pSectionMulti->dispose();
123 if ( m_pGroupMulti.is() )
124 m_pGroupMulti->dispose();
126 catch (uno::Exception&)
130 // -----------------------------------------------------------------------------
131 void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
133 const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
134 if ( xSection.is() )
136 const uno::Reference< report::XSection> xCurrentSection = m_aReportSection.getSection();
137 if ( _rEvent.PropertyName.equals(PROPERTY_HEIGHT) )
139 m_pParent->getView()->SetUpdateMode(FALSE);
140 Resize();
141 m_pParent->getView()->notifySizeChanged();
142 m_pParent->resize(*this);
143 m_pParent->getView()->SetUpdateMode(TRUE);
144 m_aStartMarker.Invalidate(INVALIDATE_NOERASE);
145 m_aEndMarker.Invalidate(INVALIDATE_NOERASE);
146 m_aReportSection.Invalidate(/*INVALIDATE_NOERASE*/);
147 getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
148 // Invalidate(INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
149 // m_pParent->Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_NOERASE|INVALIDATE_TRANSPARENT);
150 // m_pParent->Invalidate(/*INVALIDATE_NOCHILDREN | INVALIDATE_NOERASE |*/ INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
152 else if ( _rEvent.PropertyName.equals(PROPERTY_NAME) && !xSection->getGroup().is() )
154 uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
155 if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
156 || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
157 || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
158 || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
159 m_aStartMarker.Invalidate(INVALIDATE_NOERASE);
160 else
162 String sTitle = String(ModuleRes(RID_STR_DETAIL));
163 m_aStartMarker.setTitle(sTitle);
164 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
167 } // if ( xSection.is() )
168 else if ( _rEvent.PropertyName.equals(PROPERTY_EXPRESSION) )
170 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
171 if ( xGroup.is() )
173 if ( !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)) )
174 setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
178 // -----------------------------------------------------------------------------
179 bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,USHORT _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OReportHelper> _pIsSectionOn)
181 OReportHelper aReportHelper(_xReport);
182 const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection.getSection();
183 if ( bRet )
185 String sTitle = String(ModuleRes(_nResId));
186 m_aStartMarker.setTitle(sTitle);
187 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
188 } // if ( bRet )
189 return bRet;
191 // -----------------------------------------------------------------------------
192 bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,USHORT _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OGroupHelper> _pIsSectionOn)
194 OGroupHelper aGroupHelper(_xGroup);
195 const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection.getSection() ;
196 if ( bRet )
198 String sTitle = String(ModuleRes(_nResId));
199 sTitle.SearchAndReplace('#',_xGroup->getExpression());
200 m_aStartMarker.setTitle(sTitle);
201 m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
202 } // if ( _pIsSectionOn(&aGroupHelper) )
203 return bRet;
205 //------------------------------------------------------------------------------
206 void OSectionWindow::ImplInitSettings()
208 SetBackground( );
209 //SetBackground( Wallpaper( COL_RED ));
211 //-----------------------------------------------------------------------------
212 void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
214 Window::DataChanged( rDCEvt );
216 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
217 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
219 ImplInitSettings();
220 Invalidate();
223 //------------------------------------------------------------------------------
224 void OSectionWindow::Resize()
226 Window::Resize();
228 Size aOutputSize = GetOutputSizePixel();
229 Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
230 aEndWidth *= GetMapMode().GetScaleX();
232 const Point aThumbPos = m_pParent->getView()->getThumbPos();
233 aOutputSize.Width() -= aThumbPos.X();
234 aOutputSize.Height() -= m_aSplitter.GetSizePixel().Height();
236 if ( m_aStartMarker.isCollapsed() )
238 Point aPos(0,0);
239 m_aStartMarker.SetPosSizePixel(aPos,aOutputSize);
241 else
243 const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
245 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
246 aStartWidth *= GetMapMode().GetScaleX();
248 // set start marker
249 m_aStartMarker.SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
251 // set report section
252 const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
253 Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
254 Point aReportPos(aStartWidth,0);
255 aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
256 if ( bShowEndMarker )
257 aSectionSize.Width() -= (long)aEndWidth;
259 m_aReportSection.SetPosSizePixel(aReportPos,aSectionSize);
261 // set splitter
262 aReportPos.Y() += aSectionSize.Height();
263 m_aSplitter.SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter.GetSizePixel().Height()));
264 aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
265 m_aSplitter.SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
267 // set end marker
268 aReportPos.X() += aSectionSize.Width();
269 aReportPos.Y() = 0;
270 m_aEndMarker.Show(bShowEndMarker);
271 m_aEndMarker.SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
274 // -----------------------------------------------------------------------------
275 void OSectionWindow::setCollapsed(sal_Bool _bCollapsed)
277 m_aReportSection.Show(_bCollapsed);
278 m_aEndMarker.Show(_bCollapsed);
279 m_aSplitter.Show(_bCollapsed);
281 //-----------------------------------------------------------------------------
282 void OSectionWindow::showProperties()
284 m_pParent->getView()->showProperties( m_aReportSection.getSection().get() );
286 //-----------------------------------------------------------------------------
287 void OSectionWindow::setMarked(sal_Bool _bMark)
289 m_aStartMarker.setMarked(_bMark);
290 m_aEndMarker.setMarked(_bMark);
292 // -----------------------------------------------------------------------------
293 IMPL_LINK( OSectionWindow, Collapsed, OStartMarker *, _pMarker )
295 if ( _pMarker )
297 setCollapsed(!_pMarker->isCollapsed());
298 m_pParent->resize(*this);
299 Resize();
300 // TRY
301 // m_pParent->Invalidate(INVALIDATE_TRANSPARENT | INVALIDATE_NOCHILDREN);
302 Invalidate();
303 // _pMarker->Invalidate();
305 return 0L;
307 // -----------------------------------------------------------------------------
308 void OSectionWindow::zoom(const Fraction& _aZoom)
310 setZoomFactor(_aZoom,*this);
311 m_aStartMarker.zoom(_aZoom);
313 setZoomFactor(_aZoom,m_aReportSection);
314 setZoomFactor(_aZoom,m_aSplitter);
315 setZoomFactor(_aZoom,m_aEndMarker);
316 //Resize();
317 Invalidate(/*INVALIDATE_UPDATE |*/ /* | INVALIDATE_TRANSPARENT *//*INVALIDATE_NOCHILDREN*/);
319 //-----------------------------------------------------------------------------
320 IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*, )
322 const String sEmpty(ModuleRes(RID_STR_UNDO_CHANGE_SIZE));
323 getViewsWindow()->getView()->getReportView()->getController().getUndoMgr()->EnterListAction(sEmpty,String());
324 return 0L;
326 //------------------------------------------------------------------------------
327 IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*, )
329 getViewsWindow()->getView()->getReportView()->getController().getUndoMgr()->LeaveListAction();
330 /*getViewsWindow()->Resize();*/
331 return 0L;
333 //-----------------------------------------------------------------------------
334 IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
336 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
338 return 0L;
341 sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
342 const Point aPos = _pSplitter->GetPosPixel();
345 const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
346 nSplitPos = m_aSplitter.PixelToLogic(Size(0,nSplitPos)).Height();
347 // nSplitPos = xSection->getHeight() + m_aSplitter.PixelToLogic(Size(0,nSplitPos - aPos.Y() )).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() /*&& nSplitPos < (xReportComponent->getPositionY() + xReportComponent->getHeight())*/ )
355 nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
357 } // for (sal_Int32 i = 0; i < nCount; ++i)
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;
367 // -----------------------------------------------------------------------------
368 void lcl_scroll(Window& _rWindow,const Point& _aDelta)
370 _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y()/*,SCROLL_CHILDREN*//*|SCROLL_CLIP*/);
371 _rWindow.Invalidate(INVALIDATE_TRANSPARENT);
373 // -----------------------------------------------------------------------------
374 void lcl_setOrigin(Window& _rWindow,long _nX, long _nY)
376 MapMode aMap = _rWindow.GetMapMode();
377 aMap.SetOrigin( Point(- _nX, - _nY));
378 _rWindow.SetMapMode( aMap );
380 //----------------------------------------------------------------------------
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,aDelta.X(), 0);
389 aMapMode = m_aReportSection.GetMapMode();
390 const Point aNew = aMapMode.GetOrigin();
391 const Point aDiff = aOld - aNew;
393 //OWindowPositionCorrector aCorrector(&m_aReportSection,-aDelta.Width(),0);
394 lcl_scroll(m_aReportSection,aDiff);
397 //lcl_setOrigin(m_aEndMarker,_nDeltaX, 0);
398 lcl_scroll(m_aEndMarker,m_aEndMarker.PixelToLogic(Point(_nX,0)));
400 lcl_setOrigin(m_aSplitter,_nX, 0);
401 lcl_scroll(m_aSplitter,aDiff);
403 Resize();
405 //==============================================================================
406 } // rptui
407 //==============================================================================