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 .
21 #include <DrawDocShell.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/dialogs.hrc>
28 #include <svx/ofaitem.hxx>
29 #include <svx/svxerr.hxx>
30 #include <svl/srchitem.hxx>
31 #include <svl/languageoptions.hxx>
32 #include <svtools/langtab.hxx>
33 #include <svx/srchdlg.hxx>
34 #include <sfx2/request.hxx>
35 #include <sfx2/sfxdlg.hxx>
36 #include <vcl/abstdlg.hxx>
37 #include <vcl/window.hxx>
38 #include <svl/style.hxx>
39 #include <svx/drawitem.hxx>
40 #include <editeng/unolingu.hxx>
41 #include <editeng/langitem.hxx>
42 #include <editeng/eeitem.hxx>
43 #include <com/sun/star/i18n/TextConversionOption.hpp>
44 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
47 #include <drawdoc.hxx>
50 #include <fusearch.hxx>
51 #include <ViewShell.hxx>
53 #include <slideshow.hxx>
54 #include <fuhhconv.hxx>
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::beans
;
59 using namespace ::com::sun::star::uno
;
63 static void lcl_setLanguageForObj( SdrObject
*pObj
, LanguageType nLang
, bool bLanguageNone
)
65 const sal_uInt16 aLangWhichId_EE
[3] =
73 nLang
= LANGUAGE_NONE
;
75 if( nLang
!= LANGUAGE_DONTKNOW
)
77 if( nLang
== LANGUAGE_NONE
)
79 for(sal_uInt16 n
: aLangWhichId_EE
)
80 pObj
->SetMergedItem( SvxLanguageItem( nLang
, n
) );
84 sal_uInt16 nLangWhichId
= 0;
85 SvtScriptType nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nLang
);
88 case SvtScriptType::LATIN
: nLangWhichId
= EE_CHAR_LANGUAGE
; break;
89 case SvtScriptType::ASIAN
: nLangWhichId
= EE_CHAR_LANGUAGE_CJK
; break;
90 case SvtScriptType::COMPLEX
: nLangWhichId
= EE_CHAR_LANGUAGE_CTL
; break;
92 OSL_FAIL("unexpected case" );
95 pObj
->SetMergedItem( SvxLanguageItem( nLang
, nLangWhichId
) );
98 else // Reset to default
100 for(sal_uInt16 n
: aLangWhichId_EE
)
101 pObj
->ClearMergedItem( n
);
105 static void lcl_setLanguage( const SdDrawDocument
*pDoc
, const OUString
&rLanguage
, bool bLanguageNone
= false )
107 LanguageType nLang
= SvtLanguageTable::GetLanguageType( rLanguage
);
109 // Do it for SdDrawDocument->SetLanguage as well?
111 sal_uInt16 nPageCount
= pDoc
->GetPageCount(); // Pick All Pages
112 for( sal_uInt16 nPage
= 0; nPage
< nPageCount
; nPage
++ )
114 const SdrPage
*pPage
= pDoc
->GetPage( nPage
);
115 const size_t nObjCount
= pPage
->GetObjCount();
116 for( size_t nObj
= 0; nObj
< nObjCount
; ++nObj
)
118 SdrObject
*pObj
= pPage
->GetObj( nObj
);
119 if (pObj
->GetObjIdentifier() != OBJ_PAGE
)
120 lcl_setLanguageForObj( pObj
, nLang
, bLanguageNone
);
126 * Handles SFX-Requests
128 void DrawDocShell::Execute( SfxRequest
& rReq
)
130 if(mpViewShell
&& SlideShow::IsRunning( mpViewShell
->GetViewShellBase() ))
132 // during a running presentation no slot will be executed
136 switch ( rReq
.GetSlot() )
138 case SID_SEARCH_ITEM
:
140 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
144 const SvxSearchItem
& rSearchItem
= pReqArgs
->Get(SID_SEARCH_ITEM
);
146 SD_MOD()->SetSearchItem(std::unique_ptr
<SvxSearchItem
>(static_cast<SvxSearchItem
*>(rSearchItem
.Clone())));
162 if( dynamic_cast< FuSearch
* >(mxDocShellFunction
.get()) )
164 // End Search&Replace in all docshells
165 SfxObjectShell
* pFirstShell
= SfxObjectShell::GetFirst();
166 SfxObjectShell
* pShell
= pFirstShell
;
170 if( dynamic_cast< const DrawDocShell
*>( pShell
) != nullptr)
172 static_cast<DrawDocShell
*>(pShell
)->CancelSearching();
175 pShell
= SfxObjectShell::GetNext(*pShell
);
177 if (pShell
== pFirstShell
)
183 SetDocShellFunction(nullptr);
192 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
196 rtl::Reference
< FuSearch
> xFuSearch( dynamic_cast< FuSearch
* >( GetDocShellFunction().get() ) );
198 if( !xFuSearch
.is() && mpViewShell
)
200 ::sd::View
* pView
= mpViewShell
->GetView();
201 SetDocShellFunction( FuSearch::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), pView
, mpDoc
, rReq
) );
202 xFuSearch
.set( dynamic_cast< FuSearch
* >( GetDocShellFunction().get() ) );
207 const SvxSearchItem
& rSearchItem
= pReqArgs
->Get(SID_SEARCH_ITEM
);
209 SD_MOD()->SetSearchItem(std::unique_ptr
<SvxSearchItem
>(static_cast<SvxSearchItem
*>( rSearchItem
.Clone() )));
210 xFuSearch
->SearchAndReplace(&rSearchItem
);
220 ExecuteSlot(rReq
, SfxObjectShell::GetStaticInterface());
224 case SID_GET_COLORLIST
:
226 const SvxColorListItem
* pColItem
= GetItem( SID_COLOR_TABLE
);
227 XColorListRef pList
= pColItem
->GetColorList();
228 rReq
.SetReturnValue( OfaRefItem
<XColorList
>( SID_GET_COLORLIST
, pList
) );
234 const SdrSwapGraphicsMode nOldSwapMode
= mpDoc
->GetSwapGraphicsMode();
236 mpDoc
->SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP
);
237 ExecuteSlot( rReq
, SfxObjectShell::GetStaticInterface() );
238 mpDoc
->SetSwapGraphicsMode( nOldSwapMode
);
242 case SID_HANGUL_HANJA_CONVERSION
:
246 rtl::Reference
<FuPoor
> aFunc( FuHangulHanjaConversion::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), mpViewShell
->GetView(), mpDoc
, rReq
) );
247 static_cast< FuHangulHanjaConversion
* >( aFunc
.get() )->StartConversion( LANGUAGE_KOREAN
, LANGUAGE_KOREAN
, nullptr, i18n::TextConversionOption::CHARACTER_BY_CHARACTER
, true );
252 case SID_CHINESE_CONVERSION
:
256 rtl::Reference
<FuPoor
> aFunc( FuHangulHanjaConversion::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), mpViewShell
->GetView(), mpDoc
, rReq
) );
257 static_cast< FuHangulHanjaConversion
* >( aFunc
.get() )->StartChineseConversion();
261 case SID_LANGUAGE_STATUS
:
263 OUString aNewLangTxt
;
264 const SfxStringItem
* pItem
= rReq
.GetArg
<SfxStringItem
>(SID_LANGUAGE_STATUS
);
266 aNewLangTxt
= pItem
->GetValue();
267 if (aNewLangTxt
== "*" )
269 // open the dialog "Tools/Options/Language Settings - Language"
270 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
271 if (pFact
&& mpViewShell
)
273 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateVclDialog( mpViewShell
->GetActiveWindow(), SID_LANGUAGE_OPTIONS
));
281 // setting the new language...
282 if (!aNewLangTxt
.isEmpty())
284 const OUString
aDocumentLangPrefix("Default_");
285 const OUString
aStrNone("LANGUAGE_NONE");
286 const OUString
aStrResetLangs("RESET_LANGUAGES");
287 SdDrawDocument
* pDoc
= mpViewShell
->GetDoc();
289 if (-1 != (nPos
= aNewLangTxt
.indexOf( aDocumentLangPrefix
)))
291 aNewLangTxt
= aNewLangTxt
.replaceAt( nPos
, aDocumentLangPrefix
.getLength(), "" );
297 if (aNewLangTxt
== aStrNone
)
298 lcl_setLanguage( pDoc
, OUString(), true );
299 else if (aNewLangTxt
== aStrResetLangs
)
300 lcl_setLanguage( pDoc
, OUString() );
302 lcl_setLanguage( pDoc
, aNewLangTxt
);
304 if ( pDoc
->GetOnlineSpell() )
306 pDoc
->StartOnlineSpelling();
311 Broadcast(SfxHint(SfxHintId::LanguageChanged
));
315 case SID_NOTEBOOKBAR
:
317 const SfxStringItem
* pFile
= rReq
.GetArg
<SfxStringItem
>( SID_NOTEBOOKBAR
);
321 SfxBindings
& rBindings( mpViewShell
->GetFrame()->GetBindings() );
323 if ( sfx2::SfxNotebookBar::IsActive() )
324 sfx2::SfxNotebookBar::ExecMethod( rBindings
, pFile
? pFile
->GetValue() : "" );
326 sfx2::SfxNotebookBar::CloseMethod( rBindings
);
336 void DrawDocShell::SetDocShellFunction( const rtl::Reference
<FuPoor
>& xFunction
)
338 if( mxDocShellFunction
.is() )
339 mxDocShellFunction
->Dispose();
341 mxDocShellFunction
= xFunction
;
344 } // end of namespace sd
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */