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 .
21 #include "DrawDocShell.hxx"
22 #include <vcl/svapp.hxx>
24 #include <sfx2/docfac.hxx>
25 #include <sfx2/objface.hxx>
27 #include <svx/svxids.hrc>
28 #include <svl/srchitem.hxx>
29 #include <svx/srchdlg.hxx>
30 #include <editeng/flstitem.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/intitem.hxx>
33 #include <sfx2/printer.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <svx/drawitem.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <svl/whiter.hxx>
38 #include <svl/itempool.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <vcl/graphicfilter.hxx>
41 #include <comphelper/classids.hxx>
42 #include <svl/cjkoptions.hxx>
43 #include <svl/visitem.hxx>
45 #include <svx/svdoutl.hxx>
47 #include <sfx2/fcontnr.hxx>
52 #include "stlpool.hxx"
53 #include "strings.hrc"
55 #include "drawdoc.hxx"
58 #include "res_bmp.hrc"
60 #include "fusearch.hxx"
61 #include "ViewShell.hxx"
62 #include "sdresid.hxx"
63 #include "slideshow.hxx"
64 #include "drawview.hxx"
65 #include "FrameView.hxx"
66 #include "unomodel.hxx"
67 #include "undo/undomanager.hxx"
68 #include "undo/undofactory.hxx"
69 #include "OutlineView.hxx"
70 #include "ViewShellBase.hxx"
74 #include "sdslots.hxx"
76 SFX_IMPL_INTERFACE(DrawDocShell
, SfxObjectShell
, SdResId(0))
78 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
84 GraphicFilter
* GetGrfFilter();
87 * slotmaps and definitions of SFX
89 TYPEINIT1( DrawDocShell
, SfxObjectShell
);
91 SFX_IMPL_OBJECTFACTORY(
93 SvGlobalName(SO3_SIMPRESS_CLASSID
),
94 SFXOBJECTSHELL_STD_NORMAL
,
97 void DrawDocShell::Construct( bool bClipboard
)
99 mbInDestruction
= sal_False
;
100 SetSlotFilter(); // setzt Filter zurueck
102 mbOwnDocument
= mpDoc
== 0;
104 mpDoc
= new SdDrawDocument(meDocType
, this);
106 // The document has been created so we can call UpdateRefDevice() to set
107 // the document's ref device.
110 SetBaseModel( new SdXImpressDocument( this, bClipboard
) );
111 SetPool( &mpDoc
->GetItemPool() );
112 mpUndoManager
= new sd::UndoManager
;
113 mpDoc
->SetSdrUndoManager( mpUndoManager
);
114 mpDoc
->SetSdrUndoFactory( new sd::UndoFactory
);
115 UpdateTablePointers();
116 SetStyleFamily(5); //CL: actually SFX_STYLE_FAMILY_PSEUDO
119 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode
,
120 sal_Bool bDataObject
,
121 DocumentType eDocumentType
) :
122 SfxObjectShell( eMode
== SFX_CREATE_MODE_INTERNAL
? SFX_CREATE_MODE_EMBEDDED
: eMode
),
128 meDocType(eDocumentType
),
130 mbSdDataObj(bDataObject
),
131 mbOwnPrinter(sal_False
),
132 mbNewDocument( sal_True
)
134 Construct( eMode
== SFX_CREATE_MODE_INTERNAL
);
137 DrawDocShell::DrawDocShell( const sal_uInt64 nModelCreationFlags
, sal_Bool bDataObject
, DocumentType eDocumentType
) :
138 SfxObjectShell( nModelCreationFlags
),
144 meDocType(eDocumentType
),
146 mbSdDataObj(bDataObject
),
147 mbOwnPrinter(sal_False
),
148 mbNewDocument( sal_True
)
150 Construct( sal_False
);
153 DrawDocShell::DrawDocShell(SdDrawDocument
* pDoc
, SfxObjectCreateMode eMode
,
154 sal_Bool bDataObject
,
155 DocumentType eDocumentType
) :
156 SfxObjectShell(eMode
== SFX_CREATE_MODE_INTERNAL
? SFX_CREATE_MODE_EMBEDDED
: eMode
),
162 meDocType(eDocumentType
),
164 mbSdDataObj(bDataObject
),
165 mbOwnPrinter(sal_False
),
166 mbNewDocument( sal_True
)
168 Construct( eMode
== SFX_CREATE_MODE_INTERNAL
);
171 DrawDocShell::~DrawDocShell()
173 // Tell all listeners that the doc shell is about to be
174 // destroyed. This has been introduced for the PreviewRenderer to
175 // free its view (that uses the item poll of the doc shell) but
176 // may be useful in other places as well.
177 Broadcast(SfxSimpleHint(SFX_HINT_DYING
));
179 mbInDestruction
= sal_True
;
181 SetDocShellFunction(0);
186 mpDoc
->SetSdrUndoManager( 0 );
187 delete mpUndoManager
;
195 // that the navigator get informed about the disappearance of the document
196 SfxBoolItem
aItem(SID_NAVIGATOR_INIT
, sal_True
);
197 SfxViewFrame
* pFrame
= mpViewShell
? mpViewShell
->GetFrame() : GetFrame();
200 pFrame
= SfxViewFrame::GetFirst( this );
203 pFrame
->GetDispatcher()->Execute(
204 SID_NAVIGATOR_INIT
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L);
207 void DrawDocShell::GetState(SfxItemSet
&rSet
)
210 SfxWhichIter
aIter( rSet
);
211 sal_uInt16 nWhich
= aIter
.FirstWhich();
215 sal_uInt16 nSlotId
= SfxItemPool::IsWhich(nWhich
)
216 ? GetPool().GetSlotId(nWhich
)
221 case SID_SEARCH_ITEM
:
223 rSet
.Put( *SD_MOD()->GetSearchItem() );
229 sal_Bool bDisabled
= sal_False
;
232 rSet
.DisableItem(SID_CLOSEDOC
);
236 GetSlotState(SID_CLOSEDOC
, SfxObjectShell::GetInterface(), &rSet
);
241 case SID_SEARCH_OPTIONS
:
243 sal_uInt16 nOpt
= SEARCH_OPTIONS_SEARCH
|
244 SEARCH_OPTIONS_WHOLE_WORDS
|
245 SEARCH_OPTIONS_BACKWARDS
|
246 SEARCH_OPTIONS_REG_EXP
|
247 SEARCH_OPTIONS_EXACT
|
248 SEARCH_OPTIONS_SIMILARITY
|
249 SEARCH_OPTIONS_SELECTION
;
253 nOpt
|= SEARCH_OPTIONS_REPLACE
;
254 nOpt
|= SEARCH_OPTIONS_REPLACE_ALL
;
257 rSet
.Put(SfxUInt16Item(nWhich
, nOpt
));
263 GetSlotState( SID_VERSION
, SfxObjectShell::GetInterface(), &rSet
);
267 case SID_CHINESE_CONVERSION
:
268 case SID_HANGUL_HANJA_CONVERSION
:
270 rSet
.Put(SfxVisibilityItem(nWhich
, SvtCJKOptions().IsAnyEnabled()));
277 nWhich
= aIter
.NextWhich();
280 SfxViewFrame
* pFrame
= SfxViewFrame::Current();
284 if (rSet
.GetItemState(SID_RELOAD
) != SFX_ITEM_UNKNOWN
)
286 pFrame
->GetSlotState(SID_RELOAD
,
287 pFrame
->GetInterface(), &rSet
);
292 void DrawDocShell::InPlaceActivate( sal_Bool bActive
)
294 ViewShell
* pViewSh
= NULL
;
295 SfxViewShell
* pSfxViewSh
= NULL
;
296 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, false);
297 std::vector
<FrameView
*> &rViews
= mpDoc
->GetFrameViewList();
301 std::vector
<FrameView
*>::iterator pIter
;
302 for ( pIter
= rViews
.begin(); pIter
!= rViews
.end(); ++pIter
)
307 while (pSfxViewFrame
)
309 // determine the number of FrameViews
310 pSfxViewSh
= pSfxViewFrame
->GetViewShell();
311 pViewSh
= PTR_CAST( ViewShell
, pSfxViewSh
);
313 if ( pViewSh
&& pViewSh
->GetFrameView() )
315 pViewSh
->WriteFrameViewData();
316 rViews
.push_back( new FrameView( mpDoc
, pViewSh
->GetFrameView() ) );
319 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, false);
323 SfxObjectShell::InPlaceActivate( bActive
);
327 for( sal_uInt32 i
= 0; pSfxViewFrame
&& (i
< rViews
.size()); i
++ )
329 // determine the number of FrameViews
330 pSfxViewSh
= pSfxViewFrame
->GetViewShell();
331 pViewSh
= PTR_CAST( ViewShell
, pSfxViewSh
);
335 pViewSh
->ReadFrameViewData( rViews
[ i
] );
338 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, false);
343 void DrawDocShell::Activate( sal_Bool bMDI
)
348 mpDoc
->StartOnlineSpelling();
352 void DrawDocShell::Deactivate( sal_Bool
)
356 ::svl::IUndoManager
* DrawDocShell::GetUndoManager()
358 return mpUndoManager
;
361 void DrawDocShell::UpdateTablePointers()
363 PutItem( SvxColorListItem( mpDoc
->GetColorList(), SID_COLOR_TABLE
) );
364 PutItem( SvxGradientListItem( mpDoc
->GetGradientList(), SID_GRADIENT_LIST
) );
365 PutItem( SvxHatchListItem( mpDoc
->GetHatchList(), SID_HATCH_LIST
) );
366 PutItem( SvxBitmapListItem( mpDoc
->GetBitmapList(), SID_BITMAP_LIST
) );
367 PutItem( SvxDashListItem( mpDoc
->GetDashList(), SID_DASH_LIST
) );
368 PutItem( SvxLineEndListItem( mpDoc
->GetLineEndList(), SID_LINEEND_LIST
) );
373 void DrawDocShell::CancelSearching()
375 if( dynamic_cast<FuSearch
*>( mxDocShellFunction
.get() ) )
377 SetDocShellFunction(0);
382 * apply configured slot filters
384 void DrawDocShell::ApplySlotFilter() const
386 SfxViewShell
* pTestViewShell
= SfxViewShell::GetFirst();
388 while( pTestViewShell
)
390 if( pTestViewShell
->GetObjectShell()
391 == const_cast<DrawDocShell
*>( this )
392 && pTestViewShell
->GetViewFrame()
393 && pTestViewShell
->GetViewFrame()->GetDispatcher() )
395 SfxDispatcher
* pDispatcher
= pTestViewShell
->GetViewFrame()->GetDispatcher();
398 pDispatcher
->SetSlotFilter( mbFilterEnable
, mnFilterCount
, mpFilterSIDs
);
400 pDispatcher
->SetSlotFilter();
402 if( pDispatcher
->GetBindings() )
403 pDispatcher
->GetBindings()->InvalidateAll( sal_True
);
406 pTestViewShell
= SfxViewShell::GetNext( *pTestViewShell
);
410 void DrawDocShell::SetModified( sal_Bool bSet
/* = sal_True */ )
412 SfxObjectShell::SetModified( bSet
);
414 // change model state, too
415 // only set the changed state if modification is enabled
416 if( IsEnableSetModified() )
419 mpDoc
->NbcSetChanged( bSet
);
421 Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED
) );
426 * Callback for ExecuteSpellPopup()
428 // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
429 // to get hands on the outliner and the text object.
430 IMPL_LINK(DrawDocShell
, OnlineSpellCallback
, SpellCallbackInfo
*, pInfo
)
432 SdrObject
* pObj
= NULL
;
433 SdrOutliner
* pOutl
= NULL
;
437 pOutl
= GetViewShell()->GetView()->GetTextEditOutliner();
438 pObj
= GetViewShell()->GetView()->GetTextEditObject();
441 mpDoc
->ImpOnlineSpellCallback(pInfo
, pObj
, pOutl
);
445 void DrawDocShell::ClearUndoBuffer()
447 // clear possible undo buffers of outliners
448 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, false);
451 ViewShellBase
* pViewShellBase
= dynamic_cast< ViewShellBase
* >( pSfxViewFrame
->GetViewShell() );
454 ::boost::shared_ptr
<ViewShell
> pViewSh( pViewShellBase
->GetMainViewShell() );
457 ::sd::View
* pView
= pViewSh
->GetView();
460 pView
->SdrEndTextEdit();
461 sd::OutlineView
* pOutlView
= dynamic_cast< sd::OutlineView
* >( pView
);
464 SdrOutliner
* pOutliner
= pOutlView
->GetOutliner();
466 pOutliner
->GetUndoManager().Clear();
471 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, false);
474 ::svl::IUndoManager
* pUndoManager
= GetUndoManager();
475 if(pUndoManager
&& pUndoManager
->GetUndoActionCount())
476 pUndoManager
->Clear();
479 } // end of namespace sd
481 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */