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