docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / sw / source / uibase / shells / annotsh.cxx
blob7e8430897fb62b09cb2d1d6abc039b6c7d2aca93
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 .
20 #include <hintids.hxx>
22 #include <com/sun/star/i18n/TextConversionOption.hpp>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/linguistic2/XThesaurus.hpp>
30 #include <i18nutil/transliteration.hxx>
31 #include <sfx2/namedcolor.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/request.hxx>
37 #include <editeng/colritem.hxx>
38 #include <editeng/editund2.hxx>
39 #include <editeng/eeitem.hxx>
40 #include <editeng/flstitem.hxx>
41 #include <editeng/spltitem.hxx>
42 #include <editeng/lrspitem.hxx>
43 #include <editeng/ulspitem.hxx>
44 #include <editeng/orphitem.hxx>
45 #include <editeng/formatbreakitem.hxx>
46 #include <editeng/widwitem.hxx>
47 #include <editeng/kernitem.hxx>
48 #include <editeng/escapementitem.hxx>
49 #include <editeng/lspcitem.hxx>
50 #include <editeng/adjustitem.hxx>
51 #include <editeng/hyphenzoneitem.hxx>
52 #include <editeng/udlnitem.hxx>
53 #include <editeng/fontitem.hxx>
54 #include <svx/clipfmtitem.hxx>
55 #include <svl/stritem.hxx>
56 #include <svl/slstitm.hxx>
57 #include <editeng/frmdiritem.hxx>
58 #include <svl/whiter.hxx>
59 #include <svl/cjkoptions.hxx>
60 #include <svl/ctloptions.hxx>
61 #include <unotools/useroptions.hxx>
62 #include <editeng/flditem.hxx>
63 #include <svx/hlnkitem.hxx>
64 #include <sfx2/htmlmode.hxx>
65 #include <editeng/langitem.hxx>
66 #include <editeng/scripttypeitem.hxx>
67 #include <swundo.hxx>
68 #include <doc.hxx>
69 #include <viewopt.hxx>
70 #include <wrtsh.hxx>
71 #include <chrdlgmodes.hxx>
72 #include <edtwin.hxx>
73 #include <SwRewriter.hxx>
75 #include <cmdid.h>
76 #include <strings.hrc>
77 #include <breakit.hxx>
78 #include <annotsh.hxx>
79 #include <view.hxx>
80 #include <PostItMgr.hxx>
81 #include <AnnotationWin.hxx>
83 #include <swtypes.hxx>
85 #include <svx/svxdlg.hxx>
87 #include <vcl/EnumContext.hxx>
88 #include <svl/itempool.hxx>
89 #include <editeng/outliner.hxx>
90 #include <editeng/editview.hxx>
91 #include <osl/diagnose.h>
93 #include <svl/languageoptions.hxx>
95 #include <svl/undo.hxx>
96 #include <swabstdlg.hxx>
98 #include <comphelper/string.hxx>
99 #include <comphelper/propertysequence.hxx>
100 #include <cppuhelper/bootstrap.hxx>
102 #include <langhelper.hxx>
104 #include <memory>
106 using namespace ::com::sun::star;
107 using namespace ::com::sun::star::uno;
108 using namespace ::com::sun::star::beans;
109 using namespace ::com::sun::star::i18n;
111 #define ShellClass_SwAnnotationShell
113 #include <sfx2/msg.hxx>
114 #include <swslots.hxx>
116 SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell)
118 void SwAnnotationShell::InitInterface_Impl()
120 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
122 GetStaticInterface()->RegisterPopupMenu(u"annotation"_ustr);
126 SfxItemPool* SwAnnotationShell::GetAnnotationPool(SwView const & rV)
128 SwWrtShell &rSh = rV.GetWrtShell();
129 return rSh.GetAttrPool().GetSecondaryPool();
132 SwAnnotationShell::SwAnnotationShell( SwView& r )
133 : m_rView(r)
135 SetPool(SwAnnotationShell::GetAnnotationPool(m_rView));
136 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Annotation));
139 SwAnnotationShell::~SwAnnotationShell()
141 if (m_rView.GetWrtShell().CanInsert())
142 m_rView.ShowCursor(true);
145 SfxUndoManager* SwAnnotationShell::GetUndoManager()
147 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
148 if ( !pPostItMgr ||
149 !pPostItMgr->HasActiveSidebarWin() )
151 OSL_ENSURE(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
152 return nullptr;
154 return &pPostItMgr->GetActiveSidebarWin()->GetOutlinerView()->GetOutliner()->GetUndoManager();
157 void SwAnnotationShell::Exec( SfxRequest &rReq )
159 //TODO: clean this up!!!!
160 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
161 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
162 return;
164 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
165 SfxItemSet aEditAttr(pOLV->GetAttribs());
166 SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
168 const sal_uInt16 nSlot = rReq.GetSlot();
169 const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID(nSlot);
170 const SfxItemSet *pNewAttrs = rReq.GetArgs();
171 sal_uInt16 nEEWhich = 0;
172 switch (nSlot)
174 case SID_PARASPACE_INCREASE:
175 case SID_PARASPACE_DECREASE:
177 SvxULSpaceItem aULSpace( aEditAttr.Get( EE_PARA_ULSPACE ) );
178 sal_uInt16 nUpper = aULSpace.GetUpper();
179 sal_uInt16 nLower = aULSpace.GetLower();
181 if ( nSlot == SID_PARASPACE_INCREASE )
183 nUpper = std::min< sal_uInt16 >( nUpper + 57, 5670 );
184 nLower = std::min< sal_uInt16 >( nLower + 57, 5670 );
186 else
188 nUpper = std::max< sal_Int16 >( nUpper - 57, 0 );
189 nLower = std::max< sal_Int16 >( nLower - 57, 0 );
192 aULSpace.SetUpper( nUpper );
193 aULSpace.SetLower( nLower );
194 aNewAttr.Put( aULSpace );
195 rReq.Done();
197 break;
198 case SID_ATTR_PARA_LRSPACE:
200 SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(rReq.
201 GetArgs()->Get(nSlot)));
202 aParaMargin.SetWhich( EE_PARA_LRSPACE );
204 aNewAttr.Put(aParaMargin);
205 rReq.Done();
206 break;
208 case SID_ATTR_PARA_LINESPACE:
210 SvxLineSpacingItem aParaMargin = static_cast<const SvxLineSpacingItem&>(pNewAttrs->Get(
211 GetPool().GetWhichIDFromSlotID(nSlot)));
212 aParaMargin.SetWhich( EE_PARA_SBL );
214 aNewAttr.Put(aParaMargin);
215 rReq.Done();
216 break;
218 case SID_ATTR_PARA_ULSPACE:
220 SvxULSpaceItem aULSpace = static_cast<const SvxULSpaceItem&>(pNewAttrs->Get(
221 GetPool().GetWhichIDFromSlotID(nSlot)));
222 aULSpace.SetWhich( EE_PARA_ULSPACE );
223 aNewAttr.Put( aULSpace );
224 rReq.Done();
226 break;
227 case FN_GROW_FONT_SIZE:
228 case FN_SHRINK_FONT_SIZE:
230 const SfxObjectShell* pObjSh = SfxObjectShell::Current();
231 const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>
232 (pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : nullptr);
233 const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
234 pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, pFontList );
236 break;
238 case SID_ATTR_CHAR_FONT:
239 case SID_ATTR_CHAR_FONTHEIGHT:
240 case SID_ATTR_CHAR_WEIGHT:
241 case SID_ATTR_CHAR_POSTURE:
243 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
244 if( !pSecondPool )
245 pSecondPool = aEditAttr.GetPool();
246 SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
247 aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
248 aNewAttr.Put( aSetItem.GetItemSet() );
249 rReq.Done();
250 break;
252 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
254 case SID_ATTR_CHAR_COLOR2:
256 if (!rReq.GetArgs())
258 const std::optional<NamedColor> oColor
259 = m_rView.GetDocShell()->GetRecentColor(SID_ATTR_CHAR_COLOR);
260 if (oColor.has_value())
262 nEEWhich = GetPool().GetWhichIDFromSlotID(SID_ATTR_CHAR_COLOR);
263 const model::ComplexColor aCol = (*oColor).getComplexColor();
264 aNewAttr.Put(SvxColorItem(aCol.getFinalColor(), aCol, nEEWhich));
265 rReq.SetArgs(aNewAttr);
266 rReq.SetSlot(SID_ATTR_CHAR_COLOR);
269 break;
271 case SID_ATTR_CHAR_BACK_COLOR:
273 nEEWhich = GetPool().GetWhichIDFromSlotID(nSlot);
274 if (!rReq.GetArgs())
276 const std::optional<NamedColor> oColor
277 = m_rView.GetDocShell()->GetRecentColor(nSlot);
278 if (oColor.has_value())
280 const model::ComplexColor aCol = (*oColor).getComplexColor();
281 aNewAttr.Put(SvxColorItem(aCol.getFinalColor(), aCol, nEEWhich));
284 break;
286 case SID_ATTR_CHAR_UNDERLINE:
288 if( rReq.GetArgs() )
290 const SvxUnderlineItem* pItem = rReq.GetArg<SvxUnderlineItem>(SID_ATTR_CHAR_UNDERLINE);
291 if (pItem)
293 aNewAttr.Put(*pItem);
295 else
297 FontLineStyle eFU = aEditAttr.Get( EE_CHAR_UNDERLINE ).GetLineStyle();
298 aNewAttr.Put( SvxUnderlineItem( eFU != LINESTYLE_NONE ?LINESTYLE_NONE : LINESTYLE_SINGLE, EE_CHAR_UNDERLINE ) );
301 break;
303 case SID_ATTR_CHAR_OVERLINE:
305 FontLineStyle eFO = aEditAttr.Get(EE_CHAR_OVERLINE).GetLineStyle();
306 aNewAttr.Put(SvxOverlineItem(eFO == LINESTYLE_SINGLE ? LINESTYLE_NONE : LINESTYLE_SINGLE, EE_CHAR_OVERLINE));
307 break;
309 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
310 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW; break;
311 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT; break;
312 case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
313 case SID_ATTR_CHAR_RELIEF : nEEWhich = EE_CHAR_RELIEF; break;
314 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
315 case SID_ATTR_CHAR_KERNING : nEEWhich = EE_CHAR_KERNING; break;
316 case SID_ATTR_CHAR_SCALEWIDTH: nEEWhich = EE_CHAR_FONTWIDTH; break;
317 case SID_ATTR_CHAR_AUTOKERN : nEEWhich = EE_CHAR_PAIRKERNING; break;
318 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT; break;
319 case SID_ATTR_PARA_ADJUST_LEFT:
320 aNewAttr.Put(SvxAdjustItem(SvxAdjust::Left, EE_PARA_JUST));
321 break;
322 case SID_ATTR_PARA_ADJUST_CENTER:
323 aNewAttr.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST));
324 break;
325 case SID_ATTR_PARA_ADJUST_RIGHT:
326 aNewAttr.Put(SvxAdjustItem(SvxAdjust::Right, EE_PARA_JUST));
327 break;
328 case SID_ATTR_PARA_ADJUST_BLOCK:
329 aNewAttr.Put(SvxAdjustItem(SvxAdjust::Block, EE_PARA_JUST));
330 break;
332 case SID_ATTR_PARA_LINESPACE_10:
334 SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
335 aItem.SetPropLineSpace(100);
336 aNewAttr.Put(aItem);
338 break;
339 case SID_ATTR_PARA_LINESPACE_115:
341 SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
342 aItem.SetPropLineSpace(115);
343 aNewAttr.Put(aItem);
345 break;
346 case SID_ATTR_PARA_LINESPACE_15:
348 SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
349 aItem.SetPropLineSpace(150);
350 aNewAttr.Put(aItem);
352 break;
353 case SID_ATTR_PARA_LINESPACE_20:
355 SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
356 aItem.SetPropLineSpace(200);
357 aNewAttr.Put(aItem);
359 break;
360 case SID_SELECTALL:
362 Outliner * pOutliner = pOLV->GetOutliner();
363 if(pOutliner)
365 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
366 if (nParaCount > 0)
367 pOLV->SelectRange(0, nParaCount );
369 break;
371 case FN_FORMAT_RESET:
373 pPostItMgr->GetActiveSidebarWin()->ResetAttributes();
374 rReq.Done();
375 break;
377 case FN_SET_SUPER_SCRIPT:
379 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
380 SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
382 if( eEsc == SvxEscapement::Superscript )
383 aItem.SetEscapement( SvxEscapement::Off );
384 else
385 aItem.SetEscapement( SvxEscapement::Superscript );
386 aNewAttr.Put( aItem );
388 break;
389 case FN_SET_SUB_SCRIPT:
391 SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
392 SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
394 if( eEsc == SvxEscapement::Subscript )
395 aItem.SetEscapement( SvxEscapement::Off );
396 else
397 aItem.SetEscapement( SvxEscapement::Subscript );
398 aNewAttr.Put( aItem );
400 break;
401 case SID_HYPERLINK_SETLINK:
403 const SfxPoolItem* pItem = nullptr;
404 if(pNewAttrs)
405 pNewAttrs->GetItemState(nSlot, false, &pItem);
407 if(pItem)
409 const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
410 SvxURLField aField(rHLinkItem.GetURL(), rHLinkItem.GetName(), SvxURLFormat::AppDefault);
411 aField.SetTargetFrame(rHLinkItem.GetTargetFrame());
413 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
415 if (pFieldItem && dynamic_cast<const SvxURLField *>(pFieldItem->GetField()) != nullptr)
417 // Select the field so that it will be deleted during insert
418 ESelection aSel = pOLV->GetSelection();
419 aSel.end.nIndex++;
420 pOLV->SetSelection(aSel);
422 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
423 pOLV->InsertField(SvxFieldItem(aField, EE_FEATURE_FIELD));
425 break;
427 case FN_INSERT_SOFT_HYPHEN:
428 case FN_INSERT_HARDHYPHEN:
429 case FN_INSERT_HARD_SPACE:
430 case FN_INSERT_NNBSP:
431 case SID_INSERT_RLM :
432 case SID_INSERT_LRM :
433 case SID_INSERT_WJ :
434 case SID_INSERT_ZWSP:
436 sal_Unicode cIns = 0;
437 switch(rReq.GetSlot())
439 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
440 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
441 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
442 case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
443 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
444 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
445 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
446 case SID_INSERT_WJ: cIns = CHAR_WJ; break;
448 pOLV->InsertText( OUString(cIns));
449 rReq.Done();
450 break;
452 case SID_CHARMAP:
454 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
455 InsertSymbol(rReq);
456 break;
458 case FN_INSERT_STRING:
460 const SfxPoolItem* pItem = nullptr;
461 if (pNewAttrs)
462 pNewAttrs->GetItemState(nSlot, false, &pItem );
463 if (pItem && pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
464 pOLV->InsertText(static_cast<const SfxStringItem *>(pItem)->GetValue());
465 break;
467 case FN_FORMAT_FOOTNOTE_DLG:
469 m_rView.ExecFormatFootnote();
470 break;
472 case FN_NUMBERING_OUTLINE_DLG:
474 m_rView.ExecNumberingOutline(GetPool());
475 rReq.Done();
477 break;
478 case SID_OPEN_XML_FILTERSETTINGS:
480 HandleOpenXmlFilterSettings(rReq);
482 break;
483 case FN_WORDCOUNT_DIALOG:
485 m_rView.UpdateWordCount(this, nSlot);
486 break;
488 case SID_CHAR_DLG_EFFECT:
489 case SID_CHAR_DLG_POSITION:
490 case SID_CHAR_DLG:
492 const SfxItemSet* pArgs = rReq.GetArgs();
493 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
495 if( !pArgs || pItem )
497 /* mod
498 SwView* pView = &GetView();
499 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) != nullptr );
500 SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
502 SfxItemSet aDlgAttr(SfxItemSet::makeFixedSfxItemSet<XATTR_FILLSTYLE, XATTR_FILLCOLOR, EE_ITEMS_START, EE_ITEMS_END>(GetPool()));
504 // util::Language does not exist in the EditEngine! Therefore not included in the set.
506 aDlgAttr.Put( aEditAttr );
507 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
509 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
510 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwCharDlg(m_rView.GetFrameWeld(), m_rView, aDlgAttr, SwCharDlgMode::Ann));
511 if (nSlot == SID_CHAR_DLG_EFFECT)
513 pDlg->SetCurPageId(u"fonteffects"_ustr);
515 if (nSlot == SID_CHAR_DLG_POSITION)
517 pDlg->SetCurPageId(u"position"_ustr);
519 else if (pItem)
521 pDlg->SetCurPageId(pItem->GetValue());
524 auto xRequest = std::make_shared<SfxRequest>(rReq);
525 rReq.Ignore(); // the 'old' request is not relevant any more
526 pDlg->StartExecuteAsync(
527 [this, pDlg, xRequest=std::move(xRequest), nEEWhich, aNewAttr2=aNewAttr, pOLV] (sal_Int32 nResult) mutable ->void
529 if (nResult == RET_OK)
531 xRequest->Done( *( pDlg->GetOutputItemSet() ) );
532 aNewAttr2.Put(*pDlg->GetOutputItemSet());
533 ExecPost(*xRequest, nEEWhich, aNewAttr2, pOLV);
535 pDlg->disposeOnce();
538 return;
540 else
541 aNewAttr.Put(*pArgs);
542 break;
544 case SID_PARA_DLG:
546 const SfxItemSet* pArgs = rReq.GetArgs();
548 if (!pArgs)
550 /* mod todo ???
551 SwView* pView = &GetView();
552 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) != nullptr );
553 SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
555 SfxItemSet aDlgAttr(SfxItemSet::makeFixedSfxItemSet<
556 EE_ITEMS_START, EE_ITEMS_END,
557 SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_WIDOWS>(GetPool()));
559 aDlgAttr.Put(aEditAttr);
561 aDlgAttr.Put( SvxHyphenZoneItem( false, RES_PARATR_HYPHENZONE) );
562 aDlgAttr.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
563 aDlgAttr.Put( SvxFormatSplitItem( true, RES_PARATR_SPLIT ) );
564 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
565 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
567 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
568 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwParaDlg(m_rView.GetFrameWeld(), m_rView, aDlgAttr, true));
569 sal_uInt16 nRet = pDlg->Execute();
570 if(RET_OK == nRet)
572 rReq.Done( *( pDlg->GetOutputItemSet() ) );
573 aNewAttr.Put(*pDlg->GetOutputItemSet());
575 if(RET_OK != nRet)
576 return;
578 else
579 aNewAttr.Put(*pArgs);
580 break;
583 case SID_AUTOSPELL_CHECK:
585 m_rView.ExecuteSlot(rReq);
586 break;
588 case SID_ATTR_PARA_LEFT_TO_RIGHT:
589 case SID_ATTR_PARA_RIGHT_TO_LEFT:
591 bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
593 const SfxPoolItem* pPoolItem;
594 if( pNewAttrs && SfxItemState::SET == pNewAttrs->GetItemState( nSlot, true, &pPoolItem ) )
596 if( !static_cast<const SfxBoolItem*>(pPoolItem)->GetValue() )
597 bLeftToRight = !bLeftToRight;
599 SfxItemSet aAttr(SfxItemSet::makeFixedSfxItemSet<
600 EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
601 EE_PARA_JUST, EE_PARA_JUST>(*aNewAttr.GetPool()));
603 SvxAdjust nAdjust = SvxAdjust::Left;
604 if( const SvxAdjustItem* pAdjustItem = aEditAttr.GetItemIfSet(EE_PARA_JUST ) )
605 nAdjust = pAdjustItem->GetAdjust();
607 if( bLeftToRight )
609 aAttr.Put( SvxFrameDirectionItem( SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ) );
610 if( nAdjust == SvxAdjust::Right )
611 aAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
613 else
615 aAttr.Put( SvxFrameDirectionItem( SvxFrameDirection::Horizontal_RL_TB, EE_PARA_WRITINGDIR ) );
616 if( nAdjust == SvxAdjust::Left )
617 aAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
619 pOLV->SetAttribs(aAttr);
620 break;
624 ExecPost(rReq, nEEWhich, aNewAttr, pOLV );
627 void SwAnnotationShell::ExecPost( SfxRequest& rReq, sal_uInt16 nEEWhich, SfxItemSet& rNewAttr, OutlinerView* pOLV )
629 const SfxItemSet *pNewAttrs = rReq.GetArgs();
630 const sal_uInt16 nSlot = rReq.GetSlot();
631 const sal_uInt16 nWhich = GetPool().GetWhichIDFromSlotID(nSlot);
633 if(nEEWhich && pNewAttrs)
635 rNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
637 else if (nEEWhich == EE_CHAR_COLOR)
639 m_rView.GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_EFFECT);
641 else if (nEEWhich == EE_CHAR_KERNING)
643 m_rView.GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_POSITION);
647 tools::Rectangle aOutRect = pOLV->GetOutputArea();
648 if (tools::Rectangle() != aOutRect && rNewAttr.Count())
649 pOLV->SetAttribs(rNewAttr);
651 m_rView.GetViewFrame().GetBindings().InvalidateAll(false);
652 if ( pOLV->GetOutliner()->IsModified() )
653 m_rView.GetWrtShell().SetModified();
656 void SwAnnotationShell::GetState(SfxItemSet& rSet)
658 //TODO: clean this up!!!
659 // FN_SET_SUPER_SCRIPT
660 //SID_ATTR_PARA_ADJUST
661 //SID_ATTR_PARA_ADJUST_BLOCK
663 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
664 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
665 return;
667 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
668 SfxItemSet aEditAttr(pOLV->GetAttribs());
670 SfxWhichIter aIter(rSet);
671 sal_uInt16 nWhich = aIter.FirstWhich();
672 while(nWhich)
674 sal_uInt16 nEEWhich = 0;
675 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
676 switch( nSlotId )
678 case SID_ATTR_PARA_LRSPACE:
679 case SID_ATTR_PARA_LEFTSPACE:
680 case SID_ATTR_PARA_RIGHTSPACE:
681 case SID_ATTR_PARA_FIRSTLINESPACE:
683 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_LRSPACE );
684 if( eState >= SfxItemState::DEFAULT )
686 SvxLRSpaceItem aLR = aEditAttr.Get( EE_PARA_LRSPACE );
687 aLR.SetWhich(nSlotId);
688 rSet.Put(aLR);
690 else
691 rSet.InvalidateItem(nSlotId);
693 break;
694 case SID_ATTR_PARA_LINESPACE:
696 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_SBL );
697 if( eState >= SfxItemState::DEFAULT )
699 const SvxLineSpacingItem& aLR = aEditAttr.Get( EE_PARA_SBL );
700 rSet.Put(aLR);
702 else
703 rSet.InvalidateItem(nSlotId);
705 break;
706 case SID_ATTR_PARA_ULSPACE:
707 case SID_ATTR_PARA_ABOVESPACE:
708 case SID_ATTR_PARA_BELOWSPACE:
709 case SID_PARASPACE_INCREASE:
710 case SID_PARASPACE_DECREASE:
712 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_ULSPACE );
713 if( eState >= SfxItemState::DEFAULT )
715 SvxULSpaceItem aULSpace = aEditAttr.Get( EE_PARA_ULSPACE );
716 if ( !aULSpace.GetUpper() && !aULSpace.GetLower() )
717 rSet.DisableItem( SID_PARASPACE_DECREASE );
718 else if ( aULSpace.GetUpper() >= 5670 && aULSpace.GetLower() >= 5670 )
719 rSet.DisableItem( SID_PARASPACE_INCREASE );
720 if ( nSlotId == SID_ATTR_PARA_ULSPACE
721 || nSlotId == SID_ATTR_PARA_BELOWSPACE
722 || nSlotId == SID_ATTR_PARA_ABOVESPACE
725 aULSpace.SetWhich(nSlotId);
726 rSet.Put(aULSpace);
729 else
731 rSet.DisableItem( SID_PARASPACE_INCREASE );
732 rSet.DisableItem( SID_PARASPACE_DECREASE );
733 rSet.InvalidateItem( SID_ATTR_PARA_ULSPACE );
734 rSet.InvalidateItem( SID_ATTR_PARA_ABOVESPACE );
735 rSet.InvalidateItem( SID_ATTR_PARA_BELOWSPACE );
738 break;
739 case SID_ATTR_CHAR_FONT:
740 case SID_ATTR_CHAR_FONTHEIGHT:
741 case SID_ATTR_CHAR_WEIGHT:
742 case SID_ATTR_CHAR_POSTURE:
744 SvtScriptType nScriptType = pOLV->GetSelectedScriptType();
745 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
746 if( !pSecondPool )
747 pSecondPool = aEditAttr.GetPool();
748 SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
749 aSetItem.GetItemSet().Put( aEditAttr, false );
750 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
751 if( pI )
753 rSet.Put(pI->CloneSetWhich(nWhich));
755 else
756 rSet.InvalidateItem( nWhich );
758 break;
759 case SID_ATTR_CHAR_COLOR2:
760 case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
761 case SID_ATTR_CHAR_BACK_COLOR: nEEWhich = EE_CHAR_BKGCOLOR; break;
762 case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
763 case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
764 case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
765 case SID_ATTR_CHAR_SHADOWED: nEEWhich = EE_CHAR_SHADOW;break;
766 case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
767 case SID_ATTR_CHAR_LANGUAGE : nEEWhich = EE_CHAR_LANGUAGE;break;
768 case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT;break;
769 case SID_ATTR_CHAR_KERNING: nEEWhich = EE_CHAR_KERNING;break;
770 case FN_SET_SUPER_SCRIPT:
771 case FN_SET_SUB_SCRIPT:
773 SvxEscapement nEsc;
774 if (nWhich==FN_SET_SUPER_SCRIPT)
775 nEsc = SvxEscapement::Superscript;
776 else
777 nEsc = SvxEscapement::Subscript;
779 const SfxPoolItem *pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
780 if( nEsc == static_cast<const SvxEscapementItem*>(pEscItem)->GetEscapement() )
781 rSet.Put( SfxBoolItem( nWhich, true ));
782 else
783 rSet.InvalidateItem( nWhich );
784 break;
786 case SID_ATTR_PARA_ADJUST_LEFT:
787 case SID_ATTR_PARA_ADJUST_RIGHT:
788 case SID_ATTR_PARA_ADJUST_CENTER:
789 case SID_ATTR_PARA_ADJUST_BLOCK:
791 SvxAdjust eAdjust = SvxAdjust::Left;
792 if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
793 eAdjust = SvxAdjust::Left;
794 else if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
795 eAdjust = SvxAdjust::Right;
796 else if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
797 eAdjust = SvxAdjust::Center;
798 else if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
799 eAdjust = SvxAdjust::Block;
801 const SvxAdjustItem *pAdjust = aEditAttr.GetItemIfSet( EE_PARA_JUST, false );
803 if( !pAdjust || IsInvalidItem( pAdjust ))
805 rSet.InvalidateItem( nSlotId );
807 else
809 if ( eAdjust == pAdjust->GetAdjust())
810 rSet.Put( SfxBoolItem( nWhich, true ));
811 else
812 rSet.InvalidateItem( nWhich );
814 break;
816 case SID_ATTR_PARA_LINESPACE_10:
817 case SID_ATTR_PARA_LINESPACE_115:
818 case SID_ATTR_PARA_LINESPACE_15:
819 case SID_ATTR_PARA_LINESPACE_20:
821 int nLSpace = 0;
822 if (nWhich==SID_ATTR_PARA_LINESPACE_10)
823 nLSpace = 100;
824 else if (nWhich==SID_ATTR_PARA_LINESPACE_115)
825 nLSpace = 115;
826 else if (nWhich==SID_ATTR_PARA_LINESPACE_15)
827 nLSpace = 150;
828 else if (nWhich==SID_ATTR_PARA_LINESPACE_20)
829 nLSpace = 200;
831 const SvxLineSpacingItem *pLSpace = aEditAttr.GetItemIfSet( EE_PARA_SBL, false );
833 if( !pLSpace || IsInvalidItem( pLSpace ))
835 rSet.InvalidateItem( nSlotId );
837 else
839 if( nLSpace == pLSpace->GetPropLineSpace() )
840 rSet.Put( SfxBoolItem( nWhich, true ));
841 else
843 // tdf#114631 - disable non selected line spacing
844 rSet.Put(SfxBoolItem(nWhich, false));
847 break;
849 case SID_AUTOSPELL_CHECK:
851 const SfxPoolItemHolder aResult(m_rView.GetSlotState(nWhich));
852 if (aResult)
853 rSet.Put(SfxBoolItem(nWhich, static_cast<const SfxBoolItem*>(aResult.getItem())->GetValue()));
854 else
855 rSet.DisableItem( nWhich );
856 break;
858 case SID_ATTR_PARA_LEFT_TO_RIGHT:
859 case SID_ATTR_PARA_RIGHT_TO_LEFT:
861 if ( !SvtCTLOptions::IsCTLFontEnabled() )
862 rSet.DisableItem( nWhich );
863 else
865 if(pOLV->GetOutliner() && pOLV->GetOutliner()->IsVertical())
866 rSet.DisableItem( nWhich );
867 else
869 bool bFlag = false;
870 switch( aEditAttr.Get( EE_PARA_WRITINGDIR ).GetValue() )
872 case SvxFrameDirection::Horizontal_LR_TB:
874 bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
875 rSet.Put( SfxBoolItem( nWhich, bFlag ));
876 break;
878 case SvxFrameDirection::Horizontal_RL_TB:
880 bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
881 rSet.Put( SfxBoolItem( nWhich, bFlag ));
882 break;
884 default:
885 break;
890 break;
891 case SID_INSERT_RLM :
892 case SID_INSERT_LRM :
894 bool bEnabled = SvtCTLOptions::IsCTLFontEnabled();
895 m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, bEnabled );
896 if(!bEnabled)
897 rSet.DisableItem(nWhich);
899 break;
900 default:
901 rSet.InvalidateItem( nWhich );
902 break;
905 if(nEEWhich)
907 rSet.Put(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
908 if(nEEWhich == EE_CHAR_KERNING)
910 SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING );
911 if ( eState == SfxItemState::INVALID )
913 rSet.InvalidateItem(EE_CHAR_KERNING);
918 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
919 rSet.DisableItem( nWhich );
921 nWhich = aIter.NextWhich();
925 void SwAnnotationShell::ExecSearch(SfxRequest& rReq)
927 m_rView.ExecSearch(rReq);
930 void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
932 m_rView.StateSearch(rSet);
935 void SwAnnotationShell::ExecClpbrd(SfxRequest const &rReq)
937 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
938 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
939 return;
941 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
943 tools::Long aOldHeight = pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight();
944 sal_uInt16 nSlot = rReq.GetSlot();
945 switch (nSlot)
947 case SID_CUT:
948 if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
949 pOLV->Cut();
950 break;
951 case SID_COPY:
952 if( pOLV->HasSelection() )
953 pOLV->Copy();
954 break;
955 case SID_PASTE:
956 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
957 pOLV->PasteSpecial();
958 break;
959 case SID_PASTE_UNFORMATTED:
960 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
961 pOLV->Paste();
962 break;
963 case SID_PASTE_SPECIAL:
965 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
967 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
968 ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(m_rView.GetEditWin().GetFrameWeld()));
970 pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
971 pDlg->Insert( SotClipboardFormatId::RTF, OUString() );
972 pDlg->Insert( SotClipboardFormatId::RICHTEXT, OUString() );
974 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &m_rView.GetEditWin() ) );
976 SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
978 if (nFormat != SotClipboardFormatId::NONE)
980 if (nFormat == SotClipboardFormatId::STRING)
981 pOLV->Paste();
982 else
983 pOLV->PasteSpecial();
986 break;
988 case SID_CLIPBOARD_FORMAT_ITEMS:
990 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
991 const SfxPoolItem* pItem;
992 if (rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
994 if (const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item *>(pItem))
995 nFormat = static_cast<SotClipboardFormatId>(pUInt32Item->GetValue());
998 if ( nFormat != SotClipboardFormatId::NONE )
1000 if (SotClipboardFormatId::STRING == nFormat)
1001 pOLV->Paste();
1002 else
1003 pOLV->PasteSpecial();
1005 break;
1008 pPostItMgr->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight,pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
1011 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
1013 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1014 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1015 return;
1016 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1018 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &m_rView.GetEditWin() ) );
1019 bool bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF )
1020 || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ));
1021 bPastePossible = bPastePossible && (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED);
1023 SfxWhichIter aIter(rSet);
1024 sal_uInt16 nWhich = aIter.FirstWhich();
1026 while(nWhich)
1028 switch(nWhich)
1030 case SID_CUT:
1032 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus() == SwPostItHelper::DELETED)
1033 rSet.DisableItem( nWhich );
1034 [[fallthrough]];
1036 case SID_COPY:
1038 SfxObjectShell* pObjectShell = GetObjectShell();
1039 if (!pOLV->HasSelection() || (pObjectShell && pObjectShell->isContentExtractionLocked()) )
1040 rSet.DisableItem( nWhich );
1041 break;
1043 case SID_PASTE:
1044 case SID_PASTE_UNFORMATTED:
1045 case SID_PASTE_SPECIAL:
1047 if( !bPastePossible )
1048 rSet.DisableItem( nWhich );
1049 break;
1051 case SID_CLIPBOARD_FORMAT_ITEMS:
1053 if ( bPastePossible )
1055 SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1056 if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
1057 aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
1058 if ( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) )
1059 aFormats.AddClipbrdFormat( SotClipboardFormatId::RICHTEXT );
1060 aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
1061 rSet.Put( aFormats );
1063 else
1064 rSet.DisableItem( nWhich );
1065 break;
1068 nWhich = aIter.NextWhich();
1072 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
1074 SfxWhichIter aIter( rSet );
1075 sal_uInt16 nWhich = aIter.FirstWhich();
1077 while( nWhich )
1079 switch( nWhich )
1081 case FN_STAT_SELMODE:
1083 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1084 rSet.DisableItem( nWhich );
1085 break;
1087 case FN_STAT_TEMPLATE:
1089 rSet.DisableItem( nWhich );
1090 break;
1093 nWhich = aIter.NextWhich();
1097 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
1099 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1100 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1101 return;
1103 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1104 SfxWhichIter aIter(rSet);
1105 sal_uInt16 nWhich = aIter.FirstWhich();
1107 while(nWhich)
1109 switch(nWhich)
1111 case SID_HYPERLINK_GETLINK:
1113 SvxHyperlinkItem aHLinkItem;
1114 aHLinkItem.SetInsertMode(HLINK_FIELD);
1116 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1118 if (pFieldItem)
1120 if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField *>(pFieldItem->GetField()))
1122 aHLinkItem.SetName(pURLField->GetRepresentation());
1123 aHLinkItem.SetURL(pURLField->GetURL());
1124 aHLinkItem.SetTargetFrame(pURLField->GetTargetFrame());
1127 else
1129 OUString sSel(pOLV->GetSelected());
1130 sSel = sSel.copy(0, std::min<sal_Int32>(255, sSel.getLength()));
1131 aHLinkItem.SetName(comphelper::string::stripEnd(sSel, ' '));
1134 sal_uInt16 nHtmlMode = ::GetHtmlMode(m_rView.GetDocShell());
1135 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
1136 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1138 rSet.Put(aHLinkItem);
1140 break;
1143 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1144 rSet.DisableItem( nWhich );
1146 nWhich = aIter.NextWhich();
1150 void SwAnnotationShell::NoteExec(SfxRequest const &rReq)
1152 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1153 if ( !pPostItMgr )
1154 return;
1156 sal_uInt16 nSlot = rReq.GetSlot();
1157 switch (nSlot)
1159 case FN_REPLY:
1160 case FN_POSTIT:
1161 case FN_DELETE_COMMENT:
1162 case FN_DELETE_COMMENT_THREAD:
1163 case FN_RESOLVE_NOTE:
1164 case FN_RESOLVE_NOTE_THREAD:
1165 case FN_PROMOTE_COMMENT:
1166 if ( pPostItMgr->HasActiveSidebarWin() )
1167 pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot);
1168 break;
1169 case FN_DELETE_ALL_NOTES:
1170 pPostItMgr->Delete();
1171 break;
1172 case FN_FORMAT_ALL_NOTES:
1173 pPostItMgr->ExecuteFormatAllDialog(m_rView);
1174 break;
1175 case FN_DELETE_NOTE_AUTHOR:
1177 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1178 if ( pItem )
1179 pPostItMgr->Delete( pItem->GetValue() );
1180 else if ( pPostItMgr->HasActiveSidebarWin() )
1181 pPostItMgr->Delete( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1182 break;
1184 case FN_HIDE_NOTE:
1185 break;
1186 case FN_HIDE_ALL_NOTES:
1187 pPostItMgr->Hide();
1188 break;
1189 case FN_HIDE_NOTE_AUTHOR:
1191 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1192 if ( pItem )
1193 pPostItMgr->Hide( pItem->GetValue() );
1194 else if ( pPostItMgr->HasActiveSidebarWin() )
1195 pPostItMgr->Hide( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1200 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1202 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1203 SfxWhichIter aIter(rSet);
1204 sal_uInt16 nWhich = aIter.FirstWhich();
1205 while(nWhich)
1207 sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
1208 switch( nSlotId )
1210 case FN_POSTIT:
1211 case FN_DELETE_ALL_NOTES:
1212 case FN_FORMAT_ALL_NOTES:
1213 case FN_HIDE_NOTE:
1214 case FN_HIDE_ALL_NOTES:
1215 case FN_DELETE_COMMENT:
1216 case FN_DELETE_COMMENT_THREAD:
1218 if( !pPostItMgr
1219 || !pPostItMgr->HasActiveAnnotationWin() )
1221 rSet.DisableItem(nWhich);
1223 break;
1225 case FN_RESOLVE_NOTE:
1227 if( !pPostItMgr
1228 || !pPostItMgr->HasActiveAnnotationWin() )
1230 rSet.DisableItem(nWhich);
1232 else
1234 SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsResolved());
1235 rSet.Put( aBool );
1237 break;
1239 case FN_RESOLVE_NOTE_THREAD:
1241 if( !pPostItMgr
1242 || !pPostItMgr->HasActiveAnnotationWin() )
1244 rSet.DisableItem(nWhich);
1246 else
1248 SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsThreadResolved());
1249 rSet.Put( aBool );
1251 break;
1253 case FN_DELETE_NOTE_AUTHOR:
1254 case FN_HIDE_NOTE_AUTHOR:
1256 if( !pPostItMgr
1257 || !pPostItMgr->HasActiveAnnotationWin() )
1259 rSet.DisableItem(nWhich);
1261 else
1263 OUString aText( nSlotId == FN_DELETE_NOTE_AUTHOR ?
1264 SwResId( STR_DELETE_NOTE_AUTHOR ) : SwResId( STR_HIDE_NOTE_AUTHOR ) );
1265 SwRewriter aRewriter;
1266 aRewriter.AddRule( UndoArg1, pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1267 aText = aRewriter.Apply( aText );
1268 SfxStringItem aItem( nSlotId, aText );
1269 rSet.Put( aItem );
1271 break;
1273 case FN_REPLY:
1275 if ( !pPostItMgr ||
1276 !pPostItMgr->HasActiveAnnotationWin() )
1278 rSet.DisableItem(nWhich);
1280 else
1282 SvtUserOptions aUserOpt;
1283 OUString sAuthor;
1284 if( (sAuthor = aUserOpt.GetFullName()).isEmpty() &&
1285 (sAuthor = aUserOpt.GetID()).isEmpty() )
1286 sAuthor = SwResId( STR_REDLINE_UNKNOWN_AUTHOR );
1287 if (sAuthor == pPostItMgr->GetActiveSidebarWin()->GetAuthor())
1288 rSet.DisableItem(nWhich);
1290 break;
1292 case FN_PROMOTE_COMMENT:
1294 if (!pPostItMgr || !pPostItMgr->HasActiveAnnotationWin()
1295 || pPostItMgr->GetActiveSidebarWin()->IsRootNote())
1297 rSet.DisableItem(nWhich);
1299 break;
1301 default:
1302 rSet.InvalidateItem( nWhich );
1303 break;
1306 if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
1308 if ( (pPostItMgr->GetActiveSidebarWin()->IsReadOnlyOrProtected()) &&
1309 ( (nSlotId==FN_DELETE_COMMENT) || (nSlotId==FN_REPLY) ) )
1310 rSet.DisableItem( nWhich );
1312 nWhich = aIter.NextWhich();
1316 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1318 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1319 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1320 return;
1322 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1323 sal_uInt16 nSlot = rReq.GetSlot();
1324 SwWrtShell &rSh = m_rView.GetWrtShell();
1325 bool bRestoreSelection = false;
1326 ESelection aOldSelection;
1328 switch (nSlot)
1330 case SID_LANGUAGE_STATUS:
1332 aOldSelection = pOLV->GetSelection();
1333 if (!pOLV->GetEditView().HasSelection())
1335 pOLV->GetEditView().SelectCurrentWord();
1338 bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,m_rView,rSh);
1339 break;
1341 case SID_THES:
1343 OUString aReplaceText;
1344 const SfxStringItem* pItem2 = rReq.GetArg(FN_PARAM_THES_WORD_REPLACE);
1345 if (pItem2)
1346 aReplaceText = pItem2->GetValue();
1347 if (!aReplaceText.isEmpty())
1348 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
1349 break;
1351 case SID_THESAURUS:
1353 pOLV->StartThesaurus(rReq.GetFrameWeld());
1354 break;
1356 case SID_HANGUL_HANJA_CONVERSION:
1357 pOLV->StartTextConversion(rReq.GetFrameWeld(), LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr,
1358 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true, false);
1359 break;
1361 case SID_CHINESE_CONVERSION:
1363 //open ChineseTranslationDialog
1364 Reference< XComponentContext > xContext(
1365 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1366 if(xContext.is())
1368 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1369 if(xMCF.is())
1371 Reference< ui::dialogs::XExecutableDialog > xDialog(
1372 xMCF->createInstanceWithContext(
1373 u"com.sun.star.linguistic2.ChineseTranslationDialog"_ustr, xContext),
1374 UNO_QUERY);
1375 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1376 if( xInit.is() )
1378 // initialize dialog
1379 uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
1381 {"ParentWindow", uno::Any(Reference<awt::XWindow>())}
1382 }));
1383 xInit->initialize( aSeq );
1385 //execute dialog
1386 sal_Int16 nDialogRet = xDialog->execute();
1387 if( RET_OK == nDialogRet )
1389 //get some parameters from the dialog
1390 bool bToSimplified = true;
1391 bool bUseVariants = true;
1392 bool bCommonTerms = true;
1393 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1394 if( xProp.is() )
1398 xProp->getPropertyValue( u"IsDirectionToSimplified"_ustr ) >>= bToSimplified;
1399 xProp->getPropertyValue( u"IsUseCharacterVariants"_ustr ) >>= bUseVariants;
1400 xProp->getPropertyValue( u"IsTranslateCommonTerms"_ustr ) >>= bCommonTerms;
1402 catch (const Exception&)
1407 //execute translation
1408 LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1409 LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1410 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1411 if( !bCommonTerms )
1412 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1414 vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
1415 nTargetLang, GetDefaultFontFlags::OnlyOne );
1417 pOLV->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
1420 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1421 if( xComponent.is() )
1422 xComponent->dispose();
1426 break;
1429 if (bRestoreSelection)
1431 // restore selection
1432 pOLV->GetEditView().SetSelection( aOldSelection );
1436 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1438 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1439 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1440 return;
1442 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1444 SfxWhichIter aIter(rSet);
1445 sal_uInt16 nWhich = aIter.FirstWhich();
1446 while(nWhich)
1448 switch (nWhich)
1450 case SID_LANGUAGE_STATUS:
1452 SwLangHelper::GetLanguageStatus(pOLV,rSet);
1453 break;
1456 case SID_THES:
1458 OUString aStatusVal;
1459 LanguageType nLang = LANGUAGE_NONE;
1460 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
1461 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
1463 // disable "Thesaurus" context menu entry if there is nothing to look up
1464 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1465 if (!bIsLookUpWord ||
1466 !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1467 rSet.DisableItem( SID_THES );
1468 break;
1471 // disable "Thesaurus" if the language is not supported
1472 case SID_THESAURUS:
1474 TypedWhichId<SvxLanguageItem> nLangWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE,
1475 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1476 const SvxLanguageItem &rItem = m_rView.GetWrtShell().GetDoc()->GetDefault(nLangWhich);
1477 LanguageType nLang = rItem.GetLanguage();
1478 uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() );
1479 if (!xThes.is() || nLang == LANGUAGE_NONE ||
1480 !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1481 rSet.DisableItem( SID_THESAURUS );
1483 break;
1484 case SID_HANGUL_HANJA_CONVERSION:
1485 case SID_CHINESE_CONVERSION:
1487 if (!SvtCJKOptions::IsAnyEnabled())
1489 m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, false );
1490 rSet.DisableItem(nWhich);
1492 else
1493 m_rView.GetViewFrame().GetBindings().SetVisibleState( nWhich, true );
1495 break;
1498 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1499 rSet.DisableItem( nWhich );
1501 nWhich = aIter.NextWhich();
1505 void SwAnnotationShell::ExecTransliteration(SfxRequest const &rReq)
1507 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1508 if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1509 return;
1511 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1513 if (!pOLV)
1514 return;
1516 TransliterationFlags nMode = TransliterationFlags::NONE;
1518 switch( rReq.GetSlot() )
1520 case SID_TRANSLITERATE_SENTENCE_CASE:
1521 nMode = TransliterationFlags::SENTENCE_CASE;
1522 break;
1523 case SID_TRANSLITERATE_TITLE_CASE:
1524 nMode = TransliterationFlags::TITLE_CASE;
1525 break;
1526 case SID_TRANSLITERATE_TOGGLE_CASE:
1527 nMode = TransliterationFlags::TOGGLE_CASE;
1528 break;
1529 case SID_TRANSLITERATE_UPPER:
1530 nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
1531 break;
1532 case SID_TRANSLITERATE_LOWER:
1533 nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
1534 break;
1535 case SID_TRANSLITERATE_HALFWIDTH:
1536 nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
1537 break;
1538 case SID_TRANSLITERATE_FULLWIDTH:
1539 nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
1540 break;
1541 case SID_TRANSLITERATE_HIRAGANA:
1542 nMode = TransliterationFlags::KATAKANA_HIRAGANA;
1543 break;
1544 case SID_TRANSLITERATE_KATAKANA:
1545 nMode = TransliterationFlags::HIRAGANA_KATAKANA;
1546 break;
1548 default:
1549 OSL_ENSURE(false, "wrong dispatcher");
1552 if( nMode != TransliterationFlags::NONE )
1553 pOLV->TransliterateText( nMode );
1556 void SwAnnotationShell::ExecRotateTransliteration( SfxRequest const & rReq )
1558 if( rReq.GetSlot() != SID_TRANSLITERATE_ROTATE_CASE )
1559 return;
1561 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1562 if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1563 return;
1565 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1567 if (!pOLV)
1568 return;
1570 pOLV->TransliterateText(m_aRotateCase.getNextMode());
1573 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1575 const SfxItemSet* pArgs = rReq.GetArgs();
1576 SfxUndoManager* pUndoManager = GetUndoManager();
1577 SwWrtShell &rSh = m_rView.GetWrtShell();
1578 SwUndoId nUndoId(SwUndoId::EMPTY);
1580 // tdf#147928 get these before "undo" which may delete this SwAnnotationShell
1581 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1582 SfxBindings& rBindings = m_rView.GetViewFrame().GetBindings();
1584 tools::Long aOldHeight = pPostItMgr->HasActiveSidebarWin()
1585 ? pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight()
1586 : 0;
1588 sal_uInt16 nId = rReq.GetSlot();
1589 sal_uInt16 nCnt = 1;
1590 const SfxPoolItem* pItem=nullptr;
1591 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ) )
1592 nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1593 switch( nId )
1595 case SID_UNDO:
1597 rSh.GetLastUndoInfo(nullptr, &nUndoId);
1598 if (nUndoId == SwUndoId::CONFLICT)
1600 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1601 break;
1604 if ( pUndoManager )
1606 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1607 sal_uInt16 nSteps = nCnt;
1608 if ( nCount < nCnt )
1610 nCnt = nCnt - nCount;
1611 nSteps = nCount;
1613 else
1614 nCnt = 0;
1616 while( nSteps-- )
1617 pUndoManager->Undo();
1620 if ( nCnt )
1621 rSh.Do( SwWrtShell::UNDO, nCnt );
1623 break;
1626 case SID_REDO:
1628 (void)rSh.GetFirstRedoInfo(nullptr, &nUndoId);
1629 if (nUndoId == SwUndoId::CONFLICT)
1631 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1632 break;
1635 if ( pUndoManager )
1637 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1638 sal_uInt16 nSteps = nCnt;
1639 if ( nCount < nCnt )
1641 nCnt = nCnt - nCount;
1642 nSteps = nCount;
1644 else
1645 nCnt = 0;
1647 while( nSteps-- )
1648 pUndoManager->Redo();
1651 if ( nCnt )
1652 rSh.Do( SwWrtShell::REDO, nCnt );
1654 break;
1658 rBindings.InvalidateAll(false);
1660 if (pPostItMgr->HasActiveSidebarWin())
1661 pPostItMgr->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight, pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
1664 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1666 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1667 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1668 return;
1670 SfxWhichIter aIter(rSet);
1671 SwUndoId nUndoId(SwUndoId::EMPTY);
1672 sal_uInt16 nWhich = aIter.FirstWhich();
1673 SfxUndoManager* pUndoManager = GetUndoManager();
1674 SfxViewFrame& rSfxViewFrame = m_rView.GetViewFrame();
1675 SwWrtShell &rSh = m_rView.GetWrtShell();
1677 while( nWhich )
1679 switch ( nWhich )
1681 case SID_UNDO:
1683 sal_uInt16 nCount = pUndoManager ? pUndoManager->GetUndoActionCount() : 0;
1684 if ( nCount )
1685 rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1686 else if (rSh.GetLastUndoInfo(nullptr, &nUndoId))
1688 rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1690 else if (nUndoId == SwUndoId::CONFLICT)
1692 rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1694 else
1695 rSet.DisableItem(nWhich);
1696 break;
1698 case SID_REDO:
1700 sal_uInt16 nCount = pUndoManager ? pUndoManager->GetRedoActionCount() : 0;
1701 if ( nCount )
1702 rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1703 else if (rSh.GetFirstRedoInfo(nullptr, &nUndoId))
1705 rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1707 else if (nUndoId == SwUndoId::CONFLICT)
1709 rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1711 else
1712 rSet.DisableItem(nWhich);
1713 break;
1715 case SID_GETUNDOSTRINGS:
1716 case SID_GETREDOSTRINGS:
1718 if( pUndoManager )
1720 OUString (SfxUndoManager::*fnGetComment)( size_t, bool const ) const;
1722 sal_uInt16 nCount;
1723 if( SID_GETUNDOSTRINGS == nWhich )
1725 nCount = pUndoManager->GetUndoActionCount();
1726 fnGetComment = &SfxUndoManager::GetUndoActionComment;
1728 else
1730 nCount = pUndoManager->GetRedoActionCount();
1731 fnGetComment = &SfxUndoManager::GetRedoActionComment;
1734 OUStringBuffer sList;
1735 if( nCount )
1737 for( sal_uInt16 n = 0; n < nCount; ++n )
1738 sList.append( (pUndoManager->*fnGetComment)( n, SfxUndoManager::TopLevel ) + "\n");
1741 SfxStringListItem aItem( nWhich );
1742 if ((nWhich == SID_GETUNDOSTRINGS) &&
1743 rSh.GetLastUndoInfo(nullptr, nullptr))
1745 rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1747 else if ((nWhich == SID_GETREDOSTRINGS) &&
1748 (rSh.GetFirstRedoInfo(nullptr, nullptr)))
1750 rSh.GetDoStrings( SwWrtShell::REDO, aItem );
1753 sList.append(aItem.GetString());
1754 aItem.SetString( sList.makeStringAndClear() );
1755 rSet.Put( aItem );
1757 else
1758 rSet.DisableItem( nWhich );
1760 break;
1762 default:
1764 rSfxViewFrame.GetSlotState( nWhich, rSfxViewFrame.GetInterface(), &rSet );
1765 break;
1770 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1771 rSet.DisableItem( nWhich );
1773 nWhich = aIter.NextWhich();
1777 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1779 SfxWhichIter aIter(rSet);
1780 sal_uInt16 nWhich = aIter.FirstWhich();
1781 while (nWhich)
1783 rSet.DisableItem( nWhich );
1784 nWhich = aIter.NextWhich();
1788 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1790 SwPostItMgr* pPostItMgr = m_rView.GetPostItMgr();
1791 if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1792 return;
1794 OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1796 const SfxItemSet *pArgs = rReq.GetArgs();
1797 const SfxStringItem* pCharMapItem = nullptr;
1798 if( pArgs )
1799 pCharMapItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
1801 OUString sSym;
1802 OUString sFontName;
1803 if ( pCharMapItem )
1805 sSym = pCharMapItem->GetValue();
1806 const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false);
1807 if (pFontItem)
1808 sFontName = pFontItem->GetValue();
1811 SfxItemSet aSet(pOLV->GetAttribs());
1812 SvtScriptType nScript = pOLV->GetSelectedScriptType();
1813 std::shared_ptr<SvxFontItem> aSetDlgFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
1815 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1816 aSetItem.GetItemSet().Put( aSet, false );
1817 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1818 if( pI )
1820 aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
1822 else
1824 TypedWhichId<SvxFontItem> nFontWhich =
1825 GetWhichOfScript(
1826 SID_ATTR_CHAR_FONT,
1827 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
1828 aSetDlgFont.reset(aSet.Get(nFontWhich).Clone());
1831 if (sFontName.isEmpty())
1832 sFontName = aSetDlgFont->GetFamilyName();
1835 vcl::Font aFont(sFontName, Size(1,1));
1836 if( sSym.isEmpty() )
1838 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1840 SfxAllItemSet aAllSet( GetPool() );
1841 aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
1843 SwViewOption aOpt(*m_rView.GetWrtShell().GetViewOptions());
1844 const OUString& sSymbolFont = aOpt.GetSymbolFont();
1845 if( !sSymbolFont.isEmpty() )
1846 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1847 else
1848 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont->GetFamilyName() ) );
1850 // If character is selected then it can be shown.
1851 auto xFrame = m_rView.GetViewFrame().GetFrame().GetFrameInterface();
1852 VclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(m_rView.GetFrameWeld(), aAllSet, xFrame));
1853 pDlg->StartExecuteAsync(
1854 [pDlg] (sal_Int32 /*nResult*/)->void
1856 pDlg->disposeOnce();
1859 return;
1862 // do not flicker
1863 pOLV->HideCursor();
1864 Outliner * pOutliner = pOLV->GetOutliner();
1865 pOutliner->SetUpdateLayout(false);
1867 SfxItemSet aOldSet( pOLV->GetAttribs() );
1868 SfxItemSet aFontSet(SfxItemSet::makeFixedSfxItemSet<
1869 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
1870 EE_CHAR_FONTINFO_CTL>(*aOldSet.GetPool()));
1871 aFontSet.Set( aOldSet );
1873 // Insert string
1874 pOLV->InsertText( sSym);
1876 // Attributing (set font)
1877 SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1878 SvxFontItem aFontItem (aFont.GetFamilyType(), aFont.GetFamilyName(),
1879 aFont.GetStyleName(), aFont.GetPitch(),
1880 aFont.GetCharSet(),
1881 EE_CHAR_FONTINFO );
1882 SvtScriptType nScriptBreak = g_pBreakIt->GetAllScriptsOfText( sSym );
1883 if( SvtScriptType::LATIN & nScriptBreak )
1884 aSetFont.Put( aFontItem );
1885 if( SvtScriptType::ASIAN & nScriptBreak )
1887 aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
1888 aSetFont.Put( aFontItem );
1890 if( SvtScriptType::COMPLEX & nScriptBreak )
1892 aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
1893 aSetFont.Put( aFontItem );
1895 pOLV->SetAttribs(aSetFont);
1897 // Erase selection
1898 ESelection aSel(pOLV->GetSelection());
1899 aSel.CollapseToEnd();
1900 pOLV->SetSelection(aSel);
1902 // Restore old font
1903 pOLV->SetAttribs( aFontSet );
1905 // From now on show it again
1906 pOutliner->SetUpdateLayout(true);
1907 pOLV->ShowCursor();
1909 rReq.AppendItem( SfxStringItem( SID_CHARMAP, sSym ) );
1910 if(!aFont.GetFamilyName().isEmpty())
1911 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetFamilyName() ) );
1912 rReq.Done();
1916 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */