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 "SectionWindow.hxx"
29 : : #include "ReportWindow.hxx"
30 : : #include "ReportRuler.hxx"
31 : : #include "rptui_slotid.hrc"
32 : : #include "ReportController.hxx"
33 : : #include "SectionView.hxx"
34 : : #include "RptDef.hxx"
35 : : #include "ReportSection.hxx"
36 : : #include "DesignView.hxx"
37 : : #include "uistrings.hrc"
38 : : #include "helpids.hrc"
39 : : #include "RptResId.hrc"
40 : : #include "StartMarker.hxx"
41 : : #include "EndMarker.hxx"
42 : : #include "ViewsWindow.hxx"
43 : :
44 : : #include <svtools/colorcfg.hxx>
45 : : #include <functional>
46 : : #include <algorithm>
47 : : #include <vcl/svapp.hxx>
48 : : #include <connectivity/dbtools.hxx>
49 : :
50 : : namespace rptui
51 : : {
52 : : using namespace ::com::sun::star;
53 : : using namespace ::comphelper;
54 : :
55 : : DBG_NAME( rpt_OSectionWindow )
56 : 0 : OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry)
57 : : : Window( _pParent,WB_DIALOGCONTROL)
58 : : ,OPropertyChangeListener(m_aMutex)
59 : : ,m_pParent(_pParent)
60 : : ,m_aStartMarker( this,_sColorEntry)
61 : : ,m_aReportSection( this,_xSection)
62 : : ,m_aSplitter(this)
63 : 0 : ,m_aEndMarker( this,_sColorEntry)
64 : : {
65 : : DBG_CTOR( rpt_OSectionWindow,NULL);
66 : 0 : SetUniqueId(UID_RPT_SECTIONSWINDOW);
67 : 0 : const MapMode& rMapMode = _pParent->GetMapMode();
68 : 0 : SetMapMode( rMapMode );
69 : 0 : ImplInitSettings();
70 : : // TRY
71 : 0 : m_aSplitter.SetMapMode( MapMode( MAP_100TH_MM ) );
72 : 0 : m_aSplitter.SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
73 : 0 : m_aSplitter.SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
74 : 0 : m_aSplitter.SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
75 : 0 : m_aSplitter.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
76 : 0 : m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,_xSection->getHeight())).Height());
77 : :
78 : :
79 : 0 : m_aStartMarker.setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
80 : :
81 : 0 : m_aStartMarker.zoom(rMapMode.GetScaleX());
82 : 0 : setZoomFactor(rMapMode.GetScaleX(),m_aReportSection);
83 : 0 : setZoomFactor(rMapMode.GetScaleX(),m_aSplitter);
84 : 0 : setZoomFactor(rMapMode.GetScaleX(),m_aEndMarker);
85 : :
86 : 0 : m_aSplitter.Show();
87 : 0 : m_aStartMarker.Show();
88 : 0 : m_aReportSection.Show();
89 : 0 : m_aEndMarker.Show();
90 : 0 : Show();
91 : :
92 : 0 : m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
93 : 0 : m_pSectionMulti->addProperty(PROPERTY_NAME);
94 : 0 : m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
95 : :
96 : 0 : beans::PropertyChangeEvent aEvent;
97 : 0 : aEvent.Source = _xSection;
98 : 0 : aEvent.PropertyName = PROPERTY_NAME;
99 : 0 : uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
100 : 0 : if ( xGroup.is() )
101 : : {
102 : 0 : m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
103 : 0 : m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
104 : 0 : aEvent.Source = xGroup;
105 : 0 : aEvent.PropertyName = PROPERTY_EXPRESSION;
106 : : }
107 : :
108 : 0 : _propertyChanged(aEvent);
109 : 0 : }
110 : : // -----------------------------------------------------------------------------
111 : 0 : OSectionWindow::~OSectionWindow()
112 : : {
113 : : DBG_DTOR( rpt_OSectionWindow,NULL);
114 : : try
115 : : {
116 : 0 : if ( m_pSectionMulti.is() )
117 : 0 : m_pSectionMulti->dispose();
118 : 0 : if ( m_pGroupMulti.is() )
119 : 0 : m_pGroupMulti->dispose();
120 : : }
121 : 0 : catch (uno::Exception&)
122 : : {
123 : : }
124 : 0 : }
125 : : // -----------------------------------------------------------------------------
126 : 0 : void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
127 : : {
128 : 0 : const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
129 : 0 : if ( xSection.is() )
130 : : {
131 : 0 : const uno::Reference< report::XSection> xCurrentSection = m_aReportSection.getSection();
132 : 0 : if ( _rEvent.PropertyName.equals(PROPERTY_HEIGHT) )
133 : : {
134 : : static bool t4 = true;
135 : 0 : if ( t4 )
136 : 0 : m_pParent->getView()->SetUpdateMode(sal_False);
137 : : //Resize();
138 : 0 : m_pParent->getView()->notifySizeChanged();
139 : 0 : m_pParent->resize(*this);
140 : 0 : if ( t4 )
141 : 0 : m_pParent->getView()->SetUpdateMode(sal_True);
142 : : // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
143 : : }
144 : 0 : else if ( _rEvent.PropertyName.equals(PROPERTY_NAME) && !xSection->getGroup().is() )
145 : : {
146 : 0 : uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
147 : 0 : if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
148 : 0 : || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
149 : 0 : || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
150 : 0 : || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
151 : : {
152 : 0 : m_aStartMarker.Invalidate(INVALIDATE_NOERASE);
153 : : }
154 : : else
155 : : {
156 : 0 : String sTitle = String(ModuleRes(RID_STR_DETAIL));
157 : 0 : m_aStartMarker.setTitle(sTitle);
158 : 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
159 : 0 : }
160 : 0 : }
161 : : }
162 : 0 : else if ( _rEvent.PropertyName.equals(PROPERTY_EXPRESSION) )
163 : : {
164 : 0 : uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
165 : 0 : if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)))
166 : : {
167 : 0 : setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
168 : 0 : }
169 : 0 : }
170 : 0 : }
171 : : // -----------------------------------------------------------------------------
172 : 0 : bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OReportHelper> _pIsSectionOn)
173 : : {
174 : 0 : OReportHelper aReportHelper(_xReport);
175 : 0 : const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection.getSection();
176 : 0 : if ( bRet )
177 : : {
178 : 0 : String sTitle = String(ModuleRes(_nResId));
179 : 0 : m_aStartMarker.setTitle(sTitle);
180 : 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
181 : : }
182 : 0 : return bRet;
183 : : }
184 : : // -----------------------------------------------------------------------------
185 : 0 : bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OGroupHelper> _pIsSectionOn)
186 : : {
187 : 0 : OGroupHelper aGroupHelper(_xGroup);
188 : 0 : const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection.getSection() ;
189 : 0 : if ( bRet )
190 : : {
191 : 0 : ::rtl::OUString sExpression = _xGroup->getExpression();
192 : 0 : ::rtl::OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
193 : 0 : if ( !sLabel.isEmpty() )
194 : : {
195 : 0 : sExpression = sLabel;
196 : : }
197 : :
198 : 0 : String sTitle = ModuleRes(_nResId).toString();
199 : 0 : sTitle.SearchAndReplace(rtl::OUString('#') ,sExpression);
200 : 0 : m_aStartMarker.setTitle(sTitle);
201 : 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
202 : : }
203 : 0 : return bRet;
204 : : }
205 : : //------------------------------------------------------------------------------
206 : 0 : void OSectionWindow::ImplInitSettings()
207 : : {
208 : : static bool t = false;
209 : 0 : if ( t )
210 : : {
211 : 0 : EnableChildTransparentMode( sal_True );
212 : 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
213 : 0 : SetPaintTransparent( sal_True );
214 : : }
215 : 0 : SetBackground( );
216 : 0 : }
217 : : //-----------------------------------------------------------------------------
218 : 0 : void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
219 : : {
220 : 0 : Window::DataChanged( rDCEvt );
221 : :
222 : 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
223 : 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
224 : : {
225 : 0 : ImplInitSettings();
226 : 0 : Invalidate();
227 : : }
228 : 0 : }
229 : : //------------------------------------------------------------------------------
230 : 0 : void OSectionWindow::Resize()
231 : : {
232 : 0 : Window::Resize();
233 : :
234 : 0 : Size aOutputSize = GetOutputSizePixel();
235 : 0 : Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
236 : 0 : aEndWidth *= GetMapMode().GetScaleX();
237 : :
238 : 0 : const Point aThumbPos = m_pParent->getView()->getThumbPos();
239 : 0 : aOutputSize.Width() -= aThumbPos.X();
240 : 0 : aOutputSize.Height() -= m_aSplitter.GetSizePixel().Height();
241 : :
242 : 0 : if ( m_aStartMarker.isCollapsed() )
243 : : {
244 : 0 : Point aPos(0,0);
245 : 0 : m_aStartMarker.SetPosSizePixel(aPos,aOutputSize);
246 : : }
247 : : else
248 : : {
249 : 0 : const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
250 : :
251 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
252 : 0 : aStartWidth *= GetMapMode().GetScaleX();
253 : :
254 : : // set start marker
255 : 0 : m_aStartMarker.SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
256 : :
257 : : // set report section
258 : 0 : const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
259 : 0 : Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
260 : 0 : Point aReportPos(aStartWidth,0);
261 : 0 : aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
262 : 0 : if ( bShowEndMarker )
263 : 0 : aSectionSize.Width() -= (long)aEndWidth;
264 : :
265 : 0 : m_aReportSection.SetPosSizePixel(aReportPos,aSectionSize);
266 : :
267 : : // set splitter
268 : 0 : aReportPos.Y() += aSectionSize.Height();
269 : 0 : m_aSplitter.SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter.GetSizePixel().Height()));
270 : 0 : aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
271 : 0 : m_aSplitter.SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
272 : :
273 : : // set end marker
274 : 0 : aReportPos.X() += aSectionSize.Width();
275 : 0 : aReportPos.Y() = 0;
276 : 0 : m_aEndMarker.Show(bShowEndMarker);
277 : 0 : m_aEndMarker.SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
278 : : }
279 : 0 : }
280 : : // -----------------------------------------------------------------------------
281 : 0 : void OSectionWindow::setCollapsed(sal_Bool _bCollapsed)
282 : : {
283 : 0 : if ( m_aStartMarker.isCollapsed() != _bCollapsed )
284 : : {
285 : 0 : m_aStartMarker.setCollapsed(_bCollapsed);
286 : : }
287 : 0 : }
288 : : //-----------------------------------------------------------------------------
289 : 0 : void OSectionWindow::showProperties()
290 : : {
291 : 0 : m_pParent->getView()->showProperties( m_aReportSection.getSection().get() );
292 : 0 : }
293 : : //-----------------------------------------------------------------------------
294 : 0 : void OSectionWindow::setMarked(sal_Bool _bMark)
295 : : {
296 : 0 : m_aStartMarker.setMarked(_bMark);
297 : 0 : m_aEndMarker.setMarked(_bMark);
298 : 0 : }
299 : : // -----------------------------------------------------------------------------
300 : 0 : IMPL_LINK( OSectionWindow, Collapsed, OColorListener *, _pMarker )
301 : : {
302 : 0 : if ( _pMarker )
303 : : {
304 : 0 : sal_Bool bShow = !_pMarker->isCollapsed();
305 : 0 : m_aReportSection.Show(bShow);
306 : 0 : m_aEndMarker.Show(bShow);
307 : 0 : m_aSplitter.Show(bShow);
308 : :
309 : 0 : m_pParent->resize(*this);
310 : : }
311 : 0 : return 0L;
312 : : }
313 : : // -----------------------------------------------------------------------------
314 : 0 : void OSectionWindow::zoom(const Fraction& _aZoom)
315 : : {
316 : 0 : setZoomFactor(_aZoom,*this);
317 : 0 : m_aStartMarker.zoom(_aZoom);
318 : :
319 : 0 : setZoomFactor(_aZoom,m_aReportSection);
320 : 0 : setZoomFactor(_aZoom,m_aSplitter);
321 : 0 : setZoomFactor(_aZoom,m_aEndMarker);
322 : 0 : Invalidate();
323 : 0 : }
324 : : //-----------------------------------------------------------------------------
325 : 0 : IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*, )
326 : : {
327 : 0 : const String sUndoAction( ModuleRes( RID_STR_UNDO_CHANGE_SIZE ) );
328 : 0 : getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, String() );
329 : 0 : return 0L;
330 : : }
331 : : //------------------------------------------------------------------------------
332 : 0 : IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*, )
333 : : {
334 : 0 : getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
335 : 0 : return 0L;
336 : : }
337 : : //-----------------------------------------------------------------------------
338 : 0 : IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
339 : : {
340 : 0 : if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
341 : : {
342 : 0 : return 0L;
343 : : }
344 : :
345 : 0 : sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
346 : :
347 : 0 : const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
348 : 0 : nSplitPos = m_aSplitter.PixelToLogic(Size(0,nSplitPos)).Height();
349 : :
350 : 0 : const sal_Int32 nCount = xSection->getCount();
351 : 0 : for (sal_Int32 i = 0; i < nCount; ++i)
352 : : {
353 : 0 : uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
354 : 0 : if ( xReportComponent.is() )
355 : : {
356 : 0 : nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
357 : : }
358 : 0 : }
359 : :
360 : 0 : if ( nSplitPos < 0 )
361 : 0 : nSplitPos = 0;
362 : :
363 : 0 : xSection->setHeight(nSplitPos);
364 : 0 : m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,nSplitPos)).Height());
365 : :
366 : 0 : return 0L;
367 : : }
368 : : // -----------------------------------------------------------------------------
369 : 0 : void lcl_scroll(Window& _rWindow,const Point& _aDelta)
370 : : {
371 : 0 : _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
372 : 0 : _rWindow.Invalidate(INVALIDATE_TRANSPARENT);
373 : 0 : }
374 : : // -----------------------------------------------------------------------------
375 : 0 : void lcl_setOrigin(Window& _rWindow,long _nX, long _nY)
376 : : {
377 : 0 : MapMode aMap = _rWindow.GetMapMode();
378 : 0 : aMap.SetOrigin( Point(- _nX, - _nY));
379 : 0 : _rWindow.SetMapMode( aMap );
380 : 0 : }
381 : : //----------------------------------------------------------------------------
382 : 0 : void OSectionWindow::scrollChildren(long _nX)
383 : : {
384 : 0 : const Point aDelta( _nX,0 );
385 : :
386 : 0 : MapMode aMapMode( m_aReportSection.GetMapMode() );
387 : 0 : const Point aOld = aMapMode.GetOrigin();
388 : 0 : lcl_setOrigin(m_aReportSection,aDelta.X(), 0);
389 : :
390 : 0 : aMapMode = m_aReportSection.GetMapMode();
391 : 0 : const Point aNew = aMapMode.GetOrigin();
392 : 0 : const Point aDiff = aOld - aNew;
393 : : {
394 : 0 : lcl_scroll(m_aReportSection,aDiff);
395 : : }
396 : :
397 : 0 : lcl_scroll(m_aEndMarker,m_aEndMarker.PixelToLogic(Point(_nX,0)));
398 : :
399 : 0 : lcl_setOrigin(m_aSplitter,_nX, 0);
400 : 0 : lcl_scroll(m_aSplitter,aDiff);
401 : 0 : }
402 : : //==============================================================================
403 : : } // rptui
404 : : //==============================================================================
405 : :
406 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|