1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
44 #include <drawdoc.hxx>
45 #include <fusearch.hxx>
46 #include <ViewShell.hxx>
47 #include <slideshow.hxx>
48 #include <fuhhconv.hxx>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::uno
;
57 static void lcl_setLanguageForObj( SdrObject
*pObj
, LanguageType nLang
, bool bLanguageNone
)
59 const sal_uInt16 aLangWhichId_EE
[3] =
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
) );
78 sal_uInt16 nLangWhichId
= 0;
79 SvtScriptType nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nLang
);
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;
86 OSL_FAIL("unexpected case" );
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();
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
142 switch ( rReq
.GetSlot() )
144 case SID_SEARCH_ITEM
:
146 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
150 const SvxSearchItem
& rSearchItem
= pReqArgs
->Get(SID_SEARCH_ITEM
);
152 SD_MOD()->SetSearchItem(std::unique_ptr
<SvxSearchItem
>(rSearchItem
.Clone()));
170 sd::View
* pView
= mpViewShell
->GetView();
173 auto& rFunctionContext
= pView
->getSearchContext();
174 rtl::Reference
<FuSearch
>& xFuSearch(rFunctionContext
.getFunctionSearch());
178 // End Search&Replace in all docshells
179 SfxObjectShell
* pFirstShell
= SfxObjectShell::GetFirst();
180 SfxObjectShell
* pShell
= pFirstShell
;
184 auto pDrawDocShell
= dynamic_cast<DrawDocShell
*>(pShell
);
186 pDrawDocShell
->CancelSearching();
188 pShell
= SfxObjectShell::GetNext(*pShell
);
190 if (pShell
== pFirstShell
)
194 rFunctionContext
.resetSearchFunction();
205 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
207 if (pReqArgs
&& mpViewShell
)
209 sd::View
* pView
= mpViewShell
->GetView();
212 rtl::Reference
<FuSearch
> & xFuSearch
= pView
->getSearchContext().getFunctionSearch();
216 xFuSearch
= rtl::Reference
<FuSearch
>(
217 FuSearch::createPtr(mpViewShell
,
218 mpViewShell
->GetActiveWindow(),
219 pView
, mpDoc
, rReq
));
221 pView
->getSearchContext().setSearchFunction(xFuSearch
);
226 const SvxSearchItem
& rSearchItem
= pReqArgs
->Get(SID_SEARCH_ITEM
);
228 SD_MOD()->SetSearchItem(std::unique_ptr
<SvxSearchItem
>(rSearchItem
.Clone()));
229 xFuSearch
->SearchAndReplace(&rSearchItem
);
240 ExecuteSlot(rReq
, SfxObjectShell::GetStaticInterface());
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
) );
254 ExecuteSlot( rReq
, SfxObjectShell::GetStaticInterface() );
258 case SID_HANGUL_HANJA_CONVERSION
:
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 );
268 case SID_CHINESE_CONVERSION
:
272 rtl::Reference
<FuPoor
> aFunc( FuHangulHanjaConversion::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), mpViewShell
->GetView(), mpDoc
, rReq
) );
273 static_cast< FuHangulHanjaConversion
* >( aFunc
.get() )->StartChineseConversion();
277 case SID_LANGUAGE_STATUS
:
279 OUString aNewLangTxt
;
280 const SfxStringItem
* pItem
= rReq
.GetArg
<SfxStringItem
>(SID_LANGUAGE_STATUS
);
282 aNewLangTxt
= pItem
->GetValue();
284 if (aNewLangTxt
== "*" )
286 // open the dialog "Tools/Options/Language Settings - Language"
289 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
290 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateVclDialog( mpViewShell
->GetFrameWeld(), SID_LANGUAGE_OPTIONS
));
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();
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
"" );
319 lcl_setLanguage( pDoc
, aNewLangTxt
);
321 else if (-1 != (nPos
= aNewLangTxt
.indexOf( aSelectionLangPrefix
)))
324 aNewLangTxt
= aNewLangTxt
.replaceAt( nPos
, aSelectionLangPrefix
.getLength(), u
"" );
326 else if (-1 != (nPos
= aNewLangTxt
.indexOf( aParagraphLangPrefix
)))
329 aNewLangTxt
= aNewLangTxt
.replaceAt( nPos
, aParagraphLangPrefix
.getLength(), u
"" );
332 if (bSelection
|| bParagraph
)
334 SdrView
* pSdrView
= mpViewShell
->GetDrawView();
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
) );
352 ESelection aSel
= rEditView
.GetSelection();
355 aSel
.nEndPos
= EE_TEXTPOS_ALL
;
356 rEditView
.SetSelection( aSel
);
359 rEditView
.SetAttribs( aAttrs
);
361 rEditView
.SetSelection( aOldSel
);
364 if ( pDoc
->GetOnlineSpell() )
366 pDoc
->StartOnlineSpelling();
371 Broadcast(SfxHint(SfxHintId::LanguageChanged
));
374 case SID_SPELLCHECK_IGNORE_ALL
:
378 SdrView
* pSdrView
= mpViewShell
->GetDrawView();
382 EditView
& rEditView
= pSdrView
->GetTextEditOutlinerView()->GetEditView();
383 OUString sIgnoreText
;
384 const SfxStringItem
* pItem2
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_1
);
386 sIgnoreText
= pItem2
->GetValue();
388 if(sIgnoreText
== "Spelling")
390 ESelection aOldSel
= rEditView
.GetSelection();
391 rEditView
.SpellIgnoreWord();
392 rEditView
.SetSelection( aOldSel
);
396 case SID_SPELLCHECK_APPLY_SUGGESTION
:
400 SdrView
* pSdrView
= mpViewShell
->GetDrawView();
404 EditView
& rEditView
= pSdrView
->GetTextEditOutlinerView()->GetEditView();
406 const SfxStringItem
* pItem2
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_1
);
408 sApplyText
= pItem2
->GetValue();
410 static const OUStringLiteral
sSpellingRule(u
"Spelling_");
412 if(-1 != (nPos
= sApplyText
.indexOf( sSpellingRule
)))
414 sApplyText
= sApplyText
.replaceAt(nPos
, sSpellingRule
.getLength(), u
"");
415 rEditView
.InsertText( sApplyText
);
420 case SID_NOTEBOOKBAR
:
422 const SfxStringItem
* pFile
= rReq
.GetArg
<SfxStringItem
>( SID_NOTEBOOKBAR
);
426 SfxBindings
& rBindings( mpViewShell
->GetFrame()->GetBindings() );
428 if ( sfx2::SfxNotebookBar::IsActive() )
429 sfx2::SfxNotebookBar::ExecMethod( rBindings
, pFile
? pFile
->GetValue() : "" );
431 sfx2::SfxNotebookBar::CloseMethod( rBindings
);
441 } // end of namespace sd
443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */