/src/libreoffice/sw/source/uibase/uno/unotxvw.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
77 | | #include <names.hxx> |
78 | | |
79 | | using namespace ::com::sun::star; |
80 | | using namespace ::com::sun::star::uno; |
81 | | using namespace ::com::sun::star::lang; |
82 | | using namespace ::com::sun::star::beans; |
83 | | using namespace ::com::sun::star::text; |
84 | | using namespace ::com::sun::star::view; |
85 | | using namespace ::com::sun::star::frame; |
86 | | |
87 | | using ::com::sun::star::util::URL; |
88 | | |
89 | | SwXTextView::SwXTextView(SwView* pSwView) : |
90 | 4.01k | SwXTextView_Base(pSwView), |
91 | 4.01k | m_SelChangedListeners(m_aMutex), |
92 | 4.01k | m_pView(pSwView), |
93 | 4.01k | m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_VIEW ) ) |
94 | 4.01k | { |
95 | | |
96 | 4.01k | } |
97 | | |
98 | | SwXTextView::~SwXTextView() |
99 | 0 | { |
100 | 0 | Invalidate(); |
101 | 0 | } |
102 | | |
103 | | void SwXTextView::Invalidate() |
104 | 8.02k | { |
105 | 8.02k | if(mxViewSettings.is()) |
106 | 4.01k | { |
107 | 4.01k | mxViewSettings->Invalidate(); |
108 | 4.01k | mxViewSettings.clear(); |
109 | 4.01k | } |
110 | 8.02k | if(mxTextViewCursor.is()) |
111 | 0 | { |
112 | 0 | mxTextViewCursor->Invalidate(); |
113 | 0 | mxTextViewCursor.clear(); |
114 | 0 | } |
115 | | |
116 | 8.02k | osl_atomic_increment(&m_refCount); //prevent second d'tor call |
117 | | |
118 | 8.02k | { |
119 | 8.02k | uno::Reference<uno::XInterface> const xInt(static_cast< |
120 | 8.02k | cppu::OWeakObject*>(static_cast<SfxBaseController*>(this))); |
121 | 8.02k | lang::EventObject aEvent(xInt); |
122 | 8.02k | m_SelChangedListeners.disposeAndClear(aEvent); |
123 | 8.02k | } |
124 | | |
125 | 8.02k | osl_atomic_decrement(&m_refCount); |
126 | 8.02k | m_pView = nullptr; |
127 | 8.02k | } |
128 | | |
129 | | sal_Bool SwXTextView::select(const uno::Any& aInterface) |
130 | 0 | { |
131 | 0 | SolarMutexGuard aGuard; |
132 | |
|
133 | 0 | uno::Reference< uno::XInterface > xInterface; |
134 | 0 | if (!GetView() || !(aInterface >>= xInterface)) |
135 | 0 | { |
136 | 0 | return false; |
137 | 0 | } |
138 | | |
139 | 0 | SwWrtShell& rSh = GetView()->GetWrtShell(); |
140 | 0 | SwDoc* pDoc = GetView()->GetDocShell()->GetDoc(); |
141 | 0 | std::vector<SdrObject *> sdrObjects; |
142 | 0 | uno::Reference<awt::XControlModel> const xCtrlModel(xInterface, |
143 | 0 | UNO_QUERY); |
144 | 0 | if (xCtrlModel.is()) |
145 | 0 | { |
146 | 0 | uno::Reference<awt::XControl> xControl; |
147 | 0 | SdrObject *const pSdrObject = GetControl(xCtrlModel, xControl); |
148 | 0 | if (pSdrObject) // hmm... needs view to verify it's in right doc... |
149 | 0 | { |
150 | 0 | sdrObjects.push_back(pSdrObject); |
151 | 0 | } |
152 | 0 | } |
153 | 0 | else |
154 | 0 | { |
155 | 0 | std::optional<SwPaM> pPaM; |
156 | 0 | std::pair<UIName, FlyCntType> frame; |
157 | 0 | UIName tableName; |
158 | 0 | SwUnoTableCursor const* pTableCursor(nullptr); |
159 | 0 | ::sw::mark::MarkBase const* pMark(nullptr); |
160 | 0 | SwUnoCursorHelper::GetSelectableFromAny(xInterface, *pDoc, |
161 | 0 | pPaM, frame, tableName, pTableCursor, pMark, sdrObjects); |
162 | 0 | if (pPaM) |
163 | 0 | { |
164 | 0 | rSh.EnterStdMode(); |
165 | 0 | rSh.SetSelection(*pPaM); |
166 | | // the pPaM has been copied - delete it |
167 | 0 | while (pPaM->GetNext() != &*pPaM) |
168 | 0 | { |
169 | | // coverity[deref_arg] - the SwPaM delete moves a new entry into GetNext() |
170 | 0 | delete pPaM->GetNext(); |
171 | 0 | } |
172 | 0 | pPaM.reset(); |
173 | 0 | return true; |
174 | 0 | } |
175 | 0 | else if (!frame.first.isEmpty()) |
176 | 0 | { |
177 | 0 | bool const bSuccess(rSh.GotoFly(frame.first, frame.second)); |
178 | 0 | if (bSuccess) |
179 | 0 | { |
180 | 0 | rSh.HideCursor(); |
181 | 0 | rSh.EnterSelFrameMode(); |
182 | 0 | } |
183 | 0 | return true; |
184 | 0 | } |
185 | 0 | else if (!tableName.isEmpty()) |
186 | 0 | { |
187 | 0 | rSh.EnterStdMode(); |
188 | 0 | rSh.GotoTable(tableName); |
189 | 0 | return true; |
190 | 0 | } |
191 | 0 | else if (pTableCursor) |
192 | 0 | { |
193 | 0 | UnoActionRemoveContext const aContext(*pTableCursor); |
194 | 0 | rSh.EnterStdMode(); |
195 | 0 | rSh.SetSelection(*pTableCursor); |
196 | 0 | return true; |
197 | 0 | } |
198 | 0 | else if (pMark) |
199 | 0 | { |
200 | 0 | rSh.EnterStdMode(); |
201 | 0 | rSh.GotoMark(pMark); |
202 | 0 | return true; |
203 | 0 | } |
204 | | // sdrObjects handled below |
205 | 0 | } |
206 | 0 | bool bRet(false); |
207 | 0 | if (!sdrObjects.empty()) |
208 | 0 | { |
209 | |
|
210 | 0 | SdrView *const pDrawView = rSh.GetDrawView(); |
211 | 0 | SdrPageView *const pPV = pDrawView->GetSdrPageView(); |
212 | |
|
213 | 0 | pDrawView->SdrEndTextEdit(); |
214 | 0 | pDrawView->UnmarkAll(); |
215 | |
|
216 | 0 | for (SdrObject* pSdrObject : sdrObjects) |
217 | 0 | { |
218 | | // GetSelectableFromAny did not check pSdrObject is in right doc! |
219 | 0 | if (pPV && pSdrObject->getSdrPageFromSdrObject() == pPV->GetPage()) |
220 | 0 | { |
221 | 0 | pDrawView->MarkObj(pSdrObject, pPV); |
222 | 0 | bRet = true; |
223 | 0 | } |
224 | 0 | } |
225 | | |
226 | | // tdf#112696 if we selected every individual element of a group, then |
227 | | // select that group instead |
228 | 0 | const SdrMarkList &rMrkList = pDrawView->GetMarkedObjectList(); |
229 | 0 | size_t nMarkCount = rMrkList.GetMarkCount(); |
230 | 0 | if (nMarkCount > 1) |
231 | 0 | { |
232 | 0 | SdrObject* pObject = rMrkList.GetMark(0)->GetMarkedSdrObj(); |
233 | 0 | SdrObject* pGroupParent = pObject->getParentSdrObjectFromSdrObject(); |
234 | 0 | for (size_t i = 1; i < nMarkCount; ++i) |
235 | 0 | { |
236 | 0 | pObject = rMrkList.GetMark(i)->GetMarkedSdrObj(); |
237 | 0 | SdrObject* pParent = pObject->getParentSdrObjectFromSdrObject(); |
238 | 0 | if (pParent != pGroupParent) |
239 | 0 | { |
240 | 0 | pGroupParent = nullptr; |
241 | 0 | break; |
242 | 0 | } |
243 | 0 | } |
244 | |
|
245 | 0 | if (pGroupParent && pGroupParent->IsGroupObject() && |
246 | 0 | pGroupParent->getChildrenOfSdrObject()->GetObjCount() == nMarkCount) |
247 | 0 | { |
248 | 0 | pDrawView->UnmarkAll(); |
249 | 0 | pDrawView->MarkObj(pGroupParent, pPV); |
250 | 0 | } |
251 | 0 | } |
252 | 0 | } |
253 | 0 | return bRet; |
254 | 0 | } |
255 | | |
256 | | uno::Any SwXTextView::getSelection() |
257 | 0 | { |
258 | 0 | SolarMutexGuard aGuard; |
259 | 0 | uno::Reference< uno::XInterface > aRef; |
260 | 0 | if(GetView()) |
261 | 0 | { |
262 | | //force immediate shell update |
263 | 0 | m_pView->StopShellTimer(); |
264 | | //Generating an interface from the current selection. |
265 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
266 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
267 | 0 | switch(eSelMode) |
268 | 0 | { |
269 | 0 | case ShellMode::TableText : |
270 | 0 | { |
271 | 0 | if(rSh.GetTableCursor()) |
272 | 0 | { |
273 | 0 | OSL_ENSURE(rSh.GetTableFormat(), "not a table format?"); |
274 | 0 | uno::Reference< text::XTextTableCursor > xCursor = new SwXTextTableCursor(*rSh.GetTableFormat(), |
275 | 0 | rSh.GetTableCursor()); |
276 | 0 | aRef.set(xCursor, uno::UNO_QUERY); |
277 | 0 | break; |
278 | 0 | } |
279 | 0 | [[fallthrough]]; |
280 | | // without a table selection the text will be delivered |
281 | 0 | } |
282 | 0 | case ShellMode::ListText : |
283 | 0 | case ShellMode::TableListText: |
284 | 0 | case ShellMode::Text : |
285 | 0 | { |
286 | 0 | rtl::Reference< SwXTextRanges > xPos = SwXTextRanges::Create(rSh.GetCursor()); |
287 | 0 | aRef.set(uno::Reference< container::XIndexAccess >(xPos), uno::UNO_QUERY); |
288 | 0 | } |
289 | 0 | break; |
290 | 0 | case ShellMode::Frame : |
291 | 0 | { |
292 | 0 | SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat(); |
293 | 0 | if (pFormat) |
294 | 0 | { |
295 | 0 | aRef = cppu::getXWeak(SwXTextFrame::CreateXTextFrame( |
296 | 0 | pFormat->GetDoc(), pFormat).get()); |
297 | 0 | } |
298 | 0 | } |
299 | 0 | break; |
300 | 0 | case ShellMode::Graphic : |
301 | 0 | { |
302 | 0 | SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat(); |
303 | 0 | if (pFormat) |
304 | 0 | { |
305 | 0 | aRef = cppu::getXWeak(SwXTextGraphicObject::CreateXTextGraphicObject( |
306 | 0 | pFormat->GetDoc(), pFormat).get()); |
307 | 0 | } |
308 | 0 | } |
309 | 0 | break; |
310 | 0 | case ShellMode::Object : |
311 | 0 | { |
312 | 0 | SwFrameFormat *const pFormat = rSh.GetFlyFrameFormat(); |
313 | 0 | if (pFormat) |
314 | 0 | { |
315 | 0 | aRef = cppu::getXWeak(SwXTextEmbeddedObject::CreateXTextEmbeddedObject( |
316 | 0 | pFormat->GetDoc(), pFormat).get()); |
317 | 0 | } |
318 | 0 | } |
319 | 0 | break; |
320 | 0 | case ShellMode::Draw : |
321 | 0 | case ShellMode::DrawForm : |
322 | 0 | case ShellMode::DrawText : |
323 | 0 | case ShellMode::Bezier : |
324 | 0 | case ShellMode::ExtrudedCustomShape: |
325 | 0 | case ShellMode::FontWork: |
326 | 0 | { |
327 | 0 | uno::Reference< drawing::XShapes > xShCol = drawing::ShapeCollection::create( |
328 | 0 | comphelper::getProcessComponentContext()); |
329 | |
|
330 | 0 | const SdrMarkList& rMarkList = rSh.GetDrawView()->GetMarkedObjectList(); |
331 | 0 | for(size_t i = 0; i < rMarkList.GetMarkCount(); ++i) |
332 | 0 | { |
333 | 0 | SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj(); |
334 | 0 | uno::Reference<drawing::XShape> xShape = SwFmDrawPage::GetShape( pObj ); |
335 | 0 | xShCol->add(xShape); |
336 | 0 | } |
337 | 0 | aRef.set(xShCol, uno::UNO_QUERY); |
338 | 0 | } |
339 | 0 | break; |
340 | 0 | default:;//prevent warning |
341 | 0 | } |
342 | 0 | } |
343 | 0 | uno::Any aRet(&aRef, cppu::UnoType<uno::XInterface>::get()); |
344 | 0 | return aRet; |
345 | 0 | } |
346 | | |
347 | | void SwXTextView::addSelectionChangeListener( |
348 | | const uno::Reference< view::XSelectionChangeListener > & rxListener) |
349 | 0 | { |
350 | 0 | SolarMutexGuard aGuard; |
351 | 0 | m_SelChangedListeners.addInterface(rxListener); |
352 | 0 | } |
353 | | |
354 | | void SwXTextView::removeSelectionChangeListener( |
355 | | const uno::Reference< view::XSelectionChangeListener > & rxListener) |
356 | 0 | { |
357 | 0 | SolarMutexGuard aGuard; |
358 | 0 | m_SelChangedListeners.removeInterface(rxListener); |
359 | 0 | } |
360 | | |
361 | | SdrObject* SwXTextView::GetControl( |
362 | | const uno::Reference< awt::XControlModel > & xModel, |
363 | | uno::Reference< awt::XControl >& xToFill ) |
364 | 0 | { |
365 | 0 | SwView* pView2 = GetView(); |
366 | 0 | FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr; |
367 | 0 | SdrView* pDrawView = pView2 ? pView2->GetDrawView() : nullptr; |
368 | 0 | vcl::Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : nullptr; |
369 | |
|
370 | 0 | OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::GetControl: how could I?" ); |
371 | |
|
372 | 0 | SdrObject* pControl = nullptr; |
373 | 0 | if ( pFormShell && pDrawView && pWindow ) |
374 | 0 | pControl = pFormShell->GetFormControl( xModel, *pDrawView, *pWindow->GetOutDev(), xToFill ); |
375 | 0 | return pControl; |
376 | 0 | } |
377 | | |
378 | | uno::Reference< awt::XControl > SwXTextView::getControl(const uno::Reference< awt::XControlModel > & xModel) |
379 | 0 | { |
380 | 0 | SolarMutexGuard aGuard; |
381 | 0 | uno::Reference< awt::XControl > xRet; |
382 | 0 | GetControl(xModel, xRet); |
383 | 0 | return xRet; |
384 | 0 | } |
385 | | |
386 | | uno::Reference< form::runtime::XFormController > SAL_CALL SwXTextView::getFormController( const uno::Reference< form::XForm >& Form ) |
387 | 0 | { |
388 | 0 | SolarMutexGuard aGuard; |
389 | |
|
390 | 0 | SwView* pView2 = GetView(); |
391 | 0 | FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr; |
392 | 0 | SdrView* pDrawView = pView2 ? pView2->GetDrawView() : nullptr; |
393 | 0 | vcl::Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : nullptr; |
394 | 0 | OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::getFormController: how could I?" ); |
395 | |
|
396 | 0 | uno::Reference< form::runtime::XFormController > xController; |
397 | 0 | if ( pFormShell && pDrawView && pWindow ) |
398 | 0 | xController = FmFormShell::GetFormController( Form, *pDrawView, *pWindow->GetOutDev() ); |
399 | 0 | return xController; |
400 | 0 | } |
401 | | |
402 | | sal_Bool SAL_CALL SwXTextView::isFormDesignMode( ) |
403 | 0 | { |
404 | 0 | SolarMutexGuard aGuard; |
405 | 0 | SwView* pView2 = GetView(); |
406 | 0 | FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr; |
407 | 0 | return !pFormShell || pFormShell->IsDesignMode(); |
408 | 0 | } |
409 | | |
410 | | void SAL_CALL SwXTextView::setFormDesignMode( sal_Bool DesignMode ) |
411 | 0 | { |
412 | 0 | SolarMutexGuard aGuard; |
413 | 0 | SwView* pView2 = GetView(); |
414 | 0 | FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : nullptr; |
415 | 0 | if ( pFormShell ) |
416 | 0 | pFormShell->SetDesignMode( DesignMode ); |
417 | 0 | } |
418 | | |
419 | | uno::Reference< text::XTextViewCursor > SwXTextView::getViewCursor() |
420 | 0 | { |
421 | 0 | SolarMutexGuard aGuard; |
422 | 0 | comphelper::ProfileZone aZone("getViewCursor"); |
423 | 0 | if(!GetView()) |
424 | 0 | throw uno::RuntimeException(); |
425 | | |
426 | 0 | if(!mxTextViewCursor.is()) |
427 | 0 | { |
428 | 0 | mxTextViewCursor = new SwXTextViewCursor(GetView()); |
429 | 0 | } |
430 | 0 | return mxTextViewCursor; |
431 | 0 | } |
432 | | |
433 | | uno::Reference<text::XTextRange> |
434 | | SwXTextView::createTextRangeByPixelPosition(const awt::Point& rPixelPosition) |
435 | 0 | { |
436 | 0 | SolarMutexGuard aGuard; |
437 | |
|
438 | 0 | Point aPixelPoint(rPixelPosition.X, rPixelPosition.Y); |
439 | 0 | if (!m_pView) |
440 | 0 | throw RuntimeException(); |
441 | | |
442 | 0 | Point aLogicPoint = m_pView->GetEditWin().PixelToLogic(aPixelPoint); |
443 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
444 | 0 | SwPosition aPosition(*rSh.GetCurrentShellCursor().GetPoint()); |
445 | 0 | rSh.GetLayout()->GetModelPositionForViewPoint(&aPosition, aLogicPoint); |
446 | |
|
447 | 0 | if (aPosition.GetNode().IsGrfNode()) |
448 | 0 | { |
449 | | // The point is closest to a graphic node, look up its format. |
450 | 0 | const SwFrameFormat* pGraphicFormat = aPosition.GetNode().GetFlyFormat(); |
451 | 0 | if (pGraphicFormat) |
452 | 0 | { |
453 | | // Get the anchor of this format. |
454 | 0 | const SwFormatAnchor& rAnchor = pGraphicFormat->GetAnchor(); |
455 | 0 | const SwPosition* pAnchor = rAnchor.GetContentAnchor(); |
456 | 0 | if (pAnchor) |
457 | 0 | { |
458 | 0 | aPosition = *pAnchor; |
459 | 0 | } |
460 | 0 | else |
461 | 0 | { |
462 | | // Page-anchored graphics have no anchor. |
463 | 0 | return {}; |
464 | 0 | } |
465 | 0 | } |
466 | 0 | } |
467 | | |
468 | 0 | rtl::Reference<SwXTextRange> xRet |
469 | 0 | = SwXTextRange::CreateXTextRange(*rSh.GetDoc(), aPosition, /*pMark=*/nullptr); |
470 | |
|
471 | 0 | return xRet; |
472 | 0 | } |
473 | | |
474 | | uno::Reference< beans::XPropertySet > SwXTextView::getViewSettings() |
475 | 4.01k | { |
476 | 4.01k | SolarMutexGuard aGuard; |
477 | 4.01k | if(!m_pView) |
478 | 0 | throw uno::RuntimeException(); |
479 | | |
480 | 4.01k | if(!mxViewSettings.is()) |
481 | 4.01k | { |
482 | 4.01k | mxViewSettings = new SwXViewSettings( m_pView ); |
483 | 4.01k | } |
484 | | |
485 | 4.01k | return mxViewSettings; |
486 | 4.01k | } |
487 | | |
488 | | Sequence< Sequence< PropertyValue > > SwXTextView::getRubyList( sal_Bool /*bAutomatic*/ ) |
489 | 0 | { |
490 | 0 | SolarMutexGuard aGuard; |
491 | |
|
492 | 0 | if(!GetView()) |
493 | 0 | throw RuntimeException(); |
494 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
495 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
496 | 0 | if (eSelMode != ShellMode::ListText && |
497 | 0 | eSelMode != ShellMode::TableListText && |
498 | 0 | eSelMode != ShellMode::TableText && |
499 | 0 | eSelMode != ShellMode::Text ) |
500 | 0 | return Sequence< Sequence< PropertyValue > > (); |
501 | | |
502 | 0 | SwRubyList aList; |
503 | |
|
504 | 0 | const sal_uInt16 nCount = SwDoc::FillRubyList( *rSh.GetCursor(), aList ); |
505 | 0 | Sequence< Sequence< PropertyValue > > aRet(nCount); |
506 | 0 | Sequence< PropertyValue >* pRet = aRet.getArray(); |
507 | 0 | ProgName aString; |
508 | 0 | for(sal_uInt16 n = 0; n < nCount; n++) |
509 | 0 | { |
510 | 0 | const SwRubyListEntry* pEntry = aList[n].get(); |
511 | |
|
512 | 0 | const OUString& rEntryText = pEntry->GetText(); |
513 | 0 | const SwFormatRuby& rAttr = pEntry->GetRubyAttr(); |
514 | 0 | sal_Int32 nSequence = pEntry->GetSequence(); |
515 | |
|
516 | 0 | pRet[n].realloc(7); |
517 | 0 | PropertyValue* pValues = pRet[n].getArray(); |
518 | 0 | pValues[0].Name = UNO_NAME_RUBY_BASE_TEXT; |
519 | 0 | pValues[0].Value <<= rEntryText; |
520 | 0 | pValues[1].Name = UNO_NAME_RUBY_TEXT; |
521 | 0 | pValues[1].Value <<= rAttr.GetText(); |
522 | 0 | pValues[2].Name = UNO_NAME_RUBY_CHAR_STYLE_NAME; |
523 | 0 | SwStyleNameMapper::FillProgName(rAttr.GetCharFormatName(), aString, SwGetPoolIdFromName::ChrFmt ); |
524 | 0 | pValues[2].Value <<= aString.toString(); |
525 | 0 | pValues[3].Name = UNO_NAME_RUBY_ADJUST; |
526 | 0 | pValues[3].Value <<= static_cast<sal_Int16>(rAttr.GetAdjustment()); |
527 | 0 | pValues[4].Name = UNO_NAME_RUBY_IS_ABOVE; |
528 | 0 | pValues[4].Value <<= !rAttr.GetPosition(); |
529 | 0 | pValues[5].Name = UNO_NAME_RUBY_POSITION; |
530 | 0 | pValues[5].Value <<= rAttr.GetPosition(); |
531 | 0 | pValues[6].Name = UNO_NAME_RUBY_SEQUENCE_NUMBER; |
532 | 0 | pValues[6].Value <<= nSequence; |
533 | 0 | } |
534 | 0 | return aRet; |
535 | 0 | } |
536 | | |
537 | | void SAL_CALL SwXTextView::setRubyList( |
538 | | const Sequence< Sequence< PropertyValue > >& rRubyList, sal_Bool /*bAutomatic*/ ) |
539 | 0 | { |
540 | 0 | SolarMutexGuard aGuard; |
541 | |
|
542 | 0 | if(!GetView() || !rRubyList.hasElements()) |
543 | 0 | throw RuntimeException(); |
544 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
545 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
546 | 0 | if (eSelMode != ShellMode::ListText && |
547 | 0 | eSelMode != ShellMode::TableListText && |
548 | 0 | eSelMode != ShellMode::TableText && |
549 | 0 | eSelMode != ShellMode::Text ) |
550 | 0 | throw RuntimeException(); |
551 | | |
552 | 0 | SwRubyList aList; |
553 | |
|
554 | 0 | for(const Sequence<PropertyValue>& rPropList : rRubyList) |
555 | 0 | { |
556 | 0 | std::unique_ptr<SwRubyListEntry> pEntry(new SwRubyListEntry); |
557 | 0 | OUString sTmp; |
558 | 0 | for(const PropertyValue& rProperty : rPropList) |
559 | 0 | { |
560 | 0 | if(rProperty.Name == UNO_NAME_RUBY_BASE_TEXT) |
561 | 0 | { |
562 | 0 | rProperty.Value >>= sTmp; |
563 | 0 | pEntry->SetText(sTmp); |
564 | 0 | } |
565 | 0 | else if(rProperty.Name == UNO_NAME_RUBY_TEXT) |
566 | 0 | { |
567 | 0 | rProperty.Value >>= sTmp; |
568 | 0 | pEntry->GetRubyAttr().SetText(sTmp); |
569 | 0 | } |
570 | 0 | else if(rProperty.Name == UNO_NAME_RUBY_CHAR_STYLE_NAME) |
571 | 0 | { |
572 | 0 | if(rProperty.Value >>= sTmp) |
573 | 0 | { |
574 | 0 | UIName sName; |
575 | 0 | SwStyleNameMapper::FillUIName(ProgName(sTmp), sName, SwGetPoolIdFromName::ChrFmt ); |
576 | 0 | const SwPoolFormatId nPoolId = sName.isEmpty() ? SwPoolFormatId::ZERO |
577 | 0 | : SwStyleNameMapper::GetPoolIdFromUIName(sName, |
578 | 0 | SwGetPoolIdFromName::ChrFmt ); |
579 | |
|
580 | 0 | pEntry->GetRubyAttr().SetCharFormatName( sName ); |
581 | 0 | pEntry->GetRubyAttr().SetCharFormatId( nPoolId ); |
582 | 0 | } |
583 | 0 | } |
584 | 0 | else if(rProperty.Name == UNO_NAME_RUBY_ADJUST) |
585 | 0 | { |
586 | 0 | sal_Int16 nTmp = 0; |
587 | 0 | if(rProperty.Value >>= nTmp) |
588 | 0 | pEntry->GetRubyAttr().SetAdjustment(static_cast<css::text::RubyAdjust>(nTmp)); |
589 | 0 | } |
590 | 0 | else if(rProperty.Name == UNO_NAME_RUBY_IS_ABOVE) |
591 | 0 | { |
592 | 0 | bool bValue = !rProperty.Value.hasValue() || |
593 | 0 | *o3tl::doAccess<bool>(rProperty.Value); |
594 | 0 | pEntry->GetRubyAttr().SetPosition(bValue ? 0 : 1); |
595 | 0 | } |
596 | 0 | else if(rProperty.Name == UNO_NAME_RUBY_POSITION) |
597 | 0 | { |
598 | 0 | sal_Int16 nTmp = 0; |
599 | 0 | if(rProperty.Value >>= nTmp) |
600 | 0 | pEntry->GetRubyAttr().SetPosition( nTmp ); |
601 | 0 | } |
602 | 0 | else if (rProperty.Name == UNO_NAME_RUBY_SEQUENCE_NUMBER) |
603 | 0 | { |
604 | 0 | sal_Int32 nTmp = 0; |
605 | 0 | if (rProperty.Value >>= nTmp) |
606 | 0 | { |
607 | 0 | pEntry->SetSequence(nTmp); |
608 | 0 | } |
609 | 0 | } |
610 | 0 | } |
611 | 0 | aList.push_back(std::move(pEntry)); |
612 | 0 | } |
613 | 0 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); |
614 | 0 | pDoc->SetRubyList( *rSh.GetCursor(), aList ); |
615 | 0 | } |
616 | | |
617 | | SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc() |
618 | 0 | { |
619 | 0 | SwWrtShell& rOldSh = m_pView->GetWrtShell(); |
620 | 0 | SfxPrinter *pPrt = rOldSh.getIDocumentDeviceAccess().getPrinter( false ); |
621 | 0 | rtl::Reference<SwDocShell> pDocSh = new SwDocShell(SfxObjectCreateMode::STANDARD); |
622 | 0 | SfxObjectShellLock xDocSh(pDocSh.get()); |
623 | 0 | xDocSh->DoInitNew(); |
624 | 0 | SwDoc *const pTempDoc( pDocSh->GetDoc() ); |
625 | | // #i103634#, #i112425#: do not expand numbering and fields on PDF export |
626 | 0 | pTempDoc->SetClipBoard(true); |
627 | 0 | rOldSh.FillPrtDoc(*pTempDoc, pPrt); |
628 | 0 | SfxViewFrame* pDocFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, SFX_INTERFACE_NONE ); |
629 | 0 | SwView* pDocView = static_cast<SwView*>( pDocFrame->GetViewShell() ); |
630 | 0 | pDocView->AttrChangedNotify(nullptr);//So that SelectShell is called. |
631 | 0 | if (SwWrtShell* pSh = pDocView->GetWrtShellPtr()) |
632 | 0 | { |
633 | 0 | IDocumentDeviceAccess& rIDDA = pSh->getIDocumentDeviceAccess(); |
634 | 0 | SfxPrinter* pTempPrinter = rIDDA.getPrinter( true ); |
635 | |
|
636 | 0 | const SwPageDesc& rCurPageDesc = rOldSh.GetPageDesc(rOldSh.GetCurPageDesc()); |
637 | |
|
638 | 0 | IDocumentDeviceAccess& rIDDA_old = rOldSh.getIDocumentDeviceAccess(); |
639 | |
|
640 | 0 | if( rIDDA_old.getPrinter( false ) ) |
641 | 0 | { |
642 | 0 | rIDDA.setJobsetup( *rIDDA_old.getJobsetup() ); |
643 | | //#69563# if it isn't the same printer then the pointer has been invalidated! |
644 | 0 | pTempPrinter = rIDDA.getPrinter( true ); |
645 | 0 | } |
646 | |
|
647 | 0 | pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue()); |
648 | 0 | } |
649 | |
|
650 | 0 | return xDocSh; |
651 | 0 | } |
652 | | |
653 | | void SwXTextView::NotifySelChanged() |
654 | 15.1k | { |
655 | 15.1k | OSL_ENSURE( m_pView, "view is missing" ); |
656 | | |
657 | 15.1k | lang::EventObject const aEvent(getXWeak()); |
658 | 15.1k | m_SelChangedListeners.notifyEach( |
659 | 15.1k | &view::XSelectionChangeListener::selectionChanged, aEvent); |
660 | 15.1k | } |
661 | | |
662 | | void SwXTextView::NotifyDBChanged() |
663 | 0 | { |
664 | 0 | URL aURL; |
665 | 0 | aURL.Complete = OUString::createFromAscii(SwXDispatch::GetDBChangeURL()); |
666 | |
|
667 | 0 | m_SelChangedListeners.forEach( |
668 | 0 | [&aURL] (const uno::Reference<XSelectionChangeListener>& xListener) |
669 | 0 | { |
670 | 0 | uno::Reference<XDispatch> xDispatch(xListener, UNO_QUERY); |
671 | 0 | if (xDispatch) |
672 | 0 | xDispatch->dispatch(aURL, {}); |
673 | 0 | }); |
674 | 0 | } |
675 | | |
676 | | uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXTextView::getPropertySetInfo( ) |
677 | 12.0k | { |
678 | 12.0k | SolarMutexGuard aGuard; |
679 | 12.0k | static uno::Reference< XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo(); |
680 | 12.0k | return aRef; |
681 | 12.0k | } |
682 | | |
683 | | void SAL_CALL SwXTextView::setPropertyValue( |
684 | | const OUString& rPropertyName, const uno::Any& rValue ) |
685 | 0 | { |
686 | 0 | SolarMutexGuard aGuard; |
687 | |
|
688 | 0 | if (rPropertyName == "PDFExport_ShowChanges") |
689 | 0 | { |
690 | | // hack used in PDF export code to turn off (or on) exporting showing tracked changes |
691 | | // logic is simplified from FN_REDLINE_SHOW path in SwView |
692 | 0 | bool bShow = false; |
693 | 0 | rValue >>= bShow; |
694 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
695 | 0 | rSh.StartAllAction(); |
696 | 0 | rSh.GetLayout()->SetHideRedlines(!bShow); |
697 | 0 | rSh.EndAllAction(); |
698 | 0 | return; |
699 | 0 | } |
700 | | |
701 | 0 | const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); |
702 | 0 | if (!pEntry) |
703 | 0 | throw UnknownPropertyException(rPropertyName); |
704 | 0 | else if (pEntry->nFlags & PropertyAttribute::READONLY) |
705 | 0 | throw PropertyVetoException(); |
706 | 0 | else |
707 | 0 | { |
708 | 0 | switch (pEntry->nWID) |
709 | 0 | { |
710 | 0 | case WID_IS_HIDE_SPELL_MARKS : |
711 | | // deprecated #i91949 |
712 | 0 | break; |
713 | 0 | case WID_IS_CONSTANT_SPELLCHECK : |
714 | 0 | { |
715 | 0 | bool bVal = false; |
716 | 0 | const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions(); |
717 | 0 | if (!pOpt || !(rValue >>= bVal)) |
718 | 0 | throw RuntimeException(); |
719 | 0 | SwViewOption aNewOpt( *pOpt ); |
720 | 0 | if (pEntry->nWID == WID_IS_CONSTANT_SPELLCHECK) |
721 | 0 | aNewOpt.SetOnlineSpell(bVal); |
722 | 0 | m_pView->GetWrtShell().ApplyViewOptions( aNewOpt ); |
723 | 0 | } |
724 | 0 | break; |
725 | 0 | default : |
726 | 0 | OSL_FAIL("unknown WID"); |
727 | 0 | } |
728 | 0 | } |
729 | 0 | } |
730 | | |
731 | | uno::Any SAL_CALL SwXTextView::getPropertyValue( |
732 | | const OUString& rPropertyName ) |
733 | 0 | { |
734 | 0 | SolarMutexGuard aGuard; |
735 | |
|
736 | 0 | Any aRet; |
737 | |
|
738 | 0 | if (rPropertyName == "PDFExport_ShowChanges") |
739 | 0 | { |
740 | 0 | const bool bShow = !m_pView->GetWrtShell().GetLayout()->IsHideRedlines(); |
741 | 0 | aRet <<= bShow; |
742 | 0 | return aRet; |
743 | 0 | } |
744 | | |
745 | 0 | const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); |
746 | 0 | if (!pEntry) |
747 | 0 | throw UnknownPropertyException(rPropertyName); |
748 | | |
749 | 0 | sal_Int16 nWID = pEntry->nWID; |
750 | 0 | switch (nWID) |
751 | 0 | { |
752 | 0 | case WID_PAGE_COUNT : |
753 | 0 | case WID_LINE_COUNT : |
754 | 0 | { |
755 | | // format document completely in order to get meaningful |
756 | | // values for page count and line count |
757 | 0 | m_pView->GetWrtShell().CalcLayout(); |
758 | |
|
759 | 0 | sal_Int32 nCount = -1; |
760 | 0 | if (nWID == WID_PAGE_COUNT) |
761 | 0 | nCount = m_pView->GetWrtShell().GetPageCount(); |
762 | 0 | else // WID_LINE_COUNT |
763 | 0 | nCount = m_pView->GetWrtShell().GetLineCount(); |
764 | 0 | aRet <<= nCount; |
765 | 0 | } |
766 | 0 | break; |
767 | 0 | case WID_IS_HIDE_SPELL_MARKS : |
768 | | // deprecated #i91949 |
769 | 0 | break; |
770 | 0 | case WID_IS_CONSTANT_SPELLCHECK : |
771 | 0 | { |
772 | 0 | const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions(); |
773 | 0 | if (!pOpt) |
774 | 0 | throw RuntimeException(); |
775 | 0 | aRet <<= pOpt->IsOnlineSpell(); |
776 | 0 | } |
777 | 0 | break; |
778 | 0 | default : |
779 | 0 | OSL_FAIL("unknown WID"); |
780 | 0 | } |
781 | | |
782 | 0 | return aRet; |
783 | 0 | } |
784 | | |
785 | | void SAL_CALL SwXTextView::addPropertyChangeListener( |
786 | | const OUString& /*rPropertyName*/, |
787 | | const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ ) |
788 | 0 | { |
789 | 0 | OSL_FAIL("not implemented"); |
790 | 0 | } |
791 | | |
792 | | void SAL_CALL SwXTextView::removePropertyChangeListener( |
793 | | const OUString& /*rPropertyName*/, |
794 | | const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ ) |
795 | 0 | { |
796 | 0 | OSL_FAIL("not implemented"); |
797 | 0 | } |
798 | | |
799 | | void SAL_CALL SwXTextView::addVetoableChangeListener( |
800 | | const OUString& /*rPropertyName*/, |
801 | | const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ ) |
802 | 0 | { |
803 | 0 | OSL_FAIL("not implemented"); |
804 | 0 | } |
805 | | |
806 | | void SAL_CALL SwXTextView::removeVetoableChangeListener( |
807 | | const OUString& /*rPropertyName*/, |
808 | | const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ ) |
809 | 0 | { |
810 | 0 | OSL_FAIL("not implemented"); |
811 | 0 | } |
812 | | |
813 | | OUString SwXTextView::getImplementationName() |
814 | 0 | { |
815 | 0 | return u"SwXTextView"_ustr; |
816 | 0 | } |
817 | | |
818 | | sal_Bool SwXTextView::supportsService(const OUString& rServiceName) |
819 | 0 | { |
820 | 0 | return cppu::supportsService(this, rServiceName); |
821 | 0 | } |
822 | | |
823 | | Sequence< OUString > SwXTextView::getSupportedServiceNames() |
824 | 0 | { |
825 | 0 | return { u"com.sun.star.text.TextDocumentView"_ustr, u"com.sun.star.view.OfficeDocumentView"_ustr }; |
826 | 0 | } |
827 | | |
828 | | SwXTextViewCursor::SwXTextViewCursor(SwView* pVw) : |
829 | 0 | m_pView(pVw), |
830 | 0 | m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)) |
831 | 0 | { |
832 | 0 | } |
833 | | |
834 | | SwXTextViewCursor::~SwXTextViewCursor() |
835 | 0 | { |
836 | 0 | } |
837 | | |
838 | | // used to determine if there is a text selection or not. |
839 | | // If there is no text selection the functions that need a working |
840 | | // cursor will be disabled (throw RuntimeException). This will be the case |
841 | | // for the following interfaces: |
842 | | // - XViewCursor |
843 | | // - XTextCursor |
844 | | // - XTextRange |
845 | | // - XLineCursor |
846 | | bool SwXTextViewCursor::IsTextSelection( bool bAllowTables ) const |
847 | 0 | { |
848 | |
|
849 | 0 | bool bRes = false; |
850 | 0 | OSL_ENSURE(m_pView, "m_pView is NULL ???"); |
851 | 0 | if(m_pView) |
852 | 0 | { |
853 | | //! m_pView->GetShellMode() will only work after the shell |
854 | | //! has already changed and thus can not be used here! |
855 | 0 | SelectionType eSelType = m_pView->GetWrtShell().GetSelectionType(); |
856 | 0 | bRes = ( (SelectionType::Text & eSelType) || |
857 | 0 | (SelectionType::NumberList & eSelType) ) && |
858 | 0 | (!(SelectionType::TableCell & eSelType) || bAllowTables); |
859 | 0 | } |
860 | 0 | return bRes; |
861 | 0 | } |
862 | | |
863 | | sal_Bool SwXTextViewCursor::isVisible() |
864 | 0 | { |
865 | 0 | OSL_FAIL("not implemented"); |
866 | 0 | return true; |
867 | 0 | } |
868 | | |
869 | | void SwXTextViewCursor::setVisible(sal_Bool /*bVisible*/) |
870 | 0 | { |
871 | 0 | OSL_FAIL("not implemented"); |
872 | 0 | } |
873 | | |
874 | | awt::Point SwXTextViewCursor::getPosition() |
875 | 0 | { |
876 | 0 | SolarMutexGuard aGuard; |
877 | 0 | awt::Point aRet; |
878 | 0 | if(!m_pView) |
879 | 0 | throw uno::RuntimeException(); |
880 | | |
881 | 0 | const SwWrtShell& rSh = m_pView->GetWrtShell(); |
882 | 0 | const SwRect& aCharRect(rSh.GetCharRect()); |
883 | |
|
884 | 0 | const SwFrameFormat& rMaster = rSh.GetPageDesc( rSh.GetCurPageDesc() ).GetMaster(); |
885 | |
|
886 | 0 | const SvxULSpaceItem& rUL = rMaster.GetULSpace(); |
887 | 0 | const tools::Long nY = aCharRect.Top() - (rUL.GetUpper() + DOCUMENTBORDER); |
888 | 0 | aRet.Y = convertTwipToMm100(nY); |
889 | |
|
890 | 0 | const SvxLRSpaceItem& rLR = rMaster.GetLRSpace(); |
891 | 0 | const tools::Long nX = aCharRect.Left() - (rLR.ResolveLeft() + DOCUMENTBORDER); |
892 | 0 | aRet.X = convertTwipToMm100(nX); |
893 | |
|
894 | 0 | return aRet; |
895 | 0 | } |
896 | | |
897 | | void SwXTextViewCursor::collapseToStart() |
898 | 0 | { |
899 | 0 | SolarMutexGuard aGuard; |
900 | 0 | if(!m_pView) |
901 | 0 | throw uno::RuntimeException(); |
902 | | |
903 | 0 | if (!IsTextSelection()) |
904 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
905 | | |
906 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
907 | 0 | if(rSh.HasSelection()) |
908 | 0 | { |
909 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
910 | 0 | pShellCursor->Normalize(); |
911 | 0 | pShellCursor->DeleteMark(); |
912 | 0 | rSh.EnterStdMode(); |
913 | 0 | rSh.SetSelection(*pShellCursor); |
914 | 0 | } |
915 | |
|
916 | 0 | } |
917 | | |
918 | | void SwXTextViewCursor::collapseToEnd() |
919 | 0 | { |
920 | 0 | SolarMutexGuard aGuard; |
921 | 0 | if(!m_pView) |
922 | 0 | throw uno::RuntimeException(); |
923 | | |
924 | 0 | if (!IsTextSelection()) |
925 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
926 | | |
927 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
928 | 0 | if(rSh.HasSelection()) |
929 | 0 | { |
930 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
931 | 0 | pShellCursor->Normalize(false); |
932 | 0 | pShellCursor->DeleteMark(); |
933 | 0 | rSh.EnterStdMode(); |
934 | 0 | rSh.SetSelection(*pShellCursor); |
935 | 0 | } |
936 | |
|
937 | 0 | } |
938 | | |
939 | | sal_Bool SwXTextViewCursor::isCollapsed() |
940 | 0 | { |
941 | 0 | SolarMutexGuard aGuard; |
942 | 0 | bool bRet = false; |
943 | 0 | if(!m_pView) |
944 | 0 | throw uno::RuntimeException(); |
945 | | |
946 | 0 | if (!IsTextSelection()) |
947 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
948 | | |
949 | 0 | const SwWrtShell& rSh = m_pView->GetWrtShell(); |
950 | 0 | bRet = !rSh.HasSelection(); |
951 | |
|
952 | 0 | return bRet; |
953 | |
|
954 | 0 | } |
955 | | |
956 | | sal_Bool SwXTextViewCursor::goLeft(sal_Int16 nCount, sal_Bool bExpand) |
957 | 0 | { |
958 | 0 | SolarMutexGuard aGuard; |
959 | 0 | bool bRet = false; |
960 | 0 | if(!m_pView) |
961 | 0 | throw uno::RuntimeException(); |
962 | | |
963 | 0 | if (!IsTextSelection()) |
964 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
965 | | |
966 | 0 | bRet = m_pView->GetWrtShell().Left( SwCursorSkipMode::Chars, bExpand, nCount, true ); |
967 | |
|
968 | 0 | return bRet; |
969 | 0 | } |
970 | | |
971 | | sal_Bool SwXTextViewCursor::goRight(sal_Int16 nCount, sal_Bool bExpand) |
972 | 0 | { |
973 | 0 | SolarMutexGuard aGuard; |
974 | 0 | bool bRet = false; |
975 | 0 | if(!m_pView) |
976 | 0 | throw uno::RuntimeException(); |
977 | | |
978 | 0 | if (!IsTextSelection()) |
979 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
980 | | |
981 | 0 | bRet = m_pView->GetWrtShell().Right( SwCursorSkipMode::Chars, bExpand, nCount, true ); |
982 | |
|
983 | 0 | return bRet; |
984 | |
|
985 | 0 | } |
986 | | |
987 | | void SwXTextViewCursor::gotoRange( |
988 | | const uno::Reference< text::XTextRange > & xRange, |
989 | | sal_Bool bExpand) |
990 | 0 | { |
991 | 0 | SolarMutexGuard aGuard; |
992 | 0 | if(!(m_pView && xRange.is())) |
993 | 0 | throw uno::RuntimeException(); |
994 | | |
995 | 0 | if (!IsTextSelection()) |
996 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
997 | | |
998 | 0 | SwUnoInternalPaM rDestPam(*m_pView->GetDocShell()->GetDoc()); |
999 | 0 | if (!::sw::XTextRangeToSwPaM(rDestPam, xRange)) |
1000 | 0 | { |
1001 | 0 | throw uno::RuntimeException(); |
1002 | 0 | } |
1003 | | |
1004 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
1005 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1006 | | // call EnterStdMode in non-text selections only |
1007 | 0 | if(!bExpand || |
1008 | 0 | (eSelMode != ShellMode::TableText && |
1009 | 0 | eSelMode != ShellMode::ListText && |
1010 | 0 | eSelMode != ShellMode::TableListText && |
1011 | 0 | eSelMode != ShellMode::Text )) |
1012 | 0 | rSh.EnterStdMode(); |
1013 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1014 | 0 | SwPaM aOwnPaM(*pShellCursor->GetPoint()); |
1015 | 0 | if(pShellCursor->HasMark()) |
1016 | 0 | { |
1017 | 0 | aOwnPaM.SetMark(); |
1018 | 0 | *aOwnPaM.GetMark() = *pShellCursor->GetMark(); |
1019 | 0 | } |
1020 | |
|
1021 | 0 | SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xRange.get()); |
1022 | 0 | SwXParagraph* pPara = dynamic_cast<SwXParagraph*>(xRange.get()); |
1023 | 0 | OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xRange.get()); |
1024 | |
|
1025 | 0 | const FrameTypeFlags nFrameType = rSh.GetFrameType(nullptr,true); |
1026 | |
|
1027 | 0 | SwStartNodeType eSearchNodeType = SwNormalStartNode; |
1028 | 0 | if(nFrameType & FrameTypeFlags::FLY_ANY) |
1029 | 0 | eSearchNodeType = SwFlyStartNode; |
1030 | 0 | else if(nFrameType &FrameTypeFlags::HEADER) |
1031 | 0 | eSearchNodeType = SwHeaderStartNode; |
1032 | 0 | else if(nFrameType & FrameTypeFlags::FOOTER) |
1033 | 0 | eSearchNodeType = SwFooterStartNode; |
1034 | 0 | else if(nFrameType & FrameTypeFlags::TABLE) |
1035 | 0 | eSearchNodeType = SwTableBoxStartNode; |
1036 | 0 | else if(nFrameType & FrameTypeFlags::FOOTNOTE) |
1037 | 0 | eSearchNodeType = SwFootnoteStartNode; |
1038 | |
|
1039 | 0 | const SwStartNode* pOwnStartNode = aOwnPaM.GetPointNode(). |
1040 | 0 | FindStartNodeByType(eSearchNodeType); |
1041 | |
|
1042 | 0 | const SwNode* pSrcNode = nullptr; |
1043 | 0 | if(pCursor && pCursor->GetPaM()) |
1044 | 0 | { |
1045 | 0 | pSrcNode = &pCursor->GetPaM()->GetPointNode(); |
1046 | 0 | } |
1047 | 0 | else if (pRange) |
1048 | 0 | { |
1049 | 0 | SwPaM aPam(pRange->GetDoc().GetNodes()); |
1050 | 0 | if (pRange->GetPositions(aPam)) |
1051 | 0 | { |
1052 | 0 | pSrcNode = &aPam.GetPointNode(); |
1053 | 0 | } |
1054 | 0 | } |
1055 | 0 | else if (pPara && pPara->GetTextNode()) |
1056 | 0 | { |
1057 | 0 | pSrcNode = pPara->GetTextNode(); |
1058 | 0 | } |
1059 | 0 | const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindStartNodeByType(eSearchNodeType) : nullptr; |
1060 | | |
1061 | | //Skip SectionNodes |
1062 | 0 | while(pTmp && pTmp->IsSectionNode()) |
1063 | 0 | { |
1064 | 0 | pTmp = pTmp->StartOfSectionNode(); |
1065 | 0 | } |
1066 | 0 | while(pOwnStartNode && pOwnStartNode->IsSectionNode()) |
1067 | 0 | { |
1068 | 0 | pOwnStartNode = pOwnStartNode->StartOfSectionNode(); |
1069 | 0 | } |
1070 | | //Without Expand it is allowed to jump out with the ViewCursor everywhere, |
1071 | | //with Expand only in the same environment |
1072 | 0 | if(bExpand && |
1073 | 0 | (pOwnStartNode != pTmp || |
1074 | 0 | (eSelMode != ShellMode::TableText && |
1075 | 0 | eSelMode != ShellMode::ListText && |
1076 | 0 | eSelMode != ShellMode::TableListText && |
1077 | 0 | eSelMode != ShellMode::Text))) |
1078 | 0 | throw uno::RuntimeException(); |
1079 | | |
1080 | | //Now, the selection must be expanded. |
1081 | 0 | if(bExpand) |
1082 | 0 | { |
1083 | | // The cursor should include everything that has been included |
1084 | | // by him and the transferred Range. |
1085 | 0 | SwPosition aOwnLeft(*aOwnPaM.Start()); |
1086 | 0 | SwPosition aOwnRight(*aOwnPaM.End()); |
1087 | 0 | auto [pParamLeft, pParamRight] = rDestPam.StartEnd(); // SwPosition* |
1088 | | // Now four SwPositions are there, two of them are needed, but which? |
1089 | 0 | if(aOwnRight > *pParamRight) |
1090 | 0 | *aOwnPaM.GetPoint() = std::move(aOwnRight); |
1091 | 0 | else |
1092 | 0 | *aOwnPaM.GetPoint() = *pParamRight; |
1093 | 0 | aOwnPaM.SetMark(); |
1094 | 0 | if(aOwnLeft < *pParamLeft) |
1095 | 0 | *aOwnPaM.GetMark() = std::move(aOwnLeft); |
1096 | 0 | else |
1097 | 0 | *aOwnPaM.GetMark() = *pParamLeft; |
1098 | 0 | } |
1099 | 0 | else |
1100 | 0 | { |
1101 | | //The cursor shall match the passed range. |
1102 | 0 | *aOwnPaM.GetPoint() = *rDestPam.GetPoint(); |
1103 | 0 | if(rDestPam.HasMark()) |
1104 | 0 | { |
1105 | 0 | aOwnPaM.SetMark(); |
1106 | 0 | *aOwnPaM.GetMark() = *rDestPam.GetMark(); |
1107 | 0 | } |
1108 | 0 | else |
1109 | 0 | aOwnPaM.DeleteMark(); |
1110 | 0 | } |
1111 | 0 | rSh.SetSelection(aOwnPaM); |
1112 | | |
1113 | |
|
1114 | 0 | } |
1115 | | |
1116 | | void SwXTextViewCursor::gotoStart(sal_Bool bExpand) |
1117 | 0 | { |
1118 | 0 | SolarMutexGuard aGuard; |
1119 | 0 | comphelper::ProfileZone aZone("SwXTextViewCursor::gotoStart"); |
1120 | 0 | if(!m_pView) |
1121 | 0 | throw uno::RuntimeException(); |
1122 | | |
1123 | 0 | if (!IsTextSelection()) |
1124 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1125 | | |
1126 | 0 | m_pView->GetWrtShell().StartOfSection( bExpand ); |
1127 | |
|
1128 | 0 | } |
1129 | | |
1130 | | void SwXTextViewCursor::gotoEnd(sal_Bool bExpand) |
1131 | 0 | { |
1132 | 0 | SolarMutexGuard aGuard; |
1133 | 0 | comphelper::ProfileZone aZone("SwXTextViewCursor::gotoEnd"); |
1134 | 0 | if(!m_pView) |
1135 | 0 | throw uno::RuntimeException(); |
1136 | | |
1137 | 0 | if (!IsTextSelection()) |
1138 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1139 | | |
1140 | 0 | m_pView->GetWrtShell().EndOfSection( bExpand ); |
1141 | |
|
1142 | 0 | } |
1143 | | |
1144 | | sal_Bool SwXTextViewCursor::jumpToFirstPage() |
1145 | 0 | { |
1146 | 0 | SolarMutexGuard aGuard; |
1147 | 0 | bool bRet = false; |
1148 | 0 | if(!m_pView) |
1149 | 0 | throw uno::RuntimeException(); |
1150 | | |
1151 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1152 | 0 | if (rSh.IsSelFrameMode()) |
1153 | 0 | { |
1154 | 0 | rSh.UnSelectFrame(); |
1155 | 0 | rSh.LeaveSelFrameMode(); |
1156 | 0 | } |
1157 | 0 | rSh.EnterStdMode(); |
1158 | 0 | bRet = rSh.SttEndDoc(true); |
1159 | |
|
1160 | 0 | return bRet; |
1161 | 0 | } |
1162 | | |
1163 | | sal_Bool SwXTextViewCursor::jumpToLastPage() |
1164 | 0 | { |
1165 | 0 | SolarMutexGuard aGuard; |
1166 | 0 | bool bRet = false; |
1167 | 0 | if(!m_pView) |
1168 | 0 | throw uno::RuntimeException(); |
1169 | | |
1170 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1171 | 0 | if (rSh.IsSelFrameMode()) |
1172 | 0 | { |
1173 | 0 | rSh.UnSelectFrame(); |
1174 | 0 | rSh.LeaveSelFrameMode(); |
1175 | 0 | } |
1176 | 0 | rSh.EnterStdMode(); |
1177 | 0 | bRet = rSh.SttEndDoc(false); |
1178 | 0 | rSh.SttPg(); |
1179 | |
|
1180 | 0 | return bRet; |
1181 | 0 | } |
1182 | | |
1183 | | sal_Bool SwXTextViewCursor::jumpToPage(sal_Int16 nPage) |
1184 | 0 | { |
1185 | 0 | SolarMutexGuard aGuard; |
1186 | 0 | bool bRet = false; |
1187 | 0 | if(!m_pView) |
1188 | 0 | throw uno::RuntimeException(); |
1189 | | |
1190 | 0 | bRet = m_pView->GetWrtShell().GotoPage(nPage, true); |
1191 | |
|
1192 | 0 | return bRet; |
1193 | 0 | } |
1194 | | |
1195 | | sal_Bool SwXTextViewCursor::jumpToNextPage() |
1196 | 0 | { |
1197 | 0 | SolarMutexGuard aGuard; |
1198 | 0 | bool bRet = false; |
1199 | 0 | if(!m_pView) |
1200 | 0 | throw uno::RuntimeException(); |
1201 | | |
1202 | 0 | bRet = m_pView->GetWrtShell().SttNxtPg(); |
1203 | |
|
1204 | 0 | return bRet; |
1205 | 0 | } |
1206 | | |
1207 | | sal_Bool SwXTextViewCursor::jumpToPreviousPage() |
1208 | 0 | { |
1209 | 0 | SolarMutexGuard aGuard; |
1210 | 0 | bool bRet = false; |
1211 | 0 | if(!m_pView) |
1212 | 0 | throw uno::RuntimeException(); |
1213 | | |
1214 | 0 | bRet = m_pView->GetWrtShell().EndPrvPg(); |
1215 | |
|
1216 | 0 | return bRet; |
1217 | 0 | } |
1218 | | |
1219 | | sal_Bool SwXTextViewCursor::jumpToEndOfPage() |
1220 | 0 | { |
1221 | 0 | SolarMutexGuard aGuard; |
1222 | 0 | bool bRet = false; |
1223 | 0 | if(!m_pView) |
1224 | 0 | throw uno::RuntimeException(); |
1225 | | |
1226 | 0 | bRet = m_pView->GetWrtShell().EndPg(); |
1227 | |
|
1228 | 0 | return bRet; |
1229 | 0 | } |
1230 | | |
1231 | | sal_Bool SwXTextViewCursor::jumpToStartOfPage() |
1232 | 0 | { |
1233 | 0 | SolarMutexGuard aGuard; |
1234 | 0 | bool bRet = false; |
1235 | 0 | if(!m_pView) |
1236 | 0 | throw uno::RuntimeException(); |
1237 | | |
1238 | 0 | bRet = m_pView->GetWrtShell().SttPg(); |
1239 | |
|
1240 | 0 | return bRet; |
1241 | 0 | } |
1242 | | |
1243 | | sal_Int16 SwXTextViewCursor::getPage() |
1244 | 0 | { |
1245 | 0 | SolarMutexGuard aGuard; |
1246 | 0 | sal_Int16 nRet = 0; |
1247 | 0 | if(!m_pView) |
1248 | 0 | throw uno::RuntimeException(); |
1249 | | |
1250 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1251 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1252 | 0 | nRet = static_cast<sal_Int16>(pShellCursor->GetPageNum()); |
1253 | |
|
1254 | 0 | return nRet; |
1255 | 0 | } |
1256 | | |
1257 | | sal_Bool SwXTextViewCursor::screenDown() |
1258 | 0 | { |
1259 | 0 | SolarMutexGuard aGuard; |
1260 | 0 | bool bRet = false; |
1261 | 0 | if(!m_pView) |
1262 | 0 | throw uno::RuntimeException(); |
1263 | | |
1264 | 0 | SfxRequest aReq(FN_PAGEDOWN, SfxCallMode::SLOT, m_pView->GetPool()); |
1265 | 0 | m_pView->Execute(aReq); |
1266 | 0 | const SfxPoolItemHolder& rResult(aReq.GetReturnValue()); |
1267 | 0 | bRet = rResult && static_cast<const SfxBoolItem*>(rResult.getItem())->GetValue(); |
1268 | |
|
1269 | 0 | return bRet; |
1270 | 0 | } |
1271 | | |
1272 | | sal_Bool SwXTextViewCursor::screenUp() |
1273 | 0 | { |
1274 | 0 | SolarMutexGuard aGuard; |
1275 | 0 | bool bRet = false; |
1276 | 0 | if(!m_pView) |
1277 | 0 | throw uno::RuntimeException(); |
1278 | | |
1279 | 0 | SfxRequest aReq(FN_PAGEUP, SfxCallMode::SLOT, m_pView->GetPool()); |
1280 | 0 | m_pView->Execute(aReq); |
1281 | 0 | const SfxPoolItemHolder& rResult(aReq.GetReturnValue()); |
1282 | 0 | bRet = rResult && static_cast<const SfxBoolItem*>(rResult.getItem())->GetValue(); |
1283 | |
|
1284 | 0 | return bRet; |
1285 | 0 | } |
1286 | | |
1287 | | uno::Reference< text::XText > SwXTextViewCursor::getText() |
1288 | 0 | { |
1289 | 0 | SolarMutexGuard aGuard; |
1290 | 0 | if(!m_pView) |
1291 | 0 | throw uno::RuntimeException(); |
1292 | | |
1293 | 0 | if (!IsTextSelection( false )) |
1294 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1295 | | |
1296 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1297 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1298 | 0 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); |
1299 | 0 | uno::Reference< SwXText > xRet = ::sw::CreateParentXText(*pDoc, *pShellCursor->Start()); |
1300 | |
|
1301 | 0 | return xRet; |
1302 | 0 | } |
1303 | | |
1304 | | uno::Reference< text::XTextRange > SwXTextViewCursor::getStart() |
1305 | 0 | { |
1306 | 0 | SolarMutexGuard aGuard; |
1307 | 0 | if(!m_pView) |
1308 | 0 | throw uno::RuntimeException(); |
1309 | | |
1310 | 0 | if (!IsTextSelection()) |
1311 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1312 | | |
1313 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1314 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1315 | 0 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); |
1316 | |
|
1317 | 0 | return SwXTextRange::CreateXTextRange(*pDoc, *pShellCursor->Start(), nullptr); |
1318 | 0 | } |
1319 | | |
1320 | | uno::Reference< text::XTextRange > SwXTextViewCursor::getEnd() |
1321 | 0 | { |
1322 | 0 | SolarMutexGuard aGuard; |
1323 | 0 | if(!m_pView) |
1324 | 0 | throw uno::RuntimeException(); |
1325 | | |
1326 | 0 | if (!IsTextSelection()) |
1327 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1328 | | |
1329 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1330 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1331 | 0 | SwDoc* pDoc = m_pView->GetDocShell()->GetDoc(); |
1332 | |
|
1333 | 0 | return SwXTextRange::CreateXTextRange(*pDoc, *pShellCursor->End(), nullptr); |
1334 | 0 | } |
1335 | | |
1336 | | OUString SwXTextViewCursor::getString() |
1337 | 0 | { |
1338 | 0 | SolarMutexGuard aGuard; |
1339 | 0 | OUString uRet; |
1340 | 0 | if(m_pView) |
1341 | 0 | { |
1342 | 0 | if (!IsTextSelection( false )) |
1343 | 0 | { |
1344 | 0 | SAL_WARN("sw.uno", "no text selection in getString() " << getXWeak()); |
1345 | 0 | return uRet; |
1346 | 0 | } |
1347 | | |
1348 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
1349 | 0 | switch(eSelMode) |
1350 | 0 | { |
1351 | | //! since setString for SEL_TABLE_TEXT (with possible |
1352 | | //! multi selection of cells) would not work properly we |
1353 | | //! will ignore this case for both |
1354 | | //! functions (setString AND getString) because of symmetrie. |
1355 | | |
1356 | 0 | case ShellMode::ListText : |
1357 | 0 | case ShellMode::TableListText: |
1358 | 0 | case ShellMode::Text : |
1359 | 0 | { |
1360 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1361 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1362 | 0 | SwUnoCursorHelper::GetTextFromPam(*pShellCursor, uRet, |
1363 | 0 | rSh.GetLayout()); |
1364 | 0 | break; |
1365 | 0 | } |
1366 | 0 | default:;//prevent warning |
1367 | 0 | } |
1368 | 0 | } |
1369 | 0 | return uRet; |
1370 | 0 | } |
1371 | | |
1372 | | void SwXTextViewCursor::setString(const OUString& aString) |
1373 | 0 | { |
1374 | 0 | SolarMutexGuard aGuard; |
1375 | 0 | if(!m_pView) |
1376 | 0 | return; |
1377 | | |
1378 | 0 | if (!IsTextSelection( false )) |
1379 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1380 | | |
1381 | 0 | ShellMode eSelMode = m_pView->GetShellMode(); |
1382 | 0 | switch(eSelMode) |
1383 | 0 | { |
1384 | | //! since setString for SEL_TABLE_TEXT (with possible |
1385 | | //! multi selection of cells) would not work properly we |
1386 | | //! will ignore this case for both |
1387 | | //! functions (setString AND getString) because of symmetrie. |
1388 | | |
1389 | 0 | case ShellMode::ListText : |
1390 | 0 | case ShellMode::TableListText : |
1391 | 0 | case ShellMode::Text : |
1392 | 0 | { |
1393 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1394 | 0 | SwCursor* pShellCursor = rSh.GetCursor(); |
1395 | 0 | SwUnoCursorHelper::SetString(*pShellCursor, aString); |
1396 | 0 | break; |
1397 | 0 | } |
1398 | 0 | default:;//prevent warning |
1399 | 0 | } |
1400 | 0 | } |
1401 | | |
1402 | | uno::Reference< XPropertySetInfo > SwXTextViewCursor::getPropertySetInfo( ) |
1403 | 0 | { |
1404 | 0 | static uno::Reference< XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo(); |
1405 | 0 | return xRef; |
1406 | 0 | } |
1407 | | |
1408 | | void SwXTextViewCursor::setPropertyValue( const OUString& rPropertyName, const Any& aValue ) |
1409 | 0 | { |
1410 | 0 | SolarMutexGuard aGuard; |
1411 | 0 | if(!m_pView) |
1412 | 0 | throw RuntimeException(); |
1413 | | |
1414 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1415 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1416 | 0 | SwNode& rNode = pShellCursor->GetPointNode(); |
1417 | 0 | if (!rNode.IsTextNode()) |
1418 | 0 | throw RuntimeException(); |
1419 | | |
1420 | 0 | SwUnoCursorHelper::SetPropertyValue( |
1421 | 0 | *pShellCursor, *m_pPropSet, rPropertyName, aValue ); |
1422 | | |
1423 | |
|
1424 | 0 | } |
1425 | | |
1426 | | Any SwXTextViewCursor::getPropertyValue( const OUString& rPropertyName ) |
1427 | 0 | { |
1428 | 0 | SolarMutexGuard aGuard; |
1429 | 0 | Any aRet; |
1430 | 0 | if(!m_pView) |
1431 | 0 | throw RuntimeException(); |
1432 | | |
1433 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1434 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1435 | 0 | aRet = SwUnoCursorHelper::GetPropertyValue( |
1436 | 0 | *pShellCursor, *m_pPropSet, rPropertyName); |
1437 | |
|
1438 | 0 | return aRet; |
1439 | 0 | } |
1440 | | |
1441 | | void SwXTextViewCursor::addPropertyChangeListener( |
1442 | | const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) |
1443 | 0 | { |
1444 | 0 | } |
1445 | | |
1446 | | void SwXTextViewCursor::removePropertyChangeListener( |
1447 | | const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ ) |
1448 | 0 | { |
1449 | 0 | } |
1450 | | |
1451 | | void SwXTextViewCursor::addVetoableChangeListener( |
1452 | | const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) |
1453 | 0 | { |
1454 | 0 | } |
1455 | | |
1456 | | void SwXTextViewCursor::removeVetoableChangeListener( |
1457 | | const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) |
1458 | 0 | { |
1459 | 0 | } |
1460 | | |
1461 | | PropertyState SwXTextViewCursor::getPropertyState( const OUString& rPropertyName ) |
1462 | 0 | { |
1463 | 0 | SolarMutexGuard aGuard; |
1464 | 0 | PropertyState eState; |
1465 | 0 | if(!m_pView) |
1466 | 0 | throw RuntimeException(); |
1467 | | |
1468 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1469 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1470 | 0 | eState = SwUnoCursorHelper::GetPropertyState( |
1471 | 0 | *pShellCursor, *m_pPropSet, rPropertyName); |
1472 | |
|
1473 | 0 | return eState; |
1474 | 0 | } |
1475 | | |
1476 | | Sequence< PropertyState > SwXTextViewCursor::getPropertyStates( |
1477 | | const Sequence< OUString >& rPropertyNames ) |
1478 | 0 | { |
1479 | 0 | SolarMutexGuard aGuard; |
1480 | 0 | Sequence< PropertyState > aRet; |
1481 | 0 | if(m_pView) |
1482 | 0 | { |
1483 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1484 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1485 | 0 | aRet = SwUnoCursorHelper::GetPropertyStates( |
1486 | 0 | *pShellCursor, *m_pPropSet, rPropertyNames); |
1487 | 0 | } |
1488 | 0 | return aRet; |
1489 | 0 | } |
1490 | | |
1491 | | void SwXTextViewCursor::setPropertyToDefault( const OUString& rPropertyName ) |
1492 | 0 | { |
1493 | 0 | SolarMutexGuard aGuard; |
1494 | 0 | if(m_pView) |
1495 | 0 | { |
1496 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1497 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1498 | 0 | SwUnoCursorHelper::SetPropertyToDefault( |
1499 | 0 | *pShellCursor, *m_pPropSet, rPropertyName); |
1500 | 0 | } |
1501 | 0 | } |
1502 | | |
1503 | | Any SwXTextViewCursor::getPropertyDefault( const OUString& rPropertyName ) |
1504 | 0 | { |
1505 | 0 | Any aRet; |
1506 | 0 | SolarMutexGuard aGuard; |
1507 | 0 | if(m_pView) |
1508 | 0 | { |
1509 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1510 | 0 | SwPaM* pShellCursor = rSh.GetCursor(); |
1511 | 0 | aRet = SwUnoCursorHelper::GetPropertyDefault( |
1512 | 0 | *pShellCursor, *m_pPropSet, rPropertyName); |
1513 | 0 | } |
1514 | 0 | return aRet; |
1515 | 0 | } |
1516 | | |
1517 | | sal_Bool SwXTextViewCursor::goDown(sal_Int16 nCount, sal_Bool bExpand) |
1518 | 0 | { |
1519 | 0 | SolarMutexGuard aGuard; |
1520 | 0 | comphelper::ProfileZone aZone("SwXTextViewCursor::goDown"); |
1521 | 0 | bool bRet = false; |
1522 | 0 | if(!m_pView) |
1523 | 0 | throw uno::RuntimeException(); |
1524 | | |
1525 | 0 | if (!IsTextSelection()) |
1526 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1527 | | |
1528 | 0 | bRet = m_pView->GetWrtShell().Down( bExpand, nCount, true ); |
1529 | |
|
1530 | 0 | return bRet; |
1531 | 0 | } |
1532 | | |
1533 | | sal_Bool SwXTextViewCursor::goUp(sal_Int16 nCount, sal_Bool bExpand) |
1534 | 0 | { |
1535 | 0 | SolarMutexGuard aGuard; |
1536 | 0 | comphelper::ProfileZone aZone("SwXTextViewCursor::goUp"); |
1537 | 0 | bool bRet = false; |
1538 | 0 | if(!m_pView) |
1539 | 0 | throw uno::RuntimeException(); |
1540 | | |
1541 | 0 | if (!IsTextSelection()) |
1542 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1543 | | |
1544 | 0 | bRet = m_pView->GetWrtShell().Up( bExpand, nCount, true ); |
1545 | |
|
1546 | 0 | return bRet; |
1547 | 0 | } |
1548 | | |
1549 | | sal_Bool SwXTextViewCursor::isAtStartOfLine() |
1550 | 0 | { |
1551 | 0 | SolarMutexGuard aGuard; |
1552 | 0 | bool bRet = false; |
1553 | 0 | if(!m_pView) |
1554 | 0 | throw uno::RuntimeException(); |
1555 | | |
1556 | 0 | if (!IsTextSelection( false )) |
1557 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1558 | | |
1559 | 0 | bRet = m_pView->GetWrtShell().IsAtLeftMargin(); |
1560 | |
|
1561 | 0 | return bRet; |
1562 | 0 | } |
1563 | | |
1564 | | sal_Bool SwXTextViewCursor::isAtEndOfLine() |
1565 | 0 | { |
1566 | 0 | SolarMutexGuard aGuard; |
1567 | 0 | bool bRet = false; |
1568 | 0 | if(!m_pView) |
1569 | 0 | throw uno::RuntimeException(); |
1570 | | |
1571 | 0 | if (!IsTextSelection( false )) |
1572 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1573 | | |
1574 | 0 | bRet = m_pView->GetWrtShell().IsAtRightMargin(); |
1575 | |
|
1576 | 0 | return bRet; |
1577 | 0 | } |
1578 | | |
1579 | | void SwXTextViewCursor::gotoEndOfLine(sal_Bool bExpand) |
1580 | 0 | { |
1581 | 0 | SolarMutexGuard aGuard; |
1582 | 0 | if(!m_pView) |
1583 | 0 | throw uno::RuntimeException(); |
1584 | | |
1585 | 0 | if (!IsTextSelection( false )) |
1586 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1587 | | |
1588 | 0 | m_pView->GetWrtShell().RightMargin(bExpand, true); |
1589 | |
|
1590 | 0 | } |
1591 | | |
1592 | | void SwXTextViewCursor::gotoStartOfLine(sal_Bool bExpand) |
1593 | 0 | { |
1594 | 0 | SolarMutexGuard aGuard; |
1595 | 0 | if(!m_pView) |
1596 | 0 | throw uno::RuntimeException(); |
1597 | | |
1598 | 0 | if (!IsTextSelection( false )) |
1599 | 0 | throw uno::RuntimeException(u"no text selection"_ustr, getXWeak() ); |
1600 | | |
1601 | 0 | m_pView->GetWrtShell().LeftMargin(bExpand, true); |
1602 | |
|
1603 | 0 | } |
1604 | | |
1605 | | OUString SwXTextViewCursor::getImplementationName() |
1606 | 0 | { |
1607 | 0 | return u"SwXTextViewCursor"_ustr; |
1608 | 0 | } |
1609 | | |
1610 | | sal_Bool SwXTextViewCursor::supportsService(const OUString& rServiceName) |
1611 | 0 | { |
1612 | 0 | return cppu::supportsService(this, rServiceName); |
1613 | 0 | } |
1614 | | |
1615 | | Sequence< OUString > SwXTextViewCursor::getSupportedServiceNames() |
1616 | 0 | { |
1617 | 0 | return { u"com.sun.star.text.TextViewCursor"_ustr, |
1618 | 0 | u"com.sun.star.style.CharacterProperties"_ustr, |
1619 | 0 | u"com.sun.star.style.CharacterPropertiesAsian"_ustr, |
1620 | 0 | u"com.sun.star.style.CharacterPropertiesComplex"_ustr, |
1621 | 0 | u"com.sun.star.style.ParagraphProperties"_ustr, |
1622 | 0 | u"com.sun.star.style.ParagraphPropertiesAsian"_ustr, |
1623 | 0 | u"com.sun.star.style.ParagraphPropertiesComplex"_ustr }; |
1624 | 0 | } |
1625 | | |
1626 | | const SwDoc* SwXTextViewCursor::GetDoc() const |
1627 | 0 | { |
1628 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1629 | 0 | return rSh.GetCursor() ? &rSh.GetCursor()->GetDoc() : nullptr; |
1630 | 0 | } |
1631 | | |
1632 | | SwDoc* SwXTextViewCursor::GetDoc() |
1633 | 0 | { |
1634 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1635 | 0 | return rSh.GetCursor() ? &rSh.GetCursor()->GetDoc() : nullptr; |
1636 | 0 | } |
1637 | | |
1638 | | const SwPaM* SwXTextViewCursor::GetPaM() const |
1639 | 0 | { |
1640 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1641 | 0 | return rSh.GetCursor(); |
1642 | 0 | } |
1643 | | |
1644 | | SwPaM* SwXTextViewCursor::GetPaM() |
1645 | 0 | { |
1646 | 0 | SwWrtShell& rSh = m_pView->GetWrtShell(); |
1647 | 0 | return rSh.GetCursor(); |
1648 | 0 | } |
1649 | | |
1650 | | uno::Reference<datatransfer::XTransferable> SAL_CALL |
1651 | | SwXTextView::getTransferableForTextRange(uno::Reference<text::XTextRange> const& xTextRange) |
1652 | 0 | { |
1653 | 0 | SolarMutexGuard aGuard; |
1654 | | |
1655 | | // the point is we can copy PaM that wouldn't be legal as shell cursor |
1656 | 0 | SwUnoInternalPaM aPam(*m_pView->GetDocShell()->GetDoc()); |
1657 | 0 | if (!::sw::XTextRangeToSwPaM(aPam, xTextRange, ::sw::TextRangeMode::AllowNonTextNode)) |
1658 | 0 | { |
1659 | 0 | throw uno::RuntimeException(u"invalid text range"_ustr); |
1660 | 0 | } |
1661 | | |
1662 | | //force immediate shell update |
1663 | 0 | GetView()->StopShellTimer(); |
1664 | 0 | SwWrtShell& rSh = GetView()->GetWrtShell(); |
1665 | 0 | rtl::Reference<SwTransferable> pTransfer = new SwTransferable(rSh); |
1666 | 0 | const bool bLockedView = rSh.IsViewLocked(); |
1667 | 0 | rSh.LockView( true ); |
1668 | 0 | pTransfer->PrepareForCopyTextRange(aPam); |
1669 | 0 | rSh.LockView( bLockedView ); |
1670 | 0 | return pTransfer; |
1671 | 0 | } |
1672 | | |
1673 | | OUString SAL_CALL SwXTextView::dump(const OUString& rKind) |
1674 | 0 | { |
1675 | 0 | if (rKind == "layout") |
1676 | 0 | { |
1677 | 0 | SwRootFrame* pLayout = GetView()->GetWrtShell().GetLayout(); |
1678 | 0 | return comphelper::dumpXmlToString([pLayout](xmlTextWriterPtr pWriter) |
1679 | 0 | { pLayout->dumpAsXml(pWriter); }); |
1680 | 0 | } |
1681 | | |
1682 | 0 | return OUString(); |
1683 | 0 | } |
1684 | | |
1685 | | uno::Reference< datatransfer::XTransferable > SAL_CALL SwXTextView::getTransferable() |
1686 | 0 | { |
1687 | 0 | SolarMutexGuard aGuard; |
1688 | | |
1689 | | //force immediate shell update |
1690 | 0 | GetView()->StopShellTimer(); |
1691 | 0 | SwWrtShell& rSh = GetView()->GetWrtShell(); |
1692 | 0 | if ( GetView()->GetShellMode() == ShellMode::DrawText ) |
1693 | 0 | { |
1694 | 0 | SdrView *pSdrView = rSh.GetDrawView(); |
1695 | 0 | OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView(); |
1696 | 0 | return pOLV->GetEditView().GetTransferable(); |
1697 | 0 | } |
1698 | 0 | else |
1699 | 0 | { |
1700 | 0 | rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh ); |
1701 | 0 | const bool bLockedView = rSh.IsViewLocked(); |
1702 | 0 | rSh.LockView( true ); //lock visible section |
1703 | 0 | pTransfer->PrepareForCopy(); |
1704 | 0 | rSh.LockView( bLockedView ); |
1705 | 0 | return pTransfer; |
1706 | 0 | } |
1707 | 0 | } |
1708 | | |
1709 | | void SAL_CALL SwXTextView::insertTransferable( const uno::Reference< datatransfer::XTransferable >& xTrans ) |
1710 | 0 | { |
1711 | 0 | SolarMutexGuard aGuard; |
1712 | | |
1713 | | //force immediate shell update |
1714 | 0 | GetView()->StopShellTimer(); |
1715 | 0 | SwWrtShell& rSh = GetView()->GetWrtShell(); |
1716 | 0 | if ( GetView()->GetShellMode() == ShellMode::DrawText ) |
1717 | 0 | { |
1718 | 0 | SdrView *pSdrView = rSh.GetDrawView(); |
1719 | 0 | OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView(); |
1720 | 0 | pOLV->GetEditView().InsertText( xTrans, GetView()->GetDocShell()->GetMedium()->GetBaseURL(), false ); |
1721 | 0 | } |
1722 | 0 | else |
1723 | 0 | { |
1724 | 0 | TransferableDataHelper aDataHelper( xTrans ); |
1725 | 0 | if ( SwTransferable::IsPaste( rSh, aDataHelper ) ) |
1726 | 0 | { |
1727 | 0 | SwTransferable::Paste( rSh, aDataHelper ); |
1728 | 0 | if( rSh.IsFrameSelected() || rSh.GetSelectedObjCount() ) |
1729 | 0 | rSh.EnterSelFrameMode(); |
1730 | 0 | GetView()->AttrChangedNotify(nullptr); |
1731 | 0 | } |
1732 | 0 | } |
1733 | 0 | } |
1734 | | |
1735 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |