LibreOffice Module sd (master) 1
docshel3.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <DrawDocShell.hxx>
21
22#include <svx/svxids.hrc>
23
24#include <svx/ofaitem.hxx>
25#include <svl/stritem.hxx>
26#include <svl/srchitem.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>
40#include <editeng/editeng.hxx>
41#include <osl/diagnose.h>
42
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>
50
51using namespace ::com::sun::star;
52using namespace ::com::sun::star::beans;
53using namespace ::com::sun::star::uno;
54
55namespace sd {
56
57static void lcl_setLanguageForObj( SdrObject *pObj, LanguageType nLang, bool bLanguageNone )
58{
59 const sal_uInt16 aLangWhichId_EE[3] =
60 {
64 };
65
66 if( bLanguageNone )
67 nLang = LANGUAGE_NONE;
68
69 if( nLang != LANGUAGE_DONTKNOW )
70 {
71 if( nLang == LANGUAGE_NONE )
72 {
73 for(sal_uInt16 n : aLangWhichId_EE)
74 pObj->SetMergedItem( SvxLanguageItem( nLang, n ) );
75 }
76 else
77 {
78 sal_uInt16 nLangWhichId = 0;
80 switch (nScriptType)
81 {
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;
88 }
89 pObj->SetMergedItem( SvxLanguageItem( nLang, nLangWhichId ) );
90
91 // Reset shape text language to default, so it inherits the shape language set above.
92 OutlinerParaObject* pOutliner = pObj->GetOutlinerParaObject();
93 if (pOutliner)
94 {
95 EditTextObject& rEditTextObject
96 = const_cast<EditTextObject&>(pOutliner->GetTextObject());
97 for (sal_uInt16 n : aLangWhichId_EE)
98 {
99 rEditTextObject.RemoveCharAttribs(n);
100 }
101 }
102 }
103 }
104 else // Reset to default
105 {
106 for(sal_uInt16 n : aLangWhichId_EE)
107 pObj->ClearMergedItem( n );
108 }
109}
110
111static void lcl_setLanguage( const SdDrawDocument *pDoc, std::u16string_view rLanguage, bool bLanguageNone = false )
112{
114
115 // Do it for SdDrawDocument->SetLanguage as well?
116
117 sal_uInt16 nPageCount = pDoc->GetPageCount(); // Pick All Pages
118 for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
119 {
120 const SdrPage *pPage = pDoc->GetPage( nPage );
121 const size_t nObjCount = pPage->GetObjCount();
122 for( size_t nObj = 0; nObj < nObjCount; ++nObj )
123 {
124 SdrObject *pObj = pPage->GetObj( nObj );
125 if (pObj->GetObjIdentifier() != SdrObjKind::Page)
126 lcl_setLanguageForObj( pObj, nLang, bLanguageNone );
127 }
128 }
129}
130
135{
137 {
138 // during a running presentation no slot will be executed
139 return;
140 }
141
142 switch ( rReq.GetSlot() )
143 {
144 case SID_SEARCH_ITEM:
145 {
146 const SfxItemSet* pReqArgs = rReq.GetArgs();
147
148 if (pReqArgs)
149 {
150 const SvxSearchItem & rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM);
151
152 SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(rSearchItem.Clone()));
153 }
154
155 rReq.Done();
156 }
157 break;
158
159 case FID_SEARCH_ON:
160 {
161 // no action needed
162 rReq.Done();
163 }
164 break;
165
166 case FID_SEARCH_OFF:
167 {
168 if (mpViewShell)
169 {
170 sd::View* pView = mpViewShell->GetView();
171 if (pView)
172 {
173 auto& rFunctionContext = pView->getSearchContext();
174 rtl::Reference<FuSearch>& xFuSearch(rFunctionContext.getFunctionSearch());
175
176 if (xFuSearch.is())
177 {
178 // End Search&Replace in all docshells
180 SfxObjectShell* pShell = pFirstShell;
181
182 while (pShell)
183 {
184 auto pDrawDocShell = dynamic_cast<DrawDocShell*>(pShell);
185 if (pDrawDocShell)
186 pDrawDocShell->CancelSearching();
187
188 pShell = SfxObjectShell::GetNext(*pShell);
189
190 if (pShell == pFirstShell)
191 pShell = nullptr;
192 }
193
194 rFunctionContext.resetSearchFunction();
195 Invalidate();
196 rReq.Done();
197 }
198 }
199 }
200 }
201 break;
202
203 case FID_SEARCH_NOW:
204 {
205 const SfxItemSet* pReqArgs = rReq.GetArgs();
206
207 if (pReqArgs && mpViewShell)
208 {
209 sd::View* pView = mpViewShell->GetView();
210 if (pView)
211 {
213
214 if (!xFuSearch.is())
215 {
216 xFuSearch = rtl::Reference<FuSearch>(
219 pView, mpDoc, rReq));
220
221 pView->getSearchContext().setSearchFunction(xFuSearch);
222 }
223
224 if (xFuSearch.is())
225 {
226 const SvxSearchItem& rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM);
227
228 SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(rSearchItem.Clone()));
229 xFuSearch->SearchAndReplace(&rSearchItem);
230 }
231 }
232 }
233
234 rReq.Done();
235 }
236 break;
237
238 case SID_CLOSEDOC:
239 {
241 }
242 break;
243
244 case SID_GET_COLORLIST:
245 {
246 const SvxColorListItem* pColItem = GetItem( SID_COLOR_TABLE );
247 const XColorListRef& pList = pColItem->GetColorList();
248 rReq.SetReturnValue( OfaXColorListItem( SID_GET_COLORLIST, pList ) );
249 }
250 break;
251
252 case SID_VERSION:
253 {
255 }
256 break;
257
258 case SID_HANGUL_HANJA_CONVERSION:
259 {
260 if( mpViewShell )
261 {
263 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, nullptr, i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true );
264 }
265 }
266 break;
267
268 case SID_CHINESE_CONVERSION:
269 {
270 if( mpViewShell )
271 {
273 static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartChineseConversion();
274 }
275 }
276 break;
277 case SID_LANGUAGE_STATUS:
278 {
279 OUString aNewLangTxt;
280 const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(SID_LANGUAGE_STATUS);
281 if (pItem)
282 aNewLangTxt = pItem->GetValue();
283
284 if (aNewLangTxt == "*" )
285 {
286 // open the dialog "Tools/Options/Language Settings - Language"
287 if (mpViewShell)
288 {
290 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog( mpViewShell->GetFrameWeld(), SID_LANGUAGE_OPTIONS ));
291 pDlg->Execute();
292 }
293 }
294 else
295 {
296 if( mpViewShell )
297 {
298 // setting the new language...
299 if (!aNewLangTxt.isEmpty())
300 {
301 static constexpr OUStringLiteral aSelectionLangPrefix(u"Current_");
302 static constexpr OUStringLiteral aParagraphLangPrefix(u"Paragraph_");
303 static constexpr OUStringLiteral aDocumentLangPrefix(u"Default_");
304
305 bool bSelection = false;
306 bool bParagraph = false;
307
309 sal_Int32 nPos = -1;
310 if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix )))
311 {
312 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aDocumentLangPrefix.getLength(), u"" );
313
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 );
320 }
321 else if (-1 != (nPos = aNewLangTxt.indexOf( aSelectionLangPrefix )))
322 {
323 bSelection = true;
324 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aSelectionLangPrefix.getLength(), u"" );
325 }
326 else if (-1 != (nPos = aNewLangTxt.indexOf( aParagraphLangPrefix )))
327 {
328 bParagraph = true;
329 aNewLangTxt = aNewLangTxt.replaceAt( nPos, aParagraphLangPrefix.getLength(), u"" );
330 }
331
332 if (bSelection || bParagraph)
333 {
334 SdrView* pSdrView = mpViewShell->GetDrawView();
335 if (!pSdrView)
336 return;
337
338 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
339 const LanguageType nLangToUse = SvtLanguageTable::GetLanguageType( aNewLangTxt );
341
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)
351 {
352 ESelection aSel = rEditView.GetSelection();
353 aOldSel = aSel;
354 aSel.nStartPos = 0;
355 aSel.nEndPos = EE_TEXTPOS_ALL;
356 rEditView.SetSelection( aSel );
357 }
358
359 rEditView.SetAttribs( aAttrs );
360 if (bParagraph)
361 rEditView.SetSelection( aOldSel );
362 }
363
364 if ( pDoc->GetOnlineSpell() )
365 {
366 pDoc->StartOnlineSpelling();
367 }
368 }
369 }
370 }
371 Broadcast(SfxHint(SfxHintId::LanguageChanged));
372 }
373 break;
374 case SID_SPELLCHECK_IGNORE_ALL:
375 {
376 if (!mpViewShell)
377 return;
378 SdrView* pSdrView = mpViewShell->GetDrawView();
379 if (!pSdrView)
380 return;
381
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();
387
388 if(sIgnoreText == "Spelling")
389 {
390 ESelection aOldSel = rEditView.GetSelection();
391 rEditView.SpellIgnoreWord();
392 rEditView.SetSelection( aOldSel );
393 }
394 }
395 break;
396 case SID_SPELLCHECK_APPLY_SUGGESTION:
397 {
398 if (!mpViewShell)
399 return;
400 SdrView* pSdrView = mpViewShell->GetDrawView();
401 if (!pSdrView)
402 return;
403
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();
409
410 static constexpr OUStringLiteral sSpellingRule(u"Spelling_");
411 sal_Int32 nPos = 0;
412 if(-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
413 {
414 sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u"");
415 rEditView.InsertText( sApplyText );
416 }
417 }
418 break;
419
420 case SID_NOTEBOOKBAR:
421 {
422 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR );
423
424 if ( mpViewShell )
425 {
426 SfxBindings& rBindings( mpViewShell->GetFrame()->GetBindings() );
427
429 sfx2::SfxNotebookBar::ExecMethod( rBindings, pFile ? pFile->GetValue() : "" );
430 else
432 }
433 }
434 break;
435
436 default:
437 break;
438 }
439}
440
441} // end of namespace sd
442
443/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetValue() const
const SfxItemSet & GetEmptyItemSet() const
virtual bool RemoveCharAttribs(sal_uInt16 nWhich)=0
ESelection GetSelection() const
void SetSelection(const ESelection &rNewSel)
void InsertText(const OUString &rNew, bool bSelect=false, bool bLOKShowSelect=true)
OUString SpellIgnoreWord()
EditEngine * GetEditEngine() const
void SetAttribs(const SfxItemSet &rSet)
const EditTextObject & GetTextObject() const
EditView & GetEditView() const
SAL_DLLPRIVATE bool GetOnlineSpell() const
Definition: drawdoc.hxx:431
SAL_DLLPRIVATE void StartOnlineSpelling(bool bForceSpelling=true)
Definition: drawdoc4.cxx:729
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
const OutlinerView * GetTextEditOutlinerView() const
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
virtual OutlinerParaObject * GetOutlinerParaObject() const
virtual SdrObjKind GetObjIdentifier() const
void ClearMergedItem(const sal_uInt16 nWhich=0)
void SetMergedItem(const SfxPoolItem &rItem)
static SfxAbstractDialogFactory * Create()
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
virtual void Invalidate(sal_uInt16 nId=0) override
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void SetReturnValue(const SfxPoolItem &)
void Done(bool bRemove=false)
SfxViewFrame * GetFrame() const
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
static SfxInterface * GetStaticInterface()
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
SfxBindings & GetBindings()
static LanguageType GetLanguageType(std::u16string_view rStr)
const XColorListRef & GetColorList() const
virtual SvxSearchItem * Clone(SfxItemPool *pPool=nullptr) const override
void Execute(SfxRequest &rReq)
Handles SFX-Requests.
Definition: docshel3.cxx:134
::sd::ViewShell * mpViewShell
void CancelSearching()
Definition: docshell.cxx:381
SdDrawDocument * mpDoc
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuhhconv.cxx:88
static FuSearch * createPtr(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fusearch.cxx:60
rtl::Reference< FuSearch > & getFunctionSearch()
Definition: View.hxx:77
void setSearchFunction(rtl::Reference< FuSearch > const &xFunction)
Definition: View.hxx:82
static bool IsRunning(ViewShellBase const &rBase)
returns true if there is a running presentation for the given ViewShellBase
Definition: slideshow.cxx:208
SdDrawDocument * GetDoc() const
Definition: viewshel.cxx:1412
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
::sd::View * GetView() const
Definition: ViewShell.hxx:144
SD_DLLPUBLIC weld::Window * GetFrameWeld() const
Definition: viewshel.cxx:1582
SD_DLLPUBLIC ViewShellBase & GetViewShellBase() const
Definition: viewshel.cxx:1397
SdrView * GetDrawView() const
Definition: ViewShell.hxx:552
SearchContext & getSearchContext()
Definition: View.hxx:253
static void ExecMethod(SfxBindings &rBindings, const OUString &rUIName)
static void CloseMethod(SfxBindings &rBindings)
static bool IsActive(bool bConsiderSingleToolbar=false)
float u
#define EE_TEXTPOS_ALL
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
sal_Int64 n
#define LANGUAGE_NONE
#define LANGUAGE_KOREAN
#define LANGUAGE_DONTKNOW
SvtScriptType
sal_uInt16 nPos
SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
static void lcl_setLanguage(const SdDrawDocument *pDoc, std::u16string_view rLanguage, bool bLanguageNone=false)
Definition: docshel3.cxx:111
static void lcl_setLanguageForObj(SdrObject *pObj, LanguageType nLang, bool bLanguageNone)
Definition: docshel3.cxx:57
#define SD_MOD()
Definition: sdmod.hxx:184
sal_Int32 nEndPos
sal_Int32 nStartPos