xref: /AOO41X/main/sw/source/ui/wrtsh/wrtsh1.cxx (revision 52f1c2ee1b77392125ca30aec3c767684308e131)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <com/sun/star/container/XChild.hpp>
28 #include <com/sun/star/embed/XVisualObject.hpp>
29 #include <com/sun/star/embed/EmbedMisc.hpp>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
33 #include <com/sun/star/chart2/XChartDocument.hpp>
34 #include <com/sun/star/util/XModifiable.hpp>
35 
36 #include <math.h>   // prevent conflict between exception and std::exception
37 #include <hintids.hxx>
38 #include <svx/svdview.hxx>
39 #include <sot/factory.hxx>
40 #include <svl/itemiter.hxx>
41 #include <vcl/sound.hxx>
42 #include <tools/bigint.hxx>
43 #include <sot/storage.hxx>
44 #include <svtools/insdlg.hxx>
45 #include <sfx2/frmdescr.hxx>
46 #include <sfx2/ipclient.hxx>
47 #include <svtools/ehdl.hxx>
48 #include <svtools/soerr.hxx>
49 #include <tools/cachestr.hxx>
50 #include <unotools/moduleoptions.hxx>
51 #include <editeng/sizeitem.hxx>
52 #include <editeng/brkitem.hxx>
53 #include <editeng/svxacorr.hxx>
54 #include <vcl/graph.hxx>
55 #include <sfx2/printer.hxx>
56 #include <unotools/charclass.hxx>
57 #include <comphelper/storagehelper.hxx>
58 #include <svx/svxdlg.hxx>
59 #include <svx/extrusionbar.hxx>
60 #include <svx/fontworkbar.hxx>
61 #include <frmfmt.hxx>
62 #include <fmtftn.hxx>
63 #include <fmtpdsc.hxx>
64 #include <wdocsh.hxx>
65 #include <basesh.hxx>
66 #include <swmodule.hxx>
67 #include <wrtsh.hxx>
68 #include <view.hxx>
69 #include <uitool.hxx>
70 #include <cmdid.h>
71 #include <cfgitems.hxx>
72 #include <pagedesc.hxx>
73 #include <frmmgr.hxx>
74 #include <shellio.hxx>
75 #include <uinums.hxx>  // fuer Anwenden einer
76 #include <swundo.hxx>  // fuer Undo-Ids
77 #include <swcli.hxx>
78 #include <poolfmt.hxx>
79 #include <wview.hxx>
80 #include <edtwin.hxx>
81 #include <fmtcol.hxx>
82 #include <swtable.hxx>
83 #include <caption.hxx>
84 #include <viscrs.hxx>
85 #include <swdtflvr.hxx>
86 #include <crsskip.hxx>
87 #include <doc.hxx>
88 #include <wrtsh.hrc>
89 #include <SwStyleNameMapper.hxx>
90 #include <sfx2/request.hxx>
91 #include <paratr.hxx>
92 #include <ndtxt.hxx>
93 #include <editeng/acorrcfg.hxx>
94 #include <IMark.hxx>
95 #include <sfx2/bindings.hxx>
96 
97 // -> #111827#
98 #include <SwRewriter.hxx>
99 #include <comcore.hrc>
100 // <- #111827#
101 
102 #include <toolkit/helper/vclunohelper.hxx>
103 #include <sfx2/viewfrm.hxx>
104 
105 #include <editeng/acorrcfg.hxx>
106 
107 #include "PostItMgr.hxx"
108 #include <sfx2/msgpool.hxx>
109 
110 using namespace sw::mark;
111 using namespace com::sun::star;
112 
113 #define COMMON_INI_LIST \
114         fnDrag(&SwWrtShell::BeginDrag),\
115         fnSetCrsr(&SwWrtShell::SetCrsr),\
116         fnEndDrag(&SwWrtShell::EndDrag),\
117         fnKillSel(&SwWrtShell::Ignore),\
118         pModeStack(0), \
119         ePageMove(MV_NO),\
120         pCrsrStack(0),  \
121         rView(rShell),\
122         bDestOnStack(sal_False), \
123         fnLeaveSelect(&SwWrtShell::SttLeaveSelect)
124 
125 #define BITFLD_INI_LIST \
126         bClearMark = \
127         bIns = sal_True;\
128         bAddMode = \
129         bBlockMode = \
130         bExtMode = \
131         bInSelect = \
132         bCopy = \
133         bLayoutMode = \
134         bNoEdit = \
135         bSelWrd = \
136         bSelLn = \
137         bIsInClickToEdit = \
138         mbRetainSelection = sal_False;
139 
140 
lcl_IsAutoCorr()141 SvxAutoCorrect* lcl_IsAutoCorr()
142 {
143     SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get()->GetAutoCorrect();
144     if( pACorr && !pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
145                             AddNonBrkSpace | ChgOrdinalNumber |
146                             ChgToEnEmDash | SetINetAttr | Autocorrect ))
147         pACorr = 0;
148     return pACorr;
149 }
150 
NoEdit(sal_Bool bHideCrsr)151 void SwWrtShell::NoEdit(sal_Bool bHideCrsr)
152 {
153     if(bHideCrsr)
154         HideCrsr();
155     bNoEdit = sal_True;
156 }
157 
158 
159 
Edit()160 void SwWrtShell::Edit()
161 {
162     if (CanInsert())
163     {
164         ShowCrsr();
165         bNoEdit = sal_False;
166     }
167 }
168 
169 
170 
IsEndWrd()171 sal_Bool SwWrtShell::IsEndWrd()
172 {
173     MV_KONTEXT(this);
174     if(IsEndPara() && !IsSttPara())
175         return sal_True;
176 
177     return IsEndWord();
178 }
179 
180 
181 /*------------------------------------------------------------------------
182  Beschreibung:  Abfrage, ob Einfuegen moeglich ist; gfs. Beep
183 ------------------------------------------------------------------------*/
184 
_CanInsert()185 bool SwWrtShell::_CanInsert()
186 {
187     if(!CanInsert())
188     {
189         Sound::Beep();
190         return false;
191     }
192 
193     return true;
194 }
195 
196 /*------------------------------------------------------------------------
197  Beschreibung:  String einfuegen
198 ------------------------------------------------------------------------*/
199 
InsertByWord(const String & rStr)200 void SwWrtShell::InsertByWord( const String & rStr)
201 {
202     if( rStr.Len() )
203     {
204         sal_Bool bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 );
205         xub_StrLen nPos = 0, nStt = 0;
206         for( ; nPos < rStr.Len(); nPos++ )
207         {
208             sal_Bool bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos );
209             if( bTmpDelim != bDelim )
210             {
211                 Insert( rStr.Copy( nStt, nPos - nStt ));
212                 nStt = nPos;
213             }
214         }
215         if( nStt != nPos )
216             Insert( rStr.Copy( nStt, nPos - nStt ));
217     }
218 }
219 
220 
Insert(const String & rStr)221 void SwWrtShell::Insert( const String &rStr )
222 {
223     ResetCursorStack();
224     if( !_CanInsert() )
225         return;
226 
227     sal_Bool bStarted = sal_False, bHasSel = HasSelection(),
228         bCallIns = bIns /*|| bHasSel*/;
229     bool bDeleted = false;
230 
231     if( bHasSel || ( !bIns && SelectHiddenRange() ) )
232     {
233             // nur hier klammern, da das normale Insert schon an der
234             // Editshell geklammert ist
235         StartAllAction();
236 
237         // #111827#
238         SwRewriter aRewriter;
239 
240         aRewriter.AddRule(UNDO_ARG1, GetCrsrDescr());
241         aRewriter.AddRule(UNDO_ARG2, String(SW_RES(STR_YIELDS)));
242         {
243             String aTmpStr;
244             aTmpStr += String(SW_RES(STR_START_QUOTE));
245             aTmpStr += rStr;
246             aTmpStr += String(SW_RES(STR_END_QUOTE));
247 
248             aRewriter.AddRule(UNDO_ARG3, rStr);
249         }
250 
251         StartUndo(UNDO_REPLACE, &aRewriter);
252         bStarted = sal_True;
253         bDeleted = DelRight() != 0;
254     }
255 
256     /*
257 JP 21.01.98: Ueberschreiben ueberschreibt nur die Selektion, nicht das
258             naechste Zeichen.
259     if( bHasSel && !bIns && 1 < rStr.Len() )
260     {
261         // falls mehrere Zeichen anstehen, nur das erste einfuegen,
262         // der Rest muss dann aber Ueberschrieben werden.
263         SwEditShell::Insert( rStr.GetChar( 0 ) );
264         SwEditShell::Overwrite( rStr.Copy( 1 ) );
265     }
266     else
267 */
268     bCallIns ?
269         SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr );
270 
271 
272     if( bStarted )
273     {
274         EndAllAction();
275         EndUndo();
276     }
277 //    delete pChgFlg;
278 }
279 
280 /* Begrenzung auf maximale Hoehe geht nicht, da die maximale Hoehe
281  * des aktuellen Frames nicht erfragt werden kann. */
282 
283 
284 
Insert(const String & rPath,const String & rFilter,const Graphic & rGrf,SwFlyFrmAttrMgr * pFrmMgr,sal_Bool bRule)285 void SwWrtShell::Insert( const String &rPath, const String &rFilter,
286                          const Graphic &rGrf, SwFlyFrmAttrMgr *pFrmMgr,
287                          sal_Bool bRule )
288 {
289     ResetCursorStack();
290     if ( !_CanInsert() )
291         return;
292 
293     StartAllAction();
294 
295     SwRewriter aRewriter;
296     aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_GRAPHIC));
297 
298     StartUndo(UNDO_INSERT, &aRewriter);
299 
300     if ( HasSelection() )
301         DelRight();
302         // eingefuegte Grafik in eigenen Absatz, falls am Ende
303         // eines nichtleeren Absatzes
304     //For i120928,avoid to split node
305     //if ( IsEndPara() && !IsSttPara() )
306     //  SwFEShell::SplitNode();
307 
308     EnterSelFrmMode();
309 
310     sal_Bool bSetGrfSize = sal_True;
311     sal_Bool bOwnMgr     = sal_False;
312 
313     if ( !pFrmMgr )
314     {
315         bOwnMgr = sal_True;
316         pFrmMgr = new SwFlyFrmAttrMgr( sal_True, this, FRMMGR_TYPE_GRF );
317 
318         // VORSICHT
319         // GetAttrSet nimmt einen Abgleich vor
320         // Beim Einfuegen ist eine SwFrmSize vorhanden wegen der
321         // DEF-Rahmengroesse
322         // Diese muss fuer die optimale Groesse explizit entfernt werden
323         pFrmMgr->DelAttr(RES_FRM_SIZE);
324     }
325     else
326     {
327         Size aSz( pFrmMgr->GetSize() );
328         if ( !aSz.Width() || !aSz.Height() )
329         {
330             aSz.Width() = aSz.Height() = 567;
331             pFrmMgr->SetSize( aSz );
332         }
333         else if ( aSz.Width() != DFLT_WIDTH && aSz.Height() != DFLT_HEIGHT )
334             bSetGrfSize = sal_False;
335 
336         pFrmMgr->SetHeightSizeType(ATT_FIX_SIZE);
337 
338     }
339 
340     // Einfuegen der Grafik
341     SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrmMgr->GetAttrSet());
342     if ( bOwnMgr )
343         pFrmMgr->UpdateAttrMgr();
344 
345     if( bSetGrfSize && !bRule )
346     {
347         Size aGrfSize, aBound = GetGraphicDefaultSize();
348         GetGrfSize( aGrfSize );
349 
350         //Die GrafikSize noch um die Randattribute vergroessern, denn die
351         //Zaehlen beim Rahmen mit.
352         aGrfSize.Width() += pFrmMgr->CalcWidthBorder();
353         aGrfSize.Height()+= pFrmMgr->CalcHeightBorder();
354 
355         const BigInt aTempWidth( aGrfSize.Width() );
356         const BigInt aTempHeight( aGrfSize.Height());
357 
358         // ggf. Breite anpassen, Hoehe dann proportional verkleinern
359         if( aGrfSize.Width() > aBound.Width() )
360         {
361             aGrfSize.Width()  = aBound.Width();
362             aGrfSize.Height() = ((BigInt)aBound.Width()) * aTempHeight / aTempWidth;
363         }
364         // ggf. Hoehe anpassen, Breite dann proportional verkleinern
365         if( aGrfSize.Height() > aBound.Height() )
366         {
367             aGrfSize.Height() = aBound.Height();
368             aGrfSize.Width() =  ((BigInt)aBound.Height()) * aTempWidth / aTempHeight;
369         }
370         pFrmMgr->SetSize( aGrfSize );
371         pFrmMgr->UpdateFlyFrm();
372     }
373     if ( bOwnMgr )
374         delete pFrmMgr;
375 
376     EndUndo();
377     EndAllAction();
378 }
379 
380 
381 /*------------------------------------------------------------------------
382    Beschreibung: Fuegt ein OLE-Objekt in die CORE ein.
383                  Wenn kein Object uebergeben wird, so wird eins erzeugt.
384 ------------------------------------------------------------------------*/
385 
386 
InsertObject(const svt::EmbeddedObjectRef & xRef,SvGlobalName * pName,sal_Bool bActivate,sal_uInt16 nSlotId)387 void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName *pName,
388                             sal_Bool bActivate, sal_uInt16 nSlotId )
389 {
390     ResetCursorStack();
391     if( !_CanInsert() )
392         return;
393 
394     if( !xRef.is() )
395     {
396         // temporary storage
397         svt::EmbeddedObjectRef xObj;
398         uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetTemporaryStorage();
399         sal_Bool bDoVerb = sal_True;
400         if ( pName )
401         {
402             comphelper::EmbeddedObjectContainer aCnt( xStor );
403             ::rtl::OUString aName;
404             // TODO/LATER: get aspect?
405             xObj.Assign( aCnt.CreateEmbeddedObject( pName->GetByteSequence(), aName ), embed::Aspects::MSOLE_CONTENT );
406         }
407         else
408         {
409             SvObjectServerList aServerList;
410             switch (nSlotId)
411             {
412                 case SID_INSERT_OBJECT:
413                 {
414                     aServerList.FillInsertObjects();
415                     aServerList.Remove( SwDocShell::Factory().GetClassId() );
416                     // Intentionally no break!
417                 }
418 
419                 // TODO/LATER: recording! Convert properties to items
420                 case SID_INSERT_PLUGIN:
421                 case SID_INSERT_FLOATINGFRAME:
422                 {
423                     SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool();
424                     const SfxSlot* pSlot = pSlotPool->GetSlot(nSlotId);
425                     rtl::OString aCmd(".uno:");
426                     aCmd += pSlot->GetUnoName();
427                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
428                     SfxAbstractInsertObjectDialog* pDlg =
429                             pFact->CreateInsertObjectDialog( GetWin(), rtl::OStringToOUString( aCmd, RTL_TEXTENCODING_UTF8 ), xStor, &aServerList );
430                     if ( pDlg )
431                     {
432                         pDlg->Execute();
433                         bDoVerb = pDlg->IsCreateNew();
434                         ::rtl::OUString aIconMediaType;
435                         uno::Reference< io::XInputStream > xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
436                         xObj.Assign( pDlg->GetObject(),
437                                      xIconMetaFile.is() ? embed::Aspects::MSOLE_ICON : embed::Aspects::MSOLE_CONTENT );
438                         if ( xIconMetaFile.is() )
439                             xObj.SetGraphicStream( xIconMetaFile, aIconMediaType );
440 
441                         DELETEZ( pDlg );
442                     }
443 
444                     break;
445                 }
446 
447                 default:
448                     break;
449             }
450         }
451 
452         if ( xObj.is() )
453         {
454             if( InsertOleObject( xObj ) && bActivate && bDoVerb )
455             {
456                 SfxInPlaceClient* pClient = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
457                 if ( !pClient )
458                 {
459                     pClient = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
460                     SetCheckForOLEInCaption( sal_True );
461                 }
462 
463                 if ( xObj.GetViewAspect() == embed::Aspects::MSOLE_ICON )
464                 {
465                     SwRect aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
466                     aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
467                     MapMode aMapMode( MAP_TWIP );
468                     Size aSize = xObj.GetSize( &aMapMode );
469                     aArea.Width( aSize.Width() );
470                     aArea.Height( aSize.Height() );
471                     RequestObjectResize( aArea, xObj.GetObject() );
472                 }
473                 else
474                     CalcAndSetScale( xObj );
475 
476                 //#50270# Error brauchen wir nicht handeln, das erledigt das
477                 //DoVerb in der SfxViewShell
478                 pClient->DoVerb( SVVERB_SHOW );
479 
480                 // TODO/LATER: set document name - should be done in Client
481                 //if ( !ERRCODE_TOERROR( nErr ) )
482                 //    xIPObj->SetDocumentName( GetView().GetDocShell()->GetTitle() );
483             }
484         }
485     }
486     else
487     {
488         if( HasSelection() )
489             DelRight();
490         InsertOleObject( xRef );
491     }
492 }
493 
494 /*------------------------------------------------------------------------
495  Beschreibung:   Object in die Core einfuegen.
496                  Vom ClipBoard oder Insert
497 ------------------------------------------------------------------------*/
498 
InsertOleObject(const svt::EmbeddedObjectRef & xRef,SwFlyFrmFmt ** pFlyFrmFmt)499 sal_Bool SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef& xRef, SwFlyFrmFmt **pFlyFrmFmt )
500 {
501     ResetCursorStack();
502     StartAllAction();
503 
504     StartUndo(UNDO_INSERT);
505 
506     //Some differences between StarMath and any other objects:
507     //1. Selections should be deleted. For StarMath the Text should be
508     //   passed to the Object
509     //2. If the cursor is at the end of an non empty paragraph a paragraph
510     //   break should be insertet. StarMath objects are character bound and
511     //   no break should be inserted.
512     //3. If an selektion is passed to a StarMath object, this object should
513     //   not be activated. sal_False should be returned then.
514     sal_Bool bStarMath = sal_True;
515     sal_Bool bActivate = sal_True;
516 
517     // set parent to get correct VisArea(in case of object needing parent printer)
518     uno::Reference < container::XChild > xChild( xRef.GetObject(), uno::UNO_QUERY );
519     if ( xChild.is() )
520         xChild->setParent( pDoc->GetDocShell()->GetModel() );
521 
522     SvGlobalName aCLSID( xRef->getClassID() );
523     bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
524     if( IsSelection() )
525     {
526         if( bStarMath )
527         {
528             String aMathData;
529             GetSelectedText( aMathData, GETSELTXT_PARABRK_TO_ONLYCR );
530 
531             if( aMathData.Len() && svt::EmbeddedObjectRef::TryRunningState( xRef.GetObject() ) )
532             {
533                 uno::Reference < beans::XPropertySet > xSet( xRef->getComponent(), uno::UNO_QUERY );
534                 if ( xSet.is() )
535                 {
536                     try
537                     {
538                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("Formula"), uno::makeAny( ::rtl::OUString( aMathData ) ) );
539                         bActivate = sal_False;
540                     }
541                     catch ( uno::Exception& )
542                     {
543                     }
544                 }
545             }
546         }
547         DelRight();
548     }
549 
550     if ( !bStarMath )
551         SwFEShell::SplitNode( sal_False, sal_False );
552 
553     EnterSelFrmMode();
554 
555     SwFlyFrmAttrMgr aFrmMgr( sal_True, this, FRMMGR_TYPE_OLE );
556     aFrmMgr.SetHeightSizeType(ATT_FIX_SIZE);
557 
558     SwRect aBound;
559     CalcBoundRect( aBound, aFrmMgr.GetAnchor() );
560 
561     //The Size should be suggested by the OLE server
562     MapMode aMapMode( MAP_TWIP );
563     Size aSz = xRef.GetSize( &aMapMode );
564 
565     //Object size can be limited
566     if ( aSz.Width() > aBound.Width() )
567     {
568         //Immer proportional begrenzen.
569         aSz.Height() = aSz.Height() * aBound.Width() / aSz.Width();
570         aSz.Width() = aBound.Width();
571     }
572     aFrmMgr.SetSize( aSz );
573     SwFlyFrmFmt *pFmt = SwFEShell::InsertObject( xRef, &aFrmMgr.GetAttrSet() );
574 
575     // --> #i972#
576     if ( bStarMath && pDoc->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ) )
577         AlignFormulaToBaseline( xRef.GetObject() );
578     // <--
579 
580     if (pFlyFrmFmt)
581         *pFlyFrmFmt = pFmt;
582 
583     if ( SotExchange::IsChart( aCLSID ) )
584     {
585         uno::Reference< embed::XEmbeddedObject > xEmbeddedObj( xRef.GetObject(), uno::UNO_QUERY );
586         if ( xEmbeddedObj.is() )
587         {
588             bool bDisableDataTableDialog = false;
589             svt::EmbeddedObjectRef::TryRunningState( xEmbeddedObj );
590             uno::Reference< beans::XPropertySet > xProps( xEmbeddedObj->getComponent(), uno::UNO_QUERY );
591             if ( xProps.is() &&
592                  ( xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ) ) >>= bDisableDataTableDialog ) &&
593                  bDisableDataTableDialog )
594             {
595                 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ),
596                     uno::makeAny( sal_False ) );
597                 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableComplexChartTypes" ) ),
598                     uno::makeAny( sal_False ) );
599                 uno::Reference< util::XModifiable > xModifiable( xProps, uno::UNO_QUERY );
600                 if ( xModifiable.is() )
601                 {
602                     xModifiable->setModified( sal_True );
603                 }
604             }
605         }
606     }
607 
608     EndAllAction();
609     GetView().AutoCaption(OLE_CAP, &aCLSID);
610 
611     SwRewriter aRewriter;
612 
613     if ( bStarMath )
614         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_MATH_FORMULA));
615     else if ( SotExchange::IsChart( aCLSID ) )
616         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_CHART));
617     else
618         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_OLE));
619 
620     EndUndo(UNDO_INSERT, &aRewriter);
621 
622     return bActivate;
623 }
624 
625 /*------------------------------------------------------------------------
626     Beschreibung: Das aktuelle selektierte OLE-Objekt wird mit dem
627                   Verb in den Server geladen.
628 ------------------------------------------------------------------------*/
629 
630 
631 
LaunchOLEObj(long nVerb)632 void SwWrtShell::LaunchOLEObj( long nVerb )
633 {
634     if ( GetCntType() == CNT_OLE &&
635          !GetView().GetViewFrame()->GetFrame().IsInPlace() )
636     {
637         svt::EmbeddedObjectRef& xRef = GetOLEObject();
638         ASSERT( xRef.is(), "OLE not found" );
639         SfxInPlaceClient* pCli=0;
640 
641         pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() );
642         if ( !pCli )
643             pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef );
644 
645         ((SwOleClient*)pCli)->SetInDoVerb( sal_True );
646 
647         CalcAndSetScale( xRef );
648         pCli->DoVerb( nVerb );
649 
650         ((SwOleClient*)pCli)->SetInDoVerb( sal_False );
651         CalcAndSetScale( xRef );
652     }
653 }
654 
MoveObjectIfActive(svt::EmbeddedObjectRef & xObj,const Point & rOffset)655 void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef& xObj, const Point& rOffset )
656 {
657     try
658     {
659         sal_Int32 nState = xObj->getCurrentState();
660         if ( nState == ::com::sun::star::embed::EmbedStates::INPLACE_ACTIVE
661           || nState == ::com::sun::star::embed::EmbedStates::UI_ACTIVE )
662         {
663             SfxInPlaceClient* pCli =
664                 GetView().FindIPClient( xObj.GetObject(), &(GetView().GetEditWin()) );
665             if ( pCli )
666             {
667                 Rectangle aArea = pCli->GetObjArea();
668                 aArea += rOffset;
669                 pCli->SetObjArea( aArea );
670             }
671         }
672     }
673     catch( uno::Exception& )
674     {}
675 }
676 
677 
CalcAndSetScale(svt::EmbeddedObjectRef & xObj,const SwRect * pFlyPrtRect,const SwRect * pFlyFrmRect,const bool bNoTxtFrmPrtAreaChanged)678 void SwWrtShell::CalcAndSetScale( svt::EmbeddedObjectRef& xObj,
679                                   const SwRect *pFlyPrtRect,
680                                   const SwRect *pFlyFrmRect,
681                                   const bool bNoTxtFrmPrtAreaChanged )
682 {
683     //Einstellen der Skalierung am Client. Diese ergibt sich aus der Differenz
684     //zwischen der VisArea des Objektes und der ObjArea.
685     ASSERT( xObj.is(), "ObjectRef not  valid" );
686 
687     sal_Int64 nAspect = xObj.GetViewAspect();
688     if ( nAspect == embed::Aspects::MSOLE_ICON )
689         return; // the replacement image is completely controlled by container in this case
690 
691     sal_Int64 nMisc = 0;
692     sal_Bool bLinkingChart = sal_False;
693 
694     try
695     {
696         nMisc = xObj->getStatus( nAspect );
697 
698         //Das kann ja wohl nur ein nicht aktives Objekt sein. Diese bekommen
699         //auf Wunsch die neue Groesse als VisArea gesetzt (StarChart)
700         if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
701         {
702             // TODO/MBA: testing
703             SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
704                         : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
705             if( !aRect.IsEmpty() )
706             {
707                 // TODO/LEAN: getMapUnit can switch object to running state
708                 // xObj.TryRunningState();
709 
710                 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
711 
712                 // TODO/LATER: needs complete VisArea?!
713                 Size aSize( OutputDevice::LogicToLogic( aRect.SVRect(), MAP_TWIP, aUnit ).GetSize() );
714                 awt::Size aSz;
715                 aSz.Width = aSize.Width();
716                 aSz.Height = aSize.Height();
717                 xObj->setVisualAreaSize( nAspect, aSz );
718                 // --> OD 2005-05-02 #i48419# - action 'UpdateReplacement' doesn't
719                 // have to change the modified state of the document.
720                 // This is only a workaround for the defect, that this action
721                 // modifies a document after load, because unnecessarily the
722                 // replacement graphic is updated, in spite of the fact that
723                 // nothing has been changed.
724                 // If the replacement graphic changes by this action, the document
725                 // will be already modified via other mechanisms.
726                 {
727                     bool bResetEnableSetModified(false);
728                     if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
729                     {
730                         GetDoc()->GetDocShell()->EnableSetModified( sal_False );
731                         bResetEnableSetModified = true;
732                     }
733 
734                     //#i79576# don't destroy chart replacement images on load
735                     //#i79578# don't request a new replacement image for charts to often
736                     //a chart sends a modified call to the framework if it was changed
737                     //thus the replacement update is already handled elsewhere
738                     if ( !SotExchange::IsChart( xObj->getClassID() ) )
739                         xObj.UpdateReplacement();
740 
741                     if ( bResetEnableSetModified )
742                     {
743                         GetDoc()->GetDocShell()->EnableSetModified( sal_True );
744                     }
745                 }
746                 // <--
747             }
748 
749             // TODO/LATER: this is only a workaround,
750             uno::Reference< chart2::XChartDocument > xChartDocument( xObj->getComponent(), uno::UNO_QUERY );
751             bLinkingChart = ( xChartDocument.is() && !xChartDocument->hasInternalDataProvider() );
752         }
753     }
754     catch ( uno::Exception& )
755     {
756         // TODO/LATER: handle the error
757         return;
758     }
759 
760     SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
761     if ( !pCli )
762     {
763         if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY & nMisc)
764              || bLinkingChart
765             // TODO/LATER: ResizeOnPrinterChange
766              //|| SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->GetMiscStatus()
767              // --> OD #i117189# - refine condition for non-resizable objects
768              // non-resizable objects need to be set the size back by this method
769              || ( bNoTxtFrmPrtAreaChanged && nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
770         {
771             pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
772         }
773         else
774             return;
775     }
776 
777     // TODO/LEAN: getMapUnit can switch object to running state
778     // xObj.TryRunningState();
779 
780     awt::Size aSize;
781     try
782     {
783         aSize = xObj->getVisualAreaSize( nAspect );
784     }
785     catch( embed::NoVisualAreaSizeException& )
786     {
787         DBG_ERROR( "Can't get visual area size!\n" );
788         // the scaling will not be done
789     }
790     catch( uno::Exception& )
791     {
792         // TODO/LATER: handle the error
793         DBG_ERROR( "Can't get visual area size!\n" );
794         return;
795     }
796 
797     Size _aVisArea( aSize.Width, aSize.Height );
798 
799     Fraction aScaleWidth( 1, 1 );
800     Fraction aScaleHeight( 1, 1 );
801 
802     sal_Bool bUseObjectSize = sal_False;
803 
804     // solange keine vernuenftige Size vom Object kommt, kann nichts
805     // skaliert werden
806     if( _aVisArea.Width() && _aVisArea.Height() )
807     {
808         const MapMode aTmp( MAP_TWIP );
809         MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
810         _aVisArea = OutputDevice::LogicToLogic( _aVisArea, aUnit, aTmp);
811         Size aObjArea;
812         if ( pFlyPrtRect )
813             aObjArea = pFlyPrtRect->SSize();
814         else
815             aObjArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ).SSize();
816 
817         // differ the aObjArea and _aVisArea by 1 Pixel then set new VisArea
818         long nX, nY;
819         SwSelPaintRects::Get1PixelInLogic( *this, &nX, &nY );
820         if( !( _aVisArea.Width() - nX <= aObjArea.Width() &&
821                _aVisArea.Width() + nX >= aObjArea.Width() &&
822                _aVisArea.Height()- nY <= aObjArea.Height()&&
823                _aVisArea.Height()+ nY >= aObjArea.Height() ))
824         {
825             // TODO/LATER: MISCSTATUS_RESIZEONPRINTERCHANGE
826             /*
827             if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & nMisc )
828             {
829                 //This type of objects should never be resized.
830                 //If this request comes from the Writer core (inaktive Object
831                 //ist resized), the Object should be resized too.
832                 //If this request comes from the Object itself, the Frame
833                 //in the Writer core should be resized.
834                 if ( pFlyPrtRect )      //Request from core?
835                 {
836                     xObj->SetVisArea( OutputDevice::LogicToLogic(
837                         pFlyPrtRect->SVRect(), MAP_TWIP, xObj->GetMapUnit() ));
838                 }
839                 else
840                 {
841                     SwRect aTmp( Point( LONG_MIN, LONG_MIN ), _aVisArea );
842                     RequestObjectResize( aTmp, xObj );
843                 }
844                 //Der Rest erledigt sich, weil wir eh wiederkommen sollten, evtl.
845                 //sogar rekursiv.
846                 return;
847             }
848             else*/
849 
850             if ( nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE )
851             {
852                 // the object must not be scaled, the size stored in object must be used for restoring
853                 bUseObjectSize = sal_True;
854             }
855             else
856             {
857                 aScaleWidth = Fraction( aObjArea.Width(),   _aVisArea.Width() );
858                 aScaleHeight = Fraction( aObjArea.Height(), _aVisArea.Height());
859             }
860         }
861     }
862 
863     //Jetzt ist auch der guenstige Zeitpunkt die ObjArea einzustellen.
864     //Die Scalierung muss beruecksichtigt werden.
865     SwRect aArea;
866     if ( pFlyPrtRect )
867     {
868         aArea = *pFlyPrtRect;
869         aArea += pFlyFrmRect->Pos();
870     }
871     else
872     {
873         aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
874         aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
875     }
876 
877     if ( bUseObjectSize )
878     {
879         // --> this moves non-resizable object so that when adding borders the baseline remains the same
880         const SwFlyFrmFmt *pFlyFrmFmt = dynamic_cast< const SwFlyFrmFmt * >( GetFlyFrmFmt() );
881         ASSERT( pFlyFrmFmt, "Could not find fly frame." );
882         if ( pFlyFrmFmt )
883         {
884             const Point &rPoint = pFlyFrmFmt->GetLastFlyFrmPrtRectPos();
885             SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
886                         : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
887             aArea += rPoint - aRect.Pos(); // adjust area by diff of printing area position in order to keep baseline alignment correct.
888         }
889         // <--
890         aArea.Width ( _aVisArea.Width() );
891         aArea.Height( _aVisArea.Height() );
892         RequestObjectResize( aArea, xObj.GetObject() );
893     }
894     else
895     {
896         aArea.Width ( Fraction( aArea.Width()  ) / pCli->GetScaleWidth() );
897         aArea.Height( Fraction( aArea.Height() ) / pCli->GetScaleHeight());
898     }
899 
900     pCli->SetObjAreaAndScale( aArea.SVRect(), aScaleWidth, aScaleHeight );
901 }
902 
903 
904 
ConnectObj(svt::EmbeddedObjectRef & xObj,const SwRect & rPrt,const SwRect & rFrm)905 void SwWrtShell::ConnectObj( svt::EmbeddedObjectRef& xObj, const SwRect &rPrt,
906                             const SwRect &rFrm )
907 {
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 );
912 }
913 
914 /*------------------------------------------------------------------------
915  Beschreibung:  Einfuegen harter Seitenumbruch;
916                 Selektionen werden ueberschrieben
917 ------------------------------------------------------------------------*/
918 
919 
920 
InsertPageBreak(const String * pPageDesc,sal_uInt16 nPgNum)921 void SwWrtShell::InsertPageBreak(const String *pPageDesc, sal_uInt16 nPgNum )
922 {
923     ResetCursorStack();
924     if( _CanInsert() )
925     {
926         ACT_KONTEXT(this);
927         StartUndo(UNDO_UI_INSERT_PAGE_BREAK);
928 
929         if ( !IsCrsrInTbl() )
930         {
931             if(HasSelection())
932                 DelRight();
933             SwFEShell::SplitNode();
934         }
935 
936         const SwPageDesc *pDesc = pPageDesc
937                                 ? FindPageDescByName( *pPageDesc, sal_True ) : 0;
938         if( pDesc )
939         {
940             SwFmtPageDesc aDesc( pDesc );
941             aDesc.SetNumOffset( nPgNum );
942             SetAttrItem( aDesc );
943         }
944         else
945             SetAttrItem( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) );
946         EndUndo(UNDO_UI_INSERT_PAGE_BREAK);
947     }
948 }
949 /*------------------------------------------------------------------------
950  Beschreibung:  Einfuegen harter Zeilenumbruch;
951                 Selektionen werden ueberschrieben
952 ------------------------------------------------------------------------*/
953 
954 
InsertLineBreak()955 void SwWrtShell::InsertLineBreak()
956 {
957     ResetCursorStack();
958     if( _CanInsert() )
959     {
960         if(HasSelection())
961             DelRight();
962 
963         const sal_Unicode cIns = 0x0A;
964         SvxAutoCorrect* pACorr = lcl_IsAutoCorr();
965         if( pACorr )
966             AutoCorrect( *pACorr, cIns );
967         else
968             SwWrtShell::Insert( String( cIns ) );
969     }
970 }
971 /*------------------------------------------------------------------------
972  Beschreibung:  Einfuegen harter Spaltenumbruch;
973                 Selektionen werden ueberschrieben
974 ------------------------------------------------------------------------*/
975 
976 
InsertColumnBreak()977 void SwWrtShell::InsertColumnBreak()
978 {
979     ACT_KONTEXT(this);
980     ResetCursorStack();
981     if( _CanInsert() )
982     {
983         StartUndo(UNDO_UI_INSERT_COLUMN_BREAK);
984 
985         if ( !IsCrsrInTbl() )
986         {
987             if(HasSelection())
988                 DelRight();
989             SwFEShell::SplitNode( sal_False, sal_False );
990         }
991         SetAttrItem(SvxFmtBreakItem(SVX_BREAK_COLUMN_BEFORE, RES_BREAK));
992 
993         EndUndo(UNDO_UI_INSERT_COLUMN_BREAK);
994     }
995 }
996 
997 /*------------------------------------------------------------------------
998  Beschreibung:  Einfuegen Fussnote
999  Parameter:     rStr -- optionales Fussnotenzeichen
1000 ------------------------------------------------------------------------*/
1001 
1002 
InsertFootnote(const String & rStr,sal_Bool bEndNote,sal_Bool bEdit)1003 void SwWrtShell::InsertFootnote(const String &rStr, sal_Bool bEndNote, sal_Bool bEdit )
1004 {
1005     ResetCursorStack();
1006     if( _CanInsert() )
1007     {
1008         if(HasSelection())
1009         {
1010             //collapse cursor to the end
1011             if(!IsCrsrPtAtEnd())
1012                 SwapPam();
1013             ClearMark();
1014         }
1015 
1016         SwFmtFtn aFootNote( bEndNote );
1017         if(rStr.Len())
1018             aFootNote.SetNumStr( rStr );
1019 
1020         SetAttrItem(aFootNote);
1021 
1022         if( bEdit )
1023         {
1024             // zur Bearbeiung des Fussnotentextes
1025             Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1026             GotoFtnTxt();
1027         }
1028     }
1029 }
1030 /*------------------------------------------------------------------------
1031  Beschreibung:  SplitNode; hier auch, da
1032                     - selektierter Inhalt geloescht wird;
1033                     - der Cursorstack gfs. zurueckgesetzt wird.
1034 ------------------------------------------------------------------------*/
1035 
1036 
SplitNode(sal_Bool bAutoFmt,sal_Bool bCheckTableStart)1037 void SwWrtShell::SplitNode( sal_Bool bAutoFmt, sal_Bool bCheckTableStart )
1038 {
1039     ResetCursorStack();
1040     if( _CanInsert() )
1041     {
1042         ACT_KONTEXT(this);
1043 
1044         rView.GetEditWin().FlushInBuffer();
1045         sal_Bool bHasSel = HasSelection();
1046         if( bHasSel )
1047         {
1048             StartUndo( UNDO_INSERT );
1049             DelRight();
1050         }
1051 
1052         SwFEShell::SplitNode( bAutoFmt, bCheckTableStart );
1053         if( bHasSel )
1054             EndUndo( UNDO_INSERT );
1055     }
1056 }
1057 
1058 /*------------------------------------------------------------------------
1059  Beschreibung:  Numerierung anschalten
1060  Parameter:     Optionale Angabe eines Namens fuer die benannte Liste;
1061                 dieser bezeichnet eine Position, wenn er in eine
1062                 Zahl konvertierbar ist und kleiner ist als nMaxRules.
1063 -------------------------------------------------------------------------*/
1064 
1065 
1066 // zum Testen der CharFormate an der Numerierung
1067 // extern void SetNumChrFmt( SwWrtShell*, SwNumRules& );
1068 
1069 // -> #i40041#
1070 // --> OD 2005-10-25 #b6340308#
1071 // Preconditions (as far as OD has figured out):
1072 // - <SwEditShell::HasNumber()> is sal_False, if <bNum> is sal_True
1073 // - <SwEditShell::HasBullet()> is sal_False, if <bNum> is sal_False
1074 // Behavior of method is determined by the current situation at the current
1075 // cursor position in the document.
NumOrBulletOn(sal_Bool bNum)1076 void SwWrtShell::NumOrBulletOn(sal_Bool bNum)
1077 {
1078     // determine numbering rule found at current cursor position in the docment.
1079     const SwNumRule* pCurRule = GetCurNumRule();
1080 
1081     StartUndo(UNDO_NUMORNONUM);
1082 
1083     const SwNumRule * pNumRule = pCurRule;
1084 
1085     // --> OD 2005-10-25 #b6340308#
1086     // - activate outline rule respectively turning on outline rule for
1087     //   current text node. But, only for turning on a numbering (<bNum> == sal_True).
1088     // - overwrite found numbering rule at current cursor position, if
1089     //   no numbering rule can be retrieved from the paragraph style.
1090     bool bContinueFoundNumRule( false );
1091     bool bActivateOutlineRule( false );
1092     int nActivateOutlineLvl( MAXLEVEL );    // only relevant, if <bActivateOutlineRule> == sal_True
1093     SwTxtFmtColl * pColl = GetCurTxtFmtColl();
1094     if ( pColl )
1095     {
1096         // --> OD 2005-10-25 #b6340308# - retrieve numbering rule at paragraph
1097         // style, which is found at current cursor position in the document.
1098         SwNumRule* pCollRule = pDoc->FindNumRulePtr(pColl->GetNumRule().GetValue());
1099         // --> OD 2005-10-25 #125993# - The outline numbering rule isn't allowed
1100         // to be derived from a parent paragraph style to a derived one.
1101         // Thus check, if the found outline numbering rule is directly
1102         // set at the paragraph style <pColl>. If not, set <pCollRule> to NULL
1103         if ( pCollRule && pCollRule == GetDoc()->GetOutlineNumRule() )
1104         {
1105             const SwNumRule* pDirectCollRule =
1106                     pDoc->FindNumRulePtr(pColl->GetNumRule( sal_False ).GetValue());
1107             if ( !pDirectCollRule )
1108             {
1109                 pCollRule = 0;
1110             }
1111         }
1112         // --> OD 2006-11-20 #i71764#
1113         // Document setting OUTLINE_LEVEL_YIELDS_OUTLINE_RULE has no influence
1114         // any more.
1115 //        if ( pCollRule == NULL &&
1116 //             NO_NUMBERING != pColl->GetOutlineLevel() &&
1117 //             GetDoc()->get(IDocumentSettingAccess::OUTLINE_LEVEL_YIELDS_OUTLINE_RULE) )
1118 //        {
1119 //            pCollRule = GetDoc()->GetOutlineNumRule();
1120 //        }
1121         // <--
1122 
1123         // <--
1124         // --> OD 2005-10-25 #b6340308#
1125         if ( !pCollRule )
1126         {
1127             pNumRule = pCollRule;
1128         }
1129         // --> OD 2006-06-12 #b6435904#
1130         // no activation or continuation of outline numbering in Writer/Web document
1131         else if ( bNum &&
1132                   !dynamic_cast<SwWebDocShell*>(GetDoc()->GetDocShell()) &&
1133                   pCollRule == GetDoc()->GetOutlineNumRule() )
1134         // <--
1135         {
1136             if ( pNumRule == pCollRule )
1137             {
1138                 // check, if text node at current cursor positioned is counted.
1139                 // If not, let it been counted. Then it has to be checked,
1140                 // of the outline numbering has to be activated or continued.
1141                 SwTxtNode* pTxtNode =
1142                             GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1143                 if ( pTxtNode && !pTxtNode->IsCountedInList() )
1144                 {
1145                     // check, if numbering of the outline level of the pararaph
1146                     // style is active. If not, activate this outline level.
1147                     nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
1148                     ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(),   //<-end,zhaojianwei
1149                             "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1150                     if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&        //<-end,zhaojianwei
1151                          pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1152                             == SVX_NUM_NUMBER_NONE )
1153                     {
1154                         // activate outline numbering
1155                         bActivateOutlineRule = true;
1156                     }
1157                     else
1158                     {
1159                         // turning on outline numbering at current cursor position
1160                         bContinueFoundNumRule = true;
1161                     }
1162                 }
1163                 else
1164                 {
1165                     // --> OD 2009-08-27 #i101234#
1166                     // activate outline numbering, because from the precondition
1167                     // it's known, that <SwEdit::HasNumber()> == sal_False
1168                     bActivateOutlineRule = true;
1169                     nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei
1170                 }
1171             }
1172             else if ( !pNumRule )
1173             {
1174                 // --> OD 2009-08-27 #i101234#
1175                 // Check, if corresponding list level of the outline numbering
1176                 // has already a numbering format set.
1177                 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei,need further consideration
1178                 if ( pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1179                                 == SVX_NUM_NUMBER_NONE )
1180                 {
1181                     // activate outline numbering, because from the precondition
1182                     // it's known, that <SwEdit::HasNumber()> == sal_False
1183                     bActivateOutlineRule = true;
1184                 }
1185                 else
1186                 {
1187                     // turning on outline numbering at current cursor position
1188                     bContinueFoundNumRule = true;
1189                 }
1190                 // <--
1191             }
1192             else
1193             {
1194                 // check, if numbering of the outline level of the pararaph
1195                 // style is active. If not, activate this outline level.
1196                 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//#outline level,zhaojianwei
1197                 ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(),//#outline level,zhaojianwei
1198                         "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1199                 if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&//#outline level,zhaojianwei
1200                      pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1201                         == SVX_NUM_NUMBER_NONE )
1202                 {
1203                     // activate outline numbering
1204                     bActivateOutlineRule = true;
1205                 }
1206                 else
1207                 {
1208                     // turning on outline numbering at current cursor position
1209                     bContinueFoundNumRule = true;
1210                 }
1211             }
1212             pNumRule = pCollRule;
1213         }
1214     }
1215 
1216     // --> OD 2005-10-25 #b6340308#
1217     // Only automatic numbering/bullet rules should be changed.
1218     // Note: The outline numbering rule is also an automatic one. It's only
1219     //       changed, if it has to be activated.
1220     if ( pNumRule )
1221     {
1222         if ( !pNumRule->IsAutoRule() )
1223         {
1224             pNumRule = 0;
1225         }
1226         else if ( pNumRule == GetDoc()->GetOutlineNumRule() &&
1227                   !bActivateOutlineRule && !bContinueFoundNumRule )
1228         {
1229             pNumRule = 0;
1230         }
1231     }
1232     // <--
1233 
1234     // --> OD 2005-10-25 #b6340308#
1235     // Search for a previous numbering/bullet rule to continue it.
1236     // --> OD 2008-03-18 #refactorlists#
1237     String sContinuedListId;
1238     if ( !pNumRule )
1239     {
1240         pNumRule = GetDoc()->SearchNumRule( *GetCrsr()->GetPoint(),
1241                                             false, bNum, false, 0,
1242                                             sContinuedListId );
1243         bContinueFoundNumRule = pNumRule != 0;
1244     }
1245     // <--
1246 
1247     if (pNumRule)
1248     {
1249         SwNumRule aNumRule(*pNumRule);
1250 
1251         // --> OD 2005-10-25 #b6340308#
1252         // do not change found numbering/bullet rule, if it should only be continued.
1253         if ( !bContinueFoundNumRule )
1254         {
1255             SwTxtNode * pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1256 
1257             if (pTxtNode)
1258             {
1259                 // --> OD 2005-10-26 #b6340308# - use above retrieve outline
1260                 // level, if outline numbering has to be activated.
1261                 int nLevel = bActivateOutlineRule  ////#outline level,zhaojianwei,need more consideration
1262                               ? nActivateOutlineLvl
1263                               : pTxtNode->GetActualListLevel();
1264                 // <--
1265 
1266                 if (nLevel < 0)
1267                     nLevel = 0;
1268 
1269                 if (nLevel >= MAXLEVEL)
1270                     nLevel = MAXLEVEL - 1;
1271 
1272                 SwNumFmt aFmt(aNumRule.Get(static_cast<sal_uInt16>(nLevel)));
1273 
1274                 if (bNum)
1275                     aFmt.SetNumberingType(SVX_NUM_ARABIC);
1276                 else
1277                 {
1278                     // --> OD 2008-06-03 #i63395#
1279                     // Only apply user defined default bullet font
1280                     if ( numfunc::IsDefBulletFontUserDefined() )
1281                     {
1282                         const Font* pFnt = &numfunc::GetDefBulletFont();
1283                         aFmt.SetBulletFont( pFnt );
1284                     }
1285                     // <--
1286                     aFmt.SetBulletChar( numfunc::GetBulletChar(static_cast<sal_uInt8>(nLevel)));
1287                     aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1288                     // #i93908# clear suffix for bullet lists
1289                     aFmt.SetPrefix(::rtl::OUString());
1290                     aFmt.SetSuffix(::rtl::OUString());
1291                 }
1292                 aNumRule.Set(static_cast<sal_uInt16>(nLevel), aFmt);
1293             }
1294         }
1295         // <--
1296 
1297         // --> OD 2008-02-08 #newlistlevelattrs#
1298         // reset indent attribute on applying list style
1299         // --> OD 2008-03-27 #refactorlists#
1300         SetCurNumRule( aNumRule, false, sContinuedListId, true );
1301         // <--
1302     }
1303     else
1304     {
1305         // --> OD 2009-08-27 #i95907#
1306         const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1307                                     numfunc::GetDefaultPositionAndSpaceMode() );
1308         // --> OD 2008-02-11 #newlistlevelattrs#
1309         SwNumRule aNumRule( GetUniqueNumRuleName(), ePosAndSpaceMode );
1310         // <--
1311         // <--
1312         // Zeichenvorlage an die Numerierung haengen
1313         SwCharFmt* pChrFmt;
1314         SwDocShell* pDocSh = GetView().GetDocShell();
1315         // --> OD 2008-06-03 #i63395#
1316         // Only apply user defined default bullet font
1317         const Font* pFnt = numfunc::IsDefBulletFontUserDefined()
1318                            ? &numfunc::GetDefBulletFont()
1319                            : 0;
1320         // <--
1321 
1322         if (bNum)
1323         {
1324             pChrFmt = GetCharFmtFromPool( RES_POOLCHR_NUM_LEVEL );
1325         }
1326         else
1327         {
1328             pChrFmt = GetCharFmtFromPool( RES_POOLCHR_BUL_LEVEL );
1329         }
1330 
1331         const SwTxtNode* pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1332         const SwTwips nWidthOfTabs = pTxtNode
1333                                      ? pTxtNode->GetWidthOfLeadingTabs()
1334                                      : 0;
1335         GetDoc()->RemoveLeadingWhiteSpace( *GetCrsr()->GetPoint() );
1336 
1337         const bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
1338         const bool bRightToLeft = IsInRightToLeftText();
1339         for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
1340         {
1341             SwNumFmt aFmt( aNumRule.Get( nLvl ) );
1342             aFmt.SetCharFmt( pChrFmt );
1343 
1344             if (! bNum)
1345             {
1346                 // --> OD 2008-06-03 #i63395#
1347                 // Only apply user defined default bullet font
1348                 if ( pFnt )
1349                 {
1350                     aFmt.SetBulletFont( pFnt );
1351                 }
1352                 aFmt.SetBulletChar( numfunc::GetBulletChar(nLvl) );
1353                 aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1354                 // #i93908# clear suffix for bullet lists
1355                 aFmt.SetPrefix(::rtl::OUString());
1356                 aFmt.SetSuffix(::rtl::OUString());
1357             }
1358 
1359             // --> OD 2009-08-26 #i95907#
1360             if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1361             {
1362                 if(bHtml && nLvl)
1363                 {
1364                     // 1/2" fuer HTML
1365                     aFmt.SetLSpace(720);
1366                     aFmt.SetAbsLSpace(nLvl * 720);
1367                 }
1368                 else if ( nWidthOfTabs > 0 )
1369                 {
1370                     aFmt.SetAbsLSpace(nWidthOfTabs + nLvl * 720);
1371                 }
1372             }
1373             // <--
1374 
1375             // --> FME 2005-01-21 #i38904#  Default alignment for
1376             // numbering/bullet should be rtl in rtl paragraph:
1377             if ( bRightToLeft )
1378             {
1379                 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
1380             }
1381             // <--
1382 
1383             aNumRule.Set( nLvl, aFmt );
1384         }
1385 
1386         // --> OD 2009-08-26 #i95907#
1387         if ( pTxtNode &&
1388              ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1389         {
1390             // --> OD 2010-01-05 #b6884103#
1391 //            short nTxtNodeFirstLineOffset( 0 );
1392 //            pTxtNode->GetFirstLineOfsWithNum( nTxtNodeFirstLineOffset );
1393 //            const SwTwips nTxtNodeIndent = pTxtNode->GetLeftMarginForTabCalculation() +
1394 //                                           nTxtNodeFirstLineOffset;
1395             const SwTwips nTxtNodeIndent = pTxtNode->GetAdditionalIndentForStartingNewList();
1396             // <--
1397             if ( ( nTxtNodeIndent + nWidthOfTabs ) != 0 )
1398             {
1399                 // --> OD 2010-05-05 #i111172#
1400                 // If text node is already inside a list, assure that the indents
1401                 // are the same. Thus, adjust the indent change value by subtracting
1402                 // indents of to be applied list style.
1403                 SwTwips nIndentChange = nTxtNodeIndent + nWidthOfTabs;
1404                 if ( pTxtNode->GetNumRule() )
1405                 {
1406                     const SwNumFmt aFmt( aNumRule.Get( 0 ) );
1407                     if ( aFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1408                     {
1409                         nIndentChange -= aFmt.GetIndentAt() + aFmt.GetFirstLineIndent();
1410                     }
1411                 }
1412                 // <--
1413                 aNumRule.ChangeIndent( nIndentChange );
1414             }
1415         }
1416         // <--
1417         // --> OD 2008-02-08 #newlistlevelattrs#
1418         // reset indent attribute on applying list style
1419         // --> OD 2008-03-17 #refactorlists#
1420         // start new list
1421         SetCurNumRule( aNumRule, true, String(), true );
1422         // <--
1423     }
1424 
1425     EndUndo(UNDO_NUMORNONUM);
1426 }
1427 // <- #i40041#
1428 
NumOn()1429 void SwWrtShell::NumOn()
1430 {
1431     NumOrBulletOn(sal_True);
1432 }
1433 
NumOrBulletOff()1434 void SwWrtShell::NumOrBulletOff()
1435 {
1436     const SwNumRule * pCurNumRule = GetCurNumRule();
1437 
1438     if (pCurNumRule)
1439     {
1440         if (pCurNumRule->IsOutlineRule())
1441         {
1442             SwNumRule aNumRule(*pCurNumRule);
1443 
1444             SwTxtNode * pTxtNode =
1445                 GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1446 
1447             if (pTxtNode)
1448             {
1449                 sal_uInt16 nLevel = sal::static_int_cast<sal_uInt16, sal_Int32>(pTxtNode->GetActualListLevel());
1450                 SwNumFmt aFmt(aNumRule.Get(nLevel));
1451 
1452                 aFmt.SetNumberingType(SVX_NUM_NUMBER_NONE);
1453                 aNumRule.Set(nLevel, aFmt);
1454 
1455                 // --> OD 2008-03-17 #refactorlists#
1456                 // no start or continuation of a list - the outline style is only changed.
1457                 SetCurNumRule( aNumRule, false );
1458                 // <--
1459             }
1460         }
1461         else
1462         {
1463             DelNumRules();
1464         }
1465 
1466         // --> OD 2005-10-24 #126346# - Cursor can not be anymore in front of
1467         // a label, because numbering/bullet is switched off.
1468         SetInFrontOfLabel( sal_False );
1469         // <--
1470     }
1471 }
1472 // <- #i29560#
1473 
1474 /*------------------------------------------------------------------------
1475  Beschreibung:  Default-Bulletliste erfragen
1476 ------------------------------------------------------------------------*/
1477 
BulletOn()1478 void SwWrtShell::BulletOn()
1479 {
1480     NumOrBulletOn(sal_False);
1481 }
1482 
1483 
1484 /*--------------------------------------------------
1485 
1486 --------------------------------------------------*/
GetSelectionType() const1487 SelectionType SwWrtShell::GetSelectionType() const
1488 {
1489     // ContentType kann nicht ermittelt werden innerhalb einer
1490     // Start-/Endactionklammerung.
1491     // Da es keinen ungueltigen Wert gibt, wird TEXT geliefert.
1492     // Der Wert ist egal, da in EndAction ohnehin aktualisiert wird.
1493 
1494     if ( BasicActionPend() )
1495         return IsSelFrmMode() ? nsSelectionType::SEL_FRM : nsSelectionType::SEL_TXT;
1496 
1497     SwView &_rView = ((SwView&)GetView());
1498     if (_rView.GetPostItMgr() && _rView.GetPostItMgr()->HasActiveSidebarWin() )
1499         return nsSelectionType::SEL_POSTIT;
1500 
1501     int nCnt;
1502     // Insertion of a text frame is not a DrawMode
1503     if ( !_rView.GetEditWin().IsFrmAction() &&
1504         (IsObjSelected() || (_rView.IsDrawMode() && !IsFrmSelected()) ))
1505     {
1506         if (GetDrawView()->IsTextEdit())
1507             nCnt = nsSelectionType::SEL_DRW_TXT;
1508         else
1509         {
1510             if (GetView().IsFormMode()) // Nur Forms selektiert
1511                 nCnt = nsSelectionType::SEL_DRW_FORM;
1512             else
1513                 nCnt = nsSelectionType::SEL_DRW;            // Irgendein Draw-Objekt
1514 
1515             if (_rView.IsBezierEditMode())
1516                 nCnt |= nsSelectionType::SEL_BEZ;
1517             else if( GetDrawView()->GetContext() == SDRCONTEXT_MEDIA )
1518                 nCnt |= nsSelectionType::SEL_MEDIA;
1519 
1520             if (svx::checkForSelectedCustomShapes(
1521                 const_cast<SdrView *>(GetDrawView()),
1522                 true /* bOnlyExtruded */ ))
1523             {
1524                 nCnt |= nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE;
1525             }
1526             sal_uInt32 nCheckStatus = 0;
1527             if (svx::checkForSelectedFontWork(
1528                 const_cast<SdrView *>(GetDrawView()), nCheckStatus ))
1529             {
1530                 nCnt |= nsSelectionType::SEL_FONTWORK;
1531             }
1532         }
1533 
1534         return nCnt;
1535     }
1536 
1537     nCnt = GetCntType();
1538 
1539     if ( IsFrmSelected() )
1540     {
1541         if (_rView.IsDrawMode())
1542             _rView.LeaveDrawCreate();   // Aufraeumen (Bug #45639)
1543         if ( !(nCnt & (CNT_GRF | CNT_OLE)) )
1544             return nsSelectionType::SEL_FRM;
1545     }
1546 
1547     if ( IsCrsrInTbl() )
1548         nCnt |= nsSelectionType::SEL_TBL;
1549 
1550     if ( IsTableMode() )
1551         nCnt |= (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS);
1552 
1553     // Do not pop up numbering toolbar, if the text node has a numbering of type SVX_NUM_NUMBER_NONE.
1554     const SwNumRule* pNumRule = GetCurNumRule();
1555     if ( pNumRule )
1556     {
1557         const SwTxtNode* pTxtNd =
1558             GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1559 
1560         if ( pTxtNd && pTxtNd->IsInList() )
1561         {
1562             const SwNumFmt& rFmt = pNumRule->Get(sal::static_int_cast< sal_uInt8, sal_Int32>(pTxtNd->GetActualListLevel()));
1563             if ( SVX_NUM_NUMBER_NONE != rFmt.GetNumberingType() )
1564                 nCnt |= nsSelectionType::SEL_NUM;
1565         }
1566     }
1567 
1568     return nCnt;
1569 }
1570 
1571 /*------------------------------------------------------------------------
1572  Beschreibung:  Finden der TextCollection mit dem Name rCollname
1573  Return:                Pointer auf die Collection oder 0, wenn keine
1574                                 TextCollection mit diesem Namen existiert oder
1575                                 diese eine Defaultvorlage ist.
1576 ------------------------------------------------------------------------*/
1577 
1578 
GetParaStyle(const String & rCollName,GetStyle eCreate)1579 SwTxtFmtColl *SwWrtShell::GetParaStyle(const String &rCollName, GetStyle eCreate )
1580 {
1581     SwTxtFmtColl* pColl = FindTxtFmtCollByName( rCollName );
1582     if( !pColl && GETSTYLE_NOCREATE != eCreate )
1583     {
1584         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1585         if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1586             pColl = GetTxtCollFromPool( nId );
1587     }
1588     return pColl;
1589 }
1590 /*------------------------------------------------------------------------
1591  Beschreibung:  Finden der Zeichenvorlage mit dem Name rCollname
1592  Return:                Pointer auf die Collection oder 0, wenn keine
1593                                 Zeichenvorlage mit diesem Namen existiert oder
1594                                 diese eine Defaultvorlage oder automatische Vorlage ist.
1595 ------------------------------------------------------------------------*/
1596 
1597 
1598 
GetCharStyle(const String & rFmtName,GetStyle eCreate)1599 SwCharFmt *SwWrtShell::GetCharStyle(const String &rFmtName, GetStyle eCreate )
1600 {
1601     SwCharFmt* pFmt = FindCharFmtByName( rFmtName );
1602     if( !pFmt && GETSTYLE_NOCREATE != eCreate )
1603     {
1604         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1605         if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1606             pFmt = (SwCharFmt*)GetFmtFromPool( nId );
1607     }
1608     return pFmt;
1609 }
1610 
1611 /*------------------------------------------------------------------------
1612  Beschreibung:  Finden des Tabellenformates mit dem Name rFmtname
1613  Return:                Pointer auf das Format oder 0, wenn kein
1614                                 Rahmenformat mit diesem Namen existiert oder
1615                                 dieses eine Defaultformat oder automatisches Format ist.
1616 ------------------------------------------------------------------------*/
1617 
1618 
1619 
GetTblStyle(const String & rFmtName)1620 SwFrmFmt *SwWrtShell::GetTblStyle(const String &rFmtName)
1621 {
1622     SwFrmFmt *pFmt = 0;
1623     for( sal_uInt16 i = GetTblFrmFmtCount(); i; )
1624         if( !( pFmt = &GetTblFrmFmt( --i ) )->IsDefault() &&
1625             pFmt->GetName() == rFmtName && IsUsed( *pFmt ) )
1626             return pFmt;
1627     return 0;
1628 }
1629 
1630 
1631 /*------------------------------------------------------------------------
1632  Beschreibung:  Anwenden der Vorlagen
1633 ------------------------------------------------------------------------*/
1634 
1635 
1636 
SetPageStyle(const String & rCollName)1637 void SwWrtShell::SetPageStyle(const String &rCollName)
1638 {
1639     if( !SwCrsrShell::HasSelection() && !IsSelFrmMode() && !IsObjSelected() )
1640     {
1641         SwPageDesc* pDesc = FindPageDescByName( rCollName, sal_True );
1642         if( pDesc )
1643             ChgCurPageDesc( *pDesc );
1644     }
1645 }
1646 
1647 /*------------------------------------------------------------------------
1648  Beschreibung:  Zugriff Vorlagen
1649 ------------------------------------------------------------------------*/
1650 
1651 
1652 
GetCurPageStyle(const sal_Bool bCalcFrm) const1653 String SwWrtShell::GetCurPageStyle( const sal_Bool bCalcFrm ) const
1654 {
1655     return GetPageDesc(GetCurPageDesc( bCalcFrm )).GetName();
1656 }
1657 
1658 /*------------------------------------------------------------------------
1659  Beschreibung:  Aktuelle Vorlage anhand der geltenden Attribute aendern
1660 ------------------------------------------------------------------------*/
1661 
1662 
QuickUpdateStyle()1663 void SwWrtShell::QuickUpdateStyle()
1664 {
1665     SwTxtFmtColl *pColl = GetCurTxtFmtColl();
1666 
1667     // Standard kann nicht geaendert werden
1668     if(pColl && !pColl->IsDefault())
1669     {
1670         FillByEx(pColl);
1671             // Vorlage auch anwenden, um harte Attributierung
1672             // zu entfernen
1673         SetTxtFmtColl(pColl);
1674     }
1675 }
1676 
1677 
AutoUpdatePara(SwTxtFmtColl * pColl,const SfxItemSet & rStyleSet)1678 void SwWrtShell::AutoUpdatePara(SwTxtFmtColl* pColl, const SfxItemSet& rStyleSet)
1679 {
1680     SfxItemSet aCoreSet( GetAttrPool(),
1681             RES_CHRATR_BEGIN,           RES_CHRATR_END - 1,
1682             RES_PARATR_BEGIN,           RES_PARATR_END - 1,
1683             RES_FRMATR_BEGIN,           RES_FRMATR_END - 1,
1684             SID_ATTR_TABSTOP_POS,       SID_ATTR_TABSTOP_POS,
1685             SID_ATTR_TABSTOP_DEFAULTS,  SID_ATTR_TABSTOP_DEFAULTS,
1686             SID_ATTR_TABSTOP_OFFSET,    SID_ATTR_TABSTOP_OFFSET,
1687             SID_ATTR_BORDER_INNER,      SID_ATTR_BORDER_INNER,
1688             SID_ATTR_PARA_MODEL,        SID_ATTR_PARA_KEEP,
1689             SID_ATTR_PARA_PAGENUM,      SID_ATTR_PARA_PAGENUM,
1690             0   );
1691     GetCurAttr( aCoreSet );
1692     sal_Bool bReset = sal_False;
1693     SfxItemIter aParaIter( aCoreSet );
1694     const SfxPoolItem* pParaItem = aParaIter.FirstItem();
1695     while( pParaItem )
1696     {
1697         if(!IsInvalidItem(pParaItem))
1698         {
1699             sal_uInt16 nWhich = pParaItem->Which();
1700             if(SFX_ITEM_SET == aCoreSet.GetItemState(nWhich) &&
1701                SFX_ITEM_SET == rStyleSet.GetItemState(nWhich))
1702             {
1703                 aCoreSet.ClearItem(nWhich);
1704                 bReset = sal_True;
1705             }
1706         }
1707         pParaItem = aParaIter.NextItem();
1708     }
1709     StartAction();
1710     if(bReset)
1711     {
1712         ResetAttr();
1713         SetAttrSet(aCoreSet);
1714     }
1715     pDoc->ChgFmt(*pColl, rStyleSet );
1716     EndAction();
1717 }
1718 
1719 /*-----------------12.03.97 12.24-------------------
1720 
1721 --------------------------------------------------*/
1722 
AutoUpdateFrame(SwFrmFmt * pFmt,const SfxItemSet & rStyleSet)1723 void SwWrtShell::AutoUpdateFrame( SwFrmFmt* pFmt, const SfxItemSet& rStyleSet )
1724 {
1725     StartAction();
1726 
1727     ResetFlyFrmAttr( 0, &rStyleSet );
1728     pFmt->SetFmtAttr( rStyleSet );
1729 
1730     EndAction();
1731 }
1732 
1733 
AutoCorrect(SvxAutoCorrect & rACorr,sal_Unicode cChar)1734 void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar )
1735 {
1736     ResetCursorStack();
1737     if(_CanInsert())
1738     {
1739         sal_Bool bStarted = sal_False;
1740         if(HasSelection())
1741         {
1742                 // nur hier klammern, da das normale Insert schon an der
1743                 // Editshell geklammert ist
1744             StartAllAction();
1745             StartUndo(UNDO_INSERT);
1746             bStarted = sal_True;
1747             DelRight();
1748         }
1749         SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar );
1750 
1751         if(bStarted)
1752         {
1753             EndAllAction();
1754             EndUndo(UNDO_INSERT);
1755         }
1756     }
1757 }
1758 
1759 
1760 /*
1761  * eine Art kontrollierter copy ctor
1762  */
1763 
SwWrtShell(SwWrtShell & rSh,Window * _pWin,SwView & rShell)1764 SwWrtShell::SwWrtShell( SwWrtShell& rSh, Window *_pWin, SwView &rShell )
1765     : SwFEShell( rSh, _pWin ),
1766      COMMON_INI_LIST
1767 {
1768     BITFLD_INI_LIST
1769     SET_CURR_SHELL( this );
1770 
1771     SetSfxViewShell( (SfxViewShell *)&rShell );
1772     SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1773 
1774     // place the cursor on the first field...
1775     IFieldmark *pBM = NULL;
1776     if ( IsFormProtected() && ( pBM = GetFieldmarkAfter( ) ) !=NULL ) {
1777         GotoFieldmark(pBM);
1778     }
1779 }
1780 
1781 
1782 SwWrtShell::SwWrtShell( SwDoc& rDoc, Window *_pWin, SwView &rShell,
1783                         const SwViewOption *pViewOpt )
1784     : SwFEShell( rDoc, _pWin, pViewOpt),
1785       COMMON_INI_LIST
1786 {
1787     BITFLD_INI_LIST
1788     SET_CURR_SHELL( this );
1789     SetSfxViewShell( (SfxViewShell *)&rShell );
1790     SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1791 }
1792 
1793 /*
1794  * ctor
1795  */
1796 
1797 
1798 
1799 SwWrtShell::~SwWrtShell()
1800 {
1801     SET_CURR_SHELL( this );
1802     while(IsModePushed())
1803         PopMode();
1804     while(PopCrsr(sal_False))
1805         ;
1806     SwTransferable::ClearSelection( *this );
1807 }
1808 
Pop(sal_Bool bOldCrsr)1809 sal_Bool SwWrtShell::Pop( sal_Bool bOldCrsr )
1810 {
1811     sal_Bool bRet = SwCrsrShell::Pop( bOldCrsr );
1812     if( bRet && IsSelection() )
1813     {
1814         fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
1815         fnKillSel = &SwWrtShell::ResetSelect;
1816     }
1817     return bRet;
1818 }
1819 
1820 /*--------------------------------------------------------------------
1821     Beschreibung:
1822  --------------------------------------------------------------------*/
CanInsert()1823 bool SwWrtShell::CanInsert()
1824 {
1825     // #123922# The original expression looks sleek, but it is not. Using the mathematical or ('|')
1826     // instead of the logical one ('||') forces the compiler to evaluate all conditions to allow or-ing
1827     // them together (yes, he could do better). Using the logical or allows to return on the first
1828     // failing statement instead.
1829     //
1830     // return (!(IsSelFrmMode() | IsObjSelected() | (GetView().GetDrawFuncPtr() != NULL) | (GetView().GetPostItMgr()->GetActiveSidebarWin()!= NULL)));
1831 
1832     if(IsSelFrmMode())
1833     {
1834         return false;
1835     }
1836 
1837     if(IsObjSelected())
1838     {
1839         return false;
1840     }
1841 
1842     if(GetView().GetDrawFuncPtr())
1843     {
1844         return false;
1845     }
1846 
1847     if(GetView().GetPostItMgr()->GetActiveSidebarWin())
1848     {
1849         return false;
1850     }
1851 
1852     return true;
1853 }
1854 
1855 
1856 // --------------
ChgDBData(const SwDBData & aDBData)1857 void SwWrtShell::ChgDBData(const SwDBData& aDBData)
1858 {
1859     SwEditShell::ChgDBData(aDBData);
1860     //notify the db-beamer if available
1861     GetView().NotifyDBChanged();
1862 }
1863 
GetSelDescr() const1864 String SwWrtShell::GetSelDescr() const
1865 {
1866     String aResult;
1867 
1868     int nSelType = GetSelectionType();
1869     switch (nSelType)
1870     {
1871     case nsSelectionType::SEL_GRF:
1872         aResult = SW_RES(STR_GRAPHIC);
1873 
1874         break;
1875     case nsSelectionType::SEL_FRM:
1876         {
1877             const SwFrmFmt * pFrmFmt = GetCurFrmFmt();
1878 
1879             if (pFrmFmt)
1880                 aResult = pFrmFmt->GetDescription();
1881         }
1882         break;
1883     case nsSelectionType::SEL_DRW:
1884         {
1885             aResult = SW_RES(STR_DRAWING_OBJECTS);
1886         }
1887         break;
1888     default:
1889         if (0 != pDoc)
1890             aResult = GetCrsrDescr();
1891     }
1892 
1893     return aResult;
1894 }
1895 
ApplyViewOptions(const SwViewOption & rOpt)1896 void SwWrtShell::ApplyViewOptions( const SwViewOption &rOpt )
1897 {
1898     SwFEShell::ApplyViewOptions( rOpt );
1899     //#i115062# invalidate meta character slot
1900     GetView().GetViewFrame()->GetBindings().Invalidate( FN_VIEW_META_CHARS );
1901 }
1902 
1903 
1904