1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "notesuno.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <svl/smplhint.hxx> 34*cdf0e10cSrcweir #include <editeng/unotext.hxx> 35*cdf0e10cSrcweir #include <svx/svdpool.hxx> 36*cdf0e10cSrcweir #include <svx/svdobj.hxx> 37*cdf0e10cSrcweir #include <svx/unoshape.hxx> 38*cdf0e10cSrcweir #include <svx/svdocapt.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include "postit.hxx" 41*cdf0e10cSrcweir #include "cellsuno.hxx" 42*cdf0e10cSrcweir #include "docsh.hxx" 43*cdf0e10cSrcweir #include "docfunc.hxx" 44*cdf0e10cSrcweir #include "hints.hxx" 45*cdf0e10cSrcweir #include "editsrc.hxx" 46*cdf0e10cSrcweir #include "miscuno.hxx" 47*cdf0e10cSrcweir #include "unoguard.hxx" 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace com::sun::star; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //------------------------------------------------------------------------ 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // keine Properties fuer Text in Notizen 54*cdf0e10cSrcweir const SvxItemPropertySet* lcl_GetAnnotationPropertySet() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir static SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] = 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir {0,0,0,0,0,0} 59*cdf0e10cSrcweir }; 60*cdf0e10cSrcweir static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() ); 61*cdf0e10cSrcweir return &aAnnotationPropertySet_Impl; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //------------------------------------------------------------------------ 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" ) 67*cdf0e10cSrcweir //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" ) 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //------------------------------------------------------------------------ 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) : 72*cdf0e10cSrcweir pDocShell( pDocSh ), 73*cdf0e10cSrcweir aCellPos( rPos ), 74*cdf0e10cSrcweir pUnoText( NULL ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // pUnoText is allocated on demand (GetUnoText) 79*cdf0e10cSrcweir // can't be aggregated because getString/setString is handled here 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir ScAnnotationObj::~ScAnnotationObj() 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir if (pDocShell) 85*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir if (pUnoText) 88*cdf0e10cSrcweir pUnoText->release(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir if ( rHint.ISA( ScUpdateRefHint ) ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //! Ref-Update 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir else if ( rHint.ISA( SfxSimpleHint ) && 100*cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // XChild 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent() throw(uno::RuntimeException) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ScUnoGuard aGuard; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // Parent der Notiz ist die zugehoerige Zelle 114*cdf0e10cSrcweir //! existierendes Objekt finden und zurueckgeben ??? 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if (pDocShell) 117*cdf0e10cSrcweir return (cppu::OWeakObject*)new ScCellObj( pDocShell, aCellPos ); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir return NULL; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ ) 123*cdf0e10cSrcweir throw(lang::NoSupportException, uno::RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir // hamma nich 126*cdf0e10cSrcweir //! Exception oder so ??! 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // XSimpleText 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor() 132*cdf0e10cSrcweir throw(uno::RuntimeException) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir ScUnoGuard aGuard; 135*cdf0e10cSrcweir // Notizen brauchen keine Extrawurst 136*cdf0e10cSrcweir return GetUnoText().createTextCursor(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange( 140*cdf0e10cSrcweir const uno::Reference<text::XTextRange>& aTextPosition ) 141*cdf0e10cSrcweir throw(uno::RuntimeException) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir ScUnoGuard aGuard; 144*cdf0e10cSrcweir // Notizen brauchen keine Extrawurst 145*cdf0e10cSrcweir return GetUnoText().createTextCursorByRange(aTextPosition); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getString() throw(uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ScUnoGuard aGuard; 151*cdf0e10cSrcweir return GetUnoText().getString(); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir ScUnoGuard aGuard; 157*cdf0e10cSrcweir GetUnoText().setString(aText); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange, 161*cdf0e10cSrcweir const rtl::OUString& aString, sal_Bool bAbsorb ) 162*cdf0e10cSrcweir throw(uno::RuntimeException) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir ScUnoGuard aGuard; 165*cdf0e10cSrcweir GetUnoText().insertString( xRange, aString, bAbsorb ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange, 169*cdf0e10cSrcweir sal_Int16 nControlCharacter, sal_Bool bAbsorb ) 170*cdf0e10cSrcweir throw(lang::IllegalArgumentException, uno::RuntimeException) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir ScUnoGuard aGuard; 173*cdf0e10cSrcweir GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText() throw(uno::RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir ScUnoGuard aGuard; 179*cdf0e10cSrcweir return GetUnoText().getText(); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart() throw(uno::RuntimeException) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir ScUnoGuard aGuard; 185*cdf0e10cSrcweir return GetUnoText().getStart(); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd() throw(uno::RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir ScUnoGuard aGuard; 191*cdf0e10cSrcweir return GetUnoText().getEnd(); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // XSheetAnnotation 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir table::CellAddress SAL_CALL ScAnnotationObj::getPosition() throw(uno::RuntimeException) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir ScUnoGuard aGuard; 199*cdf0e10cSrcweir table::CellAddress aAdr; 200*cdf0e10cSrcweir aAdr.Sheet = aCellPos.Tab(); 201*cdf0e10cSrcweir aAdr.Column = aCellPos.Col(); 202*cdf0e10cSrcweir aAdr.Row = aCellPos.Row(); 203*cdf0e10cSrcweir return aAdr; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getAuthor() throw(uno::RuntimeException) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir ScUnoGuard aGuard; 209*cdf0e10cSrcweir const ScPostIt* pNote = ImplGetNote(); 210*cdf0e10cSrcweir return pNote ? pNote->GetAuthor() : rtl::OUString(); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir rtl::OUString SAL_CALL ScAnnotationObj::getDate() throw(uno::RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir ScUnoGuard aGuard; 216*cdf0e10cSrcweir const ScPostIt* pNote = ImplGetNote(); 217*cdf0e10cSrcweir return pNote ? pNote->GetDate() : rtl::OUString(); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir sal_Bool SAL_CALL ScAnnotationObj::getIsVisible() throw(uno::RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir ScUnoGuard aGuard; 223*cdf0e10cSrcweir const ScPostIt* pNote = ImplGetNote(); 224*cdf0e10cSrcweir return pNote && pNote->IsCaptionShown(); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible ) throw(uno::RuntimeException) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir ScUnoGuard aGuard; 230*cdf0e10cSrcweir // show/hide note with undo action 231*cdf0e10cSrcweir if( pDocShell ) 232*cdf0e10cSrcweir pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // XSheetAnnotationShapeSupplier 236*cdf0e10cSrcweir uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape() 237*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir ScUnoGuard aGuard; 240*cdf0e10cSrcweir uno::Reference < drawing::XShape > xShape; 241*cdf0e10cSrcweir if( const ScPostIt* pNote = ImplGetNote() ) 242*cdf0e10cSrcweir if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) ) 243*cdf0e10cSrcweir xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY ); 244*cdf0e10cSrcweir return xShape; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir SvxUnoText& ScAnnotationObj::GetUnoText() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir if (!pUnoText) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir ScAnnotationEditSource aEditSource( pDocShell, aCellPos ); 252*cdf0e10cSrcweir pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(), 253*cdf0e10cSrcweir uno::Reference<text::XText>() ); 254*cdf0e10cSrcweir pUnoText->acquire(); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir return *pUnoText; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir const ScPostIt* ScAnnotationObj::ImplGetNote() const 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir return pDocShell ? pDocShell->GetDocument()->GetNote( aCellPos ) : 0; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir //------------------------------------------------------------------------ 265