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/viewoptions.hxx>
25 #include <UITools.hxx>
26 #include <RptObject.hxx>
27 #include <propbrw.hxx>
29 #include <SectionView.hxx>
30 #include <ReportSection.hxx>
31 #include <rptui_slotid.hrc>
32 #include <AddField.hxx>
33 #include <ScrollHelper.hxx>
34 #include <Navigator.hxx>
35 #include <SectionWindow.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/svapp.hxx>
44 using namespace ::dbaui
;
45 using namespace ::utl
;
46 using namespace ::com::sun::star
;
49 using namespace beans
;
50 using namespace container
;
52 #define START_SIZE_TASKPANE 30
59 class OTaskWindow
: public vcl::Window
61 VclPtr
<PropBrw
> m_pPropWin
;
63 explicit OTaskWindow(vcl::Window
* _pParent
) : Window(_pParent
),m_pPropWin(nullptr){}
64 virtual ~OTaskWindow() override
{ disposeOnce(); }
65 virtual void dispose() override
{ m_pPropWin
.clear(); vcl::Window::dispose(); }
67 void setPropertyBrowser(PropBrw
* _pPropWin
)
69 m_pPropWin
= _pPropWin
;
72 virtual void Resize() override
74 const Size aSize
= GetOutputSizePixel();
75 if ( m_pPropWin
&& aSize
.Height() && aSize
.Width() )
76 m_pPropWin
->SetSizePixel(aSize
);
84 ODesignView::ODesignView( vcl::Window
* pParent
,
85 const Reference
< XComponentContext
>& _rxOrb
,
86 OReportController
& _rController
) :
87 ODataView( pParent
, _rController
, _rxOrb
, WB_DIALOGCONTROL
)
88 ,m_aSplitWin(VclPtr
<SplitWindow
>::Create(this))
89 ,m_rReportController( _rController
)
90 ,m_aScrollWindow(VclPtr
<rptui::OScrollWindowHelper
>::Create(this))
92 ,m_pCurrentView(nullptr)
93 ,m_aMarkIdle("reportdesign ODesignView Mark Idle")
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_xAddField
->getDialog()->get_window_state(WindowStateMask::All
), RTL_TEXTENCODING_ASCII_US
));
141 if (m_xAddField
->getDialog()->get_visible())
142 m_xAddField
->response(RET_CANCEL
);
146 if ( m_xReportExplorer
)
148 SvtViewOptions
aDlgOpt(EViewType::Window
, OStringToOUString(m_xReportExplorer
->get_help_id(), RTL_TEXTENCODING_UTF8
));
149 aDlgOpt
.SetWindowState(OStringToOUString(m_xReportExplorer
->getDialog()->get_window_state(WindowStateMask::All
), RTL_TEXTENCODING_ASCII_US
));
151 if (m_xReportExplorer
->getDialog()->get_visible())
152 m_xReportExplorer
->response(RET_CANCEL
);
154 m_xReportExplorer
.reset();
157 m_pTaskPane
.disposeAndClear();
158 m_aScrollWindow
.disposeAndClear();
159 m_aSplitWin
.disposeAndClear();
160 dbaui::ODataView::dispose();
163 void ODesignView::initialize()
165 SetMapMode( MapMode( MapUnit::Map100thMM
) );
166 m_aScrollWindow
->initialize();
167 m_aScrollWindow
->Show();
170 void ODesignView::DataChanged( const DataChangedEvent
& rDCEvt
)
172 ODataView::DataChanged( rDCEvt
);
174 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
175 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
182 bool ODesignView::PreNotify( NotifyEvent
& rNEvt
)
184 bool bRet
= ODataView::PreNotify(rNEvt
); // 1 := has to be handled here
185 switch(rNEvt
.GetType())
187 case MouseNotifyEvent::KEYINPUT
:
189 if ( m_pPropWin
&& m_pPropWin
->HasChildPathFocus() )
191 if (m_xAddField
&& m_xAddField
->getDialog()->has_toplevel_focus())
193 if ( m_xReportExplorer
&& m_xReportExplorer
->getDialog()->has_toplevel_focus())
195 const KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
196 if ( handleKeyEvent(*pKeyEvent
) )
198 else if ( bRet
&& m_pAccel
)
200 const vcl::KeyCode
& rCode
= pKeyEvent
->GetKeyCode();
202 aUrl
.Complete
= m_pAccel
->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rCode
));
203 if ( aUrl
.Complete
.isEmpty() || !m_xController
->isCommandEnabled( aUrl
.Complete
) )
215 void ODesignView::resizeDocumentView(tools::Rectangle
& _rPlayground
)
217 if ( !_rPlayground
.IsEmpty() )
219 const Size
aPlaygroundSize( _rPlayground
.GetSize() );
221 // calc the split pos, and forward it to the controller
222 sal_Int32 nSplitPos
= getController().getSplitPos();
223 if ( 0 != aPlaygroundSize
.Width() )
225 if ( ( -1 == nSplitPos
)
226 || ( nSplitPos
>= aPlaygroundSize
.Width() )
229 tools::Long nMinWidth
= static_cast<tools::Long
>(0.1*aPlaygroundSize
.Width());
230 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
231 nMinWidth
= m_pPropWin
->GetMinOutputSizePixel().Width();
232 nSplitPos
= static_cast<sal_Int32
>(_rPlayground
.Right() - nMinWidth
);
233 getController().setSplitPos(nSplitPos
);
237 if ( m_aSplitWin
->IsItemValid(TASKPANE_ID
) )
239 // normalize the split pos
240 const tools::Long nSplitterWidth
= StyleSettings::GetSplitSize();
241 Point
aTaskPanePos(nSplitPos
+ nSplitterWidth
, _rPlayground
.Top());
242 if (m_pTaskPane
&& m_pTaskPane
->IsVisible() && m_pPropWin
)
244 aTaskPanePos
.setX( aPlaygroundSize
.Width() - m_pTaskPane
->GetSizePixel().Width() );
245 sal_Int32 nMinWidth
= m_pPropWin
->getMinimumSize().Width();
246 if ( nMinWidth
> (aPlaygroundSize
.Width() - aTaskPanePos
.X()) )
248 aTaskPanePos
.setX( aPlaygroundSize
.Width() - nMinWidth
);
250 nSplitPos
= aTaskPanePos
.X() - nSplitterWidth
;
251 getController().setSplitPos(nSplitPos
);
253 const tools::Long nTaskPaneSize
= static_cast<tools::Long
>((aPlaygroundSize
.Width() - aTaskPanePos
.X())*100/aPlaygroundSize
.Width());
254 if ( m_aSplitWin
->GetItemSize( TASKPANE_ID
) != nTaskPaneSize
)
256 m_aSplitWin
->SetItemSize( REPORT_ID
, 99 - nTaskPaneSize
);
257 m_aSplitWin
->SetItemSize( TASKPANE_ID
, nTaskPaneSize
);
261 // set the size of the report window
262 m_aSplitWin
->SetPosSizePixel( _rPlayground
.TopLeft(),aPlaygroundSize
);
264 // just for completeness: there is no space left, we occupied it all ...
265 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
266 _rPlayground
.SetSize( Size( 0, 0 ) );
270 IMPL_LINK_NOARG(ODesignView
, MarkTimeout
, Timer
*, void)
272 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
274 m_pPropWin
->Update(m_pCurrentView
);
275 uno::Reference
<beans::XPropertySet
> xProp(m_xReportComponent
,uno::UNO_QUERY
);
278 m_pPropWin
->Update(xProp
);
279 static_cast<OTaskWindow
*>(m_pTaskPane
.get())->Resize();
286 void ODesignView::SetMode( DlgEdMode _eNewMode
)
289 if ( m_eMode
== DlgEdMode::Select
)
290 m_eActObj
= OBJ_NONE
;
292 m_aScrollWindow
->SetMode(_eNewMode
);
295 void ODesignView::SetInsertObj( SdrObjKind eObj
,const OUString
& _sShapeType
)
298 m_aScrollWindow
->SetInsertObj( eObj
,_sShapeType
);
301 OUString
const & ODesignView::GetInsertObjString() const
303 return m_aScrollWindow
->GetInsertObjString();
307 void ODesignView::Cut()
314 void ODesignView::Copy()
316 m_aScrollWindow
->Copy();
320 void ODesignView::Paste()
322 m_aScrollWindow
->Paste();
325 void ODesignView::Delete()
327 m_aScrollWindow
->Delete();
330 bool ODesignView::HasSelection() const
332 return m_aScrollWindow
->HasSelection();
336 bool ODesignView::IsPasteAllowed() const
338 return m_aScrollWindow
->IsPasteAllowed();
342 void ODesignView::UpdatePropertyBrowserDelayed(OSectionView
& _rView
)
344 if ( m_pCurrentView
!= &_rView
)
346 if ( m_pCurrentView
)
347 m_aScrollWindow
->setMarked(m_pCurrentView
,false);
348 m_pCurrentView
= &_rView
;
349 m_aScrollWindow
->setMarked(m_pCurrentView
, true);
350 m_xReportComponent
.clear();
351 DlgEdHint
aHint( RPTUI_HINT_SELECTIONCHANGED
);
358 void ODesignView::toggleGrid(bool _bGridVisible
)
360 m_aScrollWindow
->toggleGrid(_bGridVisible
);
363 sal_uInt16
ODesignView::getSectionCount() const
365 return m_aScrollWindow
->getSectionCount();
368 void ODesignView::showRuler(bool _bShow
)
370 m_aScrollWindow
->showRuler(_bShow
);
373 void ODesignView::removeSection(sal_uInt16 _nPosition
)
375 m_aScrollWindow
->removeSection(_nPosition
);
378 void ODesignView::addSection(const uno::Reference
< report::XSection
>& _xSection
,const OUString
& _sColorEntry
,sal_uInt16 _nPosition
)
380 m_aScrollWindow
->addSection(_xSection
,_sColorEntry
,_nPosition
);
383 void ODesignView::GetFocus()
389 OSectionWindow
* pSectionWindow
= m_aScrollWindow
->getMarkedSection();
390 if ( pSectionWindow
)
391 pSectionWindow
->GrabFocus();
395 void ODesignView::ImplInitSettings()
397 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
398 GetOutDev()->SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
399 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
402 IMPL_LINK_NOARG( ODesignView
, SplitHdl
, SplitWindow
*, void )
404 const Size aOutputSize
= GetOutputSizePixel();
405 const tools::Long nTest
= aOutputSize
.Width() * m_aSplitWin
->GetItemSize(TASKPANE_ID
) / 100;
406 tools::Long nMinWidth
= static_cast<tools::Long
>(0.1*aOutputSize
.Width());
407 if ( m_pPropWin
&& m_pPropWin
->IsVisible() )
408 nMinWidth
= m_pPropWin
->GetMinOutputSizePixel().Width();
410 if ( (aOutputSize
.Width() - nTest
) >= nMinWidth
&& nTest
> m_aScrollWindow
->getMaxMarkerWidth() )
412 getController().setSplitPos(nTest
);
416 void ODesignView::SelectAll(const sal_uInt16 _nObjectType
)
418 m_aScrollWindow
->SelectAll(_nObjectType
);
421 void ODesignView::unmarkAllObjects()
423 m_aScrollWindow
->unmarkAllObjects();
426 void ODesignView::togglePropertyBrowser(bool _bToggleOn
)
428 if ( !m_pPropWin
&& _bToggleOn
)
430 m_pPropWin
= VclPtr
<PropBrw
>::Create(getController().getORB(), m_pTaskPane
,this);
431 m_pPropWin
->Invalidate();
432 static_cast<OTaskWindow
*>(m_pTaskPane
.get())->setPropertyBrowser(m_pPropWin
);
433 notifySystemWindow(this,m_pPropWin
,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
435 if ( !(m_pPropWin
&& _bToggleOn
!= m_pPropWin
->IsVisible()) )
438 if ( !m_pCurrentView
&& !m_xReportComponent
.is() )
439 m_xReportComponent
= getController().getReportDefinition();
441 const bool bWillBeVisible
= _bToggleOn
;
442 m_pPropWin
->Show(bWillBeVisible
);
443 m_pTaskPane
->Show(bWillBeVisible
);
444 m_pTaskPane
->Invalidate();
446 if ( bWillBeVisible
)
447 m_aSplitWin
->InsertItem( TASKPANE_ID
, m_pTaskPane
,START_SIZE_TASKPANE
, SPLITWINDOW_APPEND
, COLSET_ID
, SplitWindowItemFlags::PercentSize
);
449 m_aSplitWin
->RemoveItem(TASKPANE_ID
);
451 if ( bWillBeVisible
)
455 void ODesignView::showProperties(const uno::Reference
< uno::XInterface
>& _xReportComponent
)
457 if ( m_xReportComponent
!= _xReportComponent
)
459 m_xReportComponent
= _xReportComponent
;
460 if ( m_pCurrentView
)
461 m_aScrollWindow
->setMarked(m_pCurrentView
,false);
462 m_pCurrentView
= nullptr;
467 bool ODesignView::isReportExplorerVisible() const
469 return m_xReportExplorer
&& m_xReportExplorer
->getDialog()->get_visible();
472 void ODesignView::toggleReportExplorer()
474 if ( !m_xReportExplorer
)
476 OReportController
& rReportController
= getController();
477 m_xReportExplorer
= std::make_shared
<ONavigator
>(GetFrameWeld(), rReportController
);
478 SvtViewOptions
aDlgOpt(EViewType::Window
, OStringToOUString(m_xReportExplorer
->get_help_id(), RTL_TEXTENCODING_UTF8
));
479 if ( aDlgOpt
.Exists() )
480 m_xReportExplorer
->getDialog()->set_window_state(OUStringToOString(aDlgOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
483 if (!m_xReportExplorer
->getDialog()->get_visible())
484 weld::DialogController::runAsync(m_xReportExplorer
, [this](sal_Int32
/*nResult*/) { m_xReportExplorer
.reset(); });
486 m_xReportExplorer
->response(RET_CANCEL
);
489 bool ODesignView::isAddFieldVisible() const
491 return m_xAddField
&& m_xAddField
->getDialog()->get_visible();
494 void ODesignView::toggleAddField()
498 uno::Reference
< report::XReportDefinition
> xReport(m_xReportComponent
,uno::UNO_QUERY
);
499 uno::Reference
< report::XReportComponent
> xReportComponent(m_xReportComponent
,uno::UNO_QUERY
);
500 OReportController
& rReportController
= getController();
501 if ( !m_pCurrentView
&& !xReport
.is() )
503 if ( xReportComponent
.is() )
504 xReport
= xReportComponent
->getSection()->getReportDefinition();
506 xReport
= rReportController
.getReportDefinition().get();
508 else if ( m_pCurrentView
)
510 uno::Reference
< report::XSection
> xSection
= m_pCurrentView
->getReportSection()->getSection();
511 xReport
= xSection
->getReportDefinition();
513 uno::Reference
< beans::XPropertySet
> xSet(rReportController
.getRowSet(),uno::UNO_QUERY
);
514 m_xAddField
= std::make_shared
<OAddFieldWindow
>(GetFrameWeld(), xSet
);
515 m_xAddField
->SetCreateHdl(LINK( &rReportController
, OReportController
, OnCreateHdl
) );
516 SvtViewOptions
aDlgOpt( EViewType::Window
, UID_RPT_RPT_APP_VIEW
);
517 if ( aDlgOpt
.Exists() )
518 m_xAddField
->getDialog()->set_window_state(OUStringToOString(aDlgOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
));
519 m_xAddField
->Update();
521 if (!m_xAddField
->getDialog()->get_visible())
522 weld::DialogController::runAsync(m_xAddField
, [this](sal_Int32
/*nResult*/) { m_xAddField
.reset(); });
524 m_xAddField
->response(RET_CANCEL
);
527 uno::Reference
< report::XSection
> ODesignView::getCurrentSection() const
529 uno::Reference
< report::XSection
> xSection
;
530 if ( m_pCurrentView
)
531 xSection
= m_pCurrentView
->getReportSection()->getSection();
536 uno::Reference
< report::XReportComponent
> ODesignView::getCurrentControlModel() const
538 uno::Reference
< report::XReportComponent
> xModel
;
539 if ( m_pCurrentView
)
541 xModel
= m_pCurrentView
->getReportSection()->getCurrentControlModel();
546 OSectionWindow
* ODesignView::getMarkedSection(NearSectionAccess nsa
) const
548 return m_aScrollWindow
->getMarkedSection(nsa
);
551 OSectionWindow
* ODesignView::getSectionWindow(const css::uno::Reference
< css::report::XSection
>& _xSection
) const
553 return m_aScrollWindow
->getSectionWindow(_xSection
);
556 void ODesignView::markSection(const sal_uInt16 _nPos
)
558 m_aScrollWindow
->markSection(_nPos
);
561 void ODesignView::fillCollapsedSections(::std::vector
<sal_uInt16
>& _rCollapsedPositions
) const
563 m_aScrollWindow
->fillCollapsedSections(_rCollapsedPositions
);
566 void ODesignView::collapseSections(const uno::Sequence
< beans::PropertyValue
>& _aCollapsedSections
)
568 m_aScrollWindow
->collapseSections(_aCollapsedSections
);
571 OUString
ODesignView::getCurrentPage() const
573 return m_pPropWin
? m_pPropWin
->getCurrentPage() : OUString();
576 void ODesignView::setCurrentPage(const OUString
& _sLastActivePage
)
579 m_pPropWin
->setCurrentPage(_sLastActivePage
);
582 void ODesignView::alignMarkedObjects(ControlModification _nControlModification
,bool _bAlignAtSection
)
584 m_aScrollWindow
->alignMarkedObjects(_nControlModification
, _bAlignAtSection
);
587 bool ODesignView::handleKeyEvent(const KeyEvent
& _rEvent
)
589 if ( m_pPropWin
&& m_pPropWin
->HasChildPathFocus() )
591 if (m_xAddField
&& m_xAddField
->getDialog()->has_toplevel_focus())
593 if (m_xReportExplorer
&& m_xReportExplorer
->getDialog()->has_toplevel_focus())
595 return m_aScrollWindow
->handleKeyEvent(_rEvent
);
598 void ODesignView::setMarked(const uno::Reference
< report::XSection
>& _xSection
,bool _bMark
)
600 m_aScrollWindow
->setMarked(_xSection
,_bMark
);
602 UpdatePropertyBrowserDelayed(getMarkedSection()->getReportSection().getSectionView());
604 m_pCurrentView
= nullptr;
607 void ODesignView::setMarked(const uno::Sequence
< uno::Reference
< report::XReportComponent
> >& _aShapes
,bool _bMark
)
609 m_aScrollWindow
->setMarked(_aShapes
,_bMark
);
610 if ( _aShapes
.hasElements() && _bMark
)
611 showProperties(_aShapes
[0]);
613 m_xReportComponent
.clear();
616 void ODesignView::MouseButtonDown( const MouseEvent
& rMEvt
)
618 if ( rMEvt
.IsLeft() )
620 const uno::Sequence
< beans::PropertyValue
> aArgs
;
621 getController().executeChecked(SID_SELECT_REPORT
,aArgs
);
623 ODataView::MouseButtonDown(rMEvt
);
626 uno::Any
ODesignView::getCurrentlyShownProperty() const
629 OSectionWindow
* pSectionWindow
= getMarkedSection();
630 if ( pSectionWindow
)
632 ::std::vector
< uno::Reference
< uno::XInterface
> > aSelection
;
633 pSectionWindow
->getReportSection().fillControlModelSelection(aSelection
);
634 if ( !aSelection
.empty() )
636 uno::Sequence
< uno::Reference
< report::XReportComponent
> > aSeq(aSelection
.size());
638 aSelection
.begin(), aSelection
.end(), aSeq
.getArray(),
639 [](const auto& rxInterface
)
640 { return uno::Reference
<report::XReportComponent
>(rxInterface
, uno::UNO_QUERY
); });
647 void ODesignView::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
649 m_aScrollWindow
->fillControlModelSelection(_rSelection
);
652 void ODesignView::setGridSnap(bool bOn
)
654 m_aScrollWindow
->setGridSnap(bOn
);
658 void ODesignView::setDragStripes(bool bOn
)
660 m_aScrollWindow
->setDragStripes(bOn
);
663 bool ODesignView::isHandleEvent() const
665 return m_pPropWin
&& m_pPropWin
->HasChildPathFocus();
668 sal_uInt32
ODesignView::getMarkedObjectCount() const
670 return m_aScrollWindow
->getMarkedObjectCount();
673 void ODesignView::zoom(const Fraction
& _aZoom
)
675 m_aScrollWindow
->zoom(_aZoom
);
678 sal_uInt16
ODesignView::getZoomFactor(SvxZoomType _eType
) const
680 return m_aScrollWindow
->getZoomFactor(_eType
);
686 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */