LibreOffice Module sd (master) 1
docshell.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 <officecfg/Office/Common.hxx>
24
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>
46#include <svl/cjkoptions.hxx>
47#include <svl/visitem.hxx>
48
49#include <app.hrc>
50#include <sdmod.hxx>
51#include <View.hxx>
52#include <drawdoc.hxx>
53
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>
61#include <comphelper/lok.hxx>
62#include <DrawViewShell.hxx>
63#include <sdpage.hxx>
65
66using namespace sd;
67#define ShellClass_DrawDocShell
68#include <sdslots.hxx>
69
71
72void DrawDocShell::InitInterface_Impl()
73{
74 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
75}
76
77namespace sd {
78
85 SvGlobalName(SO3_SIMPRESS_CLASSID),
86 "simpress" )
87
88void DrawDocShell::Construct( bool bClipboard )
89{
90 mbInDestruction = false;
91 SetSlotFilter(); // resets the filter
92
93 mbOwnDocument = mpDoc == nullptr;
94 if( mbOwnDocument )
95 mpDoc = new SdDrawDocument(meDocType, this);
96
97 // The document has been created so we can call UpdateRefDevice() to set
98 // the document's ref device.
99 UpdateRefDevice();
100
101 SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
102 SetPool( &mpDoc->GetItemPool() );
103 std::unique_ptr<sd::UndoManager> pUndoManager(new sd::UndoManager);
104 pUndoManager->SetDocShell(this);
105 mpUndoManager = std::move(pUndoManager);
106
108 && officecfg::Office::Common::Undo::Steps::get() < 1)
109 {
110 mpUndoManager->EnableUndo(false); // tdf#108863 disable if 0 steps
111 }
112 mpDoc->SetSdrUndoManager( mpUndoManager.get() );
113 mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
114 UpdateTablePointers();
115 SetStyleFamily(SfxStyleFamily::Pseudo);
116}
117
119 bool bDataObject,
120 DocumentType eDocumentType) :
122 mpDoc(nullptr),
123 mpPrinter(nullptr),
124 mpViewShell(nullptr),
125 meDocType(eDocumentType),
126 mbSdDataObj(bDataObject),
127 mbOwnPrinter(false)
128{
129 Construct( eMode == SfxObjectCreateMode::INTERNAL );
130}
131
132DrawDocShell::DrawDocShell( SfxModelFlags nModelCreationFlags, bool bDataObject, DocumentType eDocumentType ) :
133 SfxObjectShell( nModelCreationFlags ),
134 mpDoc(nullptr),
135 mpPrinter(nullptr),
136 mpViewShell(nullptr),
137 meDocType(eDocumentType),
138 mbSdDataObj(bDataObject),
139 mbOwnPrinter(false)
140{
141 Construct( false );
142}
143
145 bool bDataObject,
146 DocumentType eDocumentType) :
148 mpDoc(pDoc),
149 mpPrinter(nullptr),
150 mpViewShell(nullptr),
151 meDocType(eDocumentType),
152 mbSdDataObj(bDataObject),
153 mbOwnPrinter(false)
154{
155 Construct( eMode == SfxObjectCreateMode::INTERNAL );
156}
157
159{
160 // Tell all listeners that the doc shell is about to be
161 // destroyed. This has been introduced for the PreviewRenderer to
162 // free its view (that uses the item poll of the doc shell) but
163 // may be useful in other places as well.
164 Broadcast(SfxHint(SfxHintId::Dying));
165
166 mbInDestruction = true;
167
168 if (mpViewShell)
169 {
170 auto* pView = mpViewShell->GetView();
171 if (pView)
172 {
173 auto & pSearchContext = pView->getSearchContext();
174 pSearchContext.resetSearchFunction();
175 }
176 }
177
178 mpFontList.reset();
179
180 if( mpDoc )
181 mpDoc->SetSdrUndoManager( nullptr );
182 mpUndoManager.reset();
183
184 if (mbOwnPrinter)
186
187 if( mbOwnDocument )
188 delete mpDoc;
189
190 // that the navigator get informed about the disappearance of the document
191 SfxBoolItem aItem(SID_NAVIGATOR_INIT, true);
193
194 if( !pFrame )
195 pFrame = SfxViewFrame::GetFirst( this );
196
197 if( pFrame )
198 {
199 pFrame->GetDispatcher()->ExecuteList(
200 SID_NAVIGATOR_INIT, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
201 { &aItem });
202 }
203}
204
206{
207
208 SfxWhichIter aIter( rSet );
209 sal_uInt16 nWhich = aIter.FirstWhich();
210
211 while ( nWhich )
212 {
213 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
214 ? GetPool().GetSlotId(nWhich)
215 : nWhich;
216
217 switch ( nSlotId )
218 {
219 case SID_ATTR_CHAR_FONTLIST:
220 rSet.Put( SvxFontListItem( mpFontList.get(), nSlotId ) );
221 break;
222
223 case SID_SEARCH_ITEM:
224 {
225 rSet.Put( *SD_MOD()->GetSearchItem() );
226 }
227 break;
228
229 case SID_CLOSEDOC:
231 break;
232
233 case SID_SEARCH_OPTIONS:
234 {
235 SearchOptionFlags nOpt = SearchOptionFlags::SEARCH |
236 SearchOptionFlags::WHOLE_WORDS |
237 SearchOptionFlags::BACKWARDS |
238 SearchOptionFlags::REG_EXP |
239 SearchOptionFlags::EXACT |
240 SearchOptionFlags::SIMILARITY |
241 SearchOptionFlags::SELECTION;
242
243 if (!IsReadOnly())
244 {
245 nOpt |= SearchOptionFlags::REPLACE;
246 nOpt |= SearchOptionFlags::REPLACE_ALL;
247 }
248
249 rSet.Put(SfxUInt16Item(nWhich, static_cast<sal_uInt16>(nOpt)));
250 }
251 break;
252
253 case SID_VERSION:
254 {
256 }
257 break;
258
259 case SID_CHINESE_CONVERSION:
260 case SID_HANGUL_HANJA_CONVERSION:
261 {
263 }
264 break;
265 case SID_LANGUAGE_STATUS:
266 {
267 SdrObject* pObj = nullptr;
268 bool bLanguageFound = false;
269 OutlinerParaObject* pParaObj = nullptr;
270 LanguageType eLanguage( LANGUAGE_DONTKNOW );
271 sal_uInt16 nCount = mpDoc->GetPageCount();
272 for ( sal_uInt16 itPage = 0; itPage < nCount && !bLanguageFound; itPage++ )
273 {
274 SdrObjListIter aListIter(mpDoc->GetPage(itPage), SdrIterMode::DeepWithGroups);
275 while ( aListIter.IsMore() && !bLanguageFound )
276 {
277 pObj = aListIter.Next();
278 if ( pObj )
279 {
280 pParaObj = pObj->GetOutlinerParaObject();
281 if ( pParaObj )
282 {
283 SdrOutliner aOutliner(&mpDoc->GetPool(), OutlinerMode::TextObject);
284 aOutliner.SetText(*pParaObj);
285 eLanguage = aOutliner.GetLanguage(0, 0);
286 bLanguageFound = eLanguage != LANGUAGE_DONTKNOW;
287 }
288 }
289 }
290 }
291
292 if ( eLanguage == LANGUAGE_DONTKNOW )
293 {
294 eLanguage = mpDoc->GetLanguage( EE_CHAR_LANGUAGE );
295 }
296
297 OUString aLanguage = SvtLanguageTable::GetLanguageString(eLanguage);
299 {
300 if (eLanguage == LANGUAGE_DONTKNOW)
301 {
302 aLanguage += ";-";
303 }
304 else
305 {
306 aLanguage += ";" + LanguageTag(eLanguage).getBcp47(false);
307 }
308 }
309 rSet.Put(SfxStringItem(nWhich, aLanguage));
310 }
311 break;
312
313 case SID_NOTEBOOKBAR:
314 {
315 if (mpViewShell)
316 {
317 bool bImpress = mpDoc->GetDocumentType() == DocumentType::Impress;
318 bool bVisible = false;
319 if(bImpress)
320 {
322 u"modules/simpress/ui/");
323 }
324 else
325 {
327 u"modules/sdraw/ui/");
328 }
329 rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) );
330 }
331 }
332 break;
333
334 default:
335 break;
336 }
337 nWhich = aIter.NextWhich();
338 }
339
340 if (SfxViewFrame* pFrame = SfxViewFrame::Current())
341 {
342 if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN)
343 {
344 pFrame->GetSlotState(SID_RELOAD,
345 pFrame->GetInterface(), &rSet);
346 }
347 }
348}
349
351{
352 if (bMDI)
353 {
356 }
357}
358
360{
361}
362
364{
365 return mpUndoManager.get();
366}
367
369{
370 PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
371 PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
372 PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
373 PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
374 PutItem( SvxPatternListItem( mpDoc->GetPatternList(), SID_PATTERN_LIST ) );
375 PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
376 PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
377
379}
380
382{
383 if (mpViewShell)
384 {
385 auto* pView = mpViewShell->GetView();
386 if (pView)
387 {
388 auto & pSearchContext = pView->getSearchContext();
389 pSearchContext.resetSearchFunction();
390 }
391 }
392}
393
398{
399 SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
400
401 while( pTestViewShell )
402 {
403 if( pTestViewShell->GetObjectShell() == this
404 && pTestViewShell->GetViewFrame().GetDispatcher() )
405 {
406 SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame().GetDispatcher();
407
408 if( !mpFilterSIDs.empty() )
409 pDispatcher->SetSlotFilter( mbFilterEnable ? SfxSlotFilterState::ENABLED : SfxSlotFilterState::DISABLED, mpFilterSIDs );
410 else
411 pDispatcher->SetSlotFilter();
412
413 if( pDispatcher->GetBindings() )
414 pDispatcher->GetBindings()->InvalidateAll( true );
415 }
416
417 pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
418 }
419}
420
421void DrawDocShell::SetModified( bool bSet /* = true */ )
422{
424
425 // change model state, too
426 // only set the changed state if modification is enabled
427 if( IsEnableSetModified() )
428 {
429 if ( mpDoc )
430 mpDoc->NbcSetChanged( bSet );
431
432 Broadcast( SfxHint( SfxHintId::DocChanged ) );
433 }
434}
435
439// ExecuteSpellPopup now handled by DrawDocShell. This is necessary
440// to get hands on the outliner and the text object.
441IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo&, rInfo, void)
442{
443 SdrObject* pObj = nullptr;
444 SdrOutliner* pOutl = nullptr;
445
446 if(GetViewShell())
447 {
448 pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
449 pObj = GetViewShell()->GetView()->GetTextEditObject();
450 }
451
452 mpDoc->ImpOnlineSpellCallback(&rInfo, pObj, pOutl);
453}
454
456{
457 // clear possible undo buffers of outliners
458 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
459 while(pSfxViewFrame)
460 {
461 ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
462 if( pViewShellBase )
463 {
464 std::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
465 if( pViewSh )
466 {
467 ::sd::View* pView = pViewSh->GetView();
468 if( pView )
469 {
470 pView->SdrEndTextEdit();
471 sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
472 if( pOutlView )
473 {
474 pOutlView->GetOutliner().GetUndoManager().Clear();
475 }
476 }
477 }
478 }
479 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
480 }
481
482 SfxUndoManager* pUndoManager = GetUndoManager();
483 if(pUndoManager && pUndoManager->GetUndoActionCount())
484 pUndoManager->Clear();
485}
486
487std::shared_ptr<model::ColorSet> DrawDocShell::GetThemeColors()
488{
489 auto pViewShell = dynamic_cast<sd::DrawViewShell*>(GetViewShell());
490 if (!pViewShell)
491 return {};
492
493 SdPage* pPage = pViewShell->getCurrentPage();
494 auto pTheme = pPage->getSdrPageProperties().GetTheme();
495 if (!pPage->IsMasterPage())
496 pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().GetTheme();
497
498 if (!pTheme)
499 return {};
500
501 return pTheme->getColorSet();
502}
503
504} // end of namespace sd
505
506/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getBcp47(bool bResolveSystem=true) const
SAL_DLLPRIVATE SfxItemPool & GetPool()
Definition: drawdoc.hxx:237
SAL_DLLPRIVATE void NbcSetChanged(bool bFlag)
Definition: drawdoc.cxx:679
SAL_DLLPRIVATE void StartOnlineSpelling(bool bForceSpelling=true)
Definition: drawdoc4.cxx:729
SAL_DLLPRIVATE LanguageType GetLanguage(const sal_uInt16 nId) const
Definition: drawdoc2.cxx:875
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
XBitmapListRef GetBitmapList() const
XDashListRef GetDashList() const
void SetSdrUndoManager(SfxUndoManager *pUndoManager)
XGradientListRef GetGradientList() const
XPatternListRef GetPatternList() const
XLineEndListRef GetLineEndList() const
XColorListRef GetColorList() const
XHatchListRef GetHatchList() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * Next()
bool IsMore() const
virtual OutlinerParaObject * GetOutlinerParaObject() const
std::shared_ptr< model::Theme > const & GetTheme() const
SdrPage & TRG_GetMasterPage() const
bool IsMasterPage() const
SdrPageProperties & getSdrPageProperties()
void InvalidateAll(bool bWithMsg)
SfxBindings * GetBindings() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
void SetSlotFilter(SfxSlotFilterState nEnable=SfxSlotFilterState::DISABLED, o3tl::span< sal_uInt16 const > pSIDs=o3tl::span< sal_uInt16 const >())
void RegisterChildWindow(sal_uInt16, bool bContext=false)
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
static bool IsWhich(sal_uInt16 nId)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool IsEnableSetModified() const
bool IsReadOnly() const
virtual void SetModified(bool bModified=true)
void PutItem(const SfxPoolItem &rItem)
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
SfxItemPool & GetPool() const
SfxViewFrame * GetFrame() const
virtual SfxInterface * GetInterface() const
static SfxInterface * GetStaticInterface()
SfxViewShell * GetViewShell() const
virtual void Clear()
virtual size_t GetUndoActionCount(bool const i_currentLevel=CurrentLevel) const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxBindings & GetBindings()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxDispatcher * GetDispatcher()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxViewFrame & GetViewFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
virtual SfxObjectShell * GetObjectShell() override
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
static OUString GetLanguageString(const LanguageType eType)
void disposeAndClear()
constexpr bool empty() const noexcept
virtual SfxUndoManager * GetUndoManager() override
Definition: docshell.cxx:363
void ClearUndoBuffer()
Definition: docshell.cxx:455
virtual ~DrawDocShell() override
Definition: docshell.cxx:158
virtual void Activate(bool bMDI) override
Definition: docshell.cxx:350
sd::ViewShell * GetViewShell()
::sd::ViewShell * mpViewShell
void Construct(bool bClipboard)
std::unique_ptr< FontList > mpFontList
VclPtr< SfxPrinter > mpPrinter
virtual void Deactivate(bool bMDI) override
Definition: docshell.cxx:359
virtual void SetModified(bool=true) override
Definition: docshell.cxx:421
void ApplySlotFilter() const
apply configured slot filters
Definition: docshell.cxx:397
void CancelSearching()
Definition: docshell.cxx:381
std::unique_ptr< SfxUndoManager > mpUndoManager
void GetState(SfxItemSet &)
Definition: docshell.cxx:205
SdDrawDocument * mpDoc
o3tl::span< sal_uInt16 const > mpFilterSIDs
DrawDocShell(SfxObjectCreateMode eMode, bool bSdDataObj, DocumentType)
Definition: docshell.cxx:118
std::shared_ptr< model::ColorSet > GetThemeColors() override
Definition: docshell.cxx:487
void UpdateTablePointers()
Definition: docshell.cxx:368
void UpdateFontList()
Definition: docshel4.cxx:161
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
Derivative of sd::View for the outline mode |* .
Definition: OutlineView.hxx:55
SdrOutliner & GetOutliner()
Definition: OutlineView.hxx:82
void resetSearchFunction()
Definition: View.hxx:88
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
::sd::View * GetView() const
Definition: ViewShell.hxx:144
SearchContext & getSearchContext()
Definition: View.hxx:253
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
static bool StateMethod(SfxBindings &rBindings, std::u16string_view rUIFile, bool bReloadNotebookbar=false)
static bool IsFuzzing()
int nCount
SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell)
float u
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
Mode eMode
#define LANGUAGE_DONTKNOW
bool IsAnyEnabled()
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
SFX_IMPL_OBJECTFACTORY(DrawDocShell, SvGlobalName(SO3_SIMPRESS_CLASSID), "simpress") void DrawDocShell
slotmaps and definitions of SFX
Definition: docshell.cxx:83
DocumentType
SfxObjectCreateMode
#define SD_MOD()
Definition: sdmod.hxx:184
SfxModelFlags
static SfxItemSet & rSet
SearchOptionFlags
bool bVisible