xref: /aoo42x/main/sw/source/ui/shells/textsh.cxx (revision f120fe41)
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 
28 #define _SW_FRMVALID_HXX
29 #include <hintids.hxx>
30 
31 #include <svl/globalnameitem.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/lnkbase.hxx>
34 
35 #include <tools/errinf.hxx>
36 #include <svx/svdview.hxx>
37 #include <svl/ptitem.hxx>
38 #include <svl/stritem.hxx>
39 #include <unotools/moduleoptions.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <sfx2/fcontnr.hxx>
42 #include <svx/hlnkitem.hxx>
43 #include <svl/srchitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <svl/urihelper.hxx>
47 #include <basic/sbxvar.hxx>
48 #include <svl/whiter.hxx>
49 #include <sfx2/request.hxx>
50 #include <editeng/opaqitem.hxx>
51 #include <editeng/fontitem.hxx>
52 #include <editeng/adjitem.hxx>
53 #include <editeng/boxitem.hxx>
54 #include <editeng/sizeitem.hxx>
55 #include <editeng/svxacorr.hxx>
56 #include <editeng/scripttypeitem.hxx>
57 #include <svtools/filter.hxx>
58 #include <svx/htmlmode.hxx>
59 #include <svx/pfiledlg.hxx>
60 #include <svtools/htmlcfg.hxx>
61 #include <com/sun/star/i18n/TransliterationModules.hpp>
62 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
63 
64 #include <sot/clsids.hxx>
65 #include <editeng/acorrcfg.hxx>
66 #include <wdocsh.hxx>
67 #include <fmtinfmt.hxx>
68 #include <fmtclds.hxx>
69 #include <fmtsrnd.hxx>
70 #include <fmtfsize.hxx>
71 #include <swmodule.hxx>
72 #include <wrtsh.hxx>
73 #include <view.hxx>
74 #include <docsh.hxx>
75 #include <doc.hxx>
76 #include <uitool.hxx>
77 #include <cmdid.h>
78 #include <globals.hrc>
79 #include <frmmgr.hxx>
80 #include <textsh.hxx>
81 #include <frmfmt.hxx>
82 #include <tablemgr.hxx>
83 #include <swundo.hxx>		// fuer Undo-IDs
84 #include <shellio.hxx>
85 #include <frmdlg.hxx>
86 #include <usrpref.hxx>
87 #include <swtable.hxx>
88 #include <tblafmt.hxx>
89 #include <caption.hxx>
90 #include <idxmrk.hxx>
91 #include <poolfmt.hxx>
92 #include <breakit.hxx>
93 #include <crsskip.hxx>
94 #include <modcfg.hxx>
95 #include <column.hxx>
96 #include <edtwin.hxx>
97 #include <shells.hrc>
98 #include <popup.hrc>
99 #include <swerror.h>
100 #include <SwAppletImpl.hxx>
101 #include <unochart.hxx>
102 
103 #include <chartins.hxx>
104 
105 #define SwTextShell
106 #define Paragraph
107 #define HyphenZone
108 #define TextFont
109 #define DropCap
110 #include <sfx2/msg.hxx>
111 #include <sfx2/sidebar/EnumContext.hxx>
112 #include <swslots.hxx>
113 #include <SwRewriter.hxx>
114 #include <comcore.hrc>
115 
116 using namespace ::com::sun::star;
117 using ::rtl::OUString;
118 
119 #include <svx/svxdlg.hxx>
120 #include <svx/dialogs.hrc>
121 #include "swabstdlg.hxx"
122 #include <misc.hrc>
123 #include <table.hrc>
124 #include <frmui.hrc>
125 #include <unomid.h>
126 
127 
128 
129 /*--------------------------------------------------------------------
130 	Beschreibung:
131  --------------------------------------------------------------------*/
132 
133 SFX_IMPL_INTERFACE(SwTextShell, SwBaseShell, SW_RES(STR_SHELLNAME_TEXT))
134 {
135 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_TEXT_POPUPMENU));
136 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
137 	SFX_CHILDWINDOW_REGISTRATION(FN_EDIT_FORMULA);
138 	SFX_CHILDWINDOW_REGISTRATION(FN_INSERT_FIELD);
139 	SFX_CHILDWINDOW_REGISTRATION(FN_INSERT_IDX_ENTRY_DLG);
140 	SFX_CHILDWINDOW_REGISTRATION(FN_INSERT_AUTH_ENTRY_DLG);
141     SFX_CHILDWINDOW_REGISTRATION(SID_RUBY_DIALOG);
142 }
143 
144 
145 
146 TYPEINIT1(SwTextShell,SwBaseShell)
147 
148 
149 
150 void SwTextShell::ExecInsert(SfxRequest &rReq)
151 {
152 	SwWrtShell &rSh = GetShell();
153 
154 	ASSERT( !rSh.IsObjSelected() && !rSh.IsFrmSelected(),
155 			"Falsche Shell auf dem Dispatcher" );
156 
157 	const SfxItemSet *pArgs = rReq.GetArgs();
158 	const SfxPoolItem* pItem = 0;
159 	sal_uInt16 nSlot = rReq.GetSlot();
160 	if(pArgs)
161 		pArgs->GetItemState(nSlot, sal_False, &pItem );
162 
163 	switch( nSlot )
164 	{
165     case FN_INSERT_STRING:
166 		if( pItem )
167 			rSh.InsertByWord(((const SfxStringItem *)pItem)->GetValue());
168     break;
169     case FN_INSERT_SOFT_HYPHEN:
170 		if( CHAR_SOFTHYPHEN != rSh.SwCrsrShell::GetChar( sal_True, 0 ) &&
171 			CHAR_SOFTHYPHEN != rSh.SwCrsrShell::GetChar( sal_True, -1 ))
172 			rSh.Insert( String( CHAR_SOFTHYPHEN ) );
173 		break;
174 
175 	case FN_INSERT_HARDHYPHEN:
176 	case FN_INSERT_HARD_SPACE:
177 		{
178 			sal_Unicode cIns = FN_INSERT_HARD_SPACE == nSlot ? CHAR_HARDBLANK
179 															 : CHAR_HARDHYPHEN;
180 
181             SvxAutoCorrCfg* pACfg = SvxAutoCorrCfg::Get();
182             SvxAutoCorrect* pACorr = pACfg->GetAutoCorrect();
183             if( pACorr && pACfg->IsAutoFmtByInput() &&
184                     pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
185 								AddNonBrkSpace | ChgOrdinalNumber |
186                                 ChgToEnEmDash | SetINetAttr | Autocorrect ))
187 				rSh.AutoCorrect( *pACorr, cIns );
188 			else
189 				rSh.Insert( String( cIns ) );
190 		}
191 		break;
192     case SID_INSERT_RLM :
193     case SID_INSERT_LRM :
194     case SID_INSERT_ZWNBSP :
195     case SID_INSERT_ZWSP:
196     {
197         sal_Unicode cIns = 0;
198         switch(nSlot)
199         {
200             case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
201             case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
202             case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
203             case SID_INSERT_ZWNBSP: cIns = CHAR_ZWNBSP; break;
204         }
205         rSh.Insert( String( cIns ) );
206     }
207     break;
208 	case FN_INSERT_BREAK:
209 		rSh.SplitNode();
210         rReq.Done();
211 	break;
212 	case FN_INSERT_PAGEBREAK:
213 		rSh.InsertPageBreak();
214         rReq.Done();
215 	break;
216 	case FN_INSERT_LINEBREAK:
217 		rSh.InsertLineBreak();
218         rReq.Done();
219 	break;
220 	case FN_INSERT_COLUMN_BREAK:
221 		rSh.InsertColumnBreak();
222         rReq.Done();
223 	break;
224 	case SID_HYPERLINK_SETLINK:
225 		if (pItem)
226 			InsertHyperlink(*((const SvxHyperlinkItem *)pItem));
227         rReq.Done();
228 		break;
229 	case SID_INSERT_AVMEDIA:
230 		rReq.SetReturnValue(SfxBoolItem(nSlot, InsertMediaDlg( rReq )));
231 		break;
232 	case  SID_INSERT_SOUND:
233 	case  SID_INSERT_VIDEO:
234 	{
235 		SvxPluginFileDlg aDlg( &GetView().GetViewFrame()->GetWindow(), nSlot );
236 		aDlg.SetContext( nSlot == SID_INSERT_SOUND? sfx2::FileDialogHelper::SW_INSERT_SOUND : sfx2::FileDialogHelper::SW_INSERT_VIDEO );
237 
238 		if ( ERRCODE_NONE == aDlg.Execute() )
239 		{
240 			// URL ermitteln
241 			String aStrURL( aDlg.GetPath() );
242             aStrURL = URIHelper::SmartRel2Abs(
243                 INetURLObject(), aStrURL, URIHelper::GetMaybeFileHdl() );
244 
245 			INetURLObject* pURL = new INetURLObject();
246 			pURL->SetSmartProtocol( INET_PROT_FILE );
247 
248 			if ( pURL->SetURL( aStrURL, INetURLObject::WAS_ENCODED ) )
249 			{
250                 ::rtl::OUString aName;
251                 comphelper::EmbeddedObjectContainer aCnt;
252                 svt::EmbeddedObjectRef xObj( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName ), embed::Aspects::MSOLE_CONTENT );
253                 if ( xObj.is() )
254                 {
255                 	svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() );
256 
257                     // set properties from dialog
258                     uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
259                     if ( xSet.is() )
260                     {
261                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
262                                 uno::makeAny( ::rtl::OUString( pURL->GetMainURL( INetURLObject::NO_DECODE ) ) ) );
263                     }
264                 }
265 
266                 rSh.InsertObject( xObj, 0, sal_True, nSlot);
267 			}
268 		}
269 	}
270 	break;
271 	case SID_INSERT_OBJECT:
272 	case SID_INSERT_PLUGIN:
273     {
274         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
275 		SvGlobalName *pName = NULL;
276 		SvGlobalName aName;
277 		if ( pNameItem )
278 		{
279 			aName = pNameItem->GetValue();
280 			pName = &aName;
281 		}
282 
283         SFX_REQUEST_ARG( rReq, pClassLocationItem,  SfxStringItem, FN_PARAM_2, sal_False );
284         SFX_REQUEST_ARG( rReq, pCommandsItem,       SfxStringItem, FN_PARAM_3, sal_False );
285         //TODO/LATER: recording currently not working, need code for Commandlist
286         svt::EmbeddedObjectRef xObj;
287         if( nSlot == SID_INSERT_PLUGIN && ( pClassLocationItem || pCommandsItem ) )
288         {
289             String sClassLocation;
290             if(pClassLocationItem)
291                 sClassLocation = pClassLocationItem->GetValue();
292 
293             SvCommandList aCommandList;
294             if(pCommandsItem)
295             {
296                 sal_uInt16 nTemp;
297                 aCommandList.AppendCommands( pCommandsItem->GetValue(), &nTemp );
298             }
299 
300             {
301                 comphelper::EmbeddedObjectContainer aCnt;
302                 ::rtl::OUString sName;
303                 xObj.Assign( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), sName ),
304 							embed::Aspects::MSOLE_CONTENT );
305                 svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() );
306                 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
307                 if ( xSet.is() )
308                 {
309                     try
310                     {
311                         if ( sClassLocation.Len() )
312                             xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
313                                 uno::makeAny(
314                                     ::rtl::OUString(
315                                         URIHelper::SmartRel2Abs(
316                                             INetURLObject(), sClassLocation,
317                                             URIHelper::GetMaybeFileHdl()) ) ) );
318                         uno::Sequence< beans::PropertyValue > aSeq;
319                         if ( aCommandList.Count() )
320                         {
321                             aCommandList.FillSequence( aSeq );
322                             xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginCommands"), uno::makeAny( aSeq ) );
323                         }
324                     }
325                     catch ( uno::Exception& )
326                     {
327                     }
328                 }
329             }
330 
331             if(xObj.is())
332                 rSh.InsertOleObject( xObj );
333         }
334         else
335         {
336             DBG_ASSERT( !pNameItem || nSlot == SID_INSERT_OBJECT, "Superfluous argument!" );
337             rSh.InsertObject( xObj, pName, sal_True, nSlot);
338             rReq.Done();
339         }
340 		break;
341 	}
342     case SID_INSERT_FLOATINGFRAME:
343     {
344         svt::EmbeddedObjectRef xObj;
345         SFX_REQUEST_ARG( rReq, pNameItem,   SfxStringItem, FN_PARAM_1, sal_False );
346         SFX_REQUEST_ARG( rReq, pURLItem,    SfxStringItem, FN_PARAM_2, sal_False );
347         SFX_REQUEST_ARG( rReq, pMarginItem, SvxSizeItem, FN_PARAM_3, sal_False );
348         SFX_REQUEST_ARG( rReq, pScrollingItem, SfxByteItem, FN_PARAM_4, sal_False );
349         SFX_REQUEST_ARG( rReq, pBorderItem, SfxBoolItem, FN_PARAM_5, sal_False );
350 
351         if(pURLItem) // URL is a _must_
352         {
353             comphelper::EmbeddedObjectContainer aCnt;
354             ::rtl::OUString aName;
355             xObj.Assign( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence(), aName ),
356 						embed::Aspects::MSOLE_CONTENT );
357             svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() );
358             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
359             if ( xSet.is() )
360             {
361                 try
362                 {
363                     ScrollingMode eScroll = ScrollingAuto;
364                     if( pScrollingItem && pScrollingItem->GetValue() <= ScrollingAuto )
365                         eScroll = (ScrollingMode) pScrollingItem->GetValue();
366 
367                     Size aMargin;
368                     if ( pMarginItem )
369                         aMargin = pMarginItem->GetSize();
370 
371                     if ( pURLItem )
372                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameURL"), uno::makeAny( ::rtl::OUString( pURLItem->GetValue() ) ) );
373                     if ( pNameItem )
374                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameName"), uno::makeAny( ::rtl::OUString( pNameItem->GetValue() ) ) );
375 
376                     if ( eScroll == ScrollingAuto )
377                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll"),
378                             uno::makeAny( sal_True ) );
379                     else
380                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode"),
381                             uno::makeAny( (sal_Bool) ( eScroll == ScrollingYes) ) );
382 
383                     //if ( aFrmDescr.IsFrameBorderSet() )
384                     if ( pBorderItem )
385                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder"),
386                             uno::makeAny( (sal_Bool) pBorderItem->GetValue() ) );
387                     /*else
388                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder"),
389                             makeAny( sal_True ) );*/
390 
391                     if ( pMarginItem )
392                     {
393                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth"),
394                             uno::makeAny( sal_Int32( aMargin.Width() ) ) );
395 
396                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight"),
397                             uno::makeAny( sal_Int32( aMargin.Height() ) ) );
398                     }
399                 }
400                 catch ( uno::Exception& )
401                 {
402                 }
403             }
404 
405             rSh.InsertOleObject( xObj );
406         }
407         else
408         {
409             rSh.InsertObject( xObj, 0, sal_True, nSlot);
410             rReq.Done();
411         }
412     }
413     break;
414 	case SID_INSERT_DIAGRAM:
415 		{
416 			SvtModuleOptions aMOpt;
417 			if ( !aMOpt.IsChart() )
418 				break;
419 			if(!rReq.IsAPI())
420 			{
421 				SfxViewFrame* pVFrame = GetView().GetViewFrame();
422                 SwInsertChart( &GetView().GetEditWin(), &pVFrame->GetBindings() );
423 			}
424 			else
425 			{
426                 uno::Reference< chart2::data::XDataProvider > xDataProvider;
427                 sal_Bool bFillWithData = sal_True;
428                 OUString aRangeString;
429                 if (!GetShell().IsTblComplexForChart())
430                 {
431                     SwFrmFmt* pTblFmt = GetShell().GetTableFmt();
432                     String aCurrentTblName = pTblFmt->GetName();
433         //             String aText( String::CreateFromAscii("<.>") );   // was used for UI
434         //             aText.Insert( rWrtShell.GetBoxNms(), 2);
435         //             aText.Insert( aCurrentTblName, 1 );
436                     aRangeString = aCurrentTblName;
437                     aRangeString += OUString::valueOf( sal_Unicode('.') );
438                     aRangeString += GetShell().GetBoxNms();
439 
440                     // get table data provider
441                     xDataProvider.set( GetView().GetDocShell()->getIDocumentChartDataProviderAccess()->GetChartDataProvider() );
442                 }
443                 else
444                     bFillWithData = sal_False;  // will create chart with only it's default image
445 
446                 SwTableFUNC( &rSh, sal_False ).InsertChart( xDataProvider, bFillWithData, aRangeString );
447 				rSh.LaunchOLEObj();
448 
449                 svt::EmbeddedObjectRef& xObj = rSh.GetOLEObject();
450                 if(pItem && xObj.is())
451 				{
452 					Size aSize(((SvxSizeItem*)pItem)->GetSize());
453 					aSize = OutputDevice::LogicToLogic
454 									( aSize, MapMode( MAP_TWIP ), MapMode( MAP_100TH_MM ) );
455 
456 					if(aSize.Width() > MINLAY&& aSize.Height()> MINLAY)
457 					{
458                         awt::Size aSz;
459                         aSz.Width = aSize.Width();
460                         aSz.Height = aSize.Height();
461                         xObj->setVisualAreaSize( xObj.GetViewAspect(), aSz );
462 					}
463 				}
464 			}
465 		}
466 		break;
467 
468 	case FN_INSERT_SMA:
469 		{
470             // #i34343# Inserting a math object into an autocompletion crashes
471             // the suggestion has to be removed before
472             GetView().GetEditWin().StopQuickHelp();
473             SvGlobalName aGlobalName( SO3_SM_CLASSID );
474             rSh.InsertObject( svt::EmbeddedObjectRef(), &aGlobalName, sal_True, 0 );
475 		}
476 		break;
477 
478 	case FN_INSERT_TABLE:
479         InsertTable( rReq );
480         break;
481 
482 	case FN_INSERT_FRAME_INTERACT_NOCOL:
483 	case FN_INSERT_FRAME_INTERACT:
484 	{
485         sal_uInt16 nCols = 1;
486         sal_Bool bModifier1 = rReq.GetModifier() == KEY_MOD1;
487         if(pArgs)
488         {
489             if(FN_INSERT_FRAME_INTERACT_NOCOL != nSlot &&
490                 pArgs->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem) == SFX_ITEM_SET)
491                 nCols = ((SfxUInt16Item *)pItem)->GetValue();
492             if(pArgs->GetItemState(SID_MODIFIER, sal_False, &pItem) == SFX_ITEM_SET)
493                 bModifier1 |= KEY_MOD1 == ((SfxUInt16Item *)pItem)->GetValue();
494         }
495         if(bModifier1 )
496         {
497             SwEditWin& rEdtWin = GetView().GetEditWin();
498             Size aWinSize = rEdtWin.GetSizePixel();
499             Point aStartPos(aWinSize.Width()/2, aWinSize.Height() / 2);
500             aStartPos = rEdtWin.PixelToLogic(aStartPos);
501             aStartPos.X() -= 8 * MM50;
502             aStartPos.Y() -= 4 * MM50;
503             Size aSize(16 * MM50, 8 * MM50);
504             GetShell().LockPaint();
505             GetShell().StartAllAction();
506             SwFlyFrmAttrMgr aMgr( sal_True, GetShellPtr(), FRMMGR_TYPE_TEXT );
507             if(nCols > 1)
508             {
509                 SwFmtCol aCol;
510                 aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() );
511                 aMgr.SetCol( aCol );
512             }
513             aMgr.InsertFlyFrm(FLY_AT_PARA, aStartPos, aSize);
514             GetShell().EndAllAction();
515             GetShell().UnlockPaint();
516         }
517         else
518         {
519             GetView().InsFrmMode(nCols);
520         }
521         rReq.Ignore();
522     }
523 	break;
524 	case FN_INSERT_FRAME:
525 	{
526 		sal_Bool bSingleCol = sal_False;
527         if( 0!= dynamic_cast< SwWebDocShell*>( GetView().GetDocShell()) )
528 		{
529 			SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
530 			sal_uInt16 nExport = pHtmlOpt->GetExportMode();
531 			if( HTML_CFG_MSIE == nExport ||
532 				HTML_CFG_HTML32 == nExport ||
533 				HTML_CFG_MSIE_40 == nExport ||
534 				HTML_CFG_HTML32 == nExport )
535 			{
536 				bSingleCol = sal_True;
537 			}
538 
539 		}
540 		// Rahmen neu anlegen
541 		SwFlyFrmAttrMgr aMgr( sal_True, GetShellPtr(), FRMMGR_TYPE_TEXT );
542         if(pArgs)
543         {
544             Size aSize(aMgr.GetSize());
545             aSize.Width() = GetShell().GetAnyCurRect(RECT_PAGE_PRT).Width();
546             Point aPos = aMgr.GetPos();
547             RndStdIds eAnchor = FLY_AT_PARA;
548             if(pArgs->GetItemState(nSlot, sal_False, &pItem) == SFX_ITEM_SET)
549                 eAnchor = (RndStdIds)((SfxUInt16Item *)pItem)->GetValue();
550             if(pArgs->GetItemState(FN_PARAM_1, sal_False, &pItem)  == SFX_ITEM_SET)
551                 aPos = ((SfxPointItem *)pItem)->GetValue();
552             if(pArgs->GetItemState(FN_PARAM_2, sal_False, &pItem)  == SFX_ITEM_SET)
553                 aSize = ((SvxSizeItem *)pItem)->GetSize();
554             if(pArgs->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem)  == SFX_ITEM_SET)
555             {
556                 sal_uInt16 nCols = ((SfxUInt16Item *)pItem)->GetValue();
557                 if( !bSingleCol && 1 < nCols )
558                 {
559                     SwFmtCol aFmtCol;
560                     aFmtCol.Init( nCols , (rReq.IsAPI() ? 0
561                                         : DEF_GUTTER_WIDTH), USHRT_MAX );
562                     aMgr.SetCol(aFmtCol);
563                 }
564             }
565 
566             GetShell().LockPaint();
567             GetShell().StartAllAction();
568 
569             aMgr.InsertFlyFrm(eAnchor, aPos, aSize);
570 
571             GetShell().EndAllAction();
572             GetShell().UnlockPaint();
573         }
574         else
575         {
576             static sal_uInt16 __READONLY_DATA aFrmAttrRange[] =
577             {
578                 RES_FRMATR_BEGIN,       RES_FRMATR_END-1,
579                 SID_ATTR_BORDER_INNER,  SID_ATTR_BORDER_INNER,
580                 FN_GET_PRINT_AREA,      FN_GET_PRINT_AREA,
581                 SID_ATTR_PAGE_SIZE,     SID_ATTR_PAGE_SIZE,
582                 FN_SET_FRM_NAME,        FN_SET_FRM_NAME,
583                 SID_HTML_MODE,          SID_HTML_MODE,
584                 0
585             };
586 
587             SfxItemSet aSet(GetPool(), aFrmAttrRange );
588             aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
589             const SwRect &rPg = GetShell().GetAnyCurRect(RECT_PAGE);
590             SwFmtFrmSize aFrmSize(ATT_VAR_SIZE, rPg.Width(), rPg.Height());
591             aFrmSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
592             aSet.Put(aFrmSize);
593 
594             const SwRect &rPr = GetShell().GetAnyCurRect(RECT_PAGE_PRT);
595             SwFmtFrmSize aPrtSize(ATT_VAR_SIZE, rPr.Width(), rPr.Height());
596             aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
597             aSet.Put(aPrtSize);
598 
599             aSet.Put(aMgr.GetAttrSet());
600             aSet.SetParent( aMgr.GetAttrSet().GetParent() );
601 
602             // Minimalgroesse in Spalten loeschen
603             SvxBoxInfoItem aBoxInfo((SvxBoxInfoItem &)aSet.Get(SID_ATTR_BORDER_INNER));
604             const SvxBoxItem& rBox = (const SvxBoxItem&)aSet.Get(RES_BOX);
605             aBoxInfo.SetMinDist(sal_False);
606             aBoxInfo.SetDefDist(rBox.GetDistance(BOX_LINE_LEFT));
607             aSet.Put(aBoxInfo);
608 
609             FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebDocShell, GetView().GetDocShell()));
610             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
611 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
612             DBG_ASSERT(pFact, "Dialogdiet fail!");
613             SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_STD,
614 													GetView().GetViewFrame(), &GetView().GetViewFrame()->GetWindow(), aSet, sal_True);
615             DBG_ASSERT(pDlg, "Dialogdiet fail!");
616             if(pDlg->Execute() && pDlg->GetOutputItemSet())
617             {
618                 //local variable necessary at least after call of .AutoCaption() because this could be deleted at this point
619                 SwWrtShell& rShell = GetShell();
620                 rShell.LockPaint();
621                 rShell.StartAllAction();
622                 rShell.StartUndo(UNDO_INSERT);
623 
624                 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
625                 aMgr.SetAttrSet(*pOutSet);
626 
627                 // beim ClickToEditFeld erst die Selektion loeschen
628                 if( rShell.IsInClickToEdit() )
629                     rShell.DelRight();
630 
631                 aMgr.InsertFlyFrm();
632 
633                 uno::Reference< frame::XDispatchRecorder > xRecorder =
634                         GetView().GetViewFrame()->GetBindings().GetRecorder();
635                 if ( xRecorder.is() )
636                 {
637                     //FN_INSERT_FRAME
638                     sal_uInt16 nAnchor = (sal_uInt16)aMgr.GetAnchor();
639                         rReq.AppendItem(SfxUInt16Item(nSlot, nAnchor));
640                         rReq.AppendItem(SfxPointItem(FN_PARAM_1, rShell.GetObjAbsPos()));
641                         rReq.AppendItem(SvxSizeItem(FN_PARAM_2, rShell.GetObjSize()));
642                     rReq.Done();
643                 }
644 
645                 GetView().AutoCaption(FRAME_CAP);
646 
647                 {
648                     SwRewriter aRewriter;
649 
650                     aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_FRAME));
651 
652                     rShell.EndUndo(UNDO_INSERT, &aRewriter);
653                 }
654                 rShell.EndAllAction();
655                 rShell.UnlockPaint();
656             }
657 
658             DELETEZ(pDlg);
659         }
660 		break;
661 	}
662 	case FN_INSERT_HRULER:
663 	{
664 		String sPath;
665 		sal_Bool bSimpleLine = sal_False;
666 		sal_Bool bRet = sal_False;
667 		Window* pParent = GetView().GetWindow();
668         if ( pItem )
669         {
670             sPath = ((SfxStringItem*)pItem)->GetValue();
671             SFX_REQUEST_ARG( rReq, pSimple, SfxBoolItem, FN_PARAM_1 , sal_False );
672             if ( pSimple )
673                 bSimpleLine = pSimple->GetValue();
674         }
675         else
676         {
677             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
678             DBG_ASSERT(pFact, "Dialogdiet fail!");
679             AbstractInsertGrfRulerDlg* pDlg = pFact->CreateInsertGrfRulerDlg( DLG_INSERT_RULER,
680 														pParent );
681             DBG_ASSERT(pDlg, "Dialogdiet fail!");
682 			// MessageBox fuer fehlende Grafiken
683             if(!pDlg->HasImages())
684                 InfoBox( pParent, SW_RES(MSG_NO_RULER)).Execute();
685             if(RET_OK == pDlg->Execute())
686             {
687                 sPath = pDlg->GetGraphicName();
688                 bSimpleLine = pDlg->IsSimpleLine();
689             }
690 
691             delete pDlg;
692             rReq.AppendItem( SfxStringItem( FN_INSERT_HRULER, sPath ) );
693             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bSimpleLine ) );
694         }
695 
696 		rSh.StartAllAction();
697         rSh.StartUndo(UNDO_UI_INSERT_RULER);
698 		if(bSimpleLine)
699 		{
700 			if(!(rSh.IsSttOfPara() && rSh.IsEndOfPara())) // kein leerer Absatz?
701 				rSh.SplitNode( sal_False, sal_False ); // dann Platz schaffen
702 			rSh.SplitNode( sal_False, sal_False );
703 			rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
704 			rSh.SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_HTML_HR ));
705 			rSh.Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
706 			bRet = sal_True;
707 		}
708 		else if(sPath.Len())
709 		{
710             SwFlyFrmAttrMgr aFrmMgr( sal_True, &rSh, FRMMGR_TYPE_GRF );
711 			// am FrmMgr muessen die richtigen Parameter eingestellt werden
712 
713             aFrmMgr.SetAnchor(FLY_AS_CHAR);
714 
715 			rSh.SplitNode( sal_False, sal_False );
716 			rSh.SplitNode( sal_False, sal_False );
717 			rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
718 			rSh.SetAttr(SvxAdjustItem(SVX_ADJUST_CENTER,RES_PARATR_ADJUST ));
719             if(GRFILTER_OK == GetView().InsertGraphic(sPath, aEmptyStr, sal_True, 0, 0 ))
720 				bRet = sal_True;
721 			rSh.EnterStdMode();
722 			rSh.Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
723 		}
724 		rSh.EndAllAction();
725         rSh.EndUndo(UNDO_UI_INSERT_RULER);
726 		rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
727         rReq.Done();
728 	}
729 	break;
730 	case FN_FORMAT_COLUMN :
731 	{
732 		SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
733         DBG_ASSERT(pFact, "Dialogdiet fail!");
734         VclAbstractDialog* pColDlg = pFact->CreateVclAbstractDialog( GetView().GetWindow(), rSh, DLG_COLUMN);
735         DBG_ASSERT(pColDlg, "Dialogdiet fail!");
736 		pColDlg->Execute();
737 		delete pColDlg;
738 	}
739 	break;
740 
741 	default:
742 		ASSERT( !this, "falscher Dispatcher" );
743 		return;
744 	}
745 }
746 
747 bool lcl_IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect )
748 {
749     rWrtSh.SwapPam();
750     bool bRet = pSect == rWrtSh.GetCurrSection();
751     rWrtSh.SwapPam();
752     return bRet;
753 }
754 
755 
756 void SwTextShell::StateInsert( SfxItemSet &rSet )
757 {
758 	sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
759 	SfxWhichIter aIter( rSet );
760 	SwWrtShell &rSh = GetShell();
761 	sal_uInt16 nWhich = aIter.FirstWhich();
762 	SvtModuleOptions aMOpt;
763     SfxObjectCreateMode eCreateMode =
764                         GetView().GetDocShell()->GetCreateMode();
765 
766     rSh.Push();
767     const sal_Bool bCrsrInHidden = rSh.SelectHiddenRange();
768     // --> OD 2009-08-05 #i103839#, #b6855246#
769     // Do not call method <SwCrsrShell::Pop(..)> with 1st parameter = <sal_False>
770     // in order to avoid that the view jumps to the visible cursor.
771     rSh.Pop();
772     // <--
773 
774     while ( nWhich )
775 	{
776 		switch ( nWhich )
777 		{
778 			case SID_INSERT_SOUND:
779 			case SID_INSERT_VIDEO:
780                 /*!SvxPluginFileDlg::IsAvailable( nWhich ) ||
781 
782                 discussed with mba: for performance reasons we skip the IsAvailable call here
783                 */
784 				if ( GetShell().IsSelFrmMode() ||
785                      SFX_CREATE_MODE_EMBEDDED == eCreateMode || bCrsrInHidden )
786 				{
787 					rSet.DisableItem( nWhich );
788 				}
789 				break;
790 
791 			case SID_INSERT_DIAGRAM:
792                 if( !aMOpt.IsChart() || eCreateMode == SFX_CREATE_MODE_EMBEDDED || bCrsrInHidden )
793 				{
794 					rSet.DisableItem( nWhich );
795 				}
796 				break;
797 
798 			case FN_INSERT_SMA:
799                 if( !aMOpt.IsMath() || eCreateMode == SFX_CREATE_MODE_EMBEDDED || bCrsrInHidden )
800 				{
801 					rSet.DisableItem( nWhich );
802 				}
803 				break;
804 
805 			case SID_INSERT_FLOATINGFRAME:
806 			case SID_INSERT_OBJECT:
807 			case SID_INSERT_PLUGIN:
808 			{
809 				if( eCreateMode == SFX_CREATE_MODE_EMBEDDED || bCrsrInHidden )
810                 {
811 					rSet.DisableItem( nWhich );
812                 }
813 				else if( GetShell().IsSelFrmMode())
814 					rSet.DisableItem( nWhich );
815 				else if(SID_INSERT_FLOATINGFRAME == nWhich && nHtmlMode&HTMLMODE_ON)
816 				{
817 					SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
818 					sal_uInt16 nExport = pHtmlOpt->GetExportMode();
819 					if(HTML_CFG_MSIE_40 != nExport && HTML_CFG_WRITER != nExport )
820 						rSet.DisableItem(nWhich);
821 				}
822 			}
823 			break;
824 			case FN_INSERT_FRAME_INTERACT_NOCOL :
825 			case FN_INSERT_FRAME_INTERACT:
826 			{
827 				if ( GetShell().IsSelFrmMode() ||
828 					(0 != (nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS)) || bCrsrInHidden )
829 					rSet.DisableItem(nWhich);
830 			}
831 			break;
832 			case SID_HYPERLINK_GETLINK:
833 				{
834 					SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
835                     rSh.GetCurAttr( aSet );
836 
837 					SvxHyperlinkItem aHLinkItem;
838 					const SfxPoolItem* pItem;
839 					if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
840 					{
841 						const SwFmtINetFmt* pINetFmt = (const SwFmtINetFmt*)pItem;
842 						aHLinkItem.SetURL(pINetFmt->GetValue());
843 						aHLinkItem.SetTargetFrame(pINetFmt->GetTargetFrame());
844 						aHLinkItem.SetIntName(pINetFmt->GetName());
845 						const SvxMacro *pMacro = pINetFmt->GetMacro( SFX_EVENT_MOUSEOVER_OBJECT );
846 						if( pMacro )
847 							aHLinkItem.SetMacro(HYPERDLG_EVENT_MOUSEOVER_OBJECT, *pMacro);
848 
849 						pMacro = pINetFmt->GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
850 						if( pMacro )
851 							aHLinkItem.SetMacro(HYPERDLG_EVENT_MOUSECLICK_OBJECT, *pMacro);
852 
853 						pMacro = pINetFmt->GetMacro( SFX_EVENT_MOUSEOUT_OBJECT );
854 						if( pMacro )
855 							aHLinkItem.SetMacro(HYPERDLG_EVENT_MOUSEOUT_OBJECT, *pMacro);
856 
857 						// Text des Links besorgen
858 						rSh.StartAction();
859 						rSh.CreateCrsr();
860 						rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT,sal_True);
861 						String sLinkName = rSh.GetSelTxt();
862 						aHLinkItem.SetName(sLinkName);
863 						aHLinkItem.SetInsertMode(HLINK_FIELD);
864 						rSh.DestroyCrsr();
865 						rSh.EndAction();
866 					}
867 					else
868 					{
869 						String sReturn = rSh.GetSelTxt();
870 						sReturn.Erase(255);
871 						sReturn.EraseTrailingChars();
872 						aHLinkItem.SetName(sReturn);
873 					}
874 
875 					aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
876 						((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
877 					aHLinkItem.SetMacroEvents (	HYPERDLG_EVENT_MOUSEOVER_OBJECT|
878 								HYPERDLG_EVENT_MOUSECLICK_OBJECT | HYPERDLG_EVENT_MOUSEOUT_OBJECT );
879 
880 					rSet.Put(aHLinkItem);
881 				}
882 				break;
883 
884 			case FN_INSERT_FRAME:
885 				if(rSh.IsSelFrmMode())
886 				{
887 					const int nSel = rSh.GetSelectionType();
888 					if( ((nsSelectionType::SEL_GRF | nsSelectionType::SEL_OLE ) & nSel ) || bCrsrInHidden )
889 						rSet.DisableItem(nWhich);
890 				}
891 			break;
892 			case FN_INSERT_HRULER :
893                 if((rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel()) || bCrsrInHidden )
894 					rSet.DisableItem(nWhich);
895 			break;
896             case FN_FORMAT_COLUMN :
897             {
898                 //#i80458# column dialog cannot work if the selection contains different page styles and different sections
899                 bool bDisable = true;
900                 if( rSh.GetFlyFrmFmt() || rSh.GetSelectedPageDescs() )
901                     bDisable = false;
902                 if( bDisable )
903                 {
904                     const SwSection* pCurrSection = rSh.GetCurrSection();
905                     sal_uInt16 nFullSectCnt = rSh.GetFullSelectedSectionCount();
906                     if( pCurrSection && ( !rSh.HasSelection() || 0 != nFullSectCnt ))
907                         bDisable = false;
908                     else if(
909                         rSh.HasSelection() && rSh.IsInsRegionAvailable() &&
910                             ( !pCurrSection || ( 1 != nFullSectCnt &&
911                                 lcl_IsMarkInSameSection( rSh, pCurrSection ) )))
912                         bDisable = false;
913                 }
914                 if(bDisable)
915                     rSet.DisableItem(nWhich);
916             }
917             break;
918 		}
919 		nWhich = aIter.NextWhich();
920 	}
921 }
922 
923 /*--------------------------------------------------------------------
924 	Beschreibung:
925  --------------------------------------------------------------------*/
926 
927 void  SwTextShell::ExecDelete(SfxRequest &rReq)
928 {
929 	SwWrtShell &rSh = GetShell();
930 	switch( rReq.GetSlot() )
931 	{
932 		case FN_DELETE_SENT:
933 			if( rSh.IsTableMode() )
934 			{
935 				rSh.DeleteRow();
936 				rSh.EnterStdMode();
937 			}
938 			else
939 				rSh.DelToEndOfSentence();
940 			break;
941 		case FN_DELETE_BACK_SENT:
942 			rSh.DelToStartOfSentence();
943 			break;
944 		case FN_DELETE_WORD:
945 			rSh.DelNxtWord();
946 			break;
947 		case FN_DELETE_BACK_WORD:
948 			rSh.DelPrvWord();
949 			break;
950 		case FN_DELETE_LINE:
951 			rSh.DelToEndOfLine();
952 			break;
953 		case FN_DELETE_BACK_LINE:
954 			rSh.DelToStartOfLine();
955 			break;
956 		case FN_DELETE_PARA:
957 			rSh.DelToEndOfPara();
958 			break;
959 		case FN_DELETE_BACK_PARA:
960 			rSh.DelToStartOfPara();
961 			break;
962 		case FN_DELETE_WHOLE_LINE:
963 			rSh.DelLine();
964 			break;
965 		default:
966 			ASSERT(!this, "falscher Dispatcher");
967 			return;
968 	}
969     rReq.Done();
970 }
971 
972 void SwTextShell::ExecTransliteration( SfxRequest & rReq )
973 {
974     using namespace ::com::sun::star::i18n;
975 	{
976 		sal_uInt32 nMode = 0;
977 
978 		switch( rReq.GetSlot() )
979 		{
980         case SID_TRANSLITERATE_SENTENCE_CASE:
981             nMode = TransliterationModulesExtra::SENTENCE_CASE;
982             break;
983         case SID_TRANSLITERATE_TITLE_CASE:
984             nMode = TransliterationModulesExtra::TITLE_CASE;
985             break;
986         case SID_TRANSLITERATE_TOGGLE_CASE:
987             nMode = TransliterationModulesExtra::TOGGLE_CASE;
988             break;
989 		case SID_TRANSLITERATE_UPPER:
990 			nMode = TransliterationModules_LOWERCASE_UPPERCASE;
991 			break;
992 		case SID_TRANSLITERATE_LOWER:
993 			nMode = TransliterationModules_UPPERCASE_LOWERCASE;
994 			break;
995 
996 		case SID_TRANSLITERATE_HALFWIDTH:
997 			nMode = TransliterationModules_FULLWIDTH_HALFWIDTH;
998 			break;
999 		case SID_TRANSLITERATE_FULLWIDTH:
1000 			nMode = TransliterationModules_HALFWIDTH_FULLWIDTH;
1001 			break;
1002 
1003 		case SID_TRANSLITERATE_HIRAGANA:
1004 			nMode = TransliterationModules_KATAKANA_HIRAGANA;
1005 			break;
1006 		case SID_TRANSLITERATE_KATAGANA:
1007 			nMode = TransliterationModules_HIRAGANA_KATAKANA;
1008 			break;
1009 
1010 		default:
1011 			ASSERT(!this, "falscher Dispatcher");
1012 		}
1013 
1014 		if( nMode )
1015 			GetShell().TransliterateText( nMode );
1016 	}
1017 }
1018 
1019 
1020 /*--------------------------------------------------------------------
1021 	Beschreibung:
1022  --------------------------------------------------------------------*/
1023 
1024 
1025 
1026 SwTextShell::SwTextShell(SwView &_rView) :
1027     SwBaseShell(_rView), pPostItFldMgr( 0 )
1028 {
1029 	SetName(String::CreateFromAscii("Text"));
1030 	SetHelpId(SW_TEXTSHELL);
1031     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Text));
1032 }
1033 
1034 /*--------------------------------------------------------------------
1035 	Beschreibung:
1036  --------------------------------------------------------------------*/
1037 
1038 SwTextShell::~SwTextShell()
1039 {
1040 }
1041 
1042 /*--------------------------------------------------------------------
1043 	Beschreibung:
1044  --------------------------------------------------------------------*/
1045 
1046 void SwTextShell::InsertSymbol( SfxRequest& rReq )
1047 {
1048 	const SfxItemSet *pArgs = rReq.GetArgs();
1049 	const SfxPoolItem* pItem = 0;
1050     if( pArgs )
1051         pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
1052 
1053     String aChars, aFontName;
1054     if ( pItem )
1055     {
1056         aChars = ((const SfxStringItem*)pItem)->GetValue();
1057         const SfxPoolItem* pFtItem = NULL;
1058         pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
1059         const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
1060         if ( pFontItem )
1061             aFontName = pFontItem->GetValue();
1062     }
1063 
1064 	SwWrtShell &rSh = GetShell();
1065 	SfxItemSet aSet( GetPool(), RES_CHRATR_FONT, RES_CHRATR_FONT,
1066 								RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
1067 								RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT,
1068 								0 );
1069     rSh.GetCurAttr( aSet );
1070 	sal_uInt16 nScript = rSh.GetScriptType();
1071 
1072     SvxFontItem aFont( RES_CHRATR_FONT );
1073 	{
1074 		SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1075 		aSetItem.GetItemSet().Put( aSet, sal_False );
1076 		const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1077 		if( pI )
1078 			aFont = *(SvxFontItem*)pI;
1079 		else
1080 			aFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1081 						RES_CHRATR_FONT,
1082                         GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ) ));
1083 		if (!aFontName.Len())
1084 			aFontName = aFont.GetFamilyName();
1085 	}
1086 
1087     Font aNewFont(aFontName, Size(1,1)); // Size nur wg. CTOR
1088     if( !aChars.Len() )
1089 	{
1090 		// Eingestellten Font als Default
1091         SfxAllItemSet aAllSet( rSh.GetAttrPool() );
1092         aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
1093 
1094         SwViewOption aOpt(*GetShell().GetViewOptions());
1095         String sSymbolFont = aOpt.GetSymbolFont();
1096         if( !aFontName.Len() && sSymbolFont.Len() )
1097             aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1098         else
1099             aAllSet.Put( SfxStringItem( SID_FONT_NAME, aFont.GetFamilyName() ) );
1100 
1101 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1102         SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( GetView().GetWindow(), aAllSet,
1103 			GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
1104 		if( RET_OK == pDlg->Execute() )
1105 		{
1106             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, sal_False );
1107 			SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
1108 			if ( pFontItem )
1109 			{
1110 				aNewFont.SetName( pFontItem->GetFamilyName() );
1111 				aNewFont.SetStyleName( pFontItem->GetStyleName() );
1112 				aNewFont.SetCharSet( pFontItem->GetCharSet() );
1113 				aNewFont.SetPitch( pFontItem->GetPitch() );
1114 			}
1115 
1116             if ( pCItem )
1117 			{
1118                 aChars  = pCItem->GetValue();
1119 				aOpt.SetSymbolFont(aNewFont.GetName());
1120 				SW_MOD()->ApplyUsrPref(aOpt, &GetView());
1121 			}
1122 		}
1123 
1124 		delete pDlg;
1125 	}
1126 
1127 	sal_Bool bFontChanged = sal_False;
1128 	if( aChars.Len() )
1129 	{
1130 		rSh.StartAllAction();
1131 
1132 		// Selektierten Inhalt loeschen
1133         SwRewriter aRewriter;
1134         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_SPECIALCHAR));
1135 
1136 		rSh.StartUndo( UNDO_INSERT, &aRewriter );
1137 		if ( rSh.HasSelection() )
1138 		{
1139 			rSh.DelRight();
1140 			aSet.ClearItem();
1141             rSh.GetCurAttr( aSet );
1142 
1143 			SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1144 			aSetItem.GetItemSet().Put( aSet, sal_False );
1145 			const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1146 			if( pI )
1147 				aFont = *(SvxFontItem*)pI;
1148 			else
1149 				aFont = (SvxFontItem&)aSet.Get( GetWhichOfScript(
1150 							RES_CHRATR_FONT,
1151                             GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ) ));
1152 		}
1153 
1154 		// Zeichen einfuegen
1155 		rSh.Insert( aChars );
1156 
1157         // #108876# a font attribute has to be set always due to a guessed script type
1158         if( aNewFont.GetName().Len() )
1159         {
1160 			bFontChanged = sal_True;
1161 			SvxFontItem aNewFontItem( aFont );
1162             aNewFontItem.SetFamilyName( aNewFont.GetName());
1163             aNewFontItem.SetFamily(  aNewFont.GetFamily());
1164             aNewFontItem.SetPitch(   aNewFont.GetPitch());
1165             aNewFontItem.SetCharSet( aNewFont.GetCharSet() );
1166 
1167             SfxItemSet aRestoreSet( GetPool(), RES_CHRATR_FONT, RES_CHRATR_FONT,
1168 								               RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
1169 								               RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT, 0 );
1170 
1171             nScript = pBreakIt->GetAllScriptsOfText( aChars );
1172 			if( SCRIPTTYPE_LATIN & nScript )
1173             {
1174                 aRestoreSet.Put( aSet.Get( RES_CHRATR_FONT, sal_True ) );
1175 				aSet.Put( aNewFontItem, RES_CHRATR_FONT);
1176             }
1177 			if( SCRIPTTYPE_ASIAN & nScript )
1178             {
1179                 aRestoreSet.Put( aSet.Get( RES_CHRATR_CJK_FONT, sal_True ) );
1180 				aSet.Put( aNewFontItem, RES_CHRATR_CJK_FONT );
1181             }
1182 			if( SCRIPTTYPE_COMPLEX & nScript )
1183             {
1184                 aRestoreSet.Put( aSet.Get( RES_CHRATR_CTL_FONT, sal_True ) );
1185 				aSet.Put( aNewFontItem, RES_CHRATR_CTL_FONT );
1186             }
1187 
1188 			rSh.SetMark();
1189 			rSh.ExtendSelection( sal_False, aChars.Len() );
1190 			rSh.SetAttr( aSet, nsSetAttrMode::SETATTR_DONTEXPAND | nsSetAttrMode::SETATTR_NOFORMATATTR );
1191 			if( !rSh.IsCrsrPtAtEnd() )
1192 				rSh.SwapPam();
1193 
1194             rSh.ClearMark();
1195 
1196             // --> FME 2007-07-09 #i75891#
1197             // SETATTR_DONTEXPAND does not work if there are already hard attributes.
1198             // Therefore we have to restore the font attributes.
1199             rSh.SetMark();
1200             rSh.SetAttr( aRestoreSet );
1201             rSh.ClearMark();
1202             // <--
1203 
1204 			rSh.UpdateAttr();
1205             aFont = aNewFontItem;
1206 		}
1207 
1208 		rSh.EndAllAction();
1209         rSh.EndUndo();
1210 
1211         if ( aChars.Len() )
1212         {
1213             rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), aChars ) );
1214             rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aNewFont.GetName() ) );
1215             rReq.Done();
1216         }
1217     }
1218 }
1219