merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uno / unotxvw.cxx
blobde8bcd61ee041b99902763778dd3fbafd3f7c1a2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unotxvw.cxx,v $
10 * $Revision: 1.71 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "viscrs.hxx"
35 #include <sfx2/frame.hxx>
36 #include <sfx2/printer.hxx>
37 #include <cmdid.h>
38 #include <hintids.hxx>
39 #include <docsh.hxx>
40 #include <rubylist.hxx>
41 #include <doc.hxx>
42 #include <unotxvw.hxx>
43 #include <unodispatch.hxx>
44 #include <unomap.hxx>
45 #include <unostyle.hxx>
46 #include <unoprnms.hxx>
47 #include <view.hxx>
48 #include <viewopt.hxx>
49 #include <unomod.hxx>
50 #include <unoframe.hxx>
51 #include <unocrsr.hxx>
52 #include <wrtsh.hxx>
53 #include <unotbl.hxx>
54 #include <svx/fmshell.hxx>
55 #include <svx/svdview.hxx>
56 #include <svx/svdpage.hxx>
57 #include <svx/svdouno.hxx>
58 #include <svx/svdogrp.hxx>
59 #include <svx/pbinitem.hxx>
60 #include <pagedesc.hxx>
61 #include <svx/lrspitem.hxx>
62 #include <svx/ulspitem.hxx>
63 #include <sfx2/bindings.hxx>
64 #include <sfx2/request.hxx>
65 #include <frmatr.hxx>
66 #include <vos/mutex.hxx>
67 #include <IMark.hxx>
68 #include <unotxdoc.hxx>
69 #include <unodraw.hxx>
70 #include <svx/unoshcol.hxx>
71 #include <svx/unoshape.hxx>
72 #include <svx/svdpagv.hxx>
73 #include <swerror.h>
74 #include <tools/cachestr.hxx>
75 #include <shellio.hxx>
76 #include <ndtxt.hxx>
77 #include <SwStyleNameMapper.hxx>
78 #include <crsskip.hxx>
79 #include <com/sun/star/beans/PropertyAttribute.hpp>
81 #include <svx/editview.hxx>
82 #include <sfx2/docfile.hxx>
84 #include "swdtflvr.hxx"
85 #include <vcl/svapp.hxx>
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::uno;
90 using namespace ::com::sun::star::lang;
91 using namespace ::com::sun::star::beans;
92 using namespace ::com::sun::star::text;
93 using namespace ::com::sun::star::view;
94 using namespace ::com::sun::star::frame;
95 using namespace rtl;
97 using ::com::sun::star::util::URL;
98 using comphelper::HelperBaseNoState;
100 SV_IMPL_PTRARR( SelectionChangeListenerArr, XSelectionChangeListenerPtr );
102 /* -----------------22.05.98 12:20-------------------
104 * --------------------------------------------------*/
105 SwPaM* lcl_createPamCopy(const SwPaM& rPam)
107 SwPaM* pRet = new SwPaM(*rPam.GetPoint());
108 if(rPam.HasMark())
110 pRet->SetMark();
111 *pRet->GetMark() = *rPam.GetMark();
113 if(rPam.GetNext() != (const Ring*)&rPam)
115 SwPaM *_pStartCrsr = (SwPaM *)rPam.GetNext();
118 //neuen PaM erzeugen
119 SwPaM* pPaM = new SwPaM(*_pStartCrsr);
120 //und in den Ring einfuege\x04n
121 pPaM->MoveTo(pRet);
123 } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != rPam.GetNext() );
125 return pRet;
127 /******************************************************************
128 * SwXTextView
129 ******************************************************************/
130 /*-- 17.12.98 09:34:25---------------------------------------------------
132 -----------------------------------------------------------------------*/
133 SwXTextView::SwXTextView(SwView* pSwView) :
134 SfxBaseController(pSwView),
135 m_pView(pSwView),
136 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_VIEW ) ),
137 pxViewSettings(0),
138 pxTextViewCursor(0)
142 /*-- 17.12.98 09:34:25---------------------------------------------------
144 -----------------------------------------------------------------------*/
145 SwXTextView::~SwXTextView()
147 Invalidate();
149 /* -----------------------------09.03.01 15:47--------------------------------
151 ---------------------------------------------------------------------------*/
152 void SwXTextView::Invalidate()
154 if(pxViewSettings)
156 HelperBaseNoState *pSettings = static_cast < HelperBaseNoState * > ( pxViewSettings->get() );
157 static_cast < SwXViewSettings* > ( pSettings )->Invalidate();
158 DELETEZ(pxViewSettings);
160 if(pxTextViewCursor)
162 text::XTextViewCursor* pCrsr = pxTextViewCursor->get();
163 ((SwXTextViewCursor*)pCrsr)->Invalidate();
164 DELETEZ(pxTextViewCursor);
167 m_refCount++; //prevent second d'tor call
169 sal_uInt16 nCount = aSelChangedListeners.Count();
170 if(nCount)
172 uno::Reference< uno::XInterface > xInt = (cppu::OWeakObject*)(SfxBaseController*)this;
173 lang::EventObject aEvent(xInt);
174 for ( sal_uInt16 i = nCount; i--; )
176 uno::Reference< view::XSelectionChangeListener > *pObj = aSelChangedListeners[i];
177 (*pObj)->disposing(aEvent);
181 // #i85580: now clean up any possibly remaining entries in the array...
182 // (i.e. listeners that did not call removeSelectionChangeListener in their disposing.)
183 while ((nCount = aSelChangedListeners.Count()) != 0)
185 removeSelectionChangeListener( *aSelChangedListeners[0] );
188 m_refCount--;
189 m_pView = 0;
192 /* -----------------------------18.05.00 10:18--------------------------------
194 ---------------------------------------------------------------------------*/
195 Sequence< uno::Type > SAL_CALL SwXTextView::getTypes( ) throw(uno::RuntimeException)
197 // uno::Sequence< uno::Type > aViewTypes = SwXTextViewBaseClass::getTypes();
198 uno::Sequence< uno::Type > aBaseTypes = SfxBaseController::getTypes();
200 long nIndex = aBaseTypes.getLength();
201 aBaseTypes.realloc(
202 aBaseTypes.getLength() + 8 );
204 uno::Type* pBaseTypes = aBaseTypes.getArray();
205 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XSelectionSupplier >*)0);
206 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XServiceInfo >*)0);
207 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XFormLayerAccess >*)0);
208 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XTextViewCursorSupplier>*)0);
209 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XViewSettingsSupplier >*)0);
210 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XRubySelection >*)0);
211 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<XPropertySet >*)0);
212 pBaseTypes[nIndex++] = ::getCppuType((uno::Reference<datatransfer::XTransferableSupplier >*)0);
213 return aBaseTypes;
215 /* -----------------------------18.05.00 10:18--------------------------------
217 ---------------------------------------------------------------------------*/
218 Sequence< sal_Int8 > SAL_CALL SwXTextView::getImplementationId( ) throw(uno::RuntimeException)
220 vos::OGuard aGuard(Application::GetSolarMutex());
221 static Sequence< sal_Int8 > aId( 16 );
222 static sal_Bool bInit = sal_False;
223 if(!bInit)
225 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
226 bInit = sal_True;
228 return aId;
230 /* -----------------------------18.05.00 10:18--------------------------------
232 ---------------------------------------------------------------------------*/
233 void SAL_CALL SwXTextView::acquire( )throw()
235 SfxBaseController::acquire();
237 /* -----------------------------18.05.00 10:18--------------------------------
239 ---------------------------------------------------------------------------*/
240 void SAL_CALL SwXTextView::release( )throw()
242 SfxBaseController::release();
244 /* -----------------------------18.05.00 10:23--------------------------------
246 ---------------------------------------------------------------------------*/
247 uno::Any SAL_CALL SwXTextView::queryInterface( const uno::Type& aType )
248 throw (RuntimeException)
250 uno::Any aRet;
251 if(aType == ::getCppuType((uno::Reference<view::XSelectionSupplier >*)0))
253 uno::Reference<view::XSelectionSupplier> xRet = this;
254 aRet.setValue(&xRet, aType);
256 else if(aType == ::getCppuType((uno::Reference<lang::XServiceInfo >*)0))
258 uno::Reference<lang::XServiceInfo> xRet = this;
259 aRet.setValue(&xRet, aType);
261 else if(aType == ::getCppuType((uno::Reference<view::XControlAccess >*)0))
263 uno::Reference<view::XControlAccess> xRet = this;
264 aRet.setValue(&xRet, aType);
266 else if(aType == ::getCppuType((uno::Reference<view::XFormLayerAccess >*)0))
268 uno::Reference<view::XFormLayerAccess> xRet = this;
269 aRet.setValue(&xRet, aType);
271 else if(aType == ::getCppuType((uno::Reference<text::XTextViewCursorSupplier>*)0))
273 uno::Reference<text::XTextViewCursorSupplier> xRet = this;
274 aRet.setValue(&xRet, aType);
276 else if(aType == ::getCppuType((uno::Reference<view::XViewSettingsSupplier >*)0))
278 uno::Reference<view::XViewSettingsSupplier> xRet = this;
279 aRet.setValue(&xRet, aType);
281 else if(aType == ::getCppuType((uno::Reference<XRubySelection>*)0))
283 uno::Reference<XRubySelection> xRet = this;
284 aRet.setValue(&xRet, aType);
286 else if(aType == ::getCppuType((uno::Reference<XPropertySet>*)0))
288 uno::Reference<XPropertySet> xRet = this;
289 aRet.setValue(&xRet, aType);
291 else if(aType == ::getCppuType((uno::Reference<datatransfer::XTransferableSupplier >*)0))
293 uno::Reference<datatransfer::XTransferableSupplier> xRet = this;
294 aRet.setValue(&xRet, aType);
296 else
297 aRet = SfxBaseController::queryInterface(aType);
298 return aRet;
300 /*-- 17.12.98 09:34:26---------------------------------------------------
302 -----------------------------------------------------------------------*/
303 sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArgumentException, uno::RuntimeException )
305 ::vos::OGuard aGuard(Application::GetSolarMutex());
306 uno::Reference< uno::XInterface > xInterface;
307 if(GetView() && (aInterface >>= xInterface))
309 SwWrtShell& rSh = GetView()->GetWrtShell();
310 SwDoc* pDoc = GetView()->GetDocShell()->GetDoc();
311 uno::Reference< lang::XUnoTunnel > xIfcTunnel(xInterface, uno::UNO_QUERY);
312 uno::Reference< text::XTextCursor > xCrsr(xInterface, uno::UNO_QUERY);
313 uno::Reference< container::XIndexAccess > xPosN(xInterface, uno::UNO_QUERY);
314 uno::Reference< text::XTextRange > xPos(xInterface, uno::UNO_QUERY);
315 SwXFrame* pFrame = xIfcTunnel.is() ? reinterpret_cast<SwXFrame*>(
316 xIfcTunnel->getSomething(SwXFrame::getUnoTunnelId())) : 0;
318 SwXCell* pCell = xIfcTunnel.is() ? reinterpret_cast<SwXCell*>(
319 xIfcTunnel->getSomething(SwXCell::getUnoTunnelId())) : 0;
321 SwPaM * pPam = 0;
322 SwXTextRanges* pPosN = 0;
323 if(xCrsr.is())
326 OTextCursorHelper* pCursor =
327 xIfcTunnel.is() ?
328 reinterpret_cast<OTextCursorHelper*>(xIfcTunnel->getSomething(OTextCursorHelper::getUnoTunnelId()))
329 : 0;
331 if(pCursor && pCursor->GetDoc() == GetView()->GetDocShell()->GetDoc())
332 pPam = lcl_createPamCopy(*((SwXTextCursor*)pCursor)->GetPaM());
335 else if(xPosN.is() &&
336 xIfcTunnel.is() &&
337 0 != (pPosN = reinterpret_cast<SwXTextRanges*>(xIfcTunnel->getSomething(SwXTextRanges::getUnoTunnelId()))))
339 const SwUnoCrsr* pUnoCrsr = pPosN->GetCursor();
340 if(pUnoCrsr)
342 pPam = lcl_createPamCopy(*pUnoCrsr);
345 // prevent misinterpretation of text frames that provide a XTextRange interface, too
346 else if(!pFrame && !pCell && xPos.is())
348 SwUnoInternalPaM aPam(*pDoc);
349 if(SwXTextRange::XTextRangeToSwPaM(aPam, xPos))
351 pPam = lcl_createPamCopy(aPam);
354 if(pPam)
356 rSh.EnterStdMode();
357 rSh.SetSelection(*pPam);
358 while( pPam->GetNext() != pPam )
359 delete pPam->GetNext();
360 delete pPam;
361 return sal_True;
363 if(pFrame)
366 SwFrmFmt* pFrmFmt = pFrame->GetFrmFmt();
367 if(pFrmFmt && pFrmFmt->GetDoc() == pDoc)
369 sal_Bool bSuccess = rSh.GotoFly( pFrmFmt->GetName(), pFrame->GetFlyCntType());
370 if (bSuccess)
372 rSh.HideCrsr();
373 rSh.EnterSelFrmMode();
375 return sal_True;
379 uno::Reference< text::XTextTable > xTbl(xInterface, uno::UNO_QUERY);;
381 if(xTbl.is() && xIfcTunnel.is())
383 SwXTextTable* pTable = reinterpret_cast<SwXTextTable*>(
384 xIfcTunnel->getSomething(SwXTextTable::getUnoTunnelId()));
386 SwFrmFmt* pTblFrmFmt = pTable ? ((SwXTextTable*)pTable)->GetFrmFmt() : 0;
387 if(pTblFrmFmt &&pTblFrmFmt->GetDoc() == pDoc)
389 rSh.EnterStdMode();
390 rSh.GotoTable(pTblFrmFmt->GetName());
392 return sal_True;
395 if(pCell)
397 SwFrmFmt* pTblFrmFmt = pCell->GetFrmFmt();
398 if(pTblFrmFmt && pTblFrmFmt->GetDoc() == pDoc)
400 SwTableBox* pBox = pCell->GetTblBox();
401 SwTable* pTable = SwTable::FindTable( pTblFrmFmt );
402 pBox = pCell->FindBox(pTable, pBox);
403 if(pBox)
405 const SwStartNode* pSttNd = pBox->GetSttNd();
406 SwPosition aPos(*pSttNd);
407 SwPaM aPam(aPos);
408 aPam.Move(fnMoveForward, fnGoNode);
409 rSh.EnterStdMode();
410 rSh.SetSelection(aPam);
411 return sal_True;
415 SwXCellRange* pRange = xIfcTunnel.is() ? reinterpret_cast<SwXCellRange*>(
416 xIfcTunnel->getSomething(SwXCellRange::getUnoTunnelId())) : 0;
417 if(pRange)
419 const SwUnoCrsr* pUnoCrsr = pRange->GetTblCrsr();
420 if(pUnoCrsr)
422 UnoActionRemoveContext aContext(pDoc);
423 rSh.EnterStdMode();
424 rSh.SetSelection(*pUnoCrsr);
425 return sal_True;
428 uno::Reference< text::XTextContent > xBkm(xInterface, uno::UNO_QUERY);;
430 if(xBkm.is() && xIfcTunnel.is())
432 SwXBookmark* pBkm = reinterpret_cast<SwXBookmark*>(
433 xIfcTunnel->getSomething(SwXBookmark::getUnoTunnelId()));
434 if(pBkm && pBkm->GetDoc() == pDoc)
436 IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
437 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(pBkm->getName());
438 if( ppMark != pMarkAccess->getMarksEnd() )
440 rSh.EnterStdMode();
441 rSh.GotoMark( ppMark->get() );
443 return sal_True;
446 // IndexMark, Index, TextField, Draw, Section, Footnote, Paragraph
449 // detect controls
451 uno::Reference< awt::XControlModel > xCtrlModel(xInterface, UNO_QUERY);
452 if(xCtrlModel.is())
454 uno::Reference<awt::XControl> XControl;
455 SdrObject* pObj = GetControl(xCtrlModel, XControl);
456 if(pObj)
458 SdrView* pDrawView = rSh.GetDrawView();
459 SdrPageView* pPV = pDrawView->GetSdrPageView();
460 if ( pPV && pObj->GetPage() == pPV->GetPage() )
462 pDrawView->SdrEndTextEdit();
463 pDrawView->UnmarkAll();
464 pDrawView->MarkObj( pObj, pPV );
466 return sal_True;
470 uno::Reference< drawing::XShapes > xShapeColl( xInterface, uno::UNO_QUERY );
471 uno::Reference< beans::XPropertySet > xTmpProp(xInterface, uno::UNO_QUERY);
472 SwXShape* pSwXShape = 0;
473 if(xIfcTunnel.is())
474 pSwXShape = reinterpret_cast<SwXShape*>(xIfcTunnel->getSomething(SwXShape::getUnoTunnelId()));
475 SvxShape* pSvxShape = 0;
476 if(pSwXShape)
478 uno::Reference< uno::XAggregation > xAgg = pSwXShape->GetAggregationInterface();
479 if(xAgg.is())
481 pSvxShape = reinterpret_cast<SvxShape*>(xIfcTunnel->getSomething(SvxShape::getUnoTunnelId()));
485 if ( pSvxShape || xShapeColl.is() ) // Drawing drawing::Layer
487 SdrView* pDrawView = rSh.GetDrawView();
488 if (pDrawView)
490 pDrawView->SdrEndTextEdit();
491 pDrawView->UnmarkAll();
493 if (pSvxShape) // einzelnes Shape
495 SdrObject *pObj = pSvxShape->GetSdrObject();
496 if (pObj)
498 // lcl_ShowObject( *m_pViewSh, *pDrawView, pObj );
499 SdrPageView* pPV = pDrawView->GetSdrPageView();
500 if ( pPV && pObj->GetPage() == pPV->GetPage() )
502 pDrawView->MarkObj( pObj, pPV );
503 return sal_True;
507 else // Shape Collection
509 sal_Bool bSelected = sal_False;
510 SdrPageView* pPV = NULL;
511 long nCount = xShapeColl->getCount();
512 for ( long i = 0; i < nCount; i++ )
514 uno::Reference< drawing::XShape > xShapeInt;
515 uno::Any aAny = xShapeColl->getByIndex(i);
516 aAny >>= xShapeInt;
517 if (xShapeInt.is())
519 uno::Reference< lang::XUnoTunnel> xShapeTunnel(xShapeInt, uno::UNO_QUERY);
521 SvxShape* pShape = xShapeTunnel.is() ?
522 reinterpret_cast<SvxShape*>(xShapeTunnel->getSomething(SvxShape::getUnoTunnelId())) : 0;
524 if (pShape)
526 SdrObject *pObj = pShape->GetSdrObject();
527 if (pObj)
529 if (!pPV) // erstes Objekt
531 // lcl_ShowObject( *m_pViewSh, *pDrawView, pObj );
532 pPV = pDrawView->GetSdrPageView();
534 if ( pPV && pObj->GetPage() == pPV->GetPage() )
536 pDrawView->MarkObj( pObj, pPV );
537 bSelected = sal_True;
543 return bSelected;
548 return sal_False;
551 /*-- 17.12.98 09:34:26---------------------------------------------------
553 -----------------------------------------------------------------------*/
554 uno::Any SwXTextView::getSelection(void) throw( uno::RuntimeException )
556 ::vos::OGuard aGuard(Application::GetSolarMutex());
557 uno::Reference< uno::XInterface > aRef;
558 if(GetView())
560 //force immediat shell update
561 m_pView->StopShellTimer();
562 // ein interface aus der aktuellen Selektion erzeugen
563 SwWrtShell& rSh = m_pView->GetWrtShell();
564 ShellModes eSelMode = m_pView->GetShellMode();
565 switch(eSelMode)
567 case SHELL_MODE_TABLE_TEXT :
569 if(rSh.GetTableCrsr())
571 DBG_ASSERT(rSh.GetTableFmt(), "kein Tabellenformat?");
572 uno::Reference< text::XTextTableCursor > xCrsr = new SwXTextTableCursor(*rSh.GetTableFmt(),
573 rSh.GetTableCrsr());
574 aRef = uno::Reference< uno::XInterface > (xCrsr, uno::UNO_QUERY);;
575 break;
579 // ohne Tabellenselektion wird der Text geliefert
580 //break;
581 case SHELL_MODE_LIST_TEXT :
582 case SHELL_MODE_TABLE_LIST_TEXT:
583 case SHELL_MODE_TEXT :
585 uno::Reference< container::XIndexAccess > xPos = new SwXTextRanges(rSh.GetCrsr());
586 aRef = uno::Reference< uno::XInterface >(xPos, uno::UNO_QUERY);
588 break;
589 case SHELL_MODE_FRAME :
590 case SHELL_MODE_GRAPHIC :
591 case SHELL_MODE_OBJECT :
593 //Get FlyFrameFormat; fuer UI Macro Anbindung an Flys
594 const SwFrmFmt* pFmt = rSh.GetFlyFrmFmt();
595 if (pFmt)
597 SwXFrame* pxFrame = (SwXFrame*)SwClientIter((SwFrmFmt&)*pFmt).
598 First(TYPE(SwXFrame));
600 if(pxFrame) //das einzige gemeinsame interface fuer alle Frames
602 aRef = uno::Reference< uno::XInterface >((cppu::OWeakObject*)pxFrame, uno::UNO_QUERY);
604 else
606 if(SHELL_MODE_FRAME == eSelMode)
608 uno::Reference< text::XTextFrame > xFrm = new SwXTextFrame((SwFrmFmt&)*pFmt);
609 aRef = uno::Reference< uno::XInterface >(xFrm, uno::UNO_QUERY);
611 else if(SHELL_MODE_GRAPHIC == eSelMode)
613 uno::Reference< text::XTextContent > xFrm = new SwXTextGraphicObject((SwFrmFmt&)*pFmt);
614 aRef = xFrm;
616 else
618 uno::Reference< text::XTextContent > xFrm = new SwXTextEmbeddedObject((SwFrmFmt&)*pFmt);
619 aRef = xFrm;
624 break;
625 case SHELL_MODE_DRAW :
626 case SHELL_MODE_DRAW_CTRL :
627 case SHELL_MODE_DRAW_FORM :
628 case SHELL_MODE_DRAWTEXT :
629 case SHELL_MODE_BEZIER :
631 uno::Reference< drawing::XDrawPageSupplier > xPageSupp;
632 uno::Reference< frame::XModel > xModel = m_pView->GetDocShell()->GetBaseModel();
633 uno::Reference< lang::XUnoTunnel > xModelTunnel(xModel, uno::UNO_QUERY);
634 SwXTextDocument* pTextDoc = reinterpret_cast<SwXTextDocument*>(xModelTunnel->
635 getSomething(SwXTextDocument::getUnoTunnelId()));
637 SwFmDrawPage* pSvxDrawPage = pTextDoc->GetDrawPage()->GetSvxPage();
638 uno::Reference< drawing::XShapes > xShCol = new SvxShapeCollection();
640 const SdrMarkList& rMarkList = rSh.GetDrawView()->GetMarkedObjectList();
641 for(sal_uInt16 i = 0; i < rMarkList.GetMarkCount(); i++)
643 SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
644 uno::Reference< uno::XInterface > xInt = pSvxDrawPage->GetInterface( pObj );
645 uno::Reference< drawing::XShape > xShape(xInt, uno::UNO_QUERY);;
646 xShCol->add(xShape);
648 aRef = uno::Reference< uno::XInterface >(xShCol, uno::UNO_QUERY);
650 break;
651 default:;//prevent warning
654 uno::Any aRet(&aRef, ::getCppuType((uno::Reference<uno::XInterface>*)0));
655 return aRet;
657 /*-- 17.12.98 09:34:27---------------------------------------------------
659 -----------------------------------------------------------------------*/
660 void SwXTextView::addSelectionChangeListener(
661 const uno::Reference< view::XSelectionChangeListener > & rxListener)
662 throw( uno::RuntimeException )
664 ::vos::OGuard aGuard(Application::GetSolarMutex());
665 uno::Reference< view::XSelectionChangeListener > * pInsert = new uno::Reference< view::XSelectionChangeListener > ;
666 *pInsert = rxListener;
667 aSelChangedListeners.Insert(pInsert, aSelChangedListeners.Count());
669 /*-- 17.12.98 09:34:27---------------------------------------------------
671 -----------------------------------------------------------------------*/
672 void SwXTextView::removeSelectionChangeListener(
673 const uno::Reference< view::XSelectionChangeListener > & rxListener)
674 throw( uno::RuntimeException )
676 ::vos::OGuard aGuard(Application::GetSolarMutex());
677 view::XSelectionChangeListener* pLeft = rxListener.get();
678 for(sal_uInt16 i = 0; i < aSelChangedListeners.Count(); i++)
680 uno::Reference< view::XSelectionChangeListener > * pElem = aSelChangedListeners.GetObject(i);
681 view::XSelectionChangeListener* pRight = pElem->get();
682 if(pLeft == pRight)
684 aSelChangedListeners.Remove(i);
685 delete pElem;
686 break;
690 /* -----------------------------01.06.01 14:41--------------------------------
692 ---------------------------------------------------------------------------*/
693 SdrObject* SwXTextView::GetControl(
694 const uno::Reference< awt::XControlModel > & xModel,
695 uno::Reference< awt::XControl >& xToFill )
697 SwView* pView2 = GetView();
698 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
699 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : NULL;
700 Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : NULL;
702 DBG_ASSERT( pFormShell && pDrawView && pWindow, "SwXTextView::GetControl: how could I?" );
704 SdrObject* pControl = NULL;
705 if ( pFormShell && pDrawView && pWindow )
706 pControl = pFormShell->GetFormControl( xModel, *pDrawView, *pWindow, xToFill );
707 return pControl;
709 /*-- 17.12.98 09:34:27---------------------------------------------------
711 -----------------------------------------------------------------------*/
712 uno::Reference< awt::XControl > SwXTextView::getControl(const uno::Reference< awt::XControlModel > & xModel)
713 throw( container::NoSuchElementException, uno::RuntimeException )
715 ::vos::OGuard aGuard(Application::GetSolarMutex());
716 uno::Reference< awt::XControl > xRet;
717 GetControl(xModel, xRet);
718 return xRet;
721 /*-- 08.03.07 13:55------------------------------------------------------
723 -----------------------------------------------------------------------*/
724 uno::Reference< form::XFormController > SAL_CALL SwXTextView::getFormController( const uno::Reference< form::XForm >& _Form ) throw (RuntimeException)
726 ::vos::OGuard aGuard( Application::GetSolarMutex() );
728 SwView* pView2 = GetView();
729 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
730 SdrView* pDrawView = pView2 ? pView2->GetDrawView() : NULL;
731 Window* pWindow = pView2 ? pView2->GetWrtShell().GetWin() : NULL;
732 DBG_ASSERT( pFormShell && pDrawView && pWindow, "SwXTextView::GetControl: how could I?" );
734 uno::Reference< form::XFormController > xController;
735 if ( pFormShell && pDrawView && pWindow )
736 xController = pFormShell->GetFormController( _Form, *pDrawView, *pWindow );
737 return xController;
740 /*-- 08.03.07 13:55------------------------------------------------------
742 -----------------------------------------------------------------------*/
743 ::sal_Bool SAL_CALL SwXTextView::isFormDesignMode( ) throw (uno::RuntimeException)
745 ::vos::OGuard aGuard( Application::GetSolarMutex() );
746 SwView* pView2 = GetView();
747 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
748 return pFormShell ? pFormShell->IsDesignMode() : sal_True;
751 /*-- 08.03.07 13:55------------------------------------------------------
753 -----------------------------------------------------------------------*/
754 void SAL_CALL SwXTextView::setFormDesignMode( ::sal_Bool _DesignMode ) throw (RuntimeException)
756 ::vos::OGuard aGuard( Application::GetSolarMutex() );
757 SwView* pView2 = GetView();
758 FmFormShell* pFormShell = pView2 ? pView2->GetFormShell() : NULL;
759 if ( pFormShell )
760 pFormShell->SetDesignMode( _DesignMode );
763 /*-- 17.12.98 09:34:28---------------------------------------------------
765 -----------------------------------------------------------------------*/
766 uno::Reference< text::XTextViewCursor > SwXTextView::getViewCursor(void) throw( uno::RuntimeException )
768 ::vos::OGuard aGuard(Application::GetSolarMutex());
769 if(GetView())
771 if(!pxTextViewCursor)
773 ((SwXTextView*)this)->pxTextViewCursor = new uno::Reference< text::XTextViewCursor > ;
774 *pxTextViewCursor = new SwXTextViewCursor(GetView());
776 return *pxTextViewCursor;
778 else
779 throw uno::RuntimeException();
781 /*-- 17.12.98 09:34:28---------------------------------------------------
783 -----------------------------------------------------------------------*/
784 uno::Reference< beans::XPropertySet > SwXTextView::getViewSettings(void) throw( uno::RuntimeException )
786 ::vos::OGuard aGuard(Application::GetSolarMutex());
787 if(m_pView)
789 if(!pxViewSettings)
791 ((SwXTextView*)this)->pxViewSettings = new uno::Reference< beans::XPropertySet > ;
792 *pxViewSettings = static_cast < HelperBaseNoState * > ( new SwXViewSettings( sal_False, m_pView ) );
795 else
796 throw uno::RuntimeException();
797 return *pxViewSettings;
799 /* -----------------------------30.01.01 15:01--------------------------------
801 ---------------------------------------------------------------------------*/
802 Sequence< Sequence< PropertyValue > > SwXTextView::getRubyList( sal_Bool /*bAutomatic*/ ) throw(RuntimeException)
804 ::vos::OGuard aGuard(Application::GetSolarMutex());
806 if(!GetView())
807 throw RuntimeException();
808 SwWrtShell& rSh = m_pView->GetWrtShell();
809 ShellModes eSelMode = m_pView->GetShellMode();
810 if (eSelMode != SHELL_MODE_LIST_TEXT &&
811 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
812 eSelMode != SHELL_MODE_TABLE_TEXT &&
813 eSelMode != SHELL_MODE_TEXT )
814 return Sequence< Sequence< PropertyValue > > ();
816 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
817 SwRubyList aList;
819 USHORT nCount = pDoc->FillRubyList( *rSh.GetCrsr(), aList, 0 );
820 Sequence< Sequence< PropertyValue > > aRet(nCount);
821 Sequence< PropertyValue >* pRet = aRet.getArray();
822 String aString;
823 for(USHORT n = 0; n < nCount; n++)
825 const SwRubyListEntryPtr pEntry = aList[n];
827 const String& rEntryText = pEntry->GetText();
828 const SwFmtRuby& rAttr = pEntry->GetRubyAttr();
830 pRet[n].realloc(5);
831 PropertyValue* pValues = pRet[n].getArray();
832 pValues[0].Name = C2U(SW_PROP_NAME_STR(UNO_NAME_RUBY_BASE_TEXT));
833 pValues[0].Value <<= OUString(rEntryText);
834 pValues[1].Name = C2U(SW_PROP_NAME_STR(UNO_NAME_RUBY_TEXT));
835 pValues[1].Value <<= OUString(rAttr.GetText());
836 pValues[2].Name = C2U(SW_PROP_NAME_STR(UNO_NAME_RUBY_CHAR_STYLE_NAME));
837 SwStyleNameMapper::FillProgName(rAttr.GetCharFmtName(), aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
838 pValues[2].Value <<= OUString( aString );
839 pValues[3].Name = C2U(SW_PROP_NAME_STR(UNO_NAME_RUBY_ADJUST));
840 pValues[3].Value <<= (sal_Int16)rAttr.GetAdjustment();
841 pValues[4].Name = C2U(SW_PROP_NAME_STR(UNO_NAME_RUBY_IS_ABOVE));
842 sal_Bool bVal = !rAttr.GetPosition();
843 pValues[4].Value.setValue(&bVal, ::getBooleanCppuType());
845 return aRet;
847 /* -----------------------------30.01.01 15:02--------------------------------
849 ---------------------------------------------------------------------------*/
850 void SAL_CALL SwXTextView::setRubyList(
851 const Sequence< Sequence< PropertyValue > >& rRubyList, sal_Bool /*bAutomatic*/ )
852 throw(RuntimeException)
854 ::vos::OGuard aGuard(Application::GetSolarMutex());
856 if(!GetView() || !rRubyList.getLength())
857 throw RuntimeException();
858 SwWrtShell& rSh = m_pView->GetWrtShell();
859 ShellModes eSelMode = m_pView->GetShellMode();
860 if (eSelMode != SHELL_MODE_LIST_TEXT &&
861 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
862 eSelMode != SHELL_MODE_TABLE_TEXT &&
863 eSelMode != SHELL_MODE_TEXT )
864 throw RuntimeException();
866 SwRubyList aList;
868 const Sequence<PropertyValue>* pRubyList = rRubyList.getConstArray();
869 for(sal_Int32 nPos = 0; nPos < rRubyList.getLength(); nPos++)
871 SwRubyListEntryPtr pEntry = new SwRubyListEntry;
872 const PropertyValue* pProperties = pRubyList[nPos].getConstArray();
873 OUString sTmp;
874 for(sal_Int32 nProp = 0; nProp < pRubyList[nPos].getLength(); nProp++)
876 if(pProperties[nProp].Name.equalsAsciiL(
877 SW_PROP_NAME(UNO_NAME_RUBY_BASE_TEXT)))
879 pProperties[nProp].Value >>= sTmp;
880 pEntry->SetText(sTmp);
882 else if(pProperties[nProp].Name.equalsAsciiL(
883 SW_PROP_NAME(UNO_NAME_RUBY_TEXT)))
885 pProperties[nProp].Value >>= sTmp;
886 pEntry->GetRubyAttr().SetText(sTmp);
888 else if(pProperties[nProp].Name.equalsAsciiL(
889 SW_PROP_NAME(UNO_NAME_RUBY_CHAR_STYLE_NAME)))
891 if((pProperties[nProp].Value >>= sTmp))
893 String sName;
894 SwStyleNameMapper::FillUIName(sTmp, sName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
895 sal_uInt16 nPoolId = sName.Len() ?
896 SwStyleNameMapper::GetPoolIdFromUIName( sName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ) : 0;
898 pEntry->GetRubyAttr().SetCharFmtName( sName );
899 pEntry->GetRubyAttr().SetCharFmtId( nPoolId );
902 else if(pProperties[nProp].Name.equalsAsciiL(
903 SW_PROP_NAME(UNO_NAME_RUBY_ADJUST)))
905 sal_Int16 nTmp = 0;
906 if((pProperties[nProp].Value >>= nTmp))
907 pEntry->GetRubyAttr().SetAdjustment(nTmp);
909 else if(pProperties[nProp].Name.equalsAsciiL(
910 SW_PROP_NAME(UNO_NAME_RUBY_IS_ABOVE)))
912 sal_Bool bValue = pProperties[nProp].Value.hasValue() ?
913 *(sal_Bool*)pProperties[nProp].Value.getValue() : sal_True;
914 pEntry->GetRubyAttr().SetPosition(bValue ? 0 : 1);
917 aList.Insert(pEntry, (USHORT)nPos);
919 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
920 pDoc->SetRubyList( *rSh.GetCrsr(), aList, 0 );
922 /*-- 29.12.02 15:45:29---------------------------------------------------
924 -----------------------------------------------------------------------*/
925 SfxObjectShellRef SwXTextView::BuildTmpSelectionDoc( SfxObjectShellRef& /*rRef*/ )
927 SwWrtShell* pOldSh = &m_pView->GetWrtShell();
928 SfxPrinter *pPrt = pOldSh->getIDocumentDeviceAccess()->getPrinter( false );
929 SwDocShell* pDocSh;
930 SfxObjectShellRef xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) );
931 xDocSh->DoInitNew( 0 );
932 pOldSh->FillPrtDoc(pDocSh->GetDoc(), pPrt);
933 SfxViewFrame* pDocFrame = SfxViewFrame::CreateViewFrame( *xDocSh, 0, TRUE );
934 SwView* pDocView = (SwView*) pDocFrame->GetViewShell();
935 pDocView->AttrChangedNotify( &pDocView->GetWrtShell() );//Damit SelectShell gerufen wird.
936 SwWrtShell* pSh = pDocView->GetWrtShellPtr();
938 IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
939 SfxPrinter* pTempPrinter = pIDDA->getPrinter( true );
941 if( pOldSh )
943 const SwPageDesc& rCurPageDesc = pOldSh->GetPageDesc(pOldSh->GetCurPageDesc());
945 IDocumentDeviceAccess* pIDDA_old = pOldSh->getIDocumentDeviceAccess();
947 if( pIDDA_old->getPrinter( false ) )
949 pIDDA->setJobsetup( *pIDDA_old->getJobsetup() );
950 //#69563# if it isn't the same printer then the pointer has been invalidated!
951 pTempPrinter = pIDDA->getPrinter( true );
954 pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
957 return xDocSh;
960 /*-- 17.12.98 09:34:29---------------------------------------------------
962 -----------------------------------------------------------------------*/
963 void SwXTextView::NotifySelChanged()
965 DBG_ASSERT( m_pView, "view is missing" );
967 // destroy temporary document with selected text that is used
968 // in PDF export of (multi-)selections.
969 if (m_pView && m_pView->GetTmpSelectionDoc().Is())
971 m_pView->GetTmpSelectionDoc()->DoClose();
972 m_pView->GetTmpSelectionDoc() = 0;
975 uno::Reference< uno::XInterface > xInt = (cppu::OWeakObject*)(SfxBaseController*)this;
977 lang::EventObject aEvent(xInt);
979 sal_uInt16 nCount = aSelChangedListeners.Count();
980 for ( sal_uInt16 i = nCount; i--; )
982 uno::Reference< view::XSelectionChangeListener > *pObj = aSelChangedListeners[i];
983 (*pObj)->selectionChanged(aEvent);
986 /* -----------------------------12.07.01 13:26--------------------------------
988 ---------------------------------------------------------------------------*/
989 void SwXTextView::NotifyDBChanged()
991 URL aURL;
992 aURL.Complete = C2U(SwXDispatch::GetDBChangeURL());
994 sal_uInt16 nCount = aSelChangedListeners.Count();
995 for ( sal_uInt16 i = nCount; i--; )
997 uno::Reference< view::XSelectionChangeListener > *pObj = aSelChangedListeners[i];
998 uno::Reference<XDispatch> xDispatch((*pObj), UNO_QUERY);
999 if(xDispatch.is())
1000 xDispatch->dispatch(aURL, Sequence<PropertyValue>(0));
1004 /* -----------------------------10.12.04 11:07--------------------------------
1006 ---------------------------------------------------------------------------*/
1008 uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXTextView::getPropertySetInfo( )
1009 throw (uno::RuntimeException)
1011 vos::OGuard aGuard( Application::GetSolarMutex() );
1012 static uno::Reference< XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo();
1013 return aRef;
1017 void SAL_CALL SwXTextView::setPropertyValue(
1018 const OUString& rPropertyName, const uno::Any& rValue )
1019 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
1021 vos::OGuard aGuard( Application::GetSolarMutex() );
1022 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
1023 if (!pEntry)
1024 throw UnknownPropertyException();
1025 else if (pEntry->nFlags & PropertyAttribute::READONLY)
1026 throw PropertyVetoException();
1027 else
1029 switch (pEntry->nWID)
1031 case WID_IS_HIDE_SPELL_MARKS :
1032 // deprecated #i91949
1033 break;
1034 case WID_IS_CONSTANT_SPELLCHECK :
1036 sal_Bool bVal = sal_False;
1037 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
1038 if (!pOpt || !(rValue >>= bVal))
1039 throw RuntimeException();
1040 SwViewOption aNewOpt( *pOpt );
1041 if (pEntry->nWID == WID_IS_CONSTANT_SPELLCHECK)
1042 aNewOpt.SetOnlineSpell(bVal);
1043 m_pView->GetWrtShell().ApplyViewOptions( aNewOpt );
1045 break;
1046 default :
1047 DBG_ERROR("unknown WID");
1053 uno::Any SAL_CALL SwXTextView::getPropertyValue(
1054 const OUString& rPropertyName )
1055 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1057 vos::OGuard aGuard( Application::GetSolarMutex() );
1059 Any aRet;
1061 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName( rPropertyName );
1062 if (!pEntry)
1063 throw UnknownPropertyException();
1064 else
1066 sal_Int16 nWID = pEntry->nWID;
1067 switch (nWID)
1069 case WID_PAGE_COUNT :
1070 case WID_LINE_COUNT :
1072 // format document completely in order to get meaningful
1073 // values for page count and line count
1074 m_pView->GetWrtShell().CalcLayout();
1076 sal_Int32 nCount = -1;
1077 if (nWID == WID_PAGE_COUNT)
1078 nCount = m_pView->GetDocShell()->GetDoc()->GetPageCount();
1079 else // WID_LINE_COUNT
1080 nCount = m_pView->GetWrtShell().GetLineCount( FALSE /*of whole document*/ );
1081 aRet <<= nCount;
1083 break;
1084 case WID_IS_HIDE_SPELL_MARKS :
1085 // deprecated #i91949
1086 break;
1087 case WID_IS_CONSTANT_SPELLCHECK :
1089 const SwViewOption *pOpt = m_pView->GetWrtShell().GetViewOptions();
1090 if (!pOpt)
1091 throw RuntimeException();
1092 UINT32 nFlag = VIEWOPT_1_ONLINESPELL;
1093 sal_Bool bVal = 0 != (pOpt->GetCoreOptions() & nFlag);
1094 aRet <<= bVal;
1096 break;
1097 default :
1098 DBG_ERROR("unknown WID");
1102 return aRet;
1106 void SAL_CALL SwXTextView::addPropertyChangeListener(
1107 const OUString& /*rPropertyName*/,
1108 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
1109 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1111 DBG_WARNING("not implemented");
1115 void SAL_CALL SwXTextView::removePropertyChangeListener(
1116 const OUString& /*rPropertyName*/,
1117 const uno::Reference< beans::XPropertyChangeListener >& /*rxListener*/ )
1118 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1120 DBG_WARNING("not implemented");
1124 void SAL_CALL SwXTextView::addVetoableChangeListener(
1125 const OUString& /*rPropertyName*/,
1126 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
1127 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1129 DBG_WARNING("not implemented");
1133 void SAL_CALL SwXTextView::removeVetoableChangeListener(
1134 const OUString& /*rPropertyName*/,
1135 const uno::Reference< beans::XVetoableChangeListener >& /*rxListener*/ )
1136 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1138 DBG_WARNING("not implemented");
1141 /* -----------------------------06.04.00 11:07--------------------------------
1143 ---------------------------------------------------------------------------*/
1144 OUString SwXTextView::getImplementationName(void) throw( RuntimeException )
1146 return C2U("SwXTextView");
1148 /* -----------------------------06.04.00 11:07--------------------------------
1150 ---------------------------------------------------------------------------*/
1151 BOOL SwXTextView::supportsService(const OUString& rServiceName) throw( RuntimeException )
1153 return rServiceName.equalsAscii("com.sun.star.text.TextDocumentView") ||
1154 rServiceName.equalsAscii("com.sun.star.view.OfficeDocumentView");
1156 /* -----------------------------06.04.00 11:07--------------------------------
1158 ---------------------------------------------------------------------------*/
1159 Sequence< OUString > SwXTextView::getSupportedServiceNames(void) throw( RuntimeException )
1161 Sequence< OUString > aRet(2);
1162 OUString* pArray = aRet.getArray();
1163 pArray[0] = C2U("com.sun.star.text.TextDocumentView");
1164 pArray[1] = C2U("com.sun.star.view.OfficeDocumentView");
1165 return aRet;
1168 /******************************************************************
1169 * SwXTextViewCursor
1170 ******************************************************************/
1171 /*-- 17.12.98 09:36:23---------------------------------------------------
1173 -----------------------------------------------------------------------*/
1174 SwXTextViewCursor::SwXTextViewCursor(SwView* pVw) :
1175 m_pView(pVw),
1176 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
1179 /*-- 17.12.98 09:36:24---------------------------------------------------
1181 -----------------------------------------------------------------------*/
1182 SwXTextViewCursor::~SwXTextViewCursor()
1185 /*-- 06.10.04 09:36:25---------------------------------------------------
1187 -----------------------------------------------------------------------*/
1189 // used to determine if there is a text selction or not.
1190 // If there is no text selection the functions that need a working
1191 // cursor will be disabled (throw RuntimeException). This will be the case
1192 // for the following interfaces:
1193 // - XViewCursor
1194 // - XTextCursor
1195 // - XTextRange
1196 // - XLineCursor
1198 sal_Bool SwXTextViewCursor::IsTextSelection( sal_Bool bAllowTables ) const
1201 sal_Bool bRes = sal_False;
1202 DBG_ASSERT(m_pView, "m_pView is NULL ???");
1203 if(m_pView)
1205 //! m_pView->GetShellMode() will only work after the shell
1206 //! has already changed and thus can not be used here!
1207 SelectionType eSelType = m_pView->GetWrtShell().GetSelectionType();
1208 bRes = ( (nsSelectionType::SEL_TXT & eSelType) ||
1209 (nsSelectionType::SEL_NUM & eSelType) ) &&
1210 (!(nsSelectionType::SEL_TBL_CELLS & eSelType) || bAllowTables);
1212 return bRes;
1215 /*-- 17.12.98 09:36:25---------------------------------------------------
1217 -----------------------------------------------------------------------*/
1218 sal_Bool SwXTextViewCursor::isVisible(void) throw( uno::RuntimeException )
1220 ::vos::OGuard aGuard(Application::GetSolarMutex());
1221 DBG_WARNING("not implemented");
1222 return sal_True;
1224 /*-- 17.12.98 09:36:25---------------------------------------------------
1226 -----------------------------------------------------------------------*/
1227 void SwXTextViewCursor::setVisible(sal_Bool /*bVisible*/) throw( uno::RuntimeException )
1229 ::vos::OGuard aGuard(Application::GetSolarMutex());
1230 DBG_WARNING("not implemented");
1232 /*-- 17.12.98 09:36:26---------------------------------------------------
1234 -----------------------------------------------------------------------*/
1235 awt::Point SwXTextViewCursor::getPosition(void) throw( uno::RuntimeException )
1237 ::vos::OGuard aGuard(Application::GetSolarMutex());
1238 awt::Point aRet;
1239 if(m_pView)
1241 const SwWrtShell& rSh = m_pView->GetWrtShell();
1242 const SwRect aCharRect(rSh.GetCharRect());
1244 const SwFrmFmt& rMaster = rSh.GetPageDesc( rSh.GetCurPageDesc() ).GetMaster();
1246 const SvxULSpaceItem& rUL = rMaster.GetULSpace();
1247 const long nY = aCharRect.Top() - (rUL.GetUpper() + DOCUMENTBORDER);
1248 aRet.Y = TWIP_TO_MM100(nY);
1250 const SvxLRSpaceItem& rLR = rMaster.GetLRSpace();
1251 const long nX = aCharRect.Left() - (rLR.GetLeft() + DOCUMENTBORDER);
1252 aRet.X = TWIP_TO_MM100(nX);
1254 else
1255 throw uno::RuntimeException();
1256 return aRet;
1258 /*-- 17.12.98 09:36:26---------------------------------------------------
1260 -----------------------------------------------------------------------*/
1261 void SwXTextViewCursor::collapseToStart(void) throw( uno::RuntimeException )
1263 ::vos::OGuard aGuard(Application::GetSolarMutex());
1264 if(m_pView)
1266 if (!IsTextSelection())
1267 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1269 SwWrtShell& rSh = m_pView->GetWrtShell();
1270 if(rSh.HasSelection())
1272 SwPaM* pShellCrsr = rSh.GetCrsr();
1273 if(*pShellCrsr->GetPoint() > *pShellCrsr->GetMark())
1274 pShellCrsr->Exchange();
1275 pShellCrsr->DeleteMark();
1276 rSh.EnterStdMode();
1277 rSh.SetSelection(*pShellCrsr);
1280 else
1281 throw uno::RuntimeException();
1283 /*-- 17.12.98 09:36:26---------------------------------------------------
1285 -----------------------------------------------------------------------*/
1286 void SwXTextViewCursor::collapseToEnd(void) throw( uno::RuntimeException )
1288 ::vos::OGuard aGuard(Application::GetSolarMutex());
1289 if(m_pView)
1291 if (!IsTextSelection())
1292 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1294 SwWrtShell& rSh = m_pView->GetWrtShell();
1295 if(rSh.HasSelection())
1297 SwPaM* pShellCrsr = rSh.GetCrsr();
1298 if(*pShellCrsr->GetPoint() < *pShellCrsr->GetMark())
1299 pShellCrsr->Exchange();
1300 pShellCrsr->DeleteMark();
1301 rSh.EnterStdMode();
1302 rSh.SetSelection(*pShellCrsr);
1305 else
1306 throw uno::RuntimeException();
1308 /*-- 17.12.98 09:36:27---------------------------------------------------
1310 -----------------------------------------------------------------------*/
1311 sal_Bool SwXTextViewCursor::isCollapsed(void) throw( uno::RuntimeException )
1313 ::vos::OGuard aGuard(Application::GetSolarMutex());
1314 sal_Bool bRet = sal_False;
1315 if(m_pView)
1317 if (!IsTextSelection())
1318 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1320 const SwWrtShell& rSh = m_pView->GetWrtShell();
1321 bRet = !rSh.HasSelection();
1323 else
1324 throw uno::RuntimeException();
1325 return bRet;
1328 /*-- 17.12.98 09:36:27---------------------------------------------------
1330 -----------------------------------------------------------------------*/
1331 sal_Bool SwXTextViewCursor::goLeft(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1333 ::vos::OGuard aGuard(Application::GetSolarMutex());
1334 sal_Bool bRet = sal_False;
1335 if(m_pView)
1337 if (!IsTextSelection())
1338 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1340 for( sal_uInt16 i = 0; i < nCount; i++ )
1341 bRet = m_pView->GetWrtShell().Left( CRSR_SKIP_CHARS, bExpand, 1, sal_True );
1343 else
1344 throw uno::RuntimeException();
1345 return bRet;
1347 /*-- 17.12.98 09:36:27---------------------------------------------------
1349 -----------------------------------------------------------------------*/
1350 sal_Bool SwXTextViewCursor::goRight(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1352 ::vos::OGuard aGuard(Application::GetSolarMutex());
1353 sal_Bool bRet = sal_False;
1354 if(m_pView)
1356 if (!IsTextSelection())
1357 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1359 for( sal_uInt16 i = 0; i < nCount; i++ )
1360 bRet = m_pView->GetWrtShell().Right( CRSR_SKIP_CHARS, bExpand, 1, sal_True );
1362 else
1363 throw uno::RuntimeException();
1364 return bRet;
1367 /* -----------------08.03.99 11:18-------------------
1369 * --------------------------------------------------*/
1370 void SwXTextViewCursor::gotoRange(
1371 const uno::Reference< text::XTextRange > & xRange,
1372 sal_Bool bExpand)
1373 throw(RuntimeException)
1375 ::vos::OGuard aGuard(Application::GetSolarMutex());
1376 if(m_pView && xRange.is())
1378 if (!IsTextSelection())
1379 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1381 SwUnoInternalPaM rDestPam(*m_pView->GetDocShell()->GetDoc());
1382 if(!SwXTextRange::XTextRangeToSwPaM( rDestPam, xRange))
1383 throw IllegalArgumentException();
1385 ShellModes eSelMode = m_pView->GetShellMode();
1386 SwWrtShell& rSh = m_pView->GetWrtShell();
1387 // call EnterStdMode in non-text selections only
1388 if(!bExpand ||
1389 (eSelMode != SHELL_MODE_TABLE_TEXT &&
1390 eSelMode != SHELL_MODE_LIST_TEXT &&
1391 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
1392 eSelMode != SHELL_MODE_TEXT ))
1393 rSh.EnterStdMode();
1394 SwPaM* pShellCrsr = rSh.GetCrsr();
1395 SwPaM aOwnPaM(*pShellCrsr->GetPoint());
1396 if(pShellCrsr->HasMark())
1398 aOwnPaM.SetMark();
1399 *aOwnPaM.GetMark() = *pShellCrsr->GetMark();
1402 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
1403 SwXTextRange* pRange = 0;
1404 SwXParagraph* pPara = 0;
1405 OTextCursorHelper* pCursor = 0;
1406 if(xRangeTunnel.is())
1408 pRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething(
1409 SwXTextRange::getUnoTunnelId()));
1410 pCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething(
1411 OTextCursorHelper::getUnoTunnelId()));
1412 pPara = reinterpret_cast<SwXParagraph*>(xRangeTunnel->getSomething(
1413 SwXParagraph::getUnoTunnelId()));
1416 const sal_uInt16 nFrmType = rSh.GetFrmType(0,sal_True);
1418 SwStartNodeType eSearchNodeType = SwNormalStartNode;
1419 if(nFrmType & FRMTYPE_FLY_ANY)
1420 eSearchNodeType = SwFlyStartNode;
1421 else if(nFrmType &FRMTYPE_HEADER)
1422 eSearchNodeType = SwHeaderStartNode;
1423 else if(nFrmType & FRMTYPE_FOOTER)
1424 eSearchNodeType = SwFooterStartNode;
1425 else if(nFrmType & FRMTYPE_TABLE)
1426 eSearchNodeType = SwTableBoxStartNode;
1427 else if(nFrmType & FRMTYPE_FOOTNOTE)
1428 eSearchNodeType = SwFootnoteStartNode;
1430 const SwStartNode* pOwnStartNode = aOwnPaM.GetNode()->
1431 FindSttNodeByType(eSearchNodeType);
1433 const SwNode* pSrcNode = 0;
1434 if(pCursor && pCursor->GetPaM())
1436 pSrcNode = pCursor->GetPaM()->GetNode();
1438 else if(pRange && pRange->GetBookmark())
1440 const ::sw::mark::IMark* const pBkmk = pRange->GetBookmark();
1441 pSrcNode = &(pBkmk->GetMarkPos().nNode.GetNode());
1443 else if (pPara && pPara->GetTxtNode())
1445 pSrcNode = pPara->GetTxtNode();
1447 const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindSttNodeByType(eSearchNodeType) : 0;
1449 //SectionNodes ueberspringen
1450 while(pTmp && pTmp->IsSectionNode())
1452 pTmp = pTmp->StartOfSectionNode();
1454 while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1456 pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1458 //ohne Expand darf mit dem ViewCursor ueberall hingesprungen werden
1459 //mit Expand nur in der gleichen Umgebung
1460 if(bExpand &&
1461 (pOwnStartNode != pTmp ||
1462 (eSelMode != SHELL_MODE_TABLE_TEXT &&
1463 eSelMode != SHELL_MODE_LIST_TEXT &&
1464 eSelMode != SHELL_MODE_TABLE_LIST_TEXT &&
1465 eSelMode != SHELL_MODE_TEXT)))
1466 throw uno::RuntimeException();
1468 //jetzt muss die Selektion erweitert werden
1469 if(bExpand)
1471 // der Cursor soll alles einschliessen, was bisher von ihm und dem uebergebenen
1472 // Range eingeschlossen wurde
1473 SwPosition aOwnLeft(*aOwnPaM.Start());
1474 SwPosition aOwnRight(*aOwnPaM.End());
1475 SwPosition* pParamLeft = rDestPam.Start();
1476 SwPosition* pParamRight = rDestPam.End();
1477 // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche?
1478 if(aOwnRight > *pParamRight)
1479 *aOwnPaM.GetPoint() = aOwnRight;
1480 else
1481 *aOwnPaM.GetPoint() = *pParamRight;
1482 aOwnPaM.SetMark();
1483 if(aOwnLeft < *pParamLeft)
1484 *aOwnPaM.GetMark() = aOwnLeft;
1485 else
1486 *aOwnPaM.GetMark() = *pParamLeft;
1488 else
1490 //der Cursor soll dem uebergebenen Range entsprechen
1491 *aOwnPaM.GetPoint() = *rDestPam.GetPoint();
1492 if(rDestPam.HasMark())
1494 aOwnPaM.SetMark();
1495 *aOwnPaM.GetMark() = *rDestPam.GetMark();
1497 else
1498 aOwnPaM.DeleteMark();
1500 rSh.SetSelection(aOwnPaM);
1502 else
1503 throw uno::RuntimeException();
1506 /*-- 17.12.98 09:36:28---------------------------------------------------
1508 -----------------------------------------------------------------------*/
1509 void SwXTextViewCursor::gotoStart(sal_Bool bExpand) throw( uno::RuntimeException )
1511 ::vos::OGuard aGuard(Application::GetSolarMutex());
1512 if(m_pView)
1514 if (!IsTextSelection())
1515 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1517 m_pView->GetWrtShell().SttDoc( bExpand );
1519 else
1520 throw uno::RuntimeException();
1522 /*-- 17.12.98 09:36:28---------------------------------------------------
1524 -----------------------------------------------------------------------*/
1525 void SwXTextViewCursor::gotoEnd(sal_Bool bExpand) throw( uno::RuntimeException )
1527 ::vos::OGuard aGuard(Application::GetSolarMutex());
1528 if(m_pView)
1530 if (!IsTextSelection())
1531 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1533 m_pView->GetWrtShell().EndDoc( bExpand );
1535 else
1536 throw uno::RuntimeException();
1538 /*-- 17.12.98 09:36:28---------------------------------------------------
1540 -----------------------------------------------------------------------*/
1541 sal_Bool SwXTextViewCursor::jumpToFirstPage(void) throw( uno::RuntimeException )
1543 ::vos::OGuard aGuard(Application::GetSolarMutex());
1544 sal_Bool bRet = sal_False;
1545 if(m_pView)
1547 SwWrtShell& rSh = m_pView->GetWrtShell();
1548 if (rSh.IsSelFrmMode())
1550 rSh.UnSelectFrm();
1551 rSh.LeaveSelFrmMode();
1553 rSh.EnterStdMode();
1554 bRet = rSh.SttEndDoc(TRUE);
1556 else
1557 throw uno::RuntimeException();
1558 return bRet;
1560 /*-- 17.12.98 09:36:29---------------------------------------------------
1562 -----------------------------------------------------------------------*/
1563 sal_Bool SwXTextViewCursor::jumpToLastPage(void) throw( uno::RuntimeException )
1565 ::vos::OGuard aGuard(Application::GetSolarMutex());
1566 sal_Bool bRet = sal_False;
1567 if(m_pView)
1569 SwWrtShell& rSh = m_pView->GetWrtShell();
1570 if (rSh.IsSelFrmMode())
1572 rSh.UnSelectFrm();
1573 rSh.LeaveSelFrmMode();
1575 rSh.EnterStdMode();
1576 bRet = rSh.SttEndDoc(FALSE);
1577 rSh.SttPg();
1579 else
1580 throw uno::RuntimeException();
1581 return bRet;
1583 /*-- 17.12.98 09:36:30---------------------------------------------------
1585 -----------------------------------------------------------------------*/
1586 sal_Bool SwXTextViewCursor::jumpToPage(sal_Int16 nPage) throw( uno::RuntimeException )
1588 ::vos::OGuard aGuard(Application::GetSolarMutex());
1589 sal_Bool bRet = sal_False;
1590 if(m_pView)
1591 bRet = m_pView->GetWrtShell().GotoPage(nPage, TRUE);
1592 else
1593 throw uno::RuntimeException();
1594 return bRet;
1596 /*-- 17.12.98 09:36:30---------------------------------------------------
1598 -----------------------------------------------------------------------*/
1599 sal_Bool SwXTextViewCursor::jumpToNextPage(void) throw( uno::RuntimeException )
1601 ::vos::OGuard aGuard(Application::GetSolarMutex());
1602 sal_Bool bRet = sal_False;
1603 if(m_pView)
1604 bRet = m_pView->GetWrtShell().SttNxtPg();
1605 else
1606 throw uno::RuntimeException();
1607 return bRet;
1609 /*-- 17.12.98 09:36:31---------------------------------------------------
1611 -----------------------------------------------------------------------*/
1612 sal_Bool SwXTextViewCursor::jumpToPreviousPage(void) throw( uno::RuntimeException )
1614 ::vos::OGuard aGuard(Application::GetSolarMutex());
1615 sal_Bool bRet = sal_False;
1616 if(m_pView)
1617 bRet = m_pView->GetWrtShell().EndPrvPg();
1618 else
1619 throw uno::RuntimeException();
1620 return bRet;
1622 /*-- 17.12.98 09:36:32---------------------------------------------------
1624 -----------------------------------------------------------------------*/
1625 sal_Bool SwXTextViewCursor::jumpToEndOfPage(void) throw( uno::RuntimeException )
1627 ::vos::OGuard aGuard(Application::GetSolarMutex());
1628 sal_Bool bRet = sal_False;
1629 if(m_pView)
1630 bRet = m_pView->GetWrtShell().EndPg();
1631 else
1632 throw uno::RuntimeException();
1633 return bRet;
1635 /*-- 17.12.98 09:36:32---------------------------------------------------
1637 -----------------------------------------------------------------------*/
1638 sal_Bool SwXTextViewCursor::jumpToStartOfPage(void) throw( uno::RuntimeException )
1640 ::vos::OGuard aGuard(Application::GetSolarMutex());
1641 sal_Bool bRet = sal_False;
1642 if(m_pView)
1643 bRet = m_pView->GetWrtShell().SttPg();
1644 else
1645 throw uno::RuntimeException();
1646 return bRet;
1648 /* -----------------04.10.99 14:21-------------------
1650 --------------------------------------------------*/
1651 sal_Int16 SwXTextViewCursor::getPage(void) throw( uno::RuntimeException )
1653 ::vos::OGuard aGuard(Application::GetSolarMutex());
1654 short nRet = 0;
1655 if(m_pView)
1657 SwWrtShell& rSh = m_pView->GetWrtShell();
1658 SwPaM* pShellCrsr = rSh.GetCrsr();
1659 nRet = (short)pShellCrsr->GetPageNum( TRUE, 0 );
1661 else
1662 throw uno::RuntimeException();
1663 return nRet;
1665 /*-- 17.12.98 09:36:33---------------------------------------------------
1667 -----------------------------------------------------------------------*/
1668 sal_Bool SwXTextViewCursor::screenDown(void) throw( uno::RuntimeException )
1670 ::vos::OGuard aGuard(Application::GetSolarMutex());
1671 sal_Bool bRet = sal_False;
1672 if(m_pView)
1674 SfxRequest aReq(FN_PAGEDOWN, SFX_CALLMODE_SLOT, m_pView->GetPool());
1675 m_pView->Execute(aReq);
1676 const SfxPoolItem* pRet = aReq.GetReturnValue();
1677 bRet = pRet && ((const SfxBoolItem*)pRet)->GetValue();
1679 else
1680 throw uno::RuntimeException();
1681 return bRet;
1683 /*-- 17.12.98 09:36:33---------------------------------------------------
1685 -----------------------------------------------------------------------*/
1686 sal_Bool SwXTextViewCursor::screenUp(void) throw( uno::RuntimeException )
1688 ::vos::OGuard aGuard(Application::GetSolarMutex());
1689 sal_Bool bRet = sal_False;
1690 if(m_pView)
1692 SfxRequest aReq(FN_PAGEUP, SFX_CALLMODE_SLOT, m_pView->GetPool());
1693 m_pView->Execute(aReq);
1694 const SfxPoolItem* pRet = aReq.GetReturnValue();
1695 bRet = pRet && ((const SfxBoolItem*)pRet)->GetValue();
1697 else
1698 throw uno::RuntimeException();
1699 return bRet;
1701 /*-- 17.12.98 11:59:05---------------------------------------------------
1703 -----------------------------------------------------------------------*/
1704 uno::Reference< text::XText > SwXTextViewCursor::getText(void) throw( uno::RuntimeException )
1706 ::vos::OGuard aGuard(Application::GetSolarMutex());
1707 uno::Reference< text::XText > xRet;
1708 if(m_pView)
1710 if (!IsTextSelection( sal_False ))
1711 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1713 SwWrtShell& rSh = m_pView->GetWrtShell();
1714 SwPaM* pShellCrsr = rSh.GetCrsr();
1715 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1716 uno::Reference< text::XTextRange > xRg = SwXTextRange::CreateTextRangeFromPosition(pDoc,
1717 *pShellCrsr->Start(), 0);
1718 xRet = xRg->getText();
1720 else
1721 throw uno::RuntimeException();
1722 return xRet;
1724 /*-- 17.12.98 11:59:05---------------------------------------------------
1726 -----------------------------------------------------------------------*/
1727 uno::Reference< text::XTextRange > SwXTextViewCursor::getStart(void) throw( uno::RuntimeException )
1729 ::vos::OGuard aGuard(Application::GetSolarMutex());
1730 uno::Reference< text::XTextRange > xRet;
1731 if(m_pView)
1733 if (!IsTextSelection())
1734 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1736 SwWrtShell& rSh = m_pView->GetWrtShell();
1737 SwPaM* pShellCrsr = rSh.GetCrsr();
1738 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1739 xRet = SwXTextRange::CreateTextRangeFromPosition(pDoc,
1740 *pShellCrsr->Start(), 0);
1742 else
1743 throw uno::RuntimeException();
1744 return xRet;
1746 /*-- 17.12.98 11:59:06---------------------------------------------------
1748 -----------------------------------------------------------------------*/
1749 uno::Reference< text::XTextRange > SwXTextViewCursor::getEnd(void) throw( uno::RuntimeException )
1751 ::vos::OGuard aGuard(Application::GetSolarMutex());
1752 uno::Reference< text::XTextRange > xRet;
1753 if(m_pView)
1755 if (!IsTextSelection())
1756 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1758 SwWrtShell& rSh = m_pView->GetWrtShell();
1759 SwPaM* pShellCrsr = rSh.GetCrsr();
1760 SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
1761 xRet = SwXTextRange::CreateTextRangeFromPosition(pDoc,
1762 *pShellCrsr->End(), 0);
1764 else
1765 throw uno::RuntimeException();
1766 return xRet;
1768 /* -----------------12.10.99 09:03-------------------
1770 --------------------------------------------------*/
1771 OUString SwXTextViewCursor::getString(void) throw( uno::RuntimeException )
1773 ::vos::OGuard aGuard(Application::GetSolarMutex());
1774 OUString uRet;
1775 if(m_pView)
1777 if (!IsTextSelection( sal_False ))
1778 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1780 ShellModes eSelMode = m_pView->GetShellMode();
1781 switch(eSelMode)
1783 //! since setString for SEL_TABLE_TEXT (with possible
1784 //! multi selection of cells) would not work properly we
1785 //! will ignore this case for both
1786 //! functions (setString AND getString) because of symmetrie.
1788 case SHELL_MODE_LIST_TEXT :
1789 case SHELL_MODE_TABLE_LIST_TEXT:
1790 case SHELL_MODE_TEXT :
1792 SwWrtShell& rSh = m_pView->GetWrtShell();
1793 SwPaM* pShellCrsr = rSh.GetCrsr();
1794 SwXTextCursor::getTextFromPam(*pShellCrsr, uRet);
1796 default:;//prevent warning
1799 return uRet;
1801 /*-- 17.12.98 11:59:06---------------------------------------------------
1803 -----------------------------------------------------------------------*/
1804 void SwXTextViewCursor::setString(const OUString& aString) throw( uno::RuntimeException )
1806 ::vos::OGuard aGuard(Application::GetSolarMutex());
1807 if(m_pView)
1809 if (!IsTextSelection( sal_False ))
1810 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1812 ShellModes eSelMode = m_pView->GetShellMode();
1813 switch(eSelMode)
1815 //! since setString for SEL_TABLE_TEXT (with possible
1816 //! multi selection of cells) would not work properly we
1817 //! will ignore this case for both
1818 //! functions (setString AND getString) because of symmetrie.
1820 case SHELL_MODE_LIST_TEXT :
1821 case SHELL_MODE_TABLE_LIST_TEXT :
1822 case SHELL_MODE_TEXT :
1824 SwWrtShell& rSh = m_pView->GetWrtShell();
1825 SwCursor* pShellCrsr = rSh.GetSwCrsr();
1826 SwXTextCursor::SetString( *pShellCrsr, aString );
1828 default:;//prevent warning
1833 /*-- 29.06.00 17:33:38---------------------------------------------------
1835 -----------------------------------------------------------------------*/
1836 uno::Reference< XPropertySetInfo > SwXTextViewCursor::getPropertySetInfo( ) throw(RuntimeException)
1838 static uno::Reference< XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
1839 return xRef;
1841 /*-- 29.06.00 17:33:39---------------------------------------------------
1843 -----------------------------------------------------------------------*/
1844 void SwXTextViewCursor::setPropertyValue( const OUString& rPropertyName, const Any& aValue )
1845 throw(UnknownPropertyException, PropertyVetoException,
1846 IllegalArgumentException, WrappedTargetException, RuntimeException)
1848 ::vos::OGuard aGuard(Application::GetSolarMutex());
1849 if(m_pView)
1851 SwWrtShell& rSh = m_pView->GetWrtShell();
1852 SwPaM* pShellCrsr = rSh.GetCrsr();
1853 SwNode *pNode = pShellCrsr->GetNode();
1854 if (pNode && pNode->IsTxtNode())
1855 SwXTextCursor::SetPropertyValue(*pShellCrsr, *m_pPropSet, rPropertyName, aValue );
1856 else
1857 throw RuntimeException();
1859 else
1860 throw RuntimeException();
1862 /*-- 29.06.00 17:33:39---------------------------------------------------
1864 -----------------------------------------------------------------------*/
1865 Any SwXTextViewCursor::getPropertyValue( const OUString& rPropertyName )
1866 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1868 ::vos::OGuard aGuard(Application::GetSolarMutex());
1869 Any aRet;
1870 if(m_pView)
1872 SwWrtShell& rSh = m_pView->GetWrtShell();
1873 SwPaM* pShellCrsr = rSh.GetCrsr();
1874 aRet = SwXTextCursor::GetPropertyValue( *pShellCrsr, *m_pPropSet, rPropertyName);
1876 else
1877 throw RuntimeException();
1878 return aRet;
1880 /*-- 29.06.00 17:33:40---------------------------------------------------
1882 -----------------------------------------------------------------------*/
1883 void SwXTextViewCursor::addPropertyChangeListener(
1884 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
1885 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1888 /*-- 29.06.00 17:33:40---------------------------------------------------
1890 -----------------------------------------------------------------------*/
1891 void SwXTextViewCursor::removePropertyChangeListener(
1892 const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ )
1893 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1896 /*-- 29.06.00 17:33:41---------------------------------------------------
1898 -----------------------------------------------------------------------*/
1899 void SwXTextViewCursor::addVetoableChangeListener(
1900 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1901 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1904 /*-- 29.06.00 17:33:41---------------------------------------------------
1906 -----------------------------------------------------------------------*/
1907 void SwXTextViewCursor::removeVetoableChangeListener(
1908 const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1911 /*-- 29.06.00 17:33:41---------------------------------------------------
1913 -----------------------------------------------------------------------*/
1914 PropertyState SwXTextViewCursor::getPropertyState( const OUString& rPropertyName )
1915 throw(UnknownPropertyException, RuntimeException)
1917 ::vos::OGuard aGuard(Application::GetSolarMutex());
1918 PropertyState eState;
1919 if(m_pView)
1921 SwWrtShell& rSh = m_pView->GetWrtShell();
1922 SwPaM* pShellCrsr = rSh.GetCrsr();
1923 eState = SwXTextCursor::GetPropertyState( *pShellCrsr, *m_pPropSet, rPropertyName);
1925 else
1926 throw RuntimeException();
1927 return eState;
1929 /*-- 29.06.00 17:33:42---------------------------------------------------
1931 -----------------------------------------------------------------------*/
1932 Sequence< PropertyState > SwXTextViewCursor::getPropertyStates(
1933 const Sequence< OUString >& rPropertyNames ) throw(UnknownPropertyException, RuntimeException)
1935 ::vos::OGuard aGuard(Application::GetSolarMutex());
1936 Sequence< PropertyState > aRet;
1937 if(m_pView)
1939 SwWrtShell& rSh = m_pView->GetWrtShell();
1940 SwPaM* pShellCrsr = rSh.GetCrsr();
1941 aRet = SwXTextCursor::GetPropertyStates(*pShellCrsr, *m_pPropSet, rPropertyNames);
1943 return aRet;
1945 /*-- 29.06.00 17:33:42---------------------------------------------------
1947 -----------------------------------------------------------------------*/
1948 void SwXTextViewCursor::setPropertyToDefault( const OUString& rPropertyName )
1949 throw(UnknownPropertyException, RuntimeException)
1951 ::vos::OGuard aGuard(Application::GetSolarMutex());
1952 if(m_pView)
1954 SwWrtShell& rSh = m_pView->GetWrtShell();
1955 SwPaM* pShellCrsr = rSh.GetCrsr();
1956 SwXTextCursor::SetPropertyToDefault( *pShellCrsr, *m_pPropSet, rPropertyName);
1959 /*-- 29.06.00 17:33:43---------------------------------------------------
1961 -----------------------------------------------------------------------*/
1962 Any SwXTextViewCursor::getPropertyDefault( const OUString& rPropertyName )
1963 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1965 Any aRet;
1966 ::vos::OGuard aGuard(Application::GetSolarMutex());
1967 if(m_pView)
1969 SwWrtShell& rSh = m_pView->GetWrtShell();
1970 SwPaM* pShellCrsr = rSh.GetCrsr();
1971 aRet = SwXTextCursor::GetPropertyDefault( *pShellCrsr, *m_pPropSet, rPropertyName);
1973 return aRet;
1975 /*-- 28.09.99 08:31:19---------------------------------------------------
1977 -----------------------------------------------------------------------*/
1978 sal_Bool SwXTextViewCursor::goDown(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1980 ::vos::OGuard aGuard(Application::GetSolarMutex());
1981 sal_Bool bRet = sal_False;
1982 if(m_pView)
1984 if (!IsTextSelection())
1985 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1987 for( sal_uInt16 i = 0; i < nCount; i++ )
1988 bRet = m_pView->GetWrtShell().Down( bExpand, 1, sal_True );
1990 else
1991 throw uno::RuntimeException();
1992 return bRet;
1994 /*-- 28.09.99 08:31:20---------------------------------------------------
1996 -----------------------------------------------------------------------*/
1997 sal_Bool SwXTextViewCursor::goUp(sal_Int16 nCount, sal_Bool bExpand) throw( uno::RuntimeException )
1999 ::vos::OGuard aGuard(Application::GetSolarMutex());
2000 sal_Bool bRet = sal_False;
2001 if(m_pView)
2003 if (!IsTextSelection())
2004 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
2006 for( sal_uInt16 i = 0; i < nCount; i++ )
2007 bRet = m_pView->GetWrtShell().Up( bExpand, 1, sal_True );
2009 else
2010 throw uno::RuntimeException();
2011 return bRet;
2013 /*-- 28.09.99 08:31:20---------------------------------------------------
2015 -----------------------------------------------------------------------*/
2016 sal_Bool SwXTextViewCursor::isAtStartOfLine(void) throw( uno::RuntimeException )
2018 ::vos::OGuard aGuard(Application::GetSolarMutex());
2019 sal_Bool bRet = sal_False;
2020 if(m_pView)
2022 if (!IsTextSelection( sal_False ))
2023 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
2025 bRet = m_pView->GetWrtShell().IsAtLeftMargin();
2027 else
2028 throw uno::RuntimeException();
2029 return bRet;
2031 /*-- 28.09.99 08:31:21---------------------------------------------------
2033 -----------------------------------------------------------------------*/
2034 sal_Bool SwXTextViewCursor::isAtEndOfLine(void) throw( uno::RuntimeException )
2036 ::vos::OGuard aGuard(Application::GetSolarMutex());
2037 sal_Bool bRet = sal_False;
2038 if(m_pView)
2040 if (!IsTextSelection( sal_False ))
2041 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
2043 bRet = m_pView->GetWrtShell().IsAtRightMargin(sal_True);
2045 else
2046 throw uno::RuntimeException();
2047 return bRet;
2049 /*-- 28.09.99 08:31:21---------------------------------------------------
2051 -----------------------------------------------------------------------*/
2052 void SwXTextViewCursor::gotoEndOfLine(sal_Bool bExpand) throw( uno::RuntimeException )
2054 ::vos::OGuard aGuard(Application::GetSolarMutex());
2055 if(m_pView)
2057 if (!IsTextSelection( sal_False ))
2058 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
2060 m_pView->GetWrtShell().RightMargin(bExpand, sal_True);
2062 else
2063 throw uno::RuntimeException();
2065 /*-- 28.09.99 08:31:22---------------------------------------------------
2067 -----------------------------------------------------------------------*/
2068 void SwXTextViewCursor::gotoStartOfLine(sal_Bool bExpand) throw( uno::RuntimeException )
2070 ::vos::OGuard aGuard(Application::GetSolarMutex());
2071 if(m_pView)
2073 if (!IsTextSelection( sal_False ))
2074 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), static_cast < cppu::OWeakObject * > ( this ) );
2076 m_pView->GetWrtShell().LeftMargin(bExpand, sal_True);
2078 else
2079 throw uno::RuntimeException();
2081 /* -----------------------------06.04.00 11:07--------------------------------
2083 ---------------------------------------------------------------------------*/
2084 OUString SwXTextViewCursor::getImplementationName(void) throw( RuntimeException )
2086 return C2U("SwXTextViewCursor");
2088 /* -----------------------------06.04.00 11:07--------------------------------
2090 ---------------------------------------------------------------------------*/
2091 BOOL SwXTextViewCursor::supportsService(const OUString& rServiceName) throw( RuntimeException )
2093 return !rServiceName.compareToAscii("com.sun.star.text.TextViewCursor") ||
2094 !rServiceName.compareToAscii("com.sun.star.style.CharacterProperties") ||
2095 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesAsian") ||
2096 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesComplex") ||
2097 !rServiceName.compareToAscii("com.sun.star.style.ParagraphProperties") ||
2098 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesAsian") ||
2099 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesComplex");
2101 /* -----------------------------06.04.00 11:07--------------------------------
2103 ---------------------------------------------------------------------------*/
2104 Sequence< OUString > SwXTextViewCursor::getSupportedServiceNames(void) throw( RuntimeException )
2106 Sequence< OUString > aRet(7);
2107 OUString* pArray = aRet.getArray();
2108 pArray[0] = C2U("com.sun.star.text.TextViewCursor");
2109 pArray[1] = C2U("com.sun.star.style.CharacterProperties");
2110 pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
2111 pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
2112 pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
2113 pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
2114 pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
2115 return aRet;
2117 /* -----------------------------03.03.03 11:07--------------------------------
2119 ---------------------------------------------------------------------------*/
2120 const uno::Sequence< sal_Int8 > & SwXTextViewCursor::getUnoTunnelId()
2122 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
2123 return aSeq;
2125 /* -----------------------------03.03.03 11:07--------------------------------
2127 ---------------------------------------------------------------------------*/
2128 //XUnoTunnel
2129 sal_Int64 SAL_CALL SwXTextViewCursor::getSomething(
2130 const uno::Sequence< sal_Int8 >& rId )
2131 throw(uno::RuntimeException)
2133 if( rId.getLength() == 16
2134 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2135 rId.getConstArray(), 16 ) )
2137 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
2139 return OTextCursorHelper::getSomething(rId);;
2141 // -----------------------------------------------------------------------------
2143 IMPLEMENT_FORWARD_XINTERFACE2(SwXTextViewCursor,SwXTextViewCursor_Base,OTextCursorHelper)
2144 const SwDoc* SwXTextViewCursor::GetDoc() const
2146 SwWrtShell& rSh = m_pView->GetWrtShell();
2147 return rSh.GetCrsr() ? rSh.GetCrsr()->GetDoc() : 0;
2149 // -----------------------------------------------------------------------------
2150 SwDoc* SwXTextViewCursor::GetDoc()
2152 SwWrtShell& rSh = m_pView->GetWrtShell();
2153 return rSh.GetCrsr() ? rSh.GetCrsr()->GetDoc() : 0;
2155 // -----------------------------------------------------------------------------
2156 const SwPaM* SwXTextViewCursor::GetPaM() const
2158 SwWrtShell& rSh = m_pView->GetWrtShell();
2159 return rSh.GetCrsr();
2161 // -----------------------------------------------------------------------------
2162 SwPaM* SwXTextViewCursor::GetPaM()
2164 SwWrtShell& rSh = m_pView->GetWrtShell();
2165 return rSh.GetCrsr();
2168 uno::Reference< datatransfer::XTransferable > SAL_CALL SwXTextView::getTransferable( ) throw (uno::RuntimeException)
2170 ::vos::OGuard aGuard(Application::GetSolarMutex());
2172 //force immediat shell update
2173 GetView()->StopShellTimer();
2174 SwWrtShell& rSh = GetView()->GetWrtShell();
2175 if ( GetView()->GetShellMode() == SHELL_MODE_DRAWTEXT )
2177 SdrView *pSdrView = rSh.GetDrawView();
2178 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
2179 return pOLV->GetEditView().GetTransferable();
2181 else
2183 SwTransferable* pTransfer = new SwTransferable( rSh );
2184 const BOOL bLockedView = rSh.IsViewLocked();
2185 rSh.LockView( TRUE ); //lock visible section
2186 pTransfer->PrepareForCopy();
2187 rSh.LockView( bLockedView );
2188 return uno::Reference< datatransfer::XTransferable >( pTransfer );
2192 void SAL_CALL SwXTextView::insertTransferable( const uno::Reference< datatransfer::XTransferable >& xTrans ) throw (datatransfer::UnsupportedFlavorException, uno::RuntimeException)
2194 ::vos::OGuard aGuard(Application::GetSolarMutex());
2196 //force immediat shell update
2197 GetView()->StopShellTimer();
2198 SwWrtShell& rSh = GetView()->GetWrtShell();
2199 if ( GetView()->GetShellMode() == SHELL_MODE_DRAWTEXT )
2201 SdrView *pSdrView = rSh.GetDrawView();
2202 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
2203 pOLV->GetEditView().InsertText( xTrans, GetView()->GetDocShell()->GetMedium()->GetBaseURL(), FALSE );
2205 else
2207 TransferableDataHelper aDataHelper( xTrans );
2208 if ( SwTransferable::IsPaste( rSh, aDataHelper ) )
2210 SwTransferable::Paste( rSh, aDataHelper );
2211 if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
2212 rSh.EnterSelFrmMode();
2213 GetView()->AttrChangedNotify( &rSh );
2217 // -----------------------------------------------------------------------------