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"
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>
51 #include "stlpool.hxx"
52 #include "strings.hrc"
54 #include "drawdoc.hxx"
57 #include "res_bmp.hrc"
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"
73 #include "sdslots.hxx"
75 SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell
, SfxObjectShell
);
77 void DrawDocShell::InitInterface_Impl()
79 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
85 * slotmaps and definitions of SFX
87 TYPEINIT1( DrawDocShell
, SfxObjectShell
);
89 SFX_IMPL_OBJECTFACTORY(
91 SvGlobalName(SO3_SIMPRESS_CLASSID
),
92 SfxObjectShellFlags::STD_NORMAL
,
95 void DrawDocShell::Construct( bool bClipboard
)
97 mbInDestruction
= false;
98 SetSlotFilter(); // setzt Filter zurueck
100 mbOwnDocument
= mpDoc
== 0;
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.
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
,
119 DocumentType eDocumentType
) :
120 SfxObjectShell( eMode
== SfxObjectCreateMode::INTERNAL
? SfxObjectCreateMode::EMBEDDED
: eMode
),
126 meDocType(eDocumentType
),
128 mbSdDataObj(bDataObject
),
130 mbNewDocument( true )
132 Construct( eMode
== SfxObjectCreateMode::INTERNAL
);
135 DrawDocShell::DrawDocShell( SfxModelFlags nModelCreationFlags
, bool bDataObject
, DocumentType eDocumentType
) :
136 SfxObjectShell( nModelCreationFlags
),
142 meDocType(eDocumentType
),
144 mbSdDataObj(bDataObject
),
146 mbNewDocument( true )
151 DrawDocShell::DrawDocShell(SdDrawDocument
* pDoc
, SfxObjectCreateMode eMode
,
153 DocumentType eDocumentType
) :
154 SfxObjectShell(eMode
== SfxObjectCreateMode::INTERNAL
? SfxObjectCreateMode::EMBEDDED
: eMode
),
160 meDocType(eDocumentType
),
162 mbSdDataObj(bDataObject
),
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);
184 mpDoc
->SetSdrUndoManager( 0 );
185 delete mpUndoManager
;
188 mpPrinter
.disposeAndClear();
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();
198 pFrame
= SfxViewFrame::GetFirst( this );
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();
213 sal_uInt16 nSlotId
= SfxItemPool::IsWhich(nWhich
)
214 ? GetPool().GetSlotId(nWhich
)
219 case SID_SEARCH_ITEM
:
221 rSet
.Put( *SD_MOD()->GetSearchItem() );
226 GetSlotState(SID_CLOSEDOC
, SfxObjectShell::GetInterface(), &rSet
);
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
;
241 nOpt
|= SearchOptionFlags::REPLACE
;
242 nOpt
|= SearchOptionFlags::REPLACE_ALL
;
245 rSet
.Put(SfxUInt16Item(nWhich
, static_cast<sal_uInt16
>(nOpt
)));
251 GetSlotState( SID_VERSION
, SfxObjectShell::GetInterface(), &rSet
);
255 case SID_CHINESE_CONVERSION
:
256 case SID_HANGUL_HANJA_CONVERSION
:
258 rSet
.Put(SfxVisibilityItem(nWhich
, SvtCJKOptions().IsAnyEnabled()));
261 case SID_LANGUAGE_STATUS
:
263 // Keeping this enabled for the time being
264 rSet
.Put(SfxVisibilityItem(nWhich
, true));
271 nWhich
= aIter
.NextWhich();
274 SfxViewFrame
* pFrame
= SfxViewFrame::Current();
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();
293 std::vector
<FrameView
*>::iterator pIter
;
294 for ( pIter
= rViews
.begin(); pIter
!= rViews
.end(); ++pIter
)
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
);
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;
329 pViewSh
->ReadFrameViewData( rViews
[ i
] );
332 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, false);
337 void DrawDocShell::Activate( bool bMDI
)
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
) );
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()
386 && pTestViewShell
->GetViewFrame()
387 && pTestViewShell
->GetViewFrame()->GetDispatcher() )
389 SfxDispatcher
* pDispatcher
= pTestViewShell
->GetViewFrame()->GetDispatcher();
392 pDispatcher
->SetSlotFilter( mbFilterEnable
? SfxSlotFilterState::ENABLED
: SfxSlotFilterState::DISABLED
, mnFilterCount
, mpFilterSIDs
);
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() )
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
;
431 pOutl
= GetViewShell()->GetView()->GetTextEditOutliner();
432 pObj
= GetViewShell()->GetView()->GetTextEditObject();
435 mpDoc
->ImpOnlineSpellCallback(pInfo
, pObj
, pOutl
);
439 void DrawDocShell::ClearUndoBuffer()
441 // clear possible undo buffers of outliners
442 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, false);
445 ViewShellBase
* pViewShellBase
= dynamic_cast< ViewShellBase
* >( pSfxViewFrame
->GetViewShell() );
448 ::boost::shared_ptr
<ViewShell
> pViewSh( pViewShellBase
->GetMainViewShell() );
451 ::sd::View
* pView
= pViewSh
->GetView();
454 pView
->SdrEndTextEdit();
455 sd::OutlineView
* pOutlView
= dynamic_cast< sd::OutlineView
* >( pView
);
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
474 mpDoc
->libreOfficeKitCallback(nType
, pPayload
);
477 bool DrawDocShell::isTiledRendering() const
481 return mpDoc
->isTiledRendering();
486 } // end of namespace sd
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */