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 "ReportWindow.hxx"
20 #include "ReportSection.hxx"
21 #include "SectionView.hxx"
22 #include "ViewsWindow.hxx"
23 #include "DesignView.hxx"
24 #include "UITools.hxx"
26 #include <tools/debug.hxx>
27 #include <svtools/colorcfg.hxx>
28 #include <svl/itempool.hxx>
29 #include <unotools/syslocale.hxx>
31 #include <vcl/settings.hxx>
34 #include "dlgedfunc.hxx"
35 #include "RptModel.hxx"
36 #include "uistrings.hrc"
37 #include "RptPage.hxx"
38 #include "ReportController.hxx"
39 #include "EndMarker.hxx"
40 #include "ColorChanger.hxx"
41 #include "ScrollHelper.hxx"
43 #include "helpids.hrc"
44 #include "dlgedfac.hxx"
45 #include <boost/shared_ptr.hpp>
46 #include <toolkit/helper/vclunohelper.hxx>
49 #define SECTION_OFFSET 3
52 using namespace ::com::sun::star
;
53 using namespace ::comphelper
;
55 // class OReportWindow
58 OReportWindow::OReportWindow(OScrollWindowHelper
* _pParent
,ODesignView
* _pView
)
59 : Window(_pParent
,WB_DIALOGCONTROL
)
60 , ::comphelper::OPropertyChangeListener(m_aMutex
)
61 ,m_aHRuler(VclPtr
<Ruler
>::Create(this))
64 ,m_aViewsWindow(VclPtr
<rptui::OViewsWindow
>::Create(this))
65 ,m_pObjFac( new DlgEdFactory() )
67 SetHelpId(UID_RPT_REPORTWINDOW
);
68 SetMapMode( MapMode( MAP_100TH_MM
) );
70 m_aViewsWindow
->Show();
73 m_aHRuler
->Activate();
74 m_aHRuler
->SetPagePos(0);
75 m_aHRuler
->SetBorders();
76 m_aHRuler
->SetIndents();
77 m_aHRuler
->SetMargin1();
78 m_aHRuler
->SetMargin2();
79 const MeasurementSystem eSystem
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
80 m_aHRuler
->SetUnit(MEASURE_METRIC
== eSystem
? FUNIT_CM
: FUNIT_INCH
);
83 m_pReportListener
= addStyleListener(_pView
->getController().getReportDefinition(),this);
86 OReportWindow::~OReportWindow()
91 void OReportWindow::dispose()
93 if ( m_pReportListener
.is() )
94 m_pReportListener
->dispose();
95 m_aHRuler
.disposeAndClear();
96 m_aViewsWindow
.disposeAndClear();
99 vcl::Window::dispose();
102 void OReportWindow::SetInsertObj( sal_uInt16 eObj
,const OUString
& _sShapeType
)
104 m_aViewsWindow
->SetInsertObj( eObj
,_sShapeType
);
107 OUString
OReportWindow::GetInsertObjString() const
109 return m_aViewsWindow
->GetInsertObjString();
112 void OReportWindow::SetMode( DlgEdMode eNewMode
)
114 m_aViewsWindow
->SetMode(eNewMode
);
117 void OReportWindow::removeSection(sal_uInt16 _nPosition
)
119 m_aViewsWindow
->removeSection(_nPosition
);
120 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
121 m_aViewsWindow
->Invalidate(INVALIDATE_TRANSPARENT
);
124 void OReportWindow::addSection(const uno::Reference
< report::XSection
>& _xSection
,const OUString
& _sColorEntry
,sal_uInt16 _nPosition
)
126 if ( !_xSection
.is() )
129 m_aViewsWindow
->addSection(_xSection
,_sColorEntry
,_nPosition
);
131 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
134 void OReportWindow::toggleGrid(bool _bVisible
)
136 m_aViewsWindow
->toggleGrid(_bVisible
);
139 void OReportWindow::showRuler(bool _bShow
)
141 m_aHRuler
->Show(_bShow
);
143 m_aViewsWindow
->showRuler(_bShow
);
146 sal_Int32
OReportWindow::getMaxMarkerWidth(bool _bWithEnd
) const
148 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
));
149 aStartWidth
*= m_aViewsWindow
->GetMapMode().GetScaleX();
151 aStartWidth
+= Fraction(long(REPORT_ENDMARKER_WIDTH
));
152 return sal_Int32((long)aStartWidth
);
155 sal_Int32
OReportWindow::GetTotalWidth() const
157 sal_Int32 nWidth
= 0;
158 if ( !m_aViewsWindow
->empty() )
160 Fraction
aStartWidth(long(REPORT_ENDMARKER_WIDTH
+ REPORT_STARTMARKER_WIDTH
));
161 const Fraction
aZoom(m_pView
->getController().getZoomValue(),100);
162 aStartWidth
*= aZoom
;
163 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(m_pView
->getController().getReportDefinition(),PROPERTY_PAPERSIZE
).Width
;
164 Fraction
aPaperWidth(nPaperWidth
,1);
165 aPaperWidth
*= aZoom
;
166 const Size aPageSize
= LogicToPixel(Size(aPaperWidth
,0));
167 nWidth
= aPageSize
.Width() + long(aStartWidth
);
172 void OReportWindow::Resize()
175 if ( !m_aViewsWindow
->empty() )
177 const Size aTotalOutputSize
= GetOutputSizePixel();
178 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
)*m_pView
->getController().getZoomValue(),100);
180 const Point aOffset
= LogicToPixel( Point( SECTION_OFFSET
, 0 ), MAP_APPFONT
);
181 Point
aStartPoint((long)aStartWidth
+ aOffset
.X(),0);
182 uno::Reference
<report::XReportDefinition
> xReportDefinition
= getReportView()->getController().getReportDefinition();
183 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(xReportDefinition
,PROPERTY_PAPERSIZE
).Width
;
184 sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
185 sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
186 Size aPageSize
= m_aViewsWindow
->LogicToPixel(Size(nPaperWidth
,0));
187 nLeftMargin
= m_aViewsWindow
->LogicToPixel(Size(nLeftMargin
,0)).Width();
188 nRightMargin
= m_aViewsWindow
->LogicToPixel(Size(nRightMargin
,0)).Width();
190 aPageSize
.Height() = m_aHRuler
->GetSizePixel().Height();
192 const long nTermp(m_aViewsWindow
->getTotalHeight() + aPageSize
.Height());
193 long nSectionsHeight
= ::std::max
<long>(nTermp
,aTotalOutputSize
.Height());
195 m_aHRuler
->SetPosSizePixel(aStartPoint
,aPageSize
);
196 m_aHRuler
->SetNullOffset(nLeftMargin
);
197 m_aHRuler
->SetMargin1(0);
198 m_aHRuler
->SetMargin2(aPageSize
.Width() - nLeftMargin
- nRightMargin
);
200 aStartPoint
.Y() += aPageSize
.Height();
201 nSectionsHeight
-= aStartPoint
.Y();
203 aStartPoint
.X() = aOffset
.X();
205 m_aViewsWindow
->SetPosSizePixel(aStartPoint
,Size(aTotalOutputSize
.Width(),nSectionsHeight
));
209 Point
OReportWindow::getThumbPos() const
211 return m_pParent
->getThumbPos();
214 void OReportWindow::ImplInitSettings()
219 void OReportWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
221 Window::DataChanged( rDCEvt
);
223 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
224 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
231 sal_Int32
OReportWindow::GetTotalHeight() const
233 return m_aViewsWindow
->getTotalHeight();
236 void OReportWindow::ScrollChildren(const Point
& _aThumbPos
)
238 MapMode aMap
= m_aHRuler
->GetMapMode();
239 Point
aOrg( aMap
.GetOrigin() );
240 if ( aOrg
.X() != (-_aThumbPos
.X()) )
242 aMap
.SetOrigin( Point(- _aThumbPos
.X(), aOrg
.Y()));
243 m_aHRuler
->SetMapMode( aMap
);
244 m_aHRuler
->Scroll(-(aOrg
.X() + _aThumbPos
.X()),0);
247 m_aViewsWindow
->scrollChildren(_aThumbPos
);
250 sal_uInt16
OReportWindow::getSectionCount() const
252 return m_aViewsWindow
->getSectionCount();
255 void OReportWindow::notifySizeChanged()
257 m_pParent
->setTotalSize(GetTotalWidth(),GetTotalHeight());
260 bool OReportWindow::HasSelection() const
262 return m_aViewsWindow
->HasSelection();
265 void OReportWindow::Delete()
268 m_aViewsWindow
->Delete();
271 void OReportWindow::Copy()
274 m_aViewsWindow
->Copy();
277 void OReportWindow::Paste()
280 m_aViewsWindow
->Paste();
283 bool OReportWindow::IsPasteAllowed() const
285 return m_aViewsWindow
->IsPasteAllowed();
288 void OReportWindow::SelectAll(const sal_uInt16 _nObjectType
)
291 m_aViewsWindow
->SelectAll(_nObjectType
);
294 void OReportWindow::unmarkAllObjects(OSectionView
* _pSectionView
)
297 m_aViewsWindow
->unmarkAllObjects(_pSectionView
);
300 void OReportWindow::showProperties(const uno::Reference
< report::XSection
>& _xReportComponent
)
302 OSectionWindow
* pSectionWindow
= m_aViewsWindow
->getSectionWindow( _xReportComponent
);
303 m_pView
->UpdatePropertyBrowserDelayed(pSectionWindow
->getReportSection().getSectionView());
306 bool OReportWindow::handleKeyEvent(const KeyEvent
& _rEvent
)
308 return m_aViewsWindow
->handleKeyEvent(_rEvent
);
311 void OReportWindow::setMarked(OSectionView
* _pSectionView
, bool _bMark
)
314 m_aViewsWindow
->setMarked(_pSectionView
,_bMark
);
317 void OReportWindow::setMarked(const uno::Reference
< report::XSection
>& _xSection
, bool _bMark
)
320 m_aViewsWindow
->setMarked(_xSection
,_bMark
);
323 void OReportWindow::setMarked(const uno::Sequence
< uno::Reference
< report::XReportComponent
> >& _xShape
, bool _bMark
)
326 m_aViewsWindow
->setMarked(_xShape
,_bMark
);
329 OSectionWindow
* OReportWindow::getMarkedSection(NearSectionAccess nsa
) const
331 return m_aViewsWindow
->getMarkedSection(nsa
);
334 OSectionWindow
* OReportWindow::getSectionWindow(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
) const
336 return m_aViewsWindow
->getSectionWindow(_xSection
);
339 void OReportWindow::markSection(const sal_uInt16 _nPos
)
342 m_aViewsWindow
->markSection(_nPos
);
345 void OReportWindow::fillCollapsedSections(::std::vector
<sal_uInt16
>& _rCollapsedPositions
) const
348 m_aViewsWindow
->fillCollapsedSections(_rCollapsedPositions
);
351 void OReportWindow::collapseSections(const uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aCollpasedSections
)
354 m_aViewsWindow
->collapseSections(_aCollpasedSections
);
357 void OReportWindow::alignMarkedObjects(sal_Int32 _nControlModification
,bool _bAlignAtSection
, bool bBoundRects
)
360 m_aViewsWindow
->alignMarkedObjects(_nControlModification
, _bAlignAtSection
, bBoundRects
);
363 void OReportWindow::setGridSnap(bool bOn
)
366 m_aViewsWindow
->setGridSnap(bOn
);
369 void OReportWindow::setDragStripes(bool bOn
)
371 m_aViewsWindow
->setDragStripes(bOn
);
374 sal_uInt32
OReportWindow::getMarkedObjectCount() const
376 return m_aViewsWindow
->getMarkedObjectCount();
379 void OReportWindow::zoom(const Fraction
& _aZoom
)
381 m_aHRuler
->SetZoom(_aZoom
);
382 m_aHRuler
->Invalidate();
384 m_aViewsWindow
->zoom(_aZoom
);
387 const Point
aNewThumbPos( m_pParent
->getThumbPos() );
389 ScrollChildren( aNewThumbPos
);
392 Invalidate(INVALIDATE_NOERASE
| INVALIDATE_NOCHILDREN
| INVALIDATE_TRANSPARENT
);
395 void OReportWindow::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
397 m_aViewsWindow
->fillControlModelSelection(_rSelection
);
400 sal_Int32
OReportWindow::impl_getRealPixelWidth() const
402 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(m_pView
->getController().getReportDefinition(),PROPERTY_PAPERSIZE
).Width
;
403 MapMode
aMap( MAP_100TH_MM
);
404 const Size aPageSize
= LogicToPixel(Size(nPaperWidth
,0),aMap
);
405 return aPageSize
.Width() + REPORT_ENDMARKER_WIDTH
+ REPORT_STARTMARKER_WIDTH
+ SECTION_OFFSET
;
408 sal_uInt16
OReportWindow::getZoomFactor(SvxZoomType _eType
) const
410 sal_uInt16
nZoom(100);
411 const Size
aSize( GetSizePixel() );
414 case SvxZoomType::PERCENT
:
415 nZoom
= m_pView
->getController().getZoomValue();
417 case SvxZoomType::OPTIMAL
:
419 case SvxZoomType::WHOLEPAGE
:
421 nZoom
= (sal_uInt16
)(long)Fraction(aSize
.Width()*100,impl_getRealPixelWidth());
422 MapMode
aMap( MAP_100TH_MM
);
423 const Size aHeight
= m_aViewsWindow
->LogicToPixel(m_aViewsWindow
->PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler
->GetSizePixel().Height())),aMap
);
424 nZoom
= ::std::min(nZoom
,(sal_uInt16
)(long)Fraction(aSize
.Height()*100,aHeight
.Height()));
427 case SvxZoomType::PAGEWIDTH
:
428 nZoom
= (sal_uInt16
)(long)Fraction(aSize
.Width()*100,impl_getRealPixelWidth());
437 void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
) throw( uno::RuntimeException
)
441 m_aViewsWindow
->Resize();
442 static sal_Int32 nIn
= INVALIDATE_TRANSPARENT
;
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */