xref: /AOO41X/main/sw/source/ui/shells/drwtxtex.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
32 
33 #include <comphelper/processfactory.hxx>
34 #include <i18npool/mslangid.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/request.hxx>
38 #include <tools/shl.hxx>
39 #include <svx/svdview.hxx>
40 #include <editeng/spltitem.hxx>
41 #include <editeng/orphitem.hxx>
42 #include <editeng/brkitem.hxx>
43 #include <editeng/widwitem.hxx>
44 #include <editeng/kernitem.hxx>
45 #include <editeng/escpitem.hxx>
46 #include <editeng/lspcitem.hxx>
47 #include <editeng/adjitem.hxx>
48 #include <editeng/crsditem.hxx>
49 #include <editeng/shdditem.hxx>
50 #include <editeng/hyznitem.hxx>
51 #include <editeng/udlnitem.hxx>
52 #include <editeng/fontitem.hxx>
53 #include <editeng/fhgtitem.hxx>
54 #include <editeng/colritem.hxx>
55 #include <editeng/wghtitem.hxx>
56 #include <editeng/cntritem.hxx>
57 #include <editeng/postitem.hxx>
58 #include <editeng/frmdiritem.hxx>
59 #include <svx/svdoutl.hxx>
60 #include <sfx2/viewfrm.hxx>
61 #include <svl/whiter.hxx>
62 #include <svl/cjkoptions.hxx>
63 #include <svl/ctloptions.hxx>
64 #include <svtools/langtab.hxx>
65 #include <svl/languageoptions.hxx>
66 #include <sfx2/bindings.hxx>
67 #include <vcl/msgbox.hxx>
68 #include <sfx2/dispatch.hxx>
69 #include <sfx2/request.hxx>
70 #include <editeng/flditem.hxx>
71 #include <editeng/editstat.hxx>
72 #include <svx/hlnkitem.hxx>
73 #include <svx/htmlmode.hxx>
74 #include <svl/languageoptions.hxx>
75 #include <svl/slstitm.hxx>
76 #include <editeng/langitem.hxx>
77 #include <svtools/langtab.hxx>
78 #include <editeng/unolingu.hxx>
79 #include <editeng/scripttypeitem.hxx>
80 #include <editeng/writingmodeitem.hxx>
81 #include <editeng/eeitem.hxx>
82 #include <editeng/editeng.hxx>
83 #include <editeng/editdata.hxx>
84 #include <editeng/outliner.hxx>
85 #include <vcl/window.hxx>
86 #include <editeng/editview.hxx>
87 #include <vcl/outdev.hxx>
88 #include <editeng/hyznitem.hxx>
89 #include <editeng/kernitem.hxx>
90 #include <editeng/langitem.hxx>
91 #include <editeng/lspcitem.hxx>
92 #include <editeng/orphitem.hxx>
93 #include <editeng/outliner.hxx>
94 #include <editeng/postitem.hxx>
95 #include <editeng/scripttypeitem.hxx>
96 #include <editeng/shdditem.hxx>
97 #include <editeng/spltitem.hxx>
98 #include <svx/svdoutl.hxx>
99 #include <svx/svdview.hxx>
100 #include <editeng/udlnitem.hxx>
101 #include <editeng/unolingu.hxx>
102 #include <editeng/wghtitem.hxx>
103 #include <editeng/widwitem.hxx>
104 #include <editeng/writingmodeitem.hxx>
105 #include <tools/shl.hxx>
106 #include <vcl/msgbox.hxx>
107 #include <vcl/outdev.hxx>
108 #include <vcl/window.hxx>
109 
110 #include <cmdid.h>
111 #include <doc.hxx>
112 #include <docstat.hxx>
113 #include <drwtxtsh.hxx>
114 #include <edtwin.hxx>
115 #include <globals.hrc>
116 #include <hintids.hxx>
117 #include <initui.hxx>               // fuer SpellPointer
118 #include <langhelper.hxx>
119 #include <pardlg.hxx>
120 #include <shells.hrc>
121 #include <string.h>
122 #include <swdtflvr.hxx>
123 #include <swmodule.hxx>
124 #include <swwait.hxx>
125 #include <uitool.hxx>
126 #include <viewopt.hxx>
127 #include <wrtsh.hxx>
128 #include <wview.hxx>
129 
130 #include "swabstdlg.hxx"
131 #include "chrdlg.hrc"
132 #include "misc.hrc"
133 
134 
135 #include <langhelper.hxx>
136 
137 using namespace ::com::sun::star;
138 
139 /*--------------------------------------------------------------------
140 	Beschreibung:
141  --------------------------------------------------------------------*/
142 
143 void SwDrawTextShell::Execute( SfxRequest &rReq )
144 {
145 	SwWrtShell &rSh = GetShell();
146     	OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
147     	SfxItemSet aEditAttr(pOLV->GetAttribs());
148 	SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
149 
150 	sal_uInt16 nSlot = rReq.GetSlot();
151 
152 	sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
153 	const SfxItemSet *pNewAttrs = rReq.GetArgs();
154 
155 	bool bRestoreSelection = false;
156 	ESelection aOldSelection;
157 
158 	sal_uInt16 nEEWhich = 0;
159 	switch (nSlot)
160 	{
161 		case SID_LANGUAGE_STATUS:
162         {
163 			aOldSelection = pOLV->GetSelection();
164 			if (!pOLV->GetEditView().HasSelection())
165 			{
166 				bRestoreSelection	= true;
167 				pOLV->GetEditView().SelectCurrentWord();
168 			}
169 
170 			bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,GetView(),rSh);
171 			break;
172         }
173 
174         case SID_THES:
175         {
176             String aReplaceText;
177             SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False );
178             if (pItem2)
179                 aReplaceText = pItem2->GetValue();
180             if (aReplaceText.Len() > 0)
181                 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
182             break;
183         }
184 
185         case SID_ATTR_CHAR_FONT:
186         case SID_ATTR_CHAR_FONTHEIGHT:
187         case SID_ATTR_CHAR_WEIGHT:
188         case SID_ATTR_CHAR_POSTURE:
189         {
190             SfxItemPool* pPool2 = aEditAttr.GetPool()->GetSecondaryPool();
191             if( !pPool2 )
192                 pPool2 = aEditAttr.GetPool();
193             SvxScriptSetItem aSetItem( nSlot, *pPool2 );
194 
195             // #i78017 establish the same behaviour as in Writer
196             sal_uInt16 nScriptTypes = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
197             if (nSlot == SID_ATTR_CHAR_FONT)
198                 nScriptTypes = pOLV->GetSelectedScriptType();
199 
200             aSetItem.PutItemForScriptType( nScriptTypes, pNewAttrs->Get( nWhich ) );
201             aNewAttr.Put( aSetItem.GetItemSet() );
202         }
203         break;
204 
205         case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
206 
207 		case SID_ATTR_CHAR_UNDERLINE:
208 		{
209 		 	FontUnderline eFU = ((const SvxUnderlineItem&)aEditAttr.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
210 			aNewAttr.Put(SvxUnderlineItem(eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE));
211 		}
212 		break;
213 
214 		case SID_ATTR_CHAR_OVERLINE:
215 		{
216 		 	FontUnderline eFO = ((const SvxOverlineItem&)aEditAttr.Get(EE_CHAR_OVERLINE)).GetLineStyle();
217 			aNewAttr.Put(SvxOverlineItem(eFO == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_OVERLINE));
218 		}
219 		break;
220 
221         case SID_ATTR_CHAR_CONTOUR:     nEEWhich = EE_CHAR_OUTLINE; break;
222         case SID_ATTR_CHAR_SHADOWED:    nEEWhich = EE_CHAR_SHADOW; break;
223         case SID_ATTR_CHAR_STRIKEOUT:   nEEWhich = EE_CHAR_STRIKEOUT; break;
224         case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
225         case SID_ATTR_CHAR_RELIEF      : nEEWhich = EE_CHAR_RELIEF;  break;
226         case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
227         case SID_ATTR_CHAR_KERNING     : nEEWhich = EE_CHAR_KERNING; break;
228         case SID_ATTR_CHAR_SCALEWIDTH:   nEEWhich = EE_CHAR_FONTWIDTH; break;
229         case SID_ATTR_CHAR_AUTOKERN  :   nEEWhich = EE_CHAR_PAIRKERNING; break;
230         case SID_ATTR_CHAR_ESCAPEMENT:   nEEWhich = EE_CHAR_ESCAPEMENT; break;
231         case SID_ATTR_PARA_ADJUST_LEFT:
232 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_LEFT, EE_PARA_JUST));
233         break;
234 		case SID_ATTR_PARA_ADJUST_CENTER:
235 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
236         break;
237 		case SID_ATTR_PARA_ADJUST_RIGHT:
238 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST));
239         break;
240 		case SID_ATTR_PARA_ADJUST_BLOCK:
241 			aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_BLOCK, EE_PARA_JUST));
242         break;
243 
244 		case SID_ATTR_PARA_LINESPACE_10:
245 		{
246 			SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_LINE, EE_PARA_SBL);
247 			aItem.SetPropLineSpace(100);
248 			aNewAttr.Put(aItem);
249 		}
250 		break;
251 		case SID_ATTR_PARA_LINESPACE_15:
252 		{
253 			SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_POINT_FIVE_LINES, EE_PARA_SBL);
254 			aItem.SetPropLineSpace(150);
255 			aNewAttr.Put(aItem);
256 		}
257 		break;
258 		case SID_ATTR_PARA_LINESPACE_20:
259 		{
260 			SvxLineSpacingItem aItem(SVX_LINESPACE_TWO_LINES, EE_PARA_SBL);
261 			aItem.SetPropLineSpace(200);
262 			aNewAttr.Put(aItem);
263 		}
264 		break;
265 
266 		case FN_SET_SUPER_SCRIPT:
267 		{
268 			SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
269 			SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
270 							aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
271 
272 			if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
273 				aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
274 			else
275 				aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
276 			aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
277 		}
278 		break;
279 		case FN_SET_SUB_SCRIPT:
280 		{
281 			SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
282 			SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
283 							aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
284 
285 			if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
286 				aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
287 			else
288 				aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
289 			aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
290 		}
291 		break;
292 
293 		case SID_CHAR_DLG:
294 		case SID_CHAR_DLG_FOR_PARAGRAPH:
295 		{
296 			const SfxItemSet* pArgs = rReq.GetArgs();
297 
298 			if( !pArgs )
299 			{
300 				aOldSelection = pOLV->GetSelection();
301 				if (nSlot == SID_CHAR_DLG_FOR_PARAGRAPH)
302 				{
303 					// select current paragraph (and restore selection later on...)
304 					EditView & rEditView = pOLV->GetEditView();
305 					SwLangHelper::SelectPara( rEditView, rEditView.GetSelection() );
306 					bRestoreSelection = true;
307 				}
308 
309 				SwView* pView = &GetView();
310 				FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
311                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
312 				SfxItemSet aDlgAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
313 
314 				// util::Language gibts an der EditEngine nicht! Daher nicht im Set.
315 
316 				aDlgAttr.Put( aEditAttr );
317                 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
318 
319                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
320                 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
321 
322                 SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( pView->GetWindow(), *pView, aDlgAttr, DLG_CHAR,0, sal_True );
323                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
324 				sal_uInt16 nRet = pDlg->Execute();
325 				if(RET_OK == nRet )
326                 {
327                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
328                     aNewAttr.Put(*pDlg->GetOutputItemSet());
329                 }
330 				delete( pDlg );
331 				if(RET_OK != nRet)
332 					return ;
333 			}
334 			else
335 				aNewAttr.Put(*pArgs);
336 		}
337 		break;
338 		case FN_FORMAT_FOOTNOTE_DLG:
339 		{
340             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
341             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
342 
343             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), rView.GetWrtShell(), DLG_DOC_FOOTNOTE );
344             DBG_ASSERT(pDlg, "Dialogdiet fail!");
345 			pDlg->Execute();
346 			delete pDlg;
347 			break;
348 		}
349 		case FN_NUMBERING_OUTLINE_DLG:
350 		{
351 			SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
352 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
353             DBG_ASSERT(pFact, "Dialogdiet fail!");
354             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
355 														GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
356             DBG_ASSERT(pDlg, "Dialogdiet fail!");
357 			pDlg->Execute();
358 			delete pDlg;
359 			rReq.Done();
360 		}
361 		break;
362 		case SID_OPEN_XML_FILTERSETTINGS:
363 		{
364 			try
365 			{
366 				uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
367 				if( xDialog.is() )
368 				{
369 					xDialog->execute();
370 				}
371 			}
372 			catch( uno::Exception& )
373 			{
374 			}
375 			rReq.Ignore ();
376 		}
377 		break;
378 		case FN_WORDCOUNT_DIALOG:
379 		{
380 			SwDocStat aCurr;
381 			SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
382 			{
383 				SwWait aWait( *GetView().GetDocShell(), sal_True );
384 				rSh.StartAction();
385 				rSh.CountWords( aCurr );
386 				rSh.UpdateDocStat( aDocStat );
387 				rSh.EndAction();
388 			}
389 
390 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
391 			DBG_ASSERT(pFact, "Dialogdiet fail!");
392 			AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
393 			pDialog->SetValues(aCurr, aDocStat );
394 			pDialog->Execute();
395 			delete pDialog;
396 		}
397 		break;
398 		case SID_PARA_DLG:
399 		{
400 			const SfxItemSet* pArgs = rReq.GetArgs();
401 
402 			if (!pArgs)
403 			{
404 				SwView* pView = &GetView();
405 				FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
406                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
407 				SfxItemSet aDlgAttr(GetPool(),
408 									EE_ITEMS_START, EE_ITEMS_END,
409 									SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_HYPHENZONE,
410 									SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_SPLIT,
411 									SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_WIDOWS,
412 									SID_ATTR_PARA_ORPHANS, SID_ATTR_PARA_ORPHANS,
413 									0);
414 
415 				aDlgAttr.Put(aEditAttr);
416 
417 				// Die Werte sind erst einmal uebernommen worden, um den Dialog anzuzeigen.
418 				// Muss natuerlich noch geaendert werden
419 				// aDlgAttr.Put( SvxParaDlgLimitsItem( 567 * 50, 5670) );
420 
421                 aDlgAttr.Put( SvxHyphenZoneItem( sal_False, RES_PARATR_HYPHENZONE) );
422                 aDlgAttr.Put( SvxFmtBreakItem( SVX_BREAK_NONE, RES_BREAK ) );
423                 aDlgAttr.Put( SvxFmtSplitItem( sal_True, RES_PARATR_SPLIT ) );
424                 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
425                 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
426 
427                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
428                 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
429 
430                 SfxAbstractTabDialog* pDlg = pFact->CreateSwParaDlg( GetView().GetWindow(), GetView(), aDlgAttr,DLG_STD, DLG_PARA, 0, sal_True );
431                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
432 				sal_uInt16 nRet = pDlg->Execute();
433 				if(RET_OK == nRet)
434                 {
435                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
436                     aNewAttr.Put(*pDlg->GetOutputItemSet());
437                 }
438 				delete( pDlg );
439 				if(RET_OK != nRet)
440 					return;
441 			}
442 			else
443 				aNewAttr.Put(*pArgs);
444 		}
445 		break;
446 		case SID_AUTOSPELL_CHECK:
447 		{
448 //!! JP 16.03.2001: why??			pSdrView = rSh.GetDrawView();
449 //!! JP 16.03.2001: why??			pOutliner = pSdrView->GetTextEditOutliner();
450             SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
451             sal_uInt32 nCtrl = pOutliner->GetControlWord();
452 
453 			sal_Bool bSet = ((const SfxBoolItem&)rReq.GetArgs()->Get(
454 													nSlot)).GetValue();
455             if(bSet)
456                 nCtrl |= EE_CNTRL_ONLINESPELLING|EE_CNTRL_ALLOWBIGOBJS;
457             else
458                 nCtrl &= ~EE_CNTRL_ONLINESPELLING;
459 			pOutliner->SetControlWord(nCtrl);
460 
461             rView.ExecuteSlot(rReq);
462 		}
463 		break;
464 		case SID_HYPERLINK_SETLINK:
465 		{
466 			const SfxPoolItem* pItem = 0;
467 			if(pNewAttrs)
468 				pNewAttrs->GetItemState(nSlot, sal_False, &pItem);
469 
470 			if(pItem)
471 			{
472 				const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
473 				SvxURLField aFld(rHLinkItem.GetURL(), rHLinkItem.GetName(), SVXURLFORMAT_APPDEFAULT);
474 				aFld.SetTargetFrame(rHLinkItem.GetTargetFrame());
475 
476 				const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
477 
478 				if (pFieldItem && pFieldItem->GetField()->ISA(SvxURLField))
479 				{
480 					// Feld selektieren, so dass es beim Insert geloescht wird
481 					ESelection aSel = pOLV->GetSelection();
482 					aSel.nEndPos++;
483 					pOLV->SetSelection(aSel);
484 				}
485                 pOLV->InsertField(SvxFieldItem(aFld, EE_FEATURE_FIELD));
486 			}
487 		}
488 		break;
489 
490 		case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
491     	case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
492 			// Shellwechsel!
493 			{
494 				SdrObject* pTmpObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
495 				SdrPageView* pTmpPV = pSdrView->GetSdrPageView();
496 				SdrView* pTmpView = pSdrView;
497 
498                 pSdrView->SdrEndTextEdit(sal_True);
499 
500 				SfxItemSet aAttr( *aNewAttr.GetPool(),
501 							SDRATTR_TEXTDIRECTION,
502 							SDRATTR_TEXTDIRECTION );
503 
504 				aAttr.Put( SvxWritingModeItem(
505 					nSlot == SID_TEXTDIRECTION_LEFT_TO_RIGHT ?
506                         text::WritingMode_LR_TB
507                         : text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION ) );
508 				pTmpView->SetAttributes( aAttr );
509 
510 				rSh.GetView().BeginTextEdit( pTmpObj, pTmpPV, &rSh.GetView().GetEditWin(), sal_False);
511 				rSh.GetView().AttrChangedNotify( &rSh );
512 			}
513 			return;
514 
515         case SID_ATTR_PARA_LEFT_TO_RIGHT:
516         case SID_ATTR_PARA_RIGHT_TO_LEFT:
517         {
518             SdrObject* pTmpObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
519             SdrPageView* pTmpPV = pSdrView->GetSdrPageView();
520             SdrView* pTmpView = pSdrView;
521 
522             pSdrView->SdrEndTextEdit(sal_True);
523             sal_Bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
524 
525             const SfxPoolItem* pPoolItem;
526             if( pNewAttrs && SFX_ITEM_SET == pNewAttrs->GetItemState( nSlot, sal_True, &pPoolItem ) )
527             {
528                 if( !( (SfxBoolItem*)pPoolItem)->GetValue() )
529                     bLeftToRight = !bLeftToRight;
530             }
531             SfxItemSet aAttr( *aNewAttr.GetPool(),
532                         EE_PARA_JUST, EE_PARA_JUST,
533                         EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
534                         0 );
535 
536             sal_uInt16 nAdjust = SVX_ADJUST_LEFT;
537             if( SFX_ITEM_ON == aEditAttr.GetItemState(EE_PARA_JUST, sal_True, &pPoolItem ) )
538                 nAdjust = ( (SvxAdjustItem*)pPoolItem)->GetEnumValue();
539 
540             if( bLeftToRight )
541             {
542                 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
543                 if( nAdjust == SVX_ADJUST_RIGHT )
544                     aAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
545             }
546             else
547             {
548                 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
549                 if( nAdjust == SVX_ADJUST_LEFT )
550                     aAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
551             }
552             pTmpView->SetAttributes( aAttr );
553             rSh.GetView().BeginTextEdit( pTmpObj, pTmpPV, &rSh.GetView().GetEditWin(), sal_False );
554             rSh.GetView().AttrChangedNotify( &rSh );
555         }
556         return;
557 		default:
558 			ASSERT(!this, falscher Dispatcher);
559 			return;
560 	}
561     if(nEEWhich && pNewAttrs)
562         aNewAttr.Put(pNewAttrs->Get(nWhich), nEEWhich);
563 
564 	SetAttrToMarked(aNewAttr);
565 
566 	GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
567 
568 	if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
569 		rSh.SetModified();
570 
571 	if (bRestoreSelection)
572 	{
573 		// restore selection
574 		pOLV->GetEditView().SetSelection( aOldSelection );
575 	}
576 }
577 
578 /*--------------------------------------------------------------------
579 	Beschreibung:
580  --------------------------------------------------------------------*/
581 
582 void SwDrawTextShell::GetState(SfxItemSet& rSet)
583 {
584 	if (!IsTextEdit())	// Sonst manchmal Absturz!
585 		return;
586 
587 	OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
588     SfxWhichIter aIter(rSet);
589 	sal_uInt16 nWhich = aIter.FirstWhich();
590 
591     SfxItemSet aEditAttr( pOLV->GetAttribs() );
592 	const SfxPoolItem *pAdjust = 0, *pLSpace = 0, *pEscItem = 0;
593 	int eAdjust, nLSpace, nEsc;
594 
595 	while(nWhich)
596 	{
597 		sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
598 		sal_Bool bFlag = sal_False;
599 		switch( nSlotId )
600 		{
601 		    case SID_LANGUAGE_STATUS://20412:
602             {
603 				nSlotId = SwLangHelper::GetLanguageStatus(pOLV,rSet);;
604 				break;
605 			}
606 
607             case SID_THES:
608             {
609                 String          aStatusVal;
610                 LanguageType    nLang = LANGUAGE_NONE;
611                 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
612                 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
613 
614                 // disable "Thesaurus" context menu entry if there is nothing to look up
615                 uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
616                 lang::Locale aLocale( SvxCreateLocale( nLang ) );
617                 if (!bIsLookUpWord ||
618                     !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale ))
619                     rSet.DisableItem( SID_THES );
620 
621                 //! avoid puting the same item as SfxBoolItem at the end of this function
622                 nSlotId = 0;
623                 break;
624             }
625 
626         case SID_ATTR_PARA_ADJUST_LEFT:     eAdjust = SVX_ADJUST_LEFT; goto ASK_ADJUST;
627 		case SID_ATTR_PARA_ADJUST_RIGHT:	eAdjust = SVX_ADJUST_RIGHT; goto ASK_ADJUST;
628 		case SID_ATTR_PARA_ADJUST_CENTER:	eAdjust = SVX_ADJUST_CENTER; goto ASK_ADJUST;
629 		case SID_ATTR_PARA_ADJUST_BLOCK:	eAdjust = SVX_ADJUST_BLOCK; goto ASK_ADJUST;
630 ASK_ADJUST:
631 			{
632 				if( !pAdjust )
633 					aEditAttr.GetItemState( EE_PARA_JUST, sal_False, &pAdjust);
634 
635 				if( !pAdjust || IsInvalidItem( pAdjust ))
636 					rSet.InvalidateItem( nSlotId ), nSlotId = 0;
637 				else
638 					bFlag = eAdjust == ((SvxAdjustItem*)pAdjust)->GetAdjust();
639 			}
640 			break;
641 
642 		case SID_ATTR_PARA_LINESPACE_10:	nLSpace = 100;	goto ASK_LINESPACE;
643 		case SID_ATTR_PARA_LINESPACE_15:	nLSpace = 150;	goto ASK_LINESPACE;
644 		case SID_ATTR_PARA_LINESPACE_20:	nLSpace = 200;	goto ASK_LINESPACE;
645 ASK_LINESPACE:
646 			{
647 				if( !pLSpace )
648 					aEditAttr.GetItemState( EE_PARA_SBL, sal_False, &pLSpace );
649 
650 				if( !pLSpace || IsInvalidItem( pLSpace ))
651 					rSet.InvalidateItem( nSlotId ), nSlotId = 0;
652 				else if( nLSpace == ((const SvxLineSpacingItem*)pLSpace)->
653 												GetPropLineSpace() )
654 					bFlag = sal_True;
655 				else
656 					nSlotId = 0;
657 			}
658 			break;
659 
660 		case FN_SET_SUPER_SCRIPT:	nEsc = SVX_ESCAPEMENT_SUPERSCRIPT;
661 									goto ASK_ESCAPE;
662 		case FN_SET_SUB_SCRIPT:		nEsc = SVX_ESCAPEMENT_SUBSCRIPT;
663 									goto ASK_ESCAPE;
664 ASK_ESCAPE:
665 			{
666 				if( !pEscItem )
667 					pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
668 
669 				if( nEsc == ((const SvxEscapementItem*)
670 												pEscItem)->GetEnumValue() )
671 					bFlag = sal_True;
672 				else
673 					nSlotId = 0;
674 			}
675 			break;
676 
677         case SID_THESAURUS:
678         {
679             // disable "Thesaurus" if the language is not supported
680             const SfxPoolItem &rItem = GetShell().GetDoc()->GetDefault(
681                             GetWhichOfScript( RES_CHRATR_LANGUAGE,
682                             GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage())) );
683             LanguageType nLang = ((const SvxLanguageItem &) rItem).GetLanguage();
684 
685             uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
686             if (!xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( SvxCreateLocale( nLang ) ))
687                 rSet.DisableItem( SID_THESAURUS );
688             nSlotId = 0;
689         }
690         break;
691         case SID_HANGUL_HANJA_CONVERSION:
692         case SID_CHINESE_CONVERSION:
693         {
694             if (!SvtCJKOptions().IsAnyEnabled())
695             {
696                 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
697                 rSet.DisableItem(nWhich);
698             }
699             else
700                 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
701         }
702         break;
703 
704         case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
705         case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
706 			if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
707 			{
708 				rSet.DisableItem( nSlotId );
709 				nSlotId = 0;
710 			}
711 			else
712 			{
713                 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
714                 if( pOutliner )
715 					bFlag = pOutliner->IsVertical() ==
716 							(SID_TEXTDIRECTION_TOP_TO_BOTTOM == nSlotId);
717 				else
718 				{
719                     text::WritingMode eMode = (text::WritingMode)
720 									( (const SvxWritingModeItem&) aEditAttr.Get( SDRATTR_TEXTDIRECTION ) ).GetValue();
721 
722 					if( nSlotId == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
723 					{
724                         bFlag = eMode == text::WritingMode_LR_TB;
725 					}
726 					else
727 					{
728                         bFlag = eMode != text::WritingMode_TB_RL;
729 					}
730 				}
731 			}
732 			break;
733         case SID_ATTR_PARA_LEFT_TO_RIGHT:
734         case SID_ATTR_PARA_RIGHT_TO_LEFT:
735         {
736             if ( !SvtLanguageOptions().IsCTLFontEnabled() )
737             {
738 				rSet.DisableItem( nWhich );
739 				nSlotId = 0;
740             }
741             else
742             {
743                 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
744                 if(pOutliner && pOutliner->IsVertical())
745 				{
746 					rSet.DisableItem( nWhich );
747 					nSlotId = 0;
748 				}
749 				else
750 				{
751 					switch( ( ( (SvxFrameDirectionItem&) aEditAttr.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() )
752 					{
753 						case FRMDIR_HORI_LEFT_TOP:
754 							bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
755 						break;
756 
757 						case FRMDIR_HORI_RIGHT_TOP:
758 							bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
759 						break;
760 					}
761 				}
762 			}
763         }
764         break;
765         case SID_TRANSLITERATE_HALFWIDTH:
766         case SID_TRANSLITERATE_FULLWIDTH:
767         case SID_TRANSLITERATE_HIRAGANA:
768         case SID_TRANSLITERATE_KATAGANA:
769         {
770             SvtCJKOptions aCJKOptions;
771             if(!aCJKOptions.IsChangeCaseMapEnabled())
772             {
773                 rSet.DisableItem(nWhich);
774                 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
775             }
776             else
777                 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
778         }
779         break;
780 		case SID_INSERT_RLM :
781 		case SID_INSERT_LRM :
782 		case SID_INSERT_ZWNBSP :
783 		case SID_INSERT_ZWSP:
784         {
785 			SvtCTLOptions aCTLOptions;
786 			sal_Bool bEnabled = aCTLOptions.IsCTLFontEnabled();
787 			GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
788 			if(!bEnabled)
789 				rSet.DisableItem(nWhich);
790 		}
791 		break;
792 		default:
793 			nSlotId = 0;			    // don't know this slot
794 			break;
795 		}
796 
797 		if( nSlotId )
798 			rSet.Put( SfxBoolItem( nWhich, bFlag ));
799 
800 		nWhich = aIter.NextWhich();
801 	}
802 }
803 
804 /*--------------------------------------------------------------------
805 	Beschreibung:
806  --------------------------------------------------------------------*/
807 void SwDrawTextShell::GetDrawTxtCtrlState(SfxItemSet& rSet)
808 {
809 	if (!IsTextEdit())	// Sonst Absturz!
810 		return;
811 
812     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
813     SfxItemSet aEditAttr(pOLV->GetAttribs());
814 
815 	SfxWhichIter aIter(rSet);
816 	sal_uInt16 nWhich = aIter.FirstWhich();
817 	sal_uInt16 nScriptType = pOLV->GetSelectedScriptType();
818     while(nWhich)
819 	{
820         sal_uInt16 nEEWhich = 0;
821         sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
822 		switch( nSlotId )
823 		{
824             case SID_ATTR_CHAR_FONT:
825             case SID_ATTR_CHAR_FONTHEIGHT:
826             case SID_ATTR_CHAR_WEIGHT:
827             case SID_ATTR_CHAR_POSTURE:
828 			{
829                 SfxItemPool* pEditPool = aEditAttr.GetPool()->GetSecondaryPool();
830                 if( !pEditPool )
831                     pEditPool = aEditAttr.GetPool();
832                 SvxScriptSetItem aSetItem( nSlotId, *pEditPool );
833 				aSetItem.GetItemSet().Put( aEditAttr, sal_False );
834 				const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
835 				if( pI )
836 					rSet.Put( *pI, nWhich );
837 				else
838 					rSet.InvalidateItem( nWhich );
839 			}
840 			break;
841             case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
842             case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
843             case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
844             case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
845             case SID_ATTR_CHAR_SHADOWED:  nEEWhich = EE_CHAR_SHADOW;break;
846             case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
847             case SID_AUTOSPELL_CHECK:
848             {
849                 const SfxPoolItem* pState = rView.GetSlotState(nWhich);
850                 if (pState)
851                     rSet.Put(SfxBoolItem(nWhich, ((const SfxBoolItem*)pState)->GetValue()));
852                 else
853                     rSet.DisableItem( nWhich );
854                 break;
855             }
856             case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
857             case SID_ATTR_CHAR_RELIEF      : nEEWhich = EE_CHAR_RELIEF;  break;
858             case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
859             case SID_ATTR_CHAR_KERNING     : nEEWhich = EE_CHAR_KERNING; break;
860             case SID_ATTR_CHAR_SCALEWIDTH:   nEEWhich = EE_CHAR_FONTWIDTH;break;
861             case SID_ATTR_CHAR_AUTOKERN  :   nEEWhich = EE_CHAR_PAIRKERNING; break;
862             case SID_ATTR_CHAR_ESCAPEMENT:   nEEWhich = EE_CHAR_ESCAPEMENT; break;
863         }
864         if(nEEWhich)
865             rSet.Put(aEditAttr.Get(nEEWhich, sal_True), nWhich);
866 
867         nWhich = aIter.NextWhich();
868 	}
869 }
870 
871 /*--------------------------------------------------------------------
872 	Beschreibung:
873  --------------------------------------------------------------------*/
874 void SwDrawTextShell::ExecClpbrd(SfxRequest &rReq)
875 {
876 	if (!IsTextEdit())	// Sonst Absturz!
877 		return;
878 
879     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
880 
881     ESelection aSel(pOLV->GetSelection());
882 	const sal_Bool bCopy = (aSel.nStartPara != aSel.nEndPara) || (aSel.nStartPos != aSel.nEndPos);
883     sal_uInt16 nId = rReq.GetSlot();
884 	switch( nId )
885 	{
886 		case SID_CUT:
887 			if (bCopy)
888 				pOLV->Cut();
889 			return;
890 
891 		case SID_COPY:
892 			if (bCopy)
893 				pOLV->Copy();
894 			return;
895 
896 		case SID_PASTE:
897 			pOLV->PasteSpecial();
898 			break;
899 
900 		default:
901 			DBG_ERROR("falscher Dispatcher");
902 			return;
903 	}
904 }
905 
906 /*--------------------------------------------------------------------
907 	Beschreibung:	ClipBoard-Status
908  --------------------------------------------------------------------*/
909 void SwDrawTextShell::StateClpbrd(SfxItemSet &rSet)
910 {
911 	if (!IsTextEdit())	// Sonst Absturz!
912 		return;
913 
914     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
915     ESelection aSel(pOLV->GetSelection());
916 	const sal_Bool bCopy = (aSel.nStartPara != aSel.nEndPara) ||
917 						   (aSel.nStartPos != aSel.nEndPos);
918 
919 
920 	SfxWhichIter aIter(rSet);
921 	sal_uInt16 nWhich = aIter.FirstWhich();
922 
923 	while(nWhich)
924 	{
925 		switch(nWhich)
926 		{
927 			case SID_CUT:
928 			case SID_COPY:
929 				if( !bCopy )
930 					rSet.DisableItem( nWhich );
931 				break;
932 
933 			case SID_PASTE:
934 				{
935 					TransferableDataHelper aDataHelper(
936 						TransferableDataHelper::CreateFromSystemClipboard(
937 								&GetView().GetEditWin() ) );
938 
939 					if( !aDataHelper.GetXTransferable().is() ||
940 						!SwTransferable::IsPaste( GetShell(), aDataHelper ))
941 						rSet.DisableItem( SID_PASTE );
942 				}
943 				break;
944 
945             case SID_PASTE_SPECIAL:
946                 rSet.DisableItem( SID_PASTE_SPECIAL );
947 				break;
948             // --> OD 2008-06-20 #151110#
949             case SID_CLIPBOARD_FORMAT_ITEMS:
950                 rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS );
951                 break;
952             // <--
953 		}
954 		nWhich = aIter.NextWhich();
955 	}
956 }
957 
958 /*--------------------------------------------------------------------
959 	Beschreibung:	Hyperlink-Status
960  --------------------------------------------------------------------*/
961 
962 void SwDrawTextShell::StateInsert(SfxItemSet &rSet)
963 {
964 	if (!IsTextEdit())	// Sonst Absturz!
965 		return;
966 
967     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
968     SfxWhichIter aIter(rSet);
969 	sal_uInt16 nWhich = aIter.FirstWhich();
970 
971 	while(nWhich)
972 	{
973 		switch(nWhich)
974 		{
975 			case SID_HYPERLINK_GETLINK:
976 				{
977 					SvxHyperlinkItem aHLinkItem;
978 					aHLinkItem.SetInsertMode(HLINK_FIELD);
979 
980 					const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
981 
982 					if (pFieldItem)
983 					{
984 						const SvxFieldData* pField = pFieldItem->GetField();
985 
986 						if (pField->ISA(SvxURLField))
987 						{
988 							aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
989 							aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
990 							aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
991 						}
992 					}
993 					else
994 					{
995 						String sSel(pOLV->GetSelected());
996 						sSel.Erase(255);
997 						sSel.EraseTrailingChars();
998 						aHLinkItem.SetName(sSel);
999 					}
1000 
1001 					sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1002 					aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
1003 						((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1004 
1005 					rSet.Put(aHLinkItem);
1006 				}
1007 				break;
1008 		}
1009 		nWhich = aIter.NextWhich();
1010 	}
1011 }
1012 
1013