Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "ReportWindow.hxx"
29 : : #include "ReportSection.hxx"
30 : : #include "SectionView.hxx"
31 : : #include "ViewsWindow.hxx"
32 : : #include "ReportRuler.hxx"
33 : : #include "DesignView.hxx"
34 : : #include "UITools.hxx"
35 : :
36 : : #include <tools/debug.hxx>
37 : : #include <svtools/colorcfg.hxx>
38 : : #include <svl/itempool.hxx>
39 : : #include <unotools/syslocale.hxx>
40 : :
41 : : #include "RptDef.hxx"
42 : : #include "dlgedfunc.hxx"
43 : : #include "RptModel.hxx"
44 : : #include "uistrings.hrc"
45 : : #include "RptPage.hxx"
46 : : #include "ReportController.hxx"
47 : : #include "EndMarker.hxx"
48 : : #include "ColorChanger.hxx"
49 : : #include "ScrollHelper.hxx"
50 : :
51 : : #include "helpids.hrc"
52 : : #include "dlgedfac.hxx"
53 : : #include <boost/shared_ptr.hpp>
54 : : #include <toolkit/helper/vclunohelper.hxx>
55 : :
56 : :
57 : : #define SECTION_OFFSET 3
58 : : namespace rptui
59 : : {
60 : : using namespace ::com::sun::star;
61 : : using namespace ::comphelper;
62 : : //==================================================================
63 : : // class OReportWindow
64 : : //==================================================================
65 : : DBG_NAME( rpt_OReportWindow )
66 : : //------------------------------------------------------------------------------
67 : 0 : OReportWindow::OReportWindow(OScrollWindowHelper* _pParent,ODesignView* _pView)
68 : : : Window(_pParent,WB_DIALOGCONTROL)
69 : : , ::comphelper::OPropertyChangeListener(m_aMutex)
70 : : ,m_aHRuler(this)
71 : : ,m_pView(_pView)
72 : : ,m_pParent(_pParent)
73 : : ,m_aViewsWindow(this)
74 : 0 : ,m_pObjFac( new DlgEdFactory() )
75 : : {
76 : : DBG_CTOR( rpt_OReportWindow,NULL);
77 : 0 : SetHelpId(UID_RPT_REPORTWINDOW);
78 : 0 : SetMapMode( MapMode( MAP_100TH_MM ) );
79 : :
80 : 0 : m_aViewsWindow.Show();
81 : :
82 : 0 : m_aHRuler.Show();
83 : 0 : m_aHRuler.Activate();
84 : 0 : m_aHRuler.SetPagePos(0);
85 : 0 : m_aHRuler.SetBorders();
86 : 0 : m_aHRuler.SetIndents();
87 : 0 : m_aHRuler.SetMargin1();
88 : 0 : m_aHRuler.SetMargin2();
89 : 0 : const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
90 : 0 : m_aHRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
91 : :
92 : 0 : ImplInitSettings();
93 : 0 : m_pReportListener = addStyleListener(_pView->getController().getReportDefinition(),this);
94 : 0 : }
95 : : //------------------------------------------------------------------------------
96 : 0 : OReportWindow::~OReportWindow()
97 : : {
98 : : DBG_DTOR( rpt_OReportWindow,NULL);
99 : 0 : if ( m_pReportListener.is() )
100 : 0 : m_pReportListener->dispose();
101 : 0 : }
102 : : // -----------------------------------------------------------------------------
103 : 0 : void OReportWindow::initialize()
104 : : {
105 : 0 : m_aViewsWindow.initialize();
106 : 0 : }
107 : : //----------------------------------------------------------------------------
108 : 0 : void OReportWindow::SetInsertObj( sal_uInt16 eObj,const ::rtl::OUString& _sShapeType )
109 : : {
110 : 0 : m_aViewsWindow.SetInsertObj( eObj,_sShapeType);
111 : 0 : }
112 : :
113 : : //----------------------------------------------------------------------------
114 : 0 : rtl::OUString OReportWindow::GetInsertObjString() const
115 : : {
116 : 0 : return m_aViewsWindow.GetInsertObjString();
117 : : }
118 : : //------------------------------------------------------------------------------
119 : 0 : void OReportWindow::SetMode( DlgEdMode eNewMode )
120 : : {
121 : 0 : m_aViewsWindow.SetMode(eNewMode);
122 : 0 : }
123 : : //----------------------------------------------------------------------------
124 : 0 : void OReportWindow::removeSection(sal_uInt16 _nPosition)
125 : : {
126 : 0 : m_aViewsWindow.removeSection(_nPosition);
127 : 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
128 : 0 : m_aViewsWindow.Invalidate(INVALIDATE_TRANSPARENT);
129 : 0 : }
130 : : //----------------------------------------------------------------------------
131 : 0 : void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry,sal_uInt16 _nPosition)
132 : : {
133 : 0 : if ( !_xSection.is() )
134 : 0 : return;
135 : :
136 : 0 : m_aViewsWindow.addSection(_xSection,_sColorEntry,_nPosition);
137 : :
138 : 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
139 : : }
140 : : //------------------------------------------------------------------------------
141 : 0 : void OReportWindow::toggleGrid(sal_Bool _bVisible)
142 : : {
143 : 0 : m_aViewsWindow.toggleGrid(_bVisible);
144 : 0 : }
145 : : //----------------------------------------------------------------------------
146 : 0 : void OReportWindow::showRuler(sal_Bool _bShow)
147 : : {
148 : 0 : m_aHRuler.Show(_bShow);
149 : :
150 : 0 : m_aViewsWindow.showRuler(_bShow);
151 : 0 : }
152 : : //------------------------------------------------------------------------------
153 : 0 : sal_Int32 OReportWindow::getMaxMarkerWidth(sal_Bool _bWithEnd) const
154 : : {
155 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
156 : 0 : aStartWidth *= m_aViewsWindow.GetMapMode().GetScaleX();
157 : 0 : if ( _bWithEnd )
158 : 0 : aStartWidth += Fraction(long(REPORT_ENDMARKER_WIDTH));
159 : 0 : return sal_Int32((long)aStartWidth);
160 : : }
161 : : //------------------------------------------------------------------------------
162 : 0 : sal_Int32 OReportWindow::GetTotalWidth() const
163 : : {
164 : 0 : sal_Int32 nWidth = 0;
165 : 0 : if ( !m_aViewsWindow.empty() )
166 : : {
167 : 0 : Fraction aStartWidth(long(REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH ));
168 : 0 : const Fraction aZoom(m_pView->getController().getZoomValue(),100);
169 : 0 : aStartWidth *= aZoom;
170 : 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
171 : 0 : Fraction aPaperWidth(nPaperWidth,1);
172 : 0 : aPaperWidth *= aZoom;
173 : 0 : const Size aPageSize = LogicToPixel(Size(aPaperWidth,0));
174 : 0 : nWidth = aPageSize.Width() + long(aStartWidth);
175 : : }
176 : 0 : return nWidth;
177 : : }
178 : : //------------------------------------------------------------------------------
179 : 0 : void OReportWindow::Resize()
180 : : {
181 : 0 : Window::Resize();
182 : 0 : if ( !m_aViewsWindow.empty() )
183 : : {
184 : 0 : const Size aTotalOutputSize = GetOutputSizePixel();
185 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
186 : :
187 : 0 : const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, 0 ), MAP_APPFONT );
188 : 0 : Point aStartPoint((long)aStartWidth + aOffset.X(),0);
189 : 0 : uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
190 : 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
191 : 0 : sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
192 : 0 : sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
193 : 0 : Size aPageSize = m_aViewsWindow.LogicToPixel(Size(nPaperWidth ,0));
194 : 0 : nLeftMargin = m_aViewsWindow.LogicToPixel(Size(nLeftMargin,0)).Width();
195 : 0 : nRightMargin = m_aViewsWindow.LogicToPixel(Size(nRightMargin,0)).Width();
196 : :
197 : 0 : aPageSize.Height() = m_aHRuler.GetSizePixel().Height();
198 : :
199 : 0 : const long nTermp(m_aViewsWindow.getTotalHeight() + aPageSize.Height());
200 : 0 : long nSectionsHeight = ::std::max<long>(nTermp,aTotalOutputSize.Height());
201 : :
202 : 0 : m_aHRuler.SetPosSizePixel(aStartPoint,aPageSize);
203 : 0 : m_aHRuler.SetNullOffset(nLeftMargin);
204 : 0 : m_aHRuler.SetMargin1(0);
205 : 0 : m_aHRuler.SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
206 : :
207 : 0 : aStartPoint.Y() += aPageSize.Height();
208 : 0 : nSectionsHeight -= aStartPoint.Y();
209 : :
210 : 0 : aStartPoint.X() = aOffset.X();
211 : :
212 : 0 : m_aViewsWindow.SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
213 : : }
214 : 0 : }
215 : : //------------------------------------------------------------------------------
216 : 0 : Point OReportWindow::getThumbPos() const
217 : : {
218 : 0 : return m_pParent->getThumbPos();
219 : : }
220 : : //------------------------------------------------------------------------------
221 : 0 : void OReportWindow::ImplInitSettings()
222 : : {
223 : 0 : SetBackground( );
224 : 0 : }
225 : : //-----------------------------------------------------------------------------
226 : 0 : void OReportWindow::DataChanged( const DataChangedEvent& rDCEvt )
227 : : {
228 : 0 : Window::DataChanged( rDCEvt );
229 : :
230 : 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
231 : 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
232 : : {
233 : 0 : ImplInitSettings();
234 : 0 : Invalidate();
235 : : }
236 : 0 : }
237 : : //------------------------------------------------------------------------------
238 : 0 : sal_Int32 OReportWindow::GetTotalHeight() const
239 : : {
240 : 0 : return m_aViewsWindow.getTotalHeight();
241 : : }
242 : : //------------------------------------------------------------------------------
243 : 0 : void OReportWindow::ScrollChildren(const Point& _aThumbPos)
244 : : {
245 : 0 : MapMode aMap = m_aHRuler.GetMapMode();
246 : 0 : Point aOrg( aMap.GetOrigin() );
247 : 0 : if ( aOrg.X() != (-_aThumbPos.X()) )
248 : : {
249 : 0 : aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
250 : 0 : m_aHRuler.SetMapMode( aMap );
251 : 0 : m_aHRuler.Scroll(-(aOrg.X() + _aThumbPos.X()),0);
252 : : }
253 : :
254 : 0 : m_aViewsWindow.scrollChildren(_aThumbPos);
255 : 0 : }
256 : : //----------------------------------------------------------------------------
257 : 0 : sal_uInt16 OReportWindow::getSectionCount() const
258 : : {
259 : 0 : return m_aViewsWindow.getSectionCount();
260 : : }
261 : : //----------------------------------------------------------------------------
262 : 0 : void OReportWindow::notifySizeChanged()
263 : : {
264 : 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
265 : 0 : }
266 : : //----------------------------------------------------------------------------
267 : 0 : sal_Bool OReportWindow::HasSelection() const
268 : : {
269 : 0 : return m_aViewsWindow.HasSelection();
270 : : }
271 : : //----------------------------------------------------------------------------
272 : 0 : void OReportWindow::Delete()
273 : : {
274 : :
275 : 0 : m_aViewsWindow.Delete();
276 : 0 : }
277 : : //----------------------------------------------------------------------------
278 : 0 : void OReportWindow::Copy()
279 : : {
280 : :
281 : 0 : m_aViewsWindow.Copy();
282 : 0 : }
283 : : //----------------------------------------------------------------------------
284 : 0 : void OReportWindow::Paste()
285 : : {
286 : :
287 : 0 : m_aViewsWindow.Paste();
288 : 0 : }
289 : : //----------------------------------------------------------------------------
290 : 0 : sal_Bool OReportWindow::IsPasteAllowed() const
291 : : {
292 : 0 : return m_aViewsWindow.IsPasteAllowed();
293 : : }
294 : : //-----------------------------------------------------------------------------
295 : 0 : void OReportWindow::SelectAll(const sal_uInt16 _nObjectType)
296 : : {
297 : :
298 : 0 : m_aViewsWindow.SelectAll(_nObjectType);
299 : 0 : }
300 : : //-----------------------------------------------------------------------------
301 : 0 : void OReportWindow::unmarkAllObjects(OSectionView* _pSectionView)
302 : : {
303 : :
304 : 0 : m_aViewsWindow.unmarkAllObjects(_pSectionView);
305 : 0 : }
306 : : //-----------------------------------------------------------------------------
307 : 0 : void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
308 : : {
309 : 0 : ::boost::shared_ptr<OSectionWindow> pSectionWindow = m_aViewsWindow.getSectionWindow( _xReportComponent );
310 : 0 : m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
311 : 0 : }
312 : : //------------------------------------------------------------------------------
313 : 0 : sal_Bool OReportWindow::handleKeyEvent(const KeyEvent& _rEvent)
314 : : {
315 : 0 : return m_aViewsWindow.handleKeyEvent(_rEvent);
316 : : }
317 : : //------------------------------------------------------------------------
318 : 0 : void OReportWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
319 : : {
320 : 0 : if ( _pSectionView )
321 : 0 : m_aViewsWindow.setMarked(_pSectionView,_bMark);
322 : 0 : }
323 : : //------------------------------------------------------------------------
324 : 0 : void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
325 : : {
326 : :
327 : 0 : m_aViewsWindow.setMarked(_xSection,_bMark);
328 : 0 : }
329 : : //------------------------------------------------------------------------
330 : 0 : void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape,sal_Bool _bMark)
331 : : {
332 : :
333 : 0 : m_aViewsWindow.setMarked(_xShape,_bMark);
334 : 0 : }
335 : : //-----------------------------------------------------------------------------
336 : 0 : ::boost::shared_ptr<OSectionWindow> OReportWindow::getMarkedSection(NearSectionAccess nsa) const
337 : : {
338 : 0 : return m_aViewsWindow.getMarkedSection(nsa);
339 : : }
340 : : //-----------------------------------------------------------------------------
341 : 0 : ::boost::shared_ptr<OSectionWindow> OReportWindow::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
342 : : {
343 : 0 : return m_aViewsWindow.getSectionWindow(_xSection);
344 : : }
345 : : // -------------------------------------------------------------------------
346 : 0 : void OReportWindow::markSection(const sal_uInt16 _nPos)
347 : : {
348 : :
349 : 0 : m_aViewsWindow.markSection(_nPos);
350 : 0 : }
351 : : // -----------------------------------------------------------------------------
352 : 0 : void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
353 : : {
354 : :
355 : 0 : m_aViewsWindow.fillCollapsedSections(_rCollapsedPositions);
356 : 0 : }
357 : : // -----------------------------------------------------------------------------
358 : 0 : void OReportWindow::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections)
359 : : {
360 : :
361 : 0 : m_aViewsWindow.collapseSections(_aCollpasedSections);
362 : 0 : }
363 : : // -----------------------------------------------------------------------------
364 : 0 : void OReportWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects)
365 : : {
366 : :
367 : 0 : m_aViewsWindow.alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects);
368 : 0 : }
369 : : // -----------------------------------------------------------------------------
370 : 0 : void OReportWindow::setGridSnap(sal_Bool bOn)
371 : : {
372 : :
373 : 0 : m_aViewsWindow.setGridSnap(bOn);
374 : 0 : }
375 : : // -----------------------------------------------------------------------------
376 : 0 : void OReportWindow::setDragStripes(sal_Bool bOn)
377 : : {
378 : 0 : m_aViewsWindow.setDragStripes(bOn);
379 : 0 : }
380 : : // -----------------------------------------------------------------------------
381 : 0 : sal_uInt32 OReportWindow::getMarkedObjectCount() const
382 : : {
383 : 0 : return m_aViewsWindow.getMarkedObjectCount();
384 : : }
385 : : // -----------------------------------------------------------------------------
386 : 0 : void OReportWindow::zoom(const Fraction& _aZoom)
387 : : {
388 : 0 : m_aHRuler.SetZoom(_aZoom);
389 : 0 : m_aHRuler.Invalidate();
390 : :
391 : 0 : m_aViewsWindow.zoom(_aZoom);
392 : :
393 : 0 : notifySizeChanged();
394 : 0 : const Point aNewThumbPos( m_pParent->getThumbPos() );
395 : :
396 : 0 : ScrollChildren( aNewThumbPos );
397 : 0 : Resize();
398 : :
399 : 0 : Invalidate(INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
400 : 0 : }
401 : : // -----------------------------------------------------------------------------
402 : 0 : void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
403 : : {
404 : 0 : m_aViewsWindow.fillControlModelSelection(_rSelection);
405 : 0 : }
406 : : // -----------------------------------------------------------------------------
407 : 0 : sal_Int32 OReportWindow::impl_getRealPixelWidth() const
408 : : {
409 : 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
410 : 0 : MapMode aMap( MAP_100TH_MM );
411 : 0 : const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
412 : 0 : return aPageSize.Width() + REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH + SECTION_OFFSET;
413 : : }
414 : : // -----------------------------------------------------------------------------
415 : 0 : sal_uInt16 OReportWindow::getZoomFactor(SvxZoomType _eType) const
416 : : {
417 : 0 : sal_uInt16 nZoom(100);
418 : 0 : const Size aSize( GetSizePixel() );
419 : 0 : switch( _eType)
420 : : {
421 : : case SVX_ZOOM_PERCENT:
422 : 0 : nZoom = m_pView->getController().getZoomValue();
423 : 0 : break;
424 : : case SVX_ZOOM_OPTIMAL:
425 : 0 : break;
426 : : case SVX_ZOOM_WHOLEPAGE:
427 : : {
428 : 0 : nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
429 : 0 : MapMode aMap( MAP_100TH_MM );
430 : 0 : const Size aHeight = m_aViewsWindow.LogicToPixel(m_aViewsWindow.PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler.GetSizePixel().Height())),aMap);
431 : 0 : nZoom = ::std::min(nZoom,(sal_uInt16)(long)Fraction(aSize.Height()*100,aHeight.Height()));
432 : : }
433 : 0 : break;
434 : : case SVX_ZOOM_PAGEWIDTH:
435 : 0 : nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
436 : 0 : break;
437 : : default:
438 : 0 : break;
439 : : }
440 : :
441 : 0 : return nZoom;
442 : : }
443 : : // -----------------------------------------------------------------------------
444 : 0 : void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
445 : : {
446 : : (void)_rEvent;
447 : 0 : Resize();
448 : 0 : m_aViewsWindow.Resize();
449 : : static sal_Int32 nIn = INVALIDATE_TRANSPARENT;
450 : 0 : Invalidate(nIn);
451 : 0 : }
452 : : //==================================================================
453 : : } //rptui
454 : : //==================================================================
455 : :
456 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|