Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / docshell / docshel3.cxx
blobe482e5f13b83967490790d5a4c1b6b8f82e457f3
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 <Window.hxx>
21 #include <DrawDocShell.hxx>
23 #include <app.hrc>
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>
46 #include <sdmod.hxx>
47 #include <drawdoc.hxx>
48 #include <sdpage.hxx>
49 #include <sdattr.hxx>
50 #include <fusearch.hxx>
51 #include <ViewShell.hxx>
52 #include <View.hxx>
53 #include <slideshow.hxx>
54 #include <fuhhconv.hxx>
55 #include <memory>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::uno;
61 namespace sd {
63 static void lcl_setLanguageForObj( SdrObject *pObj, LanguageType nLang, bool bLanguageNone )
65 const sal_uInt16 aLangWhichId_EE[3] =
67 EE_CHAR_LANGUAGE,
68 EE_CHAR_LANGUAGE_CJK,
69 EE_CHAR_LANGUAGE_CTL
72 if( bLanguageNone )
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 ) );
82 else
84 sal_uInt16 nLangWhichId = 0;
85 SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
86 switch (nScriptType)
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;
91 default:
92 OSL_FAIL("unexpected case" );
93 return;
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
133 return;
136 switch ( rReq.GetSlot() )
138 case SID_SEARCH_ITEM:
140 const SfxItemSet* pReqArgs = rReq.GetArgs();
142 if (pReqArgs)
144 const SvxSearchItem & rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM);
146 SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(static_cast<SvxSearchItem*>(rSearchItem.Clone())));
149 rReq.Done();
151 break;
153 case FID_SEARCH_ON:
155 // no action needed
156 rReq.Done();
158 break;
160 case FID_SEARCH_OFF:
162 if( dynamic_cast< FuSearch* >(mxDocShellFunction.get()) )
164 // End Search&Replace in all docshells
165 SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst();
166 SfxObjectShell* pShell = pFirstShell;
168 while (pShell)
170 if( dynamic_cast< const DrawDocShell *>( pShell ) != nullptr)
172 static_cast<DrawDocShell*>(pShell)->CancelSearching();
175 pShell = SfxObjectShell::GetNext(*pShell);
177 if (pShell == pFirstShell)
179 pShell = nullptr;
183 SetDocShellFunction(nullptr);
184 Invalidate();
185 rReq.Done();
188 break;
190 case FID_SEARCH_NOW:
192 const SfxItemSet* pReqArgs = rReq.GetArgs();
194 if ( pReqArgs )
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() ) );
205 if( xFuSearch.is() )
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);
214 rReq.Done();
216 break;
218 case SID_CLOSEDOC:
220 ExecuteSlot(rReq, SfxObjectShell::GetStaticInterface());
222 break;
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 ) );
230 break;
232 case SID_VERSION:
234 const SdrSwapGraphicsMode nOldSwapMode = mpDoc->GetSwapGraphicsMode();
236 mpDoc->SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP );
237 ExecuteSlot( rReq, SfxObjectShell::GetStaticInterface() );
238 mpDoc->SetSwapGraphicsMode( nOldSwapMode );
240 break;
242 case SID_HANGUL_HANJA_CONVERSION:
244 if( mpViewShell )
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 );
250 break;
252 case SID_CHINESE_CONVERSION:
254 if( mpViewShell )
256 rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
257 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartChineseConversion();
260 break;
261 case SID_LANGUAGE_STATUS:
263 OUString aNewLangTxt;
264 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(SID_LANGUAGE_STATUS);
265 if (pItem)
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 ));
274 pDlg->Execute();
277 else
279 if( mpViewShell )
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();
288 sal_Int32 nPos = -1;
289 if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix )))
291 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aDocumentLangPrefix.getLength(), "" );
293 else
295 break;
297 if (aNewLangTxt == aStrNone)
298 lcl_setLanguage( pDoc, OUString(), true );
299 else if (aNewLangTxt == aStrResetLangs)
300 lcl_setLanguage( pDoc, OUString() );
301 else
302 lcl_setLanguage( pDoc, aNewLangTxt );
304 if ( pDoc->GetOnlineSpell() )
306 pDoc->StartOnlineSpelling();
311 Broadcast(SfxHint(SfxHintId::LanguageChanged));
313 break;
315 case SID_NOTEBOOKBAR:
317 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR );
319 if ( mpViewShell )
321 SfxBindings& rBindings( mpViewShell->GetFrame()->GetBindings() );
323 if ( sfx2::SfxNotebookBar::IsActive() )
324 sfx2::SfxNotebookBar::ExecMethod( rBindings, pFile ? pFile->GetValue() : "" );
325 else
326 sfx2::SfxNotebookBar::CloseMethod( rBindings );
329 break;
331 default:
332 break;
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: */