Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uno / unotxvw.cxx
blobf1b1019ba79c1b3bcbfd74a0e8e0b4ceae3ad5dd
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 <memory>
21 #include <viscrs.hxx>
22 #include <o3tl/any.hxx>
23 #include <sfx2/printer.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <cmdid.h>
26 #include <docsh.hxx>
27 #include <rubylist.hxx>
28 #include <doc.hxx>
29 #include <IDocumentDeviceAccess.hxx>
30 #include <unotxvw.hxx>
31 #include <unodispatch.hxx>
32 #include <unomap.hxx>
33 #include <unoprnms.hxx>
34 #include <view.hxx>
35 #include <viewopt.hxx>
36 #include <unomod.hxx>
37 #include <unoframe.hxx>
38 #include <unocrsr.hxx>
39 #include <wrtsh.hxx>
40 #include <unotbl.hxx>
41 #include <svx/fmshell.hxx>
42 #include <svx/svdview.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdouno.hxx>
45 #include <editeng/pbinitem.hxx>
46 #include <pagedesc.hxx>
47 #include <editeng/lrspitem.hxx>
48 #include <editeng/ulspitem.hxx>
49 #include <sfx2/bindings.hxx>
50 #include <sfx2/request.hxx>
51 #include <frmatr.hxx>
52 #include <IMark.hxx>
53 #include <unodraw.hxx>
54 #include <svx/svdpagv.hxx>
55 #include <ndtxt.hxx>
56 #include <SwStyleNameMapper.hxx>
57 #include <com/sun/star/beans/PropertyAttribute.hpp>
58 #include <com/sun/star/drawing/ShapeCollection.hpp>
59 #include <editeng/outliner.hxx>
60 #include <editeng/editview.hxx>
61 #include <unoparagraph.hxx>
62 #include <unocrsrhelper.hxx>
63 #include <unotextrange.hxx>
64 #include <sfx2/docfile.hxx>
65 #include <swdtflvr.hxx>
66 #include <rootfrm.hxx>
67 #include <edtwin.hxx>
68 #include <vcl/svapp.hxx>
69 #include <comphelper/processfactory.hxx>
70 #include <comphelper/profilezone.hxx>
71 #include <comphelper/servicehelper.hxx>
72 #include <cppuhelper/supportsservice.hxx>
73 #include <cppuhelper/typeprovider.hxx>
74 #include <tools/UnitConversion.hxx>
75 #include <comphelper/dumpxmltostring.hxx>
76 #include <fmtanchr.hxx>
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::uno;
80 using namespace ::com::sun::star::lang;
81 using namespace ::com::sun::star::beans;
82 using namespace ::com::sun::star::text;
83 using namespace ::com::sun::star::view;
84 using namespace ::com::sun::star::frame;
86 using ::com::sun::star::util::URL;
88 SwXTextView::SwXTextView(SwView* pSwView) :
89 SwXTextView_Base(pSwView),
90 m_SelChangedListeners(m_aMutex),
91 m_pView(pSwView),
92 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_VIEW ) )
97 SwXTextView::~SwXTextView()
99 Invalidate();
102 void SwXTextView::Invalidate()
104 if(mxViewSettings.is())
106 comphelper::ChainablePropertySet *pSettings = static_cast < comphelper::ChainablePropertySet * > ( mxViewSettings.get() );
107 static_cast < SwXViewSettings* > ( pSettings )->Invalidate();
108 mxViewSettings.clear();
110 if(mxTextViewCursor.is())
112 text::XTextViewCursor* pCursor = mxTextViewCursor.get();
113 static_cast<SwXTextViewCursor*>(pCursor)->Invalidate();
114 mxTextViewCursor.clear();
117 osl_atomic_increment(&m_refCount); //prevent second d'tor call
120 uno::Reference<uno::XInterface> const xInt(static_cast<
121 cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
122 lang::EventObject aEvent(xInt);
123 m_SelChangedListeners.disposeAndClear(aEvent);
126 osl_atomic_decrement(&m_refCount);
127 m_pView = nullptr;
130 sal_Bool SwXTextView::select(const uno::Any& aInterface)
132 SolarMutexGuard aGuard;
134 uno::Reference< uno::XInterface > xInterface;
135 if (!GetView() || !(aInterface >>= xInterface))
137 return false;
140 SwWrtShell& rSh = GetView()->GetWrtShell();
141 SwDoc* pDoc = GetView()->GetDocShell()->GetDoc();
142 std::vector<SdrObject *> sdrObjects;
143 uno::Reference<awt::XControlModel> const xCtrlModel(xInterface,
144 UNO_QUERY);
145 if (xCtrlModel.is())
147 uno::Reference<awt::XControl> xControl;
148 SdrObject *const pSdrObject = GetControl(xCtrlModel, xControl);
149 if (pSdrObject) // hmm... needs view to verify it's in right doc...
151 sdrObjects.push_back(pSdrObject);
154 else
156 SwPaM * pPaM(nullptr);
157 std::pair<OUString, FlyCntType> frame;
158 OUString tableName;
159 SwUnoTableCursor const* pTableCursor(nullptr);
160 ::sw::mark::IMark const* pMark(nullptr);
161 SwUnoCursorHelper::GetSelectableFromAny(xInterface, *pDoc,
162 pPaM, frame, tableName, pTableCursor, pMark, sdrObjects);
163 if (pPaM)
165 rSh.EnterStdMode();
166 rSh.SetSelection(*pPaM);
167 // the pPaM has been copied - delete it
168 while (pPaM->GetNext() != pPaM)
170 // coverity[deref_arg] - the SwPaM delete moves a new entry into GetNext()
171 delete pPaM->GetNext();
173 delete pPaM;
174 return true;
176 else if (!frame.first.isEmpty())
178 bool const bSuccess(rSh.GotoFly(frame.first, frame.second));
179 if (bSuccess)
181 rSh.HideCursor();
182 rSh.EnterSelFrameMode();
184 return true;
186 else if (!tableName.isEmpty())
188 rSh.EnterStdMode();
189 rSh.GotoTable(tableName);
190 return true;
192 else if (pTableCursor)
194 UnoActionRemoveContext const aContext(*pTableCursor);
195 rSh.EnterStdMode();
196 rSh.SetSelection(*pTableCursor);
197 return true;
199 else if (pMark)
201 rSh.EnterStdMode();
202 rSh.GotoMark(pMark);
203 return true;
205 // sdrObjects handled below
207 bool bRet(false);
208 if (!sdrObjects.empty())
211 SdrView *const pDrawView = rSh.GetDrawView();
212 SdrPageView *const pPV = pDrawView->GetSdrPageView();
214 pDrawView->SdrEndTextEdit();
215 pDrawView->UnmarkAll();
217 for (SdrObject* pSdrObject : sdrObjects)
219 // GetSelectableFromAny did not check pSdrObject is in right doc!
220 if (pPV && pSdrObject->getSdrPageFromSdrObject() == pPV->GetPage())
222 pDrawView->MarkObj(pSdrObject, pPV);
223 bRet = true;
227 // tdf#112696 if we selected every individual element of a group, then
228 // select that group instead
229 const SdrMarkList &rMrkList = pDrawView->GetMarkedObjectList();
230 size_t nMarkCount = rMrkList.GetMarkCount();
231 if (nMarkCount > 1)
233 SdrObject* pObject = rMrkList.GetMark(0)->GetMarkedSdrObj();
234 SdrObject* pGroupParent = pObject->getParentSdrObjectFromSdrObject();
235 for (size_t i = 1; i < nMarkCount; ++i)
237 pObject = rMrkList.GetMark(i)->GetMarkedSdrObj();
238 SdrObject* pParent = pObject->getParentSdrObjectFromSdrObject();
239 if (pParent != pGroupParent)
241 pGroupParent = nullptr;
242 break;
246 if (pGroupParent && pGroupParent->IsGroupObject() &&
247 pGroupParent->getChildrenOfSdrObject()->GetObjCount() == nMarkCount)
249 pDrawView->UnmarkAll();
250 pDrawView->MarkObj(pGroupParent, pPV);
254 return bRet;
257 uno::Any SwXTextView::getSelection()
259 SolarMutexGuard aGuard;
260 uno::Reference< uno::XInterface > aRef;
261 if(GetView())
263 //force immediat shell update
264 m_pView->StopShellTimer();
265 //Generating an interface from the current selection.
266 SwWrtShell& rSh = m_pView->GetWrtShell();
267 ShellMode eSelMode = m_pView->GetShellMode();
268 switch(eSelMode)
270 case ShellMode::TableText :
272 if(rSh.GetTableCursor())
274 OSL_ENSURE(rSh.GetTableFormat(), "not a table format?");
275 uno::Reference< text::XTextTableCursor > xCursor = new SwXTextTableCursor(*rSh.GetTableFormat(),
276 rSh.GetTableCursor());
277 aRef.set(xCursor, uno::UNO_QUERY);
278 break;
280 [[fallthrough]];
281 // without a table selection the text will be delivered
283 case ShellMode::ListText :
284 case ShellMode::TableListText:
285 case ShellMode::Text :
287 uno::Reference< container::XIndexAccess > xPos = SwXTextRanges::Create(rSh.GetCursor());
288 aRef.set(xPos, uno::UNO_QUERY);
290 break;
291 case ShellMode::Frame :
293 SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat();
294 if (pFormat)
296 aRef = static_cast<cppu::OWeakObject*>(SwXTextFrame::CreateXTextFrame(
297 *pFormat->GetDoc(), pFormat).get());
300 break;
301 case ShellMode::Graphic :
303 SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat();
304 if (pFormat)
306 aRef = static_cast<cppu::OWeakObject*>(SwXTextGraphicObject::CreateXTextGraphicObject(
307 *pFormat->GetDoc(), pFormat).get());
310 break;
311 case ShellMode::Object :
313 SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat();
314 if (pFormat)
316 aRef = static_cast<cppu::OWeakObject*>(SwXTextEmbeddedObject::CreateXTextEmbeddedObject(
317 *pFormat->GetDoc(), pFormat).get());
320 break;
321 case ShellMode::Draw :
322 case ShellMode::DrawForm :
323 case ShellMode::DrawText :
324 case ShellMode::Bezier :
326 uno::Reference< drawing::XShapes > xShCol = drawing::ShapeCollection::create(
327 comphelper::getProcessComponentContext());
329 const SdrMarkList& rMarkList = rSh.GetDrawView()->GetMarkedObjectList();
330 for(size_t i = 0; i < rMarkList.GetMarkCount(); ++i)
332 SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
333 uno::Reference<drawing::XShape> xShape = SwFmDrawPage::GetShape( pObj );
334 xShCol->add(xShape);
336 aRef.set(xShCol, uno::UNO_QUERY);
338 break;
339 default:;//prevent warning
342 uno::Any aRet(&aRef, cppu::UnoType<uno::XInterface>::get());
343 return aRet;
346 void SwXTextView::addSelectionChangeListener(
347 const uno::Reference< view::XSelectionChangeListener > & rxListener)
349 SolarMutexGuard aGuard;
350 m_SelChangedListeners.addInterface(rxListener);
353 void SwXTextView::removeSelectionChangeListener(
354 const uno::Reference< view::XSelectionChangeListener > & rxListener)
356 SolarMutexGuard aGuard;
357 m_SelChangedListeners.removeInterface(rxListener);
360 SdrObject* SwXTextView::GetControl(
361 const uno::Reference< awt::XControlModel > & xModel,
362 uno::Reference< awt::XControl >& xToFill )
364 SwView* pView2 = GetView();
365 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr;
366 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : nullptr;
367 vcl::Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : nullptr;
369 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::GetControl: how could I?" );
371 SdrObject* pControl = nullptr;
372 if ( pFormShell && pDrawView && pWindow )
373 pControl = pFormShell->GetFormControl( xModel, *pDrawView, *pWindow->GetOutDev(), xToFill );
374 return pControl;
377 uno::Reference< awt::XControl > SwXTextView::getControl(const uno::Reference< awt::XControlModel > & xModel)
379 SolarMutexGuard aGuard;
380 uno::Reference< awt::XControl > xRet;
381 GetControl(xModel, xRet);
382 return xRet;
385 uno::Reference< form::runtime::XFormController > SAL_CALL SwXTextView::getFormController( const uno::Reference< form::XForm >& Form )
387 SolarMutexGuard aGuard;
389 SwView* pView2 = GetView();
390 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr;
391 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : nullptr;
392 vcl::Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : nullptr;
393 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::getFormController: how could I?" );
395 uno::Reference< form::runtime::XFormController > xController;
396 if ( pFormShell && pDrawView && pWindow )
397 xController = FmFormShell::GetFormController( Form, *pDrawView, *pWindow->GetOutDev() );
398 return xController;
401 sal_Bool SAL_CALL SwXTextView::isFormDesignMode( )
403 SolarMutexGuard aGuard;
404 SwView* pView2 = GetView();
405 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr;
406 return !pFormShell || pFormShell->IsDesignMode();
409 void SAL_CALL SwXTextView::setFormDesignMode( sal_Bool DesignMode )
411 SolarMutexGuard aGuard;
412 SwView* pView2 = GetView();
413 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr;
414 if ( pFormShell )
415 pFormShell->SetDesignMode( DesignMode );
418 uno::Reference< text::XTextViewCursor > SwXTextView::getViewCursor()
420 SolarMutexGuard aGuard;
421 comphelper::ProfileZone aZone("getViewCursor");
422 if(!GetView())
423 throw uno::RuntimeException();
425 if(!mxTextViewCursor.is())
427 mxTextViewCursor = new SwXTextViewCursor(GetView());
429 return mxTextViewCursor;
432 uno::Reference<text::XTextRange>
433 SwXTextView::createTextRangeByPixelPosition(const awt::Point& rPixelPosition)
435 SolarMutexGuard aGuard;
437 Point aPixelPoint(rPixelPosition.X, rPixelPosition.Y);
438 if (!m_pView)
439 throw RuntimeException();
441 Point aLogicPoint = m_pView->GetEditWin().PixelToLogic(aPixelPoint);
442 SwWrtShell& rSh = m_pView->GetWrtShell();
443 SwPosition aPosition(*rSh.GetCurrentShellCursor().GetPoint());
444 rSh.GetLayout()->GetModelPositionForViewPoint(&aPosition, aLogicPoint);
446 if (aPosition.GetNode().IsGrfNode())
448 // The point is closest to a graphic node, look up its format.
449 const SwFrameFormat* pGraphicFormat = aPosition.GetNode().GetFlyFormat();
450 if (pGraphicFormat)
452 // Get the anchor of this format.
453 const SwFormatAnchor& rAnchor = pGraphicFormat->GetAnchor();
454 const SwPosition* pAnchor = rAnchor.GetContentAnchor();
455 if (pAnchor)
457 aPosition = *pAnchor;
459 else
461 // Page-anchored graphics have no anchor.
462 return {};
467 rtl::Reference<SwXTextRange> xRet
468 = SwXTextRange::CreateXTextRange(*rSh.GetDoc(), aPosition, /*pMark=*/nullptr);
470 return xRet;
473 uno::Reference< beans::XPropertySet > SwXTextView::getViewSettings()
475 SolarMutexGuard aGuard;
476 if(!m_pView)
477 throw uno::RuntimeException();
479 if(!mxViewSettings.is())
481 mxViewSettings = new SwXViewSettings( m_pView );
484 return mxViewSettings;
487 Sequence< Sequence< PropertyValue > > SwXTextView::getRubyList( sal_Bool /*bAutomatic*/ )
489 SolarMutexGuard aGuard;
491 if(!GetView())
492 throw RuntimeException();
493 SwWrtShell& rSh = m_pView->GetWrtShell();
494 ShellMode eSelMode = m_pView->GetShellMode();
495 if (eSelMode != ShellMode::ListText &&
496 eSelMode != ShellMode::TableListText &&
497 eSelMode != ShellMode::TableText &&
498 eSelMode != ShellMode::Text )
499 return Sequence< Sequence< PropertyValue > > ();
501 SwRubyList aList;
503 const sal_uInt16 nCount = SwDoc::FillRubyList( *rSh.GetCursor(), aList );
504 Sequence< Sequence< PropertyValue > > aRet(nCount);
505 Sequence< PropertyValue >* pRet = aRet.getArray();
506 OUString aString;
507 for(sal_uInt16 n = 0; n < nCount; n++)
509 const SwRubyListEntry* pEntry = aList[n].get();
511 const OUString& rEntryText = pEntry->GetText();
512 const SwFormatRuby& rAttr = pEntry->GetRubyAttr();
514 pRet[n].realloc(6);
515 PropertyValue* pValues = pRet[n].getArray();
516 pValues[0].Name = UNO_NAME_RUBY_BASE_TEXT;
517 pValues[0].Value <<= rEntryText;
518 pValues[1].Name = UNO_NAME_RUBY_TEXT;
519 pValues[1].Value <<= rAttr.GetText();
520 pValues[2].Name = UNO_NAME_RUBY_CHAR_STYLE_NAME;
521 SwStyleNameMapper::FillProgName(rAttr.GetCharFormatName(), aString, SwGetPoolIdFromName::ChrFmt );
522 pValues[2].Value <<= aString;
523 pValues[3].Name = UNO_NAME_RUBY_ADJUST;
524 pValues[3].Value <<= static_cast<sal_Int16>(rAttr.GetAdjustment());
525 pValues[4].Name = UNO_NAME_RUBY_IS_ABOVE;
526 pValues[4].Value <<= !rAttr.GetPosition();
527 pValues[5].Name = UNO_NAME_RUBY_POSITION;
528 pValues[5].Value <<= rAttr.GetPosition();
530 return aRet;
533 void SAL_CALL SwXTextView::setRubyList(
534 const Sequence< Sequence< PropertyValue > >& rRubyList, sal_Bool /*bAutomatic*/ )
536 SolarMutexGuard aGuard;
538 if(!GetView() || !rRubyList.hasElements())
539 throw RuntimeException();
540 SwWrtShell& rSh = m_pView->GetWrtShell();
541 ShellMode eSelMode = m_pView->GetShellMode();
542 if (eSelMode != ShellMode::ListText &&
543 eSelMode != ShellMode::TableListText &&
544 eSelMode != ShellMode::TableText &&
545 eSelMode != ShellMode::Text )
546 throw RuntimeException();
548 SwRubyList aList;
550 for(const Sequence<PropertyValue>& rPropList : rRubyList)
552 std::unique_ptr<SwRubyListEntry> pEntry(new SwRubyListEntry);
553 OUString sTmp;
554 for(const PropertyValue& rProperty : rPropList)
556 if(rProperty.Name == UNO_NAME_RUBY_BASE_TEXT)
558 rProperty.Value >>= sTmp;
559 pEntry->SetText(sTmp);
561 else if(rProperty.Name == UNO_NAME_RUBY_TEXT)
563 rProperty.Value >>= sTmp;
564 pEntry->GetRubyAttr().SetText(sTmp);
566 else if(rProperty.Name == UNO_NAME_RUBY_CHAR_STYLE_NAME)
568 if(rProperty.Value >>= sTmp)
570 OUString sName;
571 SwStyleNameMapper::FillUIName(sTmp, sName, SwGetPoolIdFromName::ChrFmt );
572 const sal_uInt16 nPoolId = sName.isEmpty() ? 0
573 : SwStyleNameMapper::GetPoolIdFromUIName(sName,
574 SwGetPoolIdFromName::ChrFmt );
576 pEntry->GetRubyAttr().SetCharFormatName( sName );
577 pEntry->GetRubyAttr().SetCharFormatId( nPoolId );
580 else if(rProperty.Name == UNO_NAME_RUBY_ADJUST)
582 sal_Int16 nTmp = 0;
583 if(rProperty.Value >>= nTmp)
584 pEntry->GetRubyAttr().SetAdjustment(static_cast<css::text::RubyAdjust>(nTmp));
586 else if(rProperty.Name == UNO_NAME_RUBY_IS_ABOVE)
588 bool bValue = !rProperty.Value.hasValue() ||
589 *o3tl::doAccess<bool>(rProperty.Value);
590 pEntry->GetRubyAttr().SetPosition(bValue ? 0 : 1);
592 else if(rProperty.Name == UNO_NAME_RUBY_POSITION)
594 sal_Int16 nTmp = 0;
595 if(rProperty.Value >>= nTmp)
596 pEntry->GetRubyAttr().SetPosition( nTmp );
599 aList.push_back(std::move(pEntry));
601 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
602 pDoc->SetRubyList( *rSh.GetCursor(), aList );
605 SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc()
607 SwWrtShell& rOldSh = m_pView->GetWrtShell();
608 SfxPrinter *pPrt = rOldSh.getIDocumentDeviceAccess().getPrinter( false );
609 SwDocShell* pDocSh;
610 SfxObjectShellLock xDocSh( pDocSh = new SwDocShell(SfxObjectCreateMode::STANDARD) );
611 xDocSh->DoInitNew();
612 SwDoc *const pTempDoc( pDocSh->GetDoc() );
613 // #i103634#, #i112425#: do not expand numbering and fields on PDF export
614 pTempDoc->SetClipBoard(true);
615 rOldSh.FillPrtDoc(*pTempDoc, pPrt);
616 SfxViewFrame* pDocFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, SFX_INTERFACE_NONE );
617 SwView* pDocView = static_cast<SwView*>( pDocFrame->GetViewShell() );
618 pDocView->AttrChangedNotify(nullptr);//So that SelectShell is called.
619 if (SwWrtShell* pSh = pDocView->GetWrtShellPtr())
621 IDocumentDeviceAccess& rIDDA = pSh->getIDocumentDeviceAccess();
622 SfxPrinter* pTempPrinter = rIDDA.getPrinter( true );
624 const SwPageDesc& rCurPageDesc = rOldSh.GetPageDesc(rOldSh.GetCurPageDesc());
626 IDocumentDeviceAccess& rIDDA_old = rOldSh.getIDocumentDeviceAccess();
628 if( rIDDA_old.getPrinter( false ) )
630 rIDDA.setJobsetup( *rIDDA_old.getJobsetup() );
631 //#69563# if it isn't the same printer then the pointer has been invalidated!
632 pTempPrinter = rIDDA.getPrinter( true );
635 pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
638 return xDocSh;
641 void SwXTextView::NotifySelChanged()
643 OSL_ENSURE( m_pView, "view is missing" );
645 uno::Reference<uno::XInterface> const xInt(
646 static_cast<cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
648 lang::EventObject const aEvent(xInt);
649 m_SelChangedListeners.notifyEach(
650 &view::XSelectionChangeListener::selectionChanged, aEvent);
653 void SwXTextView::NotifyDBChanged()
655 URL aURL;
656 aURL.Complete = OUString::createFromAscii(SwXDispatch::GetDBChangeURL());
658 m_SelChangedListeners.forEach(
659 [&aURL] (const uno::Reference<XSelectionChangeListener>& xListener)
661 uno::Reference<XDispatch> xDispatch(xListener, UNO_QUERY);
662 if (xDispatch)
663 xDispatch->dispatch(aURL, {});
667 uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXTextView::getPropertySetInfo( )
669 SolarMutexGuard aGuard;
670 static uno::Reference< XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo();
671 return aRef;
674 void SAL_CALL SwXTextView::setPropertyValue(
675 const OUString& rPropertyName, const uno::Any& rValue )
677 SolarMutexGuard aGuard;
678 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
679 if (!pEntry)
680 throw UnknownPropertyException(rPropertyName);
681 else if (pEntry->nFlags & PropertyAttribute::READONLY)
682 throw PropertyVetoException();
683 else
685 switch (pEntry->nWID)
687 case WID_IS_HIDE_SPELL_MARKS :
688 // deprecated #i91949
689 break;
690 case WID_IS_CONSTANT_SPELLCHECK :
692 bool bVal = false;
693 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
694 if (!pOpt || !(rValue >>= bVal))
695 throw RuntimeException();
696 SwViewOption aNewOpt( *pOpt );
697 if (pEntry->nWID == WID_IS_CONSTANT_SPELLCHECK)
698 aNewOpt.SetOnlineSpell(bVal);
699 m_pView->GetWrtShell().ApplyViewOptions( aNewOpt );
701 break;
702 default :
703 OSL_FAIL("unknown WID");
708 uno::Any SAL_CALL SwXTextView::getPropertyValue(
709 const OUString& rPropertyName )
711 SolarMutexGuard aGuard;
713 Any aRet;
715 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
716 if (!pEntry)
717 throw UnknownPropertyException(rPropertyName);
719 sal_Int16 nWID = pEntry->nWID;
720 switch (nWID)
722 case WID_PAGE_COUNT :
723 case WID_LINE_COUNT :
725 // format document completely in order to get meaningful
726 // values for page count and line count
727 m_pView->GetWrtShell().CalcLayout();
729 sal_Int32 nCount = -1;
730 if (nWID == WID_PAGE_COUNT)
731 nCount = m_pView->GetWrtShell().GetPageCount();
732 else // WID_LINE_COUNT
733 nCount = m_pView->GetWrtShell().GetLineCount();
734 aRet <<= nCount;
736 break;
737 case WID_IS_HIDE_SPELL_MARKS :
738 // deprecated #i91949
739 break;
740 case WID_IS_CONSTANT_SPELLCHECK :
742 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
743 if (!pOpt)
744 throw RuntimeException();
745 aRet <<= pOpt->IsOnlineSpell();
747 break;
748 default :
749 OSL_FAIL("unknown WID");
752 return aRet;
755 void SAL_CALL SwXTextView::addPropertyChangeListener(
756 const OUString& /*rPropertyName*/,
757 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
759 OSL_FAIL("not implemented");
762 void SAL_CALL SwXTextView::removePropertyChangeListener(
763 const OUString& /*rPropertyName*/,
764 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
766 OSL_FAIL("not implemented");
769 void SAL_CALL SwXTextView::addVetoableChangeListener(
770 const OUString& /*rPropertyName*/,
771 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
773 OSL_FAIL("not implemented");
776 void SAL_CALL SwXTextView::removeVetoableChangeListener(
777 const OUString& /*rPropertyName*/,
778 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
780 OSL_FAIL("not implemented");
783 OUString SwXTextView::getImplementationName()
785 return "SwXTextView";
788 sal_Bool SwXTextView::supportsService(const OUString& rServiceName)
790 return cppu::supportsService(this, rServiceName);
793 Sequence< OUString > SwXTextView::getSupportedServiceNames()
795 return { "com.sun.star.text.TextDocumentView", "com.sun.star.view.OfficeDocumentView" };
798 SwXTextViewCursor::SwXTextViewCursor(SwView* pVw) :
799 m_pView(pVw),
800 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
804 SwXTextViewCursor::~SwXTextViewCursor()
808 // used to determine if there is a text selection or not.
809 // If there is no text selection the functions that need a working
810 // cursor will be disabled (throw RuntimeException). This will be the case
811 // for the following interfaces:
812 // - XViewCursor
813 // - XTextCursor
814 // - XTextRange
815 // - XLineCursor
816 bool SwXTextViewCursor::IsTextSelection( bool bAllowTables ) const
819 bool bRes = false;
820 OSL_ENSURE(m_pView, "m_pView is NULL ???");
821 if(m_pView)
823 //! m_pView->GetShellMode() will only work after the shell
824 //! has already changed and thus can not be used here!
825 SelectionType eSelType = m_pView->GetWrtShell().GetSelectionType();
826 bRes = ( (SelectionType::Text & eSelType) ||
827 (SelectionType::NumberList & eSelType) ) &&
828 (!(SelectionType::TableCell & eSelType) || bAllowTables);
830 return bRes;
833 sal_Bool SwXTextViewCursor::isVisible()
835 OSL_FAIL("not implemented");
836 return true;
839 void SwXTextViewCursor::setVisible(sal_Bool /*bVisible*/)
841 OSL_FAIL("not implemented");
844 awt::Point SwXTextViewCursor::getPosition()
846 SolarMutexGuard aGuard;
847 awt::Point aRet;
848 if(!m_pView)
849 throw uno::RuntimeException();
851 const SwWrtShell& rSh = m_pView->GetWrtShell();
852 const SwRect& aCharRect(rSh.GetCharRect());
854 const SwFrameFormat& rMaster = rSh.GetPageDesc( rSh.GetCurPageDesc() ).GetMaster();
856 const SvxULSpaceItem& rUL = rMaster.GetULSpace();
857 const tools::Long nY = aCharRect.Top() - (rUL.GetUpper() + DOCUMENTBORDER);
858 aRet.Y = convertTwipToMm100(nY);
860 const SvxLRSpaceItem& rLR = rMaster.GetLRSpace();
861 const tools::Long nX = aCharRect.Left() - (rLR.GetLeft() + DOCUMENTBORDER);
862 aRet.X = convertTwipToMm100(nX);
864 return aRet;
867 void SwXTextViewCursor::collapseToStart()
869 SolarMutexGuard aGuard;
870 if(!m_pView)
871 throw uno::RuntimeException();
873 if (!IsTextSelection())
874 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
876 SwWrtShell& rSh = m_pView->GetWrtShell();
877 if(rSh.HasSelection())
879 SwPaM* pShellCursor = rSh.GetCursor();
880 if(*pShellCursor->GetPoint() > *pShellCursor->GetMark())
881 pShellCursor->Exchange();
882 pShellCursor->DeleteMark();
883 rSh.EnterStdMode();
884 rSh.SetSelection(*pShellCursor);
889 void SwXTextViewCursor::collapseToEnd()
891 SolarMutexGuard aGuard;
892 if(!m_pView)
893 throw uno::RuntimeException();
895 if (!IsTextSelection())
896 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
898 SwWrtShell& rSh = m_pView->GetWrtShell();
899 if(rSh.HasSelection())
901 SwPaM* pShellCursor = rSh.GetCursor();
902 if(*pShellCursor->GetPoint() < *pShellCursor->GetMark())
903 pShellCursor->Exchange();
904 pShellCursor->DeleteMark();
905 rSh.EnterStdMode();
906 rSh.SetSelection(*pShellCursor);
911 sal_Bool SwXTextViewCursor::isCollapsed()
913 SolarMutexGuard aGuard;
914 bool bRet = false;
915 if(!m_pView)
916 throw uno::RuntimeException();
918 if (!IsTextSelection())
919 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
921 const SwWrtShell& rSh = m_pView->GetWrtShell();
922 bRet = !rSh.HasSelection();
924 return bRet;
928 sal_Bool SwXTextViewCursor::goLeft(sal_Int16 nCount, sal_Bool bExpand)
930 SolarMutexGuard aGuard;
931 bool bRet = false;
932 if(!m_pView)
933 throw uno::RuntimeException();
935 if (!IsTextSelection())
936 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
938 bRet = m_pView->GetWrtShell().Left( SwCursorSkipMode::Chars, bExpand, nCount, true );
940 return bRet;
943 sal_Bool SwXTextViewCursor::goRight(sal_Int16 nCount, sal_Bool bExpand)
945 SolarMutexGuard aGuard;
946 bool bRet = false;
947 if(!m_pView)
948 throw uno::RuntimeException();
950 if (!IsTextSelection())
951 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
953 bRet = m_pView->GetWrtShell().Right( SwCursorSkipMode::Chars, bExpand, nCount, true );
955 return bRet;
959 void SwXTextViewCursor::gotoRange(
960 const uno::Reference< text::XTextRange > & xRange,
961 sal_Bool bExpand)
963 SolarMutexGuard aGuard;
964 if(!(m_pView && xRange.is()))
965 throw uno::RuntimeException();
967 if (!IsTextSelection())
968 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
970 SwUnoInternalPaM rDestPam(*m_pView->GetDocShell()->GetDoc());
971 if (!::sw::XTextRangeToSwPaM(rDestPam, xRange))
973 throw uno::RuntimeException();
976 ShellMode eSelMode = m_pView->GetShellMode();
977 SwWrtShell& rSh = m_pView->GetWrtShell();
978 // call EnterStdMode in non-text selections only
979 if(!bExpand ||
980 (eSelMode != ShellMode::TableText &&
981 eSelMode != ShellMode::ListText &&
982 eSelMode != ShellMode::TableListText &&
983 eSelMode != ShellMode::Text ))
984 rSh.EnterStdMode();
985 SwPaM* pShellCursor = rSh.GetCursor();
986 SwPaM aOwnPaM(*pShellCursor->GetPoint());
987 if(pShellCursor->HasMark())
989 aOwnPaM.SetMark();
990 *aOwnPaM.GetMark() = *pShellCursor->GetMark();
993 SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xRange.get());
994 SwXParagraph* pPara = dynamic_cast<SwXParagraph*>(xRange.get());
995 OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xRange.get());
997 const FrameTypeFlags nFrameType = rSh.GetFrameType(nullptr,true);
999 SwStartNodeType eSearchNodeType = SwNormalStartNode;
1000 if(nFrameType & FrameTypeFlags::FLY_ANY)
1001 eSearchNodeType = SwFlyStartNode;
1002 else if(nFrameType &FrameTypeFlags::HEADER)
1003 eSearchNodeType = SwHeaderStartNode;
1004 else if(nFrameType & FrameTypeFlags::FOOTER)
1005 eSearchNodeType = SwFooterStartNode;
1006 else if(nFrameType & FrameTypeFlags::TABLE)
1007 eSearchNodeType = SwTableBoxStartNode;
1008 else if(nFrameType & FrameTypeFlags::FOOTNOTE)
1009 eSearchNodeType = SwFootnoteStartNode;
1011 const SwStartNode* pOwnStartNode = aOwnPaM.GetPointNode().
1012 FindSttNodeByType(eSearchNodeType);
1014 const SwNode* pSrcNode = nullptr;
1015 if(pCursor && pCursor->GetPaM())
1017 pSrcNode = &pCursor->GetPaM()->GetPointNode();
1019 else if (pRange)
1021 SwPaM aPam(pRange->GetDoc().GetNodes());
1022 if (pRange->GetPositions(aPam))
1024 pSrcNode = &aPam.GetPointNode();
1027 else if (pPara && pPara->GetTextNode())
1029 pSrcNode = pPara->GetTextNode();
1031 const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindSttNodeByType(eSearchNodeType) : nullptr;
1033 //Skip SectionNodes
1034 while(pTmp && pTmp->IsSectionNode())
1036 pTmp = pTmp->StartOfSectionNode();
1038 while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1040 pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1042 //Without Expand it is allowed to jump out with the ViewCursor everywhere,
1043 //with Expand only in the same environment
1044 if(bExpand &&
1045 (pOwnStartNode != pTmp ||
1046 (eSelMode != ShellMode::TableText &&
1047 eSelMode != ShellMode::ListText &&
1048 eSelMode != ShellMode::TableListText &&
1049 eSelMode != ShellMode::Text)))
1050 throw uno::RuntimeException();
1052 //Now, the selection must be expanded.
1053 if(bExpand)
1055 // The cursor should include everything that has been included
1056 // by him and the transferred Range.
1057 SwPosition aOwnLeft(*aOwnPaM.Start());
1058 SwPosition aOwnRight(*aOwnPaM.End());
1059 auto [pParamLeft, pParamRight] = rDestPam.StartEnd(); // SwPosition*
1060 // Now four SwPositions are there, two of them are needed, but which?
1061 if(aOwnRight > *pParamRight)
1062 *aOwnPaM.GetPoint() = aOwnRight;
1063 else
1064 *aOwnPaM.GetPoint() = *pParamRight;
1065 aOwnPaM.SetMark();
1066 if(aOwnLeft < *pParamLeft)
1067 *aOwnPaM.GetMark() = aOwnLeft;
1068 else
1069 *aOwnPaM.GetMark() = *pParamLeft;
1071 else
1073 //The cursor shall match the passed range.
1074 *aOwnPaM.GetPoint() = *rDestPam.GetPoint();
1075 if(rDestPam.HasMark())
1077 aOwnPaM.SetMark();
1078 *aOwnPaM.GetMark() = *rDestPam.GetMark();
1080 else
1081 aOwnPaM.DeleteMark();
1083 rSh.SetSelection(aOwnPaM);
1088 void SwXTextViewCursor::gotoStart(sal_Bool bExpand)
1090 SolarMutexGuard aGuard;
1091 comphelper::ProfileZone aZone("SwXTextViewCursor::gotoStart");
1092 if(!m_pView)
1093 throw uno::RuntimeException();
1095 if (!IsTextSelection())
1096 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1098 m_pView->GetWrtShell().StartOfSection( bExpand );
1102 void SwXTextViewCursor::gotoEnd(sal_Bool bExpand)
1104 SolarMutexGuard aGuard;
1105 comphelper::ProfileZone aZone("SwXTextViewCursor::gotoEnd");
1106 if(!m_pView)
1107 throw uno::RuntimeException();
1109 if (!IsTextSelection())
1110 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1112 m_pView->GetWrtShell().EndOfSection( bExpand );
1116 sal_Bool SwXTextViewCursor::jumpToFirstPage()
1118 SolarMutexGuard aGuard;
1119 bool bRet = false;
1120 if(!m_pView)
1121 throw uno::RuntimeException();
1123 SwWrtShell& rSh = m_pView->GetWrtShell();
1124 if (rSh.IsSelFrameMode())
1126 rSh.UnSelectFrame();
1127 rSh.LeaveSelFrameMode();
1129 rSh.EnterStdMode();
1130 bRet = rSh.SttEndDoc(true);
1132 return bRet;
1135 sal_Bool SwXTextViewCursor::jumpToLastPage()
1137 SolarMutexGuard aGuard;
1138 bool bRet = false;
1139 if(!m_pView)
1140 throw uno::RuntimeException();
1142 SwWrtShell& rSh = m_pView->GetWrtShell();
1143 if (rSh.IsSelFrameMode())
1145 rSh.UnSelectFrame();
1146 rSh.LeaveSelFrameMode();
1148 rSh.EnterStdMode();
1149 bRet = rSh.SttEndDoc(false);
1150 rSh.SttPg();
1152 return bRet;
1155 sal_Bool SwXTextViewCursor::jumpToPage(sal_Int16 nPage)
1157 SolarMutexGuard aGuard;
1158 bool bRet = false;
1159 if(!m_pView)
1160 throw uno::RuntimeException();
1162 bRet = m_pView->GetWrtShell().GotoPage(nPage, true);
1164 return bRet;
1167 sal_Bool SwXTextViewCursor::jumpToNextPage()
1169 SolarMutexGuard aGuard;
1170 bool bRet = false;
1171 if(!m_pView)
1172 throw uno::RuntimeException();
1174 bRet = m_pView->GetWrtShell().SttNxtPg();
1176 return bRet;
1179 sal_Bool SwXTextViewCursor::jumpToPreviousPage()
1181 SolarMutexGuard aGuard;
1182 bool bRet = false;
1183 if(!m_pView)
1184 throw uno::RuntimeException();
1186 bRet = m_pView->GetWrtShell().EndPrvPg();
1188 return bRet;
1191 sal_Bool SwXTextViewCursor::jumpToEndOfPage()
1193 SolarMutexGuard aGuard;
1194 bool bRet = false;
1195 if(!m_pView)
1196 throw uno::RuntimeException();
1198 bRet = m_pView->GetWrtShell().EndPg();
1200 return bRet;
1203 sal_Bool SwXTextViewCursor::jumpToStartOfPage()
1205 SolarMutexGuard aGuard;
1206 bool bRet = false;
1207 if(!m_pView)
1208 throw uno::RuntimeException();
1210 bRet = m_pView->GetWrtShell().SttPg();
1212 return bRet;
1215 sal_Int16 SwXTextViewCursor::getPage()
1217 SolarMutexGuard aGuard;
1218 sal_Int16 nRet = 0;
1219 if(!m_pView)
1220 throw uno::RuntimeException();
1222 SwWrtShell& rSh = m_pView->GetWrtShell();
1223 SwPaM* pShellCursor = rSh.GetCursor();
1224 nRet = static_cast<sal_Int16>(pShellCursor->GetPageNum());
1226 return nRet;
1229 sal_Bool SwXTextViewCursor::screenDown()
1231 SolarMutexGuard aGuard;
1232 bool bRet = false;
1233 if(!m_pView)
1234 throw uno::RuntimeException();
1236 SfxRequest aReq(FN_PAGEDOWN, SfxCallMode::SLOT, m_pView->GetPool());
1237 m_pView->Execute(aReq);
1238 const SfxPoolItem* pRet = aReq.GetReturnValue();
1239 bRet = pRet && static_cast<const SfxBoolItem*>(pRet)->GetValue();
1241 return bRet;
1244 sal_Bool SwXTextViewCursor::screenUp()
1246 SolarMutexGuard aGuard;
1247 bool bRet = false;
1248 if(!m_pView)
1249 throw uno::RuntimeException();
1251 SfxRequest aReq(FN_PAGEUP, SfxCallMode::SLOT, m_pView->GetPool());
1252 m_pView->Execute(aReq);
1253 const SfxPoolItem* pRet = aReq.GetReturnValue();
1254 bRet = pRet && static_cast<const SfxBoolItem*>(pRet)->GetValue();
1256 return bRet;
1259 uno::Reference< text::XText > SwXTextViewCursor::getText()
1261 SolarMutexGuard aGuard;
1262 uno::Reference< text::XText > xRet;
1263 if(!m_pView)
1264 throw uno::RuntimeException();
1266 if (!IsTextSelection( false ))
1267 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1269 SwWrtShell& rSh = m_pView->GetWrtShell();
1270 SwPaM* pShellCursor = rSh.GetCursor();
1271 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1272 xRet = ::sw::CreateParentXText(*pDoc, *pShellCursor->Start());
1274 return xRet;
1277 uno::Reference< text::XTextRange > SwXTextViewCursor::getStart()
1279 SolarMutexGuard aGuard;
1280 uno::Reference< text::XTextRange > xRet;
1281 if(!m_pView)
1282 throw uno::RuntimeException();
1284 if (!IsTextSelection())
1285 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1287 SwWrtShell& rSh = m_pView->GetWrtShell();
1288 SwPaM* pShellCursor = rSh.GetCursor();
1289 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1290 xRet = SwXTextRange::CreateXTextRange(*pDoc, *pShellCursor->Start(), nullptr);
1292 return xRet;
1295 uno::Reference< text::XTextRange > SwXTextViewCursor::getEnd()
1297 SolarMutexGuard aGuard;
1298 rtl::Reference<SwXTextRange> xRet;
1299 if(!m_pView)
1300 throw uno::RuntimeException();
1302 if (!IsTextSelection())
1303 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1305 SwWrtShell& rSh = m_pView->GetWrtShell();
1306 SwPaM* pShellCursor = rSh.GetCursor();
1307 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1308 xRet = SwXTextRange::CreateXTextRange(*pDoc, *pShellCursor->End(), nullptr);
1310 return xRet;
1313 OUString SwXTextViewCursor::getString()
1315 SolarMutexGuard aGuard;
1316 OUString uRet;
1317 if(m_pView)
1319 if (!IsTextSelection( false ))
1321 SAL_WARN("sw.uno", "no text selection in getString() " << static_cast<cppu::OWeakObject*>(this));
1322 return uRet;
1325 ShellMode eSelMode = m_pView->GetShellMode();
1326 switch(eSelMode)
1328 //! since setString for SEL_TABLE_TEXT (with possible
1329 //! multi selection of cells) would not work properly we
1330 //! will ignore this case for both
1331 //! functions (setString AND getString) because of symmetrie.
1333 case ShellMode::ListText :
1334 case ShellMode::TableListText:
1335 case ShellMode::Text :
1337 SwWrtShell& rSh = m_pView->GetWrtShell();
1338 SwPaM* pShellCursor = rSh.GetCursor();
1339 SwUnoCursorHelper::GetTextFromPam(*pShellCursor, uRet,
1340 rSh.GetLayout());
1341 break;
1343 default:;//prevent warning
1346 return uRet;
1349 void SwXTextViewCursor::setString(const OUString& aString)
1351 SolarMutexGuard aGuard;
1352 if(!m_pView)
1353 return;
1355 if (!IsTextSelection( false ))
1356 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1358 ShellMode eSelMode = m_pView->GetShellMode();
1359 switch(eSelMode)
1361 //! since setString for SEL_TABLE_TEXT (with possible
1362 //! multi selection of cells) would not work properly we
1363 //! will ignore this case for both
1364 //! functions (setString AND getString) because of symmetrie.
1366 case ShellMode::ListText :
1367 case ShellMode::TableListText :
1368 case ShellMode::Text :
1370 SwWrtShell& rSh = m_pView->GetWrtShell();
1371 SwCursor* pShellCursor = rSh.GetCursor();
1372 SwUnoCursorHelper::SetString(*pShellCursor, aString);
1373 break;
1375 default:;//prevent warning
1379 uno::Reference< XPropertySetInfo > SwXTextViewCursor::getPropertySetInfo( )
1381 static uno::Reference< XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
1382 return xRef;
1385 void SwXTextViewCursor::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
1387 SolarMutexGuard aGuard;
1388 if(!m_pView)
1389 throw RuntimeException();
1391 SwWrtShell& rSh = m_pView->GetWrtShell();
1392 SwPaM* pShellCursor = rSh.GetCursor();
1393 SwNode& rNode = pShellCursor->GetPointNode();
1394 if (!rNode.IsTextNode())
1395 throw RuntimeException();
1397 SwUnoCursorHelper::SetPropertyValue(
1398 *pShellCursor, *m_pPropSet, rPropertyName, aValue );
1403 Any SwXTextViewCursor::getPropertyValue( const OUString& rPropertyName )
1405 SolarMutexGuard aGuard;
1406 Any aRet;
1407 if(!m_pView)
1408 throw RuntimeException();
1410 SwWrtShell& rSh = m_pView->GetWrtShell();
1411 SwPaM* pShellCursor = rSh.GetCursor();
1412 aRet = SwUnoCursorHelper::GetPropertyValue(
1413 *pShellCursor, *m_pPropSet, rPropertyName);
1415 return aRet;
1418 void SwXTextViewCursor::addPropertyChangeListener(
1419 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
1423 void SwXTextViewCursor::removePropertyChangeListener(
1424 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ )
1428 void SwXTextViewCursor::addVetoableChangeListener(
1429 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1433 void SwXTextViewCursor::removeVetoableChangeListener(
1434 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1438 PropertyState SwXTextViewCursor::getPropertyState( const OUString& rPropertyName )
1440 SolarMutexGuard aGuard;
1441 PropertyState eState;
1442 if(!m_pView)
1443 throw RuntimeException();
1445 SwWrtShell& rSh = m_pView->GetWrtShell();
1446 SwPaM* pShellCursor = rSh.GetCursor();
1447 eState = SwUnoCursorHelper::GetPropertyState(
1448 *pShellCursor, *m_pPropSet, rPropertyName);
1450 return eState;
1453 Sequence< PropertyState > SwXTextViewCursor::getPropertyStates(
1454 const Sequence< OUString >& rPropertyNames )
1456 SolarMutexGuard aGuard;
1457 Sequence< PropertyState > aRet;
1458 if(m_pView)
1460 SwWrtShell& rSh = m_pView->GetWrtShell();
1461 SwPaM* pShellCursor = rSh.GetCursor();
1462 aRet = SwUnoCursorHelper::GetPropertyStates(
1463 *pShellCursor, *m_pPropSet, rPropertyNames);
1465 return aRet;
1468 void SwXTextViewCursor::setPropertyToDefault( const OUString& rPropertyName )
1470 SolarMutexGuard aGuard;
1471 if(m_pView)
1473 SwWrtShell& rSh = m_pView->GetWrtShell();
1474 SwPaM* pShellCursor = rSh.GetCursor();
1475 SwUnoCursorHelper::SetPropertyToDefault(
1476 *pShellCursor, *m_pPropSet, rPropertyName);
1480 Any SwXTextViewCursor::getPropertyDefault( const OUString& rPropertyName )
1482 Any aRet;
1483 SolarMutexGuard aGuard;
1484 if(m_pView)
1486 SwWrtShell& rSh = m_pView->GetWrtShell();
1487 SwPaM* pShellCursor = rSh.GetCursor();
1488 aRet = SwUnoCursorHelper::GetPropertyDefault(
1489 *pShellCursor, *m_pPropSet, rPropertyName);
1491 return aRet;
1494 sal_Bool SwXTextViewCursor::goDown(sal_Int16 nCount, sal_Bool bExpand)
1496 SolarMutexGuard aGuard;
1497 comphelper::ProfileZone aZone("SwXTextViewCursor::goDown");
1498 bool bRet = false;
1499 if(!m_pView)
1500 throw uno::RuntimeException();
1502 if (!IsTextSelection())
1503 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1505 bRet = m_pView->GetWrtShell().Down( bExpand, nCount, true );
1507 return bRet;
1510 sal_Bool SwXTextViewCursor::goUp(sal_Int16 nCount, sal_Bool bExpand)
1512 SolarMutexGuard aGuard;
1513 comphelper::ProfileZone aZone("SwXTextViewCursor::goUp");
1514 bool bRet = false;
1515 if(!m_pView)
1516 throw uno::RuntimeException();
1518 if (!IsTextSelection())
1519 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1521 bRet = m_pView->GetWrtShell().Up( bExpand, nCount, true );
1523 return bRet;
1526 sal_Bool SwXTextViewCursor::isAtStartOfLine()
1528 SolarMutexGuard aGuard;
1529 bool bRet = false;
1530 if(!m_pView)
1531 throw uno::RuntimeException();
1533 if (!IsTextSelection( false ))
1534 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1536 bRet = m_pView->GetWrtShell().IsAtLeftMargin();
1538 return bRet;
1541 sal_Bool SwXTextViewCursor::isAtEndOfLine()
1543 SolarMutexGuard aGuard;
1544 bool bRet = false;
1545 if(!m_pView)
1546 throw uno::RuntimeException();
1548 if (!IsTextSelection( false ))
1549 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1551 bRet = m_pView->GetWrtShell().IsAtRightMargin();
1553 return bRet;
1556 void SwXTextViewCursor::gotoEndOfLine(sal_Bool bExpand)
1558 SolarMutexGuard aGuard;
1559 if(!m_pView)
1560 throw uno::RuntimeException();
1562 if (!IsTextSelection( false ))
1563 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1565 m_pView->GetWrtShell().RightMargin(bExpand, true);
1569 void SwXTextViewCursor::gotoStartOfLine(sal_Bool bExpand)
1571 SolarMutexGuard aGuard;
1572 if(!m_pView)
1573 throw uno::RuntimeException();
1575 if (!IsTextSelection( false ))
1576 throw uno::RuntimeException("no text selection", static_cast < cppu::OWeakObject * > ( this ) );
1578 m_pView->GetWrtShell().LeftMargin(bExpand, true);
1582 OUString SwXTextViewCursor::getImplementationName()
1584 return "SwXTextViewCursor";
1587 sal_Bool SwXTextViewCursor::supportsService(const OUString& rServiceName)
1589 return cppu::supportsService(this, rServiceName);
1592 Sequence< OUString > SwXTextViewCursor::getSupportedServiceNames()
1594 return { "com.sun.star.text.TextViewCursor",
1595 "com.sun.star.style.CharacterProperties",
1596 "com.sun.star.style.CharacterPropertiesAsian",
1597 "com.sun.star.style.CharacterPropertiesComplex",
1598 "com.sun.star.style.ParagraphProperties",
1599 "com.sun.star.style.ParagraphPropertiesAsian",
1600 "com.sun.star.style.ParagraphPropertiesComplex" };
1603 const SwDoc* SwXTextViewCursor::GetDoc() const
1605 SwWrtShell& rSh = m_pView->GetWrtShell();
1606 return rSh.GetCursor() ? &rSh.GetCursor()->GetDoc() : nullptr;
1609 SwDoc* SwXTextViewCursor::GetDoc()
1611 SwWrtShell& rSh = m_pView->GetWrtShell();
1612 return rSh.GetCursor() ? &rSh.GetCursor()->GetDoc() : nullptr;
1615 const SwPaM* SwXTextViewCursor::GetPaM() const
1617 SwWrtShell& rSh = m_pView->GetWrtShell();
1618 return rSh.GetCursor();
1621 SwPaM* SwXTextViewCursor::GetPaM()
1623 SwWrtShell& rSh = m_pView->GetWrtShell();
1624 return rSh.GetCursor();
1627 uno::Reference<datatransfer::XTransferable> SAL_CALL
1628 SwXTextView::getTransferableForTextRange(uno::Reference<text::XTextRange> const& xTextRange)
1630 SolarMutexGuard aGuard;
1632 // the point is we can copy PaM that wouldn't be legal as shell cursor
1633 SwUnoInternalPaM aPam(*m_pView->GetDocShell()->GetDoc());
1634 if (!::sw::XTextRangeToSwPaM(aPam, xTextRange, ::sw::TextRangeMode::AllowNonTextNode))
1636 throw uno::RuntimeException("invalid text range");
1639 //force immediate shell update
1640 GetView()->StopShellTimer();
1641 SwWrtShell& rSh = GetView()->GetWrtShell();
1642 rtl::Reference<SwTransferable> pTransfer = new SwTransferable(rSh);
1643 const bool bLockedView = rSh.IsViewLocked();
1644 rSh.LockView( true );
1645 pTransfer->PrepareForCopyTextRange(aPam);
1646 rSh.LockView( bLockedView );
1647 return pTransfer;
1650 OUString SAL_CALL SwXTextView::dump(const OUString& rKind)
1652 if (rKind == "layout")
1654 SwRootFrame* pLayout = GetView()->GetWrtShell().GetLayout();
1655 return comphelper::dumpXmlToString([pLayout](xmlTextWriterPtr pWriter)
1656 { pLayout->dumpAsXml(pWriter); });
1659 return OUString();
1662 uno::Reference< datatransfer::XTransferable > SAL_CALL SwXTextView::getTransferable()
1664 SolarMutexGuard aGuard;
1666 //force immediat shell update
1667 GetView()->StopShellTimer();
1668 SwWrtShell& rSh = GetView()->GetWrtShell();
1669 if ( GetView()->GetShellMode() == ShellMode::DrawText )
1671 SdrView *pSdrView = rSh.GetDrawView();
1672 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
1673 return pOLV->GetEditView().GetTransferable();
1675 else
1677 rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
1678 const bool bLockedView = rSh.IsViewLocked();
1679 rSh.LockView( true ); //lock visible section
1680 pTransfer->PrepareForCopy();
1681 rSh.LockView( bLockedView );
1682 return pTransfer;
1686 void SAL_CALL SwXTextView::insertTransferable( const uno::Reference< datatransfer::XTransferable >& xTrans )
1688 SolarMutexGuard aGuard;
1690 //force immediat shell update
1691 GetView()->StopShellTimer();
1692 SwWrtShell& rSh = GetView()->GetWrtShell();
1693 if ( GetView()->GetShellMode() == ShellMode::DrawText )
1695 SdrView *pSdrView = rSh.GetDrawView();
1696 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
1697 pOLV->GetEditView().InsertText( xTrans, GetView()->GetDocShell()->GetMedium()->GetBaseURL(), false );
1699 else
1701 TransferableDataHelper aDataHelper( xTrans );
1702 if ( SwTransferable::IsPaste( rSh, aDataHelper ) )
1704 SwTransferable::Paste( rSh, aDataHelper );
1705 if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
1706 rSh.EnterSelFrameMode();
1707 GetView()->AttrChangedNotify(nullptr);
1712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */