merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / wrtsh / wrtsh1.cxx
blobe50d1b63e052ed5d6dda5d8e8411a13f2aced2d0
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: wrtsh1.cxx,v $
10 * $Revision: 1.72 $
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"
33 #include <com/sun/star/container/XChild.hpp>
34 #include <com/sun/star/embed/XVisualObject.hpp>
35 #include <com/sun/star/embed/EmbedMisc.hpp>
36 #include <com/sun/star/embed/EmbedStates.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
39 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #if STLPORT_VERSION>=321
42 #include <math.h> // prevent conflict between exception and std::exception
43 #endif
44 #include <hintids.hxx>
45 #include <svx/svdview.hxx>
46 #include <sot/factory.hxx>
47 #include <svtools/itemiter.hxx>
48 #ifndef _SOUND_HXX //autogen
49 #include <vcl/sound.hxx>
50 #endif
51 #include <tools/bigint.hxx>
52 #include <sot/storage.hxx>
53 #include <svtools/insdlg.hxx>
54 #include <sfx2/frmdescr.hxx>
55 #include <sfx2/ipclient.hxx>
56 #include <svtools/ehdl.hxx>
57 #include <svtools/soerr.hxx>
58 #include <tools/cachestr.hxx>
59 #include <svtools/moduleoptions.hxx>
60 #include <svx/sizeitem.hxx>
61 #include <svx/brkitem.hxx>
62 #include <svx/svxacorr.hxx>
63 #include <vcl/graph.hxx>
64 #include <svx/impgrf.hxx>
65 #include <sfx2/printer.hxx>
66 #include <unotools/charclass.hxx>
68 #include <comphelper/storagehelper.hxx>
69 #include <svx/svxdlg.hxx>
70 #include <svx/extrusionbar.hxx>
71 #include <svx/fontworkbar.hxx>
72 #include <fmtftn.hxx>
73 #include <fmtpdsc.hxx>
74 #ifndef _WDOCSH_HXX
75 #include <wdocsh.hxx>
76 #endif
77 #ifndef _BASESH_HXX
78 #include <basesh.hxx>
79 #endif
80 #include <swmodule.hxx>
81 #include <wrtsh.hxx>
82 #ifndef _VIEW_HXX
83 #include <view.hxx>
84 #endif
85 #include <uitool.hxx>
86 #ifndef _CMDID_H
87 #include <cmdid.h>
88 #endif
89 #include <pagedesc.hxx>
90 #include <frmmgr.hxx>
91 #include <shellio.hxx>
92 #include <uinums.hxx> // fuer Anwenden einer
93 #include <swundo.hxx> // fuer Undo-Ids
94 #include <swcli.hxx>
95 #include <poolfmt.hxx>
96 #ifndef _WVIEW_HXX
97 #include <wview.hxx>
98 #endif
99 #include <edtwin.hxx>
100 #include <fmtcol.hxx>
101 #include <swtable.hxx>
102 #include <caption.hxx>
103 #include <viscrs.hxx>
104 #include <swdtflvr.hxx>
105 #include <crsskip.hxx>
106 #include <doc.hxx>
107 #ifndef _WRTSH_HRC
108 #include <wrtsh.hrc>
109 #endif
110 #include <SwStyleNameMapper.hxx>
111 #include <sfx2/request.hxx>
112 #include <paratr.hxx>
113 #include <ndtxt.hxx>
114 #include <svx/acorrcfg.hxx>
115 #include <IMark.hxx>
117 // -> #111827#
118 #include <SwRewriter.hxx>
119 #include <comcore.hrc>
120 #include <undobj.hxx>
121 // <- #111827#
123 #include <toolkit/helper/vclunohelper.hxx>
124 #include <sfx2/viewfrm.hxx>
126 #include <svx/acorrcfg.hxx>
128 #include "PostItMgr.hxx"
130 using namespace sw::mark;
131 using namespace com::sun::star;
133 #define COMMON_INI_LIST \
134 fnDrag(&SwWrtShell::BeginDrag),\
135 fnSetCrsr(&SwWrtShell::SetCrsr),\
136 fnEndDrag(&SwWrtShell::EndDrag),\
137 fnKillSel(&SwWrtShell::Ignore),\
138 pModeStack(0), \
139 ePageMove(MV_NO),\
140 pCrsrStack(0), \
141 rView(rShell),\
142 bDestOnStack(FALSE), \
143 fnLeaveSelect(&SwWrtShell::SttLeaveSelect)
145 #define BITFLD_INI_LIST \
146 bClearMark = \
147 bIns = TRUE;\
148 bAddMode = \
149 bBlockMode = \
150 bExtMode = \
151 bInSelect = \
152 bCopy = \
153 bLayoutMode = \
154 bNoEdit = \
155 bSelWrd = \
156 bSelLn = \
157 bIsInClickToEdit = \
158 mbRetainSelection = FALSE;
161 SvxAutoCorrect* lcl_IsAutoCorr()
163 SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get()->GetAutoCorrect();
164 if( pACorr && !pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
165 ChgFractionSymbol | ChgOrdinalNumber |
166 ChgToEnEmDash | SetINetAttr | Autocorrect ))
167 pACorr = 0;
168 return pACorr;
171 void SwWrtShell::NoEdit(BOOL bHideCrsr)
173 if(bHideCrsr)
174 HideCrsr();
175 bNoEdit = TRUE;
180 void SwWrtShell::Edit()
182 if (CanInsert())
184 ShowCrsr();
185 bNoEdit = FALSE;
191 BOOL SwWrtShell::IsEndWrd()
193 MV_KONTEXT(this);
194 if(IsEndPara() && !IsSttPara())
195 return TRUE;
197 return IsEndWord();
201 /*------------------------------------------------------------------------
202 Beschreibung: Abfrage, ob Einfuegen moeglich ist; gfs. Beep
203 ------------------------------------------------------------------------*/
207 BOOL SwWrtShell::_CanInsert()
209 if(!CanInsert())
211 Sound::Beep();
212 return FALSE;
214 return TRUE;
216 /*------------------------------------------------------------------------
217 Beschreibung: String einfuegen
218 ------------------------------------------------------------------------*/
220 void SwWrtShell::InsertByWord( const String & rStr)
222 if( rStr.Len() )
224 BOOL bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 );
225 xub_StrLen nPos = 0, nStt = 0;
226 for( ; nPos < rStr.Len(); nPos++ )
228 BOOL bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos );
229 if( bTmpDelim != bDelim )
231 Insert( rStr.Copy( nStt, nPos - nStt ));
232 nStt = nPos;
235 if( nStt != nPos )
236 Insert( rStr.Copy( nStt, nPos - nStt ));
241 void SwWrtShell::Insert( const String &rStr )
243 ResetCursorStack();
244 if( !_CanInsert() )
245 return;
247 BOOL bStarted = FALSE, bHasSel = HasSelection(),
248 bCallIns = bIns /*|| bHasSel*/;
249 bool bDeleted = false;
251 if( bHasSel || ( !bIns && SelectHiddenRange() ) )
253 // nur hier klammern, da das normale Insert schon an der
254 // Editshell geklammert ist
255 StartAllAction();
257 // #111827#
258 SwRewriter aRewriter;
260 aRewriter.AddRule(UNDO_ARG1, GetCrsrDescr());
261 aRewriter.AddRule(UNDO_ARG2, String(SW_RES(STR_YIELDS)));
263 String aTmpStr;
264 aTmpStr += String(SW_RES(STR_START_QUOTE));
265 aTmpStr += rStr;
266 aTmpStr += String(SW_RES(STR_END_QUOTE));
268 aRewriter.AddRule(UNDO_ARG3, rStr);
271 StartUndo(UNDO_REPLACE, &aRewriter);
272 bStarted = TRUE;
273 bDeleted = DelRight() != 0;
277 JP 21.01.98: Ueberschreiben ueberschreibt nur die Selektion, nicht das
278 naechste Zeichen.
279 if( bHasSel && !bIns && 1 < rStr.Len() )
281 // falls mehrere Zeichen anstehen, nur das erste einfuegen,
282 // der Rest muss dann aber Ueberschrieben werden.
283 SwEditShell::Insert( rStr.GetChar( 0 ) );
284 SwEditShell::Overwrite( rStr.Copy( 1 ) );
286 else
288 bCallIns ?
289 SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr );
292 if( bStarted )
294 EndAllAction();
295 EndUndo(UNDO_REPLACE);
297 // delete pChgFlg;
300 /* Begrenzung auf maximale Hoehe geht nicht, da die maximale Hoehe
301 * des aktuellen Frames nicht erfragt werden kann. */
305 void SwWrtShell::Insert( const String &rPath, const String &rFilter,
306 const Graphic &rGrf, SwFlyFrmAttrMgr *pFrmMgr,
307 BOOL bRule )
309 ResetCursorStack();
310 if ( !_CanInsert() )
311 return;
313 StartAllAction();
315 SwRewriter aRewriter;
316 aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_GRAPHIC));
318 StartUndo(UNDO_INSERT, &aRewriter);
320 if ( HasSelection() )
321 DelRight();
322 // eingefuegte Grafik in eigenen Absatz, falls am Ende
323 // eines nichtleeren Absatzes
324 if ( IsEndPara() && !IsSttPara() )
325 SwFEShell::SplitNode();
327 EnterSelFrmMode();
329 BOOL bSetGrfSize = TRUE;
330 BOOL bOwnMgr = FALSE;
332 if ( !pFrmMgr )
334 bOwnMgr = TRUE;
335 pFrmMgr = new SwFlyFrmAttrMgr( TRUE, this, FRMMGR_TYPE_GRF );
337 // VORSICHT
338 // GetAttrSet nimmt einen Abgleich vor
339 // Beim Einfuegen ist eine SwFrmSize vorhanden wegen der
340 // DEF-Rahmengroesse
341 // Diese muss fuer die optimale Groesse explizit entfernt werden
342 pFrmMgr->DelAttr(RES_FRM_SIZE);
344 else
346 Size aSz( pFrmMgr->GetSize() );
347 if ( !aSz.Width() || !aSz.Height() )
349 aSz.Width() = aSz.Height() = 567;
350 pFrmMgr->SetSize( aSz );
352 else if ( aSz.Width() != DFLT_WIDTH && aSz.Height() != DFLT_HEIGHT )
353 bSetGrfSize = FALSE;
355 pFrmMgr->SetHeightSizeType(ATT_FIX_SIZE);
359 // Einfuegen der Grafik
360 SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrmMgr->GetAttrSet());
361 if ( bOwnMgr )
362 pFrmMgr->UpdateAttrMgr();
364 if( bSetGrfSize && !bRule )
366 Size aGrfSize, aBound = GetGraphicDefaultSize();
367 GetGrfSize( aGrfSize );
369 //Die GrafikSize noch um die Randattribute vergroessern, denn die
370 //Zaehlen beim Rahmen mit.
371 aGrfSize.Width() += pFrmMgr->CalcWidthBorder();
372 aGrfSize.Height()+= pFrmMgr->CalcHeightBorder();
374 const BigInt aTempWidth( aGrfSize.Width() );
375 const BigInt aTempHeight( aGrfSize.Height());
377 // ggf. Breite anpassen, Hoehe dann proportional verkleinern
378 if( aGrfSize.Width() > aBound.Width() )
380 aGrfSize.Width() = aBound.Width();
381 aGrfSize.Height() = ((BigInt)aBound.Width()) * aTempHeight / aTempWidth;
383 // ggf. Hoehe anpassen, Breite dann proportional verkleinern
384 if( aGrfSize.Height() > aBound.Height() )
386 aGrfSize.Height() = aBound.Height();
387 aGrfSize.Width() = ((BigInt)aBound.Height()) * aTempWidth / aTempHeight;
389 pFrmMgr->SetSize( aGrfSize );
390 pFrmMgr->UpdateFlyFrm();
392 if ( bOwnMgr )
393 delete pFrmMgr;
395 EndUndo(UNDO_INSERT);
396 EndAllAction();
400 /*------------------------------------------------------------------------
401 Beschreibung: Fuegt ein OLE-Objekt in die CORE ein.
402 Wenn kein Object uebergeben wird, so wird eins erzeugt.
403 ------------------------------------------------------------------------*/
406 void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName *pName,
407 BOOL bActivate, USHORT nSlotId )
409 ResetCursorStack();
410 if( !_CanInsert() )
411 return;
413 if( !xRef.is() )
415 // temporary storage
416 svt::EmbeddedObjectRef xObj;
417 uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetTemporaryStorage();
418 BOOL bDoVerb = TRUE;
419 if ( pName )
421 comphelper::EmbeddedObjectContainer aCnt( xStor );
422 ::rtl::OUString aName;
423 // TODO/LATER: get aspect?
424 xObj.Assign( aCnt.CreateEmbeddedObject( pName->GetByteSequence(), aName ), embed::Aspects::MSOLE_CONTENT );
426 else
428 SvObjectServerList aServerList;
429 switch (nSlotId)
431 case SID_INSERT_OBJECT:
433 aServerList.FillInsertObjects();
434 aServerList.Remove( SwDocShell::Factory().GetClassId() );
435 // Intentionally no break!
438 // TODO/LATER: recording! Convert properties to items
439 case SID_INSERT_PLUGIN:
441 if(pReq)
443 INetURLObject* pURL = aDlg.GetURL();
444 if(pURL)
445 pReq->AppendItem(SfxStringItem(FN_PARAM_2, pURL->GetMainURL(INetURLObject::NO_DECODE)));
446 pReq->AppendItem(SfxStringItem(FN_PARAM_3 , aDlg.GetCommands()));
447 } */
448 case SID_INSERT_APPLET:
450 if(pReq)
452 SvAppletObjectRef xApplet ( xIPObj );
453 if(xApplet.Is())
454 pReq->AppendItem(SfxStringItem(FN_PARAM_1 , xApplet->GetCodeBase()));
455 pReq->AppendItem(SfxStringItem(FN_PARAM_2 , aDlg.GetClass()));
456 pReq->AppendItem(SfxStringItem(FN_PARAM_3 , aDlg.GetCommands()));
458 case SID_INSERT_FLOATINGFRAME:
460 if(pReq && xFloatingFrame.Is())
462 const SfxFrameDescriptor* pDescriptor = xFloatingFrame->GetFrameDescriptor();
463 pReq->AppendItem(SfxStringItem(FN_PARAM_1, pDescriptor->GetName()));
464 pReq->AppendItem(
465 SfxStringItem( FN_PARAM_2,
466 pDescriptor->GetURL().GetMainURL(INetURLObject::NO_DECODE)));
467 pReq->AppendItem(SvxSizeItem(FN_PARAM_3, pDescriptor->GetMargin()));
468 pReq->AppendItem(SfxByteItem(FN_PARAM_4, pDescriptor->GetScrollingMode()));
469 pReq->AppendItem(SfxBoolItem(FN_PARAM_5, pDescriptor->HasFrameBorder()));
472 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
473 SfxAbstractInsertObjectDialog* pDlg =
474 pFact->CreateInsertObjectDialog( GetWin(), nSlotId, xStor, &aServerList );
475 if ( pDlg )
477 pDlg->Execute();
478 bDoVerb = pDlg->IsCreateNew();
479 ::rtl::OUString aIconMediaType;
480 uno::Reference< io::XInputStream > xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
481 xObj.Assign( pDlg->GetObject(),
482 xIconMetaFile.is() ? embed::Aspects::MSOLE_ICON : embed::Aspects::MSOLE_CONTENT );
483 if ( xIconMetaFile.is() )
484 xObj.SetGraphicStream( xIconMetaFile, aIconMediaType );
486 DELETEZ( pDlg );
489 break;
492 default:
493 break;
497 if ( xObj.is() )
499 if( InsertOleObject( xObj ) && bActivate && bDoVerb )
501 SfxInPlaceClient* pClient = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
502 if ( !pClient )
504 pClient = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
505 SetCheckForOLEInCaption( TRUE );
508 if ( xObj.GetViewAspect() == embed::Aspects::MSOLE_ICON )
510 SwRect aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
511 aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
512 MapMode aMapMode( MAP_TWIP );
513 Size aSize = xObj.GetSize( &aMapMode );
514 aArea.Width( aSize.Width() );
515 aArea.Height( aSize.Height() );
516 RequestObjectResize( aArea, xObj.GetObject() );
518 else
519 CalcAndSetScale( xObj );
521 //#50270# Error brauchen wir nicht handeln, das erledigt das
522 //DoVerb in der SfxViewShell
523 pClient->DoVerb( SVVERB_SHOW );
525 // TODO/LATER: set document name - should be done in Client
526 //if ( !ERRCODE_TOERROR( nErr ) )
527 // xIPObj->SetDocumentName( GetView().GetDocShell()->GetTitle() );
531 else
533 if( HasSelection() )
534 DelRight();
535 InsertOleObject( xRef );
539 /*------------------------------------------------------------------------
540 Beschreibung: Object in die Core einfuegen.
541 Vom ClipBoard oder Insert
542 ------------------------------------------------------------------------*/
544 BOOL SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef& xRef, SwFlyFrmFmt **pFlyFrmFmt )
546 ResetCursorStack();
547 StartAllAction();
549 StartUndo(UNDO_INSERT);
551 //Some differences between StarMath and any other objects:
552 //1. Selections should be deleted. For StarMath the Text should be
553 // passed to the Object
554 //2. If the cursor is at the end of an non empty paragraph a paragraph
555 // break should be insertet. StarMath objects are character bound and
556 // no break should be inserted.
557 //3. If an selektion is passed to a StarMath object, this object should
558 // not be activated. FALSE should be returned then.
559 BOOL bStarMath = TRUE;
560 BOOL bActivate = TRUE;
562 // set parent to get correct VisArea(in case of object needing parent printer)
563 uno::Reference < container::XChild > xChild( xRef.GetObject(), uno::UNO_QUERY );
564 if ( xChild.is() )
565 xChild->setParent( pDoc->GetDocShell()->GetModel() );
567 SvGlobalName aCLSID( xRef->getClassID() );
568 bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
569 if( IsSelection() )
571 if( bStarMath )
573 String aMathData;
574 GetSelectedText( aMathData, GETSELTXT_PARABRK_TO_ONLYCR );
576 if( aMathData.Len() && svt::EmbeddedObjectRef::TryRunningState( xRef.GetObject() ) )
578 uno::Reference < beans::XPropertySet > xSet( xRef->getComponent(), uno::UNO_QUERY );
579 if ( xSet.is() )
583 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("Formula"), uno::makeAny( ::rtl::OUString( aMathData ) ) );
584 bActivate = FALSE;
586 catch ( uno::Exception& )
592 DelRight();
595 if ( !bStarMath )
596 SwFEShell::SplitNode( FALSE, FALSE );
598 EnterSelFrmMode();
600 SwFlyFrmAttrMgr aFrmMgr( TRUE, this, FRMMGR_TYPE_OLE );
601 aFrmMgr.SetHeightSizeType(ATT_FIX_SIZE);
603 SwRect aBound;
604 CalcBoundRect( aBound, aFrmMgr.GetAnchor() );
606 //The Size should be suggested by the OLE server
607 MapMode aMapMode( MAP_TWIP );
608 Size aSz = xRef.GetSize( &aMapMode );
610 //Object size can be limited
611 if ( aSz.Width() > aBound.Width() )
613 //Immer proportional begrenzen.
614 aSz.Height() = aSz.Height() * aBound.Width() / aSz.Width();
615 aSz.Width() = aBound.Width();
617 aFrmMgr.SetSize( aSz );
618 SwFlyFrmFmt *pFmt = SwFEShell::InsertObject( xRef, &aFrmMgr.GetAttrSet() );
620 if (pFlyFrmFmt)
621 *pFlyFrmFmt = pFmt;
623 EndAllAction();
624 GetView().AutoCaption(OLE_CAP, &aCLSID);
626 SwRewriter aRewriter;
628 if ( bStarMath )
629 aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_MATH_FORMULA));
630 else if ( SotExchange::IsChart( aCLSID ) )
631 aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_CHART));
632 else
633 aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_OLE));
635 EndUndo(UNDO_INSERT, &aRewriter);
637 return bActivate;
640 /*------------------------------------------------------------------------
641 Beschreibung: Das aktuelle selektierte OLE-Objekt wird mit dem
642 Verb in den Server geladen.
643 ------------------------------------------------------------------------*/
647 void SwWrtShell::LaunchOLEObj( long nVerb )
649 if ( GetCntType() == CNT_OLE &&
650 !GetView().GetViewFrame()->GetFrame()->IsInPlace() )
652 svt::EmbeddedObjectRef& xRef = GetOLEObject();
653 ASSERT( xRef.is(), "OLE not found" );
654 SfxInPlaceClient* pCli=0;
656 pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() );
657 if ( !pCli )
658 pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef );
660 ((SwOleClient*)pCli)->SetInDoVerb( TRUE );
662 CalcAndSetScale( xRef );
663 pCli->DoVerb( nVerb );
665 ((SwOleClient*)pCli)->SetInDoVerb( FALSE );
666 CalcAndSetScale( xRef );
670 void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef& xObj, const Point& rOffset )
674 sal_Int32 nState = xObj->getCurrentState();
675 if ( nState == ::com::sun::star::embed::EmbedStates::INPLACE_ACTIVE
676 || nState == ::com::sun::star::embed::EmbedStates::UI_ACTIVE )
678 SfxInPlaceClient* pCli =
679 GetView().FindIPClient( xObj.GetObject(), &(GetView().GetEditWin()) );
680 if ( pCli )
682 Rectangle aArea = pCli->GetObjArea();
683 aArea += rOffset;
684 pCli->SetObjArea( aArea );
688 catch( uno::Exception& )
693 void SwWrtShell::CalcAndSetScale( svt::EmbeddedObjectRef& xObj,
694 const SwRect *pFlyPrtRect,
695 const SwRect *pFlyFrmRect )
697 //Einstellen der Skalierung am Client. Diese ergibt sich aus der Differenz
698 //zwischen der VisArea des Objektes und der ObjArea.
699 ASSERT( xObj.is(), "ObjectRef not valid" );
701 sal_Int64 nAspect = xObj.GetViewAspect();
702 if ( nAspect == embed::Aspects::MSOLE_ICON )
703 return; // the replacement image is completely controlled by container in this case
705 sal_Int64 nMisc = 0;
706 sal_Bool bLinkingChart = sal_False;
710 nMisc = xObj->getStatus( nAspect );
712 //Das kann ja wohl nur ein nicht aktives Objekt sein. Diese bekommen
713 //auf Wunsch die neue Groesse als VisArea gesetzt (StarChart)
714 if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
716 // TODO/MBA: testing
717 SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
718 : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
719 if( !aRect.IsEmpty() )
721 // TODO/LEAN: getMapUnit can switch object to running state
722 // xObj.TryRunningState();
724 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
726 // TODO/LATER: needs complete VisArea?!
727 Size aSize( OutputDevice::LogicToLogic( aRect.SVRect(), MAP_TWIP, aUnit ).GetSize() );
728 awt::Size aSz;
729 aSz.Width = aSize.Width();
730 aSz.Height = aSize.Height();
731 xObj->setVisualAreaSize( nAspect, aSz );
732 // --> OD 2005-05-02 #i48419# - action 'UpdateReplacement' doesn't
733 // have to change the modified state of the document.
734 // This is only a workaround for the defect, that this action
735 // modifies a document after load, because unnecessarily the
736 // replacement graphic is updated, in spite of the fact that
737 // nothing has been changed.
738 // If the replacement graphic changes by this action, the document
739 // will be already modified via other mechanisms.
741 bool bResetEnableSetModified(false);
742 if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
744 GetDoc()->GetDocShell()->EnableSetModified( FALSE );
745 bResetEnableSetModified = true;
748 //#i79576# don't destroy chart replacement images on load
749 //#i79578# don't request a new replacement image for charts to often
750 //a chart sends a modified call to the framework if it was changed
751 //thus the replacement update is already handled elsewhere
752 if ( !SotExchange::IsChart( xObj->getClassID() ) )
753 xObj.UpdateReplacement();
755 if ( bResetEnableSetModified )
757 GetDoc()->GetDocShell()->EnableSetModified( TRUE );
760 // <--
763 // TODO/LATER: this is only a workaround,
764 uno::Reference< chart2::XChartDocument > xChartDocument( xObj->getComponent(), uno::UNO_QUERY );
765 bLinkingChart = ( xChartDocument.is() && !xChartDocument->hasInternalDataProvider() );
768 catch ( uno::Exception& )
770 // TODO/LATER: handle the error
771 return;
774 SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
775 if ( !pCli )
777 if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY & nMisc) || bLinkingChart
778 // TODO/LATER: ResizeOnPrinterChange
779 //|| SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->GetMiscStatus()
782 pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
784 else
785 return;
788 // TODO/LEAN: getMapUnit can switch object to running state
789 // xObj.TryRunningState();
791 awt::Size aSize;
794 aSize = xObj->getVisualAreaSize( nAspect );
796 catch( embed::NoVisualAreaSizeException& )
798 DBG_ERROR( "Can't get visual area size!\n" );
799 // the scaling will not be done
801 catch( uno::Exception& )
803 // TODO/LATER: handle the error
804 DBG_ERROR( "Can't get visual area size!\n" );
805 return;
808 Size _aVisArea( aSize.Width, aSize.Height );
810 Fraction aScaleWidth( 1, 1 );
811 Fraction aScaleHeight( 1, 1 );
813 sal_Bool bUseObjectSize = sal_False;
815 // solange keine vernuenftige Size vom Object kommt, kann nichts
816 // skaliert werden
817 if( _aVisArea.Width() && _aVisArea.Height() )
819 const MapMode aTmp( MAP_TWIP );
820 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
821 _aVisArea = OutputDevice::LogicToLogic( _aVisArea, aUnit, aTmp);
822 Size aObjArea;
823 if ( pFlyPrtRect )
824 aObjArea = pFlyPrtRect->SSize();
825 else
826 aObjArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ).SSize();
828 // differ the aObjArea and _aVisArea by 1 Pixel then set new VisArea
829 long nX, nY;
830 SwSelPaintRects::Get1PixelInLogic( *this, &nX, &nY );
831 if( !( _aVisArea.Width() - nX <= aObjArea.Width() &&
832 _aVisArea.Width() + nX >= aObjArea.Width() &&
833 _aVisArea.Height()- nY <= aObjArea.Height()&&
834 _aVisArea.Height()+ nY >= aObjArea.Height() ))
836 // TODO/LATER: MISCSTATUS_RESIZEONPRINTERCHANGE
838 if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & nMisc )
840 //This type of objects should never be resized.
841 //If this request comes from the Writer core (inaktive Object
842 //ist resized), the Object should be resized too.
843 //If this request comes from the Object itself, the Frame
844 //in the Writer core should be resized.
845 if ( pFlyPrtRect ) //Request from core?
847 xObj->SetVisArea( OutputDevice::LogicToLogic(
848 pFlyPrtRect->SVRect(), MAP_TWIP, xObj->GetMapUnit() ));
850 else
852 SwRect aTmp( Point( LONG_MIN, LONG_MIN ), _aVisArea );
853 RequestObjectResize( aTmp, xObj );
855 //Der Rest erledigt sich, weil wir eh wiederkommen sollten, evtl.
856 //sogar rekursiv.
857 return;
859 else*/
861 if ( nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE )
863 // the object must not be scaled, the size stored in object must be used for restoring
864 bUseObjectSize = sal_True;
866 else
868 aScaleWidth = Fraction( aObjArea.Width(), _aVisArea.Width() );
869 aScaleHeight = Fraction( aObjArea.Height(), _aVisArea.Height());
874 //Jetzt ist auch der guenstige Zeitpunkt die ObjArea einzustellen.
875 //Die Scalierung muss beruecksichtigt werden.
876 SwRect aArea;
877 if ( pFlyPrtRect )
879 aArea = *pFlyPrtRect;
880 aArea += pFlyFrmRect->Pos();
882 else
884 aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
885 aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
888 if ( bUseObjectSize )
890 aArea.Width ( _aVisArea.Width() );
891 aArea.Height( _aVisArea.Height() );
892 RequestObjectResize( aArea, xObj.GetObject() );
894 else
896 aArea.Width ( Fraction( aArea.Width() ) / pCli->GetScaleWidth() );
897 aArea.Height( Fraction( aArea.Height() ) / pCli->GetScaleHeight());
900 pCli->SetObjAreaAndScale( aArea.SVRect(), aScaleWidth, aScaleHeight );
905 void SwWrtShell::ConnectObj( svt::EmbeddedObjectRef& xObj, const SwRect &rPrt,
906 const SwRect &rFrm )
908 SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin());
909 if ( !pCli )
910 pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
911 CalcAndSetScale( xObj, &rPrt, &rFrm );
914 /*------------------------------------------------------------------------
915 Beschreibung: Einfuegen harter Seitenumbruch;
916 Selektionen werden ueberschrieben
917 ------------------------------------------------------------------------*/
921 void SwWrtShell::InsertPageBreak(const String *pPageDesc, USHORT nPgNum )
923 ResetCursorStack();
924 if( _CanInsert() )
926 ACT_KONTEXT(this);
927 StartUndo(UNDO_UI_INSERT_PAGE_BREAK);
929 if ( !IsCrsrInTbl() )
931 if(HasSelection())
932 DelRight();
933 SwFEShell::SplitNode();
934 // delete the numbered attribute of the last line if the last line is empty
935 GetDoc()->ClearLineNumAttrs( *GetCrsr()->GetPoint() );
938 const SwPageDesc *pDesc = pPageDesc
939 ? FindPageDescByName( *pPageDesc, TRUE ) : 0;
940 if( pDesc )
942 SwFmtPageDesc aDesc( pDesc );
943 aDesc.SetNumOffset( nPgNum );
944 SetAttr( aDesc );
946 else
947 SetAttr( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) );
948 EndUndo(UNDO_UI_INSERT_PAGE_BREAK);
951 /*------------------------------------------------------------------------
952 Beschreibung: Einfuegen harter Zeilenumbruch;
953 Selektionen werden ueberschrieben
954 ------------------------------------------------------------------------*/
957 void SwWrtShell::InsertLineBreak()
959 ResetCursorStack();
960 if( _CanInsert() )
962 if(HasSelection())
963 DelRight();
965 const sal_Unicode cIns = 0x0A;
966 SvxAutoCorrect* pACorr = lcl_IsAutoCorr();
967 if( pACorr )
968 AutoCorrect( *pACorr, cIns );
969 else
970 SwWrtShell::Insert( String( cIns ) );
973 /*------------------------------------------------------------------------
974 Beschreibung: Einfuegen harter Spaltenumbruch;
975 Selektionen werden ueberschrieben
976 ------------------------------------------------------------------------*/
979 void SwWrtShell::InsertColumnBreak()
981 ACT_KONTEXT(this);
982 ResetCursorStack();
983 if( _CanInsert() )
985 StartUndo(UNDO_UI_INSERT_COLUMN_BREAK);
987 if ( !IsCrsrInTbl() )
989 if(HasSelection())
990 DelRight();
991 SwFEShell::SplitNode( FALSE, FALSE );
993 SetAttr(SvxFmtBreakItem(SVX_BREAK_COLUMN_BEFORE, RES_BREAK));
995 EndUndo(UNDO_UI_INSERT_COLUMN_BREAK);
999 /*------------------------------------------------------------------------
1000 Beschreibung: Einfuegen Fussnote
1001 Parameter: rStr -- optionales Fussnotenzeichen
1002 ------------------------------------------------------------------------*/
1005 void SwWrtShell::InsertFootnote(const String &rStr, BOOL bEndNote, BOOL bEdit )
1007 ResetCursorStack();
1008 if( _CanInsert() )
1010 if(HasSelection())
1012 //collapse cursor to the end
1013 if(!IsCrsrPtAtEnd())
1014 SwapPam();
1015 ClearMark();
1018 SwFmtFtn aFootNote( bEndNote );
1019 if(rStr.Len())
1020 aFootNote.SetNumStr( rStr );
1022 SetAttr(aFootNote);
1024 if( bEdit )
1026 // zur Bearbeiung des Fussnotentextes
1027 Left(CRSR_SKIP_CHARS, FALSE, 1, FALSE );
1028 GotoFtnTxt();
1032 /*------------------------------------------------------------------------
1033 Beschreibung: SplitNode; hier auch, da
1034 - selektierter Inhalt geloescht wird;
1035 - der Cursorstack gfs. zurueckgesetzt wird.
1036 ------------------------------------------------------------------------*/
1039 void SwWrtShell::SplitNode( BOOL bAutoFmt, BOOL bCheckTableStart )
1041 ResetCursorStack();
1042 if( _CanInsert() )
1044 ACT_KONTEXT(this);
1046 rView.GetEditWin().FlushInBuffer();
1047 BOOL bHasSel = HasSelection();
1048 if( bHasSel )
1050 StartUndo( UNDO_INSERT );
1051 DelRight();
1054 SwFEShell::SplitNode( bAutoFmt, bCheckTableStart );
1055 if( bHasSel )
1056 EndUndo( UNDO_INSERT );
1060 /*------------------------------------------------------------------------
1061 Beschreibung: Numerierung anschalten
1062 Parameter: Optionale Angabe eines Namens fuer die benannte Liste;
1063 dieser bezeichnet eine Position, wenn er in eine
1064 Zahl konvertierbar ist und kleiner ist als nMaxRules.
1065 -------------------------------------------------------------------------*/
1068 // zum Testen der CharFormate an der Numerierung
1069 // extern void SetNumChrFmt( SwWrtShell*, SwNumRules& );
1071 // -> #i40041#
1072 // --> OD 2005-10-25 #b6340308#
1073 // Preconditions (as far as OD has figured out):
1074 // - <SwEditShell::HasNumber()> is FALSE, if <bNum> is TRUE
1075 // - <SwEditShell::HasBullet()> is FALSE, if <bNum> is FALSE
1076 // Behavior of method is determined by the current situation at the current
1077 // cursor position in the document.
1078 void SwWrtShell::NumOrBulletOn(BOOL bNum)
1080 // determine numbering rule found at current cursor position in the docment.
1081 const SwNumRule* pCurRule = GetCurNumRule();
1083 StartUndo(UNDO_NUMORNONUM);
1085 const SwNumRule * pNumRule = pCurRule;
1087 // --> OD 2005-10-25 #b6340308#
1088 // - activate outline rule respectively turning on outline rule for
1089 // current text node. But, only for turning on a numbering (<bNum> == TRUE).
1090 // - overwrite found numbering rule at current cursor position, if
1091 // no numbering rule can be retrieved from the paragraph style.
1092 bool bContinueFoundNumRule( false );
1093 bool bActivateOutlineRule( false );
1094 int nActivateOutlineLvl( MAXLEVEL ); // only relevant, if <bActivateOutlineRule> == TRUE
1095 SwTxtFmtColl * pColl = GetCurTxtFmtColl();
1096 if ( pColl )
1098 // --> OD 2005-10-25 #b6340308# - retrieve numbering rule at paragraph
1099 // style, which is found at current cursor position in the document.
1100 SwNumRule* pCollRule = pDoc->FindNumRulePtr(pColl->GetNumRule().GetValue());
1101 // --> OD 2005-10-25 #125993# - The outline numbering rule isn't allowed
1102 // to be derived from a parent paragraph style to a derived one.
1103 // Thus check, if the found outline numbering rule is directly
1104 // set at the paragraph style <pColl>. If not, set <pCollRule> to NULL
1105 if ( pCollRule && pCollRule == GetDoc()->GetOutlineNumRule() )
1107 const SwNumRule* pDirectCollRule =
1108 pDoc->FindNumRulePtr(pColl->GetNumRule( FALSE ).GetValue());
1109 if ( !pDirectCollRule )
1111 pCollRule = 0;
1114 // --> OD 2006-11-20 #i71764#
1115 // Document setting OUTLINE_LEVEL_YIELDS_OUTLINE_RULE has no influence
1116 // any more.
1117 // if ( pCollRule == NULL &&
1118 // NO_NUMBERING != pColl->GetOutlineLevel() &&
1119 // GetDoc()->get(IDocumentSettingAccess::OUTLINE_LEVEL_YIELDS_OUTLINE_RULE) )
1120 // {
1121 // pCollRule = GetDoc()->GetOutlineNumRule();
1122 // }
1123 // <--
1125 // <--
1126 // --> OD 2005-10-25 #b6340308#
1127 if ( !pCollRule )
1129 pNumRule = pCollRule;
1131 // --> OD 2006-06-12 #b6435904#
1132 // no activation or continuation of outline numbering in Writer/Web document
1133 else if ( bNum &&
1134 !dynamic_cast<SwWebDocShell*>(GetDoc()->GetDocShell()) &&
1135 pCollRule == GetDoc()->GetOutlineNumRule() )
1136 // <--
1138 if ( pNumRule == pCollRule )
1140 // check, if text node at current cursor positioned is counted.
1141 // If not, let it been counted. Then it has to be checked,
1142 // of the outline numbering has to be activated or continued.
1143 SwTxtNode* pTxtNode =
1144 GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1145 if ( pTxtNode && !pTxtNode->IsCountedInList() )
1147 // check, if numbering of the outline level of the pararaph
1148 // style is active. If not, activate this outline level.
1149 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
1150 ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(), //<-end,zhaojianwei
1151 "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1152 if ( pColl->IsAssignedToListLevelOfOutlineStyle() && //<-end,zhaojianwei
1153 pCollRule->Get( static_cast<USHORT>(nActivateOutlineLvl) ).GetNumberingType()
1154 == SVX_NUM_NUMBER_NONE )
1156 // activate outline numbering
1157 bActivateOutlineRule = true;
1159 else
1161 // turning on outline numbering at current cursor position
1162 bContinueFoundNumRule = true;
1165 else
1167 // --> OD 2009-08-27 #i101234#
1168 // activate outline numbering, because from the precondition
1169 // it's known, that <SwEdit::HasNumber()> == FALSE
1170 bActivateOutlineRule = true;
1171 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei
1174 else if ( !pNumRule )
1176 // --> OD 2009-08-27 #i101234#
1177 // Check, if corresponding list level of the outline numbering
1178 // has already a numbering format set.
1179 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei,need further consideration
1180 if ( pCollRule->Get( static_cast<USHORT>(nActivateOutlineLvl) ).GetNumberingType()
1181 == SVX_NUM_NUMBER_NONE )
1183 // activate outline numbering, because from the precondition
1184 // it's known, that <SwEdit::HasNumber()> == FALSE
1185 bActivateOutlineRule = true;
1187 else
1189 // turning on outline numbering at current cursor position
1190 bContinueFoundNumRule = true;
1192 // <--
1194 else
1196 // check, if numbering of the outline level of the pararaph
1197 // style is active. If not, activate this outline level.
1198 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//#outline level,zhaojianwei
1199 ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(),//#outline level,zhaojianwei
1200 "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1201 if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&//#outline level,zhaojianwei
1202 pCollRule->Get( static_cast<USHORT>(nActivateOutlineLvl) ).GetNumberingType()
1203 == SVX_NUM_NUMBER_NONE )
1205 // activate outline numbering
1206 bActivateOutlineRule = true;
1208 else
1210 // turning on outline numbering at current cursor position
1211 bContinueFoundNumRule = true;
1214 pNumRule = pCollRule;
1218 // --> OD 2005-10-25 #b6340308#
1219 // Only automatic numbering/bullet rules should be changed.
1220 // Note: The outline numbering rule is also an automatic one. It's only
1221 // changed, if it has to be activated.
1222 if ( pNumRule )
1224 if ( !pNumRule->IsAutoRule() )
1226 pNumRule = 0;
1228 else if ( pNumRule == GetDoc()->GetOutlineNumRule() &&
1229 !bActivateOutlineRule && !bContinueFoundNumRule )
1231 pNumRule = 0;
1234 // <--
1236 // --> OD 2005-10-25 #b6340308#
1237 // Search for a previous numbering/bullet rule to continue it.
1238 // --> OD 2008-03-18 #refactorlists#
1239 String sContinuedListId;
1240 if ( !pNumRule )
1242 pNumRule = GetDoc()->SearchNumRule( *GetCrsr()->GetPoint(),
1243 false, bNum, false, 0,
1244 sContinuedListId );
1245 bContinueFoundNumRule = pNumRule != 0;
1247 // <--
1249 if (pNumRule)
1251 SwNumRule aNumRule(*pNumRule);
1253 // --> OD 2005-10-25 #b6340308#
1254 // do not change found numbering/bullet rule, if it should only be continued.
1255 if ( !bContinueFoundNumRule )
1257 SwTxtNode * pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1259 if (pTxtNode)
1261 // --> OD 2005-10-26 #b6340308# - use above retrieve outline
1262 // level, if outline numbering has to be activated.
1263 int nLevel = bActivateOutlineRule ////#outline level,zhaojianwei,need more consideration
1264 ? nActivateOutlineLvl
1265 : pTxtNode->GetActualListLevel();
1266 // <--
1268 if (nLevel < 0)
1269 nLevel = 0;
1271 if (nLevel >= MAXLEVEL)
1272 nLevel = MAXLEVEL - 1;
1274 SwNumFmt aFmt(aNumRule.Get(static_cast<USHORT>(nLevel)));
1276 if (bNum)
1277 aFmt.SetNumberingType(SVX_NUM_ARABIC);
1278 else
1280 // --> OD 2008-06-03 #i63395#
1281 // Only apply user defined default bullet font
1282 if ( numfunc::IsDefBulletFontUserDefined() )
1284 const Font* pFnt = &numfunc::GetDefBulletFont();
1285 aFmt.SetBulletFont( pFnt );
1287 // <--
1288 aFmt.SetBulletChar( numfunc::GetBulletChar(static_cast<BYTE>(nLevel)));
1289 aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1291 aNumRule.Set(static_cast<USHORT>(nLevel), aFmt);
1294 // <--
1296 // --> OD 2008-02-08 #newlistlevelattrs#
1297 // reset indent attribute on applying list style
1298 // --> OD 2008-03-27 #refactorlists#
1299 SetCurNumRule( aNumRule, false, sContinuedListId, true );
1300 // <--
1302 else
1304 // --> OD 2009-08-27 #i95907#
1305 const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1306 numfunc::GetDefaultPositionAndSpaceMode() );
1307 // --> OD 2008-02-11 #newlistlevelattrs#
1308 SwNumRule aNumRule( GetUniqueNumRuleName(), ePosAndSpaceMode );
1309 // <--
1310 // <--
1311 // Zeichenvorlage an die Numerierung haengen
1312 SwCharFmt* pChrFmt;
1313 SwDocShell* pDocSh = GetView().GetDocShell();
1314 // --> OD 2008-06-03 #i63395#
1315 // Only apply user defined default bullet font
1316 const Font* pFnt = numfunc::IsDefBulletFontUserDefined()
1317 ? &numfunc::GetDefBulletFont()
1318 : 0;
1319 // <--
1321 if (bNum)
1323 pChrFmt = GetCharFmtFromPool( RES_POOLCHR_NUM_LEVEL );
1325 else
1327 pChrFmt = GetCharFmtFromPool( RES_POOLCHR_BUL_LEVEL );
1330 const SwTxtNode* pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1331 const SwTwips nWidthOfTabs = pTxtNode
1332 ? pTxtNode->GetWidthOfLeadingTabs()
1333 : 0;
1334 GetDoc()->RemoveLeadingWhiteSpace( *GetCrsr()->GetPoint() );
1336 const bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
1337 const bool bRightToLeft = IsInRightToLeftText();
1338 for( BYTE nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
1340 SwNumFmt aFmt( aNumRule.Get( nLvl ) );
1341 aFmt.SetCharFmt( pChrFmt );
1343 if (! bNum)
1345 // --> OD 2008-06-03 #i63395#
1346 // Only apply user defined default bullet font
1347 if ( pFnt )
1349 aFmt.SetBulletFont( pFnt );
1351 aFmt.SetBulletChar( numfunc::GetBulletChar(nLvl) );
1352 aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1355 // --> OD 2009-08-26 #i95907#
1356 if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1358 if(bHtml && nLvl)
1360 // 1/2" fuer HTML
1361 aFmt.SetLSpace(720);
1362 aFmt.SetAbsLSpace(nLvl * 720);
1364 else if ( nWidthOfTabs > 0 )
1366 aFmt.SetAbsLSpace(nWidthOfTabs + nLvl * 720);
1369 // <--
1371 // --> FME 2005-01-21 #i38904# Default alignment for
1372 // numbering/bullet should be rtl in rtl paragraph:
1373 if ( bRightToLeft )
1375 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
1377 // <--
1379 aNumRule.Set( nLvl, aFmt );
1382 // --> OD 2009-08-26 #i95907#
1383 if ( pTxtNode &&
1384 ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1386 short nTxtNodeFirstLineOffset( 0 );
1387 pTxtNode->GetFirstLineOfsWithNum( nTxtNodeFirstLineOffset );
1388 const SwTwips nTxtNodeIndent = pTxtNode->GetLeftMarginForTabCalculation() +
1389 nTxtNodeFirstLineOffset;
1390 if ( ( nTxtNodeIndent + nWidthOfTabs ) != 0 )
1392 const SwTwips nIndentChange = nTxtNodeIndent + nWidthOfTabs;
1393 aNumRule.ChangeIndent( nIndentChange );
1396 // <--
1397 // --> OD 2008-02-08 #newlistlevelattrs#
1398 // reset indent attribute on applying list style
1399 // --> OD 2008-03-17 #refactorlists#
1400 // start new list
1401 SetCurNumRule( aNumRule, true, String(), true );
1402 // <--
1405 EndUndo(UNDO_NUMORNONUM);
1407 // <- #i40041#
1409 void SwWrtShell::NumOn()
1411 NumOrBulletOn(TRUE);
1414 void SwWrtShell::NumOrBulletOff()
1416 const SwNumRule * pCurNumRule = GetCurNumRule();
1418 if (pCurNumRule)
1420 if (pCurNumRule->IsOutlineRule())
1422 SwNumRule aNumRule(*pCurNumRule);
1424 SwTxtNode * pTxtNode =
1425 GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1427 if (pTxtNode)
1429 sal_uInt16 nLevel = sal::static_int_cast<sal_uInt16, sal_Int32>(pTxtNode->GetActualListLevel());
1430 SwNumFmt aFmt(aNumRule.Get(nLevel));
1432 aFmt.SetNumberingType(SVX_NUM_NUMBER_NONE);
1433 aNumRule.Set(nLevel, aFmt);
1435 // --> OD 2008-03-17 #refactorlists#
1436 // no start or continuation of a list - the outline style is only changed.
1437 SetCurNumRule( aNumRule, false );
1438 // <--
1441 else
1443 DelNumRules();
1446 // --> OD 2005-10-24 #126346# - Cursor can not be anymore in front of
1447 // a label, because numbering/bullet is switched off.
1448 SetInFrontOfLabel( FALSE );
1449 // <--
1452 // <- #i29560#
1454 /*------------------------------------------------------------------------
1455 Beschreibung: Default-Bulletliste erfragen
1456 ------------------------------------------------------------------------*/
1458 void SwWrtShell::BulletOn()
1460 NumOrBulletOn(FALSE);
1464 /*--------------------------------------------------
1466 --------------------------------------------------*/
1467 SelectionType SwWrtShell::GetSelectionType() const
1469 // ContentType kann nicht ermittelt werden innerhalb einer
1470 // Start-/Endactionklammerung.
1471 // Da es keinen ungueltigen Wert gibt, wird TEXT geliefert.
1472 // Der Wert ist egal, da in EndAction ohnehin aktualisiert wird.
1474 if ( BasicActionPend() )
1475 return IsSelFrmMode() ? nsSelectionType::SEL_FRM : nsSelectionType::SEL_TXT;
1477 // if ( IsTableMode() )
1478 // return nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS;
1480 SwView &_rView = ((SwView&)GetView());
1481 if (_rView.GetPostItMgr() && _rView.GetPostItMgr()->GetActivePostIt() )
1482 return nsSelectionType::SEL_POSTIT;
1483 int nCnt;
1485 // Rahmen einfuegen ist kein DrawMode
1486 if ( !_rView.GetEditWin().IsFrmAction() &&
1487 (IsObjSelected() || (_rView.IsDrawMode() && !IsFrmSelected()) ))
1489 if (GetDrawView()->IsTextEdit())
1490 nCnt = nsSelectionType::SEL_DRW_TXT;
1491 else
1493 if (GetView().IsFormMode()) // Nur Forms selektiert
1494 nCnt = nsSelectionType::SEL_DRW_FORM;
1495 else
1496 nCnt = nsSelectionType::SEL_DRW; // Irgendein Draw-Objekt
1498 if (_rView.IsBezierEditMode())
1499 nCnt |= nsSelectionType::SEL_BEZ;
1500 else if( GetDrawView()->GetContext() == SDRCONTEXT_MEDIA )
1501 nCnt |= nsSelectionType::SEL_MEDIA;
1503 if (svx::checkForSelectedCustomShapes(
1504 const_cast<SdrView *>(GetDrawView()),
1505 true /* bOnlyExtruded */ ))
1507 nCnt |= nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE;
1509 sal_uInt32 nCheckStatus = 0;
1510 if (svx::checkForSelectedFontWork(
1511 const_cast<SdrView *>(GetDrawView()), nCheckStatus ))
1513 nCnt |= nsSelectionType::SEL_FONTWORK;
1517 return nCnt;
1520 nCnt = GetCntType();
1522 if ( IsFrmSelected() )
1524 if (_rView.IsDrawMode())
1525 _rView.LeaveDrawCreate(); // Aufraeumen (Bug #45639)
1526 if ( !(nCnt & (CNT_GRF | CNT_OLE)) )
1527 return nsSelectionType::SEL_FRM;
1530 if ( IsCrsrInTbl() )
1531 nCnt |= nsSelectionType::SEL_TBL;
1533 if ( IsTableMode() )
1534 nCnt |= (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS);
1536 // --> FME 2005-01-12 #i39855#
1537 // Do not pop up numbering toolbar, if the text node has a numbering
1538 // of type SVX_NUM_NUMBER_NONE.
1539 const SwNumRule* pNumRule = GetCurNumRule();
1540 if ( pNumRule )
1542 const SwTxtNode* pTxtNd =
1543 GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1545 // --> OD 2008-03-19 #refactorlists#
1546 if ( pTxtNd && pTxtNd->IsInList() )
1547 // <--
1549 const SwNumFmt& rFmt = pNumRule->Get(sal::static_int_cast< sal_uInt8, sal_Int32>(pTxtNd->GetActualListLevel()));
1550 if ( SVX_NUM_NUMBER_NONE != rFmt.GetNumberingType() )
1551 nCnt |= nsSelectionType::SEL_NUM;
1554 // <--
1556 return nCnt;
1559 /*------------------------------------------------------------------------
1560 Beschreibung: Finden der TextCollection mit dem Name rCollname
1561 Return: Pointer auf die Collection oder 0, wenn keine
1562 TextCollection mit diesem Namen existiert oder
1563 diese eine Defaultvorlage ist.
1564 ------------------------------------------------------------------------*/
1567 SwTxtFmtColl *SwWrtShell::GetParaStyle(const String &rCollName, GetStyle eCreate )
1569 SwTxtFmtColl* pColl = FindTxtFmtCollByName( rCollName );
1570 if( !pColl && GETSTYLE_NOCREATE != eCreate )
1572 USHORT nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1573 if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1574 pColl = GetTxtCollFromPool( nId );
1576 return pColl;
1578 /*------------------------------------------------------------------------
1579 Beschreibung: Finden der Zeichenvorlage mit dem Name rCollname
1580 Return: Pointer auf die Collection oder 0, wenn keine
1581 Zeichenvorlage mit diesem Namen existiert oder
1582 diese eine Defaultvorlage oder automatische Vorlage ist.
1583 ------------------------------------------------------------------------*/
1587 SwCharFmt *SwWrtShell::GetCharStyle(const String &rFmtName, GetStyle eCreate )
1589 SwCharFmt* pFmt = FindCharFmtByName( rFmtName );
1590 if( !pFmt && GETSTYLE_NOCREATE != eCreate )
1592 USHORT nId = SwStyleNameMapper::GetPoolIdFromUIName( rFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1593 if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1594 pFmt = (SwCharFmt*)GetFmtFromPool( nId );
1596 return pFmt;
1599 /*------------------------------------------------------------------------
1600 Beschreibung: Finden des Tabellenformates mit dem Name rFmtname
1601 Return: Pointer auf das Format oder 0, wenn kein
1602 Rahmenformat mit diesem Namen existiert oder
1603 dieses eine Defaultformat oder automatisches Format ist.
1604 ------------------------------------------------------------------------*/
1608 SwFrmFmt *SwWrtShell::GetTblStyle(const String &rFmtName)
1610 SwFrmFmt *pFmt = 0;
1611 for( USHORT i = GetTblFrmFmtCount(); i; )
1612 if( !( pFmt = &GetTblFrmFmt( --i ) )->IsDefault() &&
1613 pFmt->GetName() == rFmtName && IsUsed( *pFmt ) )
1614 return pFmt;
1615 return 0;
1619 /*------------------------------------------------------------------------
1620 Beschreibung: Anwenden der Vorlagen
1621 ------------------------------------------------------------------------*/
1625 void SwWrtShell::SetPageStyle(const String &rCollName)
1627 if( !SwCrsrShell::HasSelection() && !IsSelFrmMode() && !IsObjSelected() )
1629 SwPageDesc* pDesc = FindPageDescByName( rCollName, TRUE );
1630 if( pDesc )
1631 ChgCurPageDesc( *pDesc );
1635 /*------------------------------------------------------------------------
1636 Beschreibung: Zugriff Vorlagen
1637 ------------------------------------------------------------------------*/
1641 String SwWrtShell::GetCurPageStyle( const BOOL bCalcFrm ) const
1643 return GetPageDesc(GetCurPageDesc( bCalcFrm )).GetName();
1646 /*------------------------------------------------------------------------
1647 Beschreibung: Aktuelle Vorlage anhand der geltenden Attribute aendern
1648 ------------------------------------------------------------------------*/
1651 void SwWrtShell::QuickUpdateStyle()
1653 SwTxtFmtColl *pColl = GetCurTxtFmtColl();
1655 // Standard kann nicht geaendert werden
1656 if(pColl && !pColl->IsDefault())
1658 FillByEx(pColl);
1659 // Vorlage auch anwenden, um harte Attributierung
1660 // zu entfernen
1661 SetTxtFmtColl(pColl);
1666 void SwWrtShell::AutoUpdatePara(SwTxtFmtColl* pColl, const SfxItemSet& rStyleSet)
1668 SfxItemSet aCoreSet( GetAttrPool(),
1669 RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
1670 RES_PARATR_BEGIN, RES_PARATR_END - 1,
1671 RES_FRMATR_BEGIN, RES_FRMATR_END - 1,
1672 SID_ATTR_TABSTOP_POS, SID_ATTR_TABSTOP_POS,
1673 SID_ATTR_TABSTOP_DEFAULTS, SID_ATTR_TABSTOP_DEFAULTS,
1674 SID_ATTR_TABSTOP_OFFSET, SID_ATTR_TABSTOP_OFFSET,
1675 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
1676 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
1677 SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM,
1678 0 );
1679 GetCurAttr( aCoreSet );
1680 BOOL bReset = FALSE;
1681 SfxItemIter aParaIter( aCoreSet );
1682 const SfxPoolItem* pParaItem = aParaIter.FirstItem();
1683 while( pParaItem )
1685 if(!IsInvalidItem(pParaItem))
1687 USHORT nWhich = pParaItem->Which();
1688 if(SFX_ITEM_SET == aCoreSet.GetItemState(nWhich) &&
1689 SFX_ITEM_SET == rStyleSet.GetItemState(nWhich))
1691 aCoreSet.ClearItem(nWhich);
1692 bReset = TRUE;
1695 pParaItem = aParaIter.NextItem();
1697 StartAction();
1698 if(bReset)
1700 ResetAttr();
1701 SetAttr(aCoreSet);
1703 pDoc->ChgFmt(*pColl, rStyleSet );
1704 EndAction();
1707 /*-----------------12.03.97 12.24-------------------
1709 --------------------------------------------------*/
1711 void SwWrtShell::AutoUpdateFrame( SwFrmFmt* pFmt, const SfxItemSet& rStyleSet )
1713 StartAction();
1715 ResetFlyFrmAttr( 0, &rStyleSet );
1716 pFmt->SetFmtAttr( rStyleSet );
1718 EndAction();
1722 void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar )
1724 ResetCursorStack();
1725 if(_CanInsert())
1727 BOOL bStarted = FALSE;
1728 if(HasSelection())
1730 // nur hier klammern, da das normale Insert schon an der
1731 // Editshell geklammert ist
1732 StartAllAction();
1733 StartUndo(UNDO_INSERT);
1734 bStarted = TRUE;
1735 DelRight();
1737 SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar );
1739 if(bStarted)
1741 EndAllAction();
1742 EndUndo(UNDO_INSERT);
1749 * eine Art kontrollierter copy ctor
1752 SwWrtShell::SwWrtShell( SwWrtShell& rSh, Window *_pWin, SwView &rShell )
1753 : SwFEShell( rSh, _pWin ),
1754 COMMON_INI_LIST
1756 BITFLD_INI_LIST
1757 SET_CURR_SHELL( this );
1759 SetSfxViewShell( (SfxViewShell *)&rShell );
1760 SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1762 // place the cursor on the first field...
1763 IFieldmark *pBM = NULL;
1764 if ( IsFormProtected() && ( pBM = GetFieldmarkAfter( ) ) !=NULL ) {
1765 GotoFieldmark(pBM);
1770 SwWrtShell::SwWrtShell( SwDoc& rDoc, Window *_pWin, SwView &rShell,
1771 const SwViewOption *pViewOpt )
1772 : SwFEShell( rDoc, _pWin, pViewOpt),
1773 COMMON_INI_LIST
1775 BITFLD_INI_LIST
1776 SET_CURR_SHELL( this );
1777 SetSfxViewShell( (SfxViewShell *)&rShell );
1778 SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1782 * ctor
1787 SwWrtShell::~SwWrtShell()
1789 SET_CURR_SHELL( this );
1790 while(IsModePushed())
1791 PopMode();
1792 while(PopCrsr(FALSE))
1794 SwTransferable::ClearSelection( *this );
1797 BOOL SwWrtShell::Pop( BOOL bOldCrsr )
1799 BOOL bRet = SwCrsrShell::Pop( bOldCrsr );
1800 if( bRet && IsSelection() )
1802 fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
1803 fnKillSel = &SwWrtShell::ResetSelect;
1805 return bRet;
1808 /*--------------------------------------------------------------------
1809 Beschreibung:
1810 --------------------------------------------------------------------*/
1811 BOOL SwWrtShell::CanInsert()
1813 return (!(IsSelFrmMode() | IsObjSelected() | (GetView().GetDrawFuncPtr() != NULL) | (GetView().GetPostItMgr()->GetActivePostIt()!= NULL)));
1816 // die Core erzeugt eine Selektion, das SttSelect muss gerufen werden
1817 void SwWrtShell::NewCoreSelection()
1819 SttSelect();
1822 // --------------
1823 void SwWrtShell::ChgDBData(const SwDBData& aDBData)
1825 SwEditShell::ChgDBData(aDBData);
1826 //notify the db-beamer if available
1827 GetView().NotifyDBChanged();
1830 String SwWrtShell::GetSelDescr() const
1832 String aResult;
1834 int nSelType = GetSelectionType();
1835 switch (nSelType)
1837 case nsSelectionType::SEL_GRF:
1838 aResult = SW_RES(STR_GRAPHIC);
1840 break;
1841 case nsSelectionType::SEL_FRM:
1843 const SwFrmFmt * pFrmFmt = GetCurFrmFmt();
1845 if (pFrmFmt)
1846 aResult = pFrmFmt->GetDescription();
1848 break;
1849 case nsSelectionType::SEL_DRW:
1851 aResult = SW_RES(STR_DRAWING_OBJECTS);
1853 break;
1854 default:
1855 if (0 != pDoc)
1856 aResult = GetCrsrDescr();
1859 return aResult;