1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SectionWindow.cxx,v $
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"
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>
47 #include <vcl/svapp.hxx>
48 #include "StartMarker.hxx"
49 #include "EndMarker.hxx"
50 #include "ViewsWindow.hxx"
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
)
64 ,m_aStartMarker( this,_sColorEntry
)
65 ,m_aReportSection( this,_xSection
)
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
);
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
);
91 m_aStartMarker
.Show();
92 m_aReportSection
.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());
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
);
136 const uno::Reference
< report::XSection
> xCurrentSection
= m_aReportSection
.getSection();
137 if ( _rEvent
.PropertyName
.equals(PROPERTY_HEIGHT
) )
139 m_pParent
->getView()->SetUpdateMode(FALSE
);
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
);
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
);
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();
185 String sTitle
= String(ModuleRes(_nResId
));
186 m_aStartMarker
.setTitle(sTitle
);
187 m_aStartMarker
.Invalidate(INVALIDATE_CHILDREN
);
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() ;
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) )
205 //------------------------------------------------------------------------------
206 void OSectionWindow::ImplInitSettings()
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
) )
223 //------------------------------------------------------------------------------
224 void OSectionWindow::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() )
239 m_aStartMarker
.SetPosSizePixel(aPos
,aOutputSize
);
243 const bool bShowEndMarker
= m_pParent
->getView()->GetTotalWidth() <= (aThumbPos
.X() + aOutputSize
.Width() );
245 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
));
246 aStartWidth
*= GetMapMode().GetScaleX();
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
);
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
));
268 aReportPos
.X() += aSectionSize
.Width();
270 m_aEndMarker
.Show(bShowEndMarker
);
271 m_aEndMarker
.SetPosSizePixel(aReportPos
,Size(aEndWidth
,aOutputSize
.Height()));
274 // -----------------------------------------------------------------------------
275 void OSectionWindow::setCollapsed(sal_Bool _bCollapsed
)
277 if ( m_aStartMarker
.isCollapsed() != _bCollapsed
)
279 m_aStartMarker
.setCollapsed(_bCollapsed
);
282 //-----------------------------------------------------------------------------
283 void OSectionWindow::showProperties()
285 m_pParent
->getView()->showProperties( m_aReportSection
.getSection().get() );
287 //-----------------------------------------------------------------------------
288 void OSectionWindow::setMarked(sal_Bool _bMark
)
290 m_aStartMarker
.setMarked(_bMark
);
291 m_aEndMarker
.setMarked(_bMark
);
293 // -----------------------------------------------------------------------------
294 IMPL_LINK( OSectionWindow
, Collapsed
, OColorListener
*, _pMarker
)
298 sal_Bool bShow
= !_pMarker
->isCollapsed();
299 m_aReportSection
.Show(bShow
);
300 m_aEndMarker
.Show(bShow
);
301 m_aSplitter
.Show(bShow
);
303 m_pParent
->resize(*this);
306 // m_pParent->Invalidate(INVALIDATE_TRANSPARENT | INVALIDATE_NOCHILDREN);
311 // -----------------------------------------------------------------------------
312 void OSectionWindow::zoom(const Fraction
& _aZoom
)
314 setZoomFactor(_aZoom
,*this);
315 m_aStartMarker
.zoom(_aZoom
);
317 setZoomFactor(_aZoom
,m_aReportSection
);
318 setZoomFactor(_aZoom
,m_aSplitter
);
319 setZoomFactor(_aZoom
,m_aEndMarker
);
321 Invalidate(/*INVALIDATE_UPDATE |*/ /* | INVALIDATE_TRANSPARENT *//*INVALIDATE_NOCHILDREN*/);
323 //-----------------------------------------------------------------------------
324 IMPL_LINK( OSectionWindow
, StartSplitHdl
, Splitter
*, )
326 const String
sEmpty(ModuleRes(RID_STR_UNDO_CHANGE_SIZE
));
327 getViewsWindow()->getView()->getReportView()->getController().getUndoMgr()->EnterListAction(sEmpty
,String());
330 //------------------------------------------------------------------------------
331 IMPL_LINK( OSectionWindow
, EndSplitHdl
, Splitter
*, )
333 getViewsWindow()->getView()->getReportView()->getController().getUndoMgr()->LeaveListAction();
334 /*getViewsWindow()->Resize();*/
337 //-----------------------------------------------------------------------------
338 IMPL_LINK( OSectionWindow
, SplitHdl
, Splitter
*, _pSplitter
)
340 if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
345 sal_Int32 nSplitPos
= _pSplitter
->GetSplitPosPixel();
346 const Point aPos
= _pSplitter
->GetPosPixel();
349 const uno::Reference
< report::XSection
> xSection
= m_aReportSection
.getSection();
350 nSplitPos
= m_aSplitter
.PixelToLogic(Size(0,nSplitPos
)).Height();
351 // nSplitPos = xSection->getHeight() + m_aSplitter.PixelToLogic(Size(0,nSplitPos - aPos.Y() )).Height();
353 const sal_Int32 nCount
= xSection
->getCount();
354 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
356 uno::Reference
<report::XReportComponent
> xReportComponent(xSection
->getByIndex(i
),uno::UNO_QUERY
);
357 if ( xReportComponent
.is() /*&& nSplitPos < (xReportComponent->getPositionY() + xReportComponent->getHeight())*/ )
359 nSplitPos
= ::std::max(nSplitPos
,xReportComponent
->getPositionY() + xReportComponent
->getHeight());
361 } // for (sal_Int32 i = 0; i < nCount; ++i)
366 xSection
->setHeight(nSplitPos
);
367 m_aSplitter
.SetSplitPosPixel(m_aSplitter
.LogicToPixel(Size(0,nSplitPos
)).Height());
371 // -----------------------------------------------------------------------------
372 void lcl_scroll(Window
& _rWindow
,const Point
& _aDelta
)
374 _rWindow
.Scroll(-_aDelta
.X(),-_aDelta
.Y()/*,SCROLL_CHILDREN*//*|SCROLL_CLIP*/);
375 _rWindow
.Invalidate(INVALIDATE_TRANSPARENT
);
377 // -----------------------------------------------------------------------------
378 void lcl_setOrigin(Window
& _rWindow
,long _nX
, long _nY
)
380 MapMode aMap
= _rWindow
.GetMapMode();
381 aMap
.SetOrigin( Point(- _nX
, - _nY
));
382 _rWindow
.SetMapMode( aMap
);
384 //----------------------------------------------------------------------------
385 void OSectionWindow::scrollChildren(long _nX
)
387 const Point
aDelta( _nX
,0 );
389 MapMode
aMapMode( m_aReportSection
.GetMapMode() );
390 const Point aOld
= aMapMode
.GetOrigin();
391 lcl_setOrigin(m_aReportSection
,aDelta
.X(), 0);
393 aMapMode
= m_aReportSection
.GetMapMode();
394 const Point aNew
= aMapMode
.GetOrigin();
395 const Point aDiff
= aOld
- aNew
;
397 //OWindowPositionCorrector aCorrector(&m_aReportSection,-aDelta.Width(),0);
398 lcl_scroll(m_aReportSection
,aDiff
);
401 //lcl_setOrigin(m_aEndMarker,_nDeltaX, 0);
402 lcl_scroll(m_aEndMarker
,m_aEndMarker
.PixelToLogic(Point(_nX
,0)));
404 lcl_setOrigin(m_aSplitter
,_nX
, 0);
405 lcl_scroll(m_aSplitter
,aDiff
);
409 //==============================================================================
411 //==============================================================================