bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uno / unotxvw.cxx
blobcefcc8bc52433145ef2634e5377ab3feeee74441
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 .
21 #include "viscrs.hxx"
22 #include <sfx2/frame.hxx>
23 #include <sfx2/printer.hxx>
24 #include <cmdid.h>
25 #include <hintids.hxx>
26 #include <docsh.hxx>
27 #include <rubylist.hxx>
28 #include <doc.hxx>
29 #include <unotxvw.hxx>
30 #include <unodispatch.hxx>
31 #include <unomap.hxx>
32 #include <unostyle.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 <svx/svdogrp.hxx>
46 #include <editeng/pbinitem.hxx>
47 #include <pagedesc.hxx>
48 #include <editeng/lrspitem.hxx>
49 #include <editeng/ulspitem.hxx>
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/request.hxx>
52 #include <frmatr.hxx>
53 #include <osl/mutex.hxx>
54 #include <IMark.hxx>
55 #include <unotxdoc.hxx>
56 #include <unodraw.hxx>
57 #include <svx/unoshcol.hxx>
58 #include <svx/unoshape.hxx>
59 #include <svx/svdpagv.hxx>
60 #include <swerror.h>
61 #include <shellio.hxx>
62 #include <ndtxt.hxx>
63 #include <SwStyleNameMapper.hxx>
64 #include <crsskip.hxx>
65 #include <com/sun/star/beans/PropertyAttribute.hpp>
66 #include <editeng/outliner.hxx>
67 #include <editeng/editview.hxx>
68 #include <unoparagraph.hxx>
69 #include <unocrsrhelper.hxx>
70 #include <unotextrange.hxx>
71 #include <sfx2/docfile.hxx>
72 #include <switerator.hxx>
73 #include "swdtflvr.hxx"
74 #include <vcl/svapp.hxx>
75 #include <comphelper/servicehelper.hxx>
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::lang;
80 using namespace ::com::sun::star::beans;
81 using namespace ::com::sun::star::text;
82 using namespace ::com::sun::star::view;
83 using namespace ::com::sun::star::frame;
85 using ::com::sun::star::util::URL;
86 using comphelper::HelperBaseNoState;
89 SwXTextView::SwXTextView(SwView* pSwView) :
90 SfxBaseController(pSwView),
91 m_SelChangedListeners(m_aMutex),
92 m_pView(pSwView),
93 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_VIEW ) ),
94 pxViewSettings(0),
95 pxTextViewCursor(0)
100 SwXTextView::~SwXTextView()
102 Invalidate();
105 void SwXTextView::Invalidate()
107 if(pxViewSettings)
109 HelperBaseNoState *pSettings = static_cast < HelperBaseNoState * > ( pxViewSettings->get() );
110 static_cast < SwXViewSettings* > ( pSettings )->Invalidate();
111 DELETEZ(pxViewSettings);
113 if(pxTextViewCursor)
115 text::XTextViewCursor* pCrsr = pxTextViewCursor->get();
116 ((SwXTextViewCursor*)pCrsr)->Invalidate();
117 DELETEZ(pxTextViewCursor);
120 m_refCount++; //prevent second d'tor call
123 uno::Reference<uno::XInterface> const xInt(static_cast<
124 cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
125 lang::EventObject aEvent(xInt);
126 m_SelChangedListeners.disposeAndClear(aEvent);
129 m_refCount--;
130 m_pView = 0;
133 Sequence< uno::Type > SAL_CALL SwXTextView::getTypes( ) throw(uno::RuntimeException)
135 uno::Sequence< uno::Type > aBaseTypes = SfxBaseController::getTypes();
137 long nIndex = aBaseTypes.getLength();
138 aBaseTypes.realloc(
139 aBaseTypes.getLength() + 8 );
141 uno::Type* pBaseTypes = aBaseTypes.getArray();
142 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XSelectionSupplier >*)0);
143 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XServiceInfo >*)0);
144 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XFormLayerAccess >*)0);
145 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XTextViewCursorSupplier>*)0);
146 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XViewSettingsSupplier >*)0);
147 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XRubySelection >*)0);
148 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XPropertySet >*)0);
149 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<datatransfer::XTransferableSupplier >*)0);
150 return aBaseTypes;
153 namespace
155 class theSwXTextViewImplementationId : public rtl::Static< UnoTunnelIdInit, theSwXTextViewImplementationId > {};
158 Sequence< sal_Int8 > SAL_CALL SwXTextView::getImplementationId( ) throw(uno::RuntimeException)
160 return theSwXTextViewImplementationId::get().getSeq();
163 void SAL_CALL SwXTextView::acquire( )throw()
165 SfxBaseController::acquire();
168 void SAL_CALL SwXTextView::release( )throw()
170 SfxBaseController::release();
173 uno::Any SAL_CALL SwXTextView::queryInterface( const uno::Type& aType )
174 throw (RuntimeException)
176 uno::Any aRet;
177 if(aType == ::getCppuType((uno::Reference<view::XSelectionSupplier >*)0))
179 uno::Reference<view::XSelectionSupplier> xRet = this;
180 aRet.setValue(&xRet, aType);
182 else if(aType == ::getCppuType((uno::Reference<lang::XServiceInfo >*)0))
184 uno::Reference<lang::XServiceInfo> xRet = this;
185 aRet.setValue(&xRet, aType);
187 else if(aType == ::getCppuType((uno::Reference<view::XControlAccess >*)0))
189 uno::Reference<view::XControlAccess> xRet = this;
190 aRet.setValue(&xRet, aType);
192 else if(aType == ::getCppuType((uno::Reference<view::XFormLayerAccess >*)0))
194 uno::Reference<view::XFormLayerAccess> xRet = this;
195 aRet.setValue(&xRet, aType);
197 else if(aType == ::getCppuType((uno::Reference<text::XTextViewCursorSupplier>*)0))
199 uno::Reference<text::XTextViewCursorSupplier> xRet = this;
200 aRet.setValue(&xRet, aType);
202 else if(aType == ::getCppuType((uno::Reference<view::XViewSettingsSupplier >*)0))
204 uno::Reference<view::XViewSettingsSupplier> xRet = this;
205 aRet.setValue(&xRet, aType);
207 else if(aType == ::getCppuType((uno::Reference<XRubySelection>*)0))
209 uno::Reference<XRubySelection> xRet = this;
210 aRet.setValue(&xRet, aType);
212 else if(aType == ::getCppuType((uno::Reference<XPropertySet>*)0))
214 uno::Reference<XPropertySet> xRet = this;
215 aRet.setValue(&xRet, aType);
217 else if(aType == ::getCppuType((uno::Reference<datatransfer::XTransferableSupplier >*)0))
219 uno::Reference<datatransfer::XTransferableSupplier> xRet = this;
220 aRet.setValue(&xRet, aType);
222 else
223 aRet = SfxBaseController::queryInterface(aType);
224 return aRet;
227 sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArgumentException, uno::RuntimeException )
229 SolarMutexGuard aGuard;
231 uno::Reference< uno::XInterface > xInterface;
232 if (!GetView() || !(aInterface >>= xInterface))
234 return sal_False;
237 SwWrtShell& rSh = GetView()->GetWrtShell();
238 SwDoc* pDoc = GetView()->GetDocShell()->GetDoc();
239 std::vector<SdrObject *> sdrObjects;
240 uno::Reference<awt::XControlModel> const xCtrlModel(xInterface,
241 UNO_QUERY);
242 if (xCtrlModel.is())
244 uno::Reference<awt::XControl> xControl;
245 SdrObject *const pSdrObject = GetControl(xCtrlModel, xControl);
246 if (pSdrObject) // hmm... needs view to verify it's in right doc...
248 sdrObjects.push_back(pSdrObject);
251 else
253 SwPaM * pPaM(0);
254 std::pair<OUString, FlyCntType> frame;
255 OUString tableName;
256 SwUnoTableCrsr const* pTableCursor(0);
257 ::sw::mark::IMark const* pMark(0);
258 SwUnoCursorHelper::GetSelectableFromAny(xInterface, *pDoc,
259 pPaM, frame, tableName, pTableCursor, pMark, sdrObjects);
260 if (pPaM)
262 rSh.EnterStdMode();
263 rSh.SetSelection(*pPaM);
264 // the pPaM has been copied - delete it
265 while (pPaM->GetNext() != pPaM)
266 delete pPaM->GetNext();
267 delete pPaM;
268 return sal_True;
270 else if (!frame.first.isEmpty())
272 bool const bSuccess(rSh.GotoFly(frame.first, frame.second));
273 if (bSuccess)
275 rSh.HideCrsr();
276 rSh.EnterSelFrmMode();
278 return sal_True;
280 else if (!tableName.isEmpty())
282 rSh.EnterStdMode();
283 rSh.GotoTable(tableName);
284 return sal_True;
286 else if (pTableCursor)
288 UnoActionRemoveContext const aContext(pDoc);
289 rSh.EnterStdMode();
290 rSh.SetSelection(*pTableCursor);
291 return sal_True;
293 else if (pMark)
295 rSh.EnterStdMode();
296 rSh.GotoMark(pMark);
297 return sal_True;
299 // sdrObjects handled below
301 sal_Bool bRet(sal_False);
302 if (sdrObjects.size())
305 SdrView *const pDrawView = rSh.GetDrawView();
306 SdrPageView *const pPV = pDrawView->GetSdrPageView();
308 pDrawView->SdrEndTextEdit();
309 pDrawView->UnmarkAll();
311 for (size_t i = 0; i < sdrObjects.size(); ++i)
313 SdrObject *const pSdrObject(sdrObjects[i]);
314 // GetSelectableFromAny did not check pSdrObject is in right doc!
315 if (pPV && pSdrObject->GetPage() == pPV->GetPage())
317 pDrawView->MarkObj(pSdrObject, pPV);
318 bRet = sal_True;
322 return bRet;
325 uno::Any SwXTextView::getSelection(void) throw( uno::RuntimeException )
327 SolarMutexGuard aGuard;
328 uno::Reference< uno::XInterface > aRef;
329 if(GetView())
331 //force immediat shell update
332 m_pView->StopShellTimer();
333 //Generating an interface from the current selection.
334 SwWrtShell& rSh = m_pView->GetWrtShell();
335 ShellModes eSelMode = m_pView->GetShellMode();
336 switch(eSelMode)
338 case SHELL_MODE_TABLE_TEXT :
340 if(rSh.GetTableCrsr())
342 OSL_ENSURE(rSh.GetTableFmt(), "not a table format?");
343 uno::Reference< text::XTextTableCursor > xCrsr = new SwXTextTableCursor(*rSh.GetTableFmt(),
344 rSh.GetTableCrsr());
345 aRef = uno::Reference< uno::XInterface > (xCrsr, uno::UNO_QUERY);
346 break;
350 //Without a table selection the text will be delivered.
351 //break;
352 case SHELL_MODE_LIST_TEXT :
353 case SHELL_MODE_TABLE_LIST_TEXT:
354 case SHELL_MODE_TEXT :
356 uno::Reference< container::XIndexAccess > xPos = new SwXTextRanges(rSh.GetCrsr());
357 aRef = uno::Reference< uno::XInterface >(xPos, uno::UNO_QUERY);
359 break;
360 case SHELL_MODE_FRAME :
361 case SHELL_MODE_GRAPHIC :
362 case SHELL_MODE_OBJECT :
364 //Get FlyFrameFormat; for UI-Macro connection to flys
365 const SwFrmFmt* pFmt = rSh.GetFlyFrmFmt();
366 if (pFmt)
368 SwXFrame* pxFrame = SwIterator<SwXFrame,SwFmt>::FirstElement(*pFmt);
369 if(pxFrame) //The only common interface for all frames.
371 aRef = uno::Reference< uno::XInterface >((cppu::OWeakObject*)pxFrame, uno::UNO_QUERY);
373 else
375 if(SHELL_MODE_FRAME == eSelMode)
377 uno::Reference< text::XTextFrame > xFrm = new SwXTextFrame((SwFrmFmt&)*pFmt);
378 aRef = uno::Reference< uno::XInterface >(xFrm, uno::UNO_QUERY);
380 else if(SHELL_MODE_GRAPHIC == eSelMode)
382 uno::Reference< text::XTextContent > xFrm = new SwXTextGraphicObject((SwFrmFmt&)*pFmt);
383 aRef = xFrm;
385 else
387 uno::Reference< text::XTextContent > xFrm = new SwXTextEmbeddedObject((SwFrmFmt&)*pFmt);
388 aRef = xFrm;
393 break;
394 case SHELL_MODE_DRAW :
395 case SHELL_MODE_DRAW_CTRL :
396 case SHELL_MODE_DRAW_FORM :
397 case SHELL_MODE_DRAWTEXT :
398 case SHELL_MODE_BEZIER :
400 uno::Reference< drawing::XDrawPageSupplier > xPageSupp;
401 uno::Reference< frame::XModel > xModel = m_pView->GetDocShell()->GetBaseModel();
402 uno::Reference< lang::XUnoTunnel > xModelTunnel(xModel, uno::UNO_QUERY);
403 SwXTextDocument* pTextDoc = reinterpret_cast<SwXTextDocument*>(xModelTunnel->
404 getSomething(SwXTextDocument::getUnoTunnelId()));
406 SwFmDrawPage* pSvxDrawPage = pTextDoc->GetDrawPage()->GetSvxPage();
407 uno::Reference< drawing::XShapes > xShCol = new SvxShapeCollection();
409 const SdrMarkList& rMarkList = rSh.GetDrawView()->GetMarkedObjectList();
410 for(sal_uInt16 i = 0; i < rMarkList.GetMarkCount(); i++)
412 SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
413 uno::Reference< uno::XInterface > xInt = pSvxDrawPage->GetInterface( pObj );
414 uno::Reference< drawing::XShape > xShape(xInt, uno::UNO_QUERY);
415 xShCol->add(xShape);
417 aRef = uno::Reference< uno::XInterface >(xShCol, uno::UNO_QUERY);
419 break;
420 default:;//prevent warning
423 uno::Any aRet(&aRef, ::getCppuType((uno::Reference<uno::XInterface>*)0));
424 return aRet;
427 void SwXTextView::addSelectionChangeListener(
428 const uno::Reference< view::XSelectionChangeListener > & rxListener)
429 throw( uno::RuntimeException )
431 SolarMutexGuard aGuard;
432 m_SelChangedListeners.addInterface(rxListener);
435 void SwXTextView::removeSelectionChangeListener(
436 const uno::Reference< view::XSelectionChangeListener > & rxListener)
437 throw( uno::RuntimeException )
439 SolarMutexGuard aGuard;
440 m_SelChangedListeners.removeInterface(rxListener);
443 SdrObject* SwXTextView::GetControl(
444 const uno::Reference< awt::XControlModel > & xModel,
445 uno::Reference< awt::XControl >& xToFill )
447 SwView* pView2 = GetView();
448 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
449 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : NULL;
450 Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : NULL;
452 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::GetControl: how could I?" );
454 SdrObject* pControl = NULL;
455 if ( pFormShell && pDrawView && pWindow )
456 pControl = pFormShell->GetFormControl( xModel, *pDrawView, *pWindow, xToFill );
457 return pControl;
460 uno::Reference< awt::XControl > SwXTextView::getControl(const uno::Reference< awt::XControlModel > & xModel)
461 throw( container::NoSuchElementException, uno::RuntimeException )
463 SolarMutexGuard aGuard;
464 uno::Reference< awt::XControl > xRet;
465 GetControl(xModel, xRet);
466 return xRet;
469 uno::Reference< form::runtime::XFormController > SAL_CALL SwXTextView::getFormController( const uno::Reference< form::XForm >& _Form ) throw (RuntimeException)
471 SolarMutexGuard aGuard;
473 SwView* pView2 = GetView();
474 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
475 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : NULL;
476 Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : NULL;
477 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::getFormController: how could I?" );
479 uno::Reference< form::runtime::XFormController > xController;
480 if ( pFormShell && pDrawView && pWindow )
481 xController = pFormShell->GetFormController( _Form, *pDrawView, *pWindow );
482 return xController;
485 ::sal_Bool SAL_CALL SwXTextView::isFormDesignMode( ) throw (uno::RuntimeException)
487 SolarMutexGuard aGuard;
488 SwView* pView2 = GetView();
489 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
490 return pFormShell ? pFormShell->IsDesignMode() : sal_True;
493 void SAL_CALL SwXTextView::setFormDesignMode( ::sal_Bool _DesignMode ) throw (RuntimeException)
495 SolarMutexGuard aGuard;
496 SwView* pView2 = GetView();
497 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
498 if ( pFormShell )
499 pFormShell->SetDesignMode( _DesignMode );
502 uno::Reference< text::XTextViewCursor > SwXTextView::getViewCursor(void) throw( uno::RuntimeException )
504 SolarMutexGuard aGuard;
505 if(GetView())
507 if(!pxTextViewCursor)
509 ((SwXTextView*)this)->pxTextViewCursor = new uno::Reference< text::XTextViewCursor > ;
510 *pxTextViewCursor = new SwXTextViewCursor(GetView());
512 return *pxTextViewCursor;
514 else
515 throw uno::RuntimeException();
518 uno::Reference< beans::XPropertySet > SwXTextView::getViewSettings(void) throw( uno::RuntimeException )
520 SolarMutexGuard aGuard;
521 if(m_pView)
523 if(!pxViewSettings)
525 ((SwXTextView*)this)->pxViewSettings = new uno::Reference< beans::XPropertySet > ;
526 *pxViewSettings = static_cast < HelperBaseNoState * > ( new SwXViewSettings( sal_False, m_pView ) );
529 else
530 throw uno::RuntimeException();
531 return *pxViewSettings;
534 Sequence< Sequence< PropertyValue > > SwXTextView::getRubyList( sal_Bool /*bAutomatic*/ ) throw(RuntimeException)
536 SolarMutexGuard aGuard;
538 if(!GetView())
539 throw RuntimeException();
540 SwWrtShell& rSh = m_pView->GetWrtShell();
541 ShellModes eSelMode = m_pView->GetShellMode();
542 if (eSelMode != SHELL_MODE_LIST_TEXT &&
543 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
544 eSelMode != SHELL_MODE_TABLE_TEXT &&
545 eSelMode != SHELL_MODE_TEXT )
546 return Sequence< Sequence< PropertyValue > > ();
548 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
549 SwRubyList aList;
551 sal_uInt16 nCount = pDoc->FillRubyList( *rSh.GetCrsr(), aList, 0 );
552 Sequence< Sequence< PropertyValue > > aRet(nCount);
553 Sequence< PropertyValue >* pRet = aRet.getArray();
554 String aString;
555 for(sal_uInt16 n = 0; n < nCount; n++)
557 const SwRubyListEntry* pEntry = &aList[n];
559 const String& rEntryText = pEntry->GetText();
560 const SwFmtRuby& rAttr = pEntry->GetRubyAttr();
562 pRet[n].realloc(5);
563 PropertyValue* pValues = pRet[n].getArray();
564 pValues[0].Name = OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RUBY_BASE_TEXT));
565 pValues[0].Value <<= OUString(rEntryText);
566 pValues[1].Name = OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RUBY_TEXT));
567 pValues[1].Value <<= OUString(rAttr.GetText());
568 pValues[2].Name = OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RUBY_CHAR_STYLE_NAME));
569 SwStyleNameMapper::FillProgName(rAttr.GetCharFmtName(), aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
570 pValues[2].Value <<= OUString( aString );
571 pValues[3].Name = OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RUBY_ADJUST));
572 pValues[3].Value <<= (sal_Int16)rAttr.GetAdjustment();
573 pValues[4].Name = OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_RUBY_IS_ABOVE));
574 sal_Bool bVal = !rAttr.GetPosition();
575 pValues[4].Value.setValue(&bVal, ::getBooleanCppuType());
577 return aRet;
580 void SAL_CALL SwXTextView::setRubyList(
581 const Sequence< Sequence< PropertyValue > >& rRubyList, sal_Bool /*bAutomatic*/ )
582 throw(RuntimeException)
584 SolarMutexGuard aGuard;
586 if(!GetView() || !rRubyList.getLength())
587 throw RuntimeException();
588 SwWrtShell& rSh = m_pView->GetWrtShell();
589 ShellModes eSelMode = m_pView->GetShellMode();
590 if (eSelMode != SHELL_MODE_LIST_TEXT &&
591 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
592 eSelMode != SHELL_MODE_TABLE_TEXT &&
593 eSelMode != SHELL_MODE_TEXT )
594 throw RuntimeException();
596 SwRubyList aList;
598 const Sequence<PropertyValue>* pRubyList = rRubyList.getConstArray();
599 for(sal_Int32 nPos = 0; nPos < rRubyList.getLength(); nPos++)
601 SwRubyListEntry* pEntry = new SwRubyListEntry;
602 const PropertyValue* pProperties = pRubyList[nPos].getConstArray();
603 OUString sTmp;
604 for(sal_Int32 nProp = 0; nProp < pRubyList[nPos].getLength(); nProp++)
606 if(pProperties[nProp].Name.equalsAsciiL(
607 SW_PROP_NAME(UNO_NAME_RUBY_BASE_TEXT)))
609 pProperties[nProp].Value >>= sTmp;
610 pEntry->SetText(sTmp);
612 else if(pProperties[nProp].Name.equalsAsciiL(
613 SW_PROP_NAME(UNO_NAME_RUBY_TEXT)))
615 pProperties[nProp].Value >>= sTmp;
616 pEntry->GetRubyAttr().SetText(sTmp);
618 else if(pProperties[nProp].Name.equalsAsciiL(
619 SW_PROP_NAME(UNO_NAME_RUBY_CHAR_STYLE_NAME)))
621 if((pProperties[nProp].Value >>= sTmp))
623 String sName;
624 SwStyleNameMapper::FillUIName(sTmp, sName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
625 sal_uInt16 nPoolId = sName.Len() ?
626 SwStyleNameMapper::GetPoolIdFromUIName( sName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ) : 0;
628 pEntry->GetRubyAttr().SetCharFmtName( sName );
629 pEntry->GetRubyAttr().SetCharFmtId( nPoolId );
632 else if(pProperties[nProp].Name.equalsAsciiL(
633 SW_PROP_NAME(UNO_NAME_RUBY_ADJUST)))
635 sal_Int16 nTmp = 0;
636 if((pProperties[nProp].Value >>= nTmp))
637 pEntry->GetRubyAttr().SetAdjustment(nTmp);
639 else if(pProperties[nProp].Name.equalsAsciiL(
640 SW_PROP_NAME(UNO_NAME_RUBY_IS_ABOVE)))
642 sal_Bool bValue = pProperties[nProp].Value.hasValue() ?
643 *(sal_Bool*)pProperties[nProp].Value.getValue() : sal_True;
644 pEntry->GetRubyAttr().SetPosition(bValue ? 0 : 1);
647 aList.insert(aList.begin() + nPos, pEntry);
649 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
650 pDoc->SetRubyList( *rSh.GetCrsr(), aList, 0 );
653 SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc()
655 SwWrtShell& rOldSh = m_pView->GetWrtShell();
656 SfxPrinter *pPrt = rOldSh.getIDocumentDeviceAccess()->getPrinter( false );
657 SwDocShell* pDocSh;
658 SfxObjectShellLock xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) );
659 xDocSh->DoInitNew( 0 );
660 SwDoc *const pTempDoc( pDocSh->GetDoc() );
661 // #i103634#, #i112425#: do not expand numbering and fields on PDF export
662 pTempDoc->SetClipBoard(true);
663 rOldSh.FillPrtDoc(pTempDoc, pPrt);
664 SfxViewFrame* pDocFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
665 SwView* pDocView = (SwView*) pDocFrame->GetViewShell();
666 pDocView->AttrChangedNotify( &pDocView->GetWrtShell() );//So that SelectShell is called.
667 SwWrtShell* pSh = pDocView->GetWrtShellPtr();
669 IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
670 SfxPrinter* pTempPrinter = pIDDA->getPrinter( true );
672 const SwPageDesc& rCurPageDesc = rOldSh.GetPageDesc(rOldSh.GetCurPageDesc());
674 IDocumentDeviceAccess* pIDDA_old = rOldSh.getIDocumentDeviceAccess();
676 if( pIDDA_old->getPrinter( false ) )
678 pIDDA->setJobsetup( *pIDDA_old->getJobsetup() );
679 //#69563# if it isn't the same printer then the pointer has been invalidated!
680 pTempPrinter = pIDDA->getPrinter( true );
683 pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
685 return xDocSh;
688 void SwXTextView::NotifySelChanged()
690 OSL_ENSURE( m_pView, "view is missing" );
692 uno::Reference<uno::XInterface> const xInt(
693 static_cast<cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
695 lang::EventObject const aEvent(xInt);
696 m_SelChangedListeners.notifyEach(
697 &view::XSelectionChangeListener::selectionChanged, aEvent);
700 namespace {
701 struct DispatchListener
703 URL const & m_rURL;
704 Sequence<PropertyValue> const& m_rSeq;
705 explicit DispatchListener(URL const& rURL,
706 Sequence<PropertyValue> const& rSeq)
707 : m_rURL(rURL), m_rSeq(rSeq) { }
708 void operator()(uno::Reference<XDispatch> const & xListener) const
710 xListener->dispatch(m_rURL, m_rSeq);
715 void SwXTextView::NotifyDBChanged()
717 URL aURL;
718 aURL.Complete = OUString::createFromAscii(SwXDispatch::GetDBChangeURL());
720 m_SelChangedListeners.forEach<XDispatch>(
721 DispatchListener(aURL, Sequence<PropertyValue>(0)));
724 uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXTextView::getPropertySetInfo( )
725 throw (uno::RuntimeException)
727 SolarMutexGuard aGuard;
728 static uno::Reference< XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo();
729 return aRef;
732 void SAL_CALL SwXTextView::setPropertyValue(
733 const OUString& rPropertyName, const uno::Any& rValue )
734 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
736 SolarMutexGuard aGuard;
737 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
738 if (!pEntry)
739 throw UnknownPropertyException();
740 else if (pEntry->nFlags & PropertyAttribute::READONLY)
741 throw PropertyVetoException();
742 else
744 switch (pEntry->nWID)
746 case WID_IS_HIDE_SPELL_MARKS :
747 // deprecated #i91949
748 break;
749 case WID_IS_CONSTANT_SPELLCHECK :
751 sal_Bool bVal = sal_False;
752 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
753 if (!pOpt || !(rValue >>= bVal))
754 throw RuntimeException();
755 SwViewOption aNewOpt( *pOpt );
756 if (pEntry->nWID == WID_IS_CONSTANT_SPELLCHECK)
757 aNewOpt.SetOnlineSpell(bVal);
758 m_pView->GetWrtShell().ApplyViewOptions( aNewOpt );
760 break;
761 default :
762 OSL_FAIL("unknown WID");
767 uno::Any SAL_CALL SwXTextView::getPropertyValue(
768 const OUString& rPropertyName )
769 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
771 SolarMutexGuard aGuard;
773 Any aRet;
775 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
776 if (!pEntry)
777 throw UnknownPropertyException();
778 else
780 sal_Int16 nWID = pEntry->nWID;
781 switch (nWID)
783 case WID_PAGE_COUNT :
784 case WID_LINE_COUNT :
786 // format document completely in order to get meaningful
787 // values for page count and line count
788 m_pView->GetWrtShell().CalcLayout();
790 sal_Int32 nCount = -1;
791 if (nWID == WID_PAGE_COUNT)
792 nCount = m_pView->GetWrtShell().GetPageCount();
793 else // WID_LINE_COUNT
794 nCount = m_pView->GetWrtShell().GetLineCount( sal_False /*of whole document*/ );
795 aRet <<= nCount;
797 break;
798 case WID_IS_HIDE_SPELL_MARKS :
799 // deprecated #i91949
800 break;
801 case WID_IS_CONSTANT_SPELLCHECK :
803 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
804 if (!pOpt)
805 throw RuntimeException();
806 sal_uInt32 nFlag = VIEWOPT_1_ONLINESPELL;
807 sal_Bool bVal = 0 != (pOpt->GetCoreOptions() & nFlag);
808 aRet <<= bVal;
810 break;
811 default :
812 OSL_FAIL("unknown WID");
816 return aRet;
819 void SAL_CALL SwXTextView::addPropertyChangeListener(
820 const OUString& /*rPropertyName*/,
821 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
822 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
824 OSL_FAIL("not implemented");
827 void SAL_CALL SwXTextView::removePropertyChangeListener(
828 const OUString& /*rPropertyName*/,
829 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
830 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
832 OSL_FAIL("not implemented");
835 void SAL_CALL SwXTextView::addVetoableChangeListener(
836 const OUString& /*rPropertyName*/,
837 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
838 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
840 OSL_FAIL("not implemented");
843 void SAL_CALL SwXTextView::removeVetoableChangeListener(
844 const OUString& /*rPropertyName*/,
845 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
846 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
848 OSL_FAIL("not implemented");
851 OUString SwXTextView::getImplementationName(void) throw( RuntimeException )
853 return OUString("SwXTextView");
856 sal_Bool SwXTextView::supportsService(const OUString& rServiceName) throw( RuntimeException )
858 return rServiceName == "com.sun.star.text.TextDocumentView" || rServiceName == "com.sun.star.view.OfficeDocumentView";
861 Sequence< OUString > SwXTextView::getSupportedServiceNames(void) throw( RuntimeException )
863 Sequence< OUString > aRet(2);
864 OUString* pArray = aRet.getArray();
865 pArray[0] = "com.sun.star.text.TextDocumentView";
866 pArray[1] = "com.sun.star.view.OfficeDocumentView";
867 return aRet;
870 SwXTextViewCursor::SwXTextViewCursor(SwView* pVw) :
871 m_pView(pVw),
872 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
876 SwXTextViewCursor::~SwXTextViewCursor()
880 // used to determine if there is a text selction or not.
881 // If there is no text selection the functions that need a working
882 // cursor will be disabled (throw RuntimeException). This will be the case
883 // for the following interfaces:
884 // - XViewCursor
885 // - XTextCursor
886 // - XTextRange
887 // - XLineCursor
888 sal_Bool SwXTextViewCursor::IsTextSelection( sal_Bool bAllowTables ) const
891 sal_Bool bRes = sal_False;
892 OSL_ENSURE(m_pView, "m_pView is NULL ???");
893 if(m_pView)
895 //! m_pView->GetShellMode() will only work after the shell
896 //! has already changed and thus can not be used here!
897 SelectionType eSelType = m_pView->GetWrtShell().GetSelectionType();
898 bRes = ( (nsSelectionType::SEL_TXT & eSelType) ||
899 (nsSelectionType::SEL_NUM & eSelType) ) &&
900 (!(nsSelectionType::SEL_TBL_CELLS & eSelType) || bAllowTables);
902 return bRes;
905 sal_Bool SwXTextViewCursor::isVisible(void) throw( uno::RuntimeException )
907 SolarMutexGuard aGuard;
908 OSL_FAIL("not implemented");
909 return sal_True;
912 void SwXTextViewCursor::setVisible(sal_Bool /*bVisible*/) throw( uno::RuntimeException )
914 SolarMutexGuard aGuard;
915 OSL_FAIL("not implemented");
918 awt::Point SwXTextViewCursor::getPosition(void) throw( uno::RuntimeException )
920 SolarMutexGuard aGuard;
921 awt::Point aRet;
922 if(m_pView)
924 const SwWrtShell& rSh = m_pView->GetWrtShell();
925 const SwRect aCharRect(rSh.GetCharRect());
927 const SwFrmFmt& rMaster = rSh.GetPageDesc( rSh.GetCurPageDesc() ).GetMaster();
929 const SvxULSpaceItem& rUL = rMaster.GetULSpace();
930 const long nY = aCharRect.Top() - (rUL.GetUpper() + DOCUMENTBORDER);
931 aRet.Y = TWIP_TO_MM100(nY);
933 const SvxLRSpaceItem& rLR = rMaster.GetLRSpace();
934 const long nX = aCharRect.Left() - (rLR.GetLeft() + DOCUMENTBORDER);
935 aRet.X = TWIP_TO_MM100(nX);
937 else
938 throw uno::RuntimeException();
939 return aRet;
942 void SwXTextViewCursor::collapseToStart(void) throw( uno::RuntimeException )
944 SolarMutexGuard aGuard;
945 if(m_pView)
947 if (!IsTextSelection())
948 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
950 SwWrtShell& rSh = m_pView->GetWrtShell();
951 if(rSh.HasSelection())
953 SwPaM* pShellCrsr = rSh.GetCrsr();
954 if(*pShellCrsr->GetPoint() > *pShellCrsr->GetMark())
955 pShellCrsr->Exchange();
956 pShellCrsr->DeleteMark();
957 rSh.EnterStdMode();
958 rSh.SetSelection(*pShellCrsr);
961 else
962 throw uno::RuntimeException();
965 void SwXTextViewCursor::collapseToEnd(void) throw( uno::RuntimeException )
967 SolarMutexGuard aGuard;
968 if(m_pView)
970 if (!IsTextSelection())
971 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
973 SwWrtShell& rSh = m_pView->GetWrtShell();
974 if(rSh.HasSelection())
976 SwPaM* pShellCrsr = rSh.GetCrsr();
977 if(*pShellCrsr->GetPoint() < *pShellCrsr->GetMark())
978 pShellCrsr->Exchange();
979 pShellCrsr->DeleteMark();
980 rSh.EnterStdMode();
981 rSh.SetSelection(*pShellCrsr);
984 else
985 throw uno::RuntimeException();
988 sal_Bool SwXTextViewCursor::isCollapsed(void) throw( uno::RuntimeException )
990 SolarMutexGuard aGuard;
991 sal_Bool bRet = sal_False;
992 if(m_pView)
994 if (!IsTextSelection())
995 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
997 const SwWrtShell& rSh = m_pView->GetWrtShell();
998 bRet = !rSh.HasSelection();
1000 else
1001 throw uno::RuntimeException();
1002 return bRet;
1006 sal_Bool SwXTextViewCursor::goLeft(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1008 SolarMutexGuard aGuard;
1009 sal_Bool bRet = sal_False;
1010 if(m_pView)
1012 if (!IsTextSelection())
1013 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1015 for( sal_uInt16 i = 0; i < nCount; i++ )
1016 bRet = m_pView->GetWrtShell().Left( CRSR_SKIP_CHARS, bExpand, 1, sal_True );
1018 else
1019 throw uno::RuntimeException();
1020 return bRet;
1023 sal_Bool SwXTextViewCursor::goRight(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1025 SolarMutexGuard aGuard;
1026 sal_Bool bRet = sal_False;
1027 if(m_pView)
1029 if (!IsTextSelection())
1030 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1032 for( sal_uInt16 i = 0; i < nCount; i++ )
1033 bRet = m_pView->GetWrtShell().Right( CRSR_SKIP_CHARS, bExpand, 1, sal_True );
1035 else
1036 throw uno::RuntimeException();
1037 return bRet;
1041 void SwXTextViewCursor::gotoRange(
1042 const uno::Reference< text::XTextRange > & xRange,
1043 sal_Bool bExpand)
1044 throw(RuntimeException)
1046 SolarMutexGuard aGuard;
1047 if(m_pView && xRange.is())
1049 if (!IsTextSelection())
1050 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1052 SwUnoInternalPaM rDestPam(*m_pView->GetDocShell()->GetDoc());
1053 if (!::sw::XTextRangeToSwPaM(rDestPam, xRange))
1055 throw uno::RuntimeException();
1058 ShellModes eSelMode = m_pView->GetShellMode();
1059 SwWrtShell& rSh = m_pView->GetWrtShell();
1060 // call EnterStdMode in non-text selections only
1061 if(!bExpand ||
1062 (eSelMode != SHELL_MODE_TABLE_TEXT &&
1063 eSelMode != SHELL_MODE_LIST_TEXT &&
1064 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
1065 eSelMode != SHELL_MODE_TEXT ))
1066 rSh.EnterStdMode();
1067 SwPaM* pShellCrsr = rSh.GetCrsr();
1068 SwPaM aOwnPaM(*pShellCrsr->GetPoint());
1069 if(pShellCrsr->HasMark())
1071 aOwnPaM.SetMark();
1072 *aOwnPaM.GetMark() = *pShellCrsr->GetMark();
1075 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
1076 SwXTextRange* pRange = 0;
1077 SwXParagraph* pPara = 0;
1078 OTextCursorHelper* pCursor = 0;
1079 if(xRangeTunnel.is())
1081 pRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething(
1082 SwXTextRange::getUnoTunnelId()));
1083 pCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething(
1084 OTextCursorHelper::getUnoTunnelId()));
1085 pPara = reinterpret_cast<SwXParagraph*>(xRangeTunnel->getSomething(
1086 SwXParagraph::getUnoTunnelId()));
1089 const sal_uInt16 nFrmType = rSh.GetFrmType(0,sal_True);
1091 SwStartNodeType eSearchNodeType = SwNormalStartNode;
1092 if(nFrmType & FRMTYPE_FLY_ANY)
1093 eSearchNodeType = SwFlyStartNode;
1094 else if(nFrmType &FRMTYPE_HEADER)
1095 eSearchNodeType = SwHeaderStartNode;
1096 else if(nFrmType & FRMTYPE_FOOTER)
1097 eSearchNodeType = SwFooterStartNode;
1098 else if(nFrmType & FRMTYPE_TABLE)
1099 eSearchNodeType = SwTableBoxStartNode;
1100 else if(nFrmType & FRMTYPE_FOOTNOTE)
1101 eSearchNodeType = SwFootnoteStartNode;
1103 const SwStartNode* pOwnStartNode = aOwnPaM.GetNode()->
1104 FindSttNodeByType(eSearchNodeType);
1106 const SwNode* pSrcNode = 0;
1107 if(pCursor && pCursor->GetPaM())
1109 pSrcNode = pCursor->GetPaM()->GetNode();
1111 else if (pRange)
1113 SwPaM aPam(pRange->GetDoc()->GetNodes());
1114 if (pRange->GetPositions(aPam))
1116 pSrcNode = aPam.GetNode();
1119 else if (pPara && pPara->GetTxtNode())
1121 pSrcNode = pPara->GetTxtNode();
1123 const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindSttNodeByType(eSearchNodeType) : 0;
1125 //Skip SectionNodes
1126 while(pTmp && pTmp->IsSectionNode())
1128 pTmp = pTmp->StartOfSectionNode();
1130 while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1132 pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1134 //Without Expand it is allowed to jump out with the ViewCursor everywhere,
1135 //with Expand only in the same environment
1136 if(bExpand &&
1137 (pOwnStartNode != pTmp ||
1138 (eSelMode != SHELL_MODE_TABLE_TEXT &&
1139 eSelMode != SHELL_MODE_LIST_TEXT &&
1140 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
1141 eSelMode != SHELL_MODE_TEXT)))
1142 throw uno::RuntimeException();
1144 //Now, the selection must be expanded.
1145 if(bExpand)
1147 // The cursor should include everything that has been included
1148 // by him and the transfered Range.
1149 SwPosition aOwnLeft(*aOwnPaM.Start());
1150 SwPosition aOwnRight(*aOwnPaM.End());
1151 SwPosition* pParamLeft = rDestPam.Start();
1152 SwPosition* pParamRight = rDestPam.End();
1153 // Now four SwPositions are there, two of them are needed, but which?
1154 if(aOwnRight > *pParamRight)
1155 *aOwnPaM.GetPoint() = aOwnRight;
1156 else
1157 *aOwnPaM.GetPoint() = *pParamRight;
1158 aOwnPaM.SetMark();
1159 if(aOwnLeft < *pParamLeft)
1160 *aOwnPaM.GetMark() = aOwnLeft;
1161 else
1162 *aOwnPaM.GetMark() = *pParamLeft;
1164 else
1166 //The cursor shall match the passed range.
1167 *aOwnPaM.GetPoint() = *rDestPam.GetPoint();
1168 if(rDestPam.HasMark())
1170 aOwnPaM.SetMark();
1171 *aOwnPaM.GetMark() = *rDestPam.GetMark();
1173 else
1174 aOwnPaM.DeleteMark();
1176 rSh.SetSelection(aOwnPaM);
1178 else
1179 throw uno::RuntimeException();
1183 void SwXTextViewCursor::gotoStart(sal_Bool bExpand) throw( uno::RuntimeException )
1185 SolarMutexGuard aGuard;
1186 if(m_pView)
1188 if (!IsTextSelection())
1189 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1191 m_pView->GetWrtShell().SttDoc( bExpand );
1193 else
1194 throw uno::RuntimeException();
1197 void SwXTextViewCursor::gotoEnd(sal_Bool bExpand) throw( uno::RuntimeException )
1199 SolarMutexGuard aGuard;
1200 if(m_pView)
1202 if (!IsTextSelection())
1203 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1205 m_pView->GetWrtShell().EndDoc( bExpand );
1207 else
1208 throw uno::RuntimeException();
1211 sal_Bool SwXTextViewCursor::jumpToFirstPage(void) throw( uno::RuntimeException )
1213 SolarMutexGuard aGuard;
1214 sal_Bool bRet = sal_False;
1215 if(m_pView)
1217 SwWrtShell& rSh = m_pView->GetWrtShell();
1218 if (rSh.IsSelFrmMode())
1220 rSh.UnSelectFrm();
1221 rSh.LeaveSelFrmMode();
1223 rSh.EnterStdMode();
1224 bRet = rSh.SttEndDoc(sal_True);
1226 else
1227 throw uno::RuntimeException();
1228 return bRet;
1231 sal_Bool SwXTextViewCursor::jumpToLastPage(void) throw( uno::RuntimeException )
1233 SolarMutexGuard aGuard;
1234 sal_Bool bRet = sal_False;
1235 if(m_pView)
1237 SwWrtShell& rSh = m_pView->GetWrtShell();
1238 if (rSh.IsSelFrmMode())
1240 rSh.UnSelectFrm();
1241 rSh.LeaveSelFrmMode();
1243 rSh.EnterStdMode();
1244 bRet = rSh.SttEndDoc(sal_False);
1245 rSh.SttPg();
1247 else
1248 throw uno::RuntimeException();
1249 return bRet;
1252 sal_Bool SwXTextViewCursor::jumpToPage(sal_Int16 nPage) throw( uno::RuntimeException )
1254 SolarMutexGuard aGuard;
1255 sal_Bool bRet = sal_False;
1256 if(m_pView)
1257 bRet = m_pView->GetWrtShell().GotoPage(nPage, sal_True);
1258 else
1259 throw uno::RuntimeException();
1260 return bRet;
1263 sal_Bool SwXTextViewCursor::jumpToNextPage(void) throw( uno::RuntimeException )
1265 SolarMutexGuard aGuard;
1266 sal_Bool bRet = sal_False;
1267 if(m_pView)
1268 bRet = m_pView->GetWrtShell().SttNxtPg();
1269 else
1270 throw uno::RuntimeException();
1271 return bRet;
1274 sal_Bool SwXTextViewCursor::jumpToPreviousPage(void) throw( uno::RuntimeException )
1276 SolarMutexGuard aGuard;
1277 sal_Bool bRet = sal_False;
1278 if(m_pView)
1279 bRet = m_pView->GetWrtShell().EndPrvPg();
1280 else
1281 throw uno::RuntimeException();
1282 return bRet;
1285 sal_Bool SwXTextViewCursor::jumpToEndOfPage(void) throw( uno::RuntimeException )
1287 SolarMutexGuard aGuard;
1288 sal_Bool bRet = sal_False;
1289 if(m_pView)
1290 bRet = m_pView->GetWrtShell().EndPg();
1291 else
1292 throw uno::RuntimeException();
1293 return bRet;
1296 sal_Bool SwXTextViewCursor::jumpToStartOfPage(void) throw( uno::RuntimeException )
1298 SolarMutexGuard aGuard;
1299 sal_Bool bRet = sal_False;
1300 if(m_pView)
1301 bRet = m_pView->GetWrtShell().SttPg();
1302 else
1303 throw uno::RuntimeException();
1304 return bRet;
1307 sal_Int16 SwXTextViewCursor::getPage(void) throw( uno::RuntimeException )
1309 SolarMutexGuard aGuard;
1310 short nRet = 0;
1311 if(m_pView)
1313 SwWrtShell& rSh = m_pView->GetWrtShell();
1314 SwPaM* pShellCrsr = rSh.GetCrsr();
1315 nRet = (short)pShellCrsr->GetPageNum( sal_True, 0 );
1317 else
1318 throw uno::RuntimeException();
1319 return nRet;
1322 sal_Bool SwXTextViewCursor::screenDown(void) throw( uno::RuntimeException )
1324 SolarMutexGuard aGuard;
1325 sal_Bool bRet = sal_False;
1326 if(m_pView)
1328 SfxRequest aReq(FN_PAGEDOWN, SFX_CALLMODE_SLOT, m_pView->GetPool());
1329 m_pView->Execute(aReq);
1330 const SfxPoolItem* pRet = aReq.GetReturnValue();
1331 bRet = pRet && ((const SfxBoolItem*)pRet)->GetValue();
1333 else
1334 throw uno::RuntimeException();
1335 return bRet;
1338 sal_Bool SwXTextViewCursor::screenUp(void) throw( uno::RuntimeException )
1340 SolarMutexGuard aGuard;
1341 sal_Bool bRet = sal_False;
1342 if(m_pView)
1344 SfxRequest aReq(FN_PAGEUP, SFX_CALLMODE_SLOT, m_pView->GetPool());
1345 m_pView->Execute(aReq);
1346 const SfxPoolItem* pRet = aReq.GetReturnValue();
1347 bRet = pRet && ((const SfxBoolItem*)pRet)->GetValue();
1349 else
1350 throw uno::RuntimeException();
1351 return bRet;
1354 uno::Reference< text::XText > SwXTextViewCursor::getText(void) throw( uno::RuntimeException )
1356 SolarMutexGuard aGuard;
1357 uno::Reference< text::XText > xRet;
1358 if(m_pView)
1360 if (!IsTextSelection( sal_False ))
1361 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1363 SwWrtShell& rSh = m_pView->GetWrtShell();
1364 SwPaM* pShellCrsr = rSh.GetCrsr();
1365 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1366 xRet = ::sw::CreateParentXText(*pDoc, *pShellCrsr->Start());
1368 else
1369 throw uno::RuntimeException();
1370 return xRet;
1373 uno::Reference< text::XTextRange > SwXTextViewCursor::getStart(void) throw( uno::RuntimeException )
1375 SolarMutexGuard aGuard;
1376 uno::Reference< text::XTextRange > xRet;
1377 if(m_pView)
1379 if (!IsTextSelection())
1380 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1382 SwWrtShell& rSh = m_pView->GetWrtShell();
1383 SwPaM* pShellCrsr = rSh.GetCrsr();
1384 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1385 xRet = SwXTextRange::CreateXTextRange(*pDoc, *pShellCrsr->Start(), 0);
1387 else
1388 throw uno::RuntimeException();
1389 return xRet;
1392 uno::Reference< text::XTextRange > SwXTextViewCursor::getEnd(void) throw( uno::RuntimeException )
1394 SolarMutexGuard aGuard;
1395 uno::Reference< text::XTextRange > xRet;
1396 if(m_pView)
1398 if (!IsTextSelection())
1399 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1401 SwWrtShell& rSh = m_pView->GetWrtShell();
1402 SwPaM* pShellCrsr = rSh.GetCrsr();
1403 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1404 xRet = SwXTextRange::CreateXTextRange(*pDoc, *pShellCrsr->End(), 0);
1406 else
1407 throw uno::RuntimeException();
1408 return xRet;
1411 OUString SwXTextViewCursor::getString(void) throw( uno::RuntimeException )
1413 SolarMutexGuard aGuard;
1414 OUString uRet;
1415 if(m_pView)
1417 if (!IsTextSelection( sal_False ))
1418 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1420 ShellModes eSelMode = m_pView->GetShellMode();
1421 switch(eSelMode)
1423 //! since setString for SEL_TABLE_TEXT (with possible
1424 //! multi selection of cells) would not work properly we
1425 //! will ignore this case for both
1426 //! functions (setString AND getString) because of symmetrie.
1428 case SHELL_MODE_LIST_TEXT :
1429 case SHELL_MODE_TABLE_LIST_TEXT:
1430 case SHELL_MODE_TEXT :
1432 SwWrtShell& rSh = m_pView->GetWrtShell();
1433 SwPaM* pShellCrsr = rSh.GetCrsr();
1434 SwUnoCursorHelper::GetTextFromPam(*pShellCrsr, uRet);
1436 default:;//prevent warning
1439 return uRet;
1442 void SwXTextViewCursor::setString(const OUString& aString) throw( uno::RuntimeException )
1444 SolarMutexGuard aGuard;
1445 if(m_pView)
1447 if (!IsTextSelection( sal_False ))
1448 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1450 ShellModes eSelMode = m_pView->GetShellMode();
1451 switch(eSelMode)
1453 //! since setString for SEL_TABLE_TEXT (with possible
1454 //! multi selection of cells) would not work properly we
1455 //! will ignore this case for both
1456 //! functions (setString AND getString) because of symmetrie.
1458 case SHELL_MODE_LIST_TEXT :
1459 case SHELL_MODE_TABLE_LIST_TEXT :
1460 case SHELL_MODE_TEXT :
1462 SwWrtShell& rSh = m_pView->GetWrtShell();
1463 SwCursor* pShellCrsr = rSh.GetSwCrsr();
1464 SwUnoCursorHelper::SetString(*pShellCrsr, aString);
1466 default:;//prevent warning
1471 uno::Reference< XPropertySetInfo > SwXTextViewCursor::getPropertySetInfo( ) throw(RuntimeException)
1473 static uno::Reference< XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
1474 return xRef;
1477 void SwXTextViewCursor::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
1478 throw(UnknownPropertyException, PropertyVetoException,
1479 IllegalArgumentException, WrappedTargetException, RuntimeException)
1481 SolarMutexGuard aGuard;
1482 if(m_pView)
1484 SwWrtShell& rSh = m_pView->GetWrtShell();
1485 SwPaM* pShellCrsr = rSh.GetCrsr();
1486 SwNode *pNode = pShellCrsr->GetNode();
1487 if (pNode && pNode->IsTxtNode())
1489 SwUnoCursorHelper::SetPropertyValue(
1490 *pShellCrsr, *m_pPropSet, rPropertyName, aValue );
1492 else
1493 throw RuntimeException();
1495 else
1496 throw RuntimeException();
1499 Any SwXTextViewCursor::getPropertyValue( const OUString& rPropertyName )
1500 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1502 SolarMutexGuard aGuard;
1503 Any aRet;
1504 if(m_pView)
1506 SwWrtShell& rSh = m_pView->GetWrtShell();
1507 SwPaM* pShellCrsr = rSh.GetCrsr();
1508 aRet = SwUnoCursorHelper::GetPropertyValue(
1509 *pShellCrsr, *m_pPropSet, rPropertyName);
1511 else
1512 throw RuntimeException();
1513 return aRet;
1516 void SwXTextViewCursor::addPropertyChangeListener(
1517 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
1518 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1522 void SwXTextViewCursor::removePropertyChangeListener(
1523 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ )
1524 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1528 void SwXTextViewCursor::addVetoableChangeListener(
1529 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1530 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1534 void SwXTextViewCursor::removeVetoableChangeListener(
1535 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1539 PropertyState SwXTextViewCursor::getPropertyState( const OUString& rPropertyName )
1540 throw(UnknownPropertyException, RuntimeException)
1542 SolarMutexGuard aGuard;
1543 PropertyState eState;
1544 if(m_pView)
1546 SwWrtShell& rSh = m_pView->GetWrtShell();
1547 SwPaM* pShellCrsr = rSh.GetCrsr();
1548 eState = SwUnoCursorHelper::GetPropertyState(
1549 *pShellCrsr, *m_pPropSet, rPropertyName);
1551 else
1552 throw RuntimeException();
1553 return eState;
1556 Sequence< PropertyState > SwXTextViewCursor::getPropertyStates(
1557 const Sequence< OUString >& rPropertyNames ) throw(UnknownPropertyException, RuntimeException)
1559 SolarMutexGuard aGuard;
1560 Sequence< PropertyState > aRet;
1561 if(m_pView)
1563 SwWrtShell& rSh = m_pView->GetWrtShell();
1564 SwPaM* pShellCrsr = rSh.GetCrsr();
1565 aRet = SwUnoCursorHelper::GetPropertyStates(
1566 *pShellCrsr, *m_pPropSet, rPropertyNames);
1568 return aRet;
1571 void SwXTextViewCursor::setPropertyToDefault( const OUString& rPropertyName )
1572 throw(UnknownPropertyException, RuntimeException)
1574 SolarMutexGuard aGuard;
1575 if(m_pView)
1577 SwWrtShell& rSh = m_pView->GetWrtShell();
1578 SwPaM* pShellCrsr = rSh.GetCrsr();
1579 SwUnoCursorHelper::SetPropertyToDefault(
1580 *pShellCrsr, *m_pPropSet, rPropertyName);
1584 Any SwXTextViewCursor::getPropertyDefault( const OUString& rPropertyName )
1585 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1587 Any aRet;
1588 SolarMutexGuard aGuard;
1589 if(m_pView)
1591 SwWrtShell& rSh = m_pView->GetWrtShell();
1592 SwPaM* pShellCrsr = rSh.GetCrsr();
1593 aRet = SwUnoCursorHelper::GetPropertyDefault(
1594 *pShellCrsr, *m_pPropSet, rPropertyName);
1596 return aRet;
1599 sal_Bool SwXTextViewCursor::goDown(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1601 SolarMutexGuard aGuard;
1602 sal_Bool bRet = sal_False;
1603 if(m_pView)
1605 if (!IsTextSelection())
1606 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1608 for( sal_uInt16 i = 0; i < nCount; i++ )
1609 bRet = m_pView->GetWrtShell().Down( bExpand, 1, sal_True );
1611 else
1612 throw uno::RuntimeException();
1613 return bRet;
1616 sal_Bool SwXTextViewCursor::goUp(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1618 SolarMutexGuard aGuard;
1619 sal_Bool bRet = sal_False;
1620 if(m_pView)
1622 if (!IsTextSelection())
1623 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1625 for( sal_uInt16 i = 0; i < nCount; i++ )
1626 bRet = m_pView->GetWrtShell().Up( bExpand, 1, sal_True );
1628 else
1629 throw uno::RuntimeException();
1630 return bRet;
1633 sal_Bool SwXTextViewCursor::isAtStartOfLine(void) throw( uno::RuntimeException )
1635 SolarMutexGuard aGuard;
1636 sal_Bool bRet = sal_False;
1637 if(m_pView)
1639 if (!IsTextSelection( sal_False ))
1640 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1642 bRet = m_pView->GetWrtShell().IsAtLeftMargin();
1644 else
1645 throw uno::RuntimeException();
1646 return bRet;
1649 sal_Bool SwXTextViewCursor::isAtEndOfLine(void) throw( uno::RuntimeException )
1651 SolarMutexGuard aGuard;
1652 sal_Bool bRet = sal_False;
1653 if(m_pView)
1655 if (!IsTextSelection( sal_False ))
1656 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1658 bRet = m_pView->GetWrtShell().IsAtRightMargin(sal_True);
1660 else
1661 throw uno::RuntimeException();
1662 return bRet;
1665 void SwXTextViewCursor::gotoEndOfLine(sal_Bool bExpand) throw( uno::RuntimeException )
1667 SolarMutexGuard aGuard;
1668 if(m_pView)
1670 if (!IsTextSelection( sal_False ))
1671 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1673 m_pView->GetWrtShell().RightMargin(bExpand, sal_True);
1675 else
1676 throw uno::RuntimeException();
1679 void SwXTextViewCursor::gotoStartOfLine(sal_Bool bExpand) throw( uno::RuntimeException )
1681 SolarMutexGuard aGuard;
1682 if(m_pView)
1684 if (!IsTextSelection( sal_False ))
1685 throw uno::RuntimeException( OUString( "no text selection" ), static_cast < cppu::OWeakObject * > ( this ) );
1687 m_pView->GetWrtShell().LeftMargin(bExpand, sal_True);
1689 else
1690 throw uno::RuntimeException();
1693 OUString SwXTextViewCursor::getImplementationName(void) throw( RuntimeException )
1695 return OUString("SwXTextViewCursor");
1698 sal_Bool SwXTextViewCursor::supportsService(const OUString& rServiceName) throw( RuntimeException )
1700 return !rServiceName.compareToAscii("com.sun.star.text.TextViewCursor") ||
1701 !rServiceName.compareToAscii("com.sun.star.style.CharacterProperties") ||
1702 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesAsian") ||
1703 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesComplex") ||
1704 !rServiceName.compareToAscii("com.sun.star.style.ParagraphProperties") ||
1705 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesAsian") ||
1706 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesComplex");
1709 Sequence< OUString > SwXTextViewCursor::getSupportedServiceNames(void) throw( RuntimeException )
1711 Sequence< OUString > aRet(7);
1712 OUString* pArray = aRet.getArray();
1713 pArray[0] = "com.sun.star.text.TextViewCursor";
1714 pArray[1] = "com.sun.star.style.CharacterProperties";
1715 pArray[2] = "com.sun.star.style.CharacterPropertiesAsian";
1716 pArray[3] = "com.sun.star.style.CharacterPropertiesComplex";
1717 pArray[4] = "com.sun.star.style.ParagraphProperties";
1718 pArray[5] = "com.sun.star.style.ParagraphPropertiesAsian";
1719 pArray[6] = "com.sun.star.style.ParagraphPropertiesComplex";
1720 return aRet;
1723 namespace
1725 class theSwXTextViewCursorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextViewCursorUnoTunnelId > {};
1728 const uno::Sequence< sal_Int8 > & SwXTextViewCursor::getUnoTunnelId()
1730 return theSwXTextViewCursorUnoTunnelId::get().getSeq();
1733 //XUnoTunnel
1734 sal_Int64 SAL_CALL SwXTextViewCursor::getSomething(
1735 const uno::Sequence< sal_Int8 >& rId )
1736 throw(uno::RuntimeException)
1738 if( rId.getLength() == 16
1739 && 0 == memcmp( getUnoTunnelId().getConstArray(),
1740 rId.getConstArray(), 16 ) )
1742 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
1744 return OTextCursorHelper::getSomething(rId);
1747 IMPLEMENT_FORWARD_XINTERFACE2(SwXTextViewCursor,SwXTextViewCursor_Base,OTextCursorHelper)
1748 const SwDoc* SwXTextViewCursor::GetDoc() const
1750 SwWrtShell& rSh = m_pView->GetWrtShell();
1751 return rSh.GetCrsr() ? rSh.GetCrsr()->GetDoc() : 0;
1754 SwDoc* SwXTextViewCursor::GetDoc()
1756 SwWrtShell& rSh = m_pView->GetWrtShell();
1757 return rSh.GetCrsr() ? rSh.GetCrsr()->GetDoc() : 0;
1760 const SwPaM* SwXTextViewCursor::GetPaM() const
1762 SwWrtShell& rSh = m_pView->GetWrtShell();
1763 return rSh.GetCrsr();
1766 SwPaM* SwXTextViewCursor::GetPaM()
1768 SwWrtShell& rSh = m_pView->GetWrtShell();
1769 return rSh.GetCrsr();
1772 uno::Reference< datatransfer::XTransferable > SAL_CALL SwXTextView::getTransferable( ) throw (uno::RuntimeException)
1774 SolarMutexGuard aGuard;
1776 //force immediat shell update
1777 GetView()->StopShellTimer();
1778 SwWrtShell& rSh = GetView()->GetWrtShell();
1779 if ( GetView()->GetShellMode() == SHELL_MODE_DRAWTEXT )
1781 SdrView *pSdrView = rSh.GetDrawView();
1782 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
1783 return pOLV->GetEditView().GetTransferable();
1785 else
1787 SwTransferable* pTransfer = new SwTransferable( rSh );
1788 const sal_Bool bLockedView = rSh.IsViewLocked();
1789 rSh.LockView( sal_True ); //lock visible section
1790 pTransfer->PrepareForCopy();
1791 rSh.LockView( bLockedView );
1792 return uno::Reference< datatransfer::XTransferable >( pTransfer );
1796 void SAL_CALL SwXTextView::insertTransferable( const uno::Reference< datatransfer::XTransferable >& xTrans ) throw (datatransfer::UnsupportedFlavorException, uno::RuntimeException)
1798 SolarMutexGuard aGuard;
1800 //force immediat shell update
1801 GetView()->StopShellTimer();
1802 SwWrtShell& rSh = GetView()->GetWrtShell();
1803 if ( GetView()->GetShellMode() == SHELL_MODE_DRAWTEXT )
1805 SdrView *pSdrView = rSh.GetDrawView();
1806 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
1807 pOLV->GetEditView().InsertText( xTrans, GetView()->GetDocShell()->GetMedium()->GetBaseURL(), sal_False );
1809 else
1811 TransferableDataHelper aDataHelper( xTrans );
1812 if ( SwTransferable::IsPaste( rSh, aDataHelper ) )
1814 SwTransferable::Paste( rSh, aDataHelper );
1815 if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
1816 rSh.EnterSelFrmMode();
1817 GetView()->AttrChangedNotify( &rSh );
1822 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */