bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / drwtxtex.cxx
blob7ad14095a74d75f140e74b007278b8a38dbc63fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
23 #include <comphelper/processfactory.hxx>
24 #include <comphelper/string.hxx>
25 #include <i18nlangtag/mslangid.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/request.hxx>
29 #include <tools/shl.hxx>
30 #include <svx/svdview.hxx>
31 #include <editeng/spltitem.hxx>
32 #include <editeng/lrspitem.hxx>
33 #include <editeng/ulspitem.hxx>
34 #include <editeng/orphitem.hxx>
35 #include <editeng/formatbreakitem.hxx>
36 #include <editeng/widwitem.hxx>
37 #include <editeng/kernitem.hxx>
38 #include <editeng/escapementitem.hxx>
39 #include <editeng/lspcitem.hxx>
40 #include <editeng/adjustitem.hxx>
41 #include <editeng/crossedoutitem.hxx>
42 #include <editeng/shdditem.hxx>
43 #include <editeng/udlnitem.hxx>
44 #include <editeng/fontitem.hxx>
45 #include <editeng/fhgtitem.hxx>
46 #include <editeng/colritem.hxx>
47 #include <editeng/wghtitem.hxx>
48 #include <editeng/contouritem.hxx>
49 #include <editeng/postitem.hxx>
50 #include <editeng/frmdiritem.hxx>
51 #include <svx/svdoutl.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <svl/whiter.hxx>
54 #include <svl/cjkoptions.hxx>
55 #include <svl/ctloptions.hxx>
56 #include <svtools/langtab.hxx>
57 #include <svl/languageoptions.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <editeng/flditem.hxx>
60 #include <editeng/editstat.hxx>
61 #include <svx/hlnkitem.hxx>
62 #include <sfx2/htmlmode.hxx>
63 #include <svl/slstitm.hxx>
64 #include <editeng/langitem.hxx>
65 #include <editeng/unolingu.hxx>
66 #include <editeng/scripttypeitem.hxx>
67 #include <editeng/writingmodeitem.hxx>
68 #include <editeng/eeitem.hxx>
69 #include <editeng/editeng.hxx>
70 #include <editeng/editdata.hxx>
71 #include <editeng/outliner.hxx>
72 #include <vcl/window.hxx>
73 #include <editeng/editview.hxx>
74 #include <vcl/outdev.hxx>
75 #include <editeng/hyphenzoneitem.hxx>
76 #include <tools/diagnose_ex.h>
78 #include <cmdid.h>
79 #include <doc.hxx>
80 #include <docstat.hxx>
81 #include <drwtxtsh.hxx>
82 #include <edtwin.hxx>
83 #include <globals.hrc>
84 #include <hintids.hxx>
85 #include <initui.hxx> // for SpellPointer
86 #include <langhelper.hxx>
87 #include <pardlg.hxx>
88 #include <shells.hrc>
89 #include <string.h>
90 #include <swdtflvr.hxx>
91 #include <swmodule.hxx>
92 #include <swwait.hxx>
93 #include <uitool.hxx>
94 #include <viewopt.hxx>
95 #include <wrtsh.hxx>
96 #include <wview.hxx>
97 #include <wordcountdialog.hxx>
99 #include "swabstdlg.hxx"
100 #include "chrdlg.hrc"
101 #include "misc.hrc"
104 using namespace ::com::sun::star;
106 void SwDrawTextShell::Execute( SfxRequest &rReq )
108 SwWrtShell &rSh = GetShell();
109 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
110 SfxItemSet aEditAttr(pOLV->GetAttribs());
111 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
113 const sal_uInt16 nSlot = rReq.GetSlot();
115 const sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
116 const SfxItemSet *pNewAttrs = rReq.GetArgs();
118 bool bRestoreSelection = false;
119 ESelection aOldSelection;
121 sal_uInt16 nEEWhich = 0;
122 switch (nSlot)
124 case SID_LANGUAGE_STATUS:
126 aOldSelection = pOLV->GetSelection();
127 if (!pOLV->GetEditView().HasSelection())
129 bRestoreSelection = true;
130 pOLV->GetEditView().SelectCurrentWord();
133 bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,GetView(),rSh);
134 break;
137 case SID_THES:
139 String aReplaceText;
140 SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False );
141 if (pItem2)
142 aReplaceText = pItem2->GetValue();
143 if (aReplaceText.Len() > 0)
144 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
145 break;
148 case SID_ATTR_CHAR_FONT:
149 case SID_ATTR_CHAR_FONTHEIGHT:
150 case SID_ATTR_CHAR_WEIGHT:
151 case SID_ATTR_CHAR_POSTURE:
153 SfxItemPool* pPool2 = aEditAttr.GetPool()->GetSecondaryPool();
154 if( !pPool2 )
155 pPool2 = aEditAttr.GetPool();
156 SvxScriptSetItem aSetItem( nSlot, *pPool2 );
158 // #i78017 establish the same behaviour as in Writer
159 sal_uInt16 nScriptTypes = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
160 if (nSlot == SID_ATTR_CHAR_FONT)
161 nScriptTypes = pOLV->GetSelectedScriptType();
163 if (pNewAttrs)
165 aSetItem.PutItemForScriptType( nScriptTypes, pNewAttrs->Get( nWhich ) );
166 aNewAttr.Put( aSetItem.GetItemSet() );
169 break;
171 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
173 case SID_ATTR_CHAR_UNDERLINE:
175 if ( pNewAttrs )
177 const SvxTextLineItem& rTextLineItem = static_cast< const SvxTextLineItem& >( pNewAttrs->Get( pNewAttrs->GetPool()->GetWhich(nSlot) ) );
178 aNewAttr.Put( SvxUnderlineItem( rTextLineItem.GetLineStyle(), EE_CHAR_UNDERLINE ) );
180 else
182 FontUnderline eFU = ((const SvxUnderlineItem&)aEditAttr.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
183 aNewAttr.Put( SvxUnderlineItem(eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE) );
186 break;
188 case SID_ATTR_CHAR_OVERLINE:
190 FontUnderline eFO = ((const SvxOverlineItem&)aEditAttr.Get(EE_CHAR_OVERLINE)).GetLineStyle();
191 aNewAttr.Put(SvxOverlineItem(eFO == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_OVERLINE));
193 break;
195 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
196 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW; break;
197 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT; break;
198 case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
199 case SID_ATTR_CHAR_RELIEF : nEEWhich = EE_CHAR_RELIEF; break;
200 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
201 case SID_ATTR_CHAR_KERNING : nEEWhich = EE_CHAR_KERNING; break;
202 case SID_ATTR_CHAR_SCALEWIDTH: nEEWhich = EE_CHAR_FONTWIDTH; break;
203 case SID_ATTR_CHAR_AUTOKERN : nEEWhich = EE_CHAR_PAIRKERNING; break;
204 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT; break;
205 case SID_ATTR_PARA_ADJUST_LEFT:
206 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_LEFT, EE_PARA_JUST));
207 break;
208 case SID_ATTR_PARA_ADJUST_CENTER:
209 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
210 break;
211 case SID_ATTR_PARA_ADJUST_RIGHT:
212 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST));
213 break;
214 case SID_ATTR_PARA_ADJUST_BLOCK:
215 aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_BLOCK, EE_PARA_JUST));
216 break;
217 case SID_ATTR_PARA_LRSPACE:
219 SvxLRSpaceItem aParaMargin((const SvxLRSpaceItem&)rReq.
220 GetArgs()->Get(nSlot));
221 aParaMargin.SetWhich( EE_PARA_LRSPACE );
222 aNewAttr.Put(aParaMargin);
223 rReq.Done();
225 break;
226 case SID_ATTR_PARA_LINESPACE:
228 SvxLineSpacingItem aLineSpace = (const SvxLineSpacingItem&)pNewAttrs->Get(
229 GetPool().GetWhich(nSlot));
230 aLineSpace.SetWhich( EE_PARA_SBL );
231 aNewAttr.Put( aLineSpace );
232 rReq.Done();
234 break;
235 case SID_ATTR_PARA_ULSPACE:
237 SvxULSpaceItem aULSpace = (const SvxULSpaceItem&)pNewAttrs->Get(
238 GetPool().GetWhich(nSlot));
239 aULSpace.SetWhich( EE_PARA_ULSPACE );
240 aNewAttr.Put( aULSpace );
241 rReq.Done();
243 break;
245 case SID_ATTR_PARA_LINESPACE_10:
247 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_LINE, EE_PARA_SBL);
248 aItem.SetPropLineSpace(100);
249 aNewAttr.Put(aItem);
251 break;
252 case SID_ATTR_PARA_LINESPACE_15:
254 SvxLineSpacingItem aItem(SVX_LINESPACE_ONE_POINT_FIVE_LINES, EE_PARA_SBL);
255 aItem.SetPropLineSpace(150);
256 aNewAttr.Put(aItem);
258 break;
259 case SID_ATTR_PARA_LINESPACE_20:
261 SvxLineSpacingItem aItem(SVX_LINESPACE_TWO_LINES, EE_PARA_SBL);
262 aItem.SetPropLineSpace(200);
263 aNewAttr.Put(aItem);
265 break;
267 case FN_SET_SUPER_SCRIPT:
269 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
270 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
271 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
273 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
274 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
275 else
276 aItem.SetEscapement( SVX_ESCAPEMENT_SUPERSCRIPT );
277 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
279 break;
280 case FN_SET_SUB_SCRIPT:
282 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
283 SvxEscapement eEsc = (SvxEscapement ) ( (const SvxEscapementItem&)
284 aEditAttr.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
286 if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
287 aItem.SetEscapement( SVX_ESCAPEMENT_OFF );
288 else
289 aItem.SetEscapement( SVX_ESCAPEMENT_SUBSCRIPT );
290 aNewAttr.Put( aItem, EE_CHAR_ESCAPEMENT );
292 break;
294 case SID_CHAR_DLG_EFFECT:
295 case SID_CHAR_DLG:
296 case SID_CHAR_DLG_FOR_PARAGRAPH:
298 const SfxItemSet* pArgs = rReq.GetArgs();
300 if( !pArgs )
302 aOldSelection = pOLV->GetSelection();
303 if (nSlot == SID_CHAR_DLG_FOR_PARAGRAPH)
305 // select current paragraph (and restore selection later on...)
306 EditView & rEditView = pOLV->GetEditView();
307 SwLangHelper::SelectPara( rEditView, rEditView.GetSelection() );
308 bRestoreSelection = true;
311 SwView* pView = &GetView();
312 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
313 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
314 SfxItemSet aDlgAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
316 // util::Language does not exists in the EditEngine! That is why not in set.
318 aDlgAttr.Put( aEditAttr );
319 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
321 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
322 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
324 SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg(pView->GetWindow(), *pView, aDlgAttr, 0, sal_True);
325 OSL_ENSURE(pDlg, "Dialogdiet fail!");
326 if (nSlot == SID_CHAR_DLG_EFFECT)
328 pDlg->SetCurPageId(TP_CHAR_EXT);
330 sal_uInt16 nRet = pDlg->Execute();
331 if(RET_OK == nRet )
333 rReq.Done( *( pDlg->GetOutputItemSet() ) );
334 aNewAttr.Put(*pDlg->GetOutputItemSet());
336 delete( pDlg );
337 if(RET_OK != nRet)
338 return ;
340 else
341 aNewAttr.Put(*pArgs);
343 break;
344 case FN_FORMAT_FOOTNOTE_DLG:
346 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
347 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
349 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), rView.GetWrtShell(), DLG_DOC_FOOTNOTE );
350 OSL_ENSURE(pDlg, "Dialogdiet fail!");
351 pDlg->Execute();
352 delete pDlg;
353 break;
355 case FN_NUMBERING_OUTLINE_DLG:
357 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
358 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
359 OSL_ENSURE(pFact, "Dialogdiet fail!");
360 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
361 GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
362 OSL_ENSURE(pDlg, "Dialogdiet fail!");
363 pDlg->Execute();
364 delete pDlg;
365 rReq.Done();
367 break;
368 case SID_OPEN_XML_FILTERSETTINGS:
372 uno::Reference < ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext() );
373 xDialog->execute();
375 catch (const uno::Exception&)
377 DBG_UNHANDLED_EXCEPTION();
379 rReq.Ignore ();
381 break;
382 case FN_WORDCOUNT_DIALOG:
384 SfxViewFrame* pVFrame = GetView().GetViewFrame();
385 if (pVFrame != NULL)
387 pVFrame->ToggleChildWindow(FN_WORDCOUNT_DIALOG);
388 Invalidate(rReq.GetSlot());
390 SwWordCountWrapper *pWrdCnt = (SwWordCountWrapper*)pVFrame->GetChildWindow(SwWordCountWrapper::GetChildWindowId());
391 if (pWrdCnt)
392 pWrdCnt->UpdateCounts();
395 break;
396 case SID_PARA_DLG:
398 const SfxItemSet* pArgs = rReq.GetArgs();
400 if (!pArgs)
402 SwView* pView = &GetView();
403 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, pView));
404 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
405 SfxItemSet aDlgAttr(GetPool(),
406 EE_ITEMS_START, EE_ITEMS_END,
407 SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_HYPHENZONE,
408 SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_SPLIT,
409 SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_WIDOWS,
410 SID_ATTR_PARA_ORPHANS, SID_ATTR_PARA_ORPHANS,
413 aDlgAttr.Put(aEditAttr);
415 aDlgAttr.Put( SvxHyphenZoneItem( sal_False, RES_PARATR_HYPHENZONE) );
416 aDlgAttr.Put( SvxFmtBreakItem( SVX_BREAK_NONE, RES_BREAK ) );
417 aDlgAttr.Put( SvxFmtSplitItem( sal_True, RES_PARATR_SPLIT ) );
418 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
419 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
421 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
422 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
424 SfxAbstractTabDialog* pDlg = pFact->CreateSwParaDlg( GetView().GetWindow(), GetView(), aDlgAttr,DLG_STD, DLG_PARA, 0, sal_True );
425 OSL_ENSURE(pDlg, "Dialogdiet fail!");
426 sal_uInt16 nRet = pDlg->Execute();
427 if(RET_OK == nRet)
429 rReq.Done( *( pDlg->GetOutputItemSet() ) );
430 aNewAttr.Put(*pDlg->GetOutputItemSet());
432 delete( pDlg );
433 if(RET_OK != nRet)
434 return;
436 else
437 aNewAttr.Put(*pArgs);
439 break;
440 case SID_AUTOSPELL_CHECK:
442 //!! JP 16.03.2001: why?? pSdrView = rSh.GetDrawView();
443 //!! JP 16.03.2001: why?? pOutliner = pSdrView->GetTextEditOutliner();
444 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
445 sal_uInt32 nCtrl = pOutliner->GetControlWord();
447 sal_Bool bSet = ((const SfxBoolItem&)rReq.GetArgs()->Get(
448 nSlot)).GetValue();
449 if(bSet)
450 nCtrl |= EE_CNTRL_ONLINESPELLING|EE_CNTRL_ALLOWBIGOBJS;
451 else
452 nCtrl &= ~EE_CNTRL_ONLINESPELLING;
453 pOutliner->SetControlWord(nCtrl);
455 rView.ExecuteSlot(rReq);
457 break;
458 case SID_HYPERLINK_SETLINK:
460 const SfxPoolItem* pItem = 0;
461 if(pNewAttrs)
462 pNewAttrs->GetItemState(nSlot, sal_False, &pItem);
464 if(pItem)
466 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
467 SvxURLField aFld(rHLinkItem.GetURL(), rHLinkItem.GetName(), SVXURLFORMAT_APPDEFAULT);
468 aFld.SetTargetFrame(rHLinkItem.GetTargetFrame());
470 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
472 if (pFieldItem && pFieldItem->GetField()->ISA(SvxURLField))
474 // Select field so that it will be deleted during insert
475 ESelection aSel = pOLV->GetSelection();
476 aSel.nEndPos++;
477 pOLV->SetSelection(aSel);
479 pOLV->InsertField(SvxFieldItem(aFld, EE_FEATURE_FIELD));
482 break;
484 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
485 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
486 // Shell switch!
488 SdrObject* pTmpObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
489 SdrPageView* pTmpPV = pSdrView->GetSdrPageView();
490 SdrView* pTmpView = pSdrView;
492 pSdrView->SdrEndTextEdit(sal_True);
494 SfxItemSet aAttr( *aNewAttr.GetPool(),
495 SDRATTR_TEXTDIRECTION,
496 SDRATTR_TEXTDIRECTION );
498 aAttr.Put( SvxWritingModeItem(
499 nSlot == SID_TEXTDIRECTION_LEFT_TO_RIGHT ?
500 text::WritingMode_LR_TB
501 : text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION ) );
502 pTmpView->SetAttributes( aAttr );
504 rSh.GetView().BeginTextEdit( pTmpObj, pTmpPV, &rSh.GetView().GetEditWin(), sal_False);
505 rSh.GetView().AttrChangedNotify( &rSh );
507 return;
509 case SID_ATTR_PARA_LEFT_TO_RIGHT:
510 case SID_ATTR_PARA_RIGHT_TO_LEFT:
512 SdrObject* pTmpObj = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
513 SdrPageView* pTmpPV = pSdrView->GetSdrPageView();
514 SdrView* pTmpView = pSdrView;
516 pSdrView->SdrEndTextEdit(sal_True);
517 bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
519 const SfxPoolItem* pPoolItem;
520 if( pNewAttrs && SFX_ITEM_SET == pNewAttrs->GetItemState( nSlot, sal_True, &pPoolItem ) )
522 if( !( (SfxBoolItem*)pPoolItem)->GetValue() )
523 bLeftToRight = !bLeftToRight;
525 SfxItemSet aAttr( *aNewAttr.GetPool(),
526 EE_PARA_JUST, EE_PARA_JUST,
527 EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
528 0 );
530 sal_uInt16 nAdjust = SVX_ADJUST_LEFT;
531 if( SFX_ITEM_ON == aEditAttr.GetItemState(EE_PARA_JUST, sal_True, &pPoolItem ) )
532 nAdjust = ( (SvxAdjustItem*)pPoolItem)->GetEnumValue();
534 if( bLeftToRight )
536 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
537 if( nAdjust == SVX_ADJUST_RIGHT )
538 aAttr.Put( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
540 else
542 aAttr.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
543 if( nAdjust == SVX_ADJUST_LEFT )
544 aAttr.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
546 pTmpView->SetAttributes( aAttr );
547 rSh.GetView().BeginTextEdit( pTmpObj, pTmpPV, &rSh.GetView().GetEditWin(), sal_False );
548 rSh.GetView().AttrChangedNotify( &rSh );
550 return;
551 default:
552 OSL_ENSURE(!this, "wrong dispatcher");
553 return;
555 if(nEEWhich && pNewAttrs)
556 aNewAttr.Put(pNewAttrs->Get(nWhich), nEEWhich);
558 SetAttrToMarked(aNewAttr);
560 GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
562 if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
563 rSh.SetModified();
565 if (bRestoreSelection)
567 // restore selection
568 pOLV->GetEditView().SetSelection( aOldSelection );
572 void SwDrawTextShell::GetState(SfxItemSet& rSet)
574 if (!IsTextEdit()) // Otherwise sometimes crash!
575 return;
577 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
578 SfxWhichIter aIter(rSet);
579 sal_uInt16 nWhich = aIter.FirstWhich();
581 SfxItemSet aEditAttr( pOLV->GetAttribs() );
582 const SfxPoolItem *pAdjust = 0, *pLSpace = 0, *pEscItem = 0;
583 int eAdjust, nLSpace, nEsc;
585 while(nWhich)
587 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
588 sal_Bool bFlag = sal_False;
589 switch( nSlotId )
591 case SID_LANGUAGE_STATUS://20412:
593 nSlotId = SwLangHelper::GetLanguageStatus(pOLV,rSet);
594 break;
597 case SID_THES:
599 String aStatusVal;
600 LanguageType nLang = LANGUAGE_NONE;
601 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
602 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
604 // disable "Thesaurus" context menu entry if there is nothing to look up
605 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
606 if (!bIsLookUpWord ||
607 !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag( nLang ).getLocale() ))
608 rSet.DisableItem( SID_THES );
610 //! avoid putting the same item as SfxBoolItem at the end of this function
611 nSlotId = 0;
612 break;
615 case SID_ATTR_PARA_ADJUST_LEFT: eAdjust = SVX_ADJUST_LEFT; goto ASK_ADJUST;
616 case SID_ATTR_PARA_ADJUST_RIGHT: eAdjust = SVX_ADJUST_RIGHT; goto ASK_ADJUST;
617 case SID_ATTR_PARA_ADJUST_CENTER: eAdjust = SVX_ADJUST_CENTER; goto ASK_ADJUST;
618 case SID_ATTR_PARA_ADJUST_BLOCK: eAdjust = SVX_ADJUST_BLOCK; goto ASK_ADJUST;
619 ASK_ADJUST:
621 if( !pAdjust )
622 aEditAttr.GetItemState( EE_PARA_JUST, sal_False, &pAdjust);
624 if( !pAdjust || IsInvalidItem( pAdjust ))
625 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
626 else
627 bFlag = eAdjust == ((SvxAdjustItem*)pAdjust)->GetAdjust();
629 break;
631 case SID_ATTR_PARA_LRSPACE:
633 SfxItemState eState = aEditAttr.GetItemState(EE_PARA_LRSPACE);
634 if( eState >= SFX_ITEM_DEFAULT )
636 SvxLRSpaceItem aLR = (const SvxLRSpaceItem&) aEditAttr.Get( EE_PARA_LRSPACE );
637 aLR.SetWhich(SID_ATTR_PARA_LRSPACE);
638 rSet.Put(aLR);
640 else
641 rSet.InvalidateItem(nSlotId);
642 nSlotId = 0;
644 break;
645 case SID_ATTR_PARA_LINESPACE:
647 SfxItemState eState = aEditAttr.GetItemState(EE_PARA_SBL);
648 if( eState >= SFX_ITEM_DEFAULT )
650 SvxLineSpacingItem aLR = (const SvxLineSpacingItem&) aEditAttr.Get( EE_PARA_SBL );
651 rSet.Put(aLR);
653 else
654 rSet.InvalidateItem(nSlotId);
655 nSlotId = 0;
657 break;
658 case SID_ATTR_PARA_ULSPACE:
660 SfxItemState eState = aEditAttr.GetItemState(EE_PARA_ULSPACE);
661 if( eState >= SFX_ITEM_DEFAULT )
663 SvxULSpaceItem aULSpace = (const SvxULSpaceItem&) aEditAttr.Get( EE_PARA_ULSPACE );
664 aULSpace.SetWhich(SID_ATTR_PARA_ULSPACE);
665 rSet.Put(aULSpace);
667 else
668 rSet.InvalidateItem(nSlotId);
669 Invalidate(SID_ATTR_PARA_ULSPACE);
670 nSlotId = 0;
672 break;
674 case SID_ATTR_PARA_LINESPACE_10: nLSpace = 100; goto ASK_LINESPACE;
675 case SID_ATTR_PARA_LINESPACE_15: nLSpace = 150; goto ASK_LINESPACE;
676 case SID_ATTR_PARA_LINESPACE_20: nLSpace = 200; goto ASK_LINESPACE;
677 ASK_LINESPACE:
679 if( !pLSpace )
680 aEditAttr.GetItemState( EE_PARA_SBL, sal_False, &pLSpace );
682 if( !pLSpace || IsInvalidItem( pLSpace ))
683 rSet.InvalidateItem( nSlotId ), nSlotId = 0;
684 else if( nLSpace == ((const SvxLineSpacingItem*)pLSpace)->
685 GetPropLineSpace() )
686 bFlag = sal_True;
687 else
688 nSlotId = 0;
690 break;
692 case FN_SET_SUPER_SCRIPT: nEsc = SVX_ESCAPEMENT_SUPERSCRIPT;
693 goto ASK_ESCAPE;
694 case FN_SET_SUB_SCRIPT: nEsc = SVX_ESCAPEMENT_SUBSCRIPT;
695 goto ASK_ESCAPE;
696 ASK_ESCAPE:
698 if( !pEscItem )
699 pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
701 if( nEsc == ((const SvxEscapementItem*)
702 pEscItem)->GetEnumValue() )
703 bFlag = sal_True;
704 else
705 nSlotId = 0;
707 break;
709 case SID_THESAURUS:
711 // disable "Thesaurus" if the language is not supported
712 const SfxPoolItem &rItem = GetShell().GetDoc()->GetDefault(
713 GetWhichOfScript( RES_CHRATR_LANGUAGE,
714 GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage())) );
715 LanguageType nLang = ((const SvxLanguageItem &) rItem).GetLanguage();
717 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
718 if (!xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag( nLang ).getLocale() ))
719 rSet.DisableItem( SID_THESAURUS );
720 nSlotId = 0;
722 break;
723 case SID_HANGUL_HANJA_CONVERSION:
724 case SID_CHINESE_CONVERSION:
726 if (!SvtCJKOptions().IsAnyEnabled())
728 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
729 rSet.DisableItem(nWhich);
731 else
732 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
734 break;
736 case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
737 case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
738 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
740 rSet.DisableItem( nSlotId );
741 nSlotId = 0;
743 else
745 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
746 if( pOutliner )
747 bFlag = pOutliner->IsVertical() ==
748 (SID_TEXTDIRECTION_TOP_TO_BOTTOM == nSlotId);
749 else
751 text::WritingMode eMode = (text::WritingMode)
752 ( (const SvxWritingModeItem&) aEditAttr.Get( SDRATTR_TEXTDIRECTION ) ).GetValue();
754 if( nSlotId == SID_TEXTDIRECTION_LEFT_TO_RIGHT )
756 bFlag = eMode == text::WritingMode_LR_TB;
758 else
760 bFlag = eMode != text::WritingMode_TB_RL;
764 break;
765 case SID_ATTR_PARA_LEFT_TO_RIGHT:
766 case SID_ATTR_PARA_RIGHT_TO_LEFT:
768 if ( !SvtLanguageOptions().IsCTLFontEnabled() )
770 rSet.DisableItem( nWhich );
771 nSlotId = 0;
773 else
775 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
776 if(pOutliner && pOutliner->IsVertical())
778 rSet.DisableItem( nWhich );
779 nSlotId = 0;
781 else
783 switch( ( ( (SvxFrameDirectionItem&) aEditAttr.Get( EE_PARA_WRITINGDIR ) ) ).GetValue() )
785 case FRMDIR_HORI_LEFT_TOP:
786 bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
787 break;
789 case FRMDIR_HORI_RIGHT_TOP:
790 bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
791 break;
796 break;
797 case SID_TRANSLITERATE_HALFWIDTH:
798 case SID_TRANSLITERATE_FULLWIDTH:
799 case SID_TRANSLITERATE_HIRAGANA:
800 case SID_TRANSLITERATE_KATAGANA:
802 SvtCJKOptions aCJKOptions;
803 if(!aCJKOptions.IsChangeCaseMapEnabled())
805 rSet.DisableItem(nWhich);
806 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_False );
808 else
809 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, sal_True );
811 break;
812 case SID_INSERT_RLM :
813 case SID_INSERT_LRM :
814 case SID_INSERT_ZWNBSP :
815 case SID_INSERT_ZWSP:
817 SvtCTLOptions aCTLOptions;
818 sal_Bool bEnabled = aCTLOptions.IsCTLFontEnabled();
819 GetView().GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
820 if(!bEnabled)
821 rSet.DisableItem(nWhich);
823 break;
824 default:
825 nSlotId = 0; // don't know this slot
826 break;
829 if( nSlotId )
830 rSet.Put( SfxBoolItem( nWhich, bFlag ));
832 nWhich = aIter.NextWhich();
836 void SwDrawTextShell::GetDrawTxtCtrlState(SfxItemSet& rSet)
838 if (!IsTextEdit()) // Otherwise crash!
839 return;
841 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
842 SfxItemSet aEditAttr(pOLV->GetAttribs());
844 SfxWhichIter aIter(rSet);
845 sal_uInt16 nWhich = aIter.FirstWhich();
846 sal_uInt16 nScriptType = pOLV->GetSelectedScriptType();
847 while(nWhich)
849 sal_uInt16 nEEWhich = 0;
850 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
851 switch( nSlotId )
853 case SID_ATTR_CHAR_FONT:
854 case SID_ATTR_CHAR_FONTHEIGHT:
855 case SID_ATTR_CHAR_WEIGHT:
856 case SID_ATTR_CHAR_POSTURE:
858 SfxItemPool* pEditPool = aEditAttr.GetPool()->GetSecondaryPool();
859 if( !pEditPool )
860 pEditPool = aEditAttr.GetPool();
861 SvxScriptSetItem aSetItem( nSlotId, *pEditPool );
862 aSetItem.GetItemSet().Put( aEditAttr, sal_False );
863 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
864 if( pI )
865 rSet.Put( *pI, nWhich );
866 else
867 rSet.InvalidateItem( nWhich );
869 break;
870 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
871 case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
872 case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
873 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
874 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW;break;
875 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
876 case SID_AUTOSPELL_CHECK:
878 const SfxPoolItem* pState = rView.GetSlotState(nWhich);
879 if (pState)
880 rSet.Put(SfxBoolItem(nWhich, ((const SfxBoolItem*)pState)->GetValue()));
881 else
882 rSet.DisableItem( nWhich );
883 break;
885 case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
886 case SID_ATTR_CHAR_RELIEF : nEEWhich = EE_CHAR_RELIEF; break;
887 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
888 case SID_ATTR_CHAR_KERNING : nEEWhich = EE_CHAR_KERNING; break;
889 case SID_ATTR_CHAR_SCALEWIDTH: nEEWhich = EE_CHAR_FONTWIDTH;break;
890 case SID_ATTR_CHAR_AUTOKERN : nEEWhich = EE_CHAR_PAIRKERNING; break;
891 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT; break;
893 if(nEEWhich)
894 rSet.Put(aEditAttr.Get(nEEWhich, sal_True), nWhich);
896 nWhich = aIter.NextWhich();
900 void SwDrawTextShell::ExecClpbrd(SfxRequest &rReq)
902 if (!IsTextEdit()) // Otherwise crash!
903 return;
905 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
907 ESelection aSel(pOLV->GetSelection());
908 const bool bCopy = (aSel.nStartPara != aSel.nEndPara) || (aSel.nStartPos != aSel.nEndPos);
909 sal_uInt16 nId = rReq.GetSlot();
910 switch( nId )
912 case SID_CUT:
913 if (bCopy)
914 pOLV->Cut();
915 return;
917 case SID_COPY:
918 if (bCopy)
919 pOLV->Copy();
920 return;
922 case SID_PASTE:
923 pOLV->PasteSpecial();
924 break;
926 default:
927 OSL_FAIL("wrong dispatcher");
928 return;
932 void SwDrawTextShell::StateClpbrd(SfxItemSet &rSet)
934 if (!IsTextEdit()) // Otherwise crash!
935 return;
937 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
938 ESelection aSel(pOLV->GetSelection());
939 const bool bCopy = (aSel.nStartPara != aSel.nEndPara) ||
940 (aSel.nStartPos != aSel.nEndPos);
943 SfxWhichIter aIter(rSet);
944 sal_uInt16 nWhich = aIter.FirstWhich();
946 while(nWhich)
948 switch(nWhich)
950 case SID_CUT:
951 case SID_COPY:
952 if( !bCopy )
953 rSet.DisableItem( nWhich );
954 break;
956 case SID_PASTE:
958 TransferableDataHelper aDataHelper(
959 TransferableDataHelper::CreateFromSystemClipboard(
960 &GetView().GetEditWin() ) );
962 if( !aDataHelper.GetXTransferable().is() ||
963 !SwTransferable::IsPaste( GetShell(), aDataHelper ))
964 rSet.DisableItem( SID_PASTE );
966 break;
968 case SID_PASTE_SPECIAL:
969 rSet.DisableItem( SID_PASTE_SPECIAL );
970 break;
971 // #151110#
972 case SID_CLIPBOARD_FORMAT_ITEMS:
973 rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS );
974 break;
976 nWhich = aIter.NextWhich();
980 // Hyperlink status
982 void SwDrawTextShell::StateInsert(SfxItemSet &rSet)
984 if (!IsTextEdit()) // Otherwise crash!
985 return;
987 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
988 SfxWhichIter aIter(rSet);
989 sal_uInt16 nWhich = aIter.FirstWhich();
991 while(nWhich)
993 switch(nWhich)
995 case SID_HYPERLINK_GETLINK:
997 SvxHyperlinkItem aHLinkItem;
998 aHLinkItem.SetInsertMode(HLINK_FIELD);
1000 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1002 if (pFieldItem)
1004 const SvxFieldData* pField = pFieldItem->GetField();
1006 if (pField->ISA(SvxURLField))
1008 aHLinkItem.SetName(((const SvxURLField*) pField)->GetRepresentation());
1009 aHLinkItem.SetURL(((const SvxURLField*) pField)->GetURL());
1010 aHLinkItem.SetTargetFrame(((const SvxURLField*) pField)->GetTargetFrame());
1013 else
1015 String sSel(pOLV->GetSelected());
1016 sSel.Erase(255);
1017 aHLinkItem.SetName(comphelper::string::stripEnd(sSel, ' '));
1020 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
1021 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
1022 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1024 rSet.Put(aHLinkItem);
1026 break;
1028 nWhich = aIter.NextWhich();
1032 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */