Update git submodules
[LibreOffice.git] / sd / source / ui / docshell / docshel3.cxx
blobbe045818a67abc0fccfb711b4308873195568c44
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 <DrawDocShell.hxx>
22 #include <svx/svxids.hrc>
24 #include <svx/ofaitem.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/srchitem.hxx>
27 #include <svl/languageoptions.hxx>
28 #include <svtools/langtab.hxx>
29 #include <sfx2/request.hxx>
30 #include <sfx2/sfxdlg.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <vcl/abstdlg.hxx>
33 #include <svx/drawitem.hxx>
34 #include <editeng/langitem.hxx>
35 #include <editeng/eeitem.hxx>
36 #include <editeng/outlobj.hxx>
37 #include <editeng/editobj.hxx>
38 #include <com/sun/star/i18n/TextConversionOption.hpp>
39 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
40 #include <editeng/editeng.hxx>
41 #include <osl/diagnose.h>
43 #include <sdmod.hxx>
44 #include <drawdoc.hxx>
45 #include <fusearch.hxx>
46 #include <ViewShell.hxx>
47 #include <slideshow.hxx>
48 #include <fuhhconv.hxx>
49 #include <memory>
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::uno;
55 namespace sd {
57 static void lcl_setLanguageForObj( SdrObject *pObj, LanguageType nLang, bool bLanguageNone )
59 const sal_uInt16 aLangWhichId_EE[3] =
61 EE_CHAR_LANGUAGE,
62 EE_CHAR_LANGUAGE_CJK,
63 EE_CHAR_LANGUAGE_CTL
66 if( bLanguageNone )
67 nLang = LANGUAGE_NONE;
69 if( nLang != LANGUAGE_DONTKNOW )
71 if( nLang == LANGUAGE_NONE )
73 for(sal_uInt16 n : aLangWhichId_EE)
74 pObj->SetMergedItem( SvxLanguageItem( nLang, n ) );
76 else
78 sal_uInt16 nLangWhichId = 0;
79 SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
80 switch (nScriptType)
82 case SvtScriptType::LATIN : nLangWhichId = EE_CHAR_LANGUAGE; break;
83 case SvtScriptType::ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
84 case SvtScriptType::COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
85 default:
86 OSL_FAIL("unexpected case" );
87 return;
89 pObj->SetMergedItem( SvxLanguageItem( nLang, nLangWhichId ) );
91 // Reset shape text language to default, so it inherits the shape language set above.
92 OutlinerParaObject* pOutliner = pObj->GetOutlinerParaObject();
93 if (pOutliner)
95 EditTextObject& rEditTextObject
96 = const_cast<EditTextObject&>(pOutliner->GetTextObject());
97 for (sal_uInt16 n : aLangWhichId_EE)
99 rEditTextObject.RemoveCharAttribs(n);
104 else // Reset to default
106 for(sal_uInt16 n : aLangWhichId_EE)
107 pObj->ClearMergedItem( n );
111 static void lcl_setLanguage( const SdDrawDocument *pDoc, std::u16string_view rLanguage, bool bLanguageNone = false )
113 LanguageType nLang = SvtLanguageTable::GetLanguageType( rLanguage );
115 // Do it for SdDrawDocument->SetLanguage as well?
117 sal_uInt16 nPageCount = pDoc->GetPageCount(); // Pick All Pages
118 for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
120 const SdrPage *pPage = pDoc->GetPage( nPage );
121 const size_t nObjCount = pPage->GetObjCount();
122 for( size_t nObj = 0; nObj < nObjCount; ++nObj )
124 SdrObject *pObj = pPage->GetObj( nObj );
125 if (pObj->GetObjIdentifier() != SdrObjKind::Page)
126 lcl_setLanguageForObj( pObj, nLang, bLanguageNone );
132 * Handles SFX-Requests
134 void DrawDocShell::Execute( SfxRequest& rReq )
136 if(mpViewShell && SlideShow::IsRunning( mpViewShell->GetViewShellBase() ))
138 // during a running presentation no slot will be executed
139 return;
142 switch ( rReq.GetSlot() )
144 case SID_SEARCH_ITEM:
146 const SfxItemSet* pReqArgs = rReq.GetArgs();
148 if (pReqArgs)
150 const SvxSearchItem & rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM);
152 SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(rSearchItem.Clone()));
155 rReq.Done();
157 break;
159 case FID_SEARCH_ON:
161 // no action needed
162 rReq.Done();
164 break;
166 case FID_SEARCH_OFF:
168 if (mpViewShell)
170 sd::View* pView = mpViewShell->GetView();
171 if (pView)
173 auto& rFunctionContext = pView->getSearchContext();
174 rtl::Reference<FuSearch>& xFuSearch(rFunctionContext.getFunctionSearch());
176 if (xFuSearch.is())
178 // End Search&Replace in all docshells
179 SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst();
180 SfxObjectShell* pShell = pFirstShell;
182 while (pShell)
184 auto pDrawDocShell = dynamic_cast<DrawDocShell*>(pShell);
185 if (pDrawDocShell)
186 pDrawDocShell->CancelSearching();
188 pShell = SfxObjectShell::GetNext(*pShell);
190 if (pShell == pFirstShell)
191 pShell = nullptr;
194 rFunctionContext.resetSearchFunction();
195 Invalidate();
196 rReq.Done();
201 break;
203 case FID_SEARCH_NOW:
205 const SfxItemSet* pReqArgs = rReq.GetArgs();
207 if (pReqArgs && mpViewShell)
209 sd::View* pView = mpViewShell->GetView();
210 if (pView)
212 rtl::Reference<FuSearch> & xFuSearch = pView->getSearchContext().getFunctionSearch();
214 if (!xFuSearch.is())
216 xFuSearch = rtl::Reference<FuSearch>(
217 FuSearch::createPtr(mpViewShell,
218 mpViewShell->GetActiveWindow(),
219 pView, mpDoc, rReq));
221 pView->getSearchContext().setSearchFunction(xFuSearch);
224 if (xFuSearch.is())
226 const SvxSearchItem& rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM);
228 SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(rSearchItem.Clone()));
229 xFuSearch->SearchAndReplace(&rSearchItem);
234 rReq.Done();
236 break;
238 case SID_CLOSEDOC:
240 ExecuteSlot(rReq, SfxObjectShell::GetStaticInterface());
242 break;
244 case SID_GET_COLORLIST:
246 const SvxColorListItem* pColItem = GetItem( SID_COLOR_TABLE );
247 const XColorListRef& pList = pColItem->GetColorList();
248 rReq.SetReturnValue( OfaXColorListItem( SID_GET_COLORLIST, pList ) );
250 break;
252 case SID_VERSION:
254 ExecuteSlot( rReq, SfxObjectShell::GetStaticInterface() );
256 break;
258 case SID_HANGUL_HANJA_CONVERSION:
260 if( mpViewShell )
262 rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
263 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr, i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true );
266 break;
268 case SID_CHINESE_CONVERSION:
270 if( mpViewShell )
272 rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
273 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartChineseConversion();
276 break;
277 case SID_LANGUAGE_STATUS:
279 OUString aNewLangTxt;
280 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(SID_LANGUAGE_STATUS);
281 if (pItem)
282 aNewLangTxt = pItem->GetValue();
284 if (aNewLangTxt == "*" )
286 // open the dialog "Tools/Options/Language Settings - Language"
287 if (mpViewShell)
289 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
290 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog( mpViewShell->GetFrameWeld(), SID_LANGUAGE_OPTIONS ));
291 pDlg->Execute();
294 else
296 if( mpViewShell )
298 // setting the new language...
299 if (!aNewLangTxt.isEmpty())
301 static const OUStringLiteral aSelectionLangPrefix(u"Current_");
302 static const OUStringLiteral aParagraphLangPrefix(u"Paragraph_");
303 static const OUStringLiteral aDocumentLangPrefix(u"Default_");
305 bool bSelection = false;
306 bool bParagraph = false;
308 SdDrawDocument* pDoc = mpViewShell->GetDoc();
309 sal_Int32 nPos = -1;
310 if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix )))
312 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aDocumentLangPrefix.getLength(), u"" );
314 if (aNewLangTxt == "LANGUAGE_NONE")
315 lcl_setLanguage( pDoc, u"", true );
316 else if (aNewLangTxt == "RESET_LANGUAGES")
317 lcl_setLanguage( pDoc, u"" );
318 else
319 lcl_setLanguage( pDoc, aNewLangTxt );
321 else if (-1 != (nPos = aNewLangTxt.indexOf( aSelectionLangPrefix )))
323 bSelection = true;
324 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aSelectionLangPrefix.getLength(), u"" );
326 else if (-1 != (nPos = aNewLangTxt.indexOf( aParagraphLangPrefix )))
328 bParagraph = true;
329 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aParagraphLangPrefix.getLength(), u"" );
332 if (bSelection || bParagraph)
334 SdrView* pSdrView = mpViewShell->GetDrawView();
335 if (!pSdrView)
336 return;
338 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
339 const LanguageType nLangToUse = SvtLanguageTable::GetLanguageType( aNewLangTxt );
340 SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
342 SfxItemSet aAttrs = rEditView.GetEditEngine()->GetEmptyItemSet();
343 if (nScriptType == SvtScriptType::LATIN)
344 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) );
345 if (nScriptType == SvtScriptType::COMPLEX)
346 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
347 if (nScriptType == SvtScriptType::ASIAN)
348 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
349 ESelection aOldSel;
350 if (bParagraph)
352 ESelection aSel = rEditView.GetSelection();
353 aOldSel = aSel;
354 aSel.nStartPos = 0;
355 aSel.nEndPos = EE_TEXTPOS_ALL;
356 rEditView.SetSelection( aSel );
359 rEditView.SetAttribs( aAttrs );
360 if (bParagraph)
361 rEditView.SetSelection( aOldSel );
364 if ( pDoc->GetOnlineSpell() )
366 pDoc->StartOnlineSpelling();
371 Broadcast(SfxHint(SfxHintId::LanguageChanged));
373 break;
374 case SID_SPELLCHECK_IGNORE_ALL:
376 if (!mpViewShell)
377 return;
378 SdrView* pSdrView = mpViewShell->GetDrawView();
379 if (!pSdrView)
380 return;
382 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
383 OUString sIgnoreText;
384 const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
385 if (pItem2)
386 sIgnoreText = pItem2->GetValue();
388 if(sIgnoreText == "Spelling")
390 ESelection aOldSel = rEditView.GetSelection();
391 rEditView.SpellIgnoreWord();
392 rEditView.SetSelection( aOldSel );
395 break;
396 case SID_SPELLCHECK_APPLY_SUGGESTION:
398 if (!mpViewShell)
399 return;
400 SdrView* pSdrView = mpViewShell->GetDrawView();
401 if (!pSdrView)
402 return;
404 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
405 OUString sApplyText;
406 const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
407 if (pItem2)
408 sApplyText = pItem2->GetValue();
410 static const OUStringLiteral sSpellingRule(u"Spelling_");
411 sal_Int32 nPos = 0;
412 if(-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
414 sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u"");
415 rEditView.InsertText( sApplyText );
418 break;
420 case SID_NOTEBOOKBAR:
422 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR );
424 if ( mpViewShell )
426 SfxBindings& rBindings( mpViewShell->GetFrame()->GetBindings() );
428 if ( sfx2::SfxNotebookBar::IsActive() )
429 sfx2::SfxNotebookBar::ExecMethod( rBindings, pFile ? pFile->GetValue() : "" );
430 else
431 sfx2::SfxNotebookBar::CloseMethod( rBindings );
434 break;
436 default:
437 break;
441 } // end of namespace sd
443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */