1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <hintids.hxx>
21 
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>
29 
30 #include <i18nutil/transliteration.hxx>
31 #include <sfx2/objface.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/request.hxx>
35 #include <editeng/eeitem.hxx>
36 #include <editeng/flstitem.hxx>
37 #include <editeng/spltitem.hxx>
38 #include <editeng/lrspitem.hxx>
39 #include <editeng/ulspitem.hxx>
40 #include <editeng/orphitem.hxx>
41 #include <editeng/formatbreakitem.hxx>
42 #include <editeng/widwitem.hxx>
43 #include <editeng/kernitem.hxx>
44 #include <editeng/escapementitem.hxx>
45 #include <editeng/lspcitem.hxx>
46 #include <editeng/adjustitem.hxx>
47 #include <editeng/hyphenzoneitem.hxx>
48 #include <editeng/udlnitem.hxx>
49 #include <editeng/fontitem.hxx>
50 #include <svx/clipfmtitem.hxx>
51 #include <svl/stritem.hxx>
52 #include <svl/slstitm.hxx>
53 #include <editeng/frmdiritem.hxx>
54 #include <svl/whiter.hxx>
55 #include <svl/cjkoptions.hxx>
56 #include <svl/ctloptions.hxx>
57 #include <unotools/useroptions.hxx>
58 #include <editeng/flditem.hxx>
59 #include <svx/hlnkitem.hxx>
60 #include <sfx2/htmlmode.hxx>
61 #include <editeng/langitem.hxx>
62 #include <editeng/scripttypeitem.hxx>
63 #include <swundo.hxx>
64 #include <doc.hxx>
65 #include <viewopt.hxx>
66 #include <wrtsh.hxx>
67 #include <chrdlgmodes.hxx>
68 #include <edtwin.hxx>
69 #include <SwRewriter.hxx>
70 
71 #include <cmdid.h>
72 #include <strings.hrc>
73 #include <breakit.hxx>
74 #include <annotsh.hxx>
75 #include <view.hxx>
76 #include <PostItMgr.hxx>
77 #include <AnnotationWin.hxx>
78 
79 #include <swtypes.hxx>
80 
81 #include <svx/svxdlg.hxx>
82 
83 #include <vcl/EnumContext.hxx>
84 #include <svl/itempool.hxx>
85 #include <editeng/outliner.hxx>
86 #include <editeng/editview.hxx>
87 #include <osl/diagnose.h>
88 
89 #include <svl/languageoptions.hxx>
90 
91 #include <svl/undo.hxx>
92 #include <swabstdlg.hxx>
93 
94 #include <comphelper/string.hxx>
95 #include <comphelper/propertysequence.hxx>
96 #include <cppuhelper/bootstrap.hxx>
97 
98 #include <langhelper.hxx>
99 
100 #include <memory>
101 
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::beans;
105 using namespace ::com::sun::star::i18n;
106 
107 #define ShellClass_SwAnnotationShell
108 
109 #include <sfx2/msg.hxx>
110 #include <swslots.hxx>
111 
SFX_IMPL_INTERFACE(SwAnnotationShell,SfxShell)112 SFX_IMPL_INTERFACE(SwAnnotationShell, SfxShell)
113 
114 void SwAnnotationShell::InitInterface_Impl()
115 {
116     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
117 
118     GetStaticInterface()->RegisterPopupMenu("annotation");
119 }
120 
121 
GetAnnotationPool(SwView const & rV)122 SfxItemPool* SwAnnotationShell::GetAnnotationPool(SwView const & rV)
123 {
124     SwWrtShell &rSh = rV.GetWrtShell();
125     return rSh.GetAttrPool().GetSecondaryPool();
126 }
127 
SwAnnotationShell(SwView & r)128 SwAnnotationShell::SwAnnotationShell( SwView& r )
129     : rView(r)
130 {
131     SetPool(SwAnnotationShell::GetAnnotationPool(rView));
132     SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Annotation));
133 }
134 
~SwAnnotationShell()135 SwAnnotationShell::~SwAnnotationShell()
136 {
137 }
138 
GetUndoManager()139 SfxUndoManager* SwAnnotationShell::GetUndoManager()
140 {
141     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
142     if ( !pPostItMgr ||
143          !pPostItMgr->HasActiveSidebarWin() )
144     {
145         OSL_ENSURE(pPostItMgr,"PostItMgr::Layout(): We are looping forever");
146         return nullptr;
147     }
148     return &pPostItMgr->GetActiveSidebarWin()->GetOutlinerView()->GetOutliner()->GetUndoManager();
149 }
150 
Exec(SfxRequest & rReq)151 void SwAnnotationShell::Exec( SfxRequest &rReq )
152 {
153     //TODO: clean this up!!!!
154     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
155     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
156         return;
157 
158     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
159     SfxItemSet aEditAttr(pOLV->GetAttribs());
160     SfxItemSet aNewAttr(*aEditAttr.GetPool(), aEditAttr.GetRanges());
161 
162     sal_uInt16 nSlot = rReq.GetSlot();
163     sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
164     const SfxItemSet *pNewAttrs = rReq.GetArgs();
165     sal_uInt16 nEEWhich = 0;
166     switch (nSlot)
167     {
168         case SID_PARASPACE_INCREASE:
169         case SID_PARASPACE_DECREASE:
170         {
171             SvxULSpaceItem aULSpace( aEditAttr.Get( EE_PARA_ULSPACE ) );
172             sal_uInt16 nUpper = aULSpace.GetUpper();
173             sal_uInt16 nLower = aULSpace.GetLower();
174 
175             if ( nSlot == SID_PARASPACE_INCREASE )
176             {
177                 nUpper = std::min< sal_uInt16 >( nUpper + 57, 5670 );
178                 nLower = std::min< sal_uInt16 >( nLower + 57, 5670 );
179             }
180             else
181             {
182                 nUpper = std::max< sal_Int16 >( nUpper - 57, 0 );
183                 nLower = std::max< sal_Int16 >( nLower - 57, 0 );
184             }
185 
186             aULSpace.SetUpper( nUpper );
187             aULSpace.SetLower( nLower );
188             aNewAttr.Put( aULSpace );
189             rReq.Done();
190         }
191         break;
192         case SID_ATTR_PARA_LRSPACE:
193             {
194                 SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(rReq.
195                                         GetArgs()->Get(nSlot)));
196                 aParaMargin.SetWhich( EE_PARA_LRSPACE );
197 
198                 aNewAttr.Put(aParaMargin);
199                 rReq.Done();
200                 break;
201             }
202         case SID_ATTR_PARA_LINESPACE:
203             {
204                 SvxLineSpacingItem aParaMargin = static_cast<const SvxLineSpacingItem&>(pNewAttrs->Get(
205                                                             GetPool().GetWhich(nSlot)));
206                 aParaMargin.SetWhich( EE_PARA_SBL );
207 
208                 aNewAttr.Put(aParaMargin);
209                 rReq.Done();
210                 break;
211             }
212         case SID_ATTR_PARA_ULSPACE:
213             {
214                 SvxULSpaceItem aULSpace = static_cast<const SvxULSpaceItem&>(pNewAttrs->Get(
215                     GetPool().GetWhich(nSlot)));
216                 aULSpace.SetWhich( EE_PARA_ULSPACE );
217                 aNewAttr.Put( aULSpace );
218                 rReq.Done();
219             }
220             break;
221         case FN_GROW_FONT_SIZE:
222         case FN_SHRINK_FONT_SIZE:
223         {
224             const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
225                     ( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
226             const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
227             pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, pFontList );
228         }
229         break;
230 
231         case SID_ATTR_CHAR_FONT:
232         case SID_ATTR_CHAR_FONTHEIGHT:
233         case SID_ATTR_CHAR_WEIGHT:
234         case SID_ATTR_CHAR_POSTURE:
235             {
236                 SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
237                 if( !pSecondPool )
238                     pSecondPool = aEditAttr.GetPool();
239                 SvxScriptSetItem aSetItem( nSlot, *pSecondPool );
240                 aSetItem.PutItemForScriptType( pOLV->GetSelectedScriptType(), pNewAttrs->Get( nWhich ));
241                 aNewAttr.Put( aSetItem.GetItemSet() );
242                 rReq.Done();
243                 break;
244             }
245         case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
246         case SID_ATTR_CHAR_BACK_COLOR: nEEWhich = EE_CHAR_BKGCOLOR; break;
247         case SID_ATTR_CHAR_UNDERLINE:
248         {
249             if( rReq.GetArgs() )
250             {
251                 const SvxUnderlineItem* pItem = rReq.GetArg<SvxUnderlineItem>(SID_ATTR_CHAR_UNDERLINE);
252                 if (pItem)
253                 {
254                     aNewAttr.Put(*pItem);
255                 }
256                 else
257                 {
258                     FontLineStyle eFU = aEditAttr.Get( EE_CHAR_UNDERLINE ).GetLineStyle();
259                     aNewAttr.Put( SvxUnderlineItem( eFU != LINESTYLE_NONE ?LINESTYLE_NONE : LINESTYLE_SINGLE,  EE_CHAR_UNDERLINE ) );
260                 }
261             }
262             break;
263         }
264         case SID_ATTR_CHAR_OVERLINE:
265         {
266             FontLineStyle eFO = aEditAttr.Get(EE_CHAR_OVERLINE).GetLineStyle();
267             aNewAttr.Put(SvxOverlineItem(eFO == LINESTYLE_SINGLE ? LINESTYLE_NONE : LINESTYLE_SINGLE, EE_CHAR_OVERLINE));
268             break;
269         }
270         case SID_ATTR_CHAR_CONTOUR:     nEEWhich = EE_CHAR_OUTLINE; break;
271         case SID_ATTR_CHAR_SHADOWED:    nEEWhich = EE_CHAR_SHADOW; break;
272         case SID_ATTR_CHAR_STRIKEOUT:   nEEWhich = EE_CHAR_STRIKEOUT; break;
273         case SID_ATTR_CHAR_WORDLINEMODE: nEEWhich = EE_CHAR_WLM; break;
274         case SID_ATTR_CHAR_RELIEF      : nEEWhich = EE_CHAR_RELIEF;  break;
275         case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
276         case SID_ATTR_CHAR_KERNING     : nEEWhich = EE_CHAR_KERNING; break;
277         case SID_ATTR_CHAR_SCALEWIDTH:   nEEWhich = EE_CHAR_FONTWIDTH; break;
278         case SID_ATTR_CHAR_AUTOKERN  :   nEEWhich = EE_CHAR_PAIRKERNING; break;
279         case SID_ATTR_CHAR_ESCAPEMENT:   nEEWhich = EE_CHAR_ESCAPEMENT; break;
280         case SID_ATTR_PARA_ADJUST_LEFT:
281             aNewAttr.Put(SvxAdjustItem(SvxAdjust::Left, EE_PARA_JUST));
282         break;
283         case SID_ATTR_PARA_ADJUST_CENTER:
284             aNewAttr.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST));
285         break;
286         case SID_ATTR_PARA_ADJUST_RIGHT:
287             aNewAttr.Put(SvxAdjustItem(SvxAdjust::Right, EE_PARA_JUST));
288         break;
289         case SID_ATTR_PARA_ADJUST_BLOCK:
290             aNewAttr.Put(SvxAdjustItem(SvxAdjust::Block, EE_PARA_JUST));
291         break;
292 
293         case SID_ATTR_PARA_LINESPACE_10:
294         {
295             SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
296             aItem.SetPropLineSpace(100);
297             aNewAttr.Put(aItem);
298         }
299         break;
300         case SID_ATTR_PARA_LINESPACE_15:
301         {
302             SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
303             aItem.SetPropLineSpace(150);
304             aNewAttr.Put(aItem);
305         }
306         break;
307         case SID_ATTR_PARA_LINESPACE_20:
308         {
309             SvxLineSpacingItem aItem(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
310             aItem.SetPropLineSpace(200);
311             aNewAttr.Put(aItem);
312         }
313         break;
314         case SID_SELECTALL:
315         {
316             Outliner * pOutliner = pOLV->GetOutliner();
317             if(pOutliner)
318             {
319                 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
320                 if (nParaCount > 0)
321                     pOLV->SelectRange(0, nParaCount );
322             }
323             break;
324         }
325         case FN_FORMAT_RESET:
326         {
327             pPostItMgr->GetActiveSidebarWin()->ResetAttributes();
328             rReq.Done();
329             break;
330         }
331         case FN_SET_SUPER_SCRIPT:
332         {
333             SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
334             SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
335 
336             if( eEsc == SvxEscapement::Superscript )
337                 aItem.SetEscapement( SvxEscapement::Off );
338             else
339                 aItem.SetEscapement( SvxEscapement::Superscript );
340             aNewAttr.Put( aItem );
341         }
342         break;
343         case FN_SET_SUB_SCRIPT:
344         {
345             SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT);
346             SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
347 
348             if( eEsc == SvxEscapement::Subscript )
349                 aItem.SetEscapement( SvxEscapement::Off );
350             else
351                 aItem.SetEscapement( SvxEscapement::Subscript );
352             aNewAttr.Put( aItem );
353         }
354         break;
355         case SID_HYPERLINK_SETLINK:
356         {
357             const SfxPoolItem* pItem = nullptr;
358             if(pNewAttrs)
359                 pNewAttrs->GetItemState(nSlot, false, &pItem);
360 
361             if(pItem)
362             {
363                 const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
364                 SvxURLField aField(rHLinkItem.GetURL(), rHLinkItem.GetName(), SvxURLFormat::AppDefault);
365                 aField.SetTargetFrame(rHLinkItem.GetTargetFrame());
366 
367                 const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
368 
369                 if (pFieldItem && dynamic_cast<const SvxURLField *>(pFieldItem->GetField()) != nullptr)
370                 {
371                     // Select the field so that it will be deleted during insert
372                     ESelection aSel = pOLV->GetSelection();
373                     aSel.nEndPos++;
374                     pOLV->SetSelection(aSel);
375                 }
376                 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
377                     pOLV->InsertField(SvxFieldItem(aField, EE_FEATURE_FIELD));
378             }
379             break;
380         }
381         case FN_INSERT_SOFT_HYPHEN:
382         case FN_INSERT_HARDHYPHEN:
383         case FN_INSERT_HARD_SPACE:
384         case FN_INSERT_NNBSP:
385         case SID_INSERT_RLM :
386         case SID_INSERT_LRM :
387         case SID_INSERT_WJ :
388         case SID_INSERT_ZWSP:
389         {
390             sal_Unicode cIns = 0;
391             switch(rReq.GetSlot())
392             {
393                 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
394                 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
395                 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
396                 case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
397                 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
398                 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
399                 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
400                 case SID_INSERT_WJ: cIns = CHAR_WJ; break;
401             }
402             pOLV->InsertText( OUString(cIns));
403             rReq.Done();
404             break;
405         }
406         case SID_CHARMAP:
407         {
408             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
409                 InsertSymbol(rReq);
410             break;
411         }
412         case FN_INSERT_STRING:
413         {
414             const SfxPoolItem* pItem = nullptr;
415             if (pNewAttrs)
416                 pNewAttrs->GetItemState(nSlot, false, &pItem );
417             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
418                 pOLV->InsertText(static_cast<const SfxStringItem *>(pItem)->GetValue());
419             break;
420         }
421         case FN_FORMAT_FOOTNOTE_DLG:
422         {
423             rView.ExecFormatFootnote();
424             break;
425         }
426         case FN_NUMBERING_OUTLINE_DLG:
427         {
428             rView.ExecNumberingOutline(GetPool());
429             rReq.Done();
430         }
431         break;
432         case SID_OPEN_XML_FILTERSETTINGS:
433         {
434             HandleOpenXmlFilterSettings(rReq);
435         }
436         break;
437         case FN_WORDCOUNT_DIALOG:
438         {
439             rView.UpdateWordCount(this, nSlot);
440             break;
441         }
442         case SID_CHAR_DLG_EFFECT:
443         case SID_CHAR_DLG:
444         {
445             const SfxItemSet* pArgs = rReq.GetArgs();
446             const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
447 
448             if( !pArgs || pItem )
449             {
450                 /* mod
451                 SwView* pView = &GetView();
452                 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) !=  nullptr );
453                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
454                 */
455                 SfxItemSet aDlgAttr(GetPool(), svl::Items<XATTR_FILLSTYLE, XATTR_FILLCOLOR, EE_ITEMS_START, EE_ITEMS_END>{});
456 
457                 // util::Language does not exist in the EditEngine! Therefore not included in the set.
458 
459                 aDlgAttr.Put( aEditAttr );
460                 aDlgAttr.Put( SvxKerningItem(0, RES_CHRATR_KERNING) );
461 
462                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
463                 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwCharDlg(rView.GetFrameWeld(), rView, aDlgAttr, SwCharDlgMode::Ann));
464                 if (nSlot == SID_CHAR_DLG_EFFECT)
465                 {
466                     pDlg->SetCurPageId("fonteffects");
467                 }
468                 else if (pItem)
469                 {
470                     pDlg->SetCurPageId(OUStringToOString(pItem->GetValue(), RTL_TEXTENCODING_UTF8));
471                 }
472 
473                 sal_uInt16 nRet = pDlg->Execute();
474                 if(RET_OK == nRet )
475                 {
476                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
477                     aNewAttr.Put(*pDlg->GetOutputItemSet());
478                 }
479                 if(RET_OK != nRet)
480                     return ;
481             }
482             else
483                 aNewAttr.Put(*pArgs);
484             break;
485         }
486         case SID_PARA_DLG:
487         {
488             const SfxItemSet* pArgs = rReq.GetArgs();
489 
490             if (!pArgs)
491             {
492                 /* mod todo ???
493                 SwView* pView = &GetView();
494                 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) !=  nullptr );
495                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, eMetric));
496                 */
497                 SfxItemSet aDlgAttr(
498                     GetPool(),
499                     svl::Items<
500                         EE_ITEMS_START, EE_ITEMS_END,
501                         SID_ATTR_PARA_HYPHENZONE, SID_ATTR_PARA_WIDOWS>{});
502 
503                 aDlgAttr.Put(aEditAttr);
504 
505                 aDlgAttr.Put( SvxHyphenZoneItem( false, RES_PARATR_HYPHENZONE) );
506                 aDlgAttr.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
507                 aDlgAttr.Put( SvxFormatSplitItem( true, RES_PARATR_SPLIT ) );
508                 aDlgAttr.Put( SvxWidowsItem( 0, RES_PARATR_WIDOWS ) );
509                 aDlgAttr.Put( SvxOrphansItem( 0, RES_PARATR_ORPHANS ) );
510 
511                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
512                 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwParaDlg(rView.GetFrameWeld(), rView, aDlgAttr, true));
513                 sal_uInt16 nRet = pDlg->Execute();
514                 if(RET_OK == nRet)
515                 {
516                     rReq.Done( *( pDlg->GetOutputItemSet() ) );
517                     aNewAttr.Put(*pDlg->GetOutputItemSet());
518                 }
519                 if(RET_OK != nRet)
520                     return;
521             }
522             else
523                 aNewAttr.Put(*pArgs);
524             break;
525         }
526 
527         case SID_AUTOSPELL_CHECK:
528         {
529             rView.ExecuteSlot(rReq);
530             break;
531         }
532         case SID_ATTR_PARA_LEFT_TO_RIGHT:
533         case SID_ATTR_PARA_RIGHT_TO_LEFT:
534         {
535             bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
536 
537             const SfxPoolItem* pPoolItem;
538             if( pNewAttrs && SfxItemState::SET == pNewAttrs->GetItemState( nSlot, true, &pPoolItem ) )
539             {
540                 if( !static_cast<const SfxBoolItem*>(pPoolItem)->GetValue() )
541                     bLeftToRight = !bLeftToRight;
542             }
543             SfxItemSet aAttr(
544                 *aNewAttr.GetPool(),
545                 svl::Items<
546                     EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
547                     EE_PARA_JUST, EE_PARA_JUST>{});
548 
549             SvxAdjust nAdjust = SvxAdjust::Left;
550             if( SfxItemState::SET == aEditAttr.GetItemState(EE_PARA_JUST, true, &pPoolItem ) )
551                 nAdjust = static_cast<const SvxAdjustItem*>(pPoolItem)->GetAdjust();
552 
553             if( bLeftToRight )
554             {
555                 aAttr.Put( SvxFrameDirectionItem( SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ) );
556                 if( nAdjust == SvxAdjust::Right )
557                     aAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
558             }
559             else
560             {
561                 aAttr.Put( SvxFrameDirectionItem( SvxFrameDirection::Horizontal_RL_TB, EE_PARA_WRITINGDIR ) );
562                 if( nAdjust == SvxAdjust::Left )
563                     aAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
564             }
565             pOLV->SetAttribs(aAttr);
566             break;
567         }
568     }
569 
570     if(nEEWhich && pNewAttrs)
571     {
572         aNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
573     }
574 
575     tools::Rectangle aOutRect = pOLV->GetOutputArea();
576     if (tools::Rectangle() != aOutRect && aNewAttr.Count())
577         pOLV->SetAttribs(aNewAttr);
578 
579     rView.GetViewFrame()->GetBindings().InvalidateAll(false);
580     if ( pOLV->GetOutliner()->IsModified() )
581         rView.GetWrtShell().SetModified();
582 
583 }
584 
GetState(SfxItemSet & rSet)585 void SwAnnotationShell::GetState(SfxItemSet& rSet)
586 {
587     //TODO: clean this up!!!
588     // FN_SET_SUPER_SCRIPT
589     //SID_ATTR_PARA_ADJUST
590     //SID_ATTR_PARA_ADJUST_BLOCK
591 
592     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
593     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
594         return;
595 
596     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
597     SfxItemSet aEditAttr(pOLV->GetAttribs());
598 
599     SfxWhichIter aIter(rSet);
600     sal_uInt16 nWhich = aIter.FirstWhich();
601     while(nWhich)
602     {
603         sal_uInt16 nEEWhich = 0;
604         sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
605         switch( nSlotId )
606         {
607             case SID_ATTR_PARA_LRSPACE:
608             case SID_ATTR_PARA_LEFTSPACE:
609             case SID_ATTR_PARA_RIGHTSPACE:
610             case SID_ATTR_PARA_FIRSTLINESPACE:
611             {
612                 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_LRSPACE );
613                 if( eState >= SfxItemState::DEFAULT )
614                 {
615                     SvxLRSpaceItem aLR = aEditAttr.Get( EE_PARA_LRSPACE );
616                     aLR.SetWhich(nSlotId);
617                     rSet.Put(aLR);
618                 }
619                 else
620                     rSet.InvalidateItem(nSlotId);
621             }
622             break;
623             case SID_ATTR_PARA_LINESPACE:
624             {
625                 SfxItemState eState = aEditAttr.GetItemState( EE_PARA_SBL );
626                 if( eState >= SfxItemState::DEFAULT )
627                 {
628                     const SvxLineSpacingItem& aLR = aEditAttr.Get( EE_PARA_SBL );
629                     rSet.Put(aLR);
630                 }
631                 else
632                     rSet.InvalidateItem(nSlotId);
633             }
634             break;
635             case SID_ATTR_PARA_ULSPACE:
636             case SID_ATTR_PARA_ABOVESPACE:
637             case SID_ATTR_PARA_BELOWSPACE:
638             case SID_PARASPACE_INCREASE:
639             case SID_PARASPACE_DECREASE:
640                 {
641                     SfxItemState eState = aEditAttr.GetItemState( EE_PARA_ULSPACE );
642                     if( eState >= SfxItemState::DEFAULT )
643                     {
644                         SvxULSpaceItem aULSpace = aEditAttr.Get( EE_PARA_ULSPACE );
645                         if ( !aULSpace.GetUpper() && !aULSpace.GetLower() )
646                             rSet.DisableItem( SID_PARASPACE_DECREASE );
647                         else if ( aULSpace.GetUpper() >= 5670 && aULSpace.GetLower() >= 5670 )
648                             rSet.DisableItem( SID_PARASPACE_INCREASE );
649                         if ( nSlotId == SID_ATTR_PARA_ULSPACE
650                             || nSlotId == SID_ATTR_PARA_BELOWSPACE
651                             || nSlotId == SID_ATTR_PARA_ABOVESPACE
652                         )
653                         {
654                             aULSpace.SetWhich(nSlotId);
655                             rSet.Put(aULSpace);
656                         }
657                     }
658                     else
659                     {
660                         rSet.DisableItem( SID_PARASPACE_INCREASE );
661                         rSet.DisableItem( SID_PARASPACE_DECREASE );
662                         rSet.InvalidateItem( SID_ATTR_PARA_ULSPACE );
663                         rSet.InvalidateItem( SID_ATTR_PARA_ABOVESPACE );
664                         rSet.InvalidateItem( SID_ATTR_PARA_BELOWSPACE );
665                     }
666                 }
667                 break;
668             case SID_ATTR_CHAR_FONT:
669             case SID_ATTR_CHAR_FONTHEIGHT:
670             case SID_ATTR_CHAR_WEIGHT:
671             case SID_ATTR_CHAR_POSTURE:
672                 {
673                     SvtScriptType nScriptType = pOLV->GetSelectedScriptType();
674                     SfxItemPool* pSecondPool = aEditAttr.GetPool()->GetSecondaryPool();
675                     if( !pSecondPool )
676                         pSecondPool = aEditAttr.GetPool();
677                     SvxScriptSetItem aSetItem( nSlotId, *pSecondPool );
678                     aSetItem.GetItemSet().Put( aEditAttr, false );
679                     const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
680                     if( pI )
681                     {
682                         rSet.Put(pI->CloneSetWhich(nWhich));
683                     }
684                     else
685                         rSet.InvalidateItem( nWhich );
686                 }
687                 break;
688             case SID_ATTR_CHAR_COLOR: nEEWhich = EE_CHAR_COLOR; break;
689             case SID_ATTR_CHAR_BACK_COLOR: nEEWhich = EE_CHAR_BKGCOLOR; break;
690             case SID_ATTR_CHAR_UNDERLINE: nEEWhich = EE_CHAR_UNDERLINE;break;
691             case SID_ATTR_CHAR_OVERLINE: nEEWhich = EE_CHAR_OVERLINE;break;
692             case SID_ATTR_CHAR_CONTOUR: nEEWhich = EE_CHAR_OUTLINE; break;
693             case SID_ATTR_CHAR_SHADOWED:  nEEWhich = EE_CHAR_SHADOW;break;
694             case SID_ATTR_CHAR_STRIKEOUT: nEEWhich = EE_CHAR_STRIKEOUT;break;
695             case SID_ATTR_CHAR_LANGUAGE    : nEEWhich = EE_CHAR_LANGUAGE;break;
696             case SID_ATTR_CHAR_ESCAPEMENT: nEEWhich = EE_CHAR_ESCAPEMENT;break;
697             case SID_ATTR_CHAR_KERNING:  nEEWhich = EE_CHAR_KERNING;break;
698             case FN_SET_SUPER_SCRIPT:
699             case FN_SET_SUB_SCRIPT:
700             {
701                 SvxEscapement nEsc;
702                 if (nWhich==FN_SET_SUPER_SCRIPT)
703                     nEsc = SvxEscapement::Superscript;
704                 else
705                     nEsc = SvxEscapement::Subscript;
706 
707                 const SfxPoolItem *pEscItem = &aEditAttr.Get( EE_CHAR_ESCAPEMENT );
708                 if( nEsc == static_cast<const SvxEscapementItem*>(pEscItem)->GetEscapement() )
709                     rSet.Put( SfxBoolItem( nWhich, true ));
710                 else
711                     rSet.InvalidateItem( nWhich );
712                 break;
713             }
714             case SID_ATTR_PARA_ADJUST_LEFT:
715             case SID_ATTR_PARA_ADJUST_RIGHT:
716             case SID_ATTR_PARA_ADJUST_CENTER:
717             case SID_ATTR_PARA_ADJUST_BLOCK:
718                 {
719                     SvxAdjust eAdjust = SvxAdjust::Left;
720                     if (nWhich==SID_ATTR_PARA_ADJUST_LEFT)
721                         eAdjust = SvxAdjust::Left;
722                     else if (nWhich==SID_ATTR_PARA_ADJUST_RIGHT)
723                         eAdjust = SvxAdjust::Right;
724                     else if (nWhich==SID_ATTR_PARA_ADJUST_CENTER)
725                         eAdjust = SvxAdjust::Center;
726                     else if (nWhich==SID_ATTR_PARA_ADJUST_BLOCK)
727                         eAdjust = SvxAdjust::Block;
728 
729                     const SfxPoolItem *pAdjust = nullptr;
730                     aEditAttr.GetItemState( EE_PARA_JUST, false, &pAdjust);
731 
732                     if( !pAdjust || IsInvalidItem( pAdjust ))
733                     {
734                         rSet.InvalidateItem( nSlotId );
735                     }
736                     else
737                     {
738                         if ( eAdjust == static_cast<const SvxAdjustItem*>(pAdjust)->GetAdjust())
739                             rSet.Put( SfxBoolItem( nWhich, true ));
740                         else
741                             rSet.InvalidateItem( nWhich );
742                     }
743                     break;
744                 }
745             case SID_ATTR_PARA_LINESPACE_10:
746             case SID_ATTR_PARA_LINESPACE_15:
747             case SID_ATTR_PARA_LINESPACE_20:
748                 {
749                     int nLSpace = 0;
750                     if (nWhich==SID_ATTR_PARA_LINESPACE_10)
751                         nLSpace = 100;
752                     else if (nWhich==SID_ATTR_PARA_LINESPACE_15)
753                         nLSpace = 150;
754                     else if (nWhich==SID_ATTR_PARA_LINESPACE_20)
755                         nLSpace = 200;
756 
757                     const SfxPoolItem *pLSpace = nullptr;
758                     aEditAttr.GetItemState( EE_PARA_SBL, false, &pLSpace );
759 
760                     if( !pLSpace || IsInvalidItem( pLSpace ))
761                     {
762                         rSet.InvalidateItem( nSlotId );
763                     }
764                     else
765                     {
766                         if( nLSpace == static_cast<const SvxLineSpacingItem*>(pLSpace)->GetPropLineSpace() )
767                             rSet.Put( SfxBoolItem( nWhich, true ));
768                         else
769                             rSet.InvalidateItem( nWhich );
770                     }
771                     break;
772                 }
773             case SID_AUTOSPELL_CHECK:
774             {
775                 const SfxPoolItem* pState = rView.GetSlotState(nWhich);
776                 if (pState)
777                     rSet.Put(SfxBoolItem(nWhich, static_cast<const SfxBoolItem*>(pState)->GetValue()));
778                 else
779                     rSet.DisableItem( nWhich );
780                 break;
781             }
782             case SID_ATTR_PARA_LEFT_TO_RIGHT:
783             case SID_ATTR_PARA_RIGHT_TO_LEFT:
784             {
785                 if ( !SvtLanguageOptions().IsCTLFontEnabled() )
786                     rSet.DisableItem( nWhich );
787                 else
788                 {
789                     if(pOLV->GetOutliner() && pOLV->GetOutliner()->IsVertical())
790                         rSet.DisableItem( nWhich );
791                     else
792                     {
793                         bool bFlag = false;
794                         switch( aEditAttr.Get( EE_PARA_WRITINGDIR ).GetValue() )
795                         {
796                             case SvxFrameDirection::Horizontal_LR_TB:
797                             {
798                                 bFlag = nWhich == SID_ATTR_PARA_LEFT_TO_RIGHT;
799                                 rSet.Put( SfxBoolItem( nWhich, bFlag ));
800                                 break;
801                             }
802                             case SvxFrameDirection::Horizontal_RL_TB:
803                             {
804                                 bFlag = nWhich != SID_ATTR_PARA_LEFT_TO_RIGHT;
805                                 rSet.Put( SfxBoolItem( nWhich, bFlag ));
806                                 break;
807                             }
808                             default:
809                                 break;
810                         }
811                     }
812                 }
813             }
814             break;
815             case SID_INSERT_RLM :
816             case SID_INSERT_LRM :
817             {
818                 SvtCTLOptions aCTLOptions;
819                 bool bEnabled = aCTLOptions.IsCTLFontEnabled();
820                 rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, bEnabled );
821                 if(!bEnabled)
822                     rSet.DisableItem(nWhich);
823             }
824             break;
825             default:
826                 rSet.InvalidateItem( nWhich );
827                 break;
828         }
829 
830         if(nEEWhich)
831         {
832             rSet.Put(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
833             if(nEEWhich == EE_CHAR_KERNING)
834             {
835                 SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING );
836                 if ( eState == SfxItemState::DONTCARE )
837                 {
838                     rSet.InvalidateItem(EE_CHAR_KERNING);
839                 }
840             }
841         }
842 
843         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
844             rSet.DisableItem( nWhich );
845 
846         nWhich = aIter.NextWhich();
847     }
848 }
849 
ExecSearch(SfxRequest & rReq)850 void SwAnnotationShell::ExecSearch(SfxRequest& rReq)
851 {
852     rView.ExecSearch(rReq);
853 }
854 
StateSearch(SfxItemSet & rSet)855 void SwAnnotationShell::StateSearch(SfxItemSet &rSet)
856 {
857     rView.StateSearch(rSet);
858 }
859 
ExecClpbrd(SfxRequest const & rReq)860 void SwAnnotationShell::ExecClpbrd(SfxRequest const &rReq)
861 {
862     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
863     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
864         return;
865 
866     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
867 
868     tools::Long aOldHeight = pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight();
869     sal_uInt16 nSlot = rReq.GetSlot();
870     switch (nSlot)
871     {
872         case SID_CUT:
873             if ( (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED) && pOLV->HasSelection() )
874                 pOLV->Cut();
875             break;
876         case SID_COPY:
877             if( pOLV->HasSelection() )
878                 pOLV->Copy();
879             break;
880         case SID_PASTE:
881             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
882                 pOLV->PasteSpecial();
883             break;
884         case SID_PASTE_UNFORMATTED:
885             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
886                 pOLV->Paste();
887             break;
888         case SID_PASTE_SPECIAL:
889         {
890             if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED)
891             {
892                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
893                 ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(rView.GetEditWin().GetFrameWeld()));
894 
895                 pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
896                 pDlg->Insert( SotClipboardFormatId::RTF,    OUString() );
897                 pDlg->Insert( SotClipboardFormatId::RICHTEXT,    OUString() );
898 
899                 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
900 
901                 SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
902 
903                 if (nFormat != SotClipboardFormatId::NONE)
904                 {
905                     if (nFormat == SotClipboardFormatId::STRING)
906                         pOLV->Paste();
907                     else
908                         pOLV->PasteSpecial();
909                 }
910             }
911             break;
912         }
913         case SID_CLIPBOARD_FORMAT_ITEMS:
914         {
915             SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
916             const SfxPoolItem* pItem;
917             if (rReq.GetArgs() && rReq.GetArgs()->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
918             {
919                 if (const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item *>(pItem))
920                     nFormat = static_cast<SotClipboardFormatId>(pUInt32Item->GetValue());
921             }
922 
923             if ( nFormat != SotClipboardFormatId::NONE )
924             {
925                 if (SotClipboardFormatId::STRING == nFormat)
926                     pOLV->Paste();
927                 else
928                     pOLV->PasteSpecial();
929             }
930             break;
931         }
932     }
933     pPostItMgr->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight,pPostItMgr->GetActiveSidebarWin()->GetPostItTextHeight());
934 }
935 
StateClpbrd(SfxItemSet & rSet)936 void SwAnnotationShell::StateClpbrd(SfxItemSet &rSet)
937 {
938     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
939     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
940         return;
941     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
942 
943     TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( &rView.GetEditWin() ) );
944     bool bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF )
945         || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ));
946     bPastePossible = bPastePossible &&  (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()!=SwPostItHelper::DELETED);
947 
948     SfxWhichIter aIter(rSet);
949     sal_uInt16 nWhich = aIter.FirstWhich();
950 
951     while(nWhich)
952     {
953         switch(nWhich)
954         {
955             case SID_CUT:
956             {
957                 if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus() == SwPostItHelper::DELETED)
958                     rSet.DisableItem( nWhich );
959                 [[fallthrough]];
960             }
961             case SID_COPY:
962             {
963                 SfxObjectShell* pObjectShell = GetObjectShell();
964                 if (!pOLV->HasSelection() || (pObjectShell && pObjectShell->isContentExtractionLocked()) )
965                     rSet.DisableItem( nWhich );
966                 break;
967             }
968             case SID_PASTE:
969             case SID_PASTE_UNFORMATTED:
970             case SID_PASTE_SPECIAL:
971                 {
972                     if( !bPastePossible )
973                         rSet.DisableItem( nWhich );
974                     break;
975                 }
976             case SID_CLIPBOARD_FORMAT_ITEMS:
977                 {
978                     if ( bPastePossible )
979                     {
980                         SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
981                         if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
982                             aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
983                         if ( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) )
984                             aFormats.AddClipbrdFormat( SotClipboardFormatId::RICHTEXT );
985                         aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
986                         rSet.Put( aFormats );
987                     }
988                     else
989                         rSet.DisableItem( nWhich );
990                     break;
991                 }
992         }
993         nWhich = aIter.NextWhich();
994     }
995 }
996 
StateStatusLine(SfxItemSet & rSet)997 void SwAnnotationShell::StateStatusLine(SfxItemSet &rSet)
998 {
999     SfxWhichIter aIter( rSet );
1000     sal_uInt16 nWhich = aIter.FirstWhich();
1001 
1002     while( nWhich )
1003     {
1004         switch( nWhich )
1005         {
1006             case FN_STAT_SELMODE:
1007             {
1008                 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE, 0));
1009                 rSet.DisableItem( nWhich );
1010                 break;
1011             }
1012             case FN_STAT_TEMPLATE:
1013             {
1014                 rSet.DisableItem( nWhich );
1015                 break;
1016             }
1017         }
1018         nWhich = aIter.NextWhich();
1019     }
1020 }
1021 
StateInsert(SfxItemSet & rSet)1022 void SwAnnotationShell::StateInsert(SfxItemSet &rSet)
1023 {
1024     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1025     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1026         return;
1027 
1028     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1029     SfxWhichIter aIter(rSet);
1030     sal_uInt16 nWhich = aIter.FirstWhich();
1031 
1032     while(nWhich)
1033     {
1034         switch(nWhich)
1035         {
1036             case SID_HYPERLINK_GETLINK:
1037                 {
1038                     SvxHyperlinkItem aHLinkItem;
1039                     aHLinkItem.SetInsertMode(HLINK_FIELD);
1040 
1041                     const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
1042 
1043                     if (pFieldItem)
1044                     {
1045                         if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField *>(pFieldItem->GetField()))
1046                         {
1047                             aHLinkItem.SetName(pURLField->GetRepresentation());
1048                             aHLinkItem.SetURL(pURLField->GetURL());
1049                             aHLinkItem.SetTargetFrame(pURLField->GetTargetFrame());
1050                         }
1051                     }
1052                     else
1053                     {
1054                         OUString sSel(pOLV->GetSelected());
1055                         sSel = sSel.copy(0, std::min<sal_Int32>(255, sSel.getLength()));
1056                         aHLinkItem.SetName(comphelper::string::stripEnd(sSel, ' '));
1057                     }
1058 
1059                     sal_uInt16 nHtmlMode = ::GetHtmlMode(rView.GetDocShell());
1060                     aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
1061                         ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
1062 
1063                     rSet.Put(aHLinkItem);
1064                 }
1065                 break;
1066         }
1067 
1068         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1069             rSet.DisableItem( nWhich );
1070 
1071         nWhich = aIter.NextWhich();
1072     }
1073 }
1074 
NoteExec(SfxRequest const & rReq)1075 void SwAnnotationShell::NoteExec(SfxRequest const &rReq)
1076 {
1077     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1078     if ( !pPostItMgr )
1079         return;
1080 
1081     sal_uInt16 nSlot = rReq.GetSlot();
1082     switch (nSlot)
1083     {
1084         case FN_REPLY:
1085         case FN_POSTIT:
1086         case FN_DELETE_COMMENT:
1087         case FN_DELETE_COMMENT_THREAD:
1088         case FN_RESOLVE_NOTE:
1089         case FN_RESOLVE_NOTE_THREAD:
1090             if ( pPostItMgr->HasActiveSidebarWin() )
1091                 pPostItMgr->GetActiveSidebarWin()->ExecuteCommand(nSlot);
1092             break;
1093         case FN_DELETE_ALL_NOTES:
1094             pPostItMgr->Delete();
1095             break;
1096         case FN_FORMAT_ALL_NOTES:
1097             pPostItMgr->ExecuteFormatAllDialog(rView);
1098             break;
1099         case FN_DELETE_NOTE_AUTHOR:
1100         {
1101             const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1102             if ( pItem )
1103                 pPostItMgr->Delete( pItem->GetValue() );
1104             else if ( pPostItMgr->HasActiveSidebarWin() )
1105                 pPostItMgr->Delete( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1106             break;
1107         }
1108         case FN_HIDE_NOTE:
1109             break;
1110         case FN_HIDE_ALL_NOTES:
1111             pPostItMgr->Hide();
1112             break;
1113         case FN_HIDE_NOTE_AUTHOR:
1114         {
1115             const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1116             if ( pItem )
1117                 pPostItMgr->Hide( pItem->GetValue() );
1118             else if ( pPostItMgr->HasActiveSidebarWin() )
1119                 pPostItMgr->Hide( pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1120         }
1121     }
1122 }
1123 
GetNoteState(SfxItemSet & rSet)1124 void SwAnnotationShell::GetNoteState(SfxItemSet &rSet)
1125 {
1126     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1127     SfxWhichIter aIter(rSet);
1128     sal_uInt16 nWhich = aIter.FirstWhich();
1129     while(nWhich)
1130     {
1131         sal_uInt16 nSlotId = GetPool().GetSlotId( nWhich );
1132         switch( nSlotId )
1133         {
1134         case FN_POSTIT:
1135         case FN_DELETE_ALL_NOTES:
1136         case FN_FORMAT_ALL_NOTES:
1137         case FN_HIDE_NOTE:
1138         case FN_HIDE_ALL_NOTES:
1139         case FN_DELETE_COMMENT:
1140         case FN_DELETE_COMMENT_THREAD:
1141             {
1142                 if( !pPostItMgr
1143                     || !pPostItMgr->HasActiveAnnotationWin() )
1144                 {
1145                     rSet.DisableItem(nWhich);
1146                 }
1147                 break;
1148             }
1149         case FN_RESOLVE_NOTE:
1150             {
1151                 if( !pPostItMgr
1152                     || !pPostItMgr->HasActiveAnnotationWin() )
1153                 {
1154                     rSet.DisableItem(nWhich);
1155                 }
1156                 else
1157                 {
1158                     SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsResolved());
1159                     rSet.Put( aBool );
1160                 }
1161                 break;
1162             }
1163         case FN_RESOLVE_NOTE_THREAD:
1164             {
1165                 if( !pPostItMgr
1166                     || !pPostItMgr->HasActiveAnnotationWin() )
1167                 {
1168                     rSet.DisableItem(nWhich);
1169                 }
1170                 else
1171                 {
1172                     SfxBoolItem aBool(nWhich, pPostItMgr->GetActiveSidebarWin()->IsThreadResolved());
1173                     rSet.Put( aBool );
1174                 }
1175                 break;
1176             }
1177         case FN_DELETE_NOTE_AUTHOR:
1178         case FN_HIDE_NOTE_AUTHOR:
1179         {
1180             if( !pPostItMgr
1181                 || !pPostItMgr->HasActiveAnnotationWin() )
1182             {
1183                 rSet.DisableItem(nWhich);
1184             }
1185             else
1186             {
1187                 OUString aText( nSlotId == FN_DELETE_NOTE_AUTHOR ?
1188                                 SwResId( STR_DELETE_NOTE_AUTHOR ) : SwResId( STR_HIDE_NOTE_AUTHOR ) );
1189                 SwRewriter aRewriter;
1190                 aRewriter.AddRule( UndoArg1, pPostItMgr->GetActiveSidebarWin()->GetAuthor() );
1191                 aText = aRewriter.Apply( aText );
1192                 SfxStringItem aItem( nSlotId, aText );
1193                 rSet.Put( aItem );
1194             }
1195             break;
1196         }
1197         case FN_REPLY:
1198             {
1199                 if ( !pPostItMgr ||
1200                      !pPostItMgr->HasActiveAnnotationWin() )
1201                 {
1202                     rSet.DisableItem(nWhich);
1203                 }
1204                 else
1205                 {
1206                     SvtUserOptions aUserOpt;
1207                     OUString sAuthor;
1208                     if( (sAuthor = aUserOpt.GetFullName()).isEmpty() &&
1209                         (sAuthor = aUserOpt.GetID()).isEmpty() )
1210                         sAuthor = SwResId( STR_REDLINE_UNKNOWN_AUTHOR );
1211                     if (sAuthor == pPostItMgr->GetActiveSidebarWin()->GetAuthor())
1212                         rSet.DisableItem(nWhich);
1213                 }
1214                 break;
1215             }
1216             default:
1217                 rSet.InvalidateItem( nWhich );
1218                 break;
1219         }
1220 
1221         if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
1222         {
1223             if ( (pPostItMgr->GetActiveSidebarWin()->IsProtected()) &&
1224                     ( (nSlotId==FN_DELETE_COMMENT) || (nSlotId==FN_REPLY) ) )
1225                 rSet.DisableItem( nWhich );
1226         }
1227         nWhich = aIter.NextWhich();
1228     }
1229 }
1230 
ExecLingu(SfxRequest & rReq)1231 void SwAnnotationShell::ExecLingu(SfxRequest &rReq)
1232 {
1233     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1234     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1235         return;
1236 
1237     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1238     sal_uInt16 nSlot = rReq.GetSlot();
1239     SwWrtShell &rSh = rView.GetWrtShell();
1240     bool bRestoreSelection = false;
1241     ESelection aOldSelection;
1242 
1243     switch (nSlot)
1244     {
1245         case SID_LANGUAGE_STATUS:
1246         {
1247             aOldSelection = pOLV->GetSelection();
1248             if (!pOLV->GetEditView().HasSelection())
1249             {
1250                 pOLV->GetEditView().SelectCurrentWord();
1251             }
1252 
1253             bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh);
1254             break;
1255         }
1256         case SID_THES:
1257         {
1258             OUString aReplaceText;
1259             const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES);
1260             if (pItem2)
1261                 aReplaceText = pItem2->GetValue();
1262             if (!aReplaceText.isEmpty())
1263                 ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText );
1264             break;
1265         }
1266         case SID_THESAURUS:
1267         {
1268             pOLV->StartThesaurus(rReq.GetFrameWeld());
1269             break;
1270         }
1271         case SID_HANGUL_HANJA_CONVERSION:
1272             pOLV->StartTextConversion(rReq.GetFrameWeld(), LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr,
1273                     i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true, false);
1274             break;
1275 
1276         case SID_CHINESE_CONVERSION:
1277         {
1278                 //open ChineseTranslationDialog
1279                 Reference< XComponentContext > xContext(
1280                     ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1281                 if(xContext.is())
1282                 {
1283                     Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1284                     if(xMCF.is())
1285                     {
1286                         Reference< ui::dialogs::XExecutableDialog > xDialog(
1287                                 xMCF->createInstanceWithContext(
1288                                     "com.sun.star.linguistic2.ChineseTranslationDialog", xContext),
1289                                 UNO_QUERY);
1290                         Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1291                         if( xInit.is() )
1292                         {
1293                             //  initialize dialog
1294                             uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
1295                             {
1296                                 {"ParentWindow", uno::Any(Reference<awt::XWindow>())}
1297                             }));
1298                             xInit->initialize( aSeq );
1299 
1300                             //execute dialog
1301                             sal_Int16 nDialogRet = xDialog->execute();
1302                             if( RET_OK == nDialogRet )
1303                             {
1304                                 //get some parameters from the dialog
1305                                 bool bToSimplified = true;
1306                                 bool bUseVariants = true;
1307                                 bool bCommonTerms = true;
1308                                 Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
1309                                 if( xProp.is() )
1310                                 {
1311                                     try
1312                                     {
1313                                         xProp->getPropertyValue( "IsDirectionToSimplified" ) >>= bToSimplified;
1314                                         xProp->getPropertyValue( "IsUseCharacterVariants" ) >>= bUseVariants;
1315                                         xProp->getPropertyValue( "IsTranslateCommonTerms" ) >>= bCommonTerms;
1316                                     }
1317                                     catch (const Exception&)
1318                                     {
1319                                     }
1320                                 }
1321 
1322                                 //execute translation
1323                                 LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1324                                 LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1325                                 sal_Int32 nOptions       = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1326                                 if( !bCommonTerms )
1327                                     nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1328 
1329                                 vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT,
1330                                             nTargetLang, GetDefaultFontFlags::OnlyOne );
1331 
1332                                 pOLV->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
1333                             }
1334                         }
1335                         Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1336                         if( xComponent.is() )
1337                             xComponent->dispose();
1338                     }
1339                 }
1340             }
1341             break;
1342     }
1343 
1344     if (bRestoreSelection)
1345     {
1346         // restore selection
1347         pOLV->GetEditView().SetSelection( aOldSelection );
1348     }
1349 }
1350 
GetLinguState(SfxItemSet & rSet)1351 void SwAnnotationShell::GetLinguState(SfxItemSet &rSet)
1352 {
1353     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1354     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1355         return;
1356 
1357     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1358 
1359     SfxWhichIter aIter(rSet);
1360     sal_uInt16 nWhich = aIter.FirstWhich();
1361     while(nWhich)
1362     {
1363         switch (nWhich)
1364         {
1365             case SID_LANGUAGE_STATUS:
1366             {
1367                 SwLangHelper::GetLanguageStatus(pOLV,rSet);
1368                 break;
1369             }
1370 
1371             case SID_THES:
1372             {
1373                 OUString        aStatusVal;
1374                 LanguageType    nLang = LANGUAGE_NONE;
1375                 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() );
1376                 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
1377 
1378                 // disable "Thesaurus" context menu entry if there is nothing to look up
1379                 uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1380                 if (!bIsLookUpWord ||
1381                     !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1382                     rSet.DisableItem( SID_THES );
1383                 break;
1384             }
1385 
1386             // disable "Thesaurus" if the language is not supported
1387             case SID_THESAURUS:
1388             {
1389                 const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault(
1390                             GetWhichOfScript( RES_CHRATR_LANGUAGE,
1391                             SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage())) );
1392                 LanguageType nLang = static_cast<const SvxLanguageItem &>(
1393                                                         rItem).GetLanguage();
1394                 uno::Reference< linguistic2::XThesaurus >  xThes( ::GetThesaurus() );
1395                 if (!xThes.is() || nLang == LANGUAGE_NONE ||
1396                     !xThes->hasLocale( LanguageTag::convertToLocale( nLang ) ))
1397                     rSet.DisableItem( SID_THESAURUS );
1398             }
1399             break;
1400             case SID_HANGUL_HANJA_CONVERSION:
1401             case SID_CHINESE_CONVERSION:
1402             {
1403                 if (!SvtCJKOptions().IsAnyEnabled())
1404                 {
1405                     rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, false );
1406                     rSet.DisableItem(nWhich);
1407                 }
1408                 else
1409                     rView.GetViewFrame()->GetBindings().SetVisibleState( nWhich, true );
1410             }
1411             break;
1412         }
1413 
1414         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1415             rSet.DisableItem( nWhich );
1416 
1417         nWhich = aIter.NextWhich();
1418     }
1419 }
1420 
ExecTransliteration(SfxRequest const & rReq)1421 void SwAnnotationShell::ExecTransliteration(SfxRequest const &rReq)
1422 {
1423     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1424     if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1425         return;
1426 
1427     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1428 
1429     if (!pOLV)
1430         return;
1431 
1432     TransliterationFlags nMode = TransliterationFlags::NONE;
1433 
1434     switch( rReq.GetSlot() )
1435     {
1436         case SID_TRANSLITERATE_SENTENCE_CASE:
1437             nMode = TransliterationFlags::SENTENCE_CASE;
1438             break;
1439         case SID_TRANSLITERATE_TITLE_CASE:
1440             nMode = TransliterationFlags::TITLE_CASE;
1441             break;
1442         case SID_TRANSLITERATE_TOGGLE_CASE:
1443             nMode = TransliterationFlags::TOGGLE_CASE;
1444             break;
1445         case SID_TRANSLITERATE_UPPER:
1446             nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
1447             break;
1448         case SID_TRANSLITERATE_LOWER:
1449             nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
1450             break;
1451         case SID_TRANSLITERATE_HALFWIDTH:
1452             nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
1453             break;
1454         case SID_TRANSLITERATE_FULLWIDTH:
1455             nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
1456             break;
1457         case SID_TRANSLITERATE_HIRAGANA:
1458             nMode = TransliterationFlags::KATAKANA_HIRAGANA;
1459             break;
1460         case SID_TRANSLITERATE_KATAKANA:
1461             nMode = TransliterationFlags::HIRAGANA_KATAKANA;
1462             break;
1463 
1464         default:
1465             OSL_ENSURE(false, "wrong dispatcher");
1466     }
1467 
1468     if( nMode != TransliterationFlags::NONE )
1469         pOLV->TransliterateText( nMode );
1470 }
1471 
ExecRotateTransliteration(SfxRequest const & rReq)1472 void SwAnnotationShell::ExecRotateTransliteration( SfxRequest const & rReq )
1473 {
1474     if( rReq.GetSlot() != SID_TRANSLITERATE_ROTATE_CASE )
1475         return;
1476 
1477     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1478     if (!pPostItMgr || !pPostItMgr->HasActiveSidebarWin())
1479         return;
1480 
1481     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1482 
1483     if (!pOLV)
1484         return;
1485 
1486     pOLV->TransliterateText(m_aRotateCase.getNextMode());
1487 }
1488 
ExecUndo(SfxRequest & rReq)1489 void SwAnnotationShell::ExecUndo(SfxRequest &rReq)
1490 {
1491     const SfxItemSet* pArgs = rReq.GetArgs();
1492     SfxUndoManager* pUndoManager = GetUndoManager();
1493     SwWrtShell &rSh = rView.GetWrtShell();
1494     SwUndoId nUndoId(SwUndoId::EMPTY);
1495 
1496     tools::Long aOldHeight = rView.GetPostItMgr()->HasActiveSidebarWin()
1497                       ? rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight()
1498                       : 0;
1499 
1500     sal_uInt16 nId = rReq.GetSlot();
1501     sal_uInt16 nCnt = 1;
1502     const SfxPoolItem* pItem=nullptr;
1503     if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ) )
1504         nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1505     switch( nId )
1506     {
1507         case SID_UNDO:
1508         {
1509             rSh.GetLastUndoInfo(nullptr, &nUndoId);
1510             if (nUndoId == SwUndoId::CONFLICT)
1511             {
1512                 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1513                 break;
1514             }
1515 
1516             if ( pUndoManager )
1517             {
1518                 sal_uInt16 nCount = pUndoManager->GetUndoActionCount();
1519                 sal_uInt16 nSteps = nCnt;
1520                 if ( nCount < nCnt )
1521                 {
1522                     nCnt = nCnt - nCount;
1523                     nSteps = nCount;
1524                 }
1525                 else
1526                     nCnt = 0;
1527 
1528                 while( nSteps-- )
1529                     pUndoManager->Undo();
1530             }
1531 
1532             if ( nCnt )
1533                 rSh.Do( SwWrtShell::UNDO, nCnt );
1534 
1535             break;
1536         }
1537 
1538         case SID_REDO:
1539         {
1540             (void)rSh.GetFirstRedoInfo(nullptr, &nUndoId);
1541             if (nUndoId == SwUndoId::CONFLICT)
1542             {
1543                 rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1544                 break;
1545             }
1546 
1547             if ( pUndoManager )
1548             {
1549                 sal_uInt16 nCount = pUndoManager->GetRedoActionCount();
1550                 sal_uInt16 nSteps = nCnt;
1551                 if ( nCount < nCnt )
1552                 {
1553                     nCnt = nCnt - nCount;
1554                     nSteps = nCount;
1555                 }
1556                 else
1557                     nCnt = 0;
1558 
1559                 while( nSteps-- )
1560                     pUndoManager->Redo();
1561             }
1562 
1563             if ( nCnt )
1564                 rSh.Do( SwWrtShell::REDO, nCnt );
1565 
1566             break;
1567         }
1568     }
1569 
1570     rView.GetViewFrame()->GetBindings().InvalidateAll(false);
1571 
1572     if (rView.GetPostItMgr()->HasActiveSidebarWin())
1573         rView.GetPostItMgr()->GetActiveSidebarWin()->ResizeIfNecessary(aOldHeight,rView.GetPostItMgr()->GetActiveSidebarWin()->GetPostItTextHeight());
1574 }
1575 
StateUndo(SfxItemSet & rSet)1576 void SwAnnotationShell::StateUndo(SfxItemSet &rSet)
1577 {
1578     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1579     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1580         return;
1581 
1582     SfxWhichIter aIter(rSet);
1583     SwUndoId nUndoId(SwUndoId::EMPTY);
1584     sal_uInt16 nWhich = aIter.FirstWhich();
1585     SfxUndoManager* pUndoManager = GetUndoManager();
1586     SfxViewFrame *pSfxViewFrame = rView.GetViewFrame();
1587     SwWrtShell &rSh = rView.GetWrtShell();
1588 
1589     while( nWhich )
1590     {
1591         switch ( nWhich )
1592         {
1593         case SID_UNDO:
1594             {
1595                 sal_uInt16 nCount = pUndoManager ? pUndoManager->GetUndoActionCount() : 0;
1596                 if ( nCount )
1597                     pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1598                 else if (rSh.GetLastUndoInfo(nullptr, &nUndoId))
1599                 {
1600                     rSet.Put( SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::UNDO)) );
1601                 }
1602                 else if (nUndoId == SwUndoId::CONFLICT)
1603                 {
1604                     rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1605                 }
1606                 else
1607                     rSet.DisableItem(nWhich);
1608                 break;
1609             }
1610         case SID_REDO:
1611             {
1612                 sal_uInt16 nCount = pUndoManager ? pUndoManager->GetRedoActionCount() : 0;
1613                 if ( nCount )
1614                     pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1615                 else if (rSh.GetFirstRedoInfo(nullptr, &nUndoId))
1616                 {
1617                     rSet.Put(SfxStringItem( nWhich, rSh.GetDoString(SwWrtShell::REDO)) );
1618                 }
1619                 else if (nUndoId == SwUndoId::CONFLICT)
1620                 {
1621                     rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
1622                 }
1623                 else
1624                     rSet.DisableItem(nWhich);
1625                 break;
1626             }
1627         case SID_GETUNDOSTRINGS:
1628         case SID_GETREDOSTRINGS:
1629             {
1630                 if( pUndoManager )
1631                 {
1632                     OUString (SfxUndoManager::*fnGetComment)( size_t, bool const ) const;
1633 
1634                     sal_uInt16 nCount;
1635                     if( SID_GETUNDOSTRINGS == nWhich )
1636                     {
1637                         nCount = pUndoManager->GetUndoActionCount();
1638                         fnGetComment = &SfxUndoManager::GetUndoActionComment;
1639                     }
1640                     else
1641                     {
1642                         nCount = pUndoManager->GetRedoActionCount();
1643                         fnGetComment = &SfxUndoManager::GetRedoActionComment;
1644                     }
1645 
1646                     OUStringBuffer sList;
1647                     if( nCount )
1648                     {
1649                         for( sal_uInt16 n = 0; n < nCount; ++n )
1650                             sList.append( (pUndoManager->*fnGetComment)( n, SfxUndoManager::TopLevel ) + "\n");
1651                     }
1652 
1653                     SfxStringListItem aItem( nWhich );
1654                     if ((nWhich == SID_GETUNDOSTRINGS) &&
1655                         rSh.GetLastUndoInfo(nullptr, nullptr))
1656                     {
1657                         rSh.GetDoStrings( SwWrtShell::UNDO, aItem );
1658                     }
1659                     else if ((nWhich == SID_GETREDOSTRINGS) &&
1660                              (rSh.GetFirstRedoInfo(nullptr, nullptr)))
1661                     {
1662                         rSh.GetDoStrings( SwWrtShell::REDO, aItem );
1663                     }
1664 
1665                     sList.append(aItem.GetString());
1666                     aItem.SetString( sList.makeStringAndClear() );
1667                     rSet.Put( aItem );
1668                 }
1669                 else
1670                     rSet.DisableItem( nWhich );
1671             }
1672             break;
1673 
1674         default:
1675             {
1676                 pSfxViewFrame->GetSlotState( nWhich, pSfxViewFrame->GetInterface(), &rSet );
1677                 break;
1678             }
1679 
1680         }
1681 
1682         if (pPostItMgr->GetActiveSidebarWin()->GetLayoutStatus()==SwPostItHelper::DELETED)
1683             rSet.DisableItem( nWhich );
1684 
1685         nWhich = aIter.NextWhich();
1686     }
1687 }
1688 
StateDisableItems(SfxItemSet & rSet)1689 void SwAnnotationShell::StateDisableItems( SfxItemSet &rSet )
1690 {
1691     SfxWhichIter aIter(rSet);
1692     sal_uInt16 nWhich = aIter.FirstWhich();
1693     while (nWhich)
1694     {
1695         rSet.DisableItem( nWhich );
1696         nWhich = aIter.NextWhich();
1697     }
1698 }
1699 
InsertSymbol(SfxRequest & rReq)1700 void SwAnnotationShell::InsertSymbol(SfxRequest& rReq)
1701 {
1702     SwPostItMgr* pPostItMgr = rView.GetPostItMgr();
1703     if ( !pPostItMgr || !pPostItMgr->HasActiveSidebarWin() )
1704         return;
1705 
1706     OutlinerView* pOLV = pPostItMgr->GetActiveSidebarWin()->GetOutlinerView();
1707 
1708     const SfxItemSet *pArgs = rReq.GetArgs();
1709     const SfxPoolItem* pItem = nullptr;
1710     if( pArgs )
1711         pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
1712 
1713     OUString sSym;
1714     OUString sFontName;
1715     if ( pItem )
1716     {
1717         sSym = static_cast<const SfxStringItem*>(pItem)->GetValue();
1718         const SfxPoolItem* pFtItem = nullptr;
1719         pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
1720 
1721         if (const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>(pFtItem))
1722             sFontName = pFontItem->GetValue();
1723     }
1724 
1725     SfxItemSet aSet(pOLV->GetAttribs());
1726     SvtScriptType nScript = pOLV->GetSelectedScriptType();
1727     std::shared_ptr<SvxFontItem> aSetDlgFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
1728     {
1729         SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
1730         aSetItem.GetItemSet().Put( aSet, false );
1731         const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
1732         if( pI )
1733         {
1734             aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
1735         }
1736         else
1737         {
1738             aSetDlgFont.reset(static_cast<SvxFontItem*>(aSet.Get( GetWhichOfScript(
1739                         SID_ATTR_CHAR_FONT,
1740                         SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) )).Clone()));
1741         }
1742 
1743         if (sFontName.isEmpty())
1744             sFontName = aSetDlgFont->GetFamilyName();
1745     }
1746 
1747     vcl::Font aFont(sFontName, Size(1,1));
1748     if( sSym.isEmpty() )
1749     {
1750         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1751 
1752         SfxAllItemSet aAllSet( GetPool() );
1753         aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
1754 
1755         SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
1756         const OUString& sSymbolFont = aOpt.GetSymbolFont();
1757         if( !sSymbolFont.isEmpty() )
1758             aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
1759         else
1760             aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont->GetFamilyName() ) );
1761 
1762         // If character is selected then it can be shown.
1763         auto xFrame = rView.GetViewFrame()->GetFrame().GetFrameInterface();
1764         ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(rView.GetFrameWeld(), aAllSet, xFrame));
1765         pDlg->Execute();
1766         return;
1767     }
1768 
1769     // do not flicker
1770     pOLV->HideCursor();
1771     Outliner * pOutliner = pOLV->GetOutliner();
1772     pOutliner->SetUpdateMode(false);
1773 
1774     SfxItemSet aOldSet( pOLV->GetAttribs() );
1775     SfxItemSet aFontSet(
1776         *aOldSet.GetPool(),
1777         svl::Items<
1778             EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
1779             EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL>{});
1780     aFontSet.Set( aOldSet );
1781 
1782     // Insert string
1783     pOLV->InsertText( sSym);
1784 
1785     // Attributing (set font)
1786     SfxItemSet aSetFont( *aFontSet.GetPool(), aFontSet.GetRanges() );
1787     SvxFontItem aFontItem (aFont.GetFamilyType(), aFont.GetFamilyName(),
1788                             aFont.GetStyleName(), aFont.GetPitch(),
1789                             aFont.GetCharSet(),
1790                             EE_CHAR_FONTINFO );
1791     SvtScriptType nScriptBreak = g_pBreakIt->GetAllScriptsOfText( sSym );
1792     if( SvtScriptType::LATIN & nScriptBreak )
1793         aSetFont.Put( aFontItem );
1794     if( SvtScriptType::ASIAN & nScriptBreak )
1795     {
1796         aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
1797         aSetFont.Put( aFontItem );
1798     }
1799     if( SvtScriptType::COMPLEX & nScriptBreak )
1800     {
1801         aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
1802         aSetFont.Put( aFontItem );
1803     }
1804     pOLV->SetAttribs(aSetFont);
1805 
1806     // Erase selection
1807     ESelection aSel(pOLV->GetSelection());
1808     aSel.nStartPara = aSel.nEndPara;
1809     aSel.nStartPos = aSel.nEndPos;
1810     pOLV->SetSelection(aSel);
1811 
1812     // Restore old font
1813     pOLV->SetAttribs( aFontSet );
1814 
1815     // From now on show it again
1816     pOutliner->SetUpdateMode(true);
1817     pOLV->ShowCursor();
1818 
1819     rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP), sSym ) );
1820     if(!aFont.GetFamilyName().isEmpty())
1821         rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetFamilyName() ) );
1822     rReq.Done();
1823 
1824 }
1825 
1826 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1827