Update ooo320-m1
[ooovba.git] / reportdesign / source / ui / report / ReportWindow.cxx
blob6cd1b418ebefdc7cec2045cf9f437dda81ac62bd
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: ReportWindow.cxx,v $
10 * $Revision: 1.9 $
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 "ReportWindow.hxx"
32 #include "ReportSection.hxx"
33 #include "SectionView.hxx"
34 #include "ViewsWindow.hxx"
35 #include "ReportRuler.hxx"
36 #include "DesignView.hxx"
38 #include <tools/debug.hxx>
39 #include <svtools/colorcfg.hxx>
40 #include <svtools/itempool.hxx>
41 #include <svtools/syslocale.hxx>
43 #include "RptDef.hxx"
44 #include "dlgedfunc.hxx"
45 #include "RptModel.hxx"
46 #include "uistrings.hrc"
47 #include "RptPage.hxx"
48 #include "ReportController.hxx"
49 #include "EndMarker.hxx"
50 #include "ColorChanger.hxx"
51 #include "ScrollHelper.hxx"
53 #include "helpids.hrc"
54 #include "dlgedfac.hxx"
55 #include <boost/bind.hpp>
56 #include <toolkit/helper/vclunohelper.hxx>
59 #define SECTION_OFFSET 3
60 namespace rptui
62 using namespace ::com::sun::star;
63 using namespace ::comphelper;
64 //==================================================================
65 // class OReportWindow
66 //==================================================================
67 DBG_NAME( rpt_OReportWindow )
68 //------------------------------------------------------------------------------
69 OReportWindow::OReportWindow(OScrollWindowHelper* _pParent,ODesignView* _pView)
70 : Window(_pParent,WB_DIALOGCONTROL)
71 ,m_aHRuler(this)
72 ,m_pView(_pView)
73 ,m_pParent(_pParent)
74 ,m_aViewsWindow(this)
75 ,m_pObjFac( new DlgEdFactory() )
77 DBG_CTOR( rpt_OReportWindow,NULL);
78 SetHelpId(UID_RPT_REPORTWINDOW);
79 SetMapMode( MapMode( MAP_100TH_MM ) );
81 m_aViewsWindow.Show();
83 m_aHRuler.Show();
84 m_aHRuler.Activate();
85 m_aHRuler.SetPagePos(0);
86 m_aHRuler.SetBorders();
87 m_aHRuler.SetIndents();
88 m_aHRuler.SetMargin1();
89 m_aHRuler.SetMargin2();
90 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
91 m_aHRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
93 ImplInitSettings();
95 //------------------------------------------------------------------------------
96 OReportWindow::~OReportWindow()
98 DBG_DTOR( rpt_OReportWindow,NULL);
100 // -----------------------------------------------------------------------------
101 void OReportWindow::initialize()
103 m_aViewsWindow.initialize();
105 //----------------------------------------------------------------------------
106 void OReportWindow::SetInsertObj( USHORT eObj,const ::rtl::OUString& _sShapeType )
108 m_aViewsWindow.SetInsertObj( eObj,_sShapeType);
111 //----------------------------------------------------------------------------
112 rtl::OUString OReportWindow::GetInsertObjString() const
114 return m_aViewsWindow.GetInsertObjString();
116 //------------------------------------------------------------------------------
117 void OReportWindow::SetMode( DlgEdMode eNewMode )
119 m_aViewsWindow.SetMode(eNewMode);
121 //----------------------------------------------------------------------------
122 void OReportWindow::removeSection(USHORT _nPosition)
124 m_aViewsWindow.removeSection(_nPosition);
125 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
126 m_aViewsWindow.Invalidate(INVALIDATE_TRANSPARENT);
127 //Resize();
129 //----------------------------------------------------------------------------
130 void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry,USHORT _nPosition)
132 if ( !_xSection.is() )
133 return;
135 m_aViewsWindow.addSection(_xSection,_sColorEntry,_nPosition);
137 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
139 //------------------------------------------------------------------------------
140 void OReportWindow::toggleGrid(sal_Bool _bVisible)
142 m_aViewsWindow.toggleGrid(_bVisible);
144 //----------------------------------------------------------------------------
145 void OReportWindow::showRuler(sal_Bool _bShow)
147 m_aHRuler.Show(_bShow);
149 m_aViewsWindow.showRuler(_bShow);
151 //------------------------------------------------------------------------------
152 sal_Int32 OReportWindow::getMaxMarkerWidth(sal_Bool _bWithEnd) const
154 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
155 aStartWidth *= m_aViewsWindow.GetMapMode().GetScaleX();
156 if ( _bWithEnd )
157 aStartWidth += Fraction(long(REPORT_ENDMARKER_WIDTH));
158 return sal_Int32((long)aStartWidth);
160 //------------------------------------------------------------------------------
161 sal_Int32 OReportWindow::GetTotalWidth() const
163 sal_Int32 nWidth = 0;
164 if ( !m_aViewsWindow.empty() )
166 Fraction aStartWidth(long(REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH ));
167 const Fraction aZoom(m_pView->getController().getZoomValue(),100);
168 aStartWidth *= aZoom; // m_aViewsWindow.GetMapMode().GetScaleX();;
169 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
170 Fraction aPaperWidth(nPaperWidth,1);
171 aPaperWidth *= aZoom;
172 const Size aPageSize = LogicToPixel(Size(aPaperWidth,0));
173 nWidth = aPageSize.Width() + long(aStartWidth);
175 return nWidth;
177 //------------------------------------------------------------------------------
178 void OReportWindow::Resize()
180 Window::Resize();
181 if ( !m_aViewsWindow.empty() )
183 const Size aTotalOutputSize = GetOutputSizePixel();
184 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
186 const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, 0 ), MAP_APPFONT );
187 Point aStartPoint((long)aStartWidth + aOffset.X(),0);
188 uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
189 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
190 sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
191 sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
192 Size aPageSize = m_aViewsWindow.LogicToPixel(Size(nPaperWidth ,0));
193 nLeftMargin = m_aViewsWindow.LogicToPixel(Size(nLeftMargin,0)).Width();
194 nRightMargin = m_aViewsWindow.LogicToPixel(Size(nRightMargin,0)).Width();
196 aPageSize.Height() = m_aHRuler.GetSizePixel().Height();
198 const long nTermp(m_aViewsWindow.getTotalHeight() + aPageSize.Height());
199 long nSectionsHeight = ::std::max<long>(nTermp,aTotalOutputSize.Height());
201 m_aHRuler.SetPosSizePixel(aStartPoint,aPageSize);
202 m_aHRuler.SetNullOffset(nLeftMargin);
203 m_aHRuler.SetMargin1(0);
204 m_aHRuler.SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
206 aStartPoint.Y() += aPageSize.Height();
207 nSectionsHeight -= aStartPoint.Y();
209 aStartPoint.X() = aOffset.X();
211 m_aViewsWindow.SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
214 //------------------------------------------------------------------------------
215 Point OReportWindow::getThumbPos() const
217 return m_pParent->getThumbPos();
219 //------------------------------------------------------------------------------
220 void OReportWindow::ImplInitSettings()
222 SetBackground( );
224 //-----------------------------------------------------------------------------
225 void OReportWindow::DataChanged( const DataChangedEvent& rDCEvt )
227 Window::DataChanged( rDCEvt );
229 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
230 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
232 ImplInitSettings();
233 Invalidate();
236 //------------------------------------------------------------------------------
237 sal_Int32 OReportWindow::GetTotalHeight() const
239 return m_aViewsWindow.getTotalHeight();
241 //------------------------------------------------------------------------------
242 void OReportWindow::ScrollChildren(const Point& _aThumbPos)
244 MapMode aMap = m_aHRuler.GetMapMode();
245 Point aOrg( aMap.GetOrigin() );
246 if ( aOrg.X() != (-_aThumbPos.X()) )
248 aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
249 m_aHRuler.SetMapMode( aMap );
250 m_aHRuler.Scroll(-(aOrg.X() + _aThumbPos.X()),0);
253 /*const Point aPos(PixelToLogic(_aThumbPos));*/
254 m_aViewsWindow.scrollChildren(_aThumbPos);
256 //----------------------------------------------------------------------------
257 USHORT OReportWindow::getSectionCount() const
259 return m_aViewsWindow.getSectionCount();
261 //----------------------------------------------------------------------------
262 void OReportWindow::notifySizeChanged()
264 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
266 //----------------------------------------------------------------------------
267 BOOL OReportWindow::HasSelection()
269 return m_aViewsWindow.HasSelection();
271 //----------------------------------------------------------------------------
272 void OReportWindow::Delete()
275 m_aViewsWindow.Delete();
277 //----------------------------------------------------------------------------
278 void OReportWindow::Copy()
281 m_aViewsWindow.Copy();
283 //----------------------------------------------------------------------------
284 void OReportWindow::Paste()
287 m_aViewsWindow.Paste();
289 //----------------------------------------------------------------------------
290 BOOL OReportWindow::IsPasteAllowed()
292 return m_aViewsWindow.IsPasteAllowed();
294 //-----------------------------------------------------------------------------
295 void OReportWindow::SelectAll(const sal_uInt16 _nObjectType)
298 m_aViewsWindow.SelectAll(_nObjectType);
300 //-----------------------------------------------------------------------------
301 void OReportWindow::unmarkAllObjects(OSectionView* _pSectionView)
304 m_aViewsWindow.unmarkAllObjects(_pSectionView);
306 //-----------------------------------------------------------------------------
307 void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
309 ::boost::shared_ptr<OSectionWindow> pSectionWindow = m_aViewsWindow.getSectionWindow( _xReportComponent );
310 m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
312 //------------------------------------------------------------------------------
313 sal_Bool OReportWindow::handleKeyEvent(const KeyEvent& _rEvent)
315 return m_aViewsWindow.handleKeyEvent(_rEvent);
317 //------------------------------------------------------------------------
318 void OReportWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
320 if ( _pSectionView )
321 m_aViewsWindow.setMarked(_pSectionView,_bMark);
323 //------------------------------------------------------------------------
324 void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
327 m_aViewsWindow.setMarked(_xSection,_bMark);
329 //------------------------------------------------------------------------
330 void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape,sal_Bool _bMark)
333 m_aViewsWindow.setMarked(_xShape,_bMark);
335 //-----------------------------------------------------------------------------
336 ::boost::shared_ptr<OSectionWindow> OReportWindow::getMarkedSection(NearSectionAccess nsa) const
338 return m_aViewsWindow.getMarkedSection(nsa);
340 //-----------------------------------------------------------------------------
341 ::boost::shared_ptr<OSectionWindow> OReportWindow::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
343 return m_aViewsWindow.getSectionWindow(_xSection);
345 // -------------------------------------------------------------------------
346 void OReportWindow::markSection(const sal_uInt16 _nPos)
349 m_aViewsWindow.markSection(_nPos);
351 // -----------------------------------------------------------------------------
352 void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
355 m_aViewsWindow.fillCollapsedSections(_rCollapsedPositions);
357 // -----------------------------------------------------------------------------
358 void OReportWindow::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections)
361 m_aViewsWindow.collapseSections(_aCollpasedSections);
363 // -----------------------------------------------------------------------------
364 void OReportWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects)
367 m_aViewsWindow.alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects);
369 // -----------------------------------------------------------------------------
370 void OReportWindow::setGridSnap(BOOL bOn)
373 m_aViewsWindow.setGridSnap(bOn);
375 // -----------------------------------------------------------------------------
376 void OReportWindow::setDragStripes(BOOL bOn)
378 m_aViewsWindow.setDragStripes(bOn);
380 // -----------------------------------------------------------------------------
381 BOOL OReportWindow::isDragStripes() const
383 return m_aViewsWindow.isDragStripes();
385 // -----------------------------------------------------------------------------
386 sal_uInt32 OReportWindow::getMarkedObjectCount() const
388 return m_aViewsWindow.getMarkedObjectCount();
390 // -----------------------------------------------------------------------------
391 void OReportWindow::zoom(const Fraction& _aZoom)
393 m_aHRuler.SetZoom(_aZoom);
394 m_aHRuler.Invalidate();
396 //setZoomFactor(_aZoom,*this); // if this will be include the H - ruler has the wrong size
397 m_aViewsWindow.zoom(_aZoom);
399 notifySizeChanged();
400 const Point aNewThumbPos( m_pParent->getThumbPos() );
402 ScrollChildren( aNewThumbPos );
403 Resize();
405 Invalidate(INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
407 // -----------------------------------------------------------------------------
408 void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
410 m_aViewsWindow.fillControlModelSelection(_rSelection);
412 // -----------------------------------------------------------------------------
413 sal_Int32 OReportWindow::impl_getRealPixelWidth() const
415 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
416 MapMode aMap( MAP_100TH_MM );
417 const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
418 return aPageSize.Width() + REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH + SECTION_OFFSET;
420 // -----------------------------------------------------------------------------
421 sal_uInt16 OReportWindow::getZoomFactor(SvxZoomType _eType) const
423 sal_uInt16 nZoom(100);
424 const Size aSize( GetSizePixel() );
425 switch( _eType)
427 case SVX_ZOOM_PERCENT:
428 nZoom = m_pView->getController().getZoomValue();
429 break;
430 case SVX_ZOOM_OPTIMAL:
431 break;
432 case SVX_ZOOM_WHOLEPAGE:
434 nZoom = (USHORT)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
435 MapMode aMap( MAP_100TH_MM );
436 const Size aHeight = m_aViewsWindow.LogicToPixel(m_aViewsWindow.PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler.GetSizePixel().Height())),aMap);
437 nZoom = ::std::min(nZoom,(USHORT)(long)Fraction(aSize.Height()*100,aHeight.Height()));
439 break;
440 case SVX_ZOOM_PAGEWIDTH:
441 nZoom = (USHORT)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
442 break;
443 default:
444 break;
447 return nZoom;
449 //==================================================================
450 } //rptui
451 //==================================================================