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 .
20 #include <DesignView.hxx>
21 #include <ReportController.hxx>
22 #include <svtools/acceleratorexecute.hxx>
23 #include <unotools/syslocale.hxx>
24 #include <unotools/viewoptions.hxx>
26 #include <UITools.hxx>
27 #include <RptObject.hxx>
28 #include <propbrw.hxx>
29 #include <toolkit/helper/convert.hxx>
31 #include <SectionView.hxx>
32 #include <ReportSection.hxx>
33 #include <rptui_slotid.hrc>
34 #include <svx/svxids.hrc>
35 #include <AddField.hxx>
36 #include <ScrollHelper.hxx>
37 #include <Navigator.hxx>
38 #include <SectionWindow.hxx>
40 #include <vcl/settings.hxx>
41 #include <vcl/svapp.hxx>
45 using namespace ::dbaui
;
46 using namespace ::utl
;
47 using namespace ::com::sun::star
;
50 using namespace beans
;
51 using namespace container
;
53 #define START_SIZE_TASKPANE 30
58 class OTaskWindow
: public vcl::Window
60 VclPtr
<PropBrw
> m_pPropWin
;
62 explicit OTaskWindow(vcl::Window
* _pParent
) : Window(_pParent
),m_pPropWin(nullptr){}
63 virtual ~OTaskWindow() override
{ disposeOnce(); }
64 virtual void dispose() override
{ m_pPropWin
.clear(); vcl::Window::dispose(); }
66 void setPropertyBrowser(PropBrw
* _pPropWin
)
68 m_pPropWin
= _pPropWin
;
71 virtual void Resize() override
73 const Size aSize
= GetOutputSizePixel();
74 if ( m_pPropWin
&& aSize
.Height() && aSize
.Width() )
75 m_pPropWin
->SetSizePixel(aSize
);
83 ODesignView::ODesignView( vcl::Window
* pParent
,
84 const Reference
< XComponentContext
>& _rxOrb
,
85 OReportController
& _rController
) :
86 ODataView( pParent
, _rController
, _rxOrb
, WB_DIALOGCONTROL
)
87 ,m_aSplitWin(VclPtr
<SplitWindow
>::Create(this))
88 ,m_rReportController( _rController
)
89 ,m_aScrollWindow(VclPtr
<rptui::OScrollWindowHelper
>::Create(this))
92 ,m_pCurrentView(nullptr)
93 ,m_pReportExplorer(nullptr)
94 ,m_eMode( DlgEdMode::Select
)
95 ,m_eActObj( OBJ_NONE
)
96 ,m_aGridSizeCoarse( 1000, 1000 ) // #i93595# 100TH_MM changed to grid using coarse 1 cm grid
97 ,m_aGridSizeFine( 250, 250 ) // and a 0,25 cm subdivision for better visualisation
100 SetHelpId(UID_RPT_RPT_APP_VIEW
);
103 SetMapMode( MapMode( MapUnit::Map100thMM
) );
105 // now create the task pane on the right side :-)
106 m_pTaskPane
= VclPtr
<OTaskWindow
>::Create(this);
108 m_aSplitWin
->InsertItem( COLSET_ID
,100,SPLITWINDOW_APPEND
, 0, SplitWindowItemFlags::PercentSize
| SplitWindowItemFlags::ColSet
);
109 m_aSplitWin
->InsertItem( REPORT_ID
, m_aScrollWindow
.get(), 100, SPLITWINDOW_APPEND
, COLSET_ID
, SplitWindowItemFlags::PercentSize
);
112 m_aSplitWin
->SetSplitHdl(LINK(this, ODesignView
,SplitHdl
));
113 m_aSplitWin
->SetAlign(WindowAlign::Left
);
116 m_aMarkIdle
.SetInvokeHandler( LINK( this, ODesignView
, MarkTimeout
) );
120 ODesignView::~ODesignView()
125 void ODesignView::dispose()
129 m_aScrollWindow
->Hide();
133 notifySystemWindow(this,m_pPropWin
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
134 m_pPropWin
.disposeAndClear();
138 SvtViewOptions
aDlgOpt( EViewType::Window
, UID_RPT_RPT_APP_VIEW
);
139 aDlgOpt
.SetWindowState(OStringToOUString(m_pAddField
->GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
140 notifySystemWindow(this,m_pAddField
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
141 m_pAddField
.disposeAndClear();
143 if ( m_pReportExplorer
)
145 SvtViewOptions
aDlgOpt(EViewType::Window
, OStringToOUString(m_pReportExplorer
->GetHelpId(), RTL_TEXTENCODING_UTF8
));
146 aDlgOpt
.SetWindowState(OStringToOUString(m_pReportExplorer
->GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
147 notifySystemWindow(this,m_pReportExplorer
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
148 m_pReportExplorer
.disposeAndClear();
151 m_pTaskPane
.disposeAndClear();
152 m_aScrollWindow
.disposeAndClear();
153 m_aSplitWin
.disposeAndClear();
154 dbaui::ODataView::dispose();
157 void ODesignView::initialize()
159 SetMapMode( MapMode( MapUnit::Map100thMM
) );
160 m_aScrollWindow
->initialize();
161 m_aScrollWindow
->Show();
164 void ODesignView::DataChanged( const DataChangedEvent
& rDCEvt
)
166 ODataView::DataChanged( rDCEvt
);
168 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
169 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
176 bool ODesignView::PreNotify( NotifyEvent
& rNEvt
)
178 bool bRet
= ODataView::PreNotify(rNEvt
); // 1 := has to be handled here
179 switch(rNEvt
.GetType())
181 case MouseNotifyEvent::KEYINPUT
:
183 if ( m_pPropWin
&& m_pPropWin
->HasChildPathFocus() )
185 if ( m_pAddField
&& m_pAddField
->HasChildPathFocus() )
187 if ( m_pReportExplorer
&& m_pReportExplorer
->HasChildPathFocus() )
189 const KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
190 if ( handleKeyEvent(*pKeyEvent
) )
192 else if ( bRet
&& m_pAccel
.get() )
194 const vcl::KeyCode
& rCode
= pKeyEvent
->GetKeyCode();
196 aUrl
.Complete
= m_pAccel
->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rCode
));
197 if ( aUrl
.Complete
.isEmpty() || !m_xController
->isCommandEnabled( aUrl
.Complete
) )
209 void ODesignView::resizeDocumentView(tools::Rectangle
& _rPlayground
)
211 if ( !_rPlayground
.IsEmpty() )
213 const Size
aPlaygroundSize( _rPlayground
.GetSize() );
215 // calc the split pos, and forward it to the controller
216 sal_Int32 nSplitPos
= getController().getSplitPos();
217 if ( 0 != aPlaygroundSize
.Width() )
219 if ( ( -1 == nSplitPos
)
220 || ( nSplitPos
>= aPlaygroundSize
.Width() )
223 long nMinWidth
= static_cast<long>(0.1*aPlaygroundSize
.Width());
224 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
225 nMinWidth
= m_pPropWin
->GetMinOutputSizePixel().Width();
226 nSplitPos
= static_cast<sal_Int32
>(_rPlayground
.Right() - nMinWidth
);
227 getController().setSplitPos(nSplitPos
);
231 if ( m_aSplitWin
->IsItemValid(TASKPANE_ID
) )
233 // normalize the split pos
234 const long nSplitterWidth
= StyleSettings::GetSplitSize();
235 Point
aTaskPanePos(nSplitPos
+ nSplitterWidth
, _rPlayground
.Top());
236 if (m_pTaskPane
&& m_pTaskPane
->IsVisible() && m_pPropWin
)
238 aTaskPanePos
.setX( aPlaygroundSize
.Width() - m_pTaskPane
->GetSizePixel().Width() );
239 sal_Int32 nMinWidth
= m_pPropWin
->getMinimumSize().Width();
240 if ( nMinWidth
> (aPlaygroundSize
.Width() - aTaskPanePos
.X()) )
242 aTaskPanePos
.setX( aPlaygroundSize
.Width() - nMinWidth
);
244 nSplitPos
= aTaskPanePos
.X() - nSplitterWidth
;
245 getController().setSplitPos(nSplitPos
);
247 const long nTaskPaneSize
= static_cast<long>((aPlaygroundSize
.Width() - aTaskPanePos
.X())*100/aPlaygroundSize
.Width());
248 if ( m_aSplitWin
->GetItemSize( TASKPANE_ID
) != nTaskPaneSize
)
250 m_aSplitWin
->SetItemSize( REPORT_ID
, 99 - nTaskPaneSize
);
251 m_aSplitWin
->SetItemSize( TASKPANE_ID
, nTaskPaneSize
);
255 // set the size of the report window
256 m_aSplitWin
->SetPosSizePixel( _rPlayground
.TopLeft(),aPlaygroundSize
);
258 // just for completeness: there is no space left, we occupied it all ...
259 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
260 _rPlayground
.SetSize( Size( 0, 0 ) );
264 IMPL_LINK_NOARG(ODesignView
, MarkTimeout
, Timer
*, void)
266 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
268 m_pPropWin
->Update(m_pCurrentView
);
269 uno::Reference
<beans::XPropertySet
> xProp(m_xReportComponent
,uno::UNO_QUERY
);
272 m_pPropWin
->Update(xProp
);
273 static_cast<OTaskWindow
*>(m_pTaskPane
.get())->Resize();
280 void ODesignView::SetMode( DlgEdMode _eNewMode
)
283 if ( m_eMode
== DlgEdMode::Select
)
284 m_eActObj
= OBJ_NONE
;
286 m_aScrollWindow
->SetMode(_eNewMode
);
289 void ODesignView::SetInsertObj( sal_uInt16 eObj
,const OUString
& _sShapeType
)
292 m_aScrollWindow
->SetInsertObj( eObj
,_sShapeType
);
295 OUString
const & ODesignView::GetInsertObjString() const
297 return m_aScrollWindow
->GetInsertObjString();
301 void ODesignView::Cut()
308 void ODesignView::Copy()
310 m_aScrollWindow
->Copy();
314 void ODesignView::Paste()
316 m_aScrollWindow
->Paste();
319 void ODesignView::Delete()
321 m_aScrollWindow
->Delete();
324 bool ODesignView::HasSelection() const
326 return m_aScrollWindow
->HasSelection();
330 bool ODesignView::IsPasteAllowed() const
332 return m_aScrollWindow
->IsPasteAllowed();
336 void ODesignView::UpdatePropertyBrowserDelayed(OSectionView
& _rView
)
338 if ( m_pCurrentView
!= &_rView
)
340 if ( m_pCurrentView
)
341 m_aScrollWindow
->setMarked(m_pCurrentView
,false);
342 m_pCurrentView
= &_rView
;
343 m_aScrollWindow
->setMarked(m_pCurrentView
, true);
344 m_xReportComponent
.clear();
345 DlgEdHint
aHint( RPTUI_HINT_SELECTIONCHANGED
);
352 void ODesignView::toggleGrid(bool _bGridVisible
)
354 m_aScrollWindow
->toggleGrid(_bGridVisible
);
357 sal_uInt16
ODesignView::getSectionCount() const
359 return m_aScrollWindow
->getSectionCount();
362 void ODesignView::showRuler(bool _bShow
)
364 m_aScrollWindow
->showRuler(_bShow
);
367 void ODesignView::removeSection(sal_uInt16 _nPosition
)
369 m_aScrollWindow
->removeSection(_nPosition
);
372 void ODesignView::addSection(const uno::Reference
< report::XSection
>& _xSection
,const OUString
& _sColorEntry
,sal_uInt16 _nPosition
)
374 m_aScrollWindow
->addSection(_xSection
,_sColorEntry
,_nPosition
);
377 void ODesignView::GetFocus()
383 OSectionWindow
* pSectionWindow
= m_aScrollWindow
->getMarkedSection();
384 if ( pSectionWindow
)
385 pSectionWindow
->GrabFocus();
389 void ODesignView::ImplInitSettings()
391 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
392 SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
393 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
396 IMPL_LINK_NOARG( ODesignView
, SplitHdl
, SplitWindow
*, void )
398 const Size aOutputSize
= GetOutputSizePixel();
399 const long nTest
= aOutputSize
.Width() * m_aSplitWin
->GetItemSize(TASKPANE_ID
) / 100;
400 long nMinWidth
= static_cast<long>(0.1*aOutputSize
.Width());
401 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
402 nMinWidth
= m_pPropWin
->GetMinOutputSizePixel().Width();
404 if ( (aOutputSize
.Width() - nTest
) >= nMinWidth
&& nTest
> m_aScrollWindow
->getMaxMarkerWidth() )
406 getController().setSplitPos(nTest
);
410 void ODesignView::SelectAll(const sal_uInt16 _nObjectType
)
412 m_aScrollWindow
->SelectAll(_nObjectType
);
415 void ODesignView::unmarkAllObjects()
417 m_aScrollWindow
->unmarkAllObjects();
420 void ODesignView::togglePropertyBrowser(bool _bToggleOn
)
422 if ( !m_pPropWin
&& _bToggleOn
)
424 m_pPropWin
= VclPtr
<PropBrw
>::Create(getController().getORB(), m_pTaskPane
,this);
425 m_pPropWin
->Invalidate();
426 static_cast<OTaskWindow
*>(m_pTaskPane
.get())->setPropertyBrowser(m_pPropWin
);
427 notifySystemWindow(this,m_pPropWin
,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
429 if ( m_pPropWin
&& _bToggleOn
!= m_pPropWin
->IsVisible() )
431 if ( !m_pCurrentView
&& !m_xReportComponent
.is() )
432 m_xReportComponent
= getController().getReportDefinition();
434 const bool bWillBeVisible
= _bToggleOn
;
435 m_pPropWin
->Show(bWillBeVisible
);
436 m_pTaskPane
->Show(bWillBeVisible
);
437 m_pTaskPane
->Invalidate();
439 if ( bWillBeVisible
)
440 m_aSplitWin
->InsertItem( TASKPANE_ID
, m_pTaskPane
,START_SIZE_TASKPANE
, SPLITWINDOW_APPEND
, COLSET_ID
, SplitWindowItemFlags::PercentSize
);
442 m_aSplitWin
->RemoveItem(TASKPANE_ID
);
444 if ( bWillBeVisible
)
449 void ODesignView::showProperties(const uno::Reference
< uno::XInterface
>& _xReportComponent
)
451 if ( m_xReportComponent
!= _xReportComponent
)
453 m_xReportComponent
= _xReportComponent
;
454 if ( m_pCurrentView
)
455 m_aScrollWindow
->setMarked(m_pCurrentView
,false);
456 m_pCurrentView
= nullptr;
461 bool ODesignView::isReportExplorerVisible() const
463 return m_pReportExplorer
&& m_pReportExplorer
->IsVisible();
466 void ODesignView::toggleReportExplorer()
468 if ( !m_pReportExplorer
)
470 OReportController
& rReportController
= getController();
471 m_pReportExplorer
= VclPtr
<ONavigator
>::Create(this,rReportController
);
472 SvtViewOptions
aDlgOpt(EViewType::Window
, OStringToOUString(m_pReportExplorer
->GetHelpId(), RTL_TEXTENCODING_UTF8
));
473 if ( aDlgOpt
.Exists() )
474 m_pReportExplorer
->SetWindowState(OUStringToOString(aDlgOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
475 m_pReportExplorer
->AddEventListener(LINK(&rReportController
,OReportController
,EventLstHdl
));
476 notifySystemWindow(this,m_pReportExplorer
,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
479 m_pReportExplorer
->Show(!m_pReportExplorer
->IsVisible());
482 bool ODesignView::isAddFieldVisible() const
484 return m_pAddField
&& m_pAddField
->IsVisible();
487 void ODesignView::toggleAddField()
491 uno::Reference
< report::XReportDefinition
> xReport(m_xReportComponent
,uno::UNO_QUERY
);
492 uno::Reference
< report::XReportComponent
> xReportComponent(m_xReportComponent
,uno::UNO_QUERY
);
493 OReportController
& rReportController
= getController();
494 if ( !m_pCurrentView
&& !xReport
.is() )
496 if ( xReportComponent
.is() )
497 xReport
= xReportComponent
->getSection()->getReportDefinition();
499 xReport
= rReportController
.getReportDefinition().get();
501 else if ( m_pCurrentView
)
503 uno::Reference
< report::XSection
> xSection
= m_pCurrentView
->getReportSection()->getSection();
504 xReport
= xSection
->getReportDefinition();
506 uno::Reference
< beans::XPropertySet
> xSet(rReportController
.getRowSet(),uno::UNO_QUERY
);
507 m_pAddField
= VclPtr
<OAddFieldWindow
>::Create(this,xSet
);
508 m_pAddField
->SetCreateHdl(LINK( &rReportController
, OReportController
, OnCreateHdl
) );
509 SvtViewOptions
aDlgOpt( EViewType::Window
, UID_RPT_RPT_APP_VIEW
);
510 if ( aDlgOpt
.Exists() )
511 m_pAddField
->SetWindowState(OUStringToOString(aDlgOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
512 m_pAddField
->Update();
513 m_pAddField
->AddEventListener(LINK(&rReportController
,OReportController
,EventLstHdl
));
514 notifySystemWindow(this,m_pAddField
,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
518 m_pAddField
->Show(!m_pAddField
->IsVisible());
521 uno::Reference
< report::XSection
> ODesignView::getCurrentSection() const
523 uno::Reference
< report::XSection
> xSection
;
524 if ( m_pCurrentView
)
525 xSection
= m_pCurrentView
->getReportSection()->getSection();
530 uno::Reference
< report::XReportComponent
> ODesignView::getCurrentControlModel() const
532 uno::Reference
< report::XReportComponent
> xModel
;
533 if ( m_pCurrentView
)
535 xModel
= m_pCurrentView
->getReportSection()->getCurrentControlModel();
540 OSectionWindow
* ODesignView::getMarkedSection(NearSectionAccess nsa
) const
542 return m_aScrollWindow
->getMarkedSection(nsa
);
545 OSectionWindow
* ODesignView::getSectionWindow(const css::uno::Reference
< css::report::XSection
>& _xSection
) const
547 return m_aScrollWindow
->getSectionWindow(_xSection
);
550 void ODesignView::markSection(const sal_uInt16 _nPos
)
552 m_aScrollWindow
->markSection(_nPos
);
555 void ODesignView::fillCollapsedSections(::std::vector
<sal_uInt16
>& _rCollapsedPositions
) const
557 m_aScrollWindow
->fillCollapsedSections(_rCollapsedPositions
);
560 void ODesignView::collapseSections(const uno::Sequence
< beans::PropertyValue
>& _aCollpasedSections
)
562 m_aScrollWindow
->collapseSections(_aCollpasedSections
);
565 OUString
ODesignView::getCurrentPage() const
567 return m_pPropWin
? m_pPropWin
->getCurrentPage() : OUString();
570 void ODesignView::setCurrentPage(const OUString
& _sLastActivePage
)
573 m_pPropWin
->setCurrentPage(_sLastActivePage
);
576 void ODesignView::alignMarkedObjects(ControlModification _nControlModification
,bool _bAlignAtSection
)
578 m_aScrollWindow
->alignMarkedObjects(_nControlModification
, _bAlignAtSection
);
581 bool ODesignView::handleKeyEvent(const KeyEvent
& _rEvent
)
583 if ( m_pPropWin
&& m_pPropWin
->HasChildPathFocus() )
585 if ( m_pAddField
&& m_pAddField
->HasChildPathFocus() )
587 if ( m_pReportExplorer
&& m_pReportExplorer
->HasChildPathFocus() )
589 return m_aScrollWindow
->handleKeyEvent(_rEvent
);
592 void ODesignView::setMarked(const uno::Reference
< report::XSection
>& _xSection
,bool _bMark
)
594 m_aScrollWindow
->setMarked(_xSection
,_bMark
);
596 UpdatePropertyBrowserDelayed(getMarkedSection()->getReportSection().getSectionView());
598 m_pCurrentView
= nullptr;
601 void ODesignView::setMarked(const uno::Sequence
< uno::Reference
< report::XReportComponent
> >& _aShapes
,bool _bMark
)
603 m_aScrollWindow
->setMarked(_aShapes
,_bMark
);
604 if ( _aShapes
.hasElements() && _bMark
)
605 showProperties(_aShapes
[0]);
607 m_xReportComponent
.clear();
610 void ODesignView::MouseButtonDown( const MouseEvent
& rMEvt
)
612 if ( rMEvt
.IsLeft() )
614 const uno::Sequence
< beans::PropertyValue
> aArgs
;
615 getController().executeChecked(SID_SELECT_REPORT
,aArgs
);
617 ODataView::MouseButtonDown(rMEvt
);
620 uno::Any
ODesignView::getCurrentlyShownProperty() const
623 OSectionWindow
* pSectionWindow
= getMarkedSection();
624 if ( pSectionWindow
)
626 ::std::vector
< uno::Reference
< uno::XInterface
> > aSelection
;
627 pSectionWindow
->getReportSection().fillControlModelSelection(aSelection
);
628 if ( !aSelection
.empty() )
630 uno::Sequence
< uno::Reference
< report::XReportComponent
> > aSeq(aSelection
.size());
632 for(const auto& rxInterface
: aSelection
)
634 aSeq
[i
].set(rxInterface
,uno::UNO_QUERY
);
643 void ODesignView::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
645 m_aScrollWindow
->fillControlModelSelection(_rSelection
);
648 void ODesignView::setGridSnap(bool bOn
)
650 m_aScrollWindow
->setGridSnap(bOn
);
654 void ODesignView::setDragStripes(bool bOn
)
656 m_aScrollWindow
->setDragStripes(bOn
);
659 bool ODesignView::isHandleEvent() const
661 return m_pPropWin
&& m_pPropWin
->HasChildPathFocus();
664 sal_uInt32
ODesignView::getMarkedObjectCount() const
666 return m_aScrollWindow
->getMarkedObjectCount();
669 void ODesignView::zoom(const Fraction
& _aZoom
)
671 m_aScrollWindow
->zoom(_aZoom
);
674 sal_uInt16
ODesignView::getZoomFactor(SvxZoomType _eType
) const
676 return m_aScrollWindow
->getZoomFactor(_eType
);
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */