bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / docshell / docshell.cxx
blobca32796f60db541dceeecf25250e38064b507007
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"
21 #include <vcl/svapp.hxx>
23 #include <sfx2/docfac.hxx>
24 #include <sfx2/objface.hxx>
25 #include <sfx2/request.hxx>
26 #include <svx/svxids.hrc>
27 #include <svl/srchitem.hxx>
28 #include <svx/srchdlg.hxx>
29 #include <editeng/flstitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <sfx2/printer.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <svx/drawitem.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <svl/whiter.hxx>
37 #include <svl/itempool.hxx>
38 #include <svtools/ctrltool.hxx>
39 #include <vcl/graphicfilter.hxx>
40 #include <comphelper/classids.hxx>
41 #include <svl/cjkoptions.hxx>
42 #include <svl/visitem.hxx>
44 #include <svx/svdoutl.hxx>
46 #include <sfx2/fcontnr.hxx>
48 #include "app.hrc"
49 #include "sdmod.hxx"
50 #include "strmname.h"
51 #include "stlpool.hxx"
52 #include "strings.hrc"
53 #include "View.hxx"
54 #include "drawdoc.hxx"
55 #include "sdpage.hxx"
56 #include "glob.hrc"
57 #include "res_bmp.hrc"
58 #include "fupoor.hxx"
59 #include "fusearch.hxx"
60 #include "ViewShell.hxx"
61 #include "sdresid.hxx"
62 #include "slideshow.hxx"
63 #include "drawview.hxx"
64 #include "FrameView.hxx"
65 #include "unomodel.hxx"
66 #include "undo/undomanager.hxx"
67 #include "undo/undofactory.hxx"
68 #include "OutlineView.hxx"
69 #include "ViewShellBase.hxx"
71 using namespace sd;
72 #define DrawDocShell
73 #include "sdslots.hxx"
75 SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell);
77 void DrawDocShell::InitInterface_Impl()
79 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
82 namespace sd {
84 /**
85 * slotmaps and definitions of SFX
87 TYPEINIT1( DrawDocShell, SfxObjectShell );
89 SFX_IMPL_OBJECTFACTORY(
90 DrawDocShell,
91 SvGlobalName(SO3_SIMPRESS_CLASSID),
92 SfxObjectShellFlags::STD_NORMAL,
93 "simpress" )
95 void DrawDocShell::Construct( bool bClipboard )
97 mbInDestruction = false;
98 SetSlotFilter(); // setzt Filter zurueck
100 mbOwnDocument = mpDoc == 0;
101 if( mbOwnDocument )
102 mpDoc = new SdDrawDocument(meDocType, this);
104 // The document has been created so we can call UpdateRefDevice() to set
105 // the document's ref device.
106 UpdateRefDevice();
108 SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
109 SetPool( &mpDoc->GetItemPool() );
110 mpUndoManager = new sd::UndoManager;
111 mpDoc->SetSdrUndoManager( mpUndoManager );
112 mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
113 UpdateTablePointers();
114 SetStyleFamily(5); //CL: actually SFX_STYLE_FAMILY_PSEUDO
117 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
118 bool bDataObject,
119 DocumentType eDocumentType) :
120 SfxObjectShell( eMode == SfxObjectCreateMode::INTERNAL ? SfxObjectCreateMode::EMBEDDED : eMode),
121 mpDoc(NULL),
122 mpUndoManager(NULL),
123 mpPrinter(NULL),
124 mpViewShell(NULL),
125 mpFontList(NULL),
126 meDocType(eDocumentType),
127 mpFilterSIDs(0),
128 mbSdDataObj(bDataObject),
129 mbOwnPrinter(false),
130 mbNewDocument( true )
132 Construct( eMode == SfxObjectCreateMode::INTERNAL );
135 DrawDocShell::DrawDocShell( SfxModelFlags nModelCreationFlags, bool bDataObject, DocumentType eDocumentType ) :
136 SfxObjectShell( nModelCreationFlags ),
137 mpDoc(NULL),
138 mpUndoManager(NULL),
139 mpPrinter(NULL),
140 mpViewShell(NULL),
141 mpFontList(NULL),
142 meDocType(eDocumentType),
143 mpFilterSIDs(0),
144 mbSdDataObj(bDataObject),
145 mbOwnPrinter(false),
146 mbNewDocument( true )
148 Construct( false );
151 DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
152 bool bDataObject,
153 DocumentType eDocumentType) :
154 SfxObjectShell(eMode == SfxObjectCreateMode::INTERNAL ? SfxObjectCreateMode::EMBEDDED : eMode),
155 mpDoc(pDoc),
156 mpUndoManager(NULL),
157 mpPrinter(NULL),
158 mpViewShell(NULL),
159 mpFontList(NULL),
160 meDocType(eDocumentType),
161 mpFilterSIDs(0),
162 mbSdDataObj(bDataObject),
163 mbOwnPrinter(false),
164 mbNewDocument( true )
166 Construct( eMode == SfxObjectCreateMode::INTERNAL );
169 DrawDocShell::~DrawDocShell()
171 // Tell all listeners that the doc shell is about to be
172 // destroyed. This has been introduced for the PreviewRenderer to
173 // free its view (that uses the item poll of the doc shell) but
174 // may be useful in other places as well.
175 Broadcast(SfxSimpleHint(SFX_HINT_DYING));
177 mbInDestruction = true;
179 SetDocShellFunction(0);
181 delete mpFontList;
183 if( mpDoc )
184 mpDoc->SetSdrUndoManager( 0 );
185 delete mpUndoManager;
187 if (mbOwnPrinter)
188 mpPrinter.disposeAndClear();
190 if( mbOwnDocument )
191 delete mpDoc;
193 // that the navigator get informed about the disappearance of the document
194 SfxBoolItem aItem(SID_NAVIGATOR_INIT, true);
195 SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
197 if( !pFrame )
198 pFrame = SfxViewFrame::GetFirst( this );
200 if( pFrame )
201 pFrame->GetDispatcher()->Execute(
202 SID_NAVIGATOR_INIT, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L);
205 void DrawDocShell::GetState(SfxItemSet &rSet)
208 SfxWhichIter aIter( rSet );
209 sal_uInt16 nWhich = aIter.FirstWhich();
211 while ( nWhich )
213 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
214 ? GetPool().GetSlotId(nWhich)
215 : nWhich;
217 switch ( nSlotId )
219 case SID_SEARCH_ITEM:
221 rSet.Put( *SD_MOD()->GetSearchItem() );
223 break;
225 case SID_CLOSEDOC:
226 GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
227 break;
229 case SID_SEARCH_OPTIONS:
231 SearchOptionFlags nOpt = SearchOptionFlags::SEARCH |
232 SearchOptionFlags::WHOLE_WORDS |
233 SearchOptionFlags::BACKWARDS |
234 SearchOptionFlags::REG_EXP |
235 SearchOptionFlags::EXACT |
236 SearchOptionFlags::SIMILARITY |
237 SearchOptionFlags::SELECTION;
239 if (!IsReadOnly())
241 nOpt |= SearchOptionFlags::REPLACE;
242 nOpt |= SearchOptionFlags::REPLACE_ALL;
245 rSet.Put(SfxUInt16Item(nWhich, static_cast<sal_uInt16>(nOpt)));
247 break;
249 case SID_VERSION:
251 GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
253 break;
255 case SID_CHINESE_CONVERSION:
256 case SID_HANGUL_HANJA_CONVERSION:
258 rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
260 break;
261 case SID_LANGUAGE_STATUS:
263 // Keeping this enabled for the time being
264 rSet.Put(SfxVisibilityItem(nWhich, true));
266 break;
268 default:
269 break;
271 nWhich = aIter.NextWhich();
274 SfxViewFrame* pFrame = SfxViewFrame::Current();
276 if (pFrame)
278 if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN)
280 pFrame->GetSlotState(SID_RELOAD,
281 pFrame->GetInterface(), &rSet);
286 void DrawDocShell::InPlaceActivate( bool bActive )
288 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
289 std::vector<FrameView*> &rViews = mpDoc->GetFrameViewList();
291 if( !bActive )
293 std::vector<FrameView*>::iterator pIter;
294 for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
295 delete *pIter;
297 rViews.clear();
299 while (pSfxViewFrame)
301 // determine the number of FrameViews
302 SfxViewShell* pSfxViewSh = pSfxViewFrame->GetViewShell();
303 // FIXME this used to be a PTR_CAST, but when I updated the macro, I discovered that SfxViewShell is not statically castable to sd::ViewShell
304 ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
306 if ( pViewSh && pViewSh->GetFrameView() )
308 pViewSh->WriteFrameViewData();
309 rViews.push_back( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
312 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
316 SfxObjectShell::InPlaceActivate( bActive );
318 if( bActive )
320 for( sal_uInt32 i = 0; pSfxViewFrame && (i < rViews.size()); i++ )
322 // determine the number of FrameViews
323 SfxViewShell* pSfxViewSh = pSfxViewFrame->GetViewShell();
324 // FIXME this used to be a PTR_CAST, but when I updated the macro, I discovered that SfxViewShell is not statically castable to sd::ViewShell
325 ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
327 if ( pViewSh )
329 pViewSh->ReadFrameViewData( rViews[ i ] );
332 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
337 void DrawDocShell::Activate( bool bMDI)
339 if (bMDI)
341 ApplySlotFilter();
342 mpDoc->StartOnlineSpelling();
346 void DrawDocShell::Deactivate( bool )
350 ::svl::IUndoManager* DrawDocShell::GetUndoManager()
352 return mpUndoManager;
355 void DrawDocShell::UpdateTablePointers()
357 PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
358 PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
359 PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
360 PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
361 PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
362 PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
364 UpdateFontList();
367 void DrawDocShell::CancelSearching()
369 if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) )
371 SetDocShellFunction(0);
376 * apply configured slot filters
378 void DrawDocShell::ApplySlotFilter() const
380 SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
382 while( pTestViewShell )
384 if( pTestViewShell->GetObjectShell()
385 == this
386 && pTestViewShell->GetViewFrame()
387 && pTestViewShell->GetViewFrame()->GetDispatcher() )
389 SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame()->GetDispatcher();
391 if( mpFilterSIDs )
392 pDispatcher->SetSlotFilter( mbFilterEnable ? SfxSlotFilterState::ENABLED : SfxSlotFilterState::DISABLED, mnFilterCount, mpFilterSIDs );
393 else
394 pDispatcher->SetSlotFilter();
396 if( pDispatcher->GetBindings() )
397 pDispatcher->GetBindings()->InvalidateAll( true );
400 pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
404 void DrawDocShell::SetModified( bool bSet /* = true */ )
406 SfxObjectShell::SetModified( bSet );
408 // change model state, too
409 // only set the changed state if modification is enabled
410 if( IsEnableSetModified() )
412 if ( mpDoc )
413 mpDoc->NbcSetChanged( bSet );
415 Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
420 * Callback for ExecuteSpellPopup()
422 // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
423 // to get hands on the outliner and the text object.
424 IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
426 SdrObject* pObj = NULL;
427 SdrOutliner* pOutl = NULL;
429 if(GetViewShell())
431 pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
432 pObj = GetViewShell()->GetView()->GetTextEditObject();
435 mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
436 return 0;
439 void DrawDocShell::ClearUndoBuffer()
441 // clear possible undo buffers of outliners
442 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
443 while(pSfxViewFrame)
445 ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
446 if( pViewShellBase )
448 ::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
449 if( pViewSh.get() )
451 ::sd::View* pView = pViewSh->GetView();
452 if( pView )
454 pView->SdrEndTextEdit();
455 sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
456 if( pOutlView )
458 pOutlView->GetOutliner().GetUndoManager().Clear();
463 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
466 ::svl::IUndoManager* pUndoManager = GetUndoManager();
467 if(pUndoManager && pUndoManager->GetUndoActionCount())
468 pUndoManager->Clear();
471 void DrawDocShell::libreOfficeKitCallback(int nType, const char* pPayload) const
473 if (mpDoc)
474 mpDoc->libreOfficeKitCallback(nType, pPayload);
477 bool DrawDocShell::isTiledRendering() const
479 if (!mpDoc)
480 return false;
481 return mpDoc->isTiledRendering();
486 } // end of namespace sd
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */