tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / reportdesign / source / ui / report / DesignView.cxx
blob19d94c56396dad87d017e5da5eb7cb0973141847
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <RptDef.hxx>
25 #include <UITools.hxx>
26 #include <RptObject.hxx>
27 #include <propbrw.hxx>
28 #include <helpids.h>
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>
40 #include <algorithm>
42 namespace rptui
44 using namespace ::dbaui;
45 using namespace ::com::sun::star;
46 using namespace uno;
47 using namespace beans;
49 #define START_SIZE_TASKPANE 30
50 #define COLSET_ID 1
51 #define REPORT_ID 2
52 #define TASKPANE_ID 3
54 namespace {
56 class OTaskWindow : public vcl::Window
58 VclPtr<PropBrw> m_pPropWin;
59 public:
60 explicit OTaskWindow(vcl::Window* _pParent) : Window(_pParent),m_pPropWin(nullptr){}
61 virtual ~OTaskWindow() override { disposeOnce(); }
62 virtual void dispose() override { m_pPropWin.clear(); vcl::Window::dispose(); }
64 void setPropertyBrowser(PropBrw* _pPropWin)
66 m_pPropWin = _pPropWin;
69 virtual void Resize() override
71 const Size aSize = GetOutputSizePixel();
72 if ( m_pPropWin && aSize.Height() && aSize.Width() )
73 m_pPropWin->SetSizePixel(aSize);
81 ODesignView::ODesignView( vcl::Window* pParent,
82 const Reference< XComponentContext >& _rxOrb,
83 OReportController& _rController) :
84 ODataView( pParent, _rController, _rxOrb, WB_DIALOGCONTROL )
85 ,m_aSplitWin(VclPtr<SplitWindow>::Create(this))
86 ,m_rReportController( _rController )
87 ,m_aScrollWindow(VclPtr<rptui::OScrollWindowHelper>::Create(this))
88 ,m_pPropWin(nullptr)
89 ,m_pCurrentView(nullptr)
90 ,m_aMarkIdle("reportdesign ODesignView Mark Idle")
91 ,m_eMode( DlgEdMode::Select )
92 ,m_eActObj( SdrObjKind::NONE )
93 ,m_aGridSizeCoarse( 1000, 1000 ) // #i93595# 100TH_MM changed to grid using coarse 1 cm grid
94 ,m_aGridSizeFine( 250, 250 ) // and a 0,25 cm subdivision for better visualisation
95 ,m_bDeleted( false )
97 SetHelpId(u"" UID_RPT_RPT_APP_VIEW ""_ustr);
98 ImplInitSettings();
100 SetMapMode( MapMode( MapUnit::Map100thMM ) );
102 // now create the task pane on the right side :-)
103 m_pTaskPane = VclPtr<OTaskWindow>::Create(this);
105 m_aSplitWin->InsertItem( COLSET_ID,100,SPLITWINDOW_APPEND, 0, SplitWindowItemFlags::PercentSize | SplitWindowItemFlags::ColSet );
106 m_aSplitWin->InsertItem( REPORT_ID, m_aScrollWindow.get(), 100, SPLITWINDOW_APPEND, COLSET_ID, SplitWindowItemFlags::PercentSize);
108 // set up splitter
109 m_aSplitWin->SetSplitHdl(LINK(this, ODesignView,SplitHdl));
110 m_aSplitWin->SetAlign(WindowAlign::Left);
111 m_aSplitWin->Show();
113 m_aMarkIdle.SetInvokeHandler( LINK( this, ODesignView, MarkTimeout ) );
117 ODesignView::~ODesignView()
119 disposeOnce();
122 void ODesignView::dispose()
124 m_bDeleted = true;
125 Hide();
126 m_aScrollWindow->Hide();
127 m_aMarkIdle.Stop();
128 if ( m_pPropWin )
130 notifySystemWindow(this,m_pPropWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
131 m_pPropWin.disposeAndClear();
133 if ( m_xAddField )
135 SvtViewOptions aDlgOpt( EViewType::Window, u"" UID_RPT_RPT_APP_VIEW ""_ustr );
136 aDlgOpt.SetWindowState(m_xAddField->getDialog()->get_window_state(vcl::WindowDataMask::All));
138 if (m_xAddField->getDialog()->get_visible())
139 m_xAddField->response(RET_CANCEL);
141 m_xAddField.reset();
143 if ( m_xReportExplorer )
145 SvtViewOptions aDlgOpt(EViewType::Window, m_xReportExplorer->get_help_id());
146 aDlgOpt.SetWindowState(m_xReportExplorer->getDialog()->get_window_state(vcl::WindowDataMask::All));
148 if (m_xReportExplorer->getDialog()->get_visible())
149 m_xReportExplorer->response(RET_CANCEL);
151 m_xReportExplorer.reset();
154 m_pTaskPane.disposeAndClear();
155 m_aScrollWindow.disposeAndClear();
156 m_aSplitWin.disposeAndClear();
157 dbaui::ODataView::dispose();
160 void ODesignView::initialize()
162 SetMapMode( MapMode( MapUnit::Map100thMM ) );
163 m_aScrollWindow->initialize();
164 m_aScrollWindow->Show();
167 void ODesignView::DataChanged( const DataChangedEvent& rDCEvt )
169 ODataView::DataChanged( rDCEvt );
171 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
172 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
174 ImplInitSettings();
175 Invalidate();
179 bool ODesignView::PreNotify( NotifyEvent& rNEvt )
181 bool bRet = ODataView::PreNotify(rNEvt); // 1 := has to be handled here
182 switch(rNEvt.GetType())
184 case NotifyEventType::KEYINPUT:
186 if ( m_pPropWin && m_pPropWin->HasChildPathFocus() )
187 return false;
188 if (m_xAddField && m_xAddField->getDialog()->has_toplevel_focus())
189 return false;
190 if ( m_xReportExplorer && m_xReportExplorer->getDialog()->has_toplevel_focus())
191 return false;
192 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
193 if ( handleKeyEvent(*pKeyEvent) )
194 bRet = true;
195 else if ( bRet && m_pAccel )
197 const vcl::KeyCode& rCode = pKeyEvent->GetKeyCode();
198 util::URL aUrl;
199 aUrl.Complete = m_pAccel->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rCode));
200 if ( aUrl.Complete.isEmpty() || !m_xController->isCommandEnabled( aUrl.Complete ) )
201 bRet = false;
203 break;
205 default:
206 break;
209 return bRet;
212 void ODesignView::resizeDocumentView(tools::Rectangle& _rPlayground)
214 if ( !_rPlayground.IsEmpty() )
216 const Size aPlaygroundSize( _rPlayground.GetSize() );
218 // calc the split pos, and forward it to the controller
219 sal_Int32 nSplitPos = getController().getSplitPos();
220 if ( 0 != aPlaygroundSize.Width() )
222 if ( ( -1 == nSplitPos )
223 || ( nSplitPos >= aPlaygroundSize.Width() )
226 tools::Long nMinWidth = static_cast<tools::Long>(0.1*aPlaygroundSize.Width());
227 if ( m_pPropWin && m_pPropWin->IsVisible() )
228 nMinWidth = m_pPropWin->GetMinOutputSizePixel().Width();
229 nSplitPos = static_cast<sal_Int32>(_rPlayground.Right() - nMinWidth);
230 getController().setSplitPos(nSplitPos);
234 if ( m_aSplitWin->IsItemValid(TASKPANE_ID) )
236 // normalize the split pos
237 const tools::Long nSplitterWidth = StyleSettings::GetSplitSize();
238 Point aTaskPanePos(nSplitPos + nSplitterWidth, _rPlayground.Top());
239 if (m_pTaskPane && m_pTaskPane->IsVisible() && m_pPropWin)
241 aTaskPanePos.setX( aPlaygroundSize.Width() - m_pTaskPane->GetSizePixel().Width() );
242 sal_Int32 nMinWidth = m_pPropWin->getMinimumSize().Width();
243 if ( nMinWidth > (aPlaygroundSize.Width() - aTaskPanePos.X()) )
245 aTaskPanePos.setX( aPlaygroundSize.Width() - nMinWidth );
247 nSplitPos = aTaskPanePos.X() - nSplitterWidth;
248 getController().setSplitPos(nSplitPos);
250 if (const auto nWidth = aPlaygroundSize.Width())
252 const tools::Long nTaskPaneSize = static_cast<tools::Long>((aPlaygroundSize.Width() - aTaskPanePos.X())*100/nWidth);
253 if ( m_aSplitWin->GetItemSize( TASKPANE_ID ) != nTaskPaneSize )
255 m_aSplitWin->SetItemSize( REPORT_ID, 99 - nTaskPaneSize );
256 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);
276 if ( xProp.is() )
278 m_pPropWin->Update(xProp);
279 static_cast<OTaskWindow*>(m_pTaskPane.get())->Resize();
281 Resize();
286 void ODesignView::SetMode( DlgEdMode _eNewMode )
288 m_eMode = _eNewMode;
289 if ( m_eMode == DlgEdMode::Select )
290 m_eActObj = SdrObjKind::NONE;
292 m_aScrollWindow->SetMode(_eNewMode);
295 void ODesignView::SetInsertObj( SdrObjKind eObj,const OUString& _sShapeType )
297 m_eActObj = eObj;
298 m_aScrollWindow->SetInsertObj( eObj,_sShapeType );
301 OUString const & ODesignView::GetInsertObjString() const
303 return m_aScrollWindow->GetInsertObjString();
307 void ODesignView::Cut()
309 Copy();
310 Delete();
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 );
352 Broadcast( aHint );
354 m_aMarkIdle.Start();
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()
385 Window::GetFocus();
387 if ( !m_bDeleted )
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 SdrObjKind _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()) )
436 return;
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);
448 else
449 m_aSplitWin->RemoveItem(TASKPANE_ID);
451 if ( bWillBeVisible )
452 m_aMarkIdle.Start();
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;
463 m_aMarkIdle.Start();
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, m_xReportExplorer->get_help_id());
479 if ( aDlgOpt.Exists() )
480 m_xReportExplorer->getDialog()->set_window_state(aDlgOpt.GetWindowState());
483 if (!m_xReportExplorer->getDialog()->get_visible())
484 weld::DialogController::runAsync(m_xReportExplorer, [this](sal_Int32 /*nResult*/) { m_xReportExplorer.reset(); });
485 else
486 m_xReportExplorer->response(RET_CANCEL);
489 bool ODesignView::isAddFieldVisible() const
491 return m_xAddField && m_xAddField->getDialog()->get_visible();
494 void ODesignView::toggleAddField()
496 if (!m_xAddField)
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();
505 else
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, u"" UID_RPT_RPT_APP_VIEW ""_ustr );
517 if ( aDlgOpt.Exists() )
518 m_xAddField->getDialog()->set_window_state(aDlgOpt.GetWindowState());
519 m_xAddField->Update();
521 if (!m_xAddField->getDialog()->get_visible())
522 weld::DialogController::runAsync(m_xAddField, [this](sal_Int32 /*nResult*/) { m_xAddField.reset(); });
523 else
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();
533 return xSection;
536 uno::Reference< report::XReportComponent > ODesignView::getCurrentControlModel() const
538 uno::Reference< report::XReportComponent > xModel;
539 if ( m_pCurrentView )
541 xModel = m_pCurrentView->getReportSection()->getCurrentControlModel();
543 return xModel;
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)
578 if ( m_pPropWin )
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() )
590 return false;
591 if (m_xAddField && m_xAddField->getDialog()->has_toplevel_focus())
592 return false;
593 if (m_xReportExplorer && m_xReportExplorer->getDialog()->has_toplevel_focus())
594 return false;
595 return m_aScrollWindow->handleKeyEvent(_rEvent);
598 void ODesignView::setMarked(const uno::Reference< report::XSection>& _xSection,bool _bMark)
600 m_aScrollWindow->setMarked(_xSection,_bMark);
601 if ( _bMark )
602 UpdatePropertyBrowserDelayed(getMarkedSection()->getReportSection().getSectionView());
603 else
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]);
612 else
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
628 uno::Any aRet;
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());
637 std::transform(
638 aSelection.begin(), aSelection.end(), aSeq.getArray(),
639 [](const auto& rxInterface)
640 { return uno::Reference<report::XReportComponent>(rxInterface, uno::UNO_QUERY); });
641 aRet <<= aSeq;
644 return aRet;
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);
683 } // rptui
686 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */