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 .
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>
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>
64 #include <docmodel/theme/Theme.hxx>
67 #define ShellClass_DrawDocShell
68 #include <sdslots.hxx>
70 SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell
, SfxObjectShell
);
72 void DrawDocShell::InitInterface_Impl()
74 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
80 * slotmaps and definitions of SFX
83 SFX_IMPL_OBJECTFACTORY(
85 SvGlobalName(SO3_SIMPRESS_CLASSID
),
88 void DrawDocShell::Construct( bool bClipboard
)
90 mbInDestruction
= false;
91 SetSlotFilter(); // resets the filter
93 mbOwnDocument
= mpDoc
== nullptr;
95 mpDoc
= new SdDrawDocument(meDocType
, this);
97 // The document has been created so we can call UpdateRefDevice() to set
98 // the document's ref device.
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
);
107 if (!utl::ConfigManager::IsFuzzing()
108 && officecfg::Office::Common::Undo::Steps::get() < 1)
110 mpUndoManager
->EnableUndo(false); // tdf#108863 disable if 0 steps
112 mpDoc
->SetSdrUndoManager( mpUndoManager
.get() );
113 mpDoc
->SetSdrUndoFactory( new sd::UndoFactory
);
114 UpdateTablePointers();
115 SetStyleFamily(SfxStyleFamily::Pseudo
);
118 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode
,
120 DocumentType eDocumentType
) :
121 SfxObjectShell( eMode
== SfxObjectCreateMode::INTERNAL
? SfxObjectCreateMode::EMBEDDED
: eMode
),
124 mpViewShell(nullptr),
125 meDocType(eDocumentType
),
126 mbSdDataObj(bDataObject
),
129 Construct( eMode
== SfxObjectCreateMode::INTERNAL
);
132 DrawDocShell::DrawDocShell( SfxModelFlags nModelCreationFlags
, bool bDataObject
, DocumentType eDocumentType
) :
133 SfxObjectShell( nModelCreationFlags
),
136 mpViewShell(nullptr),
137 meDocType(eDocumentType
),
138 mbSdDataObj(bDataObject
),
144 DrawDocShell::DrawDocShell(SdDrawDocument
* pDoc
, SfxObjectCreateMode eMode
,
146 DocumentType eDocumentType
) :
147 SfxObjectShell(eMode
== SfxObjectCreateMode::INTERNAL
? SfxObjectCreateMode::EMBEDDED
: eMode
),
150 mpViewShell(nullptr),
151 meDocType(eDocumentType
),
152 mbSdDataObj(bDataObject
),
155 Construct( eMode
== SfxObjectCreateMode::INTERNAL
);
158 DrawDocShell::~DrawDocShell()
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
));
166 mbInDestruction
= true;
170 auto* pView
= mpViewShell
->GetView();
173 auto & pSearchContext
= pView
->getSearchContext();
174 pSearchContext
.resetSearchFunction();
181 mpDoc
->SetSdrUndoManager( nullptr );
182 mpUndoManager
.reset();
185 mpPrinter
.disposeAndClear();
190 // that the navigator get informed about the disappearance of the document
191 SfxBoolItem
aItem(SID_NAVIGATOR_INIT
, true);
192 SfxViewFrame
* pFrame
= mpViewShell
? mpViewShell
->GetFrame() : GetFrame();
195 pFrame
= SfxViewFrame::GetFirst( this );
199 pFrame
->GetDispatcher()->ExecuteList(
200 SID_NAVIGATOR_INIT
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
205 void DrawDocShell::GetState(SfxItemSet
&rSet
)
208 SfxWhichIter
aIter( rSet
);
209 sal_uInt16 nWhich
= aIter
.FirstWhich();
213 sal_uInt16 nSlotId
= SfxItemPool::IsWhich(nWhich
)
214 ? GetPool().GetSlotId(nWhich
)
219 case SID_ATTR_CHAR_FONTLIST
:
220 rSet
.Put( SvxFontListItem( mpFontList
.get(), nSlotId
) );
223 case SID_SEARCH_ITEM
:
225 rSet
.Put( *SD_MOD()->GetSearchItem() );
230 GetSlotState(SID_CLOSEDOC
, SfxObjectShell::GetInterface(), &rSet
);
233 case SID_SEARCH_OPTIONS
:
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
;
245 nOpt
|= SearchOptionFlags::REPLACE
;
246 nOpt
|= SearchOptionFlags::REPLACE_ALL
;
249 rSet
.Put(SfxUInt16Item(nWhich
, static_cast<sal_uInt16
>(nOpt
)));
255 GetSlotState( SID_VERSION
, SfxObjectShell::GetInterface(), &rSet
);
259 case SID_CHINESE_CONVERSION
:
260 case SID_HANGUL_HANJA_CONVERSION
:
262 rSet
.Put(SfxVisibilityItem(nWhich
, SvtCJKOptions::IsAnyEnabled()));
265 case SID_LANGUAGE_STATUS
:
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
++ )
274 SdrObjListIter
aListIter(mpDoc
->GetPage(itPage
), SdrIterMode::DeepWithGroups
);
275 while ( aListIter
.IsMore() && !bLanguageFound
)
277 pObj
= aListIter
.Next();
280 pParaObj
= pObj
->GetOutlinerParaObject();
283 SdrOutliner
aOutliner(&mpDoc
->GetPool(), OutlinerMode::TextObject
);
284 aOutliner
.SetText(*pParaObj
);
285 eLanguage
= aOutliner
.GetLanguage(0, 0);
286 bLanguageFound
= eLanguage
!= LANGUAGE_DONTKNOW
;
292 if ( eLanguage
== LANGUAGE_DONTKNOW
)
294 eLanguage
= mpDoc
->GetLanguage( EE_CHAR_LANGUAGE
);
297 OUString aLanguage
= SvtLanguageTable::GetLanguageString(eLanguage
);
298 if (comphelper::LibreOfficeKit::isActive())
300 if (eLanguage
== LANGUAGE_DONTKNOW
)
306 aLanguage
+= ";" + LanguageTag(eLanguage
).getBcp47(false);
309 rSet
.Put(SfxStringItem(nWhich
, aLanguage
));
313 case SID_NOTEBOOKBAR
:
317 bool bImpress
= mpDoc
->GetDocumentType() == DocumentType::Impress
;
318 bool bVisible
= false;
321 bVisible
= sfx2::SfxNotebookBar::StateMethod(mpViewShell
->GetFrame()->GetBindings(),
322 u
"modules/simpress/ui/");
326 bVisible
= sfx2::SfxNotebookBar::StateMethod(mpViewShell
->GetFrame()->GetBindings(),
327 u
"modules/sdraw/ui/");
329 rSet
.Put( SfxBoolItem( SID_NOTEBOOKBAR
, bVisible
) );
337 nWhich
= aIter
.NextWhich();
340 if (SfxViewFrame
* pFrame
= SfxViewFrame::Current())
342 if (rSet
.GetItemState(SID_RELOAD
) != SfxItemState::UNKNOWN
)
344 pFrame
->GetSlotState(SID_RELOAD
,
345 pFrame
->GetInterface(), &rSet
);
350 void DrawDocShell::Activate( bool bMDI
)
355 mpDoc
->StartOnlineSpelling();
359 void DrawDocShell::Deactivate( bool )
363 SfxUndoManager
* DrawDocShell::GetUndoManager()
365 return mpUndoManager
.get();
368 void DrawDocShell::UpdateTablePointers()
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
) );
381 void DrawDocShell::CancelSearching()
385 auto* pView
= mpViewShell
->GetView();
388 auto & pSearchContext
= pView
->getSearchContext();
389 pSearchContext
.resetSearchFunction();
395 * apply configured slot filters
397 void DrawDocShell::ApplySlotFilter() const
399 SfxViewShell
* pTestViewShell
= SfxViewShell::GetFirst();
401 while( pTestViewShell
)
403 if( pTestViewShell
->GetObjectShell() == this
404 && pTestViewShell
->GetViewFrame().GetDispatcher() )
406 SfxDispatcher
* pDispatcher
= pTestViewShell
->GetViewFrame().GetDispatcher();
408 if( !mpFilterSIDs
.empty() )
409 pDispatcher
->SetSlotFilter( mbFilterEnable
? SfxSlotFilterState::ENABLED
: SfxSlotFilterState::DISABLED
, mpFilterSIDs
);
411 pDispatcher
->SetSlotFilter();
413 if( pDispatcher
->GetBindings() )
414 pDispatcher
->GetBindings()->InvalidateAll( true );
417 pTestViewShell
= SfxViewShell::GetNext( *pTestViewShell
);
421 void DrawDocShell::SetModified( bool bSet
/* = true */ )
423 SfxObjectShell::SetModified( bSet
);
425 // change model state, too
426 // only set the changed state if modification is enabled
427 if( IsEnableSetModified() )
430 mpDoc
->NbcSetChanged( bSet
);
432 Broadcast( SfxHint( SfxHintId::DocChanged
) );
437 * Callback for ExecuteSpellPopup()
439 // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
440 // to get hands on the outliner and the text object.
441 IMPL_LINK(DrawDocShell
, OnlineSpellCallback
, SpellCallbackInfo
&, rInfo
, void)
443 SdrObject
* pObj
= nullptr;
444 SdrOutliner
* pOutl
= nullptr;
448 pOutl
= GetViewShell()->GetView()->GetTextEditOutliner();
449 pObj
= GetViewShell()->GetView()->GetTextEditObject();
452 mpDoc
->ImpOnlineSpellCallback(&rInfo
, pObj
, pOutl
);
455 void DrawDocShell::ClearUndoBuffer()
457 // clear possible undo buffers of outliners
458 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, false);
461 ViewShellBase
* pViewShellBase
= dynamic_cast< ViewShellBase
* >( pSfxViewFrame
->GetViewShell() );
464 std::shared_ptr
<ViewShell
> pViewSh( pViewShellBase
->GetMainViewShell() );
467 ::sd::View
* pView
= pViewSh
->GetView();
470 pView
->SdrEndTextEdit();
471 sd::OutlineView
* pOutlView
= dynamic_cast< sd::OutlineView
* >( pView
);
474 pOutlView
->GetOutliner().GetUndoManager().Clear();
479 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, false);
482 SfxUndoManager
* pUndoManager
= GetUndoManager();
483 if(pUndoManager
&& pUndoManager
->GetUndoActionCount())
484 pUndoManager
->Clear();
487 std::vector
<Color
> DrawDocShell::GetThemeColors()
489 auto pViewShell
= dynamic_cast<sd::DrawViewShell
*>(GetViewShell());
495 SdPage
* pPage
= pViewShell
->getCurrentPage();
496 model::Theme
* pTheme
= pPage
->getSdrPageProperties().GetTheme().get();
497 if (!pPage
->IsMasterPage())
499 pTheme
= pPage
->TRG_GetMasterPage().getSdrPageProperties().GetTheme().get();
507 return pTheme
->GetColors();
510 } // end of namespace sd
512 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */