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