Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / drwtxtsh.cxx
blobe767c8b86c1137752089f3623dc1e65c244bbe10
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>
21 #include <i18nlangtag/lang.h>
22 #include <i18nutil/transliteration.hxx>
23 #include <rtl/ustrbuf.hxx>
24 #include <svl/slstitm.hxx>
25 #include <svl/stritem.hxx>
26 #include <editeng/fontitem.hxx>
27 #include <svx/svdview.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/objface.hxx>
30 #include <svx/svdotext.hxx>
31 #include <svx/sdooitm.hxx>
32 #include <editeng/editeng.hxx>
33 #include <editeng/editview.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <editeng/scripttypeitem.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <svx/fontwork.hxx>
38 #include <sfx2/request.hxx>
39 #include <vcl/EnumContext.hxx>
40 #include <svl/whiter.hxx>
41 #include <editeng/outliner.hxx>
42 #include <editeng/editstat.hxx>
43 #include <svx/svdoutl.hxx>
44 #include <com/sun/star/i18n/TextConversionOption.hpp>
45 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
46 #include <com/sun/star/lang/XInitialization.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/awt/XWindow.hpp>
49 #include <com/sun/star/uno/XComponentContext.hpp>
50 #include <comphelper/propertysequence.hxx>
51 #include <osl/diagnose.h>
52 #include <swtypes.hxx>
53 #include <view.hxx>
54 #include <wrtsh.hxx>
55 #include <viewopt.hxx>
56 #include <drwtxtsh.hxx>
57 #include <breakit.hxx>
59 #include <cmdid.h>
61 #define ShellClass_SwDrawTextShell
62 #include <sfx2/msg.hxx>
63 #include <swslots.hxx>
64 #include <uitool.hxx>
65 #include <wview.hxx>
66 #include <swmodule.hxx>
67 #include <svx/svdoashp.hxx>
68 #include <svx/svxdlg.hxx>
69 #include <comphelper/processfactory.hxx>
70 #include <IDocumentUndoRedo.hxx>
71 #include <memory>
73 using namespace ::com::sun::star;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::beans;
76 using namespace ::com::sun::star::i18n;
78 SFX_IMPL_INTERFACE(SwDrawTextShell, SfxShell)
80 void SwDrawTextShell::InitInterface_Impl()
82 GetStaticInterface()->RegisterPopupMenu("drawtext");
84 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Draw_Text_Toolbox_Sw);
86 GetStaticInterface()->RegisterChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
90 void SwDrawTextShell::Init()
92 SwWrtShell &rSh = GetShell();
93 m_pSdrView = rSh.GetDrawView();
94 SdrOutliner * pOutliner = m_pSdrView->GetTextEditOutliner();
95 //#97471# mouse click _and_ key input at the same time
96 if( !pOutliner )
97 return ;
98 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
99 EEControlBits nCtrl = pOutliner->GetControlWord();
100 nCtrl |= EEControlBits::AUTOCORRECT;
102 SetUndoManager(&pOutliner->GetUndoManager());
104 // Now let's try an AutoSpell.
106 const SwViewOption* pVOpt = rSh.GetViewOptions();
107 if(pVOpt->IsOnlineSpell())
109 nCtrl |= EEControlBits::ONLINESPELLING|EEControlBits::ALLOWBIGOBJS;
111 else
112 nCtrl &= ~EEControlBits::ONLINESPELLING;
114 pOutliner->SetControlWord(nCtrl);
115 pOLV->ShowCursor();
118 SwDrawTextShell::SwDrawTextShell(SwView &rV) :
119 SfxShell(&rV),
120 m_rView(rV)
122 SwWrtShell &rSh = GetShell();
123 SetPool(rSh.GetAttrPool().GetSecondaryPool());
125 // Initialize and show cursor to start editing.
126 Init();
128 SetName("ObjectText");
129 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::DrawText));
132 SwDrawTextShell::~SwDrawTextShell()
134 if ( GetView().GetCurShell() == this )
135 m_rView.ResetSubShell();
138 SwWrtShell& SwDrawTextShell::GetShell()
140 return m_rView.GetWrtShell();
143 // Disable slots with this status method
145 void SwDrawTextShell::StateDisableItems( SfxItemSet &rSet )
147 SfxWhichIter aIter(rSet);
148 sal_uInt16 nWhich = aIter.FirstWhich();
150 while (nWhich)
152 rSet.DisableItem( nWhich );
153 nWhich = aIter.NextWhich();
157 void SwDrawTextShell::SetAttrToMarked(const SfxItemSet& rAttr)
159 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
160 tools::Rectangle aOutRect = pOLV->GetOutputArea();
162 if (tools::Rectangle() != aOutRect)
164 GetShell().GetDrawView()->SetAttributes(rAttr);
168 bool SwDrawTextShell::IsTextEdit() const
170 return m_pSdrView->IsTextEdit();
173 void SwDrawTextShell::ExecFontWork(SfxRequest const & rReq)
175 SwWrtShell &rSh = GetShell();
176 FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &rSh.GetView()) != nullptr );
177 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
178 SfxViewFrame& rVFrame = GetView().GetViewFrame();
179 if ( rReq.GetArgs() )
181 rVFrame.SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
182 static_cast<const SfxBoolItem&>( (rReq.GetArgs()->
183 Get(SID_FONTWORK))).GetValue());
185 else
186 rVFrame.ToggleChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
188 rVFrame.GetBindings().Invalidate(SID_FONTWORK);
191 void SwDrawTextShell::StateFontWork(SfxItemSet& rSet)
193 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
194 rSet.Put(SfxBoolItem(SID_FONTWORK, GetView().GetViewFrame().HasChildWindow(nId)));
197 // Edit SfxRequests for FontWork
199 void SwDrawTextShell::ExecFormText(SfxRequest const & rReq)
201 SwWrtShell &rSh = GetShell();
202 SdrView* pDrView = rSh.GetDrawView();
204 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
206 if ( !(rMarkList.GetMarkCount() == 1 && rReq.GetArgs()) )
207 return;
209 const SfxItemSet& rSet = *rReq.GetArgs();
211 if ( pDrView->IsTextEdit() )
213 //#111733# Sometimes SdrEndTextEdit() initiates the change in selection and
214 // 'this' is not valid anymore
215 SwView& rTempView = GetView();
216 pDrView->SdrEndTextEdit(true);
217 //this removes the current shell from the dispatcher stack!!
218 rTempView.AttrChangedNotify(nullptr);
221 pDrView->SetAttributes(rSet);
225 // Return Status values back to FontWork
227 void SwDrawTextShell::GetFormTextState(SfxItemSet& rSet)
229 SwWrtShell &rSh = GetShell();
230 SdrView* pDrView = rSh.GetDrawView();
231 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
232 const SdrObject* pObj = nullptr;
234 if ( rMarkList.GetMarkCount() == 1 )
235 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
237 const SdrTextObj* pTextObj = DynCastSdrTextObj(pObj);
238 const bool bDeactivate(
239 !pObj ||
240 !pTextObj ||
241 !pTextObj->HasText() ||
242 dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
244 if (bDeactivate)
246 rSet.DisableItem(XATTR_FORMTXTSTYLE);
247 rSet.DisableItem(XATTR_FORMTXTADJUST);
248 rSet.DisableItem(XATTR_FORMTXTDISTANCE);
249 rSet.DisableItem(XATTR_FORMTXTSTART);
250 rSet.DisableItem(XATTR_FORMTXTMIRROR);
251 rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
252 rSet.DisableItem(XATTR_FORMTXTOUTLINE);
253 rSet.DisableItem(XATTR_FORMTXTSHADOW);
254 rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
255 rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
256 rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
258 else
260 pDrView->GetAttributes( rSet );
264 void SwDrawTextShell::ExecDrawLingu(SfxRequest const &rReq)
266 SwWrtShell &rSh = GetShell();
267 OutlinerView* pOutlinerView = m_pSdrView->GetTextEditOutlinerView();
268 if( !rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() )
269 return;
271 switch(rReq.GetSlot())
273 case SID_THESAURUS:
274 pOutlinerView->StartThesaurus(rReq.GetFrameWeld());
275 break;
277 case SID_HANGUL_HANJA_CONVERSION:
278 pOutlinerView->StartTextConversion(rReq.GetFrameWeld(),
279 LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr,
280 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true, false);
281 break;
283 case SID_CHINESE_CONVERSION:
285 //open ChineseTranslationDialog
286 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
287 if (!xContext.is())
288 return;
290 Reference<lang::XMultiComponentFactory> xMCF(xContext->getServiceManager());
291 if (!xMCF.is())
292 return;
294 Reference<ui::dialogs::XExecutableDialog> xDialog(
295 xMCF->createInstanceWithContext("com.sun.star.linguistic2.ChineseTranslationDialog", xContext), UNO_QUERY);
297 Reference<lang::XInitialization> xInit(xDialog, UNO_QUERY);
299 if (!xInit.is())
300 return;
302 // initialize dialog
303 uno::Sequence<uno::Any> aSequence(comphelper::InitAnyPropertySequence(
305 {"ParentWindow", uno::Any(Reference<awt::XWindow>())}
306 }));
307 xInit->initialize( aSequence );
309 //execute dialog
310 sal_Int16 nDialogRet = xDialog->execute();
311 if(RET_OK == nDialogRet)
313 //get some parameters from the dialog
314 bool bToSimplified = true;
315 bool bUseVariants = true;
316 bool bCommonTerms = true;
317 Reference<beans::XPropertySet> xPropertySet(xDialog, UNO_QUERY);
318 if (xPropertySet.is())
322 xPropertySet->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
323 xPropertySet->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
324 xPropertySet->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
326 catch (const Exception&)
331 //execute translation
332 LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
333 LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
334 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
335 if(!bCommonTerms)
336 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
338 vcl::Font aTargetFont = OutputDevice::GetDefaultFont(DefaultFontType::CJK_TEXT, nTargetLang, GetDefaultFontFlags::OnlyOne);
340 pOutlinerView->StartTextConversion(rReq.GetFrameWeld(), nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
343 Reference<lang::XComponent> xComponent(xDialog, UNO_QUERY);
344 if (xComponent.is())
345 xComponent->dispose();
347 break;
349 default:
350 OSL_ENSURE(false, "unexpected slot-id");
354 void SwDrawTextShell::ExecDraw(SfxRequest &rReq)
356 SwWrtShell &rSh = GetShell();
357 m_pSdrView = rSh.GetDrawView();
358 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
360 switch (rReq.GetSlot())
362 case FN_INSERT_SOFT_HYPHEN:
363 case FN_INSERT_HARDHYPHEN:
364 case FN_INSERT_HARD_SPACE:
365 case FN_INSERT_NNBSP:
366 case SID_INSERT_RLM :
367 case SID_INSERT_LRM :
368 case SID_INSERT_WJ :
369 case SID_INSERT_ZWSP:
371 sal_Unicode cIns = 0;
372 switch(rReq.GetSlot())
374 case FN_INSERT_SOFT_HYPHEN: cIns = CHAR_SOFTHYPHEN; break;
375 case FN_INSERT_HARDHYPHEN: cIns = CHAR_HARDHYPHEN; break;
376 case FN_INSERT_HARD_SPACE: cIns = CHAR_HARDBLANK; break;
377 case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break;
378 case SID_INSERT_RLM : cIns = CHAR_RLM ; break;
379 case SID_INSERT_LRM : cIns = CHAR_LRM ; break;
380 case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break;
381 case SID_INSERT_WJ: cIns = CHAR_WJ; break;
383 pOLV->InsertText( OUString(cIns));
384 rReq.Done();
386 break;
387 case SID_CHARMAP:
388 { // Insert special character
389 InsertSymbol(rReq);
390 break;
392 case FN_INSERT_STRING:
394 const SfxItemSet *pNewAttrs = rReq.GetArgs();
395 sal_uInt16 nSlot = rReq.GetSlot();
396 const SfxPoolItem* pItem = nullptr;
397 if(pNewAttrs)
399 pNewAttrs->GetItemState(nSlot, false, &pItem );
400 pOLV->InsertText(static_cast<const SfxStringItem *>(pItem)->GetValue());
402 break;
405 case SID_SELECTALL:
407 SdrOutliner * pOutliner = m_pSdrView->GetTextEditOutliner();
408 if(pOutliner)
410 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
411 if (nParaCount > 0)
412 pOLV->SelectRange(0, nParaCount );
415 break;
417 case FN_FORMAT_RESET: // delete hard text attributes
419 pOLV->RemoveAttribsKeepLanguages( true );
420 pOLV->GetEditView().GetEditEngine()->RemoveFields();
421 rReq.Done();
423 break;
425 case FN_ESCAPE:
426 if (m_pSdrView->IsTextEdit())
428 // Shell switch!
429 rSh.EndTextEdit();
430 SwView& rTempView = rSh.GetView();
431 rTempView.ExitDraw();
432 rSh.Edit();
433 return;
435 break;
436 case FN_DRAWTEXT_ATTR_DLG:
438 SfxItemSet aNewAttr(m_pSdrView->GetModel().GetItemPool());
439 m_pSdrView->GetAttributes( aNewAttr );
440 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
441 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(
442 GetView().GetFrameWeld(),
443 &aNewAttr, m_pSdrView ));
444 sal_uInt16 nResult = pDlg->Execute();
446 if (nResult == RET_OK)
448 if (m_pSdrView->AreObjectsMarked())
450 m_pSdrView->SetAttributes(*pDlg->GetOutputItemSet());
451 rReq.Done(*(pDlg->GetOutputItemSet()));
455 break;
456 case SID_TABLE_VERT_NONE:
457 case SID_TABLE_VERT_CENTER:
458 case SID_TABLE_VERT_BOTTOM:
460 sal_uInt16 nSId = rReq.GetSlot();
461 if (m_pSdrView->AreObjectsMarked())
463 SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_TOP;
464 if (nSId == SID_TABLE_VERT_CENTER)
465 eTVA = SDRTEXTVERTADJUST_CENTER;
466 else if (nSId == SID_TABLE_VERT_BOTTOM)
467 eTVA = SDRTEXTVERTADJUST_BOTTOM;
469 SfxItemSet aNewAttr(m_pSdrView->GetModel().GetItemPool());
470 m_pSdrView->GetAttributes( aNewAttr );
471 aNewAttr.Put(SdrTextVertAdjustItem(eTVA));
472 m_pSdrView->SetAttributes(aNewAttr);
473 rReq.Done();
477 break;
479 default:
480 OSL_ENSURE(false, "unexpected slot-id");
481 return;
484 GetView().GetViewFrame().GetBindings().InvalidateAll(false);
486 if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
487 rSh.SetModified();
490 // Execute undo
492 void SwDrawTextShell::ExecUndo(SfxRequest &rReq)
494 if( !IsTextEdit() )
495 return;
497 bool bCallBase = true;
498 const SfxItemSet* pArgs = rReq.GetArgs();
499 if( pArgs )
501 sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
502 const SfxPoolItem* pItem;
503 switch( nId )
505 case SID_UNDO:
506 case SID_REDO:
507 if( SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ) &&
508 1 < (nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue()) )
510 // then we make by ourself.
511 SfxUndoManager* pUndoManager = GetUndoManager();
512 if( pUndoManager )
514 if( SID_UNDO == nId )
515 while( nCnt-- )
516 pUndoManager->Undo();
517 else
518 while( nCnt-- )
519 pUndoManager->Redo();
521 bCallBase = false;
522 GetView().GetViewFrame().GetBindings().InvalidateAll(false);
524 break;
527 if( bCallBase )
529 SfxViewFrame& rSfxViewFrame = GetView().GetViewFrame();
530 rSfxViewFrame.ExecuteSlot(rReq, rSfxViewFrame.GetInterface());
534 // State of undo
536 void SwDrawTextShell::StateUndo(SfxItemSet &rSet)
538 if ( !IsTextEdit() )
539 return;
541 SfxViewFrame& rSfxViewFrame = GetView().GetViewFrame();
542 SfxWhichIter aIter(rSet);
543 sal_uInt16 nWhich = aIter.FirstWhich();
544 while( nWhich )
546 switch ( nWhich )
548 case SID_GETUNDOSTRINGS:
549 case SID_GETREDOSTRINGS:
551 SfxUndoManager* pUndoManager = GetUndoManager();
552 if( pUndoManager )
554 OUString (SfxUndoManager::*fnGetComment)( size_t, bool const ) const;
556 sal_uInt16 nCount;
557 if( SID_GETUNDOSTRINGS == nWhich )
559 nCount = pUndoManager->GetUndoActionCount();
560 fnGetComment = &SfxUndoManager::GetUndoActionComment;
562 else
564 nCount = pUndoManager->GetRedoActionCount();
565 fnGetComment = &SfxUndoManager::GetRedoActionComment;
567 if( nCount )
569 OUStringBuffer sList;
570 for( sal_uInt16 n = 0; n < nCount; ++n )
571 sList.append( (pUndoManager->*fnGetComment)( n, SfxUndoManager::TopLevel ) + "\n");
573 SfxStringListItem aItem( nWhich );
574 aItem.SetString( sList.makeStringAndClear() );
575 rSet.Put( aItem );
578 else
579 rSet.DisableItem( nWhich );
581 break;
583 default:
585 auto* pUndoManager = dynamic_cast<IDocumentUndoRedo*>(GetUndoManager());
586 if (pUndoManager)
587 pUndoManager->SetView(&GetView());
588 rSfxViewFrame.GetSlotState(nWhich, rSfxViewFrame.GetInterface(), &rSet);
589 if (pUndoManager)
590 pUndoManager->SetView(nullptr);
594 nWhich = aIter.NextWhich();
598 void SwDrawTextShell::ExecTransliteration( SfxRequest const & rReq )
600 if (!m_pSdrView)
601 return;
603 using namespace i18n;
605 TransliterationFlags nMode = TransliterationFlags::NONE;
607 switch( rReq.GetSlot() )
609 case SID_TRANSLITERATE_SENTENCE_CASE:
610 nMode = TransliterationFlags::SENTENCE_CASE;
611 break;
612 case SID_TRANSLITERATE_TITLE_CASE:
613 nMode = TransliterationFlags::TITLE_CASE;
614 break;
615 case SID_TRANSLITERATE_TOGGLE_CASE:
616 nMode = TransliterationFlags::TOGGLE_CASE;
617 break;
618 case SID_TRANSLITERATE_UPPER:
619 nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
620 break;
621 case SID_TRANSLITERATE_LOWER:
622 nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
623 break;
625 case SID_TRANSLITERATE_HALFWIDTH:
626 nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
627 break;
628 case SID_TRANSLITERATE_FULLWIDTH:
629 nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
630 break;
632 case SID_TRANSLITERATE_HIRAGANA:
633 nMode = TransliterationFlags::KATAKANA_HIRAGANA;
634 break;
635 case SID_TRANSLITERATE_KATAKANA:
636 nMode = TransliterationFlags::HIRAGANA_KATAKANA;
637 break;
639 default:
640 OSL_ENSURE(false, "wrong dispatcher");
643 if( nMode != TransliterationFlags::NONE )
645 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
647 if (!pOLV)
648 return;
650 pOLV->TransliterateText( nMode );
654 void SwDrawTextShell::ExecRotateTransliteration( SfxRequest const & rReq )
656 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
658 if (!m_pSdrView)
659 return;
661 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
663 if (!pOLV)
664 return;
666 pOLV->TransliterateText( m_aRotateCase.getNextMode() );
670 // Insert special character (see SDraw: FUBULLET.CXX)
672 void SwDrawTextShell::InsertSymbol(SfxRequest& rReq)
674 OutlinerView* pOLV = m_pSdrView->GetTextEditOutlinerView();
675 if(!pOLV)
676 return;
677 const SfxItemSet *pArgs = rReq.GetArgs();
678 const SfxStringItem* pItem = nullptr;
679 if( pArgs )
680 pItem = pArgs->GetItemIfSet(SID_CHARMAP, false);
682 OUString sSym;
683 OUString sFontName;
684 if ( pItem )
686 sSym = pItem->GetValue();
687 const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false);
688 if ( pFontItem )
689 sFontName = pFontItem->GetValue();
692 SfxItemSet aSet(pOLV->GetAttribs());
693 SvtScriptType nScript = pOLV->GetSelectedScriptType();
694 std::shared_ptr<SvxFontItem> aSetDlgFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
696 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() );
697 aSetItem.GetItemSet().Put( aSet, false );
698 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
699 if( pI )
700 aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
701 else
703 TypedWhichId<SvxFontItem> nFontWhich =
704 GetWhichOfScript(
705 SID_ATTR_CHAR_FONT,
706 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) );
707 aSetDlgFont.reset(aSet.Get( nFontWhich ).Clone());
709 if (sFontName.isEmpty())
710 sFontName = aSetDlgFont->GetFamilyName();
713 vcl::Font aFont(sFontName, Size(1,1));
714 if(sSym.isEmpty())
716 SfxAllItemSet aAllSet( GetPool() );
717 aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
719 SwViewOption aOpt(*m_rView.GetWrtShell().GetViewOptions());
720 const OUString& sSymbolFont = aOpt.GetSymbolFont();
721 if( !sSymbolFont.isEmpty() )
722 aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) );
723 else
724 aAllSet.Put( SfxStringItem( SID_FONT_NAME, aSetDlgFont->GetFamilyName() ) );
726 // If character is selected, it can be shown
727 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
728 auto xFrame = m_rView.GetViewFrame().GetFrame().GetFrameInterface();
729 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(m_rView.GetFrameWeld(), aAllSet, xFrame));
730 pDlg->Execute();
731 return;
734 // do not flicker
735 pOLV->HideCursor();
736 SdrOutliner * pOutliner = m_pSdrView->GetTextEditOutliner();
737 pOutliner->SetUpdateLayout(false);
739 SfxItemSet aOldSet( pOLV->GetAttribs() );
740 SfxItemSetFixed<
741 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
742 EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL> aFontSet( *aOldSet.GetPool() );
743 aFontSet.Set( aOldSet );
745 // Insert string
746 pOLV->InsertText( sSym );
748 // assign attributes (Set font)
749 SfxItemSet aFontAttribSet( *aFontSet.GetPool(), aFontSet.GetRanges() );
750 SvxFontItem aFontItem (aFont.GetFamilyType(), aFont.GetFamilyName(),
751 aFont.GetStyleName(), aFont.GetPitch(),
752 aFont.GetCharSet(),
753 EE_CHAR_FONTINFO );
754 nScript = g_pBreakIt->GetAllScriptsOfText( sSym );
755 if( SvtScriptType::LATIN & nScript )
756 aFontAttribSet.Put( aFontItem );
757 if( SvtScriptType::ASIAN & nScript )
759 aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
760 aFontAttribSet.Put( aFontItem );
762 if( SvtScriptType::COMPLEX & nScript )
764 aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
765 aFontAttribSet.Put( aFontItem );
767 pOLV->SetAttribs(aFontAttribSet);
769 // Remove selection
770 ESelection aSel(pOLV->GetSelection());
771 aSel.nStartPara = aSel.nEndPara;
772 aSel.nStartPos = aSel.nEndPos;
773 pOLV->SetSelection(aSel);
775 // Restore old font
776 pOLV->SetAttribs( aFontSet );
778 // From now on show again
779 pOutliner->SetUpdateLayout(true);
780 pOLV->ShowCursor();
782 rReq.AppendItem( SfxStringItem( SID_CHARMAP, sSym ) );
783 if(!aFont.GetFamilyName().isEmpty())
784 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aFont.GetFamilyName() ) );
785 rReq.Done();
789 SfxUndoManager* SwDrawTextShell::GetUndoManager()
791 SwWrtShell &rSh = GetShell();
792 m_pSdrView = rSh.GetDrawView();
793 SdrOutliner * pOutliner = m_pSdrView->GetTextEditOutliner();
794 return &pOutliner->GetUndoManager();
797 void SwDrawTextShell::GetStatePropPanelAttr(SfxItemSet &rSet)
799 SfxWhichIter aIter( rSet );
800 sal_uInt16 nWhich = aIter.FirstWhich();
802 SwWrtShell &rSh = GetShell();
803 m_pSdrView = rSh.GetDrawView();
805 SfxItemSet aAttrs(m_pSdrView->GetModel().GetItemPool());
806 m_pSdrView->GetAttributes( aAttrs );
808 while ( nWhich )
810 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
811 ? GetPool().GetSlotId(nWhich)
812 : nWhich;
813 switch ( nSlotId )
815 case SID_TABLE_VERT_NONE:
816 case SID_TABLE_VERT_CENTER:
817 case SID_TABLE_VERT_BOTTOM:
818 bool bContour = false;
819 SfxItemState eConState = aAttrs.GetItemState( SDRATTR_TEXT_CONTOURFRAME );
820 if( eConState != SfxItemState::DONTCARE )
822 bContour = aAttrs.Get( SDRATTR_TEXT_CONTOURFRAME ).GetValue();
824 if (bContour) break;
826 SfxItemState eVState = aAttrs.GetItemState( SDRATTR_TEXT_VERTADJUST );
827 //SfxItemState eHState = aAttrs.GetItemState( SDRATTR_TEXT_HORZADJUST );
829 //if(SfxItemState::DONTCARE != eVState && SfxItemState::DONTCARE != eHState)
830 if(SfxItemState::DONTCARE != eVState)
832 SdrTextVertAdjust eTVA = aAttrs.Get(SDRATTR_TEXT_VERTADJUST).GetValue();
833 bool bSet = (nSlotId == SID_TABLE_VERT_NONE && eTVA == SDRTEXTVERTADJUST_TOP) ||
834 (nSlotId == SID_TABLE_VERT_CENTER && eTVA == SDRTEXTVERTADJUST_CENTER) ||
835 (nSlotId == SID_TABLE_VERT_BOTTOM && eTVA == SDRTEXTVERTADJUST_BOTTOM);
836 rSet.Put(SfxBoolItem(nSlotId, bSet));
838 else
840 rSet.Put(SfxBoolItem(nSlotId, false));
842 break;
844 nWhich = aIter.NextWhich();
848 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */