sw: lokit: make sure to read annotation html with utf-8
[LibreOffice.git] / sd / source / ui / docshell / docshell.cxx
blob834de494115922c5a920b52c2be783e6ba52ab12
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 <officecfg/Office/Common.hxx>
23 #include <unotools/configmgr.hxx>
25 #include <sfx2/docfac.hxx>
26 #include <sfx2/objface.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <svx/svxids.hrc>
29 #include <svl/srchitem.hxx>
30 #include <svx/srchdlg.hxx>
31 #include <svx/svdoutl.hxx>
32 #include <svx/svditer.hxx>
33 #include <editeng/flstitem.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/intitem.hxx>
37 #include <sfx2/printer.hxx>
38 #include <svx/drawitem.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <svl/whiter.hxx>
41 #include <svl/itempool.hxx>
42 #include <svl/stritem.hxx>
43 #include <svtools/ctrltool.hxx>
44 #include <svtools/langtab.hxx>
45 #include <comphelper/classids.hxx>
46 #include <svl/cjkoptions.hxx>
47 #include <svl/visitem.hxx>
49 #include <app.hrc>
50 #include <sdmod.hxx>
51 #include <View.hxx>
52 #include <drawdoc.hxx>
54 #include <ViewShell.hxx>
55 #include <unomodel.hxx>
56 #include <undo/undomanager.hxx>
57 #include <undo/undofactory.hxx>
58 #include <OutlineView.hxx>
59 #include <ViewShellBase.hxx>
60 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
61 #include <comphelper/lok.hxx>
62 #include <DrawViewShell.hxx>
63 #include <sdpage.hxx>
64 #include <docmodel/theme/Theme.hxx>
65 #include <Outliner.hxx>
67 using namespace sd;
68 #define ShellClass_DrawDocShell
69 #include <sdslots.hxx>
71 SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell);
73 void DrawDocShell::InitInterface_Impl()
75 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
78 namespace sd {
80 /**
81 * slotmaps and definitions of SFX
84 SFX_IMPL_OBJECTFACTORY(
85 DrawDocShell,
86 SvGlobalName(SO3_SIMPRESS_CLASSID),
87 u"simpress"_ustr )
89 void DrawDocShell::Construct( bool bClipboard )
91 mbInDestruction = false;
92 SetSlotFilter(); // resets the filter
94 mbOwnDocument = mpDoc == nullptr;
95 if( mbOwnDocument )
96 mpDoc = new SdDrawDocument(meDocType, this);
98 // The document has been created so we can call UpdateRefDevice() to set
99 // the document's ref device.
100 UpdateRefDevice();
102 SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
103 SetPool( &mpDoc->GetItemPool() );
104 std::unique_ptr<sd::UndoManager> pUndoManager(new sd::UndoManager);
105 pUndoManager->SetDocShell(this);
106 mpUndoManager = std::move(pUndoManager);
108 if (!comphelper::IsFuzzing()
109 && officecfg::Office::Common::Undo::Steps::get() < 1)
111 mpUndoManager->EnableUndo(false); // tdf#108863 disable if 0 steps
113 mpDoc->SetSdrUndoManager( mpUndoManager.get() );
114 mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
115 UpdateTablePointers();
116 SetStyleFamily(SfxStyleFamily::Pseudo);
119 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
120 bool bDataObject,
121 DocumentType eDocumentType) :
122 SfxObjectShell( eMode == SfxObjectCreateMode::INTERNAL ? SfxObjectCreateMode::EMBEDDED : eMode),
123 mpDoc(nullptr),
124 mpPrinter(nullptr),
125 mpViewShell(nullptr),
126 meDocType(eDocumentType),
127 mbSdDataObj(bDataObject),
128 mbOwnPrinter(false)
130 Construct( eMode == SfxObjectCreateMode::INTERNAL );
133 DrawDocShell::DrawDocShell( SfxModelFlags nModelCreationFlags, bool bDataObject, DocumentType eDocumentType ) :
134 SfxObjectShell( nModelCreationFlags ),
135 mpDoc(nullptr),
136 mpPrinter(nullptr),
137 mpViewShell(nullptr),
138 meDocType(eDocumentType),
139 mbSdDataObj(bDataObject),
140 mbOwnPrinter(false)
142 Construct( false );
145 DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
146 bool bDataObject,
147 DocumentType eDocumentType) :
148 SfxObjectShell(eMode == SfxObjectCreateMode::INTERNAL ? SfxObjectCreateMode::EMBEDDED : eMode),
149 mpDoc(pDoc),
150 mpPrinter(nullptr),
151 mpViewShell(nullptr),
152 meDocType(eDocumentType),
153 mbSdDataObj(bDataObject),
154 mbOwnPrinter(false)
156 Construct( eMode == SfxObjectCreateMode::INTERNAL );
159 DrawDocShell::~DrawDocShell()
161 // Tell all listeners that the doc shell is about to be
162 // destroyed. This has been introduced for the PreviewRenderer to
163 // free its view (that uses the item poll of the doc shell) but
164 // may be useful in other places as well.
165 Broadcast(SfxHint(SfxHintId::Dying));
167 mbInDestruction = true;
169 if (mpViewShell)
171 auto* pView = mpViewShell->GetView();
172 if (pView)
174 auto & pSearchContext = pView->getSearchContext();
175 pSearchContext.resetSearchFunction();
179 mpFontList.reset();
181 if( mpDoc )
182 mpDoc->SetSdrUndoManager( nullptr );
183 mpUndoManager.reset();
185 if (mbOwnPrinter)
186 mpPrinter.disposeAndClear();
188 if( mbOwnDocument )
189 delete mpDoc;
191 // that the navigator get informed about the disappearance of the document
192 SfxBoolItem aItem(SID_NAVIGATOR_INIT, true);
193 SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
195 if( !pFrame )
196 pFrame = SfxViewFrame::GetFirst( this );
198 if( pFrame )
200 pFrame->GetDispatcher()->ExecuteList(
201 SID_NAVIGATOR_INIT, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
202 { &aItem });
206 void DrawDocShell::GetState(SfxItemSet &rSet)
209 SfxWhichIter aIter( rSet );
210 sal_uInt16 nWhich = aIter.FirstWhich();
212 while ( nWhich )
214 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
215 ? GetPool().GetSlotId(nWhich)
216 : nWhich;
218 switch ( nSlotId )
220 case SID_ATTR_CHAR_FONTLIST:
221 rSet.Put( SvxFontListItem( mpFontList.get(), nSlotId ) );
222 break;
224 case SID_SEARCH_ITEM:
226 rSet.Put(*SdModule::get()->GetSearchItem());
228 break;
230 case SID_CLOSEDOC:
231 GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
232 break;
234 case SID_SEARCH_OPTIONS:
236 SearchOptionFlags nOpt = SearchOptionFlags::SEARCH |
237 SearchOptionFlags::WHOLE_WORDS |
238 SearchOptionFlags::BACKWARDS |
239 SearchOptionFlags::REG_EXP |
240 SearchOptionFlags::EXACT |
241 SearchOptionFlags::SIMILARITY |
242 SearchOptionFlags::SELECTION;
244 if (!IsReadOnly())
246 nOpt |= SearchOptionFlags::REPLACE;
247 nOpt |= SearchOptionFlags::REPLACE_ALL;
250 rSet.Put(SfxUInt16Item(nWhich, static_cast<sal_uInt16>(nOpt)));
252 break;
254 case SID_VERSION:
256 GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
258 break;
260 case SID_CHINESE_CONVERSION:
261 case SID_HANGUL_HANJA_CONVERSION:
263 rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions::IsAnyEnabled()));
265 break;
266 case SID_LANGUAGE_STATUS:
268 SdrObject* pObj = nullptr;
269 bool bLanguageFound = false;
270 OutlinerParaObject* pParaObj = nullptr;
271 LanguageType eLanguage( LANGUAGE_DONTKNOW );
272 sal_uInt16 nCount = mpDoc->GetPageCount();
273 for ( sal_uInt16 itPage = 0; itPage < nCount && !bLanguageFound; itPage++ )
275 SdrObjListIter aListIter(mpDoc->GetPage(itPage), SdrIterMode::DeepWithGroups);
276 while ( aListIter.IsMore() && !bLanguageFound )
278 pObj = aListIter.Next();
279 if ( pObj )
281 pParaObj = pObj->GetOutlinerParaObject();
282 if ( pParaObj )
284 SdrOutliner aOutliner(&mpDoc->GetPool(), OutlinerMode::TextObject);
285 aOutliner.SetText(*pParaObj);
286 eLanguage = aOutliner.GetLanguage(0, 0);
287 bLanguageFound = eLanguage != LANGUAGE_DONTKNOW;
293 if ( eLanguage == LANGUAGE_DONTKNOW )
295 eLanguage = mpDoc->GetLanguage( EE_CHAR_LANGUAGE );
298 OUString aLanguage = SvtLanguageTable::GetLanguageString(eLanguage);
299 if (comphelper::LibreOfficeKit::isActive())
301 if (eLanguage == LANGUAGE_DONTKNOW)
303 aLanguage += ";-";
305 else
307 aLanguage += ";" + LanguageTag(eLanguage).getBcp47(false);
310 rSet.Put(SfxStringItem(nWhich, aLanguage));
312 break;
314 case SID_NOTEBOOKBAR:
316 if (mpViewShell)
318 bool bImpress = mpDoc->GetDocumentType() == DocumentType::Impress;
319 bool bVisible = false;
320 if(bImpress)
322 bVisible = sfx2::SfxNotebookBar::StateMethod(mpViewShell->GetFrame()->GetBindings(),
323 u"modules/simpress/ui/");
325 else
327 bVisible = sfx2::SfxNotebookBar::StateMethod(mpViewShell->GetFrame()->GetBindings(),
328 u"modules/sdraw/ui/");
330 rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) );
333 break;
335 default:
336 break;
338 nWhich = aIter.NextWhich();
341 if (SfxViewFrame* pFrame = SfxViewFrame::Current())
343 if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN)
345 pFrame->GetSlotState(SID_RELOAD,
346 pFrame->GetInterface(), &rSet);
351 void DrawDocShell::Activate( bool bMDI)
353 if (bMDI)
355 ApplySlotFilter();
356 mpDoc->StartOnlineSpelling();
360 void DrawDocShell::Deactivate( bool )
364 SfxUndoManager* DrawDocShell::GetUndoManager()
366 return mpUndoManager.get();
369 void DrawDocShell::UpdateTablePointers()
371 PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
372 PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
373 PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
374 PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
375 PutItem( SvxPatternListItem( mpDoc->GetPatternList(), SID_PATTERN_LIST ) );
376 PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
377 PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
379 UpdateFontList();
382 void DrawDocShell::CancelSearching()
384 if (mpViewShell)
386 auto* pView = mpViewShell->GetView();
387 if (pView)
389 auto & pSearchContext = pView->getSearchContext();
390 pSearchContext.resetSearchFunction();
396 * apply configured slot filters
398 void DrawDocShell::ApplySlotFilter() const
400 SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
402 while( pTestViewShell )
404 if( pTestViewShell->GetObjectShell() == this
405 && pTestViewShell->GetViewFrame().GetDispatcher() )
407 SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame().GetDispatcher();
409 if( !mpFilterSIDs.empty() )
410 pDispatcher->SetSlotFilter( mbFilterEnable ? SfxSlotFilterState::ENABLED : SfxSlotFilterState::DISABLED, mpFilterSIDs );
411 else
412 pDispatcher->SetSlotFilter();
414 if( pDispatcher->GetBindings() )
415 pDispatcher->GetBindings()->InvalidateAll( true );
418 pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
422 void DrawDocShell::SetModified( bool bSet /* = true */ )
424 SfxObjectShell::SetModified( bSet );
426 // change model state, too
427 // only set the changed state if modification is enabled
428 if( IsEnableSetModified() )
430 if ( mpDoc )
431 mpDoc->NbcSetChanged( bSet );
433 Broadcast( SfxHint( SfxHintId::DocChanged ) );
438 * Callback for ExecuteSpellPopup()
440 // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
441 // to get hands on the outliner and the text object.
442 IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo&, rInfo, void)
444 SdrObject* pObj = nullptr;
445 SdrOutliner* pOutl = nullptr;
447 if(GetViewShell())
449 pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
450 pObj = GetViewShell()->GetView()->GetTextEditObject();
453 mpDoc->ImpOnlineSpellCallback(&rInfo, pObj, pOutl);
456 void DrawDocShell::ClearUndoBuffer()
458 // clear possible undo buffers of outliners
459 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
460 while(pSfxViewFrame)
462 ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
463 if( pViewShellBase )
465 std::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
466 if( pViewSh )
468 ::sd::View* pView = pViewSh->GetView();
469 if( pView )
471 pView->SdrEndTextEdit();
472 sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
473 if( pOutlView )
475 pOutlView->GetOutliner().GetUndoManager().Clear();
480 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
483 SfxUndoManager* pUndoManager = GetUndoManager();
484 if(pUndoManager && pUndoManager->GetUndoActionCount())
485 pUndoManager->Clear();
488 std::shared_ptr<model::ColorSet> DrawDocShell::GetThemeColors()
490 auto pViewShell = dynamic_cast<sd::DrawViewShell*>(GetViewShell());
491 if (!pViewShell)
492 return {};
494 SdPage* pPage = pViewShell->getCurrentPage();
495 auto pTheme = pPage->getSdrPageProperties().getTheme();
496 if (!pPage->IsMasterPage())
497 pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().getTheme();
499 if (!pTheme)
500 return {};
502 return pTheme->getColorSet();
505 } // end of namespace sd
507 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */